Economy Changes Phase 1

This commit is contained in:
ZomgPonies
2015-01-30 23:59:27 -05:00
parent 9d9bdfc0ea
commit ae02ebb446
13 changed files with 11524 additions and 11836 deletions
+14 -1
View File
@@ -98,6 +98,7 @@ log transactions
if(istype(I,/obj/item/weapon/spacecash))
//consume the money
authenticated_account.money += I:worth * I:amount
authenticated_account.update_balance(authenticated_account.account_number,authenticated_account.money)
if(prob(50))
playsound(loc, 'sound/items/polaroid1.ogg', 50, 1)
else
@@ -196,6 +197,7 @@ log transactions
<A href='?src=\ref[src];choice=view_screen;view_screen=1'>Change account security level</a><br>
<A href='?src=\ref[src];choice=view_screen;view_screen=2'>Make transfer</a><br>
<A href='?src=\ref[src];choice=view_screen;view_screen=3'>View transaction log</a><br>
<A href='?src=\ref[src];choice=change_pin'>Change PIN</a><br>
<A href='?src=\ref[src];choice=balance_statement'>Print balance statement</a><br>
<A href='?src=\ref[src];choice=logout'>Logout</a><br>"}
else if(linked_db)
@@ -217,6 +219,7 @@ log transactions
/obj/machinery/atm/Topic(var/href, var/href_list)
if(href_list["choice"])
switch(href_list["choice"])
if("transfer")
if(authenticated_account && linked_db)
var/transfer_amount = text2num(href_list["funds_amount"])
@@ -228,6 +231,7 @@ log transactions
if(linked_db.charge_to_account(target_account_number, authenticated_account.owner_name, transfer_purpose, machine_id, transfer_amount))
usr << "\icon[src]<span class='info'>Funds transfer successful.</span>"
authenticated_account.money -= transfer_amount
authenticated_account.update_balance(authenticated_account.account_number,authenticated_account.money)
//create an entry in the account transaction log
var/datum/transaction/T = new()
@@ -240,7 +244,6 @@ log transactions
authenticated_account.transaction_log.Add(T)
else
usr << "\icon[src]<span class='warning'>Funds transfer failed.</span>"
else
usr << "\icon[src]<span class='warning'>You don't have enough funds to do that!</span>"
if("view_screen")
@@ -312,6 +315,7 @@ log transactions
usr << "\blue The ATM's screen flashes, 'Maximum single withdrawl limit reached, defaulting to 10,000.'"
amount = 10000
authenticated_account.money -= amount
authenticated_account.update_balance(authenticated_account.account_number,authenticated_account.money)
withdraw_arbitrary_sum(amount)
//create an entry in the account transaction log
@@ -368,6 +372,15 @@ log transactions
usr.drop_item()
I.loc = src
held_card = I
if("change_pin")
if(authenticated_account)
var/new_pin = input(usr,"Enter new pin code", "PIN code changer") as num
authenticated_account.remote_access_pin = new_pin
var/DBQuery/query = dbcon.NewQuery("UPDATE characters SET account_pin='[new_pin]' WHERE account_number='[authenticated_account.account_number]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR changing bank pin. Error : \[[err]\]\n")
message_admins("SQL ERROR changing bank pin. Error : \[[err]\]\n")
if("logout")
authenticated_account = null
//usr << browse(null,"window=atm")
+32 -276
View File
@@ -1,12 +1,13 @@
var/global/current_date_string
var/global/num_financial_terminals = 1
var/global/datum/money_account/station_account
var/global/list/datum/money_account/department_accounts = list()
//var/global/datum/money_account/station_account
//var/global/list/datum/money_account/department_accounts = list()
var/global/next_account_number = 0
var/global/obj/machinery/account_database/centcomm_account_db
var/global/datum/money_account/vendor_account
//var/global/datum/money_account/vendor_account
var/global/list/all_money_accounts = list()
/*
/proc/create_station_account()
if(!station_account)
next_account_number = rand(111111, 999999)
@@ -56,67 +57,40 @@ var/global/list/all_money_accounts = list()
//the current ingame time (hh:mm) can be obtained by calling:
//worldtime2text()
*/
/proc/create_account(var/new_owner_name = "Default user", var/starting_funds = 0, var/obj/machinery/account_database/source_db)
//create a new account
var/datum/money_account/M = new()
M.owner_name = new_owner_name
M.remote_access_pin = rand(1111, 111111)
M.money = starting_funds
var/DBQuery/query = dbcon.NewQuery("SELECT account_number,account_pin,account_balance FROM characters WHERE real_name='[sql_sanitize_text(new_owner_name)]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR retrieving bank account information. Error : \[[err]\]\n")
message_admins("SQL ERROR retrieving bank account information. Error : \[[err]\]\n")
return
//create an entry in the account transaction log for when it was created
var/datum/transaction/T = new()
T.target_name = new_owner_name
T.purpose = "Account creation"
T.amount = starting_funds
if(!source_db)
//set a random date, time and location some time over the past few decades
T.date = "[num2text(rand(1,31))] [pick("January","February","March","April","May","June","July","August","September","October","November","December")], 25[rand(10,56)]"
T.time = "[rand(0,24)]:[rand(11,59)]"
T.source_terminal = "NTGalaxyNet Terminal #[rand(111,1111)]"
M.account_number = rand(111111, 999999)
else
T.date = current_date_string
T.time = worldtime2text()
T.source_terminal = source_db.machine_id
//general preferences
while(query.NextRow())
//create a new account
var/datum/money_account/M = new()
M.owner_name = new_owner_name
if(text2num(query.item[1]) == 0)
M.remote_access_pin = rand(1111, 111111)
M.money = 1000
M.account_number = rand(111111, 999999)
var/DBQuery/query2 = dbcon.NewQuery("UPDATE characters SET account_number='[M.account_number]',account_pin='[M.remote_access_pin]', account_balance='[M.money]' WHERE real_name='[sql_sanitize_text(new_owner_name)]'")
if(!query2.Execute())
var/err = query2.ErrorMsg()
log_game("SQL ERROR creating bank account. Error : \[[err]\]\n")
message_admins("SQL ERROR creating bank account. Error : \[[err]\]\n")
return
M.account_number = next_account_number
next_account_number += rand(1,25)
else
M.remote_access_pin = text2num(query.item[2])
M.money = text2num(query.item[3])
M.account_number = text2num(query.item[1])
//create a sealed package containing the account details
var/obj/item/smallDelivery/P = new /obj/item/smallDelivery(source_db.loc)
var/obj/item/weapon/paper/R = new /obj/item/weapon/paper(P)
P.wrapped = R
R.name = "Account information: [M.owner_name]"
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:94: R.info = "<b>Account details (confidential)</b><br><hr><br>"
R.info = {"<b>Account details (confidential)</b><br><hr><br>
<i>Account holder:</i> [M.owner_name]<br>
<i>Account number:</i> [M.account_number]<br>
<i>Account pin:</i> [M.remote_access_pin]<br>
<i>Starting balance:</i> $[M.money]<br>
<i>Date and time:</i> [worldtime2text()], [current_date_string]<br><br>
<i>Creation terminal ID:</i> [source_db.machine_id]<br>
<i>Authorised NT officer overseeing creation:</i> [source_db.held_card.registered_name]<br>"}
// END AUTOFIX
//stamp the paper
var/image/stampoverlay = image('icons/obj/bureaucracy.dmi')
stampoverlay.icon_state = "paper_stamp-cent"
if(!R.stamped)
R.stamped = new
R.stamped += /obj/item/weapon/stamp
R.overlays += stampoverlay
R.stamps += "<HR><i>This paper has been stamped by the Accounts Database.</i>"
//add the account
M.transaction_log.Add(T)
all_money_accounts.Add(M)
return M
all_money_accounts.Add(M)
return M
/datum/money_account
var/owner_name = ""
@@ -140,225 +114,7 @@ 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/weapon/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 = "<b>Accounts Database</b><br>"
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:171: dat += "<i>[machine_id]</i><br>"
dat += {"<i>[machine_id]</i><br>
Confirm identity: <a href='?src=\ref[src];choice=insert_card'>[held_card ? held_card : "-----"]</a><br>"}
// 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 += "<a href='?src=\ref[src];toggle_activated=1'>[activated ? "Disable" : "Enable"] remote access</a><br>"
dat += {"<a href='?src=\ref[src];toggle_activated=1'>[activated ? "Disable" : "Enable"] remote access</a><br>
You may not edit accounts at this terminal, only create and view them.<br>"}
// 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 += "<br>"
dat += {"<br>
<a href='?src=\ref[src];choice=view_accounts_list;'>Return to accounts list</a>
<form name='create_account' action='?src=\ref[src]' method='get'>
<input type='hidden' name='src' value='\ref[src]'>
<input type='hidden' name='choice' value='finalise_create_account'>
<b>Holder name:</b> <input type='text' id='holder_name' name='holder_name' style='width:250px; background-color:white;'><br>
<b>Initial funds:</b> <input type='text' id='starting_funds' name='starting_funds' style='width:250px; background-color:white;'> (subtracted from station account)<br>
<i>New accounts are automatically assigned a secret number and pin, which are printed separately in a sealed package.</i><br>
<input type='submit' value='Create'><br>
</form>"}
// 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 += "<br>"
dat += {"<br>
<a href='?src=\ref[src];choice=view_accounts_list;'>Return to accounts list</a><hr>
<b>Account number:</b> #[detailed_account_view.account_number]<br>
<b>Account holder:</b> [detailed_account_view.owner_name]<br>
<b>Account balance:</b> $[detailed_account_view.money]<br>
<table border=1 style='width:100%'>
<tr>
<td><b>Date</b></td>
<td><b>Time</b></td>
<td><b>Target</b></td>
<td><b>Purpose</b></td>
<td><b>Value</b></td>
<td><b>Source terminal ID</b></td>
</tr>"}
// 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 += "<tr>"
dat += {"<tr>
<td>[T.date]</td>
<td>[T.time]</td>
<td>[T.target_name]</td>
<td>[T.purpose]</td>
<td>$[T.amount]</td>
<td>[T.source_terminal]</td>
</tr>"}
// END AUTOFIX
dat += "</table>"
else
// AUTOFIXED BY fix_string_idiocy.py
// C:\Users\Rob\Documents\Projects\vgstation13\code\WorkInProgress\Cael_Aislinn\Economy\Accounts.dm:215: dat += "<a href='?src=\ref[src];choice=create_account;'>Create new account</a><br><br>"
dat += {"<a href='?src=\ref[src];choice=create_account;'>Create new account</a><br><br>
<table border=1 style='width:100%'>"}
// 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 += "<tr>"
dat += {"<tr>
<td>#[D.account_number]</td>
<td>[D.owner_name]</td>
<td><a href='?src=\ref[src];choice=view_account_detail;account_index=[i]'>View in detail</a></td>
</tr>"}
// END AUTOFIX
dat += "</table>"
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/weapon/card))
var/obj/item/weapon/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 = worldtime2text()
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/weapon/card/id))
var/obj/item/weapon/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/account_database/proc/charge_to_account(var/attempt_account_number, var/source_name, 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 = worldtime2text()
T.source_terminal = terminal_id
D.transaction_log.Add(T)
return 1
return 0
//this returns the first account datum that matches the supplied accnum/pin combination, it returns null if the combination did not match any account
/proc/attempt_account_access(var/attempt_account_number, var/attempt_pin_number, var/security_level_passed = 0,var/pin_needed=1)
+36 -10
View File
@@ -10,7 +10,7 @@
var/machine_id = ""
var/obj/item/weapon/card/id/held_card
var/datum/money_account/detailed_account_view
var/creating_new_account = 0
// var/creating_new_account = 0
var/activated = 1
proc/get_access_level()
@@ -39,8 +39,32 @@
<u>Generated By:</u> [held_card.registered_name], [held_card.assignment]<br>
"}
/obj/machinery/account_database/proc/charge_to_account(var/attempt_account_number, var/source_name, 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 = worldtime2text()
T.source_terminal = terminal_id
D.transaction_log.Add(T)
return 1
return 0
/obj/machinery/account_database/New()
if(!station_account)
/* if(!station_account)
create_station_account()
if(department_accounts.len == 0)
@@ -48,7 +72,7 @@
create_department_account(department)
if(!vendor_account)
create_department_account("Vendor")
vendor_account = department_accounts["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"
@@ -82,9 +106,9 @@
data["id_card"] = held_card ? text("[held_card.registered_name], [held_card.assignment]") : "-----"
data["access_level"] = get_access_level()
data["machine_id"] = machine_id
data["creating_new_account"] = creating_new_account
// data["creating_new_account"] = creating_new_account
data["detailed_account_view"] = !!detailed_account_view
data["station_account_number"] = station_account.account_number
// data["station_account_number"] = station_account.account_number
data["transactions"] = null
data["accounts"] = null
@@ -129,10 +153,11 @@
if(..())
return 1
var/datum/nanoui/ui = nanomanager.get_open_ui(usr, src, "main")
// var/datum/nanoui/ui = nanomanager.get_open_ui(usr, src, "main")
if(href_list["choice"])
switch(href_list["choice"])
/*
if("create_account")
creating_new_account = 1
@@ -145,12 +170,12 @@
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
callHook("change_account_status", list(detailed_account_view))
/*
if("finalise_create_account")
var/account_name = href_list["holder_name"]
var/starting_funds = max(text2num(href_list["starting_funds"]), 0)
@@ -167,6 +192,7 @@
ui.close()
creating_new_account = 0
*/
if("insert_card")
if(held_card)
held_card.loc = src.loc
@@ -190,7 +216,7 @@
if("view_accounts_list")
detailed_account_view = null
creating_new_account = 0
/* creating_new_account = 0
if("revoke_payroll")
var/funds = detailed_account_view.money
@@ -204,7 +230,7 @@
station_account.transaction_log.Add(station_trx)
callHook("revoke_payroll", list(detailed_account_view))
*/
if("print")
var/text
var/obj/item/weapon/paper/P = new(loc)
+11 -3
View File
@@ -38,8 +38,8 @@
if(D.remote_access_pin != attempt_pin)
return null
return D
else if(issilicon(src))
return station_account
// else if(issilicon(src))
// return station_account
/datum/money_account/proc/fmtBalance()
return "$[num2septext(money)]"
@@ -48,6 +48,7 @@
if(transaction_amount <= money)
//transfer the money
money -= transaction_amount
update_balance(account_number,money)
if(dest)
dest.money += transaction_amount
@@ -83,4 +84,11 @@
return 1
else
usr << "\icon[src]<span class='warning'>You don't have that much money!</span>"
return 0
return 0
/datum/money_account/proc/update_balance(var/account_number,var/newbalance)
var/DBQuery/query = dbcon.NewQuery("UPDATE characters SET account_balance='[newbalance]' WHERE account_number='[account_number]'")
if(!query.Execute())
var/err = query.ErrorMsg()
log_game("SQL ERROR charging bank account. Error : \[[err]\]\n")
message_admins("SQL ERROR charging bank account. Error : \[[err]\]\n")