From 20913ce7fe0ef23264f9eb68a871f37030a5a0f2 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Wed, 28 Feb 2024 14:49:38 +0900 Subject: [PATCH] Fix missing update current hp --- .Lib9c.Tests/Model/ArenaSimulatorTest.cs | 9 +++++++++ .Lib9c.Tests/Model/PlayerTest.cs | 5 ++++- Lib9c/Model/Character/ArenaCharacter.cs | 2 +- Lib9c/Model/Character/Player.cs | 8 +++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.Lib9c.Tests/Model/ArenaSimulatorTest.cs b/.Lib9c.Tests/Model/ArenaSimulatorTest.cs index e44515f03f..a321e23c24 100644 --- a/.Lib9c.Tests/Model/ArenaSimulatorTest.cs +++ b/.Lib9c.Tests/Model/ArenaSimulatorTest.cs @@ -6,6 +6,7 @@ namespace Lib9c.Tests using Lib9c.Tests.Action; using Libplanet.Action; using Libplanet.Crypto; + using Nekoyume; using Nekoyume.Action; using Nekoyume.Arena; using Nekoyume.Model; @@ -14,6 +15,7 @@ namespace Lib9c.Tests using Nekoyume.Model.Skill; using Nekoyume.Model.Stat; using Nekoyume.Model.State; + using Nekoyume.TableData; using Xunit; using Xunit.Abstractions; @@ -70,12 +72,17 @@ public void Simulate() new List { new (StatType.ATK, StatModifier.OperationType.Add, 1), + new (StatType.HP, StatModifier.OperationType.Add, 100), }, new List { new (StatType.DEF, StatModifier.OperationType.Add, 1), + new (StatType.HP, StatModifier.OperationType.Add, 100), } ); + CharacterSheet.Row row = + _tableSheets.CharacterSheet[GameConfig.DefaultAvatarCharacterId]; + var expectedHp = (new CharacterStats(row, myDigest.Level).HP + 100) * simulator.HpModifier; Assert.Equal(_random, simulator.Random); @@ -88,6 +95,8 @@ public void Simulate() { if (player.Character is ArenaCharacter arenaCharacter) { + Assert.Equal(expectedHp, arenaCharacter.HP); + Assert.Equal(expectedHp, arenaCharacter.CurrentHP); arenaCharacters.Add(arenaCharacter); } } diff --git a/.Lib9c.Tests/Model/PlayerTest.cs b/.Lib9c.Tests/Model/PlayerTest.cs index 1a609bb465..f86ab59a3d 100644 --- a/.Lib9c.Tests/Model/PlayerTest.cs +++ b/.Lib9c.Tests/Model/PlayerTest.cs @@ -873,6 +873,7 @@ public void IncreaseHpForArena() // RuneStats 520 // Assert.Equal(879, player.HP); var runeLayerHp = player.HP; + Assert.Equal(player.CurrentHP, runeLayerHp); // Update costume stats player.SetCostumeStat(_tableSheets.CostumeStatSheet); @@ -880,6 +881,7 @@ public void IncreaseHpForArena() // CostumeStats 26990 // Assert.Equal(27869, player.HP); var costumeLayerHp = player.HP; + Assert.Equal(player.CurrentHP, costumeLayerHp); // Update collection stat var modifiers = new List(); @@ -887,11 +889,12 @@ public void IncreaseHpForArena() modifiers.Add(new StatModifier(StatType.HP, StatModifier.OperationType.Percentage, 200)); modifiers.Add(addModifier); modifiers.Add(new StatModifier(StatType.HP, StatModifier.OperationType.Percentage, -100)); - player.Stats.SetCollections(modifiers); + player.SetCollections(modifiers); Assert.Equal(costumeLayerHp + addModifier.Value + costumeLayerHp, player.HP); // CollectionStats 100 + 27869(100%) // Assert.Equal(55838, player.HP); var collectionLayerHp = player.HP; + Assert.Equal(player.CurrentHP, collectionLayerHp); // Arena player.Stats.IsArenaCharacter = true; diff --git a/Lib9c/Model/Character/ArenaCharacter.cs b/Lib9c/Model/Character/ArenaCharacter.cs index 89a45c1f91..cf7233da9e 100644 --- a/Lib9c/Model/Character/ArenaCharacter.cs +++ b/Lib9c/Model/Character/ArenaCharacter.cs @@ -186,7 +186,6 @@ public ArenaCharacter( hpModifier); _skills = GetSkills(digest.Equipments, sheets.SkillSheet); _attackCountMax = AttackCountHelper.GetCountMax(digest.Level); - ResetCurrentHP(); if (digest.Runes != null) { SetRune( @@ -196,6 +195,7 @@ public ArenaCharacter( } Stats.SetCollections(collectionModifiers); + ResetCurrentHP(); } private ArenaCharacter(ArenaCharacter value) diff --git a/Lib9c/Model/Character/Player.cs b/Lib9c/Model/Character/Player.cs index 8256ae18e6..e309bba5b5 100644 --- a/Lib9c/Model/Character/Player.cs +++ b/Lib9c/Model/Character/Player.cs @@ -604,6 +604,12 @@ public void SetRune( } } + public void SetCollections(IEnumerable statModifiers) + { + Stats.SetCollections(statModifiers); + ResetCurrentHP(); + } + public void ConfigureStats(CostumeStatSheet costumeStatSheet, List runeStates, RuneOptionSheet runeOptionSheet, SkillSheet skillSheet, List collectionModifiers) { SetCostumeStat(costumeStatSheet); @@ -612,7 +618,7 @@ public void ConfigureStats(CostumeStatSheet costumeStatSheet, List ru SetRune(runeStates, runeOptionSheet, skillSheet); } - Stats.SetCollections(collectionModifiers); + SetCollections(collectionModifiers); } [Obsolete("Use SetRune")]