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

Add check slot logic #3091

Merged
15 changes: 1 addition & 14 deletions .Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ Type exc
: new ItemSlotState(BattleType.Adventure);
Assert.True(itemSlotState.Equipments.Count == 0);

var previousAvatarState = _initialState.GetAvatarState(TesterAvatarAddress);
var equipments = Doomfist.GetAllParts(TableSheets, previousAvatarState.level);
foreach (var equipment in equipments)
{
previousAvatarState.inventory.AddItem(equipment);
}

var expectedItemRewards = new List<(int, int)>();
var expectedFavRewards = new List<(int, int)>();
var firstRewardSheet = TableSheets.AdventureBossFloorFirstRewardSheet;
Expand Down Expand Up @@ -254,7 +247,7 @@ Type exc
Season = 1,
AvatarAddress = TesterAvatarAddress,
Costumes = new List<Guid>(),
Equipments = equipments.Select(e => e.NonFungibleId).ToList(),
Equipments = new List<Guid>(),
Foods = new List<Guid>(),
RuneInfos = new List<RuneSlotInfo>(),
};
Expand Down Expand Up @@ -335,12 +328,6 @@ out var items
Assert.True(
amount * currency <= state.GetBalance(TesterAvatarAddress, currency));
}

itemSlotState =
state.TryGetLegacyState(itemSlotStateAddress, out rawItemSlotState)
? new ItemSlotState(rawItemSlotState)
: new ItemSlotState(BattleType.Adventure);
Assert.True(itemSlotState.Equipments.Count > 0);
}
}

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
33 changes: 20 additions & 13 deletions .Lib9c.Tests/Action/HackAndSlashTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,12 @@ public HackAndSlashTest()
}

[Theory]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, false, true)]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, true, true)]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, true)]
[InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, true)]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false, false)]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true, false)]
[InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false, false)]
public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock, bool isClearedBefore)
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 2, true)]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, true)]
[InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, true)]
[InlineData(GameConfig.RequireCharacterLevel.CharacterFullCostumeSlot, 1, 1, false)]
[InlineData(200, 1, GameConfig.RequireClearedStageLevel.ActionsInRankingBoard, false)]
public void Execute(int avatarLevel, int worldId, int stageId, bool isClearedBefore)
{
Assert.True(_tableSheets.WorldSheet.TryGetValue(worldId, out var worldRow));
Assert.True(stageId >= worldRow.StageBegin);
Expand Down Expand Up @@ -145,10 +143,7 @@ public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock
var equipments = Doomfist.GetAllParts(_tableSheets, previousAvatarState.level);
foreach (var equipment in equipments)
{
var iLock = equipment.ItemSubType == ItemSubType.Weapon && isWeaponLock
? new OrderLock(Guid.NewGuid())
: (ILock)null;
previousAvatarState.inventory.AddItem(equipment, iLock: iLock);
previousAvatarState.inventory.AddItem(equipment, iLock: null);
}

var mailEquipmentRow = _tableSheets.EquipmentItemSheet.Values.First();
Expand Down Expand Up @@ -198,7 +193,6 @@ public void Execute(int avatarLevel, int worldId, int stageId, bool isWeaponLock

Assert.True(nextAvatarState.worldInformation.IsStageCleared(stageId));
Assert.Equal(30, nextAvatarState.mailBox.Count);
Assert.Equal(!isWeaponLock, nextAvatarState.inventory.Equipments.OfType<Weapon>().Any(w => w.equipped));
}

[Theory]
Expand Down Expand Up @@ -1571,6 +1565,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
6 changes: 6 additions & 0 deletions Lib9c/Action/AdventureBoss/ExploreAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ public override IWorld Execute(IActionContext context)
states = states.SetRuneState(AvatarAddress, runeStates);
}

// just validate
foreach (var runeSlotInfo in RuneInfos)
{
runeStates.GetRuneState(runeSlotInfo.RuneId);
}

