From 3b38d937b0967a81225b8de5220a6c2b844fdee6 Mon Sep 17 00:00:00 2001 From: variableundefined <40092670+variableundefined@users.noreply.github.com> Date: Thu, 26 Jul 2018 19:35:27 +0800 Subject: [PATCH 1/3] Economy refactors --- code/__HELPERS/time.dm | 6 +- code/game/gamemodes/game_mode.dm | 10 +- code/game/machinery/slotmachine.dm | 13 +- code/game/machinery/vending.dm | 19 +- code/modules/arcade/arcade_base.dm | 19 +- .../awaymissions/mission_code/spacehotel.dm | 6 +- code/modules/economy/ATM.dm | 34 +-- code/modules/economy/Accounts.dm | 256 ++---------------- code/modules/economy/Accounts_DB.dm | 82 ++---- code/modules/economy/EFTPOS.dm | 90 ++---- code/modules/economy/utils.dm | 90 +++--- code/modules/events/money_hacker.dm | 36 ++- code/modules/events/money_lotto.dm | 14 +- .../modular_computers/laptop_vendor.dm | 22 +- nano/templates/eftpos.tmpl | 24 +- 15 files changed, 191 insertions(+), 530 deletions(-) diff --git a/code/__HELPERS/time.dm b/code/__HELPERS/time.dm index b47e60275e8..6ebaba5bc3b 100644 --- a/code/__HELPERS/time.dm +++ b/code/__HELPERS/time.dm @@ -56,7 +56,7 @@ /* This is used for displaying the "station time" equivelent of a world.time value Calling it with no args will give you the current time, but you can specify a world.time-based value as an argument - - You can use this, for example, to do "This will expire at [station_time_at(world.time + 500)]" to display a "station time" expiration date + - You can use this, for example, to do "This will expire at [station_time_at(world.time + 500)]" to display a "station time" expiration date which is much more useful for a player)*/ /proc/station_time(time=world.time, display_only=FALSE) return ((((time - round_start_time)) + GLOB.gametime_offset) % 864000) - (display_only ? GLOB.timezoneOffset : 0) @@ -93,8 +93,8 @@ proc/isDay(var/month, var/day) /proc/stop_watch(wh) return round(0.1 * (TimeOfGame - wh), 0.1) -/proc/month2number(month) - return month_names.Find(month) +/proc/numberToMonthName(number) + return month_names.Find(number) //Take a value in seconds and returns a string of minutes and seconds in the format X minute(s) and X seconds. /proc/seconds_to_time(var/seconds as num) diff --git a/code/game/gamemodes/game_mode.dm b/code/game/gamemodes/game_mode.dm index 760868e8435..e64421f330b 100644 --- a/code/game/gamemodes/game_mode.dm +++ b/code/game/gamemodes/game_mode.dm @@ -156,15 +156,7 @@ msg="Task #[count] completed! " if(pay>0) if(M.mind.initial_account) - M.mind.initial_account.money += pay - var/datum/transaction/T = new() - T.target_name = "[command_name()] Payroll" - T.purpose = "Payment" - T.amount = pay - T.date = current_date_string - T.time = station_time_timestamp() - T.source_terminal = "\[CLASSIFIED\] Terminal #[rand(111,333)]" - M.mind.initial_account.transaction_log.Add(T) + M.mind.initial_account.credit(pay, "Payment", "\[CLASSIFIED\] Terminal #[rand(111,333)]", "[command_name()] Payroll") msg += "You have been sent the $[pay], as agreed." else msg += "However, we were unable to send you the $[pay] you're entitled." diff --git a/code/game/machinery/slotmachine.dm b/code/game/machinery/slotmachine.dm index 72fd23dde66..dd8e83d565c 100644 --- a/code/game/machinery/slotmachine.dm +++ b/code/game/machinery/slotmachine.dm @@ -49,7 +49,7 @@ return if(!account || account.money < 10) return - if(!account.charge(10, transaction_purpose = "Bet", dest_name = name)) + if(!account.charge(10, null, "Bet", "Slot Machine", "Slot Machine")) return plays += 1 working = 1 @@ -89,7 +89,7 @@ result = "You win fifty credits!" resultlvl = "good" win_money(50) - else if(roll > 300 && roll <= 600) + else if(roll > 300 && roll <= 4000) visible_message("[src] says, 'Winner! [usr.name] has won ten credits!'") result = "You win ten credits!" resultlvl = "good" @@ -106,12 +106,5 @@ if(!account) return - account.money += amt - var/datum/transaction/T = new() - T.target_name = account.owner_name - T.purpose = "Slot Winnings" - T.amount = "[amt]" - T.date = current_date_string - T.time = station_time_timestamp() - account.transaction_log.Add(T) + account.credit(amt, "Slot Winnings", "Slot Machine", account.owner_name) diff --git a/code/game/machinery/vending.dm b/code/game/machinery/vending.dm index f7b2e8bbd05..d19212eb3d1 100644 --- a/code/game/machinery/vending.dm +++ b/code/game/machinery/vending.dm @@ -399,11 +399,9 @@ return 0 else // Okay to move the money at this point - var/paid = customer_account.charge(currently_vending.price, - transaction_purpose = "Purchase of [currently_vending.product_name]", - terminal_name = name, - terminal_id = name, - dest_name = vendor_account.owner_name) + var/paid = customer_account.charge(currently_vending.price, vendor_account, + "Purchase of [currently_vending.product_name]", name, vendor_account.owner_name, + "Sale of [currently_vending.product_name]", customer_account.owner_name) if(paid) // Give the vendor the money. We use the account owner name, which means @@ -419,15 +417,8 @@ */ /obj/machinery/vending/proc/credit_purchase(var/target as text) vendor_account.money += currently_vending.price - - var/datum/transaction/T = new() - T.target_name = target - T.purpose = "Purchase of [currently_vending.product_name]" - T.amount = "[currently_vending.price]" - T.source_terminal = src.name - T.date = current_date_string - T.time = station_time_timestamp() - vendor_account.transaction_log.Add(T) + vendor_account.credit(currently_vending.price, "Sale of [currently_vending.product_name]", + name, target) /obj/machinery/vending/attack_ai(mob/user) return attack_hand(user) diff --git a/code/modules/arcade/arcade_base.dm b/code/modules/arcade/arcade_base.dm index 9b925e2f2ac..12927895030 100644 --- a/code/modules/arcade/arcade_base.dm +++ b/code/modules/arcade/arcade_base.dm @@ -118,22 +118,7 @@ else // Okay to move the money at this point - // debit money from the purchaser's account - customer_account.money -= token_price - - // create entry in the purchaser's account log - var/datum/transaction/T = new() - T.target_name = "[src.name]" - T.purpose = "Purchase of [src.name] credit" - if(token_price > 0) - T.amount = "([token_price])" - else - T.amount = "[token_price]" - T.source_terminal = src.name - T.date = current_date_string - T.time = station_time_timestamp() - customer_account.transaction_log.Add(T) - return 1 + customer_account.charge(token_price, null, "Purchase of [name] credit", name, name) /obj/machinery/arcade/proc/start_play(mob/user as mob) user.set_machine(src) @@ -159,4 +144,4 @@ /obj/machinery/arcade/Destroy() src.close_game() - return ..() \ No newline at end of file + return ..() diff --git a/code/modules/awaymissions/mission_code/spacehotel.dm b/code/modules/awaymissions/mission_code/spacehotel.dm index 81d21df5dcf..00609b7a218 100644 --- a/code/modules/awaymissions/mission_code/spacehotel.dm +++ b/code/modules/awaymissions/mission_code/spacehotel.dm @@ -234,7 +234,7 @@ D.account = get_card_account(id, occupant) if(!D.account) return null - if(!D.account.charge(100, transaction_purpose = "10 minutes", dest_name = name)) + if(!D.account.charge(100, null, "10 minutes hotel stay", "Biesel GalaxyNet Terminal [rand(111,1111)]", "[name]")) return null D.occupant = occupant @@ -251,7 +251,7 @@ if(!D || !D.occupant) return - if(D.account.charge(100, transaction_purpose = "10 minutes", dest_name = name)) + if(D.account.charge(100, null, "10 minutes hotel stay extension", "Biesel GalaxyNet Terminal [rand(111,1111)]", "[name]")) D.roomtimer = addtimer(CALLBACK(src, .proc/process_room, roomid), PAY_INTERVAL, TIMER_STOPPABLE) else force_checkout(roomid) @@ -299,4 +299,4 @@ return S.retal_target = target - S.retal = 1 \ No newline at end of file + S.retal = 1 diff --git a/code/modules/economy/ATM.dm b/code/modules/economy/ATM.dm index 6306fa5a83e..52494728155 100644 --- a/code/modules/economy/ATM.dm +++ b/code/modules/economy/ATM.dm @@ -97,18 +97,9 @@ log transactions if(!powered()) return var/obj/item/stack/spacecash/C = I - authenticated_account.money += C.amount playsound(loc, pick('sound/items/polaroid1.ogg', 'sound/items/polaroid2.ogg'), 50, 1) - //create a transaction log entry - var/datum/transaction/T = new() - T.target_name = authenticated_account.owner_name - T.purpose = "Credit deposit" - T.amount = C.amount - T.source_terminal = machine_id - T.date = current_date_string - T.time = station_time_timestamp() - authenticated_account.transaction_log.Add(T) + authenticated_account.credit(C.amount, "Credit deposit", machine_id, authenticated_account.owner_name) to_chat(user, "You insert [C] into [src].") SSnanoui.update_uis(src) @@ -175,19 +166,8 @@ log transactions else if(transfer_amount <= authenticated_account.money) var/target_account_number = text2num(href_list["target_acc_number"]) var/transfer_purpose = href_list["purpose"] - if(linked_db.charge_to_account(target_account_number, authenticated_account.owner_name, transfer_purpose, machine_id, transfer_amount)) + if(linked_db.charge_to_account(target_account_number, authenticated_account, transfer_purpose, machine_id, transfer_amount)) to_chat(usr, "[bicon(src)]Funds transfer successful.") - authenticated_account.money -= transfer_amount - - //create an entry in the account transaction log - var/datum/transaction/T = new() - T.target_name = "Account #[target_account_number]" - T.purpose = transfer_purpose - T.source_terminal = machine_id - T.date = current_date_string - T.time = station_time_timestamp() - T.amount = "([transfer_amount])" - authenticated_account.transaction_log.Add(T) else to_chat(usr, "[bicon(src)]Funds transfer failed.") @@ -263,15 +243,7 @@ log transactions authenticated_account.money -= amount withdraw_arbitrary_sum(amount) - //create an entry in the account transaction log - var/datum/transaction/T = new() - T.target_name = authenticated_account.owner_name - T.purpose = "Credit withdrawal" - T.amount = "([amount])" - T.source_terminal = machine_id - T.date = current_date_string - T.time = station_time_timestamp() - authenticated_account.transaction_log.Add(T) + authenticated_account.charge(amount, null, "Credit withdrawal", machine_id, authenticated_account.owner_name) else to_chat(usr, "[bicon(src)]You don't have enough funds to do that!") if("balance_statement") diff --git a/code/modules/economy/Accounts.dm b/code/modules/economy/Accounts.dm index 23b51fd2aea..792e53f307b 100644 --- a/code/modules/economy/Accounts.dm +++ b/code/modules/economy/Accounts.dm @@ -1,4 +1,9 @@ -var/global/current_date_string +#define STATION_CREATION_DATE "2 April, 2555" +#define STATION_CREATION_TIME "11:24:30" +#define STATION_START_CASH 75000 +#define STATION_SOURCE_TERMINAL "Biesel GalaxyNet Terminal #227" +#define DEPARTMENT_START_CASH 5000 + var/global/num_financial_terminals = 1 var/global/datum/money_account/station_account var/global/list/datum/money_account/department_accounts = list() @@ -15,19 +20,13 @@ var/global/list/all_money_accounts = list() station_account.owner_name = "[station_name()] Station Account" station_account.account_number = rand(111111, 999999) station_account.remote_access_pin = rand(1111, 111111) - station_account.money = 75000 + station_account.money = STATION_START_CASH //create an entry in the account transaction log for when it was created - var/datum/transaction/T = new() - T.target_name = station_account.owner_name - T.purpose = "Account creation" - T.amount = 75000 - T.date = "2nd April, 2555" - T.time = "11:24" - T.source_terminal = "Biesel GalaxyNet Terminal #277" + station_account.makeTransactionLog(STATION_START_CASH, "Account Creation", STATION_SOURCE_TERMINAL, station_account.owner_name, FALSE, + STATION_CREATION_DATE, STATION_CREATION_TIME) //add the account - station_account.transaction_log.Add(T) all_money_accounts.Add(station_account) /proc/create_department_account(department) @@ -37,19 +36,13 @@ var/global/list/all_money_accounts = list() department_account.owner_name = "[department] Account" department_account.account_number = rand(111111, 999999) department_account.remote_access_pin = rand(1111, 111111) - department_account.money = 5000 + department_account.money = DEPARTMENT_START_CASH //create an entry in the account transaction log for when it was created - var/datum/transaction/T = new() - T.target_name = department_account.owner_name - T.purpose = "Account creation" - T.amount = department_account.money - T.date = "2nd April, 2555" - T.time = "11:24" - T.source_terminal = "Biesel GalaxyNet Terminal #277" + department_account.makeTransactionLog(DEPARTMENT_START_CASH, "Account Creation", STATION_SOURCE_TERMINAL, department_account.owner_name, FALSE, + STATION_CREATION_DATE, STATION_CREATION_TIME) //add the account - department_account.transaction_log.Add(T) all_money_accounts.Add(department_account) department_accounts[department] = department_account @@ -73,7 +66,7 @@ var/global/list/all_money_accounts = list() if(!source_db) //set a random date, time and location some time over the past few decades T.date = "[num2text(rand(1,31))] [pick(month_names)], [rand(game_year - 20,game_year - 1)]" - T.time = "[rand(0,23)]:[rand(0,59)]" + T.time = "[rand(0,23)]:[rand(0,59)]:[rand(0,59)]" T.source_terminal = "NTGalaxyNet Terminal #[rand(111,1111)]" M.account_number = rand(111111, 999999) @@ -104,7 +97,7 @@ var/global/list/all_money_accounts = list() Date and time: [station_time_timestamp()], [current_date_string]

