Skip to content

Commit

Permalink
Merge pull request #2780 from moreal/avatar-state
Browse files Browse the repository at this point in the history
Refactor `AvatarState` constructor
  • Loading branch information
moreal authored Sep 4, 2024
2 parents 776c911 + 48a0c14 commit 65ef35b
Show file tree
Hide file tree
Showing 92 changed files with 526 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .Lib9c.DevExtensions.Tests/Action/FaucetRuneTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public FaucetRuneTest(ITestOutputHelper outputHelper)
Address agentAddress = new PrivateKey().Address;
_avatarAddress = new PrivateKey().Address;
var agentState = new AgentState(agentAddress);
var avatarState = new AvatarState(
var avatarState = AvatarState.Create(
_avatarAddress,
agentAddress,
0,
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/AccountStateDeltaExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public AccountStateDeltaExtensionsTest()
_agentState = new AgentState(_agentAddress);
_agentState.avatarAddresses[0] = _avatarAddress;
_tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
_avatarState = new AvatarState(
_avatarState = AvatarState.Create(
_avatarAddress,
_agentAddress,
0,
Expand Down
2 changes: 1 addition & 1 deletion .Lib9c.Tests/Action/AccountStateViewExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AccountStateViewExtensionsTest()
_agentState = new AgentState(_agentAddress);
_agentState.avatarAddresses[0] = _avatarAddress;
_tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
_avatarState = new AvatarState(
_avatarState = AvatarState.Create(
_avatarAddress,
_agentAddress,
0,
Expand Down
9 changes: 4 additions & 5 deletions .Lib9c.Tests/Action/ActivateCollectionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ public ActivateCollectionTest()

_avatarAddress = _agentAddress.Derive("avatar");
var gameConfigState = new GameConfigState(sheets[nameof(GameConfigSheet)]);
var avatarState = new AvatarState(
var avatarState = AvatarState.Create(
_avatarAddress,
_agentAddress,
0,
_tableSheets.GetAvatarSheets(),
default
)
{
level = 100,
};
);
avatarState.level = 100;

agentState.avatarAddresses.Add(0, _avatarAddress);

_initialState = new World(MockUtil.MockModernWorldState)
Expand Down
30 changes: 21 additions & 9 deletions .Lib9c.Tests/Action/AdventureBoss/ClaimAdventureBossRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ public class ClaimAdventureBossRewardTest
private static readonly Address WantedAvatarAddress =
Addresses.GetAvatarAddress(WantedAddress, 0);

private static readonly AvatarState WantedAvatarState = new (
WantedAvatarAddress, WantedAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "wanted"
private static readonly AvatarState WantedAvatarState = AvatarState.Create(
WantedAvatarAddress,
WantedAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "wanted"
);

private static readonly AgentState WantedState = new (WantedAddress)
Expand All @@ -58,9 +62,13 @@ public class ClaimAdventureBossRewardTest
private static readonly Address ExplorerAvatarAddress =
Addresses.GetAvatarAddress(ExplorerAddress, 0);

private static readonly AvatarState ExplorerAvatarState = new (
ExplorerAvatarAddress, ExplorerAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "explorer"
private static readonly AvatarState ExplorerAvatarState = AvatarState.Create(
ExplorerAvatarAddress,
ExplorerAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "explorer"
);

private static readonly AgentState ExplorerState = new (ExplorerAddress)
Expand All @@ -78,9 +86,13 @@ public class ClaimAdventureBossRewardTest
private static readonly Address TesterAvatarAddress =
Addresses.GetAvatarAddress(TesterAddress, 0);

private static readonly AvatarState TesterAvatarState = new (
TesterAvatarAddress, TesterAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "Tester"
private static readonly AvatarState TesterAvatarState = AvatarState.Create(
TesterAvatarAddress,
TesterAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "Tester"
);

private static readonly AgentState TesterState = new (TesterAddress)
Expand Down
27 changes: 20 additions & 7 deletions .Lib9c.Tests/Action/AdventureBoss/ExploreAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ public class ExploreAdventureBossTest
private static readonly Address WantedAvatarAddress =
Addresses.GetAvatarAddress(WantedAddress, 0);

private static readonly AvatarState WantedAvatarState = new (
WantedAvatarAddress, WantedAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "wanted"
private static readonly AvatarState WantedAvatarState = AvatarState.Create(
WantedAvatarAddress,
WantedAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "wanted"
);

private static readonly AgentState WantedState = new (WantedAddress)
Expand All @@ -55,10 +59,14 @@ public class ExploreAdventureBossTest
private static readonly Address TesterAvatarAddress =
Addresses.GetAvatarAddress(TesterAddress, 0);

private static readonly AvatarState TesterAvatarState = new (
TesterAvatarAddress, TesterAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "Tester"
) { level = 500 };
private static readonly AvatarState TesterAvatarState = AvatarState.Create(
TesterAvatarAddress,
TesterAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "Tester"
);

private static readonly AgentState TesterState = new (TesterAddress)
{
Expand All @@ -80,6 +88,11 @@ public class ExploreAdventureBossTest
.SetAgentState(TesterAddress, TesterState)
.MintAsset(new ActionContext(), WantedAddress, 1_000_000 * NCG);

static ExploreAdventureBossTest()
{
TesterAvatarState.level = 500;
}

public ExploreAdventureBossTest()
{
var collectionSheet = TableSheets.CollectionSheet;
Expand Down
20 changes: 14 additions & 6 deletions .Lib9c.Tests/Action/AdventureBoss/SweepAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ public class SweepAdventureBossTest
private static readonly Address WantedAvatarAddress =
Addresses.GetAvatarAddress(WantedAddress, 0);

private static readonly AvatarState WantedAvatarState = new (
WantedAvatarAddress, WantedAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "wanted"
private static readonly AvatarState WantedAvatarState = AvatarState.Create(
WantedAvatarAddress,
WantedAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "wanted"
);

private static readonly AgentState WantedState = new (WantedAddress)
Expand All @@ -54,9 +58,13 @@ public class SweepAdventureBossTest
private static readonly Address TesterAvatarAddress =
Addresses.GetAvatarAddress(TesterAddress, 0);

private static readonly AvatarState TesterAvatarState = new (
TesterAvatarAddress, TesterAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "Tester"
private static readonly AvatarState TesterAvatarState = AvatarState.Create(
TesterAvatarAddress,
TesterAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "Tester"
);

private static readonly AgentState TesterState = new (TesterAddress)
Expand Down
20 changes: 14 additions & 6 deletions .Lib9c.Tests/Action/AdventureBoss/UnlockFloorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ public class UnlockFloorTest
private static readonly Address WantedAvatarAddress =
Addresses.GetAvatarAddress(WantedAddress, 0);

private static readonly AvatarState WantedAvatarState = new (
WantedAvatarAddress, WantedAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "wanted"
private static readonly AvatarState WantedAvatarState = AvatarState.Create(
WantedAvatarAddress,
WantedAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "wanted"
);

private static readonly AgentState WantedState = new (WantedAddress)
Expand All @@ -52,9 +56,13 @@ public class UnlockFloorTest
private static readonly Address TesterAvatarAddress =
Addresses.GetAvatarAddress(TesterAddress, 0);

private static readonly AvatarState TesterAvatarState = new (
TesterAvatarAddress, TesterAddress, 0L, TableSheets.GetAvatarSheets(),
new PrivateKey().Address, name: "Tester"
private static readonly AvatarState TesterAvatarState = AvatarState.Create(
TesterAvatarAddress,
TesterAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "Tester"
);

private static readonly AgentState TesterState = new (TesterAddress)
Expand Down
14 changes: 10 additions & 4 deletions .Lib9c.Tests/Action/AdventureBoss/WantedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ public class WantedTest
private static readonly Address AgentAddress = new PrivateKey().Address;
private static readonly Address AvatarAddress = Addresses.GetAvatarAddress(AgentAddress, 0);

private static readonly AvatarState AvatarState = new (
AvatarAddress, AgentAddress, 0L, TableSheets.GetAvatarSheets(),
private static readonly AvatarState AvatarState = AvatarState.Create(
AvatarAddress,
AgentAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "avatar1"
);

private static readonly Address
AvatarAddress2 = Addresses.GetAvatarAddress(AgentAddress, 1);

private static readonly AvatarState AvatarState2 = new (
AvatarAddress2, AgentAddress, 0L, TableSheets.GetAvatarSheets(),
private static readonly AvatarState AvatarState2 = AvatarState.Create(
AvatarAddress2,
AgentAddress,
0L,
TableSheets.GetAvatarSheets(),
new PrivateKey().Address,
name: "avatar2"
);
Expand Down
15 changes: 7 additions & 8 deletions .Lib9c.Tests/Action/ArenahelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,17 @@ public static (AgentState AgentState, AvatarState AvatarState) GetAgentStateWith
var agentState = new AgentState(agentAddress);

var avatarAddress = agentAddress.Derive("avatar");
var avatarState = new AvatarState(
var avatarState = AvatarState.Create(
avatarAddress,
agentAddress,
0,
tableSheets.GetAvatarSheets(),
rankingMapAddress)
{
worldInformation = new WorldInformation(
0,
tableSheets.WorldSheet,
clearStageId),
};
rankingMapAddress);
avatarState.worldInformation = new WorldInformation(
0,
tableSheets.WorldSheet,
clearStageId);

agentState.avatarAddresses.Add(0, avatarAddress);

return (agentState, avatarState);
Expand Down
15 changes: 7 additions & 8 deletions .Lib9c.Tests/Action/BattleArenaTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,18 +1061,17 @@ private static (AgentState AgentState, AvatarState AvatarState) GetAgentStateWit
var agentState = new AgentState(agentAddress);

var avatarAddress = agentAddress.Derive("avatar");
var avatarState = new AvatarState(
var avatarState = AvatarState.Create(
avatarAddress,
agentAddress,
0,
tableSheets.GetAvatarSheets(),
rankingMapAddress)
{
worldInformation = new WorldInformation(
0,
tableSheets.WorldSheet,
clearStageId),
};
rankingMapAddress);
avatarState.worldInformation = new WorldInformation(
0,
tableSheets.WorldSheet,
clearStageId);

agentState.avatarAddresses.Add(0, avatarAddress);

return (agentState, avatarState);
Expand Down
30 changes: 14 additions & 16 deletions .Lib9c.Tests/Action/BuyMultipleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ public BuyMultipleTest(ITestOutputHelper outputHelper)
var buyerAgentState = new AgentState(_buyerAgentAddress);
_buyerAvatarAddress = new PrivateKey().Address;
var rankingMapAddress = new PrivateKey().Address;
_buyerAvatarState = new AvatarState(
_buyerAvatarState = AvatarState.Create(
_buyerAvatarAddress,
_buyerAgentAddress,
0,
_tableSheets.GetAvatarSheets(),
rankingMapAddress)
{
worldInformation = new WorldInformation(
0,
_tableSheets.WorldSheet,
GameConfig.RequireClearedStageLevel.ActionsInShop),
};
rankingMapAddress);
_buyerAvatarState.worldInformation = new WorldInformation(
0,
_tableSheets.WorldSheet,
GameConfig.RequireClearedStageLevel.ActionsInShop);

buyerAgentState.avatarAddresses[0] = _buyerAvatarAddress;

var shopState = new ShopState();
Expand Down Expand Up @@ -613,18 +612,17 @@ public void ExecuteThrowShopItemExpiredError()
var agentState = new AgentState(agentAddress);
var rankingMapAddress = new PrivateKey().Address;

var avatarState = new AvatarState(
var avatarState = AvatarState.Create(
avatarAddress,
agentAddress,
0,
_tableSheets.GetAvatarSheets(),
rankingMapAddress)
{
worldInformation = new WorldInformation(
0,
_tableSheets.WorldSheet,
GameConfig.RequireClearedStageLevel.ActionsInShop),
};
rankingMapAddress);
avatarState.worldInformation = new WorldInformation(
0,
_tableSheets.WorldSheet,
GameConfig.RequireClearedStageLevel.ActionsInShop);

agentState.avatarAddresses[0] = avatarAddress;
_sellerAgentStateMap[avatarState] = agentState;

Expand Down
Loading

0 comments on commit 65ef35b

Please sign in to comment.