-
Notifications
You must be signed in to change notification settings - Fork 55
Adds network finance system #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| SUBSYSTEM_DEF(money_accounts) | ||
| name = "Money Accounts" | ||
| wait = 5 MINUTES | ||
| priority = SS_PRIORITY_MONEY_ACCOUNTS | ||
| var/list/datum/money_account/all_accounts = list() | ||
|
|
||
| // Independent, globally accessible accounts not tied to a network | ||
| var/list/datum/money_account/all_glob_accounts = list() | ||
|
|
||
| var/list/datum/money_account/escrow/all_escrow_accounts = list() | ||
|
|
||
| var/list/processing_accounts | ||
|
|
||
| var/adjustment = 0 | ||
|
|
||
| /datum/controller/subsystem/money_accounts/fire(resumed = FALSE) | ||
|
|
||
| if(!resumed) | ||
| processing_accounts = all_accounts.Copy() | ||
|
|
||
| var/current_time = REALTIMEOFDAY + adjustment | ||
| while(processing_accounts.len) | ||
| var/datum/money_account/curr_account = processing_accounts[processing_accounts.len] | ||
| processing_accounts.len-- | ||
|
|
||
| if(length(curr_account.pending_modifications)) | ||
| for(var/datum/account_modification/pending_mod in curr_account.pending_modifications) | ||
| if(pending_mod.start_time + pending_mod.mod_delay <= current_time) | ||
| pending_mod.modify_account() | ||
|
|
||
| if(istype(curr_account, /datum/money_account/child)) | ||
| var/datum/money_account/child/curr_child = curr_account | ||
|
|
||
| if(curr_child.withdrawal_limit && (curr_child.last_withdraw_period + config.withdraw_period <= current_time)) | ||
| curr_child.current_withdrawal = 0 | ||
| curr_child.last_withdraw_period = current_time | ||
|
|
||
| if(curr_child.interest_rate && (curr_child.last_interest_period + config.interest_period <= current_time)) | ||
| curr_child.accrue_interest() | ||
| curr_child.last_interest_period = current_time | ||
|
|
||
| if(MC_TICK_CHECK) | ||
| return | ||
|
|
||
| /datum/controller/subsystem/money_accounts/proc/accel_day() | ||
| adjustment += 1 DAY | ||
|
|
||
| /datum/controller/subsystem/money_accounts/proc/decel_day() | ||
| adjustment -= 1 DAY | ||
|
|
||
| /datum/controller/subsystem/money_accounts/proc/get_or_add_escrow(account_id, account_pin, account_provider) | ||
| var/datum/money_account/escrow/existing = get_escrow(account_id, account_pin, account_provider) | ||
| if(existing) | ||
| return existing | ||
|
|
||
| existing = new() | ||
| existing.account_id = account_id | ||
| existing.remote_access_pin = account_pin | ||
| existing.owner_name = account_provider | ||
|
|
||
| all_escrow_accounts |= existing | ||
| return existing | ||
|
|
||
| /datum/controller/subsystem/money_accounts/proc/get_escrow(account_id, account_pin, account_provider) | ||
| for(var/datum/money_account/escrow/e_account in all_escrow_accounts) | ||
| if((e_account.account_id == account_id) && e_account.remote_access_pin == account_pin) | ||
| if(!account_provider || e_account.owner_name == account_provider) | ||
| return e_account | ||
|
|
||
| /datum/controller/subsystem/money_accounts/proc/get_escrow_provider_ids() | ||
| . = list() | ||
| for(var/datum/money_account/escrow/e_account in all_escrow_accounts) | ||
| . |= e_account.owner_name | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -420,10 +420,10 @@ Helpers | |
| if(dronecount) | ||
| to_world("<b>There [dronecount>1 ? "were" : "was"] [dronecount] industrious maintenance drone\s at the end of this round.</b>") | ||
|
|
||
| if(all_money_accounts.len) | ||
| var/datum/money_account/max_profit = all_money_accounts[1] | ||
| var/datum/money_account/max_loss = all_money_accounts[1] | ||
| for(var/datum/money_account/D in all_money_accounts) | ||
| if(SSmoney_accounts.all_glob_accounts.len) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally use length() instead of len.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be fixed, as other instances. |
||
| var/datum/money_account/max_profit = SSmoney_accounts.all_glob_accounts[1] | ||
| var/datum/money_account/max_loss = SSmoney_accounts.all_glob_accounts[1] | ||
| for(var/datum/money_account/D in SSmoney_accounts.all_glob_accounts) | ||
| if(D == vendor_account) //yes we know you get lots of money | ||
| continue | ||
| var/saldo = D.get_balance() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
code/game/machinery/_machines_base/stock_parts/money_printer.dm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /obj/item/stock_parts/computer/money_printer | ||
| name = "cryptographic micro-printer" | ||
| desc = "A micro-printer capable of scanning, recycling, and printing cryptographically secured bank notes on ultra thin plastic." | ||
| icon_state = "printer" | ||
| material = /decl/material/solid/plastic | ||
| matter = list( | ||
| /decl/material/solid/fiberglass = MATTER_AMOUNT_REINFORCEMENT, | ||
| /decl/material/solid/silicon = MATTER_AMOUNT_REINFORCEMENT | ||
| ) | ||
| max_health = ITEM_HEALTH_NO_DAMAGE | ||
| external_slot = TRUE | ||
|
|
||
| var/stored_plastic = 0 // This could be capped, but it'd place an annoying limit on the amount of money you can insert at a given time. | ||
|
|
||
| /obj/item/stock_parts/computer/money_printer/examine(mob/user) | ||
| . = ..() | ||
| if(Adjacent(user)) | ||
| to_chat(user, "It has [round(stored_plastic) / SHEET_MATERIAL_AMOUNT] sheets of plastic in storage.") | ||
|
|
||
| /obj/item/stock_parts/computer/money_printer/attackby(obj/item/W, mob/user) | ||
| . = ..() | ||
| if(istype(W, /obj/item/stack/material) && W.get_material_type() == /decl/material/solid/plastic) | ||
| var/obj/item/stack/material/stack = W | ||
|
|
||
| stored_plastic += SHEET_MATERIAL_AMOUNT * stack.amount | ||
| to_chat(user, "You insert the plastic into \the [src]'s storage.") | ||
| user.drop_from_inventory(stack) | ||
| qdel(stack) | ||
|
|
||
| if(IS_SCREWDRIVER(W) && !istype(loc, /obj/machinery)) | ||
| to_chat(user, "You pry out the plastic reserves of \the [src].") | ||
| SSmaterials.create_object(/decl/material/solid/plastic, get_turf(src), round(stored_plastic / SHEET_MATERIAL_AMOUNT)) | ||
| stored_plastic = 0 | ||
|
|
||
| if(istype(W, /obj/item/cash)) | ||
| if(!loc) | ||
| return | ||
| var/datum/extension/interactive/os/current_os = get_extension(loc, /datum/extension/interactive/os) | ||
| if(!current_os) | ||
| to_chat(user, SPAN_WARNING("\The [src] must be installed before it can be used!")) | ||
| return | ||
| var/obj/item/cash/receiving = W | ||
| var/decl/currency/receiving_currency = GET_DECL(receiving.currency) | ||
| if(receiving_currency.material != /decl/material/solid/plastic) | ||
| to_chat(user, SPAN_WARNING("\The [src] cannot accept cash of this currency!")) | ||
| return | ||
|
|
||
| var/amount_taken = current_os.process_cash(receiving, usr) | ||
| if(!amount_taken) | ||
| return | ||
| else | ||
| playsound(get_turf(src), pick('sound/items/polaroid1.ogg', 'sound/items/polaroid2.ogg'), 50, 1) | ||
| to_chat(usr, SPAN_NOTICE("You insert [FLOOR(amount_taken / receiving_currency.absolute_value)] [receiving_currency.name] into \the [src].")) | ||
| receiving.adjust_worth(-amount_taken) | ||
|
|
||
| stored_plastic += amount_taken*max(1, round(SHEET_MATERIAL_AMOUNT/10)) | ||
|
|
||
| return | ||
|
|
||
| /obj/item/stock_parts/computer/money_printer/proc/can_print(amount, currency_type) | ||
| // TODO: Support for non-plastic currencies | ||
| var/decl/currency/printed_currency = GET_DECL(currency_type) | ||
| if(printed_currency.material != /decl/material/solid/plastic) | ||
| return FALSE | ||
| return (stored_plastic >= amount*max(1, round(SHEET_MATERIAL_AMOUNT/10))) | ||
|
|
||
| // BRRRR | ||
| /obj/item/stock_parts/computer/money_printer/proc/print_money(amount, currency_type, mob/user) | ||
| if(!can_print(amount, currency_type)) | ||
| return FALSE | ||
|
|
||
| stored_plastic -= amount*max(1, round(SHEET_MATERIAL_AMOUNT/10)) | ||
|
|
||
| var/obj/item/cash/cash = new(get_turf(src)) | ||
| cash.set_currency(currency_type) | ||
| cash.adjust_worth(amount) | ||
|
|
||
| if(user) | ||
| user.put_in_hands(cash) | ||
|
|
||
| return TRUE | ||
|
|
||
| /obj/item/stock_parts/computer/money_printer/filled | ||
| stored_plastic = 50*SHEET_MATERIAL_AMOUNT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gotta admit, I'm not all that fond of holding all account data in-game, and just looping through all of them constantly.
The way I handled them in my rework was via SQL tables and stored procedures. So DM had very little work to do.
But if you really wanna go that way I'm not gonna protest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the benefit of that, but since this is looping relatively rarely and performing very few actions, I'm not that worried about performance. I'm also leery of having features which require a working database to function, and that probably wouldn't pass muster upstream.