From 88b933e8a05d343c01f6697d103e07da30a393ed Mon Sep 17 00:00:00 2001 From: Tastyfish Date: Thu, 10 Dec 2015 17:35:32 -0500 Subject: [PATCH] Made slot machine have reactive ui, use bank correctly --- code/game/machinery/slotmachine.dm | 103 ++++++++++++++++++----------- code/modules/economy/utils.dm | 2 + nano/templates/slotmachine.tmpl | 34 ++++++++++ 3 files changed, 100 insertions(+), 39 deletions(-) create mode 100644 nano/templates/slotmachine.tmpl diff --git a/code/game/machinery/slotmachine.dm b/code/game/machinery/slotmachine.dm index 7e132f64614..baceb213864 100644 --- a/code/game/machinery/slotmachine.dm +++ b/code/game/machinery/slotmachine.dm @@ -9,41 +9,48 @@ var/datum/announcement/minor/slotmachine_announcement = new(do_log = 0) density = 1 var/plays = 0 var/working = 0 - var/balance=0 + var/datum/money_account/account = null + var/result = null + var/resultlvl = null -/obj/machinery/slot_machine/attack_hand(var/mob/user as mob) - if(user.mind) - if(user.mind.initial_account) - balance = user.mind.initial_account.money - user.machine = src - if (working) - var/dat = {"Slot Machine
-

- Please wait!
"} - user << browse(dat, "window=slotmachine;size=450x500") - onclose(user, "slotmachine") - else - var/dat = {"Slot Machine
-

- Five credits to play!
- Credits Remaining: [balance]
- [plays] players have tried their luck today!
-

- Play!
"} - user << browse(dat, "window=slotmachine;size=400x500") - onclose(user, "slotmachine") +/obj/machinery/slot_machine/attack_hand(mob/user as mob) + account = user.get_worn_id_account() + if(!account) + if(istype(user.get_active_hand(), /obj/item/weapon/card/id)) + account = get_card_account(user.get_active_hand()) + else + account = null + + ui_interact(user) + +/obj/machinery/slot_machine/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1) + var/data[0] + + data["working"] = working + data["money"] = account ? account.money : null + data["plays"] = plays + data["result"] = result + data["resultlvl"] = resultlvl + + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + if (!ui) + ui = new(user, src, ui_key, "slotmachine.tmpl", name, 350, 200) + ui.set_initial_data(data) + ui.open() + ui.set_auto_update(1) /obj/machinery/slot_machine/Topic(href, href_list) + add_fingerprint(usr) + if(href_list["ops"]) var/operation = text2num(href_list["ops"]) if(operation == 1) // Play if (working == 1) - usr << "You need to wait until the machine stops spinning!" return - if (balance < 5) - usr << "Insufficient money to play!" + if (!account || account.money < 5) + return + if(!account.charge(5, transaction_purpose = "Bet", dest_name = name)) return - usr.mind.initial_account.money -= 5 plays += 1 working = 1 icon_state = "slots-on" @@ -54,23 +61,41 @@ var/datum/announcement/minor/slotmachine_announcement = new(do_log = 0) playsound(src.loc, 'sound/effects/engine_alert2.ogg', 50, 0) visible_message("[src] says, 'JACKPOT! [usr.name] has won two hundred and fifty thousand credits!'") slotmachine_announcement.Announce("Congratulations to [usr.name] on winning the jackpot of two hundred and fifty thousand credits!", "Jackpot Winner") - usr.mind.initial_account.money += 250000 + result = "JACKPOT! You win two hundred and fifty thousand credits!" + resultlvl = "highlight" + win_money(250000, 0) else if (roll > 1 && roll <= 10) - playsound(src.loc, 'sound/machines/ping.ogg', 50, 0) visible_message("[src] says, 'Big Winner! [usr.name] has won five thousand credits!'") - usr.mind.initial_account.money += 5000 + result = "Big Winner! You win five thousand credits!" + resultlvl = "good" + win_money(5000) else if (roll > 10 && roll <= 100) - playsound(src.loc, 'sound/machines/ping.ogg', 50, 0) - visible_message("[src] says, 'Winner! [usr.name] has won win five hundred credits!'") - usr.mind.initial_account.money += 500 + visible_message("[src] says, 'Winner! [usr.name] has won five hundred credits!'") + result = "You win five hundred credits!" + resultlvl = "good" + win_money(500) else if (roll > 100 && roll <= 1000) - playsound(src.loc, 'sound/machines/ping.ogg', 50, 0) - usr << "You win 5 credits!" - usr.mind.initial_account.money += 5 + result = "You win 5 credits!" + resultlvl = "good" + win_money(5) else - usr << "No luck!" + result = "No luck!" + resultlvl = "average" working = 0 icon_state = "slots-off" - add_fingerprint(usr) - updateUsrDialog() - return + +/obj/machinery/slot_machine/proc/win_money(amt, playsnd=1) + if(playsnd) + playsound(src.loc, 'sound/machines/ping.ogg', 50, 0) + + 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 = worldtime2text() + account.transaction_log.Add(T) \ No newline at end of file diff --git a/code/modules/economy/utils.dm b/code/modules/economy/utils.dm index a6997bab4f4..44b5ebdd036 100644 --- a/code/modules/economy/utils.dm +++ b/code/modules/economy/utils.dm @@ -31,6 +31,8 @@ if(ishuman(src)) var/mob/living/carbon/human/H=src var/obj/item/weapon/card/id/I=H.get_idcard() + if(!I || !istype(I)) + return null var/attempt_pin=0 var/datum/money_account/D = get_money_account(I.associated_account_number) if(require_pin && user) diff --git a/nano/templates/slotmachine.tmpl b/nano/templates/slotmachine.tmpl new file mode 100644 index 00000000000..980bea6dcba --- /dev/null +++ b/nano/templates/slotmachine.tmpl @@ -0,0 +1,34 @@ + +{{if data.money != null}} +
+ {{:data.plays}} players have tried their luck today! +
+
+
Credits Remaining:
+ {{:helper.string("
{1}
", data.money >= 5 ? "" : "bad", data.money)}} +
+
+
+ Five credits to play! +
+
+ {{:helper.link('SPIN!', 'arrowrefresh-1-s', {'ops' : 1}, data.money >= 5 && !data.working ? null : 'disabled')}} +
+
+ {{if data.result}} +
+ {{:data.result}} +
+ {{/if}} + {{if data.working}} +
Spinning!
+ {{/if}} +{{else}} +
+ Could not scan your card or could not find account!
+ Please wear or hold your ID and try again. +
+{{/if}} \ No newline at end of file