Skip to content

Commit

Permalink
Merge pull request #3108 from planetarium/feature/obsolete-additem
Browse files Browse the repository at this point in the history
Feature/obsolete additem
  • Loading branch information
eugene-doobu authored Jan 7, 2025
2 parents 7c0496c + 53c8800 commit f70fdc5
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 338 deletions.
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/BuyMultipleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void Execute(params ShopItemData[] productDatas)
// Case for backward compatibility of `Buy`
if (product.ContainsInInventory)
{
sellerAvatarState.inventory.AddItem2((ItemBase)nonFungibleItem);
sellerAvatarState.inventory.AddItem((ItemBase)nonFungibleItem);
}

var shopItemId = Guid.NewGuid();
Expand Down
13 changes: 6 additions & 7 deletions .Lib9c.Tests/Action/BuyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Lib9c.Tests.Action
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Model;
using Nekoyume.Model.Item;
using Nekoyume.Model.Mail;
Expand All @@ -26,7 +25,6 @@ namespace Lib9c.Tests.Action
using Serilog;
using Xunit;
using Xunit.Abstractions;
using static Lib9c.SerializeKeys;

public class BuyTest
{
Expand Down Expand Up @@ -685,7 +683,7 @@ public void Execute_ReconfigureFungibleItem(params OrderData[] orderDataList)

var dummyItem = ItemFactory.CreateTradableMaterial(
_tableSheets.MaterialItemSheet.OrderedList.First(r => r.ItemSubType == ItemSubType.Hourglass));
sellerAvatarState.inventory.AddItem2((ItemBase)dummyItem, orderDataList.Sum(x => x.ItemCount));
sellerAvatarState.inventory.AddItem((ItemBase)dummyItem, orderDataList.Sum(x => x.ItemCount));

foreach (var orderData in orderDataList)
{
Expand Down Expand Up @@ -724,7 +722,7 @@ public void Execute_ReconfigureFungibleItem(params OrderData[] orderDataList)
);
_initialState.SetAvatarState(orderData.SellerAvatarAddress, sellerAvatarState);

var sellItem = order.Sell3(sellerAvatarState);
var sellItem = order.Sell(sellerAvatarState);
var orderDigest = order.Digest(sellerAvatarState, _tableSheets.CostumeStatSheet);

var digestListAddress = OrderDigestListState.DeriveAddress(firstData.SellerAvatarAddress);
Expand Down Expand Up @@ -767,9 +765,10 @@ public void Execute_ReconfigureFungibleItem(params OrderData[] orderDataList)
.SetLegacyState(orderDigestListState.Address, orderDigestListState.Serialize());
}

var sumCount = orderDataList.Sum(x => x.ItemCount);
Assert.Equal(1, sellerAvatarState.inventory.Items.Count);
Assert.Equal(sumCount, sellerAvatarState.inventory.Items.First().count);
// 2 -> because Locked item see AddFungibleItem(ItemBase itemBase, int count = 1, ILock iLock = null)
Assert.Equal(2, sellerAvatarState.inventory.Items.Count);
Assert.Equal(orderDataList[0].ItemCount, sellerAvatarState.inventory.Items.First().count);
Assert.Equal(orderDataList[1].ItemCount, sellerAvatarState.inventory.Items.Last().count);

var buyAction = new Buy
{
Expand Down
93 changes: 0 additions & 93 deletions .Lib9c.Tests/Model/Item/InventoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ public Inventory AddItem_Consumable()
return AddItem_Consumable_After(inventory);
}

[Fact]
public Inventory AddItem2_Consumable()
{
var item = GetFirstConsumable();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

inventory.AddItem2(item);
return AddItem_Consumable_After(inventory);
}

[Fact]
public Inventory AddItem_Costume()
{
Expand All @@ -81,17 +70,6 @@ public Inventory AddItem_Costume()
return AddItem_Costume_After(inventory);
}

