Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve avatar inventory logic #64

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Mimir/Controllers/AvatarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,19 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
return inventory;
}

Address inventoryAddress;
try
{
inventoryAddress = new Address(avatarAddress);
}
catch (ArgumentException e)
{
Response.StatusCode = StatusCodes.Status400BadRequest;
return null;
}

var stateGetter = new StateGetter(stateService);
var inventoryState = await stateGetter.GetInventoryStateAsync(new Address(avatarAddress));
var inventoryState = await stateGetter.GetInventoryStateAsync(inventoryAddress);
if (inventoryState is null)
{
Response.StatusCode = StatusCodes.Status404NotFound;
Expand Down
3 changes: 0 additions & 3 deletions Mimir/Models/Items/Equipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ namespace Mimir.Models.Items;

public class Equipment : Item
{
public Guid NonFungibleId { get; set; }
public int Level { get; set; }

public Equipment(Nekoyume.Model.Item.Equipment equipment) :
base(equipment, count: 1)
{
NonFungibleId = equipment.NonFungibleId;
Level = equipment.level;
}

public Equipment(BsonDocument equipment) : base(equipment)
{
NonFungibleId = Guid.Parse(equipment["NonFungibleId"].AsString);
Level = equipment["level"].AsInt32;
}
}
18 changes: 13 additions & 5 deletions Mimir/Models/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public class Item
public ItemSubType ItemSubType { get; set; }
public ElementalType ElementalType { get; set; }

public int? Count { get; set; }
public int Count { get; set; }

public Guid? NonFungibleId { get; set; }
public long? RequiredBlockIndex { get; set; }

public Item(ItemBase item, int? count)
public Item(ItemBase item, int count)
{
ItemSheetId = item.Id;
Grade = item.Grade;
Expand All @@ -24,10 +26,14 @@ public Item(ItemBase item, int? count)
ElementalType = item.ElementalType;

Count = count;

NonFungibleId = item is INonFungibleItem nonFungibleItem
? nonFungibleItem.NonFungibleId
: null;
RequiredBlockIndex = item switch
{
INonFungibleItem nonFungibleItem => nonFungibleItem.RequiredBlockIndex,
ITradableItem tradableItem => tradableItem.RequiredBlockIndex,
INonFungibleItem nfi => nfi.RequiredBlockIndex,
ITradableItem ti => ti.RequiredBlockIndex,
_ => null
};
}
Expand All @@ -40,7 +46,9 @@ public Item(BsonDocument item)
ItemSubType = (ItemSubType)item["ItemSubType"].AsInt32;
ElementalType = (ElementalType)item["ElementalType"].AsInt32;

Count = item["Count"].AsNullableInt32;
Count = item["Count"].AsInt32;

NonFungibleId = item["NonFungibleId"].AsNullableGuid;
RequiredBlockIndex = item["RequiredBlockIndex"].AsNullableInt64;
}
}