diff --git a/content/objects/decks.lua b/content/objects/decks.lua index b5a66e8..34a7d1f 100644 --- a/content/objects/decks.lua +++ b/content/objects/decks.lua @@ -74,19 +74,6 @@ SMODS.Back({ }, G.deck, nil, nil, { G.C.SECONDARY_SET.Enhanced }) _card:set_ability(G.P_CENTERS["m_glorp"], nil, true) SMODS.change_base(_card, "Glorpsuit") - -- Check if Cerber joker exists and apply Negative to 2s - local has_cerber = false - if G and G.jokers and G.jokers.cards then - for _, joker in ipairs(G.jokers.cards) do - if joker.config and joker.config.center and joker.config.center.key == "j_cerber" then - has_cerber = true - break - end - end - end - if has_cerber and _rank == "2" then - _card:set_edition("e_negative", true) - end G.E_MANAGER:add_event(Event({ func = function() return true diff --git a/content/objects/jokers.lua b/content/objects/jokers.lua index f8c109b..8c61619 100644 --- a/content/objects/jokers.lua +++ b/content/objects/jokers.lua @@ -2285,7 +2285,7 @@ SMODS.Joker({ name = "Cerber", text = { "All {C:attention}2s{} become", - "{C:dark_edition}Negative{} when obtained", + "{C:dark_edition}Negative{}", }, }, credits = { @@ -2305,20 +2305,12 @@ SMODS.Joker({ pos = { x = 4, y = 0 }, add_to_deck = function(self, card, from_debuff) if G.playing_cards and not card.debuff then - for _, pcard in ipairs(G.playing_cards) do - if pcard:get_id() == 2 and not (pcard.edition and pcard.edition.key == "e_negative") then - pcard:set_edition("e_negative", true) - end - end + Neuratro.cerberify_cards(G.playing_cards) end end, calculate = function(self, card, context) if context.playing_card_added and not context.blueprint and not context.retrigger_joker then - for _, pcard in ipairs(context.cards) do - if pcard:get_id() == 2 and not (pcard.edition and pcard.edition.key == "e_negative") then - pcard:set_edition("e_negative", true) - end - end + Neuratro.cerberify_cards(context.cards) end end, in_pool = function(self, args) diff --git a/modules/hooks/general.lua b/modules/hooks/general.lua index 406ce5d..919ec5e 100644 --- a/modules/hooks/general.lua +++ b/modules/hooks/general.lua @@ -49,6 +49,30 @@ function Card:set_sprites(center, ...) return _set_sprites(self, center, ...) end +local function cerber_card_id(card) + return card and card.base and card.base.id or nil +end + +local card_set_base = Card.set_base +function Card:set_base(...) + local previous_id = cerber_card_id(self) + local x = { card_set_base(self, ...) } + if previous_id ~= 2 and cerber_card_id(self) == 2 then + Neuratro.trigger_cerber_on_card(self) + end + return unpack(x) +end + +local smods_change_base = SMODS.change_base +function SMODS.change_base(card, ...) + local previous_id = cerber_card_id(card) + local x = { smods_change_base(card, ...) } + if card and previous_id ~= 2 and cerber_card_id(card) == 2 then + Neuratro.trigger_cerber_on_card(card) + end + return unpack(x) +end + local cardUpdateHook = Card.update function Card:update(dt) self.playbook_click_delay = math.max((self.playbook_click_delay or 0) - dt, 0) diff --git a/modules/utils/joker_utils.lua b/modules/utils/joker_utils.lua index 8c1d376..c1ca4e0 100644 --- a/modules/utils/joker_utils.lua +++ b/modules/utils/joker_utils.lua @@ -39,6 +39,55 @@ function Neuratro.has_joker(joker_key) return Neuratro.find_joker(joker_key) ~= nil end +function Neuratro.cerberify_card(card) + local card_id = card and card.base and card.base.id + if + not card + or not card_id + or not card.ability + or card.ability.set ~= "Default" + or card_id ~= 2 + or (card.edition and card.edition.key == "e_negative") + then + return false + end + + card:set_edition("e_negative", true) + return true +end + +function Neuratro.cerberify_cards(cards) + if not cards then + return false + end + + local triggered = false + + for _, card in ipairs(cards) do + if Neuratro.cerberify_card(card) then + triggered = true + end + end + + return triggered +end + +function Neuratro.trigger_cerber_on_card(card) + if not card or not Neuratro.has_joker("j_cerber") then + return false + end + + return Neuratro.cerberify_card(card) +end + +function Neuratro.trigger_cerber_on_cards(cards) + if not cards or not Neuratro.has_joker("j_cerber") then + return false + end + + return Neuratro.cerberify_cards(cards) +end + function Neuratro.trigger_filtersister_upgrade() for _, joker in ipairs(Neuratro.find_jokers("j_filtersister")) do joker.ability.extra.xmult = joker.ability.extra.xmult + joker.ability.extra.upg