[Fact]
public Inventory AddItem2_Costume()
{
var item = GetFirstCostume();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

inventory.AddItem2(item);
return AddItem_Costume_After(inventory);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
Expand All @@ -109,23 +87,6 @@ public Inventory AddItem_Material(int count)
return AddItem_Material_After(inventory, count);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
public Inventory AddItem2_Material(int count)
{
var item = GetFirstMaterial();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

for (var i = 0; i < count; i++)
{
inventory.AddItem2(item);
}

return AddItem_Material_After(inventory, count);
}

[Fact]
public Inventory AddItem_Equipment()
{
Expand All @@ -137,17 +98,6 @@ public Inventory AddItem_Equipment()
return AddItem_Equipment_After(inventory);
}

[Fact]
public Inventory AddItem2_Equipment()
{
var item = GetFirstEquipment();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

inventory.AddItem2(item);
return AddItem_Equipment_After(inventory);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
Expand All @@ -165,23 +115,6 @@ public Inventory AddItem_TradableMaterial(int count)
return AddItem_Material_After(inventory, count);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
public Inventory AddItem2_TradableMaterial(int count)
{
var item = GetFirstTradableMaterial();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

for (var i = 0; i < count; i++)
{
inventory.AddItem2(item);
}

return AddItem_Material_After(inventory, count);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
Expand All @@ -195,19 +128,6 @@ public Inventory AddFungibleItem_Material(int count)
return AddItem_Material_After(inventory, count);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
public Inventory AddFungibleItem2_Material(int count)
{
var item = GetFirstMaterial();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

inventory.AddFungibleItem2(item, count);
return AddItem_Material_After(inventory, count);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
Expand All @@ -221,19 +141,6 @@ public Inventory AddFungibleItem_TradableMaterial(int count)
return AddItem_Material_After(inventory, count);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
public Inventory AddFungibleItem2_TradableMaterial(int count)
{
var item = GetFirstTradableMaterial();
var inventory = new Inventory();
Assert.Empty(inventory.Items);

inventory.AddFungibleItem2(item, count);
return AddItem_Material_After(inventory, count);
}

[Fact]
public Inventory AddNonFungibleItem_Consumable()
{
Expand Down
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Model/State/ShardedShopStateV2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ public void Remove()
var item2 = (Weapon)ItemFactory.CreateItem(
tableSheets.ItemSheet.Values.First(r => r.ItemSubType == ItemSubType.Weapon),
random);
avatarState.inventory.AddItem2(item);
avatarState.inventory.AddItem2(item2);
avatarState.inventory.AddItem(item);
avatarState.inventory.AddItem(item2);

var orderId = new Guid("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4");
var orderId2 = new Guid("936DA01F-9ABD-4d9d-80C7-02AF85C822A8");
Expand Down
27 changes: 19 additions & 8 deletions Lib9c.DevExtensions/Manager/Contents/CreateAvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ namespace Lib9c.DevExtensions.Manager.Contents
/// </summary>
public static class CreateAvatarManager
{
// TODO: Costume과 Grimoire, Aura에 한해 하드코딩같은 형태로 구현되어 있음. 추후 수정 필요.
private const int AddItemCount = 10;

/// <summary>
/// Create an avatar and world state for testing.
/// </summary>
/// <param name="ctx">action context</param>
/// <param name="avatarAddress">avatar address</param>
/// <param name="states">base world state</param>
/// <param name="avatarState">avatar state</param>
/// <param name="random">random object</param>
/// <returns>world state with dev avatar</returns>
public static IWorld ExecuteDevExtensions(IActionContext ctx, Address avatarAddress, IWorld states, AvatarState avatarState)
public static IWorld ExecuteDevExtensions(IActionContext ctx, Address avatarAddress, IWorld states, AvatarState avatarState, IRandom random)
{
// prepare for test when executing on editor mode.
var data = TestbedHelper.LoadData<TestbedCreateAvatar>("TestbedCreateAvatar");
Expand All @@ -49,7 +53,6 @@ public static IWorld ExecuteDevExtensions(IActionContext ctx, Address avatarAddr
var characterLevelSheet = states.GetSheet<CharacterLevelSheet>();
var enhancementCostSheet = states.GetSheet<EnhancementCostSheetV2>();
var materialItemSheet = states.GetSheet<MaterialItemSheet>();
var random = ctx.GetRandom();

AddTestItems(ctx, avatarState, random, materialItemSheet);

Expand Down Expand Up @@ -252,17 +255,19 @@ private static void AddItemsForTest(
int tradableMaterialCount,
int foodCount)
{
foreach (var row in costumeItemSheet.OrderedList)
for (var i = 0; i < AddItemCount; ++i)
{
avatarState.inventory.AddItem(ItemFactory.CreateCostume(row, random.GenerateRandomGuid()));
foreach (var row in costumeItemSheet.OrderedList)
{
avatarState.inventory.AddItem(ItemFactory.CreateCostume(row, random.GenerateRandomGuid()));
}
}

foreach (var row in materialItemSheet.OrderedList)
{
avatarState.inventory.AddItem(ItemFactory.CreateMaterial(row), materialCount);

if (row.ItemSubType == ItemSubType.Hourglass ||
row.ItemSubType == ItemSubType.ApStone)
if (row.ItemSubType is ItemSubType.Hourglass || row.ItemSubType is ItemSubType.ApStone)
{
avatarState.inventory.AddItem(ItemFactory.CreateTradableMaterial(row), tradableMaterialCount);
}
Expand All @@ -271,8 +276,14 @@ private static void AddItemsForTest(
foreach (var row in equipmentItemSheet.OrderedList.Where(row =>
row.Id > GameConfig.DefaultAvatarWeaponId))
{
var itemId = random.GenerateRandomGuid();
avatarState.inventory.AddItem(ItemFactory.CreateItemUsable(row, itemId, default));
if (row.ItemSubType is ItemSubType.Grimoire || row.ItemSubType is ItemSubType.Aura)
{
for (var i = 0; i < AddItemCount; ++i)
{
avatarState.inventory.AddItem(ItemFactory.CreateItemUsable(row, random.GenerateRandomGuid(), default));
}
}
avatarState.inventory.AddItem(ItemFactory.CreateItemUsable(row, random.GenerateRandomGuid(), default));
}

foreach (var row in consumableItemSheet.OrderedList)
Expand Down
8 changes: 4 additions & 4 deletions Lib9c/Action/Buy7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public override IWorld Execute(IActionContext context)
buyerAvatarState.Update(buyerMail);
if (purchaseResult.itemUsable != null)
{
buyerAvatarState.UpdateFromAddItem2(purchaseResult.itemUsable, false);
buyerAvatarState.UpdateFromAddItem(purchaseResult.itemUsable, false);
}

if (purchaseResult.costume != null)
Expand All @@ -437,7 +437,7 @@ public override IWorld Execute(IActionContext context)

if (purchaseResult.tradableFungibleItem is TradableMaterial material)
{
buyerAvatarState.UpdateFromAddItem2(material, shopItem.TradableFungibleItemCount, false);
buyerAvatarState.UpdateFromAddItem(material, shopItem.TradableFungibleItemCount, false);
}

sellerAvatarState.Update(sellerMail);
Expand All @@ -449,8 +449,8 @@ public override IWorld Execute(IActionContext context)
sellerAvatarState.updatedAt = ctx.BlockIndex;
sellerAvatarState.blockIndex = ctx.BlockIndex;

buyerAvatarState.UpdateQuestRewards2(materialSheet);
sellerAvatarState.UpdateQuestRewards2(materialSheet);
buyerAvatarState.UpdateQuestRewards(materialSheet);
sellerAvatarState.UpdateQuestRewards(materialSheet);

states = states.SetAvatarState(sellerAvatarAddress, sellerAvatarState);
sw.Stop();
Expand Down
6 changes: 3 additions & 3 deletions Lib9c/Action/BuyMultiple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public override IWorld Execute(IActionContext context)
buyerAvatarState.Update(buyerMail);
if (purchaseResult.itemUsable != null)
{
buyerAvatarState.UpdateFromAddItem2(purchaseResult.itemUsable, false);
buyerAvatarState.UpdateFromAddItem(purchaseResult.itemUsable, false);
}
if (purchaseResult.costume != null)
{
Expand All @@ -398,7 +398,7 @@ public override IWorld Execute(IActionContext context)

sellerAvatarState.updatedAt = ctx.BlockIndex;
sellerAvatarState.blockIndex = ctx.BlockIndex;
sellerAvatarState.UpdateQuestRewards2(materialSheet);
sellerAvatarState.UpdateQuestRewards(materialSheet);

sw.Restart();
states = states.SetAvatarState(productInfo.sellerAvatarAddress, sellerAvatarState);
Expand All @@ -412,7 +412,7 @@ public override IWorld Execute(IActionContext context)
buyerAvatarState.updatedAt = ctx.BlockIndex;
buyerAvatarState.blockIndex = ctx.BlockIndex;

buyerAvatarState.UpdateQuestRewards2(materialSheet);
buyerAvatarState.UpdateQuestRewards(materialSheet);

sw.Restart();
states = states.SetAvatarState(buyerAvatarAddress, buyerAvatarState);
Expand Down
4 changes: 2 additions & 2 deletions Lib9c/Action/CombinationConsumable5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ public override IWorld Execute(IActionContext context)
);
result.id = mail.id;
avatarState.Update(mail);
avatarState.UpdateFromCombination2(itemUsable);
avatarState.UpdateFromCombination(itemUsable);
sw.Stop();
Log.Verbose("{AddressesHex}Combination Update AvatarState: {Elapsed}", addressesHex, sw.Elapsed);
sw.Restart();

var materialSheet = states.GetSheet<MaterialItemSheet>();
avatarState.UpdateQuestRewards2(materialSheet);
avatarState.UpdateQuestRewards(materialSheet);

avatarState.updatedAt = ctx.BlockIndex;
avatarState.blockIndex = ctx.BlockIndex;
Expand Down
6 changes: 3 additions & 3 deletions Lib9c/Action/CreateAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public override IWorld Execute(IActionContext context)
)
);

var random = ctx.GetRandom();
var addressesHex = GetSignerAndOtherAddressesHex(context, avatarAddress);
ValidateName(addressesHex);

Expand Down Expand Up @@ -110,7 +111,7 @@ public override IWorld Execute(IActionContext context)
avatarState.UpdateQuestRewards(materialItemSheet);

#if LIB9C_DEV_EXTENSIONS || UNITY_EDITOR
states = CreateAvatarManager.ExecuteDevExtensions(ctx, avatarAddress, states, avatarState);
states = CreateAvatarManager.ExecuteDevExtensions(ctx, avatarAddress, states, avatarState, random);
#endif

var sheets = ctx.PreviousState.GetSheets(containItemSheet: true,
Expand All @@ -120,7 +121,7 @@ public override IWorld Execute(IActionContext context)
});
var itemSheet = sheets.GetItemSheet();
var createAvatarItemSheet = sheets.GetSheet<CreateAvatarItemSheet>();
AddItem(itemSheet, createAvatarItemSheet, avatarState, context.GetRandom());
AddItem(itemSheet, createAvatarItemSheet, avatarState, random);
var createAvatarFavSheet = sheets.GetSheet<CreateAvatarFavSheet>();
states = MintAsset(createAvatarFavSheet, avatarState, states, context);

Expand Down Expand Up @@ -257,7 +258,6 @@ public static AvatarState CreateAvatarState(string name,
Address rankingMapAddress)
{
var state = ctx.PreviousState;
var random = ctx.GetRandom();
var avatarState = AvatarState.Create(
avatarAddress,
ctx.Signer,
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/DailyReward2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override IWorld Execute(IActionContext context)
result.id = mail.id;
dailyRewardResult = result;
avatarState.Update(mail);
avatarState.UpdateFromAddItem2(material, rewardItemCount, false);
avatarState.UpdateFromAddItem(material, rewardItemCount, false);
return states.SetAvatarState(avatarAddress, avatarState);
}

Expand Down
Loading

0 comments on commit f70fdc5

Please sign in to comment.