From 2b740f9bad93ff08a4d15adf5a89140fabd4f8ae Mon Sep 17 00:00:00 2001 From: Ghommie <42542238+Ghommie@users.noreply.github.com> Date: Sun, 23 Feb 2020 13:09:21 +0100 Subject: [PATCH] [s] Fixing an issue with slot machines crashing the server. --- code/__HELPERS/global_lists.dm | 8 ++++++++ code/_globalvars/lists/objects.dm | 1 + code/game/machinery/slotmachine.dm | 20 +++++++++----------- code/modules/mining/ores_coins.dm | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/code/__HELPERS/global_lists.dm b/code/__HELPERS/global_lists.dm index 4190138335..da0032a839 100644 --- a/code/__HELPERS/global_lists.dm +++ b/code/__HELPERS/global_lists.dm @@ -93,6 +93,8 @@ init_subtypes(/datum/crafting_recipe, GLOB.crafting_recipes) + INVOKE_ASYNC(GLOBAL_PROC, /proc/init_ref_coin_values) //so the current procedure doesn't sleep because of UNTIL() + //creates every subtype of prototype (excluding prototype) and adds it to list L. //if no list/L is provided, one is created. /proc/init_subtypes(prototype, list/L) @@ -110,3 +112,9 @@ for(var/path in subtypesof(prototype)) L+= path return L + +/proc/init_ref_coin_values() + for(var/path in typesof(/obj/item/coin)) + var/obj/item/coin/C = new path + UNTIL(C.flags_1 & INITIALIZED_1) //we want to make sure the value is calculated and not null. + GLOB.coin_values[path] = C.value diff --git a/code/_globalvars/lists/objects.dm b/code/_globalvars/lists/objects.dm index 42fc163879..4de7c88bf7 100644 --- a/code/_globalvars/lists/objects.dm +++ b/code/_globalvars/lists/objects.dm @@ -32,6 +32,7 @@ GLOBAL_LIST_EMPTY(meteor_list) // List of all meteors. GLOBAL_LIST_EMPTY(active_jammers) // List of active radio jammers GLOBAL_LIST_EMPTY(ladders) GLOBAL_LIST_EMPTY(trophy_cases) +GLOBAL_LIST_EMPTY(coin_values) GLOBAL_LIST_EMPTY(wire_color_directory) GLOBAL_LIST_EMPTY(wire_name_directory) diff --git a/code/game/machinery/slotmachine.dm b/code/game/machinery/slotmachine.dm index 98c8ebcaad..115c61e9b9 100644 --- a/code/game/machinery/slotmachine.dm +++ b/code/game/machinery/slotmachine.dm @@ -26,7 +26,6 @@ var/working = 0 var/balance = 0 //How much money is in the machine, ready to be CONSUMED. var/jackpots = 0 - var/list/coinvalues = list() var/list/reels = list(list("", "", "") = 0, list("", "", "") = 0, list("", "", "") = 0, list("", "", "") = 0, list("", "", "") = 0) var/list/symbols = list(SEVEN = 1, "&" = 2, "@" = 2, "$" = 2, "?" = 2, "#" = 2, "!" = 2, "%" = 2) //if people are winning too much, multiply every number in this list by 2 and see if they are still winning too much. @@ -45,10 +44,6 @@ toggle_reel_spin(0) - for(var/cointype in typesof(/obj/item/coin)) - var/obj/item/coin/C = cointype - coinvalues["[cointype]"] = initial(C.value) - /obj/machinery/computer/slot_machine/Destroy() if(balance) give_coins(balance) @@ -294,19 +289,22 @@ return amount -/obj/machinery/computer/slot_machine/proc/dispense(amount = 0, cointype = /obj/item/coin/silver, mob/living/target, throwit = 0) - var/value = coinvalues["[cointype]"] +/obj/machinery/computer/slot_machine/proc/dispense(amount = 0, cointype = /obj/item/coin/silver, mob/living/target, throwit = FALSE) + var/value = GLOB.coin_values[cointype] || GLOB.coin_values[/obj/item/coin/iron] + INVOKE_ASYNC(src, .proc/become_rich, amount, value, cointype, target, throwit) + return amount % value - - while(amount >= value) +/obj/machinery/computer/slot_machine/proc/become_rich(amount, value, cointype = /obj/item/coin/silver, mob/living/target, throwit = FALSE) + if(value <= 0) + return + while(amount >= value && !QDELETED(src)) var/obj/item/coin/C = new cointype(loc) //DOUBLE THE PAIN amount -= value if(throwit && target) C.throw_at(target, 3, 10) else random_step(C, 2, 40) - - return amount + CHECK_TICK #undef SEVEN #undef SPIN_TIME diff --git a/code/modules/mining/ores_coins.dm b/code/modules/mining/ores_coins.dm index 7fc4728329..67c26abaef 100644 --- a/code/modules/mining/ores_coins.dm +++ b/code/modules/mining/ores_coins.dm @@ -326,6 +326,7 @@ GLOBAL_LIST_INIT(sand_recipes, list(\ var/cooldown = 0 var/value var/coinflip + item_flags = NO_MAT_REDEMPTION //You know, it's kind of a problem that money is worth more extrinsicly than intrinsically in this universe. /obj/item/coin/Initialize() . = ..()