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

Skill updates for world 8 #2454

Merged
merged 21 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .Lib9c.Tests/Model/Skill/Arena/ArenaShatterStrikeTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace Lib9c.Tests.Model.Skill.Arena
{
using System;
using System.Collections.Generic;
using System.Linq;
using Bencodex.Types;
using Lib9c.Tests.Action;
using Nekoyume.Arena;
using Nekoyume.Model;
Expand Down Expand Up @@ -46,13 +48,15 @@ public ArenaShatterStrikeTest()

[Theory]
// 1bp == 0.01%
[InlineData(10000)]
[InlineData(1000)]
[InlineData(3700)]
[InlineData(100000)]
public void Use(int ratioBp)
[InlineData(2, 1000, false)]
[InlineData(2, 3700, false)]
[InlineData(2, 100_000, true)]
[InlineData(100_000, 100_000, false)]
public void Use(int hpModifier, int ratioBp, bool expectedEnemyDead)
{
var simulator = new ArenaSimulator(new TestRandom());
var gameConfigState =
new GameConfigState((Text)_tableSheets.GameConfigSheet.Serialize());
var simulator = new ArenaSimulator(new TestRandom(), hpModifier: hpModifier);
var myDigest = new ArenaPlayerDigest(_avatar1, _arenaAvatar1);
var enemyDigest = new ArenaPlayerDigest(_avatar2, _arenaAvatar2);
var arenaSheets = _tableSheets.GetArenaSimulatorSheets();
Expand All @@ -78,13 +82,14 @@ public void Use(int ratioBp)
var used = shatterStrike.Use(challenger, enemy, simulator.Turn, new List<Buff>());
Assert.Single(used.SkillInfos);
Assert.Equal(
(long)(enemy.HP * ratioBp / 10000m) - enemy.DEF + challenger.ArmorPenetration,
Math.Clamp(
enemy.HP * ratioBp / 10000m - enemy.DEF + challenger.ArmorPenetration,
1,
gameConfigState.ShatterStrikeMaxDamage
),
used.SkillInfos.First().Effect
);
if (ratioBp > 10000)
{
Assert.True(enemy.IsDead);
}
Assert.Equal(expectedEnemyDead, enemy.IsDead);
}
}
}
39 changes: 25 additions & 14 deletions .Lib9c.Tests/Model/Skill/ShatterStrikeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Lib9c.Tests.Model.Skill
using System;
using System.Collections.Generic;
using System.Linq;
using Bencodex.Types;
using Lib9c.Tests.Action;
using Libplanet.Crypto;
using Nekoyume.Battle;
Expand All @@ -19,16 +20,20 @@ public class ShatterStrikeTest

[Theory]
// 1bp == 0.01%
[InlineData(10000, true)]
[InlineData(10000, false)]
[InlineData(1000, true)]
[InlineData(1000, false)]
[InlineData(3700, true)]
[InlineData(3700, false)]
[InlineData(100000, true)]
[InlineData(100000, false)]
public void Use(int ratioBp, bool copyCharacter)
[InlineData(100, 10000, false, true)]
[InlineData(100, 10000, false, false)]
[InlineData(100, 1000, false, true)]
[InlineData(100, 1000, false, false)]
[InlineData(100, 3700, false, true)]
[InlineData(100, 3700, false, false)]
[InlineData(100, 100_000, true, true)]
[InlineData(100, 100_000, true, false)]
[InlineData(1_000_000, 100_000, false, true)]
[InlineData(1_000_000, 100_000, false, false)]
public void Use(int enemyHp, int ratioBp, bool expectedEnemyDead, bool copyCharacter)
{
var gameConfigState =
new GameConfigState((Text)_tableSheets.GameConfigSheet.Serialize());
Assert.True(
_tableSheets.SkillSheet.TryGetValue(700011, out var skillRow)
); // 700011 is ShatterStrike
Expand Down Expand Up @@ -71,6 +76,11 @@ public void Use(int ratioBp, bool copyCharacter)
var player = new Player(avatarState, simulator);
var enemyRow = _tableSheets.CharacterSheet.OrderedList
.FirstOrDefault(e => e.Id > 200000);
enemyRow.Set(new[]
{
"201000", "XS", "2", enemyHp.ToString(), "16", "6", "4", "90", "15", "3.2", "0.64",
"0.24", "0", "3.6", "0.6", "0.8", "1.2",
});
Assert.NotNull(enemyRow);

var enemy = new Enemy(player, enemyRow, 1);
Expand All @@ -80,13 +90,14 @@ public void Use(int ratioBp, bool copyCharacter)
Assert.NotNull(used);
var skillInfo = Assert.Single(used.SkillInfos);
Assert.Equal(
(long)(enemy.HP * ratioBp / 10000m) - enemy.DEF + player.ArmorPenetration,
Math.Clamp(
enemy.HP * ratioBp / 10000m - enemy.DEF + player.ArmorPenetration,
1,
gameConfigState.ShatterStrikeMaxDamage
),
skillInfo.Effect
);
if (ratioBp > 10000)
{
Assert.True(skillInfo.IsDead);
}
Assert.Equal(expectedEnemyDead, skillInfo.IsDead);
}
}
}
15 changes: 10 additions & 5 deletions .Lib9c.Tests/TableSheets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public SimulatorSheets GetSimulatorSheets()
CharacterSheet,
CharacterLevelSheet,
EquipmentItemSetEffectSheet,
RuneOptionSheet
RuneOptionSheet,
GameConfigSheet
);
}

