Skip to content

Commit

Permalink
Merge branch 'feature/adventure-boss' into feature/adv-boss/apply-review
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Jun 19, 2024
2 parents 1d777e0 + ce48094 commit bd1d8f7
Show file tree
Hide file tree
Showing 32 changed files with 674 additions and 262 deletions.
73 changes: 44 additions & 29 deletions .Lib9c.Tests/Action/AdventureBoss/ClaimAdventureBossRewardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public class ClaimAdventureBossRewardTest

private readonly IWorld _initialState = new World(MockUtil.MockModernWorldState)
.SetLegacyState(Addresses.GoldCurrency, new GoldCurrencyState(NCG).Serialize())
.SetLegacyState(
GameConfigState.Address,
new GameConfigState(Sheets["GameConfigSheet"]).Serialize()
)
.SetAvatarState(WantedAvatarAddress, WantedAvatarState)
.SetAgentState(WantedAddress, WantedState)
.SetAvatarState(ExplorerAvatarAddress, ExplorerAvatarState)
Expand Down Expand Up @@ -118,14 +122,14 @@ public static IEnumerable<object[]> GetWantedTestData()
NcgReward = 0 * NCG, // No Wanted Raffle
ItemReward = new Dictionary<int, int>
{
{ 600201, 240 },
{ 600201, 168 },
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 14 },
},
},
};
Expand All @@ -139,15 +143,15 @@ public static IEnumerable<object[]> GetWantedTestData()
ItemReward = new Dictionary<int, int>
{
{
600201, 240
}, // (200*1.2) * 0.7 / 0.5 * (120/240) + (200*1.2) * 0.3 / 0.5 * (120/240)
600201, 168
}, // (200*1.2) * 0.7 / 0.5 * (120/240)
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 14 }, // (200*1.2) * 0.3 / 2.5 * (120/240)
},
},
};
Expand All @@ -161,15 +165,15 @@ public static IEnumerable<object[]> GetWantedTestData()
ItemReward = new Dictionary<int, int>
{
{
600201, 200
}, // (300*1.2) * 0.7 / 0.5 * (100/360) + (300*1.2) * 0.2 / 0.5 * (100/360)
600201, 140
}, // (300*1.2) * 0.7 / 0.5 * (100/360)
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 12 }, // (300*1.2) * 0.3 / 2.5 * (100/360)
},
},
};
Expand All @@ -185,8 +189,8 @@ public static IEnumerable<object[]> GetExploreTestData()
ItemReward = new Dictionary<int, int>
{
{ 600201, 0 },
{ 600202, 67 },
{ 600203, 0 }, // 100 AP / 7.5 ratio * 100% contribution
{ 600202, 67 }, // 100AP / 1.5 ratio * 100% contribution
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
Expand Down Expand Up @@ -275,14 +279,14 @@ public static IEnumerable<object[]> GetPrevRewardTestData()
NcgReward = 0 * NCG, // No NCG Reward
ItemReward = new Dictionary<int, int>
{
{ 600201, 240 },
{ 600201, 168 },
{ 600202, 0 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 14 },
},
},
};
Expand Down Expand Up @@ -312,14 +316,14 @@ public static IEnumerable<object[]> GetPrevRewardTestData()
NcgReward = 20 * NCG,
ItemReward = new Dictionary<int, int>
{
{ 600201, 240 },
{ 600201, 168 },
{ 600202, 67 },
{ 600203, 0 },
},
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 14 },
},
},
};
Expand Down Expand Up @@ -430,11 +434,11 @@ public void WantedMultipleSeason()
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 28 },
},
ItemReward = new Dictionary<int, int>
{
{ 600201, 480 },
{ 600201, 336 },
{ 600202, 0 },
{ 600203, 0 },
},
Expand Down Expand Up @@ -557,13 +561,15 @@ FungibleAssetValue expectedRemainingNcg
// Explore : just add data to avoid explore reward
// Manipulate used AP Potion to calculate reward above zero
var board = state.GetExploreBoard(1);
var lst = state.GetExplorerList(1);
var exp = state.TryGetExplorer(1, TesterAvatarAddress, out var e)
? e
: new Explorer(TesterAvatarAddress, TesterAvatarState.name);
board.ExplorerList.Add((TesterAvatarAddress, TesterAvatarState.name));
lst.Explorers.Add((TesterAvatarAddress, TesterAvatarState.name));
board.UsedApPotion += 100;
board.ExplorerCount += 1;
exp.UsedApPotion += 100;
state = state.SetExploreBoard(1, board).SetExplorer(1, exp);
state = state.SetExploreBoard(1, board).SetExplorerList(1, lst).SetExplorer(1, exp);

