From 367db07c1fdbf1390e8de5fa6c2497fe320d0ce2 Mon Sep 17 00:00:00 2001 From: Xaver-DaRed Date: Tue, 27 Aug 2024 19:13:57 +0200 Subject: [PATCH] Fix when yellow weakness is chosen and use day enums --- scripts/enum/element.lua | 18 +++++++++--------- scripts/globals/abyssea.lua | 20 +++++++++++--------- scripts/mixins/abyssea_weakness.lua | 7 +++++-- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/scripts/enum/element.lua b/scripts/enum/element.lua index 3238f712321..ff1fd6955e9 100644 --- a/scripts/enum/element.lua +++ b/scripts/enum/element.lua @@ -3,13 +3,13 @@ xi = xi or {} ---@enum element xi.element = { - NONE = 0, - FIRE = 1, - ICE = 2, - WIND = 3, - EARTH = 4, - THUNDER = 5, - WATER = 6, - LIGHT = 7, - DARK = 8, + NONE = 0, + FIRE = 1, + ICE = 2, + WIND = 3, + EARTH = 4, + THUNDER = 5, + WATER = 6, + LIGHT = 7, + DARK = 8, } diff --git a/scripts/globals/abyssea.lua b/scripts/globals/abyssea.lua index 29296ee2a9f..d408fdd2cb7 100644 --- a/scripts/globals/abyssea.lua +++ b/scripts/globals/abyssea.lua @@ -813,17 +813,19 @@ xi.abyssea.getDemiluneAbyssite = function(player) end xi.abyssea.getNewYellowWeakness = function(mob) - local day = VanadielDayOfTheWeek() - local weakness = math.random(day - 1, day + 1) - - if weakness < 0 then - weakness = 7 - elseif weakness > 7 then - weakness = 0 + local currentDay = VanadielDayOfTheWeek() -- Fetch current day. + local chosenDay = math.random(currentDay - 1, currentDay + 1) -- It can be the element of the same day, the day before or the day after. + + -- Acount for day element cycling. + if chosenDay < xi.day.FIRESDAY then + chosenDay = xi.day.DARKSDAY + elseif chosenDay > xi.day.DARKSDAY then + chosenDay = xi.day.FIRESDAY end - local element = xi.magic.dayElement[weakness] - return yellowWeakness[element][math.random(#yellowWeakness[element])] + local element = xi.magic.dayElement[chosenDay] + + return yellowWeakness[element][math.random(1, #yellowWeakness[element])] -- Choose an specific spell the mob is weak to. end xi.abyssea.getNewRedWeakness = function(mob) diff --git a/scripts/mixins/abyssea_weakness.lua b/scripts/mixins/abyssea_weakness.lua index a3abf4874c0..8e380354c63 100644 --- a/scripts/mixins/abyssea_weakness.lua +++ b/scripts/mixins/abyssea_weakness.lua @@ -12,12 +12,15 @@ g_mixins.abyssea_weakness = function(mob) mobArg:setLocalVar('[CanProc]', 1) mobArg:setLocalVar('[RedWeakness]', xi.abyssea.getNewRedWeakness(mobArg)) mobArg:setLocalVar('[AbysseaRedProc]', 0) - mobArg:setLocalVar('[YellowWeakness]', xi.abyssea.getNewYellowWeakness(mobArg)) - mobArg:setLocalVar('[AbysseaYellowProc]', 0) mobArg:setLocalVar('[BlueWeakness]', xi.abyssea.getNewBlueWeakness(mobArg)) mobArg:setLocalVar('[AbysseaBlueProc]', 0) end) + mob:addListener('ENGAGE', 'ABYSSEA_WEAKNESS_ENGAGE', function(mobArg, target) + mobArg:setLocalVar('[YellowWeakness]', xi.abyssea.getNewYellowWeakness(mobArg)) + mobArg:setLocalVar('[AbysseaYellowProc]', 0) + end) + mob:addListener('ATTACKED', 'ATTACKED_ABYSSEA_CHECK_CLAIM', function(mobArg, player, action) local claimed = mobArg:getLocalVar('[ClaimedBy]') if claimed == 0 then