Skip to content

Commit

Permalink
Use buff group id instead of stat type
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Mar 19, 2024
1 parent 4bafa99 commit 1c28917
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
17 changes: 12 additions & 5 deletions .Lib9c.Tests/Model/CharacterStatsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
46 changes: 27 additions & 19 deletions Lib9c/Model/Stat/CharacterStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -326,24 +325,7 @@ public CharacterStats SetCollections(IEnumerable<StatModifier> 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)
Expand Down Expand Up @@ -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;
}
}
}
12 changes: 6 additions & 6 deletions Lib9c/TableCSV/Skill/DeBuffLimitSheet.csv
Original file line number Diff line number Diff line change
@@ -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
20 changes: 11 additions & 9 deletions Lib9c/TableData/Skill/DeBuffLimitSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ public class DeBuffLimitSheet : Sheet<int, DeBuffLimitSheet.Row>
{
public class Row : SheetRow<int>
{
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<string> 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);
}
}

Expand Down

0 comments on commit 1c28917

Please sign in to comment.