Skip to content

Commit

Permalink
Introduce DebuffLimitSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Mar 18, 2024
1 parent 33d4ba7 commit 8b97a0d
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Action/Scenario/AuraScenarioTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ public void Arena()
enemyArenaPlayerDigest,
_tableSheets.GetArenaSimulatorSheets(),
new List<StatModifier>(),
new List<StatModifier>());
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet);
// Check player, enemy equip aura
foreach (var spawn in log.OfType<ArenaSpawnCharacter>())
{
Expand Down
13 changes: 7 additions & 6 deletions .Lib9c.Tests/Model/ArenaSimulatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public void Simulate()
{
new (StatType.DEF, StatModifier.OperationType.Add, 1),
new (StatType.HP, StatModifier.OperationType.Add, 100),
}
},
_tableSheets.DeBuffLimitSheet
);
CharacterSheet.Row row =
_tableSheets.CharacterSheet[GameConfig.DefaultAvatarCharacterId];
Expand Down Expand Up @@ -133,7 +134,7 @@ public void HpIncreasingModifier(int? modifier)
var myDigest = new ArenaPlayerDigest(_avatarState1, _arenaAvatarState1);
var enemyDigest = new ArenaPlayerDigest(_avatarState2, _arenaAvatarState2);
var arenaSheets = _tableSheets.GetArenaSimulatorSheets();
var log = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>());
var log = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>(), _tableSheets.DeBuffLimitSheet);
var expectedHpModifier = modifier ?? 2;

Assert.Equal(_random, simulator.Random);
Expand Down Expand Up @@ -178,7 +179,7 @@ public void TestSpeedModifierBySkill()
var myDigest = new ArenaPlayerDigest(_avatarState1, arenaAvatarState1);
var enemyDigest = new ArenaPlayerDigest(_avatarState2, arenaAvatarState2);
var arenaSheets = _tableSheets.GetArenaSimulatorSheets();
var unskilledLog = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>());
var unskilledLog = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>(), _tableSheets.DeBuffLimitSheet);
// foreach (var log in unskilledLog)
// {
// _testOutputHelper.WriteLine($"{log.Character.Id} :: {log}");
Expand Down Expand Up @@ -231,7 +232,7 @@ public void TestSpeedModifierBySkill()
myDigest = new ArenaPlayerDigest(_avatarState1, arenaAvatarState1);
enemyDigest = new ArenaPlayerDigest(_avatarState2, arenaAvatarState2);
arenaSheets = _tableSheets.GetArenaSimulatorSheets();
var skilledLog = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>());
var skilledLog = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>(), _tableSheets.DeBuffLimitSheet);
// foreach (var log in skilledLog)
// {
// _testOutputHelper.WriteLine($"{log.Character.Id} :: {log}");
Expand Down Expand Up @@ -273,7 +274,7 @@ public void Thorns()
var myDigest = new ArenaPlayerDigest(avatarState1, arenaAvatarState1);
var enemyDigest = new ArenaPlayerDigest(avatarState2, arenaAvatarState2);
var arenaSheets = _tableSheets.GetArenaSimulatorSheets();
var log = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>(), true);
var log = simulator.Simulate(myDigest, enemyDigest, arenaSheets, new List<StatModifier>(), new List<StatModifier>(), _tableSheets.DeBuffLimitSheet, true);
var ticks = log.Events
.OfType<ArenaTickDamage>()
.ToList();
Expand Down Expand Up @@ -335,7 +336,7 @@ public void Bleed()
var enemyDigest = new ArenaPlayerDigest(avatarState2, arenaAvatarState2);
enemyDigest.Runes.Add(rune);
var arenaSheets = _tableSheets.GetArenaSimulatorSheets();
var log = simulator.Simulate(myDigest, enemyDigest, arenaSheets, modifiers, modifiers, true);
var log = simulator.Simulate(myDigest, enemyDigest, arenaSheets, modifiers, modifiers, _tableSheets.DeBuffLimitSheet, true);
var spawns = log.Events.OfType<ArenaSpawnCharacter>().ToList();
Assert.All(spawns, spawn => Assert.Equal(totalAtk, spawn.Character.ATK));
var ticks = log.Events
Expand Down
3 changes: 2 additions & 1 deletion .Lib9c.Tests/Model/BattleLogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void IsClearBeforeSimulate()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
Assert.False(simulator.Log.IsClear);
}
Expand Down
35 changes: 35 additions & 0 deletions .Lib9c.Tests/Model/CharacterStatsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Lib9c.Tests.Model
{
using Nekoyume;
using Nekoyume.Model.Buff;
using Nekoyume.Model.Stat;
using Nekoyume.TableData;
using Xunit;

public class CharacterStatsTest
{
private readonly TableSheets _tableSheets;

public CharacterStatsTest()
{
_tableSheets = new TableSheets(TableSheetsImporter.ImportSheets());
}

[Fact]
public void DeBuffLimit()
{
var stats =
new CharacterStats(
_tableSheets.CharacterSheet[GameConfig.DefaultAvatarCharacterId],
1);
var deBuffLimitSheet = new DeBuffLimitSheet();
deBuffLimitSheet.Set("id,stat_type,percentage\n1,DEF,-50");
var def = stats.DEF;
var deBuff = new StatBuff(_tableSheets.StatBuffSheet[503012]);
stats.AddBuff(deBuff, deBuffLimitSheet: deBuffLimitSheet);
var limitModifier =
new StatModifier(StatType.DEF, StatModifier.OperationType.Percentage, -50);
Assert.Equal(limitModifier.GetModifiedAll(def), stats.DEF);
}
}
}
95 changes: 45 additions & 50 deletions .Lib9c.Tests/Model/PlayerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void TickAlive()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
var enemy = new Enemy(player, _tableSheets.CharacterSheet.Values.First(), 1);
Expand Down Expand Up @@ -95,7 +96,8 @@ public void TickDead()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
var enemy = new Enemy(player, _tableSheets.CharacterSheet.Values.First(), 1);
Expand Down Expand Up @@ -146,7 +148,8 @@ public void UseDoubleAttack(SkillCategory skillCategory)
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;

