From 3b65ea47eafc9709a8a8bee654567ecf39c70288 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Wed, 3 Sep 2025 08:43:40 +0530 Subject: [PATCH] 2 minor enforcements for vending machines (#92752) ## About The Pull Request - Ensures vending machines don't runtime if the buyer dont have an ID card, valid account or department job. The UI usually disables itself when this is case but if this proc is called through other means we ensure no runtime occurs - Dispensing an item (like when the machine shoots out items/freebies/regular vending) always uses power & not just when buying the item through the UI ## Changelog :cl: code: adds some null checks against players without an ID card/valid account vending an item code: ensures dispensing an item always uses energy & not just when vending /:cl: --- code/modules/vending/vendor/inventory.dm | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/code/modules/vending/vendor/inventory.dm b/code/modules/vending/vendor/inventory.dm index f180058f8a6..11ed45c8272 100644 --- a/code/modules/vending/vendor/inventory.dm +++ b/code/modules/vending/vendor/inventory.dm @@ -168,6 +168,10 @@ if(isliving(user)) living_user = user card_used = living_user.get_idcard(TRUE) + if(QDELETED(card_used)) + speak("You do not possess an ID to purchase [item_record.name].") + return + if(age_restrictions && item_record.age_restricted && (!card_used.registered_age || card_used.registered_age < AGE_MINOR)) speak("You are not of legal age to purchase [item_record.name].") if(!(user in GLOB.narcd_underages)) @@ -190,7 +194,6 @@ purchase_message_cooldown = world.time + 5 SECONDS //This is not the best practice, but it's safe enough here since the chances of two people using a machine with the same ref in 5 seconds is fuck low last_shopper = REF(user) - use_energy(active_power_usage) if(icon_vend) //Show the vending animation if needed flick(icon_vend, src) @@ -226,16 +229,16 @@ var/obj/item/vended_item = null if(dispense_returned) vended_item = LAZYACCESS(item_record.returned_products, LAZYLEN(item_record.returned_products)) //first in, last out - if(!QDELETED(vended_item)) - vended_item.forceMove(spawn_location) + vended_item.forceMove(spawn_location) else if(item_record.amount) vended_item = new item_record.product_path(spawn_location) if(vended_item.type in contraband) ADD_TRAIT(vended_item, TRAIT_CONTRABAND, INNATE_TRAIT) item_record.amount-- - if(!QDELETED(vended_item)) - on_dispense(vended_item, dispense_returned) + on_dispense(vended_item, dispense_returned) + use_energy(active_power_usage) + return vended_item /** @@ -262,10 +265,13 @@ /obj/machinery/vending/proc/proceed_payment(obj/item/card/id/paying_id_card, mob/living/mob_paying, datum/data/vending_product/product_to_vend, price_to_use, discountless) PROTECTED_PROC(TRUE) - if(QDELETED(paying_id_card)) //not available(null) or somehow is getting destroyed - speak("You do not possess an ID to purchase [product_to_vend.name].") - return FALSE + //do we have an account with job to purchase var/datum/bank_account/account = paying_id_card.registered_account + if(!account || !account.account_job) //unregistered account & jobless + speak("Your do not have a valid account with an registered job.") + return FALSE + + //deduct money from person if(account.account_job && account.account_job.paycheck_department == payment_department && !discountless) price_to_use = max(round(price_to_use * DEPARTMENT_DISCOUNT), 1) //No longer free, but signifigantly cheaper. if(LAZYLEN(product_to_vend.returned_products)) @@ -274,7 +280,8 @@ speak("You do not possess the funds to purchase [product_to_vend.name].") flick(icon_deny,src) return FALSE - //actual payment here + + //transfer money to machine var/datum/bank_account/paying_id_account = SSeconomy.get_dep_account(payment_department) if(paying_id_account) SSblackbox.record_feedback("amount", "vending_spent", price_to_use)