Expand Down Expand Up @@ -319,7 +320,8 @@ public StageSimulatorSheets GetStageSimulatorSheets()
StageSheet,
StageWaveSheet,
EnemySkillSheet,
RuneOptionSheet
RuneOptionSheet,
GameConfigSheet
);
}

Expand Down Expand Up @@ -370,7 +372,8 @@ public RankingSimulatorSheets GetRankingSimulatorSheets()
CharacterLevelSheet,
EquipmentItemSetEffectSheet,
WeeklyArenaRewardSheet,
RuneOptionSheet
RuneOptionSheet,
GameConfigSheet
);
}

Expand Down Expand Up @@ -405,7 +408,8 @@ public ArenaSimulatorSheets GetArenaSimulatorSheets()
EquipmentItemSetEffectSheet,
CostumeStatSheet,
WeeklyArenaRewardSheet,
RuneOptionSheet
RuneOptionSheet,
GameConfigSheet
);
}

Expand Down Expand Up @@ -446,7 +450,8 @@ public RaidSimulatorSheets GetRaidSimulatorSheets()
WorldBossBattleRewardSheet,
RuneWeightSheet,
RuneSheet,
RuneOptionSheet
RuneOptionSheet,
GameConfigSheet
);
}

Expand Down
3 changes: 2 additions & 1 deletion Lib9c/Action/BattleArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ public override IWorld Execute(IActionContext context)
}
for (var i = 0; i < ticket; i++)
{
var simulator = new ArenaSimulator(random, HpIncreasingModifier);
var simulator = new ArenaSimulator(random, HpIncreasingModifier,
gameConfigState.ShatterStrikeMaxDamage);
var log = simulator.Simulate(
myArenaPlayerDigest,
enemyArenaPlayerDigest,
Expand Down
8 changes: 7 additions & 1 deletion Lib9c/Arena/ArenaSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ public class ArenaSimulator : IArenaSimulator
public ArenaLog Log { get; private set; }
public int HpModifier { get; }

public ArenaSimulator(IRandom random, int hpModifier = 2)
public long ShatterStrikeMaxDamage { get; private set; }

public ArenaSimulator(IRandom random,
int hpModifier = 2,
long shatterStrikeMaxDamage = 400_000 // 400K is initial limit of ShatterStrike. Use this as default.
)
{
Random = random;
Turn = 1;
HpModifier = hpModifier;
ShatterStrikeMaxDamage = shatterStrikeMaxDamage;
}

public ArenaLog Simulate(
Expand Down
52 changes: 38 additions & 14 deletions Lib9c/Battle/Simulator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Bencodex.Types;
using Libplanet.Action;
using Nekoyume.Model;
using Nekoyume.Model.BattleStatus;
Expand Down Expand Up @@ -30,8 +31,7 @@ public abstract class Simulator : ISimulator
public readonly CharacterLevelSheet CharacterLevelSheet;
public readonly EquipmentItemSetEffectSheet EquipmentItemSetEffectSheet;

public readonly List<int> StatDebuffList;
public readonly List<int> ActionDebuffList;
public long ShatterStrikeMaxDamage { get; private set; }

protected const int MaxTurn = 200;
public int TurnNumber;
Expand All @@ -48,6 +48,18 @@ protected Simulator(IRandom random,
LogEvent = logEvent;
}

protected Simulator(IRandom random,
AvatarState avatarState,
List<Guid> foods,
SimulatorSheets simulatorSheets, bool logEvent = true)
: this(random, new Player(avatarState, simulatorSheets), foods, simulatorSheets)
{
LogEvent = logEvent;
ShatterStrikeMaxDamage =
new GameConfigState((Text)simulatorSheets.GameConiConfigSheet.Serialize())
U-lis marked this conversation as resolved.
Show resolved Hide resolved
.ShatterStrikeMaxDamage;
}

protected Simulator(
IRandom random,
Player player,
Expand All @@ -65,18 +77,30 @@ SimulatorSheetsV1 simulatorSheets
CharacterSheet = simulatorSheets.CharacterSheet;
CharacterLevelSheet = simulatorSheets.CharacterLevelSheet;
EquipmentItemSetEffectSheet = simulatorSheets.EquipmentItemSetEffectSheet;
var debuffSkillIdList = SkillSheet.Values
.Where(s => s.SkillType == SkillType.Debuff).Select(s => s.Id);
StatDebuffList = SkillBuffSheet.Values.Where(
bf => debuffSkillIdList.Contains(bf.SkillId)).Aggregate(
new List<int>(),
(current, bf) => current.Concat(bf.BuffIds).ToList()
);
ActionDebuffList = SkillActionBuffSheet.Values.Where(
bf => debuffSkillIdList.Contains(bf.SkillId)).Aggregate(
new List<int>(),
(current, bf) => current.Concat(bf.BuffIds).ToList()
);
Log = new BattleLog();
player.Simulator = this;
Player = player;
Player.Use(foods);
Player.ResetCurrentHP();
}

protected Simulator(
IRandom random,
Player player,
List<Guid> foods,
SimulatorSheets simulatorSheets
)
{
Random = random;
MaterialItemSheet = simulatorSheets.MaterialItemSheet;
SkillSheet = simulatorSheets.SkillSheet;
SkillBuffSheet = simulatorSheets.SkillBuffSheet;
StatBuffSheet = simulatorSheets.StatBuffSheet;
SkillActionBuffSheet = simulatorSheets.SkillActionBuffSheet;
ActionBuffSheet = simulatorSheets.ActionBuffSheet;
CharacterSheet = simulatorSheets.CharacterSheet;
CharacterLevelSheet = simulatorSheets.CharacterLevelSheet;
EquipmentItemSetEffectSheet = simulatorSheets.EquipmentItemSetEffectSheet;
Log = new BattleLog();
player.Simulator = this;
Player = player;
Expand Down
15 changes: 10 additions & 5 deletions Lib9c/Extensions/SheetsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ public static SimulatorSheets GetSimulatorSheets(
sheets.GetSheet<CharacterSheet>(),
sheets.GetSheet<CharacterLevelSheet>(),
sheets.GetSheet<EquipmentItemSetEffectSheet>(),
sheets.GetSheet<RuneOptionSheet>()
sheets.GetSheet<RuneOptionSheet>(),
sheets.GetSheet<GameConfigSheet>()
);
}

Expand Down Expand Up @@ -244,7 +245,8 @@ public static StageSimulatorSheets GetStageSimulatorSheets(
sheets.GetSheet<StageSheet>(),
sheets.GetSheet<StageWaveSheet>(),
sheets.GetSheet<EnemySkillSheet>(),
sheets.GetSheet<RuneOptionSheet>()
sheets.GetSheet<RuneOptionSheet>(),
sheets.GetSheet<GameConfigSheet>()
);
}

Expand Down Expand Up @@ -296,7 +298,8 @@ public static RankingSimulatorSheets GetRankingSimulatorSheets(
sheets.GetSheet<CharacterLevelSheet>(),
sheets.GetSheet<EquipmentItemSetEffectSheet>(),
sheets.GetSheet<WeeklyArenaRewardSheet>(),
sheets.GetSheet<RuneOptionSheet>()
sheets.GetSheet<RuneOptionSheet>(),
sheets.GetSheet<GameConfigSheet>()
);
}

Expand Down Expand Up @@ -348,7 +351,8 @@ public static ArenaSimulatorSheets GetArenaSimulatorSheets(
sheets.GetSheet<EquipmentItemSetEffectSheet>(),
sheets.GetSheet<CostumeStatSheet>(),
sheets.GetSheet<WeeklyArenaRewardSheet>(),
sheets.GetSheet<RuneOptionSheet>()
sheets.GetSheet<RuneOptionSheet>(),
sheets.GetSheet<GameConfigSheet>()
);
}