Creation terminal ID: [source_db.machine_id]
Authorised NT officer overseeing creation: [overseer]
"} - // END AUTOFIX + //stamp the paper var/image/stampoverlay = image('icons/obj/bureaucracy.dmi') stampoverlay.icon_state = "paper_stamp-cent" @@ -133,7 +126,6 @@ var/global/list/all_money_accounts = list() /datum/money_account/New() ..() - //security_level = pick (0,1) //Stealing is now slightly viable /datum/transaction var/target_name = "" @@ -142,222 +134,14 @@ var/global/list/all_money_accounts = list() var/date = "" var/time = "" var/source_terminal = "" -/* -/obj/machinery/account_database - name = "Accounts database" - desc = "Holds transaction logs, account data and all kinds of other financial records." - icon = 'icons/obj/virology.dmi' - icon_state = "analyser" - density = 1 - req_one_access = list(access_hop, access_captain) - var/receipt_num - var/machine_id = "" - var/obj/item/card/id/held_card - var/access_level = 0 - var/datum/money_account/detailed_account_view - var/creating_new_account = 0 - var/activated = 1 -/obj/machinery/account_database/New() - ..() - if(!station_account) - create_station_account() - - if(department_accounts.len == 0) - for(var/department in station_departments) - create_department_account(department) - if(!vendor_account) - create_department_account("Vendor") - vendor_account = department_accounts["Vendor"] - - if(!current_date_string) - current_date_string = "[num2text(rand(1,31))] [pick("January","February","March","April","May","June","July","August","September","October","November","December")], 2557" - - machine_id = "[station_name()] Acc. DB #[num_financial_terminals++]" - -/obj/machinery/account_database/attack_hand(mob/user as mob) - if(ishuman(user) && !user.stat && get_dist(src,user) <= 1) - var/dat = "Accounts Database
" - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:171: dat += "[machine_id]
" - dat += {"[machine_id]
- Confirm identity: [held_card ? held_card : "-----"]
"} - // END AUTOFIX - if(access_level > 0) - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:175: dat += "[activated ? "Disable" : "Enable"] remote access
" - dat += {"[activated ? "Disable" : "Enable"] remote access
- You may not edit accounts at this terminal, only create and view them.
"} - // END AUTOFIX - if(creating_new_account) - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:178: dat += "
" - dat += {"
- Return to accounts list -
- - - Holder name:
- Initial funds: (subtracted from station account)
- New accounts are automatically assigned a secret number and pin, which are printed separately in a sealed package.
-
-
"} - // END AUTOFIX - else - if(detailed_account_view) - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:190: dat += "
" - dat += {"
- Return to accounts list
- Account number: #[detailed_account_view.account_number]
- Account holder: [detailed_account_view.owner_name]
- Account balance: $[detailed_account_view.money]
- - - - - - - - - "} - // END AUTOFIX - for(var/datum/transaction/T in detailed_account_view.transaction_log) - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:205: dat += "" - dat += {" - - - - - - - "} - // END AUTOFIX - dat += "
DateTimeTargetPurposeValueSource terminal ID
[T.date][T.time][T.target_name][T.purpose]$[T.amount][T.source_terminal]
" - else - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:215: dat += "Create new account

