Files
Bubberstation/code/datums/elements/uplink_reimburse.dm
T
0938c796a8 [MIRROR] Adds a signal to buying items from the uplink (& fixes TC misinfo) (#26449)
* Adds a signal to buying items from the uplink (& fixes TC misinfo) (#81372)

## About The Pull Request

Adds a signal when someone buys an item from the uplink and removes
single-letter vars from the ``spawn_item`` proc, and adds/standardizes
add/removing of telecrystals from uplinks (and admin setting how much TC
they have) to ensure the UI always has the right amount of telecrystals
displayed in it.

## Why It's Good For The Game

There are reasons why someone would want to hook up to a traitor's
uplink and listen to items they purchase to do any special effect
on-purchase, so this adds support to do anything in the future with it.
Also tells players how much TC they actually have without forcing them
to close/reopen the UI every time they insert some TC in it by hand.

## Changelog

🆑
fix: Uplinks now update their UI when you add telecrystals in them, so
you don't need to close and reopen it.
/🆑

* Adds a signal to buying items from the uplink (& fixes TC misinfo)

---------

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
2024-02-10 23:17:36 -05:00

58 lines
2.1 KiB
Plaintext

/**
* Uplink Reimburse element.
* When element is applied onto items, it allows them to be reimbursed if an user pokes an item with a uplink component with them.
*
* Element is only compatible with items.
*/
/datum/element/uplink_reimburse
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 1
/// TC to refund!
var/refundable_tc = 1
/datum/element/uplink_reimburse/Attach(datum/target, refundable_tc = 1)
. = ..()
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
src.refundable_tc = refundable_tc
RegisterSignal(target, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(target, COMSIG_ITEM_ATTEMPT_TC_REIMBURSE, PROC_REF(reimburse))
RegisterSignal(target,COMSIG_TRAITOR_ITEM_USED(target.type), PROC_REF(used))
/datum/element/uplink_reimburse/Detach(datum/target)
UnregisterSignal(target, list(COMSIG_ATOM_EXAMINE, COMSIG_TRAITOR_ITEM_USED(target.type), COMSIG_ITEM_ATTEMPT_TC_REIMBURSE))
return ..()
///signal called on parent being examined
/datum/element/uplink_reimburse/proc/on_examine(datum/target, mob/user, list/examine_list)
SIGNAL_HANDLER
if(!IS_TRAITOR(user) && !IS_NUKE_OP(user))
examine_list += span_warning("There's a label on the side, but it's written in indecipherable gibberish. You have no idea what it means!")
return
examine_list += span_notice("There's a label written in codespeak on the side, saying that this item can be refunded for [refundable_tc] by applying it onto an uplink.")
/datum/element/uplink_reimburse/proc/reimburse(obj/item/refund_item, mob/user, datum/component/uplink/uplink_comp)
SIGNAL_HANDLER
if(!uplink_comp)
CRASH("No uplink component in arguments detected")
to_chat(user, span_notice("You tap [uplink_comp.uplink_handler] with [refund_item], and a moment after [refund_item] disappears in a puff of red smoke!"))
do_sparks(2, source = uplink_comp.uplink_handler)
uplink_comp.uplink_handler.add_telecrystals(refundable_tc)
qdel(refund_item)
/// If the item is used, it needs to no longer be refundable
/datum/element/uplink_reimburse/proc/used(datum/target)
SIGNAL_HANDLER
Detach(target)