Skip to content

Commit

Permalink
Merge pull request #120 from planetarium/feature/add-icon-id
Browse files Browse the repository at this point in the history
Add "IconId" into ItemProduct model
  • Loading branch information
U-lis authored Sep 5, 2024
2 parents 5995437 + 613f454 commit a96c32b
Show file tree
Hide file tree
Showing 11 changed files with 691 additions and 14 deletions.
5 changes: 5 additions & 0 deletions MarketService.Response/Interface/IItemProductSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace MarketService.Response.Interface;
public interface IItemProductSchema : IProductSchema
{
public int ItemId { get; set; }
public int IconId { get; set; }
public int Grade { get; set; }
public ItemType ItemType { get; set; }
public ItemSubType ItemSubType { get; set; }
Expand All @@ -19,4 +20,8 @@ public interface IItemProductSchema : IProductSchema
public ICollection<SkillResponseModel> SkillModels { get; }
public ICollection<StatResponseModel> StatModels { get; }
public int OptionCountFromCombination { get; set; }

// Custom Crafted Equipment
public bool ByCustomCraft { get; set; }
public bool HasRandomOnlyIcon { get; set; }
}
8 changes: 6 additions & 2 deletions MarketService.Response/ItemProductResponseModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Libplanet;
using Libplanet.Crypto;
using MarketService.Response.Interface;
using Nekoyume.Model.Elemental;
Expand All @@ -20,6 +19,7 @@ public class ItemProductResponseModel : IItemProductSchema
public bool Exist { get; set; }
public bool Legacy { get; set; }
public int ItemId { get; set; }
public int IconId { get; set; }
public int Grade { get; set; }
public ItemType ItemType { get; set; }
public ItemSubType ItemSubType { get; set; }
Expand All @@ -34,5 +34,9 @@ public class ItemProductResponseModel : IItemProductSchema
public decimal UnitPrice { get; set; }
public int Crystal { get; set; }
public int CrystalPerPrice { get; set; }

// CustomCraft
public bool ByCustomCraft { get; set; }
public bool HasRandomOnlyIcon { get; set; }
}
}
}
28 changes: 19 additions & 9 deletions MarketService.Tests/RpcClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using Libplanet.Types.Assets;
using Libplanet.Mocks;
using Libplanet.Types.Blocks;
using Libplanet.Types.Evidence;
using Libplanet.Types.Tx;
using MagicOnion;
using MagicOnion.Server;
using MarketService.Models;
Expand Down Expand Up @@ -328,7 +326,7 @@ public RpcClientTest(ITestOutputHelper output)
new DbContextOptionsBuilder<MarketContext>().UseNpgsql(_connectionString)
.UseLowerCaseNamingConvention().Options, new DbContextFactorySource<MarketContext>());
#pragma warning restore EF1001
var rpcConfigOptions = new RpcConfigOptions {Host = "localhost", Port = 5000};
var rpcConfigOptions = new RpcConfigOptions { Host = "localhost", Port = 5000 };
var receiver = new Receiver(new Logger<Receiver>(new LoggerFactory()));
using var logger = _output.BuildLoggerFor<RpcClient>();
_client = new TestClient(new OptionsWrapper<RpcConfigOptions>(rpcConfigOptions),
Expand Down Expand Up @@ -365,7 +363,7 @@ public async Task SyncOrder_Cancel(ItemSubType itemSubType)
tradableItem = ItemFactory.CreateCostume(row, order.TradableId);
}

item = (ItemBase) tradableItem;
item = (ItemBase)tradableItem;
var blockIndex = ActionObsoleteConfig.V100080ObsoleteIndex + 1L;

var orderDigest = new OrderDigest(
Expand Down Expand Up @@ -429,7 +427,7 @@ public async Task SyncOrder_ReRegister(ItemSubType itemSubType)
itemSubType, 1);
_testService.SetOrder(order);
var item = ItemFactory.CreateItemUsable(_row, order.TradableId, 0L);
((Equipment) item).optionCountFromCombination = 1;
((Equipment)item).optionCountFromCombination = 1;
var blockIndex = ActionObsoleteConfig.V100080ObsoleteIndex + 1L;
var orderDigest = new OrderDigest(
agentAddress,
Expand Down Expand Up @@ -496,8 +494,11 @@ await _client.SyncOrder(null!, _crystalEquipmentGrindingSheet,
Assert.True(newProduct.Exist);
}

[Fact]
public async Task SyncProduct()
[Theory]
[InlineData(10151000, false, false)]
[InlineData(10151000, true, false)]
[InlineData(10120000, true, true)]
public async Task SyncProduct(int iconId, bool byCustomCraft, bool hasRandomOnlyIcon)
{
var ct = new CancellationToken();
#pragma warning disable EF1001
Expand All @@ -517,7 +518,11 @@ public async Task SyncProduct()
{
var tradableId = Guid.NewGuid();
var productId = Guid.NewGuid();
var item = ItemFactory.CreateItemUsable(_row, tradableId, 1L, i + 1);
var item = (Equipment)ItemFactory.CreateItemUsable(_row, tradableId, 1L, i + 1);
item.IconId = iconId;
item.ByCustomCraft = byCustomCraft;
item.HasRandomOnlyIcon = hasRandomOnlyIcon;

var itemProduct = new ItemProduct
{
ProductId = productId,
Expand Down Expand Up @@ -553,6 +558,10 @@ await _client.SyncProduct(null!, _crystalEquipmentGrindingSheet, _crystalMonster
Assert.True(itemProduct.CombatPoint > 0);
Assert.True(itemProduct.Level > 0);
Assert.Equal(1, itemProduct.Grade);
// If item does not have IconId, IconId is same as ItemId
Assert.Equal(iconId, itemProduct.IconId);
Assert.Equal(byCustomCraft, itemProduct.ByCustomCraft);
Assert.Equal(hasRandomOnlyIcon, itemProduct.HasRandomOnlyIcon);
}
}

Expand Down Expand Up @@ -876,8 +885,9 @@ private void SetShopStates(ItemSubType itemSubType, OrderDigest orderDigest)
{
shopState.Add(orderDigest, 0L);
}

_testService.SetState(shopAddress, shopState.Serialize());
}
}
}
}
}
Loading

0 comments on commit a96c32b

Please sign in to comment.