From a7d817f202136439c3dee11cd36603b698bb07a5 Mon Sep 17 00:00:00 2001 From: Xaver-DaRed Date: Tue, 10 Feb 2026 18:13:04 +0100 Subject: [PATCH] Cleanup `WEAPONSKILL_TAKE` listener usage and reorder parameters --- documentation/AI_Events.txt | 10 +++++----- scripts/globals/abyssea/lights.lua | 4 ++-- scripts/mixins/abyssea_weakness.lua | 6 +++--- scripts/mixins/dynamis_beastmen.lua | 6 +++--- scripts/mixins/dynamis_dreamland.lua | 8 ++++---- scripts/mixins/families/chigoe.lua | 10 ++++------ scripts/mixins/families/maat.lua | 5 ++--- .../mobs/Unfettered_Twitherym.lua | 14 +++++++------- scripts/zones/Lebros_Cavern/mobs/Brittle_Rock.lua | 6 +++--- .../mobs/Dilapidated_Gate.lua | 2 +- src/map/ai/states/weaponskill_state.cpp | 2 +- src/map/entities/battleentity.cpp | 2 +- 12 files changed, 36 insertions(+), 39 deletions(-) diff --git a/documentation/AI_Events.txt b/documentation/AI_Events.txt index 5845fe23e80..8b7e9ee58ca 100644 --- a/documentation/AI_Events.txt +++ b/documentation/AI_Events.txt @@ -48,11 +48,11 @@ ABILITY_USE - Entity, Target, Ability, action ABILITY_TAKE - Target, Entity, Ability, action ABILITY_STATE_EXIT - Entity, Ability -WEAPONSKILL_STATE_ENTER - Entity, Skillid -WEAPONSKILL_BEFORE_USE - Entity, Skillid -WEAPONSKILL_USE - Entity, Target, Skillid, TP, action -WEAPONSKILL_TAKE - Target, Entity, Skillid, TP, action -WEAPONSKILL_STATE_EXIT - Entity, Skillid +WEAPONSKILL_STATE_ENTER - userEntity, skillId +WEAPONSKILL_BEFORE_USE - userEntity, skillId +WEAPONSKILL_USE - userEntity, targetEntity, skillId, tp, action +WEAPONSKILL_TAKE - userEntity, targetEntity, skillId, tp, action +WEAPONSKILL_STATE_EXIT - userEntity, skillId MAGIC_START - Entity, Spell, action MAGIC_USE - Entity, Target, Spell, action diff --git a/scripts/globals/abyssea/lights.lua b/scripts/globals/abyssea/lights.lua index 2b2bb9fd28a..9c40f34cf89 100644 --- a/scripts/globals/abyssea/lights.lua +++ b/scripts/globals/abyssea/lights.lua @@ -539,7 +539,7 @@ xi.abyssea.AddDeathListeners = function(mob) end end) - mob:addListener('WEAPONSKILL_TAKE', 'ABYSSEA_WS_DEATH_CHECK', function(target, user, wsid) + mob:addListener('WEAPONSKILL_TAKE', 'ABYSSEA_WS_DEATH_CHECK', function(user, target, skillId, tp, action) -- TODO: Make this human-readable, and break out from the listener local magicalWS = { @@ -555,7 +555,7 @@ xi.abyssea.AddDeathListeners = function(mob) target:getDeathType() == xi.abyssea.deathType.NONE then for i = 1, #magicalWS do - if wsid == magicalWS[i] then + if skillId == magicalWS[i] then wsType = xi.abyssea.deathType.WS_MAGICAL break end diff --git a/scripts/mixins/abyssea_weakness.lua b/scripts/mixins/abyssea_weakness.lua index 8e380354c63..4afe521f757 100644 --- a/scripts/mixins/abyssea_weakness.lua +++ b/scripts/mixins/abyssea_weakness.lua @@ -36,11 +36,11 @@ g_mixins.abyssea_weakness = function(mob) end end) - mob:addListener('WEAPONSKILL_TAKE', 'ABYSSEA_WS_PROC_CHECK', function(target, user, wsid) + mob:addListener('WEAPONSKILL_TAKE', 'ABYSSEA_WS_PROC_CHECK', function(user, target, skillId, tp, action) if target:canChangeState() then - if wsid == target:getLocalVar('[RedWeakness]') then + if skillId == target:getLocalVar('[RedWeakness]') then xi.abyssea.procMonster(target, user, xi.abyssea.triggerType.RED) - elseif wsid == target:getLocalVar('[BlueWeakness]') then + elseif skillId == target:getLocalVar('[BlueWeakness]') then xi.abyssea.procMonster(target, user, xi.abyssea.triggerType.BLUE) end end diff --git a/scripts/mixins/dynamis_beastmen.lua b/scripts/mixins/dynamis_beastmen.lua index 5f09f8cdb83..476cf2ba48e 100644 --- a/scripts/mixins/dynamis_beastmen.lua +++ b/scripts/mixins/dynamis_beastmen.lua @@ -54,10 +54,10 @@ g_mixins.dynamis_beastmen = function(dynamisBeastmenMob) end end) - dynamisBeastmenMob:addListener('WEAPONSKILL_TAKE', 'DYNAMIS_WS_PROC_CHECK', function(target, user, wsid) + dynamisBeastmenMob:addListener('WEAPONSKILL_TAKE', 'DYNAMIS_WS_PROC_CHECK', function(user, target, skillId, tp, action) if procjobs[target:getMainJob()] == 'ws' and - math.random(0, 99) < 25 and + math.random(1, 100) <= 25 and target:getLocalVar('dynamis_proc') == 0 then xi.dynamis.procMonster(target, user) @@ -67,7 +67,7 @@ g_mixins.dynamis_beastmen = function(dynamisBeastmenMob) dynamisBeastmenMob:addListener('ABILITY_TAKE', 'DYNAMIS_ABILITY_PROC_CHECK', function(mob, user, ability, action) if procjobs[mob:getMainJob()] == 'ja' and - math.random(0, 99) < 20 and + math.random(1, 100) <= 20 and mob:getLocalVar('dynamis_proc') == 0 then xi.dynamis.procMonster(mob, user) diff --git a/scripts/mixins/dynamis_dreamland.lua b/scripts/mixins/dynamis_dreamland.lua index 153cfa07128..9bd47a8a234 100644 --- a/scripts/mixins/dynamis_dreamland.lua +++ b/scripts/mixins/dynamis_dreamland.lua @@ -54,7 +54,7 @@ g_mixins.dynamis_dreamland = function(dynamisDreamlandMob) local vanaHour = VanadielHour() if - math.random(0, 99) < 8 and + math.random(1, 100) <= 8 and target:getLocalVar('dynamis_proc') == 0 and ( currency == 0 or @@ -68,12 +68,12 @@ g_mixins.dynamis_dreamland = function(dynamisDreamlandMob) end end) - dynamisDreamlandMob:addListener('WEAPONSKILL_TAKE', 'DYNAMIS_WS_PROC_CHECK', function(target, user, wsid) + dynamisDreamlandMob:addListener('WEAPONSKILL_TAKE', 'DYNAMIS_WS_PROC_CHECK', function(user, target, skillId, tp, action) local currency = target:getLocalVar('dynamis_currency') local vanaHour = VanadielHour() if - math.random(0, 99) < 25 and + math.random(1, 100) <= 25 and target:getLocalVar('dynamis_proc') == 0 and ( currency == 0 or @@ -92,7 +92,7 @@ g_mixins.dynamis_dreamland = function(dynamisDreamlandMob) local vanaHour = VanadielHour() if - math.random(0, 99) < 20 and + math.random(1, 100) <= 20 and target:getLocalVar('dynamis_proc') == 0 and ( currency == 0 or diff --git a/scripts/mixins/families/chigoe.lua b/scripts/mixins/families/chigoe.lua index 0ca7dc1dbac..619472d9609 100644 --- a/scripts/mixins/families/chigoe.lua +++ b/scripts/mixins/families/chigoe.lua @@ -41,12 +41,10 @@ g_mixins.families.chigoe = function(chigoeMob) mob:setHP(0) end) - chigoeMob:addListener('WEAPONSKILL_TAKE', 'CHIGOE_WEAPONSKILL_TAKE', function(mob, wsid) - if wsid then - mob:setMobMod(xi.mobMod.EXP_BONUS, -100) - mob:setMobMod(xi.mobMod.NO_DROPS, 1) - mob:setHP(0) - end + chigoeMob:addListener('WEAPONSKILL_TAKE', 'CHIGOE_WEAPONSKILL_TAKE', function(user, target, skillId, tp, action) + target:setMobMod(xi.mobMod.EXP_BONUS, -100) + target:setMobMod(xi.mobMod.NO_DROPS, 1) + target:setHP(0) end) chigoeMob:addListener('ABILITY_TAKE', 'CHIGOE_ABILITY_TAKE', function(mob, user, ability) diff --git a/scripts/mixins/families/maat.lua b/scripts/mixins/families/maat.lua index 31be69008ee..d5d947f0b84 100644 --- a/scripts/mixins/families/maat.lua +++ b/scripts/mixins/families/maat.lua @@ -96,9 +96,8 @@ g_mixins.families.maat = function(maatMob) mob:messageText(mob, ID.text.YOUVE_COME_A_LONG_WAY) end) - maatMob:addListener('WEAPONSKILL_TAKE', 'MAAT_WEAPONSKILL_TAKE', function(target, user, wsid, tp, action) - local ID = zones[target:getZoneID()] - target:messageText(target, ID.text.THAT_LL_HURT_IN_THE_MORNING) + maatMob:addListener('WEAPONSKILL_TAKE', 'MAAT_WEAPONSKILL_TAKE', function(user, target, skillId, tp, action) + target:messageText(target, zones[target:getZoneID()].text.THAT_LL_HURT_IN_THE_MORNING) end) maatMob:addListener('WEAPONSKILL_USE', 'MAAT_WEAPONSKILL_USE', function(mob, target, wsid, tp, action) diff --git a/scripts/zones/Ceizak_Battlegrounds/mobs/Unfettered_Twitherym.lua b/scripts/zones/Ceizak_Battlegrounds/mobs/Unfettered_Twitherym.lua index dc03ed58c8e..2a0ffab687b 100644 --- a/scripts/zones/Ceizak_Battlegrounds/mobs/Unfettered_Twitherym.lua +++ b/scripts/zones/Ceizak_Battlegrounds/mobs/Unfettered_Twitherym.lua @@ -94,15 +94,15 @@ entity.onMobSpawn = function(mob) end end) - mob:addListener('WEAPONSKILL_TAKE', 'SKILLCHAIN_DETECT', function(mobArg, _, skillID) - if mobArg:hasStatusEffect(xi.effect.SKILLCHAIN) then - if mobArg:getLocalVar('chosenElement') ~= 0 then - local skillchainEffect = mobArg:getStatusEffect(xi.effect.SKILLCHAIN) + mob:addListener('WEAPONSKILL_TAKE', 'SKILLCHAIN_DETECT', function(user, target, skillId, tp, action) + if target:hasStatusEffect(xi.effect.SKILLCHAIN) then + if target:getLocalVar('chosenElement') ~= 0 then + local skillchainEffect = target:getStatusEffect(xi.effect.SKILLCHAIN) local power = skillchainEffect:getPower() - if isSkillchainCorrect(mobArg, power) then - resetDamageModifiers(mobArg) - mobArg:setLocalVar('chosenElement', 0) + if isSkillchainCorrect(target, power) then + resetDamageModifiers(target) + target:setLocalVar('chosenElement', 0) for phase, _ in pairs(phaseDTApplied) do phaseDTApplied[phase] = false end diff --git a/scripts/zones/Lebros_Cavern/mobs/Brittle_Rock.lua b/scripts/zones/Lebros_Cavern/mobs/Brittle_Rock.lua index ead9bb50696..848a624dc56 100644 --- a/scripts/zones/Lebros_Cavern/mobs/Brittle_Rock.lua +++ b/scripts/zones/Lebros_Cavern/mobs/Brittle_Rock.lua @@ -21,9 +21,9 @@ entity.onMobSpawn = function(mob) mob:setMod(xi.mod.CURSE_MEVA, 9999) mob:setMod(xi.mod.EVA, 0) mob:setMobMod(xi.mobMod.NO_DROPS, 1) - mob:addListener('WEAPONSKILL_TAKE', 'BRITTLE_ROCK_WEAPONSKILL_TAKE', function(mobArg, user, wsid) - if wsid == 1838 then - mobArg:setHP(0) + mob:addListener('WEAPONSKILL_TAKE', 'BRITTLE_ROCK_WEAPONSKILL_TAKE', function(user, target, skillId, tp, action) + if skillId == 1838 then + target:setHP(0) end end) end diff --git a/scripts/zones/Mamool_Ja_Training_Grounds/mobs/Dilapidated_Gate.lua b/scripts/zones/Mamool_Ja_Training_Grounds/mobs/Dilapidated_Gate.lua index 720bd9206be..a202f477d40 100644 --- a/scripts/zones/Mamool_Ja_Training_Grounds/mobs/Dilapidated_Gate.lua +++ b/scripts/zones/Mamool_Ja_Training_Grounds/mobs/Dilapidated_Gate.lua @@ -11,7 +11,7 @@ entity.onMobSpawn = function(mob) mob:hideName(true) mob:setAutoAttackEnabled(false) mob:setMobMod(xi.mobMod.NO_MOVE, 1) - mob:addListener('WEAPONSKILL_TAKE', 'DILAPIDATED_GATE_WEAPONSKILL_TAKE', function(target, attacker, skillId, tp, action) + mob:addListener('WEAPONSKILL_TAKE', 'DILAPIDATED_GATE_WEAPONSKILL_TAKE', function(user, target, skillId, tp, action) if skillId == 1733 or skillId == 1923 then -- firespit target:setLocalVar('hits', target:getLocalVar('hits') + 1) elseif skillId == 1736 or skillId == 1925 then --Axe Throw or Stave Toss diff --git a/src/map/ai/states/weaponskill_state.cpp b/src/map/ai/states/weaponskill_state.cpp index ab1ed08c01a..28052eda4a8 100644 --- a/src/map/ai/states/weaponskill_state.cpp +++ b/src/map/ai/states/weaponskill_state.cpp @@ -158,7 +158,7 @@ bool CWeaponSkillState::Update(timer::time_point tick) uint32 weaponskillDamage = weaponskillVar & 0xFFFFFF; m_PEntity->PAI->EventHandler.triggerListener("WEAPONSKILL_USE", m_PEntity, PTarget, m_PSkill->getID(), m_spent, &action, weaponskillDamage); - PTarget->PAI->EventHandler.triggerListener("WEAPONSKILL_TAKE", PTarget, m_PEntity, m_PSkill->getID(), m_spent, &action); + PTarget->PAI->EventHandler.triggerListener("WEAPONSKILL_TAKE", m_PEntity, PTarget, m_PSkill->getID(), m_spent, &action); if (m_PEntity->objtype == TYPE_PC) { diff --git a/src/map/entities/battleentity.cpp b/src/map/entities/battleentity.cpp index fd17a0457d9..0cc0c0d986e 100644 --- a/src/map/entities/battleentity.cpp +++ b/src/map/entities/battleentity.cpp @@ -2654,7 +2654,7 @@ void CBattleEntity::OnMobSkillFinished(CMobSkillState& state, action_t& action) { damage = luautils::OnMobWeaponSkill(PTargetFound, this, PSkill, &action); this->PAI->EventHandler.triggerListener("WEAPONSKILL_USE", this, PTargetFound, PSkill->getID(), state.GetSpentTP(), &action, damage); - PTargetFound->PAI->EventHandler.triggerListener("WEAPONSKILL_TAKE", PTargetFound, this, PSkill->getID(), state.GetSpentTP(), &action); + PTargetFound->PAI->EventHandler.triggerListener("WEAPONSKILL_TAKE", this, PTargetFound, PSkill->getID(), state.GetSpentTP(), &action); } if (msg == MsgBasic::NONE)