Skip to content

Commit

Permalink
Merge pull request #2431 from planetarium/release/1.9.2
Browse files Browse the repository at this point in the history
Divide SetRuneStats, RuneSkills for fix rune skill
  • Loading branch information
ipdae authored Feb 29, 2024
2 parents ff2c8ae + 4bca541 commit 04d6656
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 27 deletions.
67 changes: 67 additions & 0 deletions .Lib9c.Tests/Model/ArenaSimulatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,72 @@ public void Thorns()
Assert.True(challengerTick.Character.HP > enemyTick.Character.HP);
Assert.True(enemyTick.SkillInfos.First().Effect > challengerTick.SkillInfos.First().Effect);
}

[Fact]
public void Bleed()
{
var random = new TestRandom();
var avatarState1 = _avatarState1;
var avatarState2 = _avatarState2;

var arenaAvatarState1 = new ArenaAvatarState(avatarState1);
var arenaAvatarState2 = new ArenaAvatarState(avatarState2);

var characterRow = _tableSheets.CharacterSheet[GameConfig.DefaultAvatarCharacterId];
var stats = characterRow.ToStats(avatarState1.level);
var totalAtk = 141138;
var baseAtk = stats.ATK;
var runeOptionSheet = _tableSheets.RuneOptionSheet;
var runeRow = runeOptionSheet[10003];
var rune = new RuneState(10003);
while (rune.Level < 89)
{
rune.LevelUp();
}

var optionInfo = runeRow.LevelOptionMap[89];
var statModifiers = new List<StatModifier>();
statModifiers.AddRange(
optionInfo.Stats.Select(x =>
new StatModifier(
x.stat.StatType,
x.operationType,
x.stat.TotalValueAsLong)));
foreach (var modifier in statModifiers)
{
if (modifier.StatType == StatType.ATK)
{
baseAtk += modifier.Value;
}
}

// Add collection modifier without level stats, rune stats
var collectionModifier = new StatModifier(StatType.ATK, StatModifier.OperationType.Add, totalAtk - baseAtk);
var modifiers = new List<StatModifier>
{
collectionModifier,
new (StatType.HP, StatModifier.OperationType.Add, totalAtk * 10),
};

var simulator = new ArenaSimulator(random);
var myDigest = new ArenaPlayerDigest(avatarState1, arenaAvatarState1);
myDigest.Runes.Add(rune);
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 spawns = log.Events.OfType<ArenaSpawnCharacter>().ToList();
Assert.All(spawns, spawn => Assert.Equal(totalAtk, spawn.Character.ATK));
var ticks = log.Events
.OfType<ArenaTickDamage>()
.ToList();
var challengerTick = ticks.First(r => !r.Character.IsEnemy);
var enemyTick = ticks.First(r => r.Character.IsEnemy);
var challengerInfo = challengerTick.SkillInfos.First();
var enemyInfo = enemyTick.SkillInfos.First();
var dmg = (int)decimal.Round(totalAtk * optionInfo.SkillValue);
Assert.Equal(dmg, challengerInfo.Effect);
Assert.Equal(dmg, enemyInfo.Effect);
}
}
}
4 changes: 2 additions & 2 deletions .Lib9c.Tests/Model/PlayerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ public void StatsLayerTest()
{
runeState,
};
player.SetRune(runeStates, _tableSheets.RuneOptionSheet, _tableSheets.SkillSheet);
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);
Expand Down Expand Up @@ -866,7 +866,7 @@ public void IncreaseHpForArena()
{
runeState,
};
player.SetRune(runeStates, _tableSheets.RuneOptionSheet, _tableSheets.SkillSheet);
player.SetRuneStats(runeStates, _tableSheets.RuneOptionSheet);
var runeOptionRow = _tableSheets.RuneOptionSheet.Values.First(r => r.RuneId == runeId);
var runeHp = runeOptionRow.LevelOptionMap[1].Stats.Sum(r => r.stat.BaseValueAsLong);
Assert.Equal(consumableLayerHp + runeHp, player.HP);
Expand Down
12 changes: 4 additions & 8 deletions Lib9c/Arena/ArenaSimulatorV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,15 @@ private static SimplePriorityQueue<ArenaCharacter, decimal> SpawnPlayers(
var challenger = new ArenaCharacter(simulator, challengerDigest, simulatorSheets);
if (challengerDigest.Runes != null)
{
challenger.SetRune(
challengerDigest.Runes,
simulatorSheets.RuneOptionSheet,
simulatorSheets.SkillSheet);
challenger.SetRuneStats(challengerDigest.Runes, simulatorSheets.RuneOptionSheet);
challenger.SetRuneSkills(challengerDigest.Runes, simulatorSheets.RuneOptionSheet, simulatorSheets.SkillSheet);
}

var enemy = new ArenaCharacter(simulator, enemyDigest, simulatorSheets, true);
if (enemyDigest.Runes != null)
{
enemy.SetRune(
enemyDigest.Runes,
simulatorSheets.RuneOptionSheet,
simulatorSheets.SkillSheet);
enemy.SetRuneStats(enemyDigest.Runes, simulatorSheets.RuneOptionSheet);
enemy.SetRuneSkills(enemyDigest.Runes, simulatorSheets.RuneOptionSheet, simulatorSheets.SkillSheet);
}

challenger.Spawn(enemy);
Expand Down
10 changes: 9 additions & 1 deletion Lib9c/Battle/RaidSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ public RaidSimulator(
CostumeStatSheet costumeStatSheet,
List<StatModifier> collectionModifiers) : base(random, avatarState, foods, simulatorSheets)
{
Player.ConfigureStats(costumeStatSheet, runeStates, simulatorSheets.RuneOptionSheet, simulatorSheets.SkillSheet, collectionModifiers);
var runeOptionSheet = simulatorSheets.RuneOptionSheet;
var skillSheet = simulatorSheets.SkillSheet;
Player.ConfigureStats(costumeStatSheet, runeStates, runeOptionSheet, skillSheet,
collectionModifiers);
if (runeStates is not null)
{
// call SetRuneSkills last. because rune skills affect from total calculated stats
Player.SetRuneSkills(runeStates, runeOptionSheet, skillSheet);
}

BossId = bossId;
_waves = new List<RaidBoss>();
Expand Down
10 changes: 9 additions & 1 deletion Lib9c/Battle/StageSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public StageSimulator(IRandom random,
simulatorSheets,
logEvent)
{
Player.ConfigureStats(costumeStatSheet, runeStates, simulatorSheets.RuneOptionSheet, simulatorSheets.SkillSheet, collectionModifiers);
var runeOptionSheet = simulatorSheets.RuneOptionSheet;
var skillSheet = simulatorSheets.SkillSheet;
Player.ConfigureStats(costumeStatSheet, runeStates, runeOptionSheet, skillSheet,
collectionModifiers);
if (runeStates is not null)
{
// call SetRuneSkills last. because rune skills affect from total calculated stats
Player.SetRuneSkills(runeStates, runeOptionSheet, skillSheet);
}

_waves = new List<Wave>();
_waveRewards = waveRewards;
Expand Down
37 changes: 27 additions & 10 deletions Lib9c/Model/Character/ArenaCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,21 @@ public ArenaCharacter(
hpModifier);
_skills = GetSkills(digest.Equipments, sheets.SkillSheet);
_attackCountMax = AttackCountHelper.GetCountMax(digest.Level);
if (digest.Runes != null)

var runes = digest.Runes;
var runeOptionSheet = sheets.RuneOptionSheet;
bool runeExist = runes != null;
if (runeExist)
{
SetRune(
digest.Runes,
sheets.RuneOptionSheet,
sheets.SkillSheet);
SetRuneStats(runes, runeOptionSheet);
}

Stats.SetCollections(collectionModifiers);
ResetCurrentHP();
if (runeExist)
{
// call SetRuneSkills last. because rune skills affect from total calculated stats
SetRuneSkills(runes, runeOptionSheet, sheets.SkillSheet);
}
}

private ArenaCharacter(ArenaCharacter value)
Expand Down Expand Up @@ -443,10 +448,7 @@ public void SetRuneV2(
}
}

public void SetRune(
List<RuneState> runes,
RuneOptionSheet runeOptionSheet,
SkillSheet skillSheet)
public void SetRuneStats(List<RuneState> runes, RuneOptionSheet runeOptionSheet)
{
foreach (var rune in runes)
{
Expand All @@ -465,6 +467,21 @@ public void SetRune(
x.stat.TotalValueAsLong)));
Stats.AddRune(statModifiers);
ResetCurrentHP();
}
}