Expand Down Expand Up @@ -197,7 +200,8 @@ public void UseAuraSkill()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
new DeBuffLimitSheet()
);
var player = simulator.Player;
var enemy = new Enemy(player, _tableSheets.CharacterSheet.Values.First(), 1);
Expand Down Expand Up @@ -252,7 +256,8 @@ public void UseAuraBuffWithFood()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
new DeBuffLimitSheet()
);
var player = simulator.Player;
var enemy = new Enemy(player, _tableSheets.CharacterSheet.Values.First(), 1);
Expand Down Expand Up @@ -380,7 +385,8 @@ public void GetExpV3(int nextLevel, bool log)
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
Assert.Empty(player.eventMap);
Expand Down Expand Up @@ -459,7 +465,8 @@ public void GetStun()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
var enemy = new Enemy(player, _tableSheets.CharacterSheet.Values.First(), 1);
Expand Down Expand Up @@ -528,7 +535,8 @@ public void GiveStun()
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var skill = SkillFactory.Get(_tableSheets.SkillSheet[700004], 0, 100, 0, StatType.NONE);
skill.CustomField = new SkillCustomField { BuffDuration = 2 };
Expand Down Expand Up @@ -611,7 +619,8 @@ public void Vampiric(int duration, int percent)
_random,
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
var enemy = new Enemy(
Expand Down Expand Up @@ -687,59 +696,45 @@ public void StatsLayerTest()
_tableSheets.CostumeStatSheet.Values.First(r => r.StatType == StatType.ATK);
var costumeId = costumeStatRow.CostumeId;
var costume = ItemFactory.CreateCostume(_tableSheets.CostumeItemSheet[costumeId], Guid.NewGuid());
costume.equipped = true;
_avatarState.inventory.AddItem(costume);
// costume.equipped = true;
// _avatarState.inventory.AddItem(costume);
var foodRow =
_tableSheets.ConsumableItemSheet.Values.First(r =>
r.Stats.Any(s => s.StatType == StatType.ATK));
var food = (Consumable)ItemFactory.CreateItem(foodRow, _random);
_avatarState.inventory.AddItem(food);

// Update equipment stats
var player = new Player(
_avatarState,
_tableSheets.CharacterSheet,
_tableSheets.CharacterLevelSheet,
_tableSheets.EquipmentItemSetEffectSheet
);
Assert.Equal(player.ATK, player.Stats.BaseATK + player.Stats.EquipmentStats.ATK);
// BaseAtk 20, EquipmentStats 1
// Assert.Equal(21, player.ATK);
var equipmentLayerAtk = player.ATK;

// Update consumable stats
player.Use(new List<Guid>
{
food.ItemId,
});
Assert.Equal(player.ATK, equipmentLayerAtk + food.Stats.Where(s => s.StatType == StatType.ATK).Sum(s => s.BaseValueAsLong));
// ConsumableStats 18
// Assert.Equal(39, player.ATK);
var consumableLayerAtk = player.ATK;

// Update rune stat
var runeId = 10002;
var runeState = new RuneState(runeId);
runeState.LevelUp();
Assert.Equal(1, runeState.Level);

var runeStates = new List<RuneState>
{
runeState,
};
player.SetRuneStats(runeStates, _tableSheets.RuneOptionSheet);
var runeOptionRow = _tableSheets.RuneOptionSheet.Values.First(r => r.RuneId == runeId);
var runeAtk = runeOptionRow.LevelOptionMap[1].Stats.Sum(r => r.stat.BaseValueAsLong);
Assert.Equal(player.ATK, consumableLayerAtk + runeAtk);
// RuneStats 235
// Assert.Equal(274, player.ATK);
var runeLayerAtk = player.ATK;

// Update costume stats
player.SetCostumeStat(_tableSheets.CostumeStatSheet);
Assert.Equal(player.ATK, runeLayerAtk + costumeStatRow.Stat);
// CostumeStats 1829
// Assert.Equal(2103, player.ATK);
var simulator = new StageSimulator(
_random,
_avatarState,
new List<Guid>()
{
food.ItemId,
},
runeStates,
new List<Nekoyume.Model.Skill.Skill>(),
1,
1,
_tableSheets.StageSheet[1],
_tableSheets.StageWaveSheet[1],
false,
20,
_tableSheets.GetSimulatorSheets(),
_tableSheets.EnemySkillSheet,
new CostumeStatSheet(),
new List<ItemBase>(),
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
var costumeLayerAtk = player.ATK;

// Update collection stat
Expand Down Expand Up @@ -808,7 +803,7 @@ public void StatsLayerTest()
var addBuffAtk = addBuffModifier.GetModifiedValue(costumeLayerAtk);
Assert.Equal(10, addBuffAtk);

player.Stats.SetBuffs(statBuffs);
player.Stats.SetBuffs(statBuffs, _tableSheets.DeBuffLimitSheet);
Assert.Equal(player.ATK, collectionLayerAtk + addBuffAtk + percentageBuffAtk);
// 20 + 1 + 18 + 1829 + 235 + 100 + 1662
// Assert.Equal(3865, player.ATK);
Expand Down Expand Up @@ -912,7 +907,7 @@ public void IncreaseHpForArena()
statBuffs.Add(percentageBuff);
var percentageModifier = percentageBuff.GetModifier();
var percentageBuffAtk = (long)percentageModifier.GetModifiedValue(arenaHp);
player.Stats.SetBuffs(statBuffs);
player.Stats.SetBuffs(statBuffs, _tableSheets.DeBuffLimitSheet);
Assert.Equal(arenaHp + percentageBuffAtk, player.HP);
Assert.Equal(arenaHp, player.Stats.StatWithoutBuffs.HP);
}
Expand Down
9 changes: 6 additions & 3 deletions .Lib9c.Tests/Model/RaidSimulatorV3Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public void Simulate()
new List<StatModifier>
{
new (StatType.DEF, StatModifier.OperationType.Percentage, 100),
});
},
_tableSheets.DeBuffLimitSheet);
Assert.Equal(_random, simulator.Random);
Assert.Equal(simulator.Player.Stats.BaseStats.DEF * 2, simulator.Player.Stats.DEF);
Assert.Equal(simulator.Player.Stats.BaseStats.DEF, simulator.Player.Stats.CollectionStats.DEF);
Expand Down Expand Up @@ -96,7 +97,8 @@ public void TestSpeedMultiplierBySkill()
null,
_tableSheets.GetRaidSimulatorSheets(),
_tableSheets.CostumeStatSheet,
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = simulator.Player;
var unskilledLogs = simulator.Simulate();
Expand Down Expand Up @@ -136,7 +138,8 @@ public void TestSpeedMultiplierBySkill()
null,
_tableSheets.GetRaidSimulatorSheets(),
_tableSheets.CostumeStatSheet,
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
player = simulator.Player;
var skilledLogs = simulator.Simulate();
Expand Down
1 change: 1 addition & 0 deletions .Lib9c.Tests/Model/Skill/DoubleAttackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bool copyCharacter
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet,
copyCharacter
);
var player = new Player(avatarState, simulator)
Expand Down
7 changes: 5 additions & 2 deletions .Lib9c.Tests/Model/Skill/NormalAttackTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void Use(bool copyCharacter)
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet,
copyCharacter
);
var player = new Player(avatarState, simulator);
Expand Down Expand Up @@ -130,7 +131,8 @@ public void FocusSkill()
new TestRandom(seed),
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
var player = new Player(avatarState, simulator);

Expand Down Expand Up @@ -178,7 +180,8 @@ public void FocusSkill()
new TestRandom(seed),
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>()
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet
);
player = new Player(avatarState, simulator);
player.AddBuff(new Focus(_tableSheets.ActionBuffSheet.OrderedList.First(s => s.ActionBuffType == ActionBuffType.Focus)));
Expand Down
1 change: 1 addition & 0 deletions .Lib9c.Tests/Model/Skill/ShatterStrikeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void Use(int enemyHp, int ratioBp, bool expectedEnemyDead, bool copyChara
_tableSheets.StageSheet[1],
_tableSheets.MaterialItemSheet),
new List<StatModifier>(),
_tableSheets.DeBuffLimitSheet,
copyCharacter,
shatterStrikeMaxDamage: gameConfigState.ShatterStrikeMaxDamage
);
Expand Down
Loading

0 comments on commit 8b97a0d

Please sign in to comment.