Skip to content

Commit

Permalink
cook capitalism (#22852)
Browse files Browse the repository at this point in the history
  • Loading branch information
ynot01 authored Dec 16, 2024
1 parent 201a9b7 commit c70ea40
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
52 changes: 47 additions & 5 deletions code/modules/vending/_vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ IF YOU MODIFY THE PRODUCTS LIST OF A MACHINE, MAKE SURE TO UPDATE ITS RESUPPLY C
/// used for narcing on underages
var/obj/item/radio/alertradio

/// payout account (weakref) for custom items
var/datum/weakref/custom_payout_account

/obj/item/circuitboard
///determines if the circuit board originated from a vendor off station or not.
var/onstation = TRUE
Expand Down Expand Up @@ -288,6 +291,17 @@ IF YOU MODIFY THE PRODUCTS LIST OF A MACHINE, MAKE SURE TO UPDATE ITS RESUPPLY C
return
set_light(powered() ? MINIMUM_USEFUL_LIGHT_RANGE : 0)

/obj/machinery/vending/update_desc()
. = ..()
desc = initial(desc)
if(custom_payout_account)
var/datum/bank_account/account = custom_payout_account.resolve()
if(istype(account))
desc += "\n"
desc += span_notice("Custom orders are paid out to <b>[account.account_holder]</b>.")
desc += "\n"
desc += span_notice("Custom orders are priced at <b>[chef_price]</b> credits.")

/obj/machinery/vending/update_icon_state()
if(stat & BROKEN)
icon_state = "[initial(icon_state)]-broken"
Expand Down Expand Up @@ -657,6 +671,28 @@ GLOBAL_LIST_EMPTY(vending_products)
P.amount++
loaded_items++

if(custom_payout_account && custom_payout_account.resolve())
return

var/obj/item/card/id/id_card = user.get_idcard()
if(!istype(id_card))
return

var/datum/bank_account/account = id_card.registered_account
if(!istype(account))
return

custom_payout_account = WEAKREF(account)
// at the time of writing, tgui_input_number is nonfunctional
// 10s timeout so people cant change price while a customer is shopping
tgui_input_text_async(user, "Set a price for custom items (1-9999)", "Custom Price", "10", 4, FALSE, CALLBACK(src, PROC_REF(chef_price_update)), 10 SECONDS)

/obj/machinery/vending/proc/chef_price_update(entry)
var/input_text = text2num(entry)
if(isnum(input_text) && input_text >= 1 && input_text <= 9999)
chef_price = input_text
update_desc()

/obj/machinery/vending/exchange_parts(mob/user, obj/item/storage/part_replacer/W)
if(!istype(W))
return FALSE
Expand Down Expand Up @@ -884,7 +920,7 @@ GLOBAL_LIST_EMPTY(vending_products)
vend_ready = FALSE //One thing at a time!!

// Charge the user
if (!charge_user(chef_price, P.full_name, FALSE))
if (!charge_user(chef_price, P.full_name, TRUE, TRUE))
vend_ready = TRUE
return

Expand All @@ -905,7 +941,7 @@ GLOBAL_LIST_EMPTY(vending_products)
* Charge the user during a vend
* Returns false if the user could not buy this item
*/
/obj/machinery/vending/proc/charge_user(price, item_name, always_charge)
/obj/machinery/vending/proc/charge_user(price, item_name, always_charge, pay_custom = FALSE)
var/mob/living/L
if(isliving(usr))
L = usr
Expand All @@ -929,9 +965,15 @@ GLOBAL_LIST_EMPTY(vending_products)
say("You do not possess the funds to purchase \the [item_name].")
flick(icon_deny,src)
return FALSE
var/datum/bank_account/D = SSeconomy.get_dep_account(payment_department)
if(D)
D.adjust_money(price)
if(pay_custom)
var/datum/bank_account/custom_account = custom_payout_account.resolve()
if(istype(custom_account))
custom_account.adjust_money(price)
custom_account.bank_card_talk("\A [item_name] was purchased for [price] credits!")
else
var/datum/bank_account/D = SSeconomy.get_dep_account(payment_department)
if(D)
D.adjust_money(price)

return TRUE

Expand Down
12 changes: 1 addition & 11 deletions tgui/packages/tgui/interfaces/Vending.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ const VendingRow = (props, context) => {
// yogs end
);

const customFree = (
!data.onstation
|| (
data.user
&& data.department
&& data.department === data.user.department
)
|| data.ignores_capitalism
);

return (
<Table.Row>
<Table.Cell collapsing>
Expand Down Expand Up @@ -80,7 +70,7 @@ const VendingRow = (props, context) => {
|| !data.user
|| (!free && product.price > data.user.cash)
)}
content={customFree ? 'FREE' : product.price + ' cr'}
content={product.price + ' cr'}
onClick={() => act('vend_custom', {
'item': product.name,
})} />
Expand Down

0 comments on commit c70ea40

Please sign in to comment.