port of https://github.com/tgstation/tgstation/pull/49111 aka sales taggers, credit to ArcaneMusic

This commit is contained in:
shellspeed1
2022-09-18 20:55:22 -07:00
parent 3dace329be
commit b4f886d999
14 changed files with 299 additions and 5 deletions
+28
View File
@@ -0,0 +1,28 @@
/datum/component/pricetag
var/datum/bank_account/owner
var/profit_ratio = 1
/datum/component/pricetag/Initialize(_owner,_profit_ratio)
if(!isobj(parent)) //Has to account for both objects and sellable structures like crates.
return COMPONENT_INCOMPATIBLE
owner = _owner
if(_profit_ratio)
profit_ratio = _profit_ratio
RegisterSignal(parent, COMSIG_ITEM_SOLD, .proc/split_profit)
RegisterSignal(parent, COMSIG_STRUCTURE_UNWRAPPED, .proc/Unwrapped)
RegisterSignal(parent, COMSIG_ITEM_UNWRAPPED, .proc/Unwrapped)
RegisterSignal(parent, COMSIG_ITEM_SPLIT_PROFIT, .proc/return_ratio)
/datum/component/pricetag/proc/Unwrapped()
qdel(src) //Once it leaves it's wrapped container, the object in question should lose it's pricetag component.
/datum/component/pricetag/proc/split_profit(var/item_value)
var/price = item_value
if(price)
var/adjusted_value = price*(profit_ratio/100)
owner.adjust_money(adjusted_value)
owner.bank_card_talk("Sale recorded. [adjusted_value] credits added to account.")
return TRUE
/datum/component/pricetag/proc/return_ratio()
return profit_ratio