diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index d4f385f7363..913f3f3fcb8 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -548,6 +548,28 @@ GLOBAL_LIST_EMPTY(vending_machines_to_restock) return . +/** + * After-effects of refilling a vending machine from a refill canister + * + * This takes the amount of products restocked and gives the user our contained credits if needed, + * sending the user a fitting message. + * + * Arguments: + * * user - the user restocking us + * * restocked - the amount of items we've been refilled with + */ +/obj/machinery/vending/proc/post_restock(mob/living/user, restocked) + if(!restocked) + to_chat(user, span_warning("There's nothing to restock!")) + return + + to_chat(user, span_notice("You loaded [restocked] items in [src][credits_contained > 0 ? ", and are rewarded [credits_contained] credits." : "."]")) + var/datum/bank_account/cargo_account = SSeconomy.get_dep_account(ACCOUNT_CAR) + cargo_account.adjust_money(round(credits_contained * 0.5), "Vending: Restock") + var/obj/item/holochip/payday = new(src, credits_contained) + try_put_in_hand(payday, user) + credits_contained = 0 + /** * Refill our inventory from the passed in product list into the record list * @@ -704,15 +726,8 @@ GLOBAL_LIST_EMPTY(vending_machines_to_restock) to_chat(user, span_warning("[canister] is empty!")) else // instantiate canister if needed - var/transferred = restock(canister) - if(transferred) - to_chat(user, span_notice("You loaded [transferred] items in [src][credits_contained > 0 ? ", and are rewarded [credits_contained] credits." : "."]")) - var/datum/bank_account/cargo_account = SSeconomy.get_dep_account(ACCOUNT_CAR) - cargo_account.adjust_money(round(credits_contained * 0.5), "Vending: Restock") - var/obj/item/holochip/payday = new(src, credits_contained) - try_put_in_hand(payday, user) - else - to_chat(user, span_warning("There's nothing to restock!")) + var/restocked = restock(canister) + post_restock(user, restocked) return if(compartmentLoadAccessCheck(user) && !user.combat_mode) @@ -1145,17 +1160,18 @@ GLOBAL_LIST_EMPTY(vending_machines_to_restock) if(!component_parts || !refill_canister) return FALSE - var/moved = 0 - if(panel_open || replacer.works_from_distance) - if(replacer.works_from_distance) - display_parts(user) - for(var/replacer_item in replacer) - if(istype(replacer, refill_canister)) - moved += restock(replacer_item) - else - display_parts(user) - if(moved) - to_chat(user, span_notice("[moved] items restocked.")) + if(!panel_open || replacer.works_from_distance) + to_chat(user, display_parts(user)) + + if(!panel_open && !replacer.works_from_distance) + return FALSE + + var/restocked = 0 + for(var/replacer_item in replacer) + if(istype(replacer_item, refill_canister)) + restocked += restock(replacer_item) + post_restock(user, restocked) + if(restocked > 0) replacer.play_rped_sound() return TRUE