Skip to content

Commit 7a5e986

Browse files
authored
Merge pull request #793 from InvalidOS/caeruleum_fix
Fix/optimize Caeruleum
2 parents d028ad4 + 4f91b1b commit 7a5e986

File tree

1 file changed

+101
-64
lines changed

1 file changed

+101
-64
lines changed

items/exotic.lua

Lines changed: 101 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,41 +1681,72 @@ local caeruleum = {
16811681
object_type = "Joker",
16821682
name = "cry-Caeruleum",
16831683
key = "caeruleum",
1684-
config = {
1685-
immutable = {
1686-
max_op = 3,
1687-
},
1688-
},
16891684

1690-
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, ...)
1685+
config = {},
16951686

1696-
local left_joker = nil
1697-
local right_joker = nil
1687+
init = function(self)
1688+
local scie = SMODS.calculate_individual_effect
1689+
function SMODS.calculate_individual_effect(effect, scored_card, key, amount, from_edition, ...)
1690+
local card = effect.card or scored_card
1691+
local caeruleum_messages = {}
16981692

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

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
1739+
-- run normal function
1740+
local ret = scie(effect, scored_card, key, amount, from_edition, ...)
17131741

1714-
if right_joker and right_joker.config.center.key == "j_cry_caeruleum" then
1715-
ret = Cryptid.caeruleum_mod_chips(ret, right_joker)
1742+
-- display caeruleum messages
1743+
if #caeruleum_messages > 0 then
1744+
for _, msg in ipairs(caeruleum_messages) do
1745+
card_eval_status_text(unpack(msg))
17161746
end
17171747
end
17181748

1749+
-- return result
17191750
return ret
17201751
end
17211752
end,
@@ -1733,7 +1764,39 @@ local caeruleum = {
17331764
vars = {},
17341765
}
17351766
end,
1736-
calculate = function(self, card, context) end,
1767+
calculate = function(self, card, context)
1768+
-- used to "mark" jokers to be affected by caeruleum
1769+
if context.before and context.cardarea == G.jokers then
1770+
local left_joker = nil
1771+
local right_joker = nil
1772+
1773+
for i = 1, #G.jokers.cards do
1774+
if G.jokers.cards[i] == card then
1775+
left_joker = G.jokers.cards[i - 1]
1776+
right_joker = G.jokers.cards[i + 1]
1777+
end
1778+
end
1779+
1780+
-- allows caeruleum to stack
1781+
-- boolean value is true if the joker was to the left of caeruleum (so caeruleum is to the right of it)
1782+
if left_joker and left_joker.config.center.key ~= "j_cry_caeruleum" then
1783+
left_joker.ability.cry_caeruleum = left_joker.ability.cry_caeruleum or {}
1784+
left_joker.ability.cry_caeruleum[#left_joker.ability.cry_caeruleum+1] = true
1785+
end
1786+
1787+
if right_joker and right_joker.config.center.key ~= "j_cry_caeruleum" then
1788+
right_joker.ability.cry_caeruleum = right_joker.ability.cry_caeruleum or {}
1789+
right_joker.ability.cry_caeruleum[#right_joker.ability.cry_caeruleum+1] = false
1790+
end
1791+
end
1792+
1793+
if context.after and context.cardarea == G.jokers then
1794+
-- reset this on every joker just to avoid weird bugs
1795+
for i = 1, #G.jokers.cards do
1796+
G.jokers.cards[i].ability.cry_caeruleum = nil
1797+
end
1798+
end
1799+
end,
17371800
cry_credits = {
17381801
idea = { "HexaCryonic" },
17391802
art = { "Tatteredlurker" },
@@ -1775,54 +1838,28 @@ local chipsReturnOperators = {
17751838
"echips",
17761839
}
17771840

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)
1841+
--- Handles Caeruleum's operator increase.
1842+
--- @param key string The key being checked.
1843+
--- @return boolean was_key_changed Whether the key was actually changed.
1844+
--- @return string new_key The new key if it was changed, or old one if it wasn't.
1845+
--- @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)
1846+
function Cryptid.caeruleum_new_key(key)
1847+
if not SMODS.Calculation_Controls.chips or not key then
1848+
return false, key
17941849
end
17951850

17961851
for _, op in ipairs(chipsOperators) do
1797-
for _, key in pairs(op.keys) do
1798-
if effect[key] then
1799-
new_effect[key] = nil
1852+
for _, key2 in pairs(op.keys) do
1853+
if key == key2 then
18001854
local op2 = math.max(1, math.min(op.operation + 1, 3))
1801-
new_effect[chipsReturnOperators[op2]] = effect[key]
1855+
local new_key = chipsReturnOperators[op2]
18021856

1803-
if key:sub(-4) == "_mod" then
1804-
new_effect.remove_default_message = true
1805-
end
1806-
1807-
new_effect = SMODS.merge_effects({
1808-
new_effect,
1809-
{
1810-
message = localize({
1811-
type = "variable",
1812-
key = chipsMessageKeys[op2],
1813-
vars = {
1814-
number_format(effect[key]),
1815-
},
1816-
}),
1817-
card = caeruleum,
1818-
focus = caeruleum,
1819-
},
1820-
})
1857+
return true, new_key, op2
18211858
end
18221859
end
18231860
end
18241861

1825-
return new_effect
1862+
return false, key
18261863
end
18271864

18281865
local items = {

0 commit comments

Comments
 (0)