From 1c289177a422c383aa77b53f7c0ced00f097f18b Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 19 Mar 2024 14:14:23 +0900 Subject: [PATCH] Use buff group id instead of stat type --- .Lib9c.Tests/Model/CharacterStatsTest.cs | 17 ++++++--- Lib9c/Model/Stat/CharacterStats.cs | 46 +++++++++++++---------- Lib9c/TableCSV/Skill/DeBuffLimitSheet.csv | 12 +++--- Lib9c/TableData/Skill/DeBuffLimitSheet.cs | 20 +++++----- 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/.Lib9c.Tests/Model/CharacterStatsTest.cs b/.Lib9c.Tests/Model/CharacterStatsTest.cs index 6b14d0a97a..b6f5c45e9e 100644 --- a/.Lib9c.Tests/Model/CharacterStatsTest.cs +++ b/.Lib9c.Tests/Model/CharacterStatsTest.cs @@ -23,13 +23,20 @@ public void DeBuffLimit() _tableSheets.CharacterSheet[GameConfig.DefaultAvatarCharacterId], 1); var deBuffLimitSheet = new DeBuffLimitSheet(); - deBuffLimitSheet.Set("id,stat_type,percentage\n1,DEF,-50"); - var def = stats.DEF; + // -100% def but limit -50% stats var deBuff = new StatBuff(_tableSheets.StatBuffSheet[503012]); + var groupId = deBuff.RowData.GroupId; + deBuffLimitSheet.Set($"group_id,percentage\n{groupId},-50"); + var def = stats.DEF; stats.AddBuff(deBuff, deBuffLimitSheet: deBuffLimitSheet); - var limitModifier = - new StatModifier(StatType.DEF, StatModifier.OperationType.Percentage, -50); - Assert.Equal(limitModifier.GetModifiedAll(def), stats.DEF); + var modifier = deBuffLimitSheet[groupId].GetModifier(deBuff.RowData.StatType); + Assert.Equal(modifier.GetModifiedAll(def), stats.DEF); + + // -500% critical with no limit + var deBuff2 = new StatBuff(_tableSheets.StatBuffSheet[204003]); + Assert.True(stats.CRI > 0); + stats.AddBuff(deBuff2, deBuffLimitSheet: deBuffLimitSheet); + Assert.Equal(0, stats.CRI); } } } diff --git a/Lib9c/Model/Stat/CharacterStats.cs b/Lib9c/Model/Stat/CharacterStats.cs index d69ca589af..c48d40324c 100644 --- a/Lib9c/Model/Stat/CharacterStats.cs +++ b/Lib9c/Model/Stat/CharacterStats.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Nekoyume.Model.Item; -using Nekoyume.Model.Skill; using Nekoyume.TableData; namespace Nekoyume.Model.Stat @@ -326,24 +325,7 @@ public CharacterStats SetCollections(IEnumerable statModifiers, public void AddBuff(Buff.StatBuff buff, DeBuffLimitSheet deBuffLimitSheet, bool updateImmediate = true) { - var modifier = buff.GetModifier(); - if (buff.IsDebuff()) - { - var statType = modifier.StatType; - var stat = _statMap.GetStatAsLong(statType); - var buffModified = modifier.GetModifiedValue(stat); - var row = deBuffLimitSheet.Values.FirstOrDefault(r => - r.Modifier.StatType == statType); - if (row is not null) - { - var limitModifier = row.Modifier; - var maxModified = (long)limitModifier.GetModifiedValue(stat); - if (maxModified > buffModified) - { - modifier = limitModifier; - } - } - } + var modifier = GetBuffModifier(buff, deBuffLimitSheet); _buffStatModifiers[buff.RowData.GroupId] = modifier; if (updateImmediate) @@ -630,5 +612,31 @@ public void ConfigureStats( SetCollections(collectionStatModifiers); } + + private StatModifier GetBuffModifier(Buff.StatBuff buff, DeBuffLimitSheet deBuffLimitSheet) + { + var modifier = buff.GetModifier(); + if (buff.IsDebuff()) + { + try + { + var statType = modifier.StatType; + var limitModifier = deBuffLimitSheet[buff.RowData.GroupId].GetModifier(statType); + var stat = _statMap.GetStatAsLong(statType); + var buffModified = modifier.GetModifiedValue(stat); + var maxModified = (long)limitModifier.GetModifiedValue(stat); + if (maxModified > buffModified) + { + return limitModifier; + } + } + catch (KeyNotFoundException) + { + // pass + } + } + + return modifier; + } } } diff --git a/Lib9c/TableCSV/Skill/DeBuffLimitSheet.csv b/Lib9c/TableCSV/Skill/DeBuffLimitSheet.csv index 64f554b3ae..8d3e682dd6 100644 --- a/Lib9c/TableCSV/Skill/DeBuffLimitSheet.csv +++ b/Lib9c/TableCSV/Skill/DeBuffLimitSheet.csv @@ -1,6 +1,6 @@ -id,stat_type,percentage -1,ATK,-1 -2,DEF,-10 -3,CRI,-20 -4,HIT,-50 -5,SPD,-100 +group_id,percentage +1,-1 +2,-10 +3,-20 +4,-50 +5,-100 diff --git a/Lib9c/TableData/Skill/DeBuffLimitSheet.cs b/Lib9c/TableData/Skill/DeBuffLimitSheet.cs index 531f557e68..817049bb2f 100644 --- a/Lib9c/TableData/Skill/DeBuffLimitSheet.cs +++ b/Lib9c/TableData/Skill/DeBuffLimitSheet.cs @@ -10,19 +10,21 @@ public class DeBuffLimitSheet : Sheet { public class Row : SheetRow { - public override int Key => Id; + public override int Key => GroupId; - public int Id { get; set; } - public StatModifier Modifier { get; set; } + public int GroupId { get; set; } + + public int Value { get; set; } public override void Set(IReadOnlyList fields) { - Id = ParseInt(fields[0]); - Modifier = new StatModifier( - (StatType) Enum.Parse(typeof(StatType), fields[1]), - StatModifier.OperationType.Percentage, - ParseInt(fields[2]) - ); + GroupId = ParseInt(fields[0]); + Value = ParseInt(fields[1]); + } + + public StatModifier GetModifier(StatType statType) + { + return new StatModifier(statType, StatModifier.OperationType.Percentage, Value); } }