Skip to content

Commit

Permalink
[MIRROR] Fix a few vendor restocking bugs (#2910)
Browse files Browse the repository at this point in the history
* Fix a few vendor restocking bugs (#82603)

## About The Pull Request

So while working on fixing standard RPEDs working at all, I noticed they
weren't displaying parts when used on a vendor.
Looking into it, it seemed to be because the vendors just called
`display_parts(user)` on its own:

https://github.com/tgstation/tgstation/blob/1780fcef62e0413da65375a37f7c8030a0371419/code/modules/vending/_vending.dm#L1151
While other machinery would wrap it in a `to_chat(...)` call.

https://github.com/tgstation/tgstation/blob/1780fcef62e0413da65375a37f7c8030a0371419/code/game/machinery/_machinery.dm#L971
So, we do that too!

But then, during further testing, I noticed it wasn't actually
restocking. Ever. Even though it's calling the `restock(...)` proc with
the same inputs as you would do manually- oh. _oh._

https://github.com/tgstation/tgstation/blob/1780fcef62e0413da65375a37f7c8030a0371419/code/modules/vending/_vending.dm#L1152-L1154
It's checking the replacer for whether it's a refill canister, and not
the contents of it. Has been doing this for about 8 months, apparently.
No wonder it wasn't working.

Great! This should work, right? One more round of testing!
Aaaaand it doesn't actually pay out any credits when restocking this
way.
That's because it's *specifically* coded on `attackby(...)`.

https://github.com/tgstation/tgstation/blob/1780fcef62e0413da65375a37f7c8030a0371419/code/modules/vending/_vending.dm#L707-L715
Alright, well, we move this to a new `post_restock(...)` proc, and call
this whenever we're done doing restocks.
```dm
/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)
```
This is separate from the `restock(...)`, so we can call it when we're
_done_ restocking and need a message, rather than sending one for each
canister in our RPED. We can't just break the loop on the first fitting
canister, because the items we need might be spread over multiple
partially full canisters.

Third round of testing anyone? Oh hey infinite money glitch.
It seems like we never actually reset the `credits_contained` var after
paying out with it.
Soooo we just append this to our `post_restock(...)` proc, and be done
with it.
```dm
/obj/machinery/vending/proc/post_restock(mob/living/user, restocked)
	(...)
	try_put_in_hand(payday, user)
	credits_contained = 0
```

At this point, I felt it better we also reorganized the vendor
`exchange_parts(...)` to only have one `display_parts(...)` call and an
early return if we can't exchange parts.

Any further issues I could find I felt were outside of the scope, and
better off atomized into a separate pr.
## Why It's Good For The Game

Fixes RPEDs not working with vendors at all.
Fixes RPEDs not displaying vendor parts.
Fixes restocking vendors with an RPED not giving credits.
Fixes vendors not resetting their contained credits when restocked.
## Changelog
:cl:
fix: RPEDs can be used on vendors again. Note that only bluespace RPEDs
can carry vendor refills as of writing.
fix: RPEDs can display vendor parts again.
fix: Restocking vendors gives credits whether done manually or by RPEDs.
fix: Vendors reset their contained credits when restocked.
/:cl:

---------



* Fix a few vendor restocking bugs

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: _0Steven <[email protected]>
Co-authored-by: san7890 <[email protected]>
  • Loading branch information
4 people authored Apr 16, 2024
1 parent 8d2cd95 commit d8683b9
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions code/modules/vending/_vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d8683b9

Please sign in to comment.