" - dat += {"Create new account

- "} - // END AUTOFIX - for(var/i=1, i<=all_money_accounts.len, i++) - var/datum/money_account/D = all_money_accounts[i] - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:219: dat += "" - dat += {" - - - - "} - // END AUTOFIX - dat += "
#[D.account_number][D.owner_name]View in detail
" - - user << browse(dat,"window=account_db;size=700x650") - else - user << browse(null,"window=account_db") - -/obj/machinery/account_database/attackby(O as obj, user as mob)//TODO:SANITY - if(istype(O, /obj/item/card)) - var/obj/item/card/id/idcard = O - if(!held_card) - usr.drop_item() - idcard.loc = src - held_card = idcard - - if(access_cent_captain in idcard.access) - access_level = 2 - else if(access_hop in idcard.access || access_captain in idcard.access) - access_level = 1 - else - ..() - -/obj/machinery/account_database/Topic(var/href, var/href_list) - ..() - if(href_list["toggle_activated"]) - activated = !activated - - if(href_list["choice"]) - switch(href_list["choice"]) - if("create_account") - creating_new_account = 1 - if("finalise_create_account") - var/account_name = href_list["holder_name"] - var/starting_funds = max(text2num(href_list["starting_funds"]), 0) - create_account(account_name, starting_funds, src) - if(starting_funds > 0) - //subtract the money - station_account.money -= starting_funds - - //create a transaction log entry - var/datum/transaction/T = new() - T.target_name = account_name - T.purpose = "New account funds initialisation" - T.amount = "([starting_funds])" - T.date = current_date_string - T.time = station_time_timestamp() - T.source_terminal = machine_id - station_account.transaction_log.Add(T) - - creating_new_account = 0 - if("insert_card") - if(held_card) - held_card.loc = src.loc - - if(ishuman(usr) && !usr.get_active_hand()) - usr.put_in_hands(held_card) - held_card = null - access_level = 0 - - else - var/obj/item/I = usr.get_active_hand() - if(istype(I, /obj/item/card/id)) - var/obj/item/card/id/C = I - usr.drop_item() - C.loc = src - held_card = C - - if(access_cent_captain in C.access) - access_level = 2 - else if(access_hop in C.access || access_captain in C.access) - access_level = 1 - if("view_account_detail") - var/index = text2num(href_list["account_index"]) - if(index && index <= all_money_accounts.len) - detailed_account_view = all_money_accounts[index] - if("view_accounts_list") - detailed_account_view = null - creating_new_account = 0 - - src.attack_hand(usr) -*/ -/obj/machinery/computer/account_database/proc/charge_to_account(var/attempt_account_number, var/source_name, var/purpose, var/terminal_id, var/amount) +/obj/machinery/computer/account_database/proc/charge_to_account(var/attempt_account_number, datum/money_account/source, var/purpose, var/terminal_id, var/amount) if(!activated) return 0 for(var/datum/money_account/D in all_money_accounts) if(D.account_number == attempt_account_number && !D.suspended) - D.money += amount - - //create a transaction log entry - var/datum/transaction/T = new() - T.target_name = source_name - T.purpose = purpose - if(amount < 0) - T.amount = "([amount])" - else - T.amount = "[amount]" - T.date = current_date_string - T.time = station_time_timestamp() - T.source_terminal = terminal_id - D.transaction_log.Add(T) - + source.charge(amount, D, purpose, terminal_id, "Account #[D.account_number]", "Transfer from [source.owner_name]", + "[D.owner_name]") return 1 return 0 @@ -378,3 +162,9 @@ var/global/list/all_money_accounts = list() for(var/datum/money_account/D in all_money_accounts) if(D.account_number == attempt_account_number) return D + +#undef STATION_CREATION_DATE +#undef STATION_CREATION_TIME +#undef STATION_START_CASH +#undef STATION_SOURCE_TERMINAL +#undef DEPARTMENT_START_CASH diff --git a/code/modules/economy/Accounts_DB.dm b/code/modules/economy/Accounts_DB.dm index 3ea778671a1..e99367cb8fd 100644 --- a/code/modules/economy/Accounts_DB.dm +++ b/code/modules/economy/Accounts_DB.dm @@ -1,3 +1,4 @@ +var/global/current_date_string /obj/machinery/computer/account_database name = "Accounts Uplink Terminal" @@ -15,34 +16,6 @@ light_color = LIGHT_COLOR_GREEN -/obj/machinery/computer/account_database/proc/get_access_level(var/mob/user) - if(user.can_admin_interact()) - return 2 - if(!held_card) - return 0 - if(access_cent_commander in held_card.access) - return 2 - else if(access_hop in held_card.access || access_captain in held_card.access) - return 1 - -/obj/machinery/computer/account_database/proc/create_transation(target, reason, amount) - var/datum/transaction/T = new() - T.target_name = target - T.purpose = reason - T.amount = amount - T.date = current_date_string - T.time = station_time_timestamp() - T.source_terminal = machine_id - return T - -/obj/machinery/computer/account_database/proc/accounting_letterhead(report_name) - return {" -

