Skip to content

Commit 45036a5

Browse files
committed
caeruleum uses SMODS.calculate_individual_effect
1 parent d028ad4 commit 45036a5

File tree

1 file changed

+109
-47
lines changed

1 file changed

+109
-47
lines changed

items/exotic.lua

Lines changed: 109 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,41 +1681,78 @@ local caeruleum = {
16811681
object_type = "Joker",
16821682
name = "cry-Caeruleum",
16831683
key = "caeruleum",
1684-
config = {
1684+
1685+
-- this is just hardcoded because it's kinda unavoidable
1686+
--[[config = {
16851687
immutable = {
16861688
max_op = 3,
16871689
},
1688-
},
1690+
},]]
16891691

16901692
init = function(self)
1691-
-- this is probably not a very good way of doing this but uh it's how i did it
1692-
local ccj = Card.calculate_joker
1693-
function Card:calculate_joker(context, ...)
1694-
local ret = ccj(self, context, ...)
1695-
1696-
local left_joker = nil
1697-
local right_joker = nil
1693+
local scie = SMODS.calculate_individual_effect
1694+
function SMODS.calculate_individual_effect(effect, scored_card, key, amount, from_edition, ...)
1695+
local card = effect.card or scored_card
1696+
local caeruleum_messages = {}
16981697

1699-
if #SMODS.find_card("j_cry_caeruleum") >= 1 then
1700-
-- find caeruleum, call its function if it exists
1698+
if Cryptid.safe_get(card, "ability", "cry_caeruleum") then
17011699
for i = 1, #G.jokers.cards do
1702-
if G.jokers.cards[i] == self then
1703-
left_joker = G.jokers.cards[i - 1]
1704-
right_joker = G.jokers.cards[i + 1]
1700+
if G.jokers.cards[i] == card then
1701+
for _, b in ipairs(card.ability.cry_caeruleum) do
1702+
local caeruleum = G.jokers.cards[i + (b and 1 or -1)]
1703+
print(i + (b and 1 or -1))
1704+
local was_key_changed, new_key, op = Cryptid.caeruleum_new_key(key)
1705+
1706+
-- change the key!
1707+
if was_key_changed then
1708+
key = new_key
1709+
1710+
-- no _mod returns because i hate them
1711+
-- effect.remove_default_message = (key:sub(-4) == "_mod")
1712+
1713+
-- create a new message for caeruleum to display
1714+
local chipsMessageKeys = {
1715+
"a_chips",
1716+
"a_xchips",
1717+
"a_powchips",
1718+
}
1719+
1720+
-- these get run through card_eval_status_text AFTER the normal calculate_individual_effect runs
1721+
caeruleum_messages[#caeruleum_messages+1] = {
1722+
caeruleum,
1723+
"extra",
1724+
nil,
1725+
percent,
1726+
nil,
1727+
{
1728+
message = localize({
1729+
type = "variable",
1730+
key = chipsMessageKeys[op],
1731+
vars = {
1732+
number_format(amount),
1733+
},
1734+
}),
1735+
focus = caeruleum,
1736+
sound = 'chips1',
1737+
}
1738+
}
1739+
end
1740+
end
17051741
end
17061742
end
1743+
end
17071744

1708-
-- with supercell, 2 copies will only give ^15 instead of ^30 due to the ^2 from the first one being overridden
1709-
-- fixing this would be very hard
1710-
if left_joker and left_joker.config.center.key == "j_cry_caeruleum" then
1711-
ret = Cryptid.caeruleum_mod_chips(ret, left_joker)
1712-
end
1745+
-- run normal function
1746+
local ret = scie(effect, scored_card, key, amount, from_edition, ...)
17131747

1714-
if right_joker and right_joker.config.center.key == "j_cry_caeruleum" then
1715-
ret = Cryptid.caeruleum_mod_chips(ret, right_joker)
1748+
-- display caeruleum messages
1749+
if #caeruleum_messages > 0 then
1750+
for _, msg in ipairs(caeruleum_messages) do
1751+
card_eval_status_text(unpack(msg))
17161752
end
17171753
end
17181754

1755+
-- return result
17191756
return ret
17201757
end
17211758
end,
@@ -1733,7 +1770,39 @@ local caeruleum = {
17331770
vars = {},
17341771
}
17351772
end,
1736-
calculate = function(self, card, context) end,
1773+
calculate = function(self, card, context)
1774+
-- used to "mark" jokers to be affected by caeruleum
1775+
if context.before and context.cardarea == G.jokers then
1776+
local left_joker = nil
1777+
local right_joker = nil
1778+
1779+
for i = 1, #G.jokers.cards do
1780+
if G.jokers.cards[i] == card then
1781+
left_joker = G.jokers.cards[i - 1]
1782+
right_joker = G.jokers.cards[i + 1]
1783+
end
1784+
end
1785+
1786+
-- allows caeruleum to stack
1787+
-- boolean value is true if the joker was to the left of caeruleum (so caeruleum is to the right of it)
1788+
if left_joker and left_joker.config.center.key ~= "j_cry_caeruleum" then
1789+
left_joker.ability.cry_caeruleum = left_joker.ability.cry_caeruleum or {}
1790+
left_joker.ability.cry_caeruleum[#left_joker.ability.cry_caeruleum+1] = true
1791+
end
1792+
1793+
if right_joker and right_joker.config.center.key ~= "j_cry_caeruleum" then
1794+
right_joker.ability.cry_caeruleum = right_joker.ability.cry_caeruleum or {}
1795+
right_joker.ability.cry_caeruleum[#right_joker.ability.cry_caeruleum+1] = false
1796+
end
1797+
end
1798+
1799+
if context.after and context.cardarea == G.jokers then
1800+
-- reset this on every joker just to avoid weird bugs
1801+
for i = 1, #G.jokers.cards do
1802+
G.jokers.cards[i].ability.cry_caeruleum = nil
1803+
end
1804+
end
1805+
end,
17371806
cry_credits = {
17381807
idea = { "HexaCryonic" },
17391808
art = { "Tatteredlurker" },
@@ -1775,36 +1844,29 @@ local chipsReturnOperators = {
17751844
"echips",
17761845
}
17771846

1778-
local chipsMessageKeys = {
1779-
"a_chips",
1780-
"a_xchips",
1781-
"a_powchips",
1782-
}
1783-
1784-
function Cryptid.caeruleum_mod_chips(effect, caeruleum)
1785-
if not SMODS.Calculation_Controls.chips or not effect or not next(effect) then
1786-
return
1787-
end
1788-
1789-
local new_effect = SMODS.shallow_copy(effect)
1790-
1791-
-- recursively go down extra tables
1792-
if effect.extra then
1793-
new_effect.extra = Cryptid.caeruleum_mod_chips(effect.extra)
1847+
--- Handles Caeruleum's operator increase.
1848+
--- @param key string The key being checked.
1849+
--- @return boolean was_key_changed Whether the key was actually changed.
1850+
--- @return string new_key The new key if it was changed, or old one if it wasn't.
1851+
--- @return integer? op The new operator's position in the hyperoperation sequence. `nil` if the key wasn't changed.\n(1 is addition, 2 is multiplication, 3 is exponentiation)
1852+
function Cryptid.caeruleum_new_key(key)
1853+
if not SMODS.Calculation_Controls.chips or not key then
1854+
return false, key
17941855
end
17951856

17961857
for _, op in ipairs(chipsOperators) do
1797-
for _, key in pairs(op.keys) do
1798-
if effect[key] then
1799-
new_effect[key] = nil
1858+
for _, key2 in pairs(op.keys) do
1859+
if key == key2 then
18001860
local op2 = math.max(1, math.min(op.operation + 1, 3))
1801-
new_effect[chipsReturnOperators[op2]] = effect[key]
1861+
local new_key = chipsReturnOperators[op2]
1862+
1863+
return true, new_key, op2
18021864

1803-
if key:sub(-4) == "_mod" then
1865+
--[[if key:sub(-4) == "_mod" then
18041866
new_effect.remove_default_message = true
1805-
end
1867+
end]]
18061868

1807-
new_effect = SMODS.merge_effects({
1869+
--[[new_effect = SMODS.merge_effects({
18081870
new_effect,
18091871
{
18101872
message = localize({
@@ -1817,12 +1879,12 @@ function Cryptid.caeruleum_mod_chips(effect, caeruleum)
18171879
card = caeruleum,
18181880
focus = caeruleum,
18191881
},
1820-
})
1882+
})]]
18211883
end
18221884
end
18231885
end
18241886

1825-
return new_effect
1887+
return false, key
18261888
end
18271889

18281890
local items = {

0 commit comments

Comments
 (0)