From 3d2f115dbf11098cfcb3f1240654b2f079dfc752 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 24 Jan 2022 19:30:08 +0100 Subject: [PATCH] [MIRROR] Fixes + expands vending machine returned purchases [MDB IGNORE] (#10954) * Fixes + expands vending machine returned purchases (#64314) Fixes vending machine returns, also makes it so you can return anything to (nearly) any vending machine. New stuff vends first. Secondhand stuff last. * Fixes + expands vending machine returned purchases Co-authored-by: cacogen <25089914+cacogen@users.noreply.github.com> --- code/modules/vending/_vending.dm | 52 ++++++++++++++++++++++++----- code/modules/vending/autodrobe.dm | 3 -- code/modules/vending/clothesmate.dm | 3 -- code/modules/vending/wardrobes.dm | 3 -- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index 2d4d6149ca0..9becf90a5d8 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -36,6 +36,8 @@ var/age_restricted = FALSE ///Whether the product can be recolored by the GAGS system var/colorable + ///List of items that have been returned to the vending machine. + var/list/returned_products /** * # vending machines @@ -278,6 +280,14 @@ found_anything = FALSE for(var/record in shuffle(product_records)) var/datum/data/vending_product/R = record + + //first dump any of the items that have been returned, in case they contain the nuke disk or something + for(var/obj/returned_obj_to_dump in R.returned_products) + LAZYREMOVE(R.returned_products, returned_obj_to_dump) + returned_obj_to_dump.forceMove(get_turf(src)) + step(returned_obj_to_dump, pick(GLOB.alldirs)) + R.amount-- + if(R.amount <= 0) //Try to use a record that actually has something to dump. continue var/dump_path = R.product_path @@ -288,8 +298,8 @@ if(found_anything && prob(80)) continue - var/obj/O = new dump_path(loc) - step(O, pick(GLOB.alldirs)) + var/obj/obj_to_dump = new dump_path(loc) + step(obj_to_dump, pick(GLOB.alldirs)) found_anything = TRUE dump_amount++ if (dump_amount >= 16) @@ -511,9 +521,13 @@ GLOBAL_LIST_EMPTY(vending_products) var/dump_path = R.product_path if(!dump_path) continue - + if(R.amount > LAZYLEN(R.returned_products)) //always give out new stuff that costs before free returned stuff, because of the risk getting gibbed involved + new dump_path(get_turf(src)) + else + var/obj/returned_obj_to_dump = LAZYACCESS(R.returned_products, LAZYLEN(R.returned_products)) //first in, last out + LAZYREMOVE(R.returned_products, returned_obj_to_dump) + returned_obj_to_dump.forceMove(get_turf(src)) R.amount-- - new dump_path(get_turf(src)) break ///Tilts ontop of the atom supplied, if crit is true some extra shit can happen. Returns TRUE if it dealt damage to something. @@ -646,11 +660,18 @@ GLOBAL_LIST_EMPTY(vending_products) . = TRUE if(!user.transferItemToLoc(I, src)) return FALSE + to_chat(user, span_notice("You insert [I] into [src]'s input compartment.")) + + for(var/datum/data/vending_product/product_datum in product_records + coin_records + hidden_records) + if(ispath(I.type, product_datum.product_path)) + product_datum.amount++ + LAZYADD(product_datum.returned_products, I) + return + if(vending_machine_input[format_text(I.name)]) vending_machine_input[format_text(I.name)]++ else vending_machine_input[format_text(I.name)] = 1 - to_chat(user, span_notice("You insert [I] into [src]'s input compartment.")) loaded_items++ /obj/machinery/vending/unbuckle_mob(mob/living/buckled_mob, force = FALSE, can_fall = TRUE) @@ -926,6 +947,8 @@ GLOBAL_LIST_EMPTY(vending_products) price_to_use = max(round(price_to_use * VENDING_DISCOUNT), 1) //No longer free, but signifigantly cheaper. if(coin_records.Find(R) || hidden_records.Find(R)) price_to_use = R.custom_premium_price ? R.custom_premium_price : extra_price + if(LAZYLEN(R.returned_products)) + price_to_use = 0 //returned items are free if(price_to_use && !account.adjust_money(-price_to_use)) say("You do not possess the funds to purchase [R.name].") flick(icon_deny,src) @@ -945,7 +968,13 @@ GLOBAL_LIST_EMPTY(vending_products) if(icon_vend) //Show the vending animation if needed flick(icon_vend,src) playsound(src, 'sound/machines/machine_vend.ogg', 50, TRUE, extrarange = -3) - var/obj/item/vended_item = new R.product_path(get_turf(src)) + var/obj/item/vended_item + if(!LAZYLEN(R.returned_products)) //always give out free returned stuff first, e.g. to avoid walling a traitor objective in a bag behind paid items + vended_item = new R.product_path(get_turf(src)) + else + vended_item = LAZYACCESS(R.returned_products, LAZYLEN(R.returned_products)) //first in, last out + LAZYREMOVE(R.returned_products, vended_item) + vended_item.forceMove(get_turf(src)) if(greyscale_colors) vended_item.set_greyscale(colors=greyscale_colors) R.amount-- @@ -1013,9 +1042,13 @@ GLOBAL_LIST_EMPTY(vending_products) var/dump_path = R.product_path if(!dump_path) continue - + if(R.amount > LAZYLEN(R.returned_products)) //always throw new stuff that costs before free returned stuff, because of the hacking effort and time between throws involved + throw_item = new dump_path(loc) + else + throw_item = LAZYACCESS(R.returned_products, LAZYLEN(R.returned_products)) //first in, last out + throw_item.forceMove(loc) + LAZYREMOVE(R.returned_products, throw_item) R.amount-- - throw_item = new dump_path(loc) break if(!throw_item) return FALSE @@ -1064,6 +1097,9 @@ GLOBAL_LIST_EMPTY(vending_products) * * user - the user doing the loading */ /obj/machinery/vending/proc/canLoadItem(obj/item/I, mob/user) + if((I.type in products) || (I.type in premium) || (I.type in contraband)) + return TRUE + to_chat(user, span_warning("[src] does not accept [I]!")) return FALSE /obj/machinery/vending/hitby(atom/movable/AM, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum) diff --git a/code/modules/vending/autodrobe.dm b/code/modules/vending/autodrobe.dm index 345675136b4..56aa0536188 100644 --- a/code/modules/vending/autodrobe.dm +++ b/code/modules/vending/autodrobe.dm @@ -165,9 +165,6 @@ payment_department = ACCOUNT_SRV light_mask="theater-light-mask" -/obj/machinery/vending/autodrobe/canLoadItem(obj/item/I,mob/user) - return (I.type in products) - /obj/machinery/vending/autodrobe/all_access desc = "A vending machine for costumes. This model appears to have no access restrictions." req_access = null diff --git a/code/modules/vending/clothesmate.dm b/code/modules/vending/clothesmate.dm index e18ad65582c..48a7e0b56ed 100644 --- a/code/modules/vending/clothesmate.dm +++ b/code/modules/vending/clothesmate.dm @@ -208,9 +208,6 @@ light_mask = "wardrobe-light-mask" light_color = LIGHT_COLOR_ELECTRIC_GREEN -/obj/machinery/vending/clothing/canLoadItem(obj/item/I,mob/user) - return (I.type in products) - /obj/item/vending_refill/clothing machine_name = "ClothesMate" icon_state = "refill_clothes" diff --git a/code/modules/vending/wardrobes.dm b/code/modules/vending/wardrobes.dm index 93c5052de6c..da9d876583a 100644 --- a/code/modules/vending/wardrobes.dm +++ b/code/modules/vending/wardrobes.dm @@ -9,9 +9,6 @@ panel_type = "panel19" light_mask = "wardrobe-light-mask" -/obj/machinery/vending/wardrobe/canLoadItem(obj/item/I,mob/user) - return (I.type in products) - /obj/machinery/vending/wardrobe/sec_wardrobe name = "\improper SecDrobe" desc = "A vending machine for security and security-related clothing!"