var collectionExist =
states.TryGetCollectionState(AvatarAddress, out var collectionState) &&
collectionState.Ids.Any();
Expand Down
6 changes: 6 additions & 0 deletions Lib9c/Action/EventDungeonBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ is Bencodex.Types.List serializedEventDungeonInfoList
states = states.SetRuneState(AvatarAddress, runeStates);
}

// just validate
foreach (var runeSlotInfo in RuneInfos)
{
runeStates.GetRuneState(runeSlotInfo.RuneId);
}

var random = context.GetRandom();
var collectionModifiers = new List<StatModifier>();
if (collectionExist)
Expand Down
6 changes: 6 additions & 0 deletions Lib9c/Action/HackAndSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,12 @@ public IWorld Execute(
states = states.SetRuneState(AvatarAddress, runeStates);
}

// just validate
foreach (var runeSlotInfo in RuneInfos)
{
runeStates.GetRuneState(runeSlotInfo.RuneId);
}

slotstateActivity?.Dispose();
sw.Stop();
Log.Verbose("{AddressesHex} {Source} HAS {Process} from #{BlockIndex}: {Elapsed}",
Expand Down
6 changes: 6 additions & 0 deletions Lib9c/Action/HackAndSlashSweep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ public override IWorld Execute(IActionContext context)
states = states.SetRuneState(avatarAddress, runeStates);
}

// just validate
foreach (var runeSlotInfo in runeInfos)
{
runeStates.GetRuneState(runeSlotInfo.RuneId);
}

var equippedRune = new List<RuneState>();
foreach (var runeInfo in runeSlotState.GetEquippedRuneSlotInfos())
{
Expand Down
6 changes: 6 additions & 0 deletions Lib9c/Action/Raid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ public override IWorld Execute(IActionContext context)
states = states.SetRuneState(AvatarAddress, runeStates);
}

// just validate
foreach (var runeSlotInfo in RuneInfos)
{
runeStates.GetRuneState(runeSlotInfo.RuneId);
}

var collectionModifiers = new List<StatModifier>();
if (collectionExist)
{
Expand Down
6 changes: 3 additions & 3 deletions Lib9c/Model/State/AvatarState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public void ValidateEquipments(List<Guid> equipmentIds, long blockIndex)
{
if (!inventory.TryGetNonFungibleItem(itemId, out ItemUsable outNonFungibleItem))
{
continue;
throw new ItemDoesNotExistException($"Equipment {itemId} does not exist.");
}

var equipment = (Equipment) outNonFungibleItem;
Expand Down Expand Up @@ -673,7 +673,7 @@ public List<Equipment> ValidateEquipmentsV2(List<Guid> equipmentIds, long blockI
{
if (!inventory.TryGetNonFungibleItem(itemId, out ItemUsable outNonFungibleItem))
{
continue;
throw new ItemDoesNotExistException($"Equipment {itemId} does not exist.");
}

var equipment = (Equipment)outNonFungibleItem;
Expand Down Expand Up @@ -755,7 +755,7 @@ public List<Equipment> ValidateEquipmentsV3(List<Guid> equipmentIds, long blockI
{
if (!inventory.TryGetNonFungibleItem(itemId, out ItemUsable outNonFungibleItem))
{
continue;
throw new ItemDoesNotExistException($"Equipment {itemId} does not exist.");
}

var equipment = (Equipment)outNonFungibleItem;
Expand Down
3 changes: 1 addition & 2 deletions Lib9c/Model/State/RuneSlotState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Nekoyume.Action;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Rune;
using Nekoyume.TableData;
using Nekoyume.TableData.Rune;

namespace Nekoyume.Model.State
Expand All @@ -18,7 +17,7 @@ public static Address DeriveAddress(Address avatarAddress, BattleType battleType

public BattleType BattleType { get; }

private readonly List<RuneSlot> _slots = new List<RuneSlot>();
private readonly List<RuneSlot> _slots = new();

public RuneSlotState(BattleType battleType)
{
Expand Down
Loading