Skip to content

Commit

Permalink
Merge pull request #236 from Eremel/stake-update
Browse files Browse the repository at this point in the history
Stake update
  • Loading branch information
Aurelius7309 committed Aug 12, 2024
2 parents 76da138 + 3515470 commit 5ebe968
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 22 deletions.
61 changes: 39 additions & 22 deletions core/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -516,37 +516,42 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
inject = function(self)
if not self.injected then
-- Inject stake in the correct spot
local count = #G.P_CENTER_POOLS[self.set] + 1
self.count = #G.P_CENTER_POOLS[self.set] + 1
self.order = self.count
if self.above_stake then
count = G.P_STAKES[self.class_prefix .. "_" .. self.above_stake].stake_level + 1
self.order = G.P_STAKES[self.class_prefix .. "_" .. self.above_stake].order + 1
end
self.order = count
self.stake_level = count
for _, v in pairs(G.P_STAKES) do
if v.stake_level >= self.stake_level then
v.stake_level = v.stake_level + 1
v.order = v.stake_level
if v.order >= self.order then
v.order = v.order + 1
end
end
G.P_STAKES[self.key] = self
table.insert(G.P_CENTER_POOLS.Stake, self)
-- Sticker sprites (stake_ prefix is removed for vanilla compatiblity)
if self.sticker_pos ~= nil then
G.shared_stickers[self.key:sub(7)] = Sprite(0, 0, G.CARD_W, G.CARD_H,
G.ASSET_ATLAS[self.sticker_atlas] or G.ASSET_ATLAS["stickers"], self.sticker_pos)
G.sticker_map[self.stake_level] = self.key:sub(7)
G.ASSET_ATLAS[self.sticker_atlas] or G.ASSET_ATLAS["stickers"], self.sticker_pos)
G.sticker_map[self.key] = self.key:sub(7)
else
G.sticker_map[self.stake_level] = nil
G.sticker_map[self.key] = nil
end
else
G.P_STAKES[self.key] = self
table.insert(G.P_CENTER_POOLS.Stake, self)
end
self.injected = true
-- should only need to do this once per injection routine
G.P_CENTER_POOLS[self.set] = {}
for _, v in pairs(G.P_STAKES) do
SMODS.insert_pool(G.P_CENTER_POOLS[self.set], v)
end,
post_inject_class = function(self)
table.sort(G.P_CENTER_POOLS[self.set], function(a, b) return a.order < b.order end)
for _,stake in pairs(G.P_CENTER_POOLS.Stake) do
local applied = SMODS.build_stake_chain(stake)
stake.stake_level = 0
for i,_ in ipairs(G.P_CENTER_POOLS.Stake) do
if applied[i] then stake.stake_level = stake.stake_level+1 end
end
end
table.sort(G.P_CENTER_POOLS[self.set], function(a, b) return a.stake_level < b.stake_level end)
G.C.STAKES = {}
for i = 1, #G.P_CENTER_POOLS[self.set] do
G.C.STAKES[i] = G.P_CENTER_POOLS[self.set][i].colour or G.C.WHITE
Expand Down Expand Up @@ -579,13 +584,25 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
get_obj = function(self, key) return G.P_STAKES[key] end
}

function SMODS.setup_stake(i)
if G.P_CENTER_POOLS['Stake'][i].modifiers then
G.P_CENTER_POOLS['Stake'][i].modifiers()
function SMODS.build_stake_chain(stake, applied)
if not applied then applied = {} end
if not stake or applied[stake.order] then return end
applied[stake.order] = stake.order
if not stake.applied_stakes then
return
end
for _, s in pairs(stake.applied_stakes) do
SMODS.build_stake_chain(G.P_STAKES['stake_'..s], applied)
end
if G.P_CENTER_POOLS['Stake'][i].applied_stakes then
for _, v in pairs(G.P_CENTER_POOLS['Stake'][i].applied_stakes) do
SMODS.setup_stake(G.P_STAKES["stake_" .. v].stake_level)
return applied
end

function SMODS.setup_stake(i)
local applied_stakes = SMODS.build_stake_chain(G.P_CENTER_POOLS.Stake[i])
for stake, _ in pairs(applied_stakes) do
if G.P_CENTER_POOLS['Stake'][stake].modifiers then
sendDebugMessage("Applying "..G.P_CENTER_POOLS['Stake'][stake].key)
G.P_CENTER_POOLS['Stake'][stake].modifiers()
end
end
end
Expand Down Expand Up @@ -625,7 +642,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
pos = { x = 2, y = 0 },
sticker_pos = { x = 3, y = 0 },
modifiers = function()
G.GAME.modifiers.scaling = math.max(G.GAME.modifiers.scaling or 0, 2)
G.GAME.modifiers.scaling = (G.GAME.modifiers.scaling or 0) + 1
end,
colour = G.C.GREEN,
loc_txt = {}
Expand Down Expand Up @@ -664,7 +681,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
pos = { x = 0, y = 1 },
sticker_pos = { x = 1, y = 1 },
modifiers = function()
G.GAME.modifiers.scaling = math.max(G.GAME.modifiers.scaling or 0, 3)
G.GAME.modifiers.scaling = (G.GAME.modifiers.scaling or 0) + 1
end,
colour = G.C.PURPLE,
loc_txt = {}
Expand Down
61 changes: 61 additions & 0 deletions core/overrides.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1245,3 +1245,64 @@ G.FUNCS.your_collection_enhancements_page = function(args)
end
end
--#endregion

