Skip to content

Commit

Permalink
fix inventory state
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-doobu committed Dec 17, 2024
1 parent 0144b54 commit 8317149
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ Type exc
previousAvatarState.inventory.AddItem(equipment);
}

state = state.SetAvatarState(TesterAvatarAddress, previousAvatarState);

var expectedItemRewards = new List<(int, int)>();
var expectedFavRewards = new List<(int, int)>();
var firstRewardSheet = TableSheets.AdventureBossFloorFirstRewardSheet;
Expand Down
15 changes: 15 additions & 0 deletions .Lib9c.Tests/Action/EventDungeonBattleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,21 @@ private IWorld Execute(
previousAvatarState.inventory.AddItem(equipment, iLock: null);
}

previousStates = previousStates.SetAvatarState(_avatarAddress, previousAvatarState);

var allRuneState = previousStates.GetRuneState(_avatarAddress, out _);
if (!allRuneState.TryGetRuneState(runeId, out _))
{
allRuneState.AddRuneState(new RuneState(runeId, 1));
}

if (!allRuneState.TryGetRuneState(runeId2, out _))
{
allRuneState.AddRuneState(new RuneState(runeId2, 1));
}

previousStates = previousStates.SetRuneState(_avatarAddress, allRuneState);

var action = new EventDungeonBattle
{
AvatarAddress = _avatarAddress,
Expand Down
15 changes: 12 additions & 3 deletions .Lib9c.Tests/Action/HackAndSlashSweepTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ public HackAndSlashSweepTest()

public (List<Guid> Equipments, List<Guid> Costumes) GetDummyItems(AvatarState avatarState)
{
var equipments = Doomfist.GetAllParts(_tableSheets, avatarState.level)
.Select(e => e.NonFungibleId).ToList();
var equipments = Doomfist.GetAllParts(_tableSheets, avatarState.level).ToList();
foreach (var equipment in equipments)
{
avatarState.inventory.AddItem(equipment, iLock: null);
}

var equipmentGuids = equipments.Select(e => e.NonFungibleId).ToList();
var random = new TestRandom();
var costumes = new List<Guid>();
if (avatarState.level >= GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot)
Expand All @@ -111,7 +116,7 @@ public HackAndSlashSweepTest()
costumes.Add(costume.ItemId);
}

return (equipments, costumes);
return (equipmentGuids, costumes);
}

[Fact]
Expand Down Expand Up @@ -349,6 +354,7 @@ public void Execute_NotEnoughMaterialException(int useApStoneCount, int holdingA
(int)playCount);

var (equipments, costumes) = GetDummyItems(avatarState);
state = state.SetAvatarState(_avatarAddress, avatarState);

var action = new HackAndSlashSweep
{
Expand Down Expand Up @@ -405,6 +411,8 @@ public void Execute_NotEnoughActionPointException()
(int)playCount);

var (equipments, costumes) = GetDummyItems(avatarState);
state = state.SetAvatarState(_avatarAddress, avatarState);

var action = new HackAndSlashSweep
{
runeInfos = new List<RuneSlotInfo>(),
Expand Down Expand Up @@ -461,6 +469,7 @@ public void Execute_PlayCountIsZeroException()
(int)playCount);

var (equipments, costumes) = GetDummyItems(avatarState);
state = state.SetAvatarState(_avatarAddress, avatarState);
var action = new HackAndSlashSweep
{
costumes = costumes,
Expand Down
13 changes: 13 additions & 0 deletions .Lib9c.Tests/Action/HackAndSlashTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,19 @@ public void ExecuteTwoRepetitions()
_avatarAddress.Derive("world_ids"),
List.Empty.Add(worldId.Serialize()));

var allRuneState = state.GetRuneState(_avatarAddress, out _);
if (!allRuneState.TryGetRuneState(30001, out _))
{
allRuneState.AddRuneState(new RuneState(30001));
}

if (!allRuneState.TryGetRuneState(10002, out _))
{
allRuneState.AddRuneState(new RuneState(10002));
}

state = state.SetRuneState(_avatarAddress, allRuneState);

var action = new HackAndSlash
{
Costumes = costumes,
Expand Down
13 changes: 13 additions & 0 deletions .Lib9c.Tests/Action/RaidTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ int runeId2
state = state.SetLegacyState(Addresses.TableSheet.Derive(key), value.Serialize());
}

var allRuneState = state.GetRuneState(_avatarAddress, out _);
if (!allRuneState.TryGetRuneState(runeId, out _))
{
allRuneState.AddRuneState(new RuneState(runeId, 1));
}

if (!allRuneState.TryGetRuneState(runeId2, out _))
{
allRuneState.AddRuneState(new RuneState(runeId2, 1));
}

state = state.SetRuneState(_avatarAddress, allRuneState);

var gameConfigState = new GameConfigState(_sheets[nameof(GameConfigSheet)]);
var avatarState = AvatarState.Create(
_avatarAddress,
Expand Down
7 changes: 7 additions & 0 deletions .Lib9c.Tests/Action/Scenario/RuneScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ public void MigrateToRuneStateModule()
avatarState.inventory.AddItem(equipment, iLock: iLock);
}

foreach (var equipment in equipments)
{
avatarState.inventory.AddItem(equipment, iLock: null);
}

initialState = initialState.SetAvatarState(avatarAddress, avatarState);

var action = new HackAndSlash
{
Costumes = costumes,
Expand Down

0 comments on commit 8317149

Please sign in to comment.