ports https://github.com/tgstation/tgstation/pull/56375. Credit to cacogen.
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
/datum/component/pricetag
|
||||
var/datum/bank_account/owner
|
||||
var/profit_ratio = 1
|
||||
///Payee gets 100% of the value if no ratio has been set.
|
||||
var/default_profit_ratio = 1
|
||||
///List of bank accounts this pricetag pays out to. Format is payees[bank_account] = profit_ratio.
|
||||
var/list/payees = list()
|
||||
|
||||
|
||||
/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
|
||||
payees[_owner] = _profit_ratio
|
||||
else
|
||||
payees[_owner] = default_profit_ratio
|
||||
RegisterSignal(parent, COMSIG_ITEM_SOLD, .proc/split_profit)
|
||||
RegisterSignal(parent, COMSIG_STRUCTURE_UNWRAPPED, .proc/Unwrapped)
|
||||
RegisterSignal(parent, COMSIG_ITEM_UNWRAPPED, .proc/Unwrapped)
|
||||
@@ -19,10 +23,13 @@
|
||||
/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.")
|
||||
for(var/datum/bank_account/payee in payees)
|
||||
var/profit_ratio = payees[payee]
|
||||
var/adjusted_value = price * profit_ratio
|
||||
var/datum/bank_account/bank_account = payee
|
||||
bank_account.adjust_money(adjusted_value)
|
||||
bank_account.bank_card_talk("Sale of [parent] recorded. [adjusted_value] credits added to account.")
|
||||
return TRUE
|
||||
|
||||
/datum/component/pricetag/proc/return_ratio()
|
||||
return profit_ratio
|
||||
return default_profit_ratio
|
||||
|
||||
Reference in New Issue
Block a user