function get_joker_win_sticker(_center, index)
if G.PROFILES[G.SETTINGS.profile].joker_usage[_center.key] and G.PROFILES[G.SETTINGS.profile].joker_usage[_center.key].wins_by_key then
local _stake = nil
local _count = 0
for key, _ in pairs(G.PROFILES[G.SETTINGS.profile].joker_usage[_center.key].wins_by_key) do
_count = _count + 1
if (G.P_STAKES[key] and G.P_STAKES[key].stake_level or 0) > (_stake and G.P_STAKES[_stake].stake_level or 0) then
_stake = key
end
end
if index then return _stake and _count or 0 end
return G.sticker_map[_stake]
end
if index then return 0 end
end

function get_deck_win_stake(_deck_key)
if not _deck_key then
local _stake, _stake_low = nil, nil
local deck_count = 0
for _, deck in pairs(G.PROFILES[G.SETTINGS.profile].deck_usage) do
local deck_won_with = false
for key, _ in pairs(deck.wins_by_key) do
deck_won_with = true
if (G.P_STAKES[key] and G.P_STAKES[key].stake_level or 0) > (_stake and G.P_STAKES[_stake].stake_level or 0) then
_stake = key
end
end
if deck_won_with then deck_count = deck_count + 1 end
if not _stake_low then _stake_low = _stake end
if (G.P_STAKES[_stake] and G.P_STAKES[_stake].stake_level or 0) < (_stake_low and G.P_STAKES[_stake_low].stake_level or 0) then
_stake_low = _stake
end
end
return G.P_STAKES[_stake].order, (deck_count >= #G.P_CENTER_POOLS.Back and G.P_STAKES[_stake_low].order or 0)
end
if G.PROFILES[G.SETTINGS.profile].deck_usage[_deck_key] and G.PROFILES[G.SETTINGS.profile].deck_usage[_deck_key].wins_by_key then
local _stake = nil
for key, _ in pairs(G.PROFILES[G.SETTINGS.profile].deck_usage[_deck_key].wins_by_key) do
if (G.P_STAKES[key] and G.P_STAKES[key].stake_level or 0) > (_stake and G.P_STAKES[_stake].stake_level or 0) then
_stake = key
end
end
if _stake then return G.P_STAKES[_stake].order end
end
return 0
end

function get_deck_win_sticker(_center)
if G.PROFILES[G.SETTINGS.profile].deck_usage[_center.key] and
G.PROFILES[G.SETTINGS.profile].deck_usage[_center.key].wins_by_key then
local _stake = nil
for key, _ in pairs(G.PROFILES[G.SETTINGS.profile].deck_usage[_center.key].wins_by_key) do
if (G.P_STAKES[key] and G.P_STAKES[key].stake_level or 0) > (_stake and G.P_STAKES[_stake].stake_level or 0) then
_stake = key
end
end
if _stake then return G.sticker_map[_stake] end
end
end
55 changes: 55 additions & 0 deletions core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,59 @@ function SMODS.poll_seal(args)
end
end
end
end

function SMODS.get_blind_amount(ante)
local scale = G.GAME.modifiers.scaling
local amounts = {
300,
700 + 100*scale,
1400 + 600*scale,
2100 + 2900*scale,
15000 + 5000*scale*math.log(scale),
12000 + 8000*(scale+1)*(0.4*scale),
10000 + 25000*(scale+1)*((scale/4)^2),
50000 * (scale+1)^2 * (scale/7)^2
}

if ante < 1 then return 100 end
if ante <= 8 then return amounts[ante] - amounts[ante]%(10^math.floor(math.log10(amounts[ante])-1)) end
local a, b, c, d = amounts[8], amounts[8]/amounts[7], ante-8, 1 + 0.2*(ante-8)
local amount = math.floor(a*(b + (b*0.75*c)^d)^c)
amount = amount - amount%(10^math.floor(math.log10(amount)-1))
return amount
end

function SMODS.stake_from_index(index)
local stake = G.P_CENTER_POOLS.Stake[index] or nil
if not stake then return "error" end
return stake.key
end

function convert_save_data()
for k, v in pairs(G.PROFILES[G.SETTINGS.profile].deck_usage) do
if not v.wins_by_key and not v.losses_by_key then
v.wins_by_key = {}
for index, number in pairs(v.wins) do
v.wins_by_key[SMODS.stake_from_index(index)] = number
end
v.losses_by_key = {}
for index, number in pairs(v.losses) do
v.losses_by_key[SMODS.stake_from_index(index)] = number
end
end
end
for k, v in pairs(G.PROFILES[G.SETTINGS.profile].joker_usage) do
if not v.wins_by_key and not v.losses_by_key then
v.wins_by_key = {}
for index, number in pairs(v.wins) do
v.wins_by_key[SMODS.stake_from_index(index)] = number
end
v.losses_by_key = {}
for index, number in pairs(v.losses) do
v.losses_by_key[SMODS.stake_from_index(index)] = number
end
end
end
G:save_settings()
end
1 change: 1 addition & 0 deletions loader/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ end
local init_item_prototypes_ref = Game.init_item_prototypes
function Game:init_item_prototypes()
init_item_prototypes_ref(self)
convert_save_data()
if SMODS.booted then
SMODS.injectItems()
end
Expand Down
89 changes: 89 additions & 0 deletions lovely/stake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,93 @@ target = "functions/common_events.lua"
pattern = 'if highest_win >= 8 then'
position = "at"
payload = 'if highest_win >= G.P_STAKES["stake_gold"].stake_level then'
match_indent = true

# get_blind_amount
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'function get_blind_amount(ante)'
position = "after"
payload = '''if G.GAME.modifiers.scaling and G.GAME.modifiers.scaling > 3 then return SMODS.get_blind_amount(ante) end'''
match_indent = true

# set_joker_usage
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key] = {count = 1, order = v.config.center.order, wins = {}, losses = {}}'
position = "at"
payload = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key] = {count = 1, order = v.config.center.order, wins = {}, losses = {}, wins_by_key = {}, losses_by_key = {}}'
match_indent = true

