Skip to content

Commit

Permalink
Refactor Equipment
Browse files Browse the repository at this point in the history
- Rename exp to Exp
- Put Exp from equipment row data when creating new equipment
  • Loading branch information
U-lis committed Aug 22, 2023
1 parent 7610b6c commit 91d8e60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions .Lib9c.Tests/Action/ItemEnhancementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ public void Execute(
var equipment = (Equipment)ItemFactory.CreateItemUsable(row, default, 0, startLevel);
if (startLevel == 0)
{
equipment.exp = (long)row.Exp!;
equipment.Exp = (long)row.Exp!;
}
else
{
equipment.exp = _tableSheets.EnhancementCostSheetV3.Values.First(r =>
equipment.Exp = _tableSheets.EnhancementCostSheetV3.Values.First(r =>
r.Grade == equipment.Grade && r.ItemSubType == equipment.ItemSubType &&
r.Level == equipment.level).Exp;
}

var startExp = equipment.exp;
var startExp = equipment.Exp;
_avatarState.inventory.AddItem(equipment, count: 1);

var expectedExpIncrement = 0L;
Expand All @@ -143,16 +143,16 @@ public void Execute(
(Equipment)ItemFactory.CreateItemUsable(row, materialId, 0, materialLevel);
if (materialLevel == 0)
{
material.exp = (long)row.Exp!;
material.Exp = (long)row.Exp!;
}
else
{
material.exp = _tableSheets.EnhancementCostSheetV3.Values.First(r =>
material.Exp = _tableSheets.EnhancementCostSheetV3.Values.First(r =>
r.Grade == material.Grade && r.ItemSubType == material.ItemSubType &&
r.Level == material.level).Exp;
}

expectedExpIncrement += material.exp;
expectedExpIncrement += material.Exp;
_avatarState.inventory.AddItem(material, count: 1);
}

Expand Down Expand Up @@ -226,7 +226,7 @@ public void Execute(
var nextAvatarState = nextState.GetAvatarState(_avatarAddress);
Assert.Equal(default, resultEquipment.ItemId);
Assert.Equal(expectedLevel, resultEquipment.level);
Assert.Equal(startExp + expectedExpIncrement, resultEquipment.exp);
Assert.Equal(startExp + expectedExpIncrement, resultEquipment.Exp);
Assert.Equal(
(3_000_000 - expectedCost) * _currency,
nextState.GetBalance(_agentAddress, _currency)
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Model/Item/EquipmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Serialize(long exp)
Assert.NotNull(_equipmentRow);

var costume = new Equipment(_equipmentRow, Guid.NewGuid(), 0);
costume.exp = exp;
costume.Exp = exp;
var serialized = costume.Serialize();
var deserialized = new Equipment((Bencodex.Types.Dictionary)serialized);
var reSerialized = deserialized.Serialize();
Expand Down
1 change: 0 additions & 1 deletion Lib9c/Action/CombinationEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Libplanet.Action;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume.Extensions;
using Nekoyume.Helper;
using Nekoyume.Model.Item;
Expand Down
6 changes: 3 additions & 3 deletions Lib9c/Action/ItemEnhancement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ public override IAccountStateDelta Execute(IActionContext context)
var preItemUsable = new Equipment((Dictionary)enhancementEquipment.Serialize());

// Equipment level up & Update
enhancementEquipment.exp +=
materialEquipments.Aggregate(0L, (total, m) => total + m.exp);
enhancementEquipment.Exp +=
materialEquipments.Aggregate(0L, (total, m) => total + m.Exp);
var row = enhancementCostSheet
.OrderByDescending(r => r.Value.Exp)
.First(row =>
row.Value.ItemSubType == enhancementEquipment.ItemSubType &&
row.Value.Grade == enhancementEquipment.Grade &&
row.Value.Exp <= enhancementEquipment.exp
row.Value.Exp <= enhancementEquipment.Exp
).Value;

if (row.Level > enhancementEquipment.level)
Expand Down
13 changes: 7 additions & 6 deletions Lib9c/Model/Item/Equipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Equipment : ItemUsable, IEquippableItem
// FIXME: Whether the equipment is equipped or not has no asset value and must be removed from the state.
public bool equipped;
public int level;
public long exp;
public long Exp;
public int optionCountFromCombination;

public DecimalStat Stat { get; }
Expand All @@ -41,6 +41,7 @@ public Equipment(EquipmentItemSheet.Row data, Guid id, long requiredBlockIndex,
SetId = data.SetId;
SpineResourcePath = data.SpineResourcePath;
MadeWithMimisbrunnrRecipe = madeWithMimisbrunnrRecipe;
Exp = data.Exp ?? 0L;
}

public Equipment(Dictionary serialized) : base(serialized)
Expand All @@ -66,11 +67,11 @@ public Equipment(Dictionary serialized) : base(serialized)
{
try
{
exp = value.ToLong();
Exp = value.ToLong();
}
catch (InvalidCastException)
{
exp = (long)((Integer)value).Value;
Exp = (long)((Integer)value).Value;
}
}

Expand Down Expand Up @@ -125,9 +126,9 @@ public override IValue Serialize()
dict = dict.SetItem(MadeWithMimisbrunnrRecipeKey, MadeWithMimisbrunnrRecipe.Serialize());
}

if (exp > 0)
if (Exp > 0)
{
dict = dict.SetItem(EquipmentExpKey, exp.Serialize());
dict = dict.SetItem(EquipmentExpKey, Exp.Serialize());
}

return dict;
Expand Down Expand Up @@ -351,7 +352,7 @@ private void UpdateOptionsV3(IRandom random, EnhancementCostSheetV3.Row row)
protected bool Equals(Equipment other)
{
return base.Equals(other) && equipped == other.equipped && level == other.level &&
exp == other.exp && Equals(Stat, other.Stat) && SetId == other.SetId &&
Exp == other.Exp && Equals(Stat, other.Stat) && SetId == other.SetId &&
SpineResourcePath == other.SpineResourcePath;
}

Expand Down

0 comments on commit 91d8e60

Please sign in to comment.