Skip to content

Commit

Permalink
Extend effect:addMod to work consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
MowFord committed May 22, 2024
1 parent f6ae1ea commit 704908e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 3 additions & 6 deletions scripts/globals/job_utils/rune_fencer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ local function applyVallationValianceSDTMods(target, SDTTypes, power, effect, du
local newEffect = target:getStatusEffect(effect)

for _, SDT in ipairs(SDTTypes) do
target:addMod(SDT, power)
newEffect:addMod(SDT, power) -- due to order of events, this only adds mods to the container, not to the owner of the effect.
newEffect:addMod(SDT, power)
end
end
end
Expand All @@ -309,8 +308,7 @@ local function applyGambitSDTMods(target, SDTTypes, power, effect, duration) --
local newEffect = target:getStatusEffect(effect)

for _, SDT in ipairs(SDTTypes) do
target:addMod(SDT, power)
newEffect:addMod(SDT, power) -- due to order of events, this only adds mods to the container, not to the owner of the effect.
newEffect:addMod(SDT, power)
end
end
end
Expand Down Expand Up @@ -695,7 +693,7 @@ local function addPflugResistType(type, effect, power)

local resistTypes = pflugResistTypes[type]

for _, resistMod in pairs(resistTypes) do -- store mod in effect, this function is triggered from event onEffectGain so it adds to the player automatically.
for _, resistMod in pairs(resistTypes) do
effect:addMod(resistMod, power)
end
end
Expand Down Expand Up @@ -782,7 +780,6 @@ xi.job_utils.rune_fencer.useRayke = function(player, target, ability, action)
local element = getRaykeElement(rune)

raykeElements = raykeElements + bit.lshift(element, 4 * i) -- pack 4 bit damage type into 16 bit int
target:addMod(resRankMod, -1)
effect:addMod(resRankMod, -1) -- Status effect handles removing the mods

i = i + 1
Expand Down
10 changes: 9 additions & 1 deletion src/map/lua/lua_statuseffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "common/timer.h"

#include "lua_statuseffect.h"
#include "status_effect_container.h"
#include "status_effect.h"
#include "status_effect_container.h"

#include "entities/battleentity.h"

Expand Down Expand Up @@ -207,6 +207,14 @@ void CLuaStatusEffect::setStartTime(uint32 time)
void CLuaStatusEffect::addMod(uint16 mod, int16 amount)
{
m_PLuaStatusEffect->addMod(static_cast<Mod>(mod), amount);

// Since an effect's mod list is only applied to entity when adding the effect
// we need to add the mod to the entity manually if the effect is already applied
auto* PBattleEntity = dynamic_cast<CBattleEntity*>(m_PBaseEntity);
if (PBattleEntity)
{
PBattleEntity->addModifier(static_cast<Mod>(mod), amount);
}
}

//======================================================//
Expand Down
2 changes: 1 addition & 1 deletion src/map/status_effect_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CStatusEffectContainer
CBattleEntity* m_POwner = nullptr;

// void ReplaceStatusEffect(EFFECT effect); //this needs to be implemented
void RemoveStatusEffect(uint32 id, bool silent = false); // We remove the effect by its number in the container
void RemoveStatusEffect(uint32 id, bool silent = false); // We remove the effect by its number in the container
void DeleteStatusEffects();
void SetEffectParams(CStatusEffect* StatusEffect); // We set the effect of the effect
void HandleAura(CStatusEffect* PStatusEffect);
Expand Down

0 comments on commit 704908e

Please sign in to comment.