From efeb03304e45b5c035b17afaf49f56b05e855271 Mon Sep 17 00:00:00 2001 From: Ghom <42542238+Ghommie@users.noreply.github.com> Date: Wed, 19 Mar 2025 20:42:54 +0100 Subject: [PATCH] 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 :cl: 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. /:cl: --- code/game/objects/items/piggy_bank.dm | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/code/game/objects/items/piggy_bank.dm b/code/game/objects/items/piggy_bank.dm index b6294dbc4dd..8b0af071fa4 100644 --- a/code/game/objects/items/piggy_bank.dm +++ b/code/game/objects/items/piggy_bank.dm @@ -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.