# set_joker_win
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key] = G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key] or {count = 1, order = v.config.center.order, wins = {}, losses = {}}'
position = "at"
payload = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key] = G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key] or {count = 1, order = v.config.center.order, wins = {}, losses = {}, wins_by_key = {}, losses_by_key = {}}'
match_indent = true

#set_joker_win
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].wins[G.GAME.stake] = (G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].wins[G.GAME.stake] or 0) + 1'
position = "after"
payload = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].wins_by_key[SMODS.stake_from_index(G.GAME.stake)] = (G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].wins_by_key[SMODS.stake_from_index(G.GAME.stake)] or 0) + 1'
match_indent = true

#set_joker_loss
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].losses[G.GAME.stake] = (G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].losses[G.GAME.stake] or 0) + 1'
position = "after"
payload = 'G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].losses_by_key[SMODS.stake_from_index(G.GAME.stake)] = (G.PROFILES[G.SETTINGS.profile].joker_usage[v.config.center_key].losses_by_key[SMODS.stake_from_index(G.GAME.stake)] or 0) + 1'
match_indent = true

#set_deck_usage
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key] = {count = 1, order = G.GAME.selected_back.effect.center.order, wins = {}, losses = {}}'
position = "at"
payload = 'G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key] = {count = 1, order = G.GAME.selected_back.effect.center.order, wins = {}, losses = {}, wins_by_key = {}, losses_by_key = {}}'
match_indent = true

#set_deck_win
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'if not G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key] then G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key] = {count = 1, order = G.GAME.selected_back.effect.center.order, wins = {}, losses = {}} end'
position = "at"
payload = 'if not G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key] then G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key] = {count = 1, order = G.GAME.selected_back.effect.center.order, wins = {}, losses = {}, wins_by_key = {}, losses_by_key = {}} end'
match_indent = true

#set_deck_win
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].wins[G.GAME.stake] = (G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].wins[G.GAME.stake] or 0) + 1'
position = "after"
payload = 'G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].wins_by_key[SMODS.stake_from_index(G.GAME.stake)] = (G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].wins_by_key[SMODS.stake_from_index(G.GAME.stake)] or 0) + 1'
match_indent = true

#set_deck_win
[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].losses[G.GAME.stake] = (G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].losses[G.GAME.stake] or 0) + 1'
position = "after"
payload = 'G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].losses_by_key[SMODS.stake_by_index(G.GAME.stake)] = (G.PROFILES[G.SETTINGS.profile].deck_usage[deck_key].losses_by_key[SMODS.stake_by_index(G.GAME.stake)] or 0) + 1'
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = 'G.viewed_stake = math.min(max_stake+1, G.viewed_stake)'
position = "after"
payload = '''if G.viewed_stake > #G.P_CENTER_POOLS.Stake then G.viewed_stake = #G.P_CENTER_POOLS.Stake end'''
match_indent = true

0 comments on commit 5ebe968

Please sign in to comment.