Claw Game Fixes

Fixes #2795
- Game will now close if you wander away from the machine
- Cannot use the game while laying down/dead
- Game can now be closed like a normal window, and will behave properly
when doing so
- Dropped prizes will actually visibly fall before the game over screen
appears
- Claw game will now properly use machine processing for power and such

Also some code adjustments to help make it more organized or something.
- Seriously though, it does clean some stuff up and removes a redundant
variable
This commit is contained in:
FalseIncarnate
2015-12-10 06:21:46 -05:00
parent 5cc11bc947
commit 7ac2826037
3 changed files with 67 additions and 31 deletions
+47 -14
View File
@@ -11,8 +11,8 @@
var/tokens = 0
var/freeplay = 0 //for debugging and admin kindness
var/token_price = 0
var/playing = 0 //only has one set of controls, so only one person can play at once
var/last_winner = null //for letting people who to hunt down and steal prizes from
var/window_name = "arcade" //in case you want to change the window name for certain machines
/obj/machinery/arcade/New()
..()
@@ -34,22 +34,29 @@
else
user << "\The [src.name] has [tokens] play credits!"
/obj/machinery/arcade/attack_hand(mob/user as mob)
if(..())
if(in_use && src == user.machine) //this one checks if they fell down/died and closes the game
src.close_game()
return
if(in_use && src == user.machine) //this one just checks if they are playing so it doesn't eat tokens
return
interact(user)
/obj/machinery/arcade/interact(mob/user as mob)
if(stat & BROKEN || panel_open)
return 0
return
if(!tokens && !freeplay)
user << "\The [src.name] doesn't have enough credits to play! Pay first!"
return 0
if(!playing && (tokens || freeplay))
user.set_machine(src)
playing = 1
if(!freeplay)
tokens -= 1
return 1
if(playing && (src != user.machine))
user << "Someone else is already playing this machine, please wait your turn!"
return 0
return 1
return
if(!in_use && (tokens || freeplay))
in_use = 1
start_play(user)
return
if(in_use)
if(src != user.machine)
user << "Someone else is already playing this machine, please wait your turn!"
return
/obj/machinery/arcade/attackby(var/obj/item/O as obj, var/mob/user as mob, params)
if(istype(O, /obj/item/weapon/screwdriver) && anchored)
@@ -129,4 +136,30 @@
T.date = current_date_string
T.time = worldtime2text()
customer_account.transaction_log.Add(T)
return 1
return 1
/obj/machinery/arcade/proc/start_play(mob/user as mob)
user.set_machine(src)
if(!freeplay)
tokens -= 1
/obj/machinery/arcade/proc/close_game()
in_use = 0
for(var/mob/user in viewers(world.view, src)) // I don't know who you are.
if(user.client && user.machine == src) // I will look for you,
user.unset_machine() // I will find you,
user << browse(null, "window=[window_name]") // And I will kill you.
return
/obj/machinery/arcade/proc/win()
return
/obj/machinery/arcade/process()
if(in_use)
src.updateUsrDialog()
if(!in_use)
src.close_game()
/obj/machinery/arcade/Destroy()
src.close_game()
return ..()
+11 -13
View File
@@ -6,6 +6,7 @@
icon = 'icons/obj/arcade.dmi'
icon_state = "clawmachine_1_on"
token_price = 15
window_name = "Claw Game"
var/machine_image = "_1"
var/bonus_prize_chance = 5 //chance to dispense a SECOND prize if you win, increased by matter bin rating
@@ -18,8 +19,11 @@
'icons/obj/arcade_images/prizeorbs.png')
/obj/machinery/arcade/claw/New()
src.addAtProcessing()
machine_image = pick("_1", "_2")
update_icon()
component_parts = list()
component_parts += new /obj/item/weapon/circuitboard/clawgame(null)
component_parts += new /obj/item/weapon/stock_parts/matter_bin(null)
@@ -27,6 +31,7 @@
component_parts += new /obj/item/stack/cable_coil(null, 5)
component_parts += new /obj/item/stack/sheet/glass(null, 1)
RefreshParts()
if(!claw_game_html)
claw_game_html = file2text('code/modules/arcade/crane.html')
claw_game_html = replacetext(claw_game_html, "/* ref src */", "\ref[src]")
@@ -48,7 +53,7 @@
icon_state = "clawmachine[machine_image]_on"
return
/obj/machinery/arcade/claw/proc/win()
/obj/machinery/arcade/claw/win()
icon_state = "clawmachine[machine_image]_win"
visible_message("<span class='game say'><span class='name'>[src.name]</span> beeps, \"WINNER!\"</span>")
if(prob(bonus_prize_chance))
@@ -59,17 +64,12 @@
spawn(10)
update_icon()
/obj/machinery/arcade/claw/attack_hand(mob/user as mob)
interact(user)
/obj/machinery/arcade/claw/interact(mob/user as mob)
if(!..())
return
/obj/machinery/arcade/claw/start_play(mob/user as mob)
..()
user << browse_rsc('page.css')
for(var/i=1, i<=img_resources.len, i++)
user << browse_rsc(img_resources[i])
user << browse(claw_game_html, "window=arcade;size=700x600;can_close=0")
return
user << browse(claw_game_html, "window=[window_name];size=700x600")
/obj/machinery/arcade/claw/Topic(href, list/href_list)
if(..())
@@ -77,8 +77,6 @@
var/prize_won = null
prize_won = href_list["prizeWon"]
if(!isnull(prize_won))
usr.unset_machine()
playing = 0
usr << browse(null, "window=arcade") //just in case
close_game()
if(prize_won == "1")
win()
win()
+9 -4
View File
@@ -49,7 +49,7 @@
setTimeout(function(){
state='falling';
$('#debug-streak').html(0); //reset streak
setTimeout(gameShutDown(),500); //end game because you dropped it
setTimeout(gameShutDown,500); //end game because you dropped it
},4*error+300);
}
@@ -252,9 +252,14 @@
if(prizeWon)
close_game_link = '<h2>YOU WON!</h2><br><a href="byond://?src=/* ref src */;prizeWon=1">\[Close Game\]</a>'
document.getElementById('game').innerHTML = '<center><h1> GAME OVER!</h1><br>'+close_game_link+'</center>'
}</script>
}
function emergencyShutDown(){
document.getElementById("close_nao").click();
}
</script>
</head>
<body>
<body onunload="emergencyShutDown()">
<div id='game' style='position: relative;'>
<div id="background"></div>
@@ -274,7 +279,7 @@
</div>
<div id='controls' style='position: absolute; top: 550px'>
<br><button id="play_btn" onclick="gameStartUp()">Play Now!</button> <button id="close_btn" onclick="gameShutDown()">Close Game.</button>
<br><button id="play_btn" onclick="gameStartUp()">Play Now!</button> <button id="close_btn" onclick="gameShutDown()">Close Game.</button><a id="close_nao" hidden="true" href="byond://?src=/* ref src */;prizeWon=0"></a>
<br>
<button onmouseover="joystickControlOn('left')" onmouseout="joystickControlOff('left')">/==<br>\==</button>
<button onmousedown="joystickControlOn('down')" onmouseup="joystickControlOff('down')">DROP<br>CLAW</button>