Skip to content

Commit

Permalink
Merge pull request #23 from Lhars/Treasury-Updates
Browse files Browse the repository at this point in the history
Treasury Updates
  • Loading branch information
TheGreatKitsune authored Sep 29, 2024
2 parents 756bddf + 256e131 commit d4ecd6a
Showing 1 changed file with 81 additions and 78 deletions.
159 changes: 81 additions & 78 deletions code/controllers/subsystem/rogue/treasury.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SUBSYSTEM_DEF(treasury)
var/interest_rate = 0.25
var/next_treasury_check = 0
var/list/log_entries = list()
var/list/vault_accounting = list() //used for the vault count, cleared every fire()


/datum/controller/subsystem/treasury/Initialize()
Expand All @@ -52,7 +53,7 @@ SUBSYSTEM_DEF(treasury)
/datum/controller/subsystem/treasury/fire(resumed = 0)
if(world.time > next_treasury_check)
next_treasury_check = world.time + rand(5 MINUTES, 8 MINUTES)
var/list/stockpile_items = list()
vault_accounting = list()
if(SSticker.current_state == GAME_STATE_PLAYING)
for(var/datum/roguestock/X in stockpile_datums)
if(!X.stable_price && !X.transport_item)
Expand All @@ -68,27 +69,25 @@ SUBSYSTEM_DEF(treasury)
for(var/obj/item/I in A)
if(!isturf(I.loc))
continue
if(I.get_real_price() <= 0 || istype(I, /obj/item/roguecoin))
continue
if(!I.submitted_to_stockpile)
I.submitted_to_stockpile = TRUE
if(I.type in stockpile_items)
stockpile_items[I.type] *= multiple_item_penalty
else
stockpile_items[I.type] = I.get_real_price()
amt_to_generate += (stockpile_items[I.type]*interest_rate)
amt_to_generate += add_to_vault(I)
for(var/obj/structure/closet/C in A)
for(var/obj/item/I in C.contents)
amt_to_generate += add_to_vault(I)
amt_to_generate = amt_to_generate - (amt_to_generate * queens_tax)
amt_to_generate = round(amt_to_generate)
give_money_treasury(amt_to_generate, "wealth horde")
var/people_told = 0
for(var/mob/living/carbon/human/X in GLOB.human_list)
switch(X.job)
if("Monarch", "Steward", "Clerk")
people_told += 1
send_ooc_note("Income from wealth horde: +[amt_to_generate]", name = X.real_name)
if(people_told > 3)
return
give_money_treasury(amt_to_generate, "wealth hoard")
send_ooc_note("Income from wealth hoard: +[amt_to_generate]", job = list("Monarch", "Steward", "Clerk"))

/datum/controller/subsystem/treasury/proc/add_to_vault(var/obj/item/I)
if(I.get_real_price() <= 0 || istype(I, /obj/item/roguecoin))
return
if(!I.submitted_to_stockpile)
I.submitted_to_stockpile = TRUE
if(I.type in vault_accounting)
vault_accounting[I.type] *= multiple_item_penalty
else
vault_accounting[I.type] = I.get_real_price()
return (vault_accounting[I.type]*interest_rate)

/datum/controller/subsystem/treasury/proc/create_bank_account(name, initial_deposit)
if(!name)
Expand All @@ -113,50 +112,54 @@ SUBSYSTEM_DEF(treasury)
log_to_steward("+[amt] to treasury")

//pays to account from treasury (payroll)
/datum/controller/subsystem/treasury/proc/give_money_account(amt, name, source)
if(!amt)
return
if(!name)
return
var/found_account
if (amt > treasury_value) // Check if the amount exceeds the treasury balance
send_ooc_note("<b>The Bank:</b> Error: Insufficient funds in the treasury to complete the transaction.", name = name)
return FALSE // Return early if the treasury balance is insufficient
for(var/X in bank_accounts)
if(X == name)
if(amt > 0)
bank_accounts[X] += amt // Deposit the money into the player's account
treasury_value -= amt // Deduct the given amount from the treasury
else
// Check if the amount to be fined exceeds the player's account balance
if(abs(amt) > bank_accounts[X])
send_ooc_note("<b>The Bank:</b> Error: Insufficient funds in the player's account to complete the fine.", name = name)
return FALSE // Return early if the player has insufficient funds
bank_accounts[X] -= abs(amt) // Deduct the fine amount from the player's account
treasury_value += abs(amt) // Add the fined amount to the treasury
found_account = TRUE
break
if(!found_account)
return FALSE