Expand Down Expand Up @@ -407,7 +411,8 @@ public static RaidSimulatorSheets GetRaidSimulatorSheets(
sheets.GetSheet<WorldBossBattleRewardSheet>(),
sheets.GetSheet<RuneWeightSheet>(),
sheets.GetSheet<RuneSheet>(),
sheets.GetSheet<RuneOptionSheet>()
sheets.GetSheet<RuneOptionSheet>(),
sheets.GetSheet<GameConfigSheet>()
);
}

Expand Down
20 changes: 0 additions & 20 deletions Lib9c/Model/Character/ArenaCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class ArenaCharacter : ICloneable
private readonly ActionBuffSheet _actionBuffSheet;
private readonly ArenaSkills _skills;

private readonly List<int> _statDebuffList;
private readonly List<int> _actionDebuffList;

public readonly IArenaSimulator Simulator;
public readonly ArenaSkills _runeSkills = new ArenaSkills();
public readonly Dictionary<int, int> RuneSkillCooldownMap = new Dictionary<int, int>();
Expand Down Expand Up @@ -144,20 +141,6 @@ public ArenaCharacter(
_skillActionBuffSheet = sheets.SkillActionBuffSheet;
_actionBuffSheet = sheets.ActionBuffSheet;

var debuffSkillIdList = _skillSheet.Values
.Where(s => s.SkillType == SkillType.Debuff).Select(s => s.Id);
_statDebuffList = _skillBuffSheet.Values.Where(
bf => debuffSkillIdList.Contains(bf.SkillId)).Aggregate(
new List<int>(),
(current, bf) => current.Concat(bf.BuffIds).ToList()
);
_actionDebuffList = _skillActionBuffSheet.Values.Where(
bf => debuffSkillIdList.Contains(bf.SkillId)).Aggregate(
new List<int>(),
(current, bf) => current.Concat(bf.BuffIds).ToList()
);


Simulator = simulator;
Stats = GetStatV1(
digest,
Expand Down Expand Up @@ -238,9 +221,6 @@ private ArenaCharacter(ArenaCharacter value)
_skillActionBuffSheet = value._skillActionBuffSheet;
_actionBuffSheet = value._actionBuffSheet;

_statDebuffList = value._statDebuffList;
_actionDebuffList = value._actionDebuffList;

Simulator = value.Simulator;
Stats = new CharacterStats(value.Stats);
_skills = value._skills;
Expand Down
9 changes: 9 additions & 0 deletions Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Nekoyume.Arena;
using Nekoyume.Battle;
using Nekoyume.Model.Elemental;
using Nekoyume.Model.Stat;
Expand Down Expand Up @@ -60,6 +61,14 @@ protected ArenaAttackSkill(
damage = Math.Max(damage - finalDEF, 1);
// Apply damage reduce
damage = (int)((damage - target.DRV) * (1 - target.DRR / 10000m));

// ShatterStrike has max damage limitation
if (SkillRow.SkillCategory is SkillCategory.ShatterStrike)
{
damage = Math.Clamp(damage,
1, ((ArenaSimulator)caster.Simulator).ShatterStrikeMaxDamage);
U-lis marked this conversation as resolved.
Show resolved Hide resolved
}

target.CurrentHP -= damage;

// double attack must be shown as critical attack
Expand Down
Loading
Loading