Skip to content

Commit c95f141

Browse files
committed
Add ItemOption stat calculation
1 parent 1d9a709 commit c95f141

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

src/common/Edelstein.Common.Gameplay.Game/Combat/Stats/StatModifier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ public record StatModifier(
1717
public int IncFlat { get; set; }
1818

1919
public int Apply(int value)
20-
=> Math.Min(Math.Max((int)((value + IncBase) * (1 + IncRate / 100d) + IncFlat), Min), Max);
20+
=> Math.Min(Math.Max(value + IncBase + (int)((value + IncBase) * IncRate / 100d) + IncFlat, Min), Max);
2121
}

src/common/Edelstein.Common.Gameplay.Game/Objects/Users/Stats/Calculations/FieldUserStatsCalculatorEquip.cs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
using System.Collections.Immutable;
1+
using System;
2+
using System.Collections.Immutable;
23
using System.Linq;
34
using System.Threading.Tasks;
45
using Edelstein.Protocol.Gameplay.Entities.Inventories;
56
using Edelstein.Protocol.Gameplay.Entities.Inventories.Templates;
7+
using Edelstein.Protocol.Gameplay.Entities.Inventories.Templates.Options;
68
using Edelstein.Protocol.Gameplay.Game.Objects.Users.Stats;
79
using Edelstein.Protocol.Utilities.Pipelines;
810
using Edelstein.Protocol.Utilities.Templates;
911

1012
namespace Edelstein.Common.Gameplay.Game.Objects.Users.Stats.Calculations;
1113

1214
public class FieldUserStatsCalculatorEquip(
13-
ITemplateManager<IItemTemplate> items
15+
ITemplateManager<IItemTemplate> items,
16+
ITemplateManager<IItemOptionTemplate> options
1417
) : IFieldUserStatsCalculatorEntry
1518
{
1619
public int Priority => FieldUserStatsCalculatorSteps.Equip;
@@ -60,7 +63,65 @@ public async Task Handle(IPipelineContext ctx, IFieldUserStatsCalculatorContext
6063

6164
stats.MaxHP.IncRate += template.IncMaxHPr;
6265
stats.MaxMP.IncRate += template.IncMaxMPr;
66+
67+
var grade = (ItemOptionGrade)(item.Grade & 0x3);
68+
if ((item.Grade & (int)ItemOptionGradeState.Released) > 0 &&
69+
grade is
70+
ItemOptionGrade.Rare or
71+
ItemOptionGrade.Epic or
72+
ItemOptionGrade.Unique)
73+
{
74+
var level = (template.ReqLevel - 1) / 10;
75+
76+
level = Math.Max(1, level);
77+
level = Math.Min(20, level);
78+
79+
await ApplyItemOption(stats, item.Option1, level);
80+
await ApplyItemOption(stats, item.Option2, level);
81+
await ApplyItemOption(stats, item.Option3, level);
82+
}
6383
}
6484
}
6585
}
86+
87+
private async Task ApplyItemOption(IFieldUserStatsCalculatorContext stats, int option, int level)
88+
{
89+
var template = await options.Retrieve(option);
90+
if (template == null) return;
91+
var templateLevel = await template.Levels.Retrieve(level);
92+
if (templateLevel == null) return;
93+
94+
stats.STR.IncBase += templateLevel.IncSTR;
95+
stats.DEX.IncBase += templateLevel.IncDEX;
96+
stats.LUK.IncBase += templateLevel.IncLUK;
97+
stats.INT.IncBase += templateLevel.IncINT;
98+
99+
stats.STR.IncRate += templateLevel.IncSTRr;
100+
stats.DEX.IncRate += templateLevel.IncDEXr;
101+
stats.LUK.IncRate += templateLevel.IncLUKr;
102+
stats.INT.IncRate += templateLevel.IncINTr;
103+
104+
stats.MaxHP.IncBase += templateLevel.IncMaxHP;
105+
stats.MaxMP.IncBase += templateLevel.IncMaxMP;
106+
107+
stats.MaxHP.IncRate += templateLevel.IncMaxHPr;
108+
stats.MaxMP.IncRate += templateLevel.IncMaxMPr;
109+
110+
stats.PAD.IncBase += templateLevel.IncPAD;
111+
stats.PDD.IncBase += templateLevel.IncPDD;
112+
stats.MAD.IncBase += templateLevel.IncMAD;
113+
stats.MDD.IncBase += templateLevel.IncMDD;
114+
stats.ACC.IncBase += templateLevel.IncACC;
115+
stats.EVA.IncBase += templateLevel.IncEVA;
116+
117+
stats.PAD.IncRate += templateLevel.IncPADr;
118+
stats.PDD.IncRate += templateLevel.IncPDDr;
119+
stats.MAD.IncRate += templateLevel.IncMADr;
120+
stats.MDD.IncRate += templateLevel.IncMDDr;
121+
stats.ACC.IncRate += templateLevel.IncACCr;
122+
stats.EVA.IncRate += templateLevel.IncEVAr;
123+
124+
stats.Speed.IncBase += templateLevel.IncSpeed;
125+
stats.Jump.IncBase += templateLevel.IncJump;
126+
}
66127
}

0 commit comments

Comments
 (0)