if (amt > 0)
// Player received money
if(source)
send_ooc_note("<b>The Bank:</b> You received money. ([source])", name = name)
log_to_steward("+[amt] from treasury to [name] ([source])")
else
send_ooc_note("<b>The Bank:</b> You received money.", name = name)
log_to_steward("+[amt] from treasury to [name]")
else
// Player was fined
if(source)
send_ooc_note("<b>The Bank:</b> You were fined. ([source])", name = name)
log_to_steward("[name] was fined [amt] ([source])")
else
send_ooc_note("<b>The Bank:</b> You were fined.", name = name)
log_to_steward("[name] was fined [amt]")

return TRUE
/datum/controller/subsystem/treasury/proc/give_money_account(amt, target, source)
if(!amt)
return
if(!target)
return
var/target_name = target
if(istype(target,/mob/living/carbon/human))
var/mob/living/carbon/human/H = target
target_name = H.real_name
var/found_account
if (amt > treasury_value) // Check if the amount exceeds the treasury balance
send_ooc_note("<b>The Bank:</b> Error: Insufficient funds in the treasury to complete the transaction.", name = target_name)
return FALSE // Return early if the treasury balance is insufficient
for(var/X in bank_accounts)
if(X == target)
if(amt > 0)
bank_accounts[X] += amt // Deposit the money into the player's account
treasury_value -= amt // Deduct the given amount from the treasury
else
// Check if the amount to be fined exceeds the player's account balance
if(abs(amt) > bank_accounts[X])
send_ooc_note("<b>The Bank:</b> Error: Insufficient funds in the account to complete the fine.", name = target_name)
return FALSE // Return early if the player has insufficient funds
bank_accounts[X] -= abs(amt) // Deduct the fine amount from the player's account
treasury_value += abs(amt) // Add the fined amount to the treasury
found_account = TRUE
break
if(!found_account)
return FALSE

if (amt > 0)
// Player received money
if(source)
send_ooc_note("<b>The Bank:</b> You received money. ([source])", name = target_name)
log_to_steward("+[amt] from treasury to [name] ([source])")
else
send_ooc_note("<b>The Bank:</b> You received money.", name = target_name)
log_to_steward("+[amt] from treasury to [name]")
else
// Player was fined
if(source)
send_ooc_note("<b>The Bank:</b> You were fined. ([source])", name = target_name)
log_to_steward("[name] was fined [amt] ([source])")
else
send_ooc_note("<b>The Bank:</b> You were fined.", name = target_name)
log_to_steward("[name] was fined [amt]")

return TRUE

///Deposits money into a character's bank account. Taxes are deducted from the deposit and added to the treasury.
///@param amt: The amount of money to deposit.
Expand Down Expand Up @@ -186,21 +189,21 @@ SUBSYSTEM_DEF(treasury)


/datum/controller/subsystem/treasury/proc/withdraw_money_account(amt, name)
if(!amt)
return
var/found_account
for(var/X in bank_accounts)
if(X == name)
if(bank_accounts[X] < amt) // Check if the withdrawal amount exceeds the player's account balance
send_ooc_note("<b>The Bank:</b> Error: Insufficient funds in the player's account to complete the withdrawal.", name = name)
return // Return without processing the transaction
bank_accounts[X] -= amt
found_account = TRUE
break
if(!found_account)
return
log_to_steward("-[amt] withdrawn by [name]")
return TRUE
if(!amt)
return
var/found_account
for(var/X in bank_accounts)
if(X == name)
if(bank_accounts[X] < amt) // Check if the withdrawal amount exceeds the player's account balance
send_ooc_note("<b>The Bank:</b> Error: Insufficient funds in the account to complete the withdrawal.", name = name)
return // Return without processing the transaction
bank_accounts[X] -= amt //The account accounts accountingly. Shame on you if you copy this, apple.
found_account = TRUE
break
if(!found_account)
return
log_to_steward("-[amt] withdrawn by [name]")
return TRUE


/datum/controller/subsystem/treasury/proc/log_to_steward(log)
Expand Down

0 comments on commit d4ecd6a

Please sign in to comment.