public void SetRuneSkills(
List<RuneState> runes,
RuneOptionSheet runeOptionSheet,
SkillSheet skillSheet)
{
foreach (var rune in runes)
{
if (!runeOptionSheet.TryGetValue(rune.RuneId, out var optionRow) ||
!optionRow.LevelOptionMap.TryGetValue(rune.Level, out var optionInfo))
{
continue;
}

if (optionInfo.SkillId == default ||
!skillSheet.TryGetValue(optionInfo.SkillId, out var skillRow))
Expand Down
32 changes: 27 additions & 5 deletions Lib9c/Model/Character/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,12 @@ public void SetCostumeStat(CostumeStatSheet costumeStatSheet)
ResetCurrentHP();
}

public void SetRune(
List<RuneState> runes,
RuneOptionSheet runeOptionSheet,
SkillSheet skillSheet)
/// <summary>
/// Sets the rune stats for a player character.
/// </summary>
/// <param name="runes">The list of rune states for the player character.</param>
/// <param name="runeOptionSheet">The rune option sheet that contains information about rune options.</param>
public void SetRuneStats(List<RuneState> runes, RuneOptionSheet runeOptionSheet)
{
foreach (var rune in runes)
{
Expand All @@ -573,6 +575,26 @@ public void SetRune(

Stats.AddRuneStat(optionInfo);
ResetCurrentHP();
}
}

/// <summary>
/// Sets the rune skills for the player.
/// </summary>
/// <param name="runes">The list of rune states.</param>
/// <param name="runeOptionSheet">The rune option sheet.</param>
/// <param name="skillSheet">The skill sheet.</param>
public void SetRuneSkills(
List<RuneState> runes,
RuneOptionSheet runeOptionSheet,
SkillSheet skillSheet)
{
foreach (var rune in runes)
{
if (!runeOptionSheet.TryGetOptionInfo(rune.RuneId, rune.Level, out var optionInfo))
{
continue;
}

if (optionInfo.SkillId == default ||
!skillSheet.TryGetValue(optionInfo.SkillId, out var skillRow))
Expand Down Expand Up @@ -615,7 +637,7 @@ public void ConfigureStats(CostumeStatSheet costumeStatSheet, List<RuneState> ru
SetCostumeStat(costumeStatSheet);
if (runeStates != null)
{
SetRune(runeStates, runeOptionSheet, skillSheet);
SetRuneStats(runeStates, runeOptionSheet);
}

SetCollections(collectionModifiers);
Expand Down

0 comments on commit 04d6656

Please sign in to comment.