The contents of a piggy bank are now capped, anything exceeding the limit is converted into a single holochip. (#90088)

## About The Pull Request
Piggy banks have a hard cap of 35 items. Anything beyond that is
crunched down into a single chip.

## Why It's Good For The Game
This prevents Lenald from making lag bombs with piggy banks. :^)

## Changelog

🆑
fix: The number of coins, chips or bills that can fit inside a piggy
bank is now capped, anything exceeding that amount is converted into a
single holochip.
/🆑
This commit is contained in:
Ghom
2025-03-19 19:42:54 +00:00
committed by GitHub
parent ee141fcaf0
commit efeb03304e
+29 -1
View File
@@ -49,14 +49,41 @@
SSticker.OnRoundend(persistence_cb)
if(initial_value && initial_value + calculate_dosh_amount() <= maximum_value)
new /obj/item/holochip(src, initial_value)
var/obj/item/holochip/chip = locate() in src
if(!chip)
new /obj/item/holochip(src, initial_value)
else
chip.credits += initial_value
chip.update_appearance()
if(maximum_savings_per_shift)
maximum_value = calculate_dosh_amount() + maximum_savings_per_shift
/obj/item/piggy_bank/proc/save_cash()
sanitize_piggy_bank_contents_len()
SSpersistence.save_piggy_bank(src)
#define MAXIMUM_PIGGY_BANK_CONTENTS_LENGTH 35
///This prevents the piggy bank from becoming laggy as hell if broken with hundred upon hundreds of chips inside it.
/obj/item/piggy_bank/proc/sanitize_piggy_bank_contents_len()
var/contents_len = length(contents)
if(contents_len <= MAXIMUM_PIGGY_BANK_CONTENTS_LENGTH)
return
// that +1 is to make space for the holochip with the collected amount
var/iterations = contents_len + 1 - MAXIMUM_PIGGY_BANK_CONTENTS_LENGTH
var/creds_amount = 0
for(var/i in 1 to iterations)
var/obj/item/money = pick(contents)
if(!istype(money)) // Very barebone safety for somethig that shouldn't happen just in case
continue // Yes, this means we lose an iteration, the code is that simple.
creds_amount += money.get_item_credit_value()
qdel(money)
if(creds_amount)
new /obj/item/holochip(src, creds_amount)
#undef MAXIMUM_PIGGY_BANK_CONTENTS_LENGTH
/obj/item/piggy_bank/Destroy()
if(persistence_cb)
LAZYREMOVE(SSticker.round_end_events, persistence_cb) //cleanup the callback.
@@ -112,6 +139,7 @@
balloon_alert(user, "stuck in your hands!")
else
balloon_alert(user, "inserted [creds_value] creds")
sanitize_piggy_bank_contents_len()
return TRUE
///Returns the total amount of credits that its contents amount to.