Skip to content

Commit

Permalink
Revert "Remove 🧹 HackAndSlash3"
Browse files Browse the repository at this point in the history
  • Loading branch information
sonohoshi authored Mar 13, 2024
1 parent 9c378d9 commit 1b82b33
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 32 deletions.
39 changes: 15 additions & 24 deletions .Lib9c.Tests/Action/Scenario/WorldUnlockScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ namespace Lib9c.Tests.Action.Scenario
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Libplanet.Action.State;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Nekoyume;
using Nekoyume.Action;
using Nekoyume.Model;
Expand Down Expand Up @@ -35,13 +35,12 @@ public WorldUnlockScenarioTest()

_avatarAddress = _agentAddress.Derive("avatar");
_rankingMapAddress = _avatarAddress.Derive("ranking_map");
var gameConfigState = new GameConfigState(sheets[nameof(GameConfigSheet)]);
var avatarState = new AvatarState(
_avatarAddress,
_agentAddress,
0,
_tableSheets.GetAvatarSheets(),
gameConfigState,
new GameConfigState(sheets[nameof(GameConfigSheet)]),
_rankingMapAddress
)
{
Expand All @@ -51,18 +50,11 @@ public WorldUnlockScenarioTest()

_weeklyArenaState = new WeeklyArenaState(0);

#pragma warning disable CS0618
// Use of obsolete method Currency.Legacy(): https://github.com/planetarium/lib9c/discussions/1319
var currency = Currency.Legacy("NCG", 2, null);
#pragma warning restore CS0618
var goldCurrencyState = new GoldCurrencyState(currency);
_initialState = new World(new MockWorldState())
.SetLegacyState(Addresses.GoldCurrency, goldCurrencyState.Serialize())
.SetLegacyState(_weeklyArenaState.address, _weeklyArenaState.Serialize())
.SetAgentState(_agentAddress, agentState)
.SetAvatarState(_avatarAddress, avatarState)
.SetLegacyState(_rankingMapAddress, new RankingMapState(_rankingMapAddress).Serialize())
.SetLegacyState(gameConfigState.address, gameConfigState.Serialize());
.SetLegacyState(_rankingMapAddress, new RankingMapState(_rankingMapAddress).Serialize());

foreach (var (key, value) in sheets)
{
Expand Down Expand Up @@ -98,27 +90,25 @@ public void UnlockWorldByHackAndSlashAfterPatchTableWithAddRow(
var doomfist = Doomfist.GetOne(_tableSheets, avatarState.level, ItemSubType.Weapon);
avatarState.inventory.AddItem(doomfist);

var nextState = _initialState
.SetAvatarState(_avatarAddress, avatarState)
.SetLegacyState(
_avatarAddress.Derive("world_ids"),
new Bencodex.Types.List(Enumerable.Range(1, worldIdToClear).Select(i => i.Serialize())));
var hackAndSlash = new HackAndSlash
var nextState = _initialState.SetAvatarState(_avatarAddress, avatarState);
var hackAndSlash = new HackAndSlash3
{
WorldId = worldIdToClear,
StageId = stageIdToClear,
AvatarAddress = _avatarAddress,
Costumes = new List<Guid>(),
Equipments = new List<Guid> { doomfist.NonFungibleId },
Foods = new List<Guid>(),
RuneInfos = new List<RuneSlotInfo>(),
worldId = worldIdToClear,
stageId = stageIdToClear,
avatarAddress = _avatarAddress,
costumes = new List<int>(),
equipments = new List<Guid> { doomfist.NonFungibleId },
foods = new List<Guid>(),
WeeklyArenaAddress = _weeklyArenaState.address,
RankingMapAddress = _rankingMapAddress,
};
nextState = hackAndSlash.Execute(new ActionContext
{
PreviousState = nextState,
Signer = _agentAddress,
RandomSeed = 0,
});
Assert.True(hackAndSlash.Result.IsClear);

avatarState = nextState.GetAvatarState(_avatarAddress);
Assert.True(avatarState.worldInformation.IsStageCleared(stageIdToClear));
Expand Down Expand Up @@ -159,6 +149,7 @@ public void UnlockWorldByHackAndSlashAfterPatchTableWithAddRow(
Signer = _agentAddress,
RandomSeed = 0,
});
Assert.True(hackAndSlash.Result.IsClear);

avatarState = nextState.GetAvatarState(_avatarAddress);
Assert.True(avatarState.worldInformation.IsWorldUnlocked(worldIdToUnlock));
Expand Down
19 changes: 11 additions & 8 deletions Lib9c/Action/HackAndSlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,17 @@ public IWorld Execute(
sw.Restart();
if (simulator.Log.IsClear)
{
avatarState.worldInformation.ClearStage(
WorldId,
StageId,
blockIndex,
worldSheet,
worldUnlockSheet
);
stageCleared = true;
if (!stageCleared)
{
avatarState.worldInformation.ClearStage(
WorldId,
StageId,
blockIndex,
worldSheet,
worldUnlockSheet
);
stageCleared = true;
}
sw.Stop();
Log.Verbose("{AddressesHex} {Source} HAS {Process} from #{BlockIndex}: {Elapsed}",
addressesHex, source, "ClearStage", blockIndex, sw.Elapsed.TotalMilliseconds);
Expand Down
Loading

0 comments on commit 1b82b33

Please sign in to comment.