From b2d9f568d07b7bef07149ec153a986a822ec74f4 Mon Sep 17 00:00:00 2001 From: Xaver-DaRed Date: Thu, 28 Sep 2023 01:36:20 +0200 Subject: [PATCH] Implement getMaxGearMod() to be used in core --- scripts/globals/weaponskills.lua | 2 +- src/map/entities/battleentity.cpp | 35 +++++++++++++++++++++++++++++++ src/map/entities/battleentity.h | 1 + src/map/utils/battleutils.cpp | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/scripts/globals/weaponskills.lua b/scripts/globals/weaponskills.lua index a118a4d25f5..6d39c2312e3 100644 --- a/scripts/globals/weaponskills.lua +++ b/scripts/globals/weaponskills.lua @@ -84,7 +84,7 @@ end -- https://www.bg-wiki.com/ffxi/Agwu%27s_Scythe Souleater Effect that goes beyond established cap, Stalwart Soul bonus being additive to trait local function souleaterBonus(attacker, wsParams) if attacker:hasStatusEffect(xi.effect.SOULEATER) then - local souleaterEffect = attacker:getMaxGearMod(xi.mod.SOULEATER_EFFECT) * 0.01) + local souleaterEffect = attacker:getMaxGearMod(xi.mod.SOULEATER_EFFECT) * 0.01 local souleaterEffectII = attacker:getMod(xi.mod.SOULEATER_EFFECT_II) * 0.01 local stalwartSoulBonus = 1 - attacker:getMod(xi.mod.STALWART_SOUL) / 100 local bonusDamage = math.floor(attacker:getHP() * (0.1 + souleaterEffect + souleaterEffectII)) diff --git a/src/map/entities/battleentity.cpp b/src/map/entities/battleentity.cpp index 3477233ffc0..08f53a96278 100644 --- a/src/map/entities/battleentity.cpp +++ b/src/map/entities/battleentity.cpp @@ -1188,6 +1188,41 @@ int16 CBattleEntity::getMod(Mod modID) return m_modStat[modID]; } +/************************************************************************ + * * + * Get the highest value of the specified modifier across all gear * + * * + ************************************************************************/ +int16 CBattleEntity::getMaxGearMod(Mod modID) +{ + TracyZoneScoped; + auto* PChar = dynamic_cast(this); + uint16 maxModValue = 0; + + if (!PChar) + { + ShowWarning("CBattleEntity::getMaxGearMod() - Entity is not a player."); + + return 0; + } + + for (uint8 i = 0; i < SLOT_BACK; ++i) + { + auto* PItem = PChar->getEquip((SLOTTYPE)i); + if (PItem && (PItem->isType(ITEM_EQUIPMENT) || PItem->isType(ITEM_WEAPON))) + { + uint16 modValue = PItem->getModifier(modID); + + if (modValue > maxModValue) + { + maxModValue = modValue; + } + } + } + + return maxModValue; +} + void CBattleEntity::addPetModifier(Mod type, PetModType petmod, int16 amount) { TracyZoneScoped; diff --git a/src/map/entities/battleentity.h b/src/map/entities/battleentity.h index aaed5b16ef0..f7a2c046203 100644 --- a/src/map/entities/battleentity.h +++ b/src/map/entities/battleentity.h @@ -600,6 +600,7 @@ class CBattleEntity : public CBaseEntity DAMAGE_TYPE damageType = DAMAGE_TYPE::NONE, bool isSkillchainDamage = false); int16 getMod(Mod modID); + int16 getMaxGearMod(Mod modID); bool CanRest(); // checks if able to heal bool Rest(float rate); // heal an amount of hp / mp diff --git a/src/map/utils/battleutils.cpp b/src/map/utils/battleutils.cpp index 33a20f24e08..35a5dbe9fb9 100644 --- a/src/map/utils/battleutils.cpp +++ b/src/map/utils/battleutils.cpp @@ -4471,7 +4471,7 @@ namespace battleutils if (m_PChar->StatusEffectContainer->HasStatusEffect(EFFECT_SOULEATER)) { // Souleater's HP consumed is 10% (base) + x% from gear (ONLY HIGHEST) + x% from gear augments. - float souleaterBonus = m_PChar->getMaxGearMod(Mod::SOULEATER_EFFECT) * 0.01); + float souleaterBonus = m_PChar->getMaxGearMod(Mod::SOULEATER_EFFECT) * 0.01; float souleaterBonusII = m_PChar->getMod(Mod::SOULEATER_EFFECT_II) * 0.01; float stalwartSoulBonus = 1 - static_cast(m_PChar->getMod(Mod::STALWART_SOUL)) / 100; float bonusDamage = m_PChar->health.hp * (0.1f + souleaterBonus + souleaterBonusII);