var materialSheet = state.GetSheet<MaterialItemSheet>();
var materialRow =
Expand Down Expand Up @@ -593,9 +599,11 @@ FungibleAssetValue expectedRemainingNcg
// Manipulate used AP Potion to calculate reward above zero
board = state.GetExploreBoard(1);
board.UsedApPotion += 99;
lst = state.GetExplorerList(1);
lst.AddExplorer(ExplorerAvatarAddress, ExplorerAvatarState.name);
exp = state.GetExplorer(1, ExplorerAvatarAddress);
exp.UsedApPotion += 99;
state = state.SetExploreBoard(1, board).SetExplorer(1, exp);
state = state.SetExploreBoard(1, board).SetExplorerList(1, lst).SetExplorer(1, exp);
}

// Burn all remaining NCG to make test easier
Expand Down Expand Up @@ -633,6 +641,9 @@ FungibleAssetValue expectedRemainingNcg

var seasonBountyBoardAddress =
Addresses.BountyBoard.Derive(AdventureBossHelper.GetSeasonAsAddressForm(1));
var explorerList = resultState.GetExplorerList(1);
Assert.Equal(anotherExplorerCount == 0 ? 1 : 2, explorerList.Explorers.Count);
Assert.Equal(exploreBoard.ExplorerCount, explorerList.Explorers.Count);
Assert.Equal((int)(bounty * 0.05) * NCG, exploreBoard.RaffleReward);
Assert.Equal(
expectedRemainingNcg,
Expand Down Expand Up @@ -711,13 +722,14 @@ public void ExploreMultipleSeason()

// Manipulate used AP Potion to calculate reward above zero
var board = state.GetExploreBoard(1);
board.ExplorerList.Add((TesterAvatarAddress, TesterAvatarState.name));
var lst = state.GetExplorerList(1);
lst.Explorers.Add((TesterAvatarAddress, TesterAvatarState.name));
board.UsedApPotion += 100;
var exp = state.TryGetExplorer(1, TesterAvatarAddress, out var e)
? e
: new Explorer(TesterAvatarAddress, TesterAvatarState.name);
exp.UsedApPotion += 100;
state = state.SetExploreBoard(1, board).SetExplorer(1, exp);
state = state.SetExploreBoard(1, board).SetExplorerList(1, lst).SetExplorer(1, exp);

// No Explore
state = new Wanted
Expand Down Expand Up @@ -749,13 +761,13 @@ public void ExploreMultipleSeason()

// Manipulate used AP Potion to calculate reward above zero
board = state.GetExploreBoard(3);
board.ExplorerList.Add((TesterAvatarAddress, TesterAvatarState.name));
lst.Explorers.Add((TesterAvatarAddress, TesterAvatarState.name));
board.UsedApPotion += 100;
exp = state.TryGetExplorer(3, TesterAvatarAddress, out e)
? e
: new Explorer(TesterAvatarAddress, TesterAvatarState.name);
exp.UsedApPotion += 100;
state = state.SetExploreBoard(3, board).SetExplorer(3, exp);
state = state.SetExploreBoard(3, board).SetExplorerList(3, lst).SetExplorer(3, exp);

// Burn remaining NCG
state = state.BurnAsset(
Expand Down Expand Up @@ -800,11 +812,11 @@ public void AllReward()
FavReward = new Dictionary<int, int>
{
{ 20001, 0 },
{ 30001, 0 },
{ 30001, 14 },
},
ItemReward = new Dictionary<int, int>
{
{ 600201, 240 },
{ 600201, 168 },
{ 600202, 67 },
{ 600203, 0 },
},
Expand Down Expand Up @@ -834,13 +846,14 @@ public void AllReward()
// Explore : just add data to avoid explore reward
// Manipulate used AP Potion to calculate reward above zero
var board = state.GetExploreBoard(1);
var lst = state.GetExplorerList(1);
board.UsedApPotion += 100;
board.ExplorerList.Add((TesterAvatarAddress, TesterAvatarState.name));
lst.Explorers.Add((TesterAvatarAddress, TesterAvatarState.name));
var exp = state.TryGetExplorer(1, TesterAvatarAddress, out var e)
? e
: new Explorer(TesterAvatarAddress, TesterAvatarState.name);
exp.UsedApPotion += 100;
state = state.SetExploreBoard(1, board).SetExplorer(1, exp);
state = state.SetExploreBoard(1, board).SetExplorerList(1, lst).SetExplorer(1, exp);

// Burn
state = state.BurnAsset(
Expand Down Expand Up @@ -902,8 +915,9 @@ AdventureBossGameData.ClaimableReward expectedReward
// Explore : just add data to avoid explore reward
// Manipulate used AP Potion to calculate reward above zero
var board = state.GetExploreBoard(1);
var lst = state.GetExplorerList(1);
board.UsedApPotion += 100;
board.ExplorerList.Add(explore
lst.Explorers.Add(explore
? (TesterAvatarAddress, TesterAvatarState.name)
: (ExplorerAvatarAddress, ExplorerAvatarState.name));
var exp =
Expand All @@ -916,7 +930,8 @@ AdventureBossGameData.ClaimableReward expectedReward
explore ? TesterAvatarState.name : ExplorerAvatarState.name
);
exp.UsedApPotion += 100;
state = state.SetExploreBoard(1, board).SetExplorer(1, exp);
state = state.SetExploreBoard(1, board).SetExplorerList(1, lst).SetExplorerList(1, lst)
.SetExplorer(1, exp);

// Next Season
state = new Wanted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public class ExploreAdventureBossTest

private readonly IWorld _initialState = new World(MockUtil.MockModernWorldState)
.SetLegacyState(Addresses.GoldCurrency, new GoldCurrencyState(NCG).Serialize())
.SetLegacyState(
GameConfigState.Address,
new GameConfigState(Sheets["GameConfigSheet"]).Serialize()
)
.SetAvatarState(WantedAvatarAddress, WantedAvatarState)
.SetAgentState(WantedAddress, WantedState)
.SetAvatarState(TesterAvatarAddress, TesterAvatarState)
Expand Down Expand Up @@ -193,7 +197,7 @@ public void Execute(
{
Season = 1,
AvatarAddress = WantedAvatarAddress,
Bounty = Wanted.MinBounty * NCG,
Bounty = gameConfigState.AdventureBossMinBounty * NCG,
}.Execute(new ActionContext
{
PreviousState = state,
Expand Down
12 changes: 10 additions & 2 deletions .Lib9c.Tests/Action/AdventureBoss/SweepAdventureBossTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Lib9c.Tests.Action.AdventureBoss
using Nekoyume.Model.State;
using Nekoyume.Module;
using Nekoyume.TableData;
using Nekoyume.TableData.AdventureBoss;
using Xunit;

public class SweepAdventureBossTest
Expand Down Expand Up @@ -68,6 +69,10 @@ public class SweepAdventureBossTest

private readonly IWorld _initialState = new World(MockUtil.MockModernWorldState)
.SetLegacyState(Addresses.GoldCurrency, new GoldCurrencyState(NCG).Serialize())
.SetLegacyState(
GameConfigState.Address,
new GameConfigState(Sheets["GameConfigSheet"]).Serialize()
)
.SetAvatarState(WantedAvatarAddress, WantedAvatarState)
.SetAgentState(WantedAddress, WantedState)
.SetAvatarState(TesterAvatarAddress, TesterAvatarState)
Expand Down Expand Up @@ -136,7 +141,7 @@ public void Execute(
{
Season = 1,
AvatarAddress = WantedAvatarAddress,
Bounty = Wanted.MinBounty * NCG,
Bounty = gameConfigState.AdventureBossMinBounty * NCG,
}.Execute(new ActionContext
{
PreviousState = state,
Expand Down Expand Up @@ -191,13 +196,16 @@ public void Execute(
Assert.Equal(expectedPotion, potion!.count);
}

var unitSweepAp = state.GetSheet<AdventureBossSheet>().OrderedList
.First(row => row.BossId == state.GetLatestAdventureBossSeason().BossId)
.SweepAp;
var exploreBoard = state.GetExploreBoard(1);
var explorer = state.GetExplorer(1, TesterAvatarAddress);
Assert.True(explorer.Score > 0);
Assert.True(exploreBoard.TotalPoint > 0);
Assert.Equal(explorer.Score, exploreBoard.TotalPoint);
Assert.Equal(floor, explorer.Floor);
Assert.Equal(floor * SweepAdventureBoss.UnitApPotion, exploreBoard.UsedApPotion);
Assert.Equal(floor * unitSweepAp, exploreBoard.UsedApPotion);
Assert.Equal(explorer.UsedApPotion, exploreBoard.UsedApPotion);

inventory = state.GetInventoryV2(TesterAvatarAddress);
Expand Down
14 changes: 11 additions & 3 deletions .Lib9c.Tests/Action/AdventureBoss/UnlockFloorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class UnlockFloorTest
private static readonly Dictionary<string, string> Sheets =
TableSheetsImporter.ImportSheets();

private static readonly TableSheets TableSheets = new TableSheets(Sheets);
private static readonly TableSheets TableSheets = new (Sheets);
#pragma warning disable CS0618
// Use of obsolete method Currency.Legacy(): https://github.com/planetarium/lib9c/discussions/1419
private static readonly Currency NCG = Currency.Legacy("NCG", 2, null);
Expand Down Expand Up @@ -66,6 +66,10 @@ public class UnlockFloorTest

private readonly IWorld _initialState = new World(MockUtil.MockModernWorldState)
.SetLegacyState(Addresses.GoldCurrency, new GoldCurrencyState(NCG).Serialize())
.SetLegacyState(
GameConfigState.Address,
new GameConfigState(Sheets["GameConfigSheet"]).Serialize()
)
.SetAvatarState(WantedAvatarAddress, WantedAvatarState)
.SetAgentState(WantedAddress, WantedState)
.SetAvatarState(TesterAvatarAddress, TesterAvatarState)
Expand Down Expand Up @@ -117,7 +121,7 @@ public void Execute(bool useNcg, bool notEnough, int startFloor, int expectedFlo
{
Season = 1,
AvatarAddress = WantedAvatarAddress,
Bounty = Wanted.MinBounty * NCG,
Bounty = gameConfigState.AdventureBossMinBounty * NCG,
}.Execute(new ActionContext
{
PreviousState = state,
Expand All @@ -141,6 +145,7 @@ public void Execute(bool useNcg, bool notEnough, int startFloor, int expectedFlo
Signer = TesterAddress,
BlockIndex = 1L,
});

// Make all floors cleared
var explorer = state.GetExplorer(1, TesterAvatarAddress);
explorer.MaxFloor = startFloor;
Expand Down Expand Up @@ -183,7 +188,10 @@ public void Execute(bool useNcg, bool notEnough, int startFloor, int expectedFlo
Assert.Null(inventory.Items.FirstOrDefault(i => i.item.Id == 600202));
}

Assert.Equal(expectedFloor, resultState.GetExplorer(1, TesterAvatarAddress).MaxFloor);
Assert.Equal(
expectedFloor,
resultState.GetExplorer(1, TesterAvatarAddress).MaxFloor
);
}
}

Expand Down
Loading

0 comments on commit bd1d8f7

Please sign in to comment.