From c95f1411449af566d0cfb281f67ef1ba71e2ac86 Mon Sep 17 00:00:00 2001 From: Kaioru Date: Wed, 11 Dec 2024 19:40:45 +0800 Subject: [PATCH] Add ItemOption stat calculation --- .../Combat/Stats/StatModifier.cs | 2 +- .../FieldUserStatsCalculatorEquip.cs | 65 ++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/common/Edelstein.Common.Gameplay.Game/Combat/Stats/StatModifier.cs b/src/common/Edelstein.Common.Gameplay.Game/Combat/Stats/StatModifier.cs index 3fbc0adf0..24bb84de2 100644 --- a/src/common/Edelstein.Common.Gameplay.Game/Combat/Stats/StatModifier.cs +++ b/src/common/Edelstein.Common.Gameplay.Game/Combat/Stats/StatModifier.cs @@ -17,5 +17,5 @@ public record StatModifier( public int IncFlat { get; set; } public int Apply(int value) - => Math.Min(Math.Max((int)((value + IncBase) * (1 + IncRate / 100d) + IncFlat), Min), Max); + => Math.Min(Math.Max(value + IncBase + (int)((value + IncBase) * IncRate / 100d) + IncFlat, Min), Max); } diff --git a/src/common/Edelstein.Common.Gameplay.Game/Objects/Users/Stats/Calculations/FieldUserStatsCalculatorEquip.cs b/src/common/Edelstein.Common.Gameplay.Game/Objects/Users/Stats/Calculations/FieldUserStatsCalculatorEquip.cs index e77793a66..fd553e954 100644 --- a/src/common/Edelstein.Common.Gameplay.Game/Objects/Users/Stats/Calculations/FieldUserStatsCalculatorEquip.cs +++ b/src/common/Edelstein.Common.Gameplay.Game/Objects/Users/Stats/Calculations/FieldUserStatsCalculatorEquip.cs @@ -1,8 +1,10 @@ -using System.Collections.Immutable; +using System; +using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; using Edelstein.Protocol.Gameplay.Entities.Inventories; using Edelstein.Protocol.Gameplay.Entities.Inventories.Templates; +using Edelstein.Protocol.Gameplay.Entities.Inventories.Templates.Options; using Edelstein.Protocol.Gameplay.Game.Objects.Users.Stats; using Edelstein.Protocol.Utilities.Pipelines; using Edelstein.Protocol.Utilities.Templates; @@ -10,7 +12,8 @@ namespace Edelstein.Common.Gameplay.Game.Objects.Users.Stats.Calculations; public class FieldUserStatsCalculatorEquip( - ITemplateManager items + ITemplateManager items, + ITemplateManager options ) : IFieldUserStatsCalculatorEntry { public int Priority => FieldUserStatsCalculatorSteps.Equip; @@ -60,7 +63,65 @@ public async Task Handle(IPipelineContext ctx, IFieldUserStatsCalculatorContext stats.MaxHP.IncRate += template.IncMaxHPr; stats.MaxMP.IncRate += template.IncMaxMPr; + + var grade = (ItemOptionGrade)(item.Grade & 0x3); + if ((item.Grade & (int)ItemOptionGradeState.Released) > 0 && + grade is + ItemOptionGrade.Rare or + ItemOptionGrade.Epic or + ItemOptionGrade.Unique) + { + var level = (template.ReqLevel - 1) / 10; + + level = Math.Max(1, level); + level = Math.Min(20, level); + + await ApplyItemOption(stats, item.Option1, level); + await ApplyItemOption(stats, item.Option2, level); + await ApplyItemOption(stats, item.Option3, level); + } } } } + + private async Task ApplyItemOption(IFieldUserStatsCalculatorContext stats, int option, int level) + { + var template = await options.Retrieve(option); + if (template == null) return; + var templateLevel = await template.Levels.Retrieve(level); + if (templateLevel == null) return; + + stats.STR.IncBase += templateLevel.IncSTR; + stats.DEX.IncBase += templateLevel.IncDEX; + stats.LUK.IncBase += templateLevel.IncLUK; + stats.INT.IncBase += templateLevel.IncINT; + + stats.STR.IncRate += templateLevel.IncSTRr; + stats.DEX.IncRate += templateLevel.IncDEXr; + stats.LUK.IncRate += templateLevel.IncLUKr; + stats.INT.IncRate += templateLevel.IncINTr; + + stats.MaxHP.IncBase += templateLevel.IncMaxHP; + stats.MaxMP.IncBase += templateLevel.IncMaxMP; + + stats.MaxHP.IncRate += templateLevel.IncMaxHPr; + stats.MaxMP.IncRate += templateLevel.IncMaxMPr; + + stats.PAD.IncBase += templateLevel.IncPAD; + stats.PDD.IncBase += templateLevel.IncPDD; + stats.MAD.IncBase += templateLevel.IncMAD; + stats.MDD.IncBase += templateLevel.IncMDD; + stats.ACC.IncBase += templateLevel.IncACC; + stats.EVA.IncBase += templateLevel.IncEVA; + + stats.PAD.IncRate += templateLevel.IncPADr; + stats.PDD.IncRate += templateLevel.IncPDDr; + stats.MAD.IncRate += templateLevel.IncMADr; + stats.MDD.IncRate += templateLevel.IncMDDr; + stats.ACC.IncRate += templateLevel.IncACCr; + stats.EVA.IncRate += templateLevel.IncEVAr; + + stats.Speed.IncBase += templateLevel.IncSpeed; + stats.Jump.IncBase += templateLevel.IncJump; + } }