[report_name]

-
[station_name()] Accounting Report
-
- Generated By: [held_card.registered_name], [held_card.assignment]
- "} - /obj/machinery/computer/account_database/New() if(!station_account) create_station_account() @@ -55,11 +28,29 @@ vendor_account = department_accounts["Vendor"] if(!current_date_string) - current_date_string = "[time2text(world.timeofday, "DD MM")], [game_year]" + current_date_string = "[time2text(world.timeofday, "DD Month")], [game_year]" machine_id = "[station_name()] Acc. DB #[num_financial_terminals++]" ..() +/obj/machinery/computer/account_database/proc/get_access_level(var/mob/user) + if(user.can_admin_interact()) + return 2 + if(!held_card) + return 0 + if(access_cent_commander in held_card.access) + return 2 + else if(access_hop in held_card.access || access_captain in held_card.access) + return 1 + +/obj/machinery/computer/account_database/proc/accounting_letterhead(report_name) + return {" +

[report_name]

+
[station_name()] Accounting Report
+
+ Generated By: [held_card.registered_name], [held_card.assignment]
+ "} + /obj/machinery/computer/account_database/attackby(obj/O, mob/user, params) if(!istype(O, /obj/item/card/id)) return ..() @@ -160,16 +151,6 @@ if("create_account") creating_new_account = 1 - if("add_funds") - var/amount = input("Enter the amount you wish to add", "Silently add funds") as num - if(detailed_account_view) - detailed_account_view.money += amount - - if("remove_funds") - var/amount = input("Enter the amount you wish to remove", "Silently remove funds") as num - if(detailed_account_view) - detailed_account_view.money -= amount - if("toggle_suspension") if(detailed_account_view) detailed_account_view.suspended = !detailed_account_view.suspended @@ -182,14 +163,10 @@ starting_funds = Clamp(starting_funds, 0, station_account.money) // Not authorized to put the station in debt. starting_funds = min(starting_funds, fund_cap) // Not authorized to give more than the fund cap. - create_account(account_name, starting_funds, src) + var/datum/money_account/M = create_account(account_name, starting_funds, src) if(starting_funds > 0) - //subtract the money - station_account.money -= starting_funds - - //create a transaction log entry - var/trx = create_transation(account_name, "New account activation", "([starting_funds])") - station_account.transaction_log.Add(trx) + station_account.charge(starting_funds, null, "New account activation", + "", "New account activation", M.owner_name) creating_new_account = 0 ui.close() @@ -205,19 +182,6 @@ detailed_account_view = null creating_new_account = 0 - if("revoke_payroll") - var/funds = detailed_account_view.money - var/account_trx = create_transation(station_account.owner_name, "Revoke payroll", "([funds])") - var/station_trx = create_transation(detailed_account_view.owner_name, "Revoke payroll", funds) - - station_account.money += funds - detailed_account_view.money = 0 - - detailed_account_view.transaction_log.Add(account_trx) - station_account.transaction_log.Add(station_trx) - - callHook("revoke_payroll", list(detailed_account_view)) - if("print") var/text playsound(loc, 'sound/goonstation/machines/printer_thermal.ogg', 50, 1) diff --git a/code/modules/economy/EFTPOS.dm b/code/modules/economy/EFTPOS.dm index f305c43ad9d..e5f3cf6529e 100644 --- a/code/modules/economy/EFTPOS.dm +++ b/code/modules/economy/EFTPOS.dm @@ -3,8 +3,7 @@ desc = "Swipe your ID card to make purchases electronically." icon = 'icons/obj/device.dmi' icon_state = "eftpos" - var/machine_id = "" - var/eftpos_name = "Default EFTPOS scanner" + var/machine_name = "" var/transaction_locked = 0 var/transaction_paid = 0 var/transaction_amount = 0 @@ -15,7 +14,7 @@ /obj/item/eftpos/New() ..() - machine_id = "[station_name()] EFTPOS #[num_financial_terminals++]" + machine_name = "[station_name()] EFTPOS #[num_financial_terminals++]" access_code = rand(1111,111111) reconnect_database() spawn(0) @@ -28,14 +27,10 @@ /obj/item/eftpos/proc/print_reference() playsound(loc, 'sound/goonstation/machines/printer_thermal.ogg', 50, 1) var/obj/item/paper/R = new(loc) - R.name = "Reference: [eftpos_name]" - - // AUTOFIXED BY fix_string_idiocy.py - // C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\EFTPOS.dm:31: R.info = "[eftpos_name] reference

" - R.info = {"[eftpos_name] reference

+ R.name = "Reference: [machine_name]" + R.info = {"[machine_name] reference

Access code: [access_code]

Do not lose or misplace this code.
"} - // END AUTOFIX //stamp the paper var/image/stampoverlay = image('icons/obj/bureaucracy.dmi') stampoverlay.icon_state = "paper_stamp-cent" @@ -86,8 +81,7 @@ /obj/item/eftpos/ui_data(mob/user, ui_key = "main", datum/topic_state/state = default_state) var/data[0] - data["eftpos_name"] = eftpos_name - data["machine_id"] = machine_id + data["machine_name"] = machine_name data["transaction_locked"] = transaction_locked data["transaction_paid"] = transaction_paid data["transaction_purpose"] = transaction_purpose @@ -112,15 +106,6 @@ print_reference() else to_chat(usr, "[bicon(src)]Incorrect code entered.") - if("change_id") - var/attempt_code = text2num(input("Re-enter the current EFTPOS access code", "Confirm EFTPOS code")) - if(attempt_code == access_code) - var/name = input("Enter a new terminal ID for this device", "Enter new EFTPOS ID") as text|null - if(name) - eftpos_name = "[name] EFTPOS scanner" - print_reference() - else - to_chat(usr, "[bicon(src)]Incorrect code entered.") if("link_account") if(!linked_db) reconnect_database() @@ -179,48 +164,33 @@ if(istype(I, /obj/item/card/id)) var/obj/item/card/id/C = I visible_message("[user] swipes a card through [src].") - if(transaction_locked && !transaction_paid) - if(linked_account) - var/attempt_pin = input("Enter pin code", "EFTPOS transaction") as num - var/datum/money_account/D = attempt_account_access(C.associated_account_number, attempt_pin, 2) - if(D) - if(transaction_amount <= D.money) - playsound(src, 'sound/machines/chime.ogg', 50, 1) - visible_message("[bicon(src)] The [src] chimes.") - transaction_paid = 1 - //transfer the money - D.money -= transaction_amount - linked_account.money += transaction_amount + if(!transaction_locked || transaction_paid) + return + + if(!linked_account) + to_chat(user, "[bicon(src)]EFTPOS is not connected to an account.") + + var/confirm = alert("Are you sure you want to pay $[transaction_amount] to Account: [linked_account.owner_name] ", "Confirm transaction", "Yes", "No") + if(confirm == "No") + return + var/attempt_pin = input("Enter pin code", "EFTPOS transaction") as num + var/datum/money_account/D = attempt_account_access(C.associated_account_number, attempt_pin, 2) + + if(!D) + to_chat(user, "[bicon(src)]Unable to access account. Check security settings and try again.") + + if(transaction_amount > D.money) + to_chat(user, "[bicon(src)]You don't have that much money!") + return + + var/transSuccess = D.charge(transaction_amount, linked_account, transaction_purpose, machine_name, D.owner_name) + if(transSuccess == TRUE) + playsound(src, 'sound/machines/chime.ogg', 50, 1) + visible_message("[bicon(src)] The [src] chimes.") + transaction_paid = 1 - //create entries in the two account transaction logs - var/datum/transaction/T = new() - T.target_name = "[linked_account.owner_name] (via [eftpos_name])" - T.purpose = transaction_purpose - if(transaction_amount > 0) - T.amount = "([transaction_amount])" - else - T.amount = "[transaction_amount]" - T.source_terminal = machine_id - T.date = current_date_string - T.time = station_time_timestamp() - D.transaction_log.Add(T) - // - T = new() - T.target_name = D.owner_name - T.purpose = transaction_purpose - T.amount = "[transaction_amount]" - T.source_terminal = machine_id - T.date = current_date_string - T.time = station_time_timestamp() - linked_account.transaction_log.Add(T) - else - to_chat(user, "[bicon(src)]You don't have that much money!") - else - to_chat(user, "[bicon(src)]Unable to access account. Check security settings and try again.") - else - to_chat(user, "[bicon(src)]EFTPOS is not connected to an account.") else ..() - //emag? \ No newline at end of file + //emag? diff --git a/code/modules/economy/utils.dm b/code/modules/economy/utils.dm index 60361ad3f77..30d570bac92 100644 --- a/code/modules/economy/utils.dm +++ b/code/modules/economy/utils.dm @@ -46,47 +46,69 @@ /datum/money_account/proc/fmtBalance() return "$[num2septext(money)]" -/datum/money_account/proc/charge(var/transaction_amount,var/datum/money_account/dest,var/transaction_purpose, var/terminal_name="", var/terminal_id=0, var/dest_name = "UNKNOWN") +// Seperated from charge so they can reuse the code and also because there's many instances where a log will be made without actually making a transaction +/datum/money_account/proc/makeTransactionLog(transaction_amount = 0, transaction_purpose, terminal_name = "", + dest_name = "UNKNOWN", charging = TRUE, date = current_date_string, time = "") + var/datum/transaction/T = new() + T.target_name = dest_name + T.purpose = transaction_purpose + if(!charging || transaction_amount == 0) + T.amount = "[transaction_amount]" + else + T.amount = "([transaction_amount])" + + T.source_terminal = terminal_name + T.date = date + if(time == "") + T.time = station_time_timestamp() + else + T.time = time + transaction_log.Add(T) + + // Charge is for transferring money from an account to another. The destination account can possibly not exist (Magical money sink) +/datum/money_account/proc/charge(transaction_amount = 0, datum/money_account/dest, transaction_purpose, + terminal_name = "", dest_name = "UNKNOWN", dest_purpose, dest_target_name) if(suspended) to_chat(usr, "Unable to access source account: account suspended.") return 0 - + + if(transaction_amount <= money) + //transfer the money + money -= transaction_amount + makeTransactionLog(transaction_amount, transaction_purpose, terminal_name, dest_name) + if(dest) + dest.money += transaction_amount + dest.makeTransactionLog(transaction_amount, + dest_purpose ? dest_purpose : transaction_purpose, terminal_name, dest_target_name ? dest_target_name : dest_name, FALSE) + return 1 + else + to_chat(usr, "Insufficient funds in account.") + return 0 + +// phantom_charge is for when you want to charge an account, without making any corresponding log (e.g. you make it yourself with custom date +// or there won't be any log for some IC reasons (hacking) +/datum/money_account/proc/phantom_charge(transaction_amount = 0, datum/money_account/dest, suspensionbypass = 0) + if(suspended && !suspensionbypass) + return 0 + if(transaction_amount <= money) //transfer the money money -= transaction_amount if(dest) dest.money += transaction_amount - - //create entries in the two account transaction logs - var/datum/transaction/T - if(dest) - T = new() - T.target_name = owner_name - if(terminal_name!="") - T.target_name += " (via [terminal_name])" - T.purpose = transaction_purpose - if(transaction_amount > 0) - T.amount = "([transaction_amount])" - else - T.amount = "[transaction_amount]" - if(terminal_id) - T.source_terminal = terminal_id - T.date = current_date_string - T.time = station_time_timestamp() - dest.transaction_log.Add(T) - // - T = new() - T.target_name = (!dest) ? dest_name : dest.owner_name - if(terminal_name!="") - T.target_name += " (via [terminal_name])" - T.purpose = transaction_purpose - T.amount = "[transaction_amount]" - if(terminal_id) - T.source_terminal = terminal_id - T.date = current_date_string - T.time = station_time_timestamp() - transaction_log.Add(T) return 1 else - to_chat(usr, "Insufficient funds in account.") - return 0 \ No newline at end of file + return 0 + +// Credit is for giving money to an account out of thin air. Suspension does not matter. +/datum/money_account/proc/credit(transaction_amount = 0, transaction_purpose, + terminal_name = "", dest_name = "UNKNOWN", date = current_date_string, time = "") + + money += transaction_amount + makeTransactionLog(transaction_amount, transaction_purpose, terminal_name, dest_name, FALSE, date, time) + return 1 + +//phantom_credit is like the above without any log +/datum/money_account/proc/phantom_credit(transaction_amount = 0) + money += transaction_amount + return 1 diff --git a/code/modules/events/money_hacker.dm b/code/modules/events/money_hacker.dm index 641fec1405e..4ba4a14a315 100644 --- a/code/modules/events/money_hacker.dm +++ b/code/modules/events/money_hacker.dm @@ -1,3 +1,6 @@ +#define MINIMUM_PERCENTAGE_LOSS 0.5 +#define VARIABLE_LOSS 2 // Invariant: 1 - VARIABLE_LOSS/10 >= MINIMUM_PERCENTAGE_LOSS + /var/global/account_hack_attempted = 0 /datum/event/money_hacker @@ -16,7 +19,7 @@ /datum/event/money_hacker/announce() var/message = "A brute force hack has been detected (in progress since [station_time_timestamp()]). The target of the attack is: Financial account #[affected_account.account_number], \ - without intervention this attack will succeed in approximately 10 minutes. Required intervention: temporary suspension of affected accounts until the attack has ceased. \ + without intervention this attack will succeed in approximately 10 minutes. Required intervention: temporary suspension of affected account until the attack has ceased. \ Notifications will be sent as updates occur.
" var/my_department = "[station_name()] firewall subroutines" @@ -32,35 +35,38 @@ /datum/event/money_hacker/end() var/message - if(affected_account && !affected_account) - //hacker wins + if(!isnull(affected_account) && !affected_account.suspended) message = "The hack attempt has succeeded." - //subtract the money - var/lost = affected_account.money * 0.8 + (rand(2,4) - 2) / 10 - affected_account.money -= lost + var/lost = affected_account.money * (MINIMUM_PERCENTAGE_LOSS + rand(0,VARIABLE_LOSS) / 10); + + affected_account.phantom_charge(lost) + //create a taunting log entry - var/datum/transaction/T = new() - T.target_name = pick("","yo brotha from anotha motha","el Presidente","chieF smackDowN") - T.purpose = pick("Ne$ ---ount fu%ds init*&lisat@*n","PAY BACK YOUR MUM","Funds withdrawal","pWnAgE","l33t hax","liberationez") - T.amount = pick("","([rand(0,99999)])","alla money","9001$","HOLLA HOLLA GET DOLLA","([lost])") + var/dest_name = pick("","yo brotha from anotha motha","el Presidente","chieF smackDowN") + var/amount = pick("","([rand(0,99999)])","alla money","9001$","HOLLA HOLLA GET DOLLA","([lost])") + var/purpose = pick("Ne$ ---ount fu%ds init*&lisat@*n","PAY BACK YOUR MUM","Funds withdrawal","pWnAgE","l33t hax","liberationez") var/date1 = "31 December, 1999" var/date2 = "[num2text(rand(1,31))] [pick("January","February","March","April","May","June","July","August","September","October","November","December")], [rand(1000,3000)]" - T.date = pick("", current_date_string, date1, date2) + var/date = pick("", current_date_string, date1, date2) var/time1 = rand(0, 99999999) var/time2 = "[round(time1 / 36000)+12]:[(time1 / 600 % 60) < 10 ? add_zero(time1 / 600 % 60, 1) : time1 / 600 % 60]" - T.time = pick("", station_time_timestamp(), time2) - T.source_terminal = pick("","[pick("Biesel","New Gibson")] GalaxyNet Terminal #[rand(111,999)]","your mums place","nantrasen high CommanD") + var/time = pick("", station_time_timestamp(), time2) + var/source_terminal = pick("","[pick("Biesel","New Gibson")] GalaxyNet Terminal #[rand(111,999)]","your mums place","nantrasen high CommanD") + + affected_account.makeTransactionLog(amount, purpose, source_terminal, dest_name, TRUE, date, time) - affected_account.transaction_log.Add(T) else //crew wins - message = "The attack has ceased, the affected accounts can now be brought online." + message = "The attack has ceased, the affected account can now be brought online." var/my_department = "[station_name()] firewall subroutines" for(var/obj/machinery/message_server/MS in world) if(!MS.active) continue MS.send_rc_message("Head of Personnel's Desk", my_department, message, "", "", 2) + +#undef MINIMUM_PERCENTAGE_LOSS +#undef VARIABLE_LOSS diff --git a/code/modules/events/money_lotto.dm b/code/modules/events/money_lotto.dm index b95278b441b..9339ee6a626 100644 --- a/code/modules/events/money_lotto.dm +++ b/code/modules/events/money_lotto.dm @@ -8,19 +8,9 @@ if(all_money_accounts.len) var/datum/money_account/D = pick(all_money_accounts) winner_name = D.owner_name - if(!D.suspended) - D.money += winner_sum - var/datum/transaction/T = new() - T.target_name = "Nyx Daily Grand Slam -Stellar- Lottery" - T.purpose = "Winner!" - T.amount = winner_sum - T.date = current_date_string - T.time = worldtime2text() - T.source_terminal = "Biesel TCD Terminal #[rand(111,333)]" - D.transaction_log.Add(T) - - deposit_success = 1 + D.credit(winner_sum, "Winner!", "Biesel TCD Terminal #[rand(111,333)]", "Nyx Daily Grand Slam -Stellar- Lottery") + deposit_success = 1 /datum/event/money_lotto/announce() var/datum/feed_message/newMsg = new /datum/feed_message diff --git a/code/modules/modular_computers/laptop_vendor.dm b/code/modules/modular_computers/laptop_vendor.dm index 7ba6ba5751a..4fe833e08ae 100644 --- a/code/modules/modular_computers/laptop_vendor.dm +++ b/code/modules/modular_computers/laptop_vendor.dm @@ -282,21 +282,9 @@ obj/machinery/lapvend/attackby(obj/item/I, mob/user) atom_say("Insufficient funds in account.") return 0 else - var/paid = customer_account.charge(total_price, - transaction_purpose = "Purchase of [(devtype == 1) ? "laptop computer" : "tablet microcomputer"].", - terminal_name = name, - terminal_id = name, - dest_name = vendor_account.owner_name) + customer_account.charge(total_price, vendor_account, + "Purchase of [(devtype == 1) ? "laptop computer" : "tablet microcomputer"].", + name, customer_account.owner_name, "Sale of [(devtype == 1) ? "laptop computer" : "tablet microcomputer"].", + customer_account.owner_name) - if(paid) - vendor_account.money += total_price - var/datum/transaction/T = new() - T.target_name = customer_account.owner_name - T.purpose = "Purchase of [(devtype == 1) ? "laptop computer" : "tablet microcomputer"]" - T.amount = "[total_price]" - T.source_terminal = name - T.date = current_date_string - T.time = station_time_timestamp() - vendor_account.transaction_log.Add(T) - return 1 - return 0 + return 1 diff --git a/nano/templates/eftpos.tmpl b/nano/templates/eftpos.tmpl index 663f665d7f9..15f6aae465e 100644 --- a/nano/templates/eftpos.tmpl +++ b/nano/templates/eftpos.tmpl @@ -1,23 +1,22 @@ - -

{{:data.eftpos_name}}

-This terminal is {{:data.machine_id}}. Report this code when contacting Nanotrasen IT Support
+This terminal is {{:data.machine_name}}. Report this code when contacting Nanotrasen IT Support
{{if data.transaction_locked == 1}}
{{:helper.link(data.transaction_paid ? 'Reset' : 'Reset (authentication required)', 'unlock', {'choice' : 'toggle_lock'})}}

-
Transaction purpose:
+
Transaction purpose:
{{:data.transaction_purpose}}
- +
-
Value:
+
Value:
{{:data.transaction_amount}}
- +
Linked account:
{{:data.linked_account ? data.linked_account : 'None'}}
@@ -33,15 +32,15 @@ Used In File(s): /code/modules/economy/EFTPOS.dm
{{:helper.link('Lock in new transaction', 'lock', {'choice' : 'toggle_lock'})}}

-
Transaction purpose:
+
Transaction purpose:
{{:helper.link(data.transaction_purpose, 'info', {'choice' : 'trans_purpose'})}}
- +
-
Value:
+
Value:
{{:helper.link(data.transaction_amount, 'usd', {'choice' : 'trans_value'})}}
- +
Linked account:
{{:helper.link(data.linked_account ? data.linked_account : 'None', data.linked_account ? 'user' : 'user-times', {'choice' : 'link_account'})}}
@@ -49,7 +48,6 @@ Used In File(s): /code/modules/economy/EFTPOS.dm
{{:helper.link('Change access code', 'key', {'choice' : 'change_code'})}}
-
{{:helper.link('Change EFTPOS ID', 'pencil', {'choice' : 'change_id'})}}
{{:helper.link('Scan card to reset acess code', 'refresh', {'choice' : 'reset'})}}
-{{/if}} \ No newline at end of file +{{/if}} From e5ac58eadf7188e5127236a8ba35fc3c49756d59 Mon Sep 17 00:00:00 2001 From: variableundefined <40092670+variableundefined@users.noreply.github.com> Date: Thu, 26 Jul 2018 19:41:42 +0800 Subject: [PATCH 2/3] Fixes slot machine chance --- code/game/machinery/slotmachine.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/machinery/slotmachine.dm b/code/game/machinery/slotmachine.dm index dd8e83d565c..994e27194f0 100644 --- a/code/game/machinery/slotmachine.dm +++ b/code/game/machinery/slotmachine.dm @@ -89,7 +89,7 @@ result = "You win fifty credits!" resultlvl = "good" win_money(50) - else if(roll > 300 && roll <= 4000) + else if(roll > 300 && roll <= 1000) visible_message("[src] says, 'Winner! [usr.name] has won ten credits!'") result = "You win ten credits!" resultlvl = "good" From 0b4ed1f610925283cc685fdae8aeb3f6882bd6cb Mon Sep 17 00:00:00 2001 From: variableundefined <40092670+variableundefined@users.noreply.github.com> Date: Wed, 5 Sep 2018 07:45:10 +0800 Subject: [PATCH 3/3] Remove excessive var and add one missing return statement --- code/modules/economy/Accounts.dm | 2 +- code/modules/economy/EFTPOS.dm | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/code/modules/economy/Accounts.dm b/code/modules/economy/Accounts.dm index 792e53f307b..f1f283fe56a 100644 --- a/code/modules/economy/Accounts.dm +++ b/code/modules/economy/Accounts.dm @@ -135,7 +135,7 @@ var/global/list/all_money_accounts = list() var/time = "" var/source_terminal = "" -/obj/machinery/computer/account_database/proc/charge_to_account(var/attempt_account_number, datum/money_account/source, var/purpose, var/terminal_id, var/amount) +/obj/machinery/computer/account_database/proc/charge_to_account(attempt_account_number, datum/money_account/source, purpose, terminal_id, amount) if(!activated) return 0 for(var/datum/money_account/D in all_money_accounts) diff --git a/code/modules/economy/EFTPOS.dm b/code/modules/economy/EFTPOS.dm index e5f3cf6529e..b636a96e2aa 100644 --- a/code/modules/economy/EFTPOS.dm +++ b/code/modules/economy/EFTPOS.dm @@ -170,6 +170,7 @@ if(!linked_account) to_chat(user, "[bicon(src)]EFTPOS is not connected to an account.") + return var/confirm = alert("Are you sure you want to pay $[transaction_amount] to Account: [linked_account.owner_name] ", "Confirm transaction", "Yes", "No") if(confirm == "No")