mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-20 03:25:49 +01:00
[TGUI] Health sensor + Refactor (#19111)
* tgui Health sensor * quick fix, we want to clear out the var * ughhh * health update * sirryan review * exploit fix * this is more how it was supposed to be * no bundle changes because only formatting * aaa indentation is hard * ahaha indentation strikes me again
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
#define MAX_HEALTH_ACTIVATE 0
|
||||
#define MIN_HEALTH_ACTIVATE -150
|
||||
|
||||
/obj/item/assembly/health
|
||||
name = "health sensor"
|
||||
desc = "Used for scanning and monitoring health."
|
||||
icon_state = "health"
|
||||
materials = list(MAT_METAL=800, MAT_GLASS=200)
|
||||
origin_tech = "magnets=1;biotech=1"
|
||||
secured = FALSE
|
||||
|
||||
/// Are we scanning our user's health?
|
||||
var/scanning = FALSE
|
||||
var/health_scan
|
||||
var/alarm_health = 0
|
||||
|
||||
|
||||
/// Our user's health
|
||||
var/user_health
|
||||
/// The health amount on which to activate
|
||||
var/alarm_health = MAX_HEALTH_ACTIVATE
|
||||
|
||||
/obj/item/assembly/health/activate()
|
||||
if(!..())
|
||||
@@ -24,41 +27,33 @@
|
||||
START_PROCESSING(SSobj, src)
|
||||
else
|
||||
scanning = FALSE
|
||||
user_health = null // Clear out the user data, we're no longer scanning
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
update_icon()
|
||||
return secured
|
||||
|
||||
/obj/item/assembly/health/multitool_act(mob/user, obj/item/I)
|
||||
. = TRUE
|
||||
if(!I.use_tool(src, user, 0, volume = I.tool_volume))
|
||||
return
|
||||
if(alarm_health == 0)
|
||||
alarm_health = -90
|
||||
user.show_message("You toggle [src] to \"detect death\" mode.")
|
||||
else
|
||||
alarm_health = 0
|
||||
user.show_message("You toggle [src] to \"detect critical state\" mode.")
|
||||
|
||||
/obj/item/assembly/health/process()
|
||||
if(!scanning || !secured)
|
||||
STOP_PROCESSING(SSobj, src) // It should never reach here, but if it somehow does stop processing
|
||||
return
|
||||
|
||||
var/atom/A = src
|
||||
if(connected && connected.holder)
|
||||
A = connected.holder
|
||||
|
||||
for(A, A && !ismob(A), A=A.loc);
|
||||
for(A, A && !ismob(A), A = A.loc); // For A, check A exists and that its not a mob, if these are both true then set A to A.loc and repeat
|
||||
// like get_turf(), but for mobs.
|
||||
var/mob/living/M = A
|
||||
|
||||
if(M)
|
||||
health_scan = M.health
|
||||
if(health_scan <= alarm_health)
|
||||
pulse()
|
||||
audible_message("[bicon(src)] *beep* *beep*")
|
||||
toggle_scan()
|
||||
if(!isliving(A))
|
||||
user_health = null // We aint on a living thing, remove the previous data
|
||||
return
|
||||
return
|
||||
|
||||
var/mob/living/M = A
|
||||
user_health = M.health
|
||||
if(user_health <= alarm_health) // Its a health detector, not a death detector
|
||||
pulse()
|
||||
audible_message("[bicon(src)] *beep* *beep*")
|
||||
toggle_scan()
|
||||
|
||||
/obj/item/assembly/health/proc/toggle_scan()
|
||||
if(!secured)
|
||||
@@ -67,41 +62,39 @@
|
||||
if(scanning)
|
||||
START_PROCESSING(SSobj, src)
|
||||
else
|
||||
user_health = null // Clear out the user data, we're no longer scanning
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
return
|
||||
|
||||
/obj/item/assembly/health/interact(mob/user)//TODO: Change this to the wires thingy
|
||||
if(!secured)
|
||||
user.show_message("<span class='warning'>[src] is unsecured!</span>")
|
||||
return FALSE
|
||||
var/dat = text("<TT><B>Health Sensor</B> <A href='?src=[UID()];scanning=1'>[scanning?"On":"Off"]</A>")
|
||||
if(scanning && health_scan)
|
||||
dat += "<BR>Health: [health_scan]"
|
||||
var/datum/browser/popup = new(user, "hscan", name, 400, 400)
|
||||
popup.set_content(dat)
|
||||
popup.open(0)
|
||||
onclose(user, "hscan")
|
||||
return
|
||||
/obj/item/assembly/health/attack_self(mob/user)
|
||||
ui_interact(user)
|
||||
|
||||
/obj/item/assembly/health/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.deep_inventory_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "HealthSensor", name, 300, 140, master_ui, state)
|
||||
ui.open()
|
||||
|
||||
/obj/item/assembly/health/Topic(href, href_list)
|
||||
..()
|
||||
if(!ismob(usr))
|
||||
/obj/item/assembly/health/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["on"] = scanning
|
||||
data["alarm_health"] = alarm_health
|
||||
data["user_health"] = user_health
|
||||
data["maxHealth"] = MAX_HEALTH_ACTIVATE
|
||||
data["minHealth"] = MIN_HEALTH_ACTIVATE
|
||||
return data
|
||||
|
||||
/obj/item/assembly/health/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
|
||||
if(..())
|
||||
return
|
||||
|
||||
var/mob/user = usr
|
||||
. = TRUE
|
||||
|
||||
if(HAS_TRAIT(usr, TRAIT_HANDS_BLOCKED) || usr.stat || usr.restrained() || !in_range(loc, usr))
|
||||
usr << browse(null, "window=hscan")
|
||||
onclose(usr, "hscan")
|
||||
return
|
||||
switch(action)
|
||||
if("scan_toggle")
|
||||
toggle_scan()
|
||||
|
||||
if(href_list["scanning"])
|
||||
toggle_scan()
|
||||
if("alarm_health")
|
||||
alarm_health = clamp(text2num(params["alarm_health"]), MIN_HEALTH_ACTIVATE, MAX_HEALTH_ACTIVATE)
|
||||
|
||||
if(href_list["close"])
|
||||
usr << browse(null, "window=hscan")
|
||||
return
|
||||
|
||||
attack_self(user)
|
||||
return
|
||||
#undef MAX_HEALTH_ACTIVATE
|
||||
#undef MIN_HEALTH_ACTIVATE
|
||||
|
||||
Reference in New Issue
Block a user