/
screwy_health_doll.dm
80 lines (61 loc) · 3.26 KB
/
screwy_health_doll.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
///Causes the target to see incorrect health damages on the healthdoll
/datum/hallucination/fake_health_doll
random_hallucination_weight = 12
/// The duration of the hallucination
var/duration
/// Assoc list of [ref to bodyparts] to [severity]
var/list/bodyparts = list()
/// Timer ID for when we're deleted
var/del_timer_id
/datum/hallucination/fake_health_doll/New(mob/living/hallucinator, duration = 50 SECONDS)
src.duration = duration
return ..()
// So that the associated addition proc cleans it up correctly
/datum/hallucination/fake_health_doll/Destroy()
if(del_timer_id)
deltimer(del_timer_id)
for(var/obj/item/bodypart/limb as anything in bodyparts)
remove_bodypart(limb)
hallucinator.update_health_hud()
return ..()
/datum/hallucination/fake_health_doll/start()
if(!ishuman(hallucinator))
return FALSE
add_fake_limb()
del_timer_id = QDEL_IN(src, duration)
return TRUE
/// Increments the severity of the damage seen on all the limbs we are already tracking.
/datum/hallucination/fake_health_doll/proc/increment_fake_damage()
for(var/obj/item/bodypart/limb as anything in bodyparts)
bodyparts[limb] = clamp(bodyparts[limb] + 1, 1, 5)
hallucinator.update_health_hud()
/**
* Adds a fake limb to the effect.
*
* specific_limb - optional, the specific limb to apply the effect to. If not passed, picks a random limb
* seveirty - optional, the specific severity level to apply the effect. Clamped from 1 to 5. If not passed, picks a random number.
*/
/datum/hallucination/fake_health_doll/proc/add_fake_limb(obj/item/bodypart/specific_limb, severity)
var/mob/living/carbon/human/human_mob = hallucinator
var/obj/item/bodypart/picked = specific_limb || pick(human_mob.bodyparts)
if(!(picked in bodyparts))
RegisterSignal(picked, list(COMSIG_PARENT_QDELETING, COMSIG_BODYPART_REMOVED), .proc/remove_bodypart)
RegisterSignal(picked, COMSIG_BODYPART_UPDATING_HEALTH_HUD, .proc/on_bodypart_hud_update)
RegisterSignal(picked, COMSIG_BODYPART_CHECKED_FOR_INJURY, .proc/on_bodypart_checked)
bodyparts[picked] = clamp(severity || rand(1, 5), 1, 5)
hallucinator.update_health_hud()
/// Remove a bodypart from our list, unregistering all associated signals and handling the reference
/datum/hallucination/fake_health_doll/proc/remove_bodypart(obj/item/bodypart/source)
SIGNAL_HANDLER
UnregisterSignal(source, list(COMSIG_PARENT_QDELETING, COMSIG_BODYPART_REMOVED, COMSIG_BODYPART_UPDATING_HEALTH_HUD, COMSIG_BODYPART_CHECKED_FOR_INJURY))
bodyparts -= source
/// Whenever a bodypart we're tracking has their health hud updated, override it with our fake overlay
/datum/hallucination/fake_health_doll/proc/on_bodypart_hud_update(obj/item/bodypart/source, mob/living/carbon/human/owner)
SIGNAL_HANDLER
var/mutable_appearance/fake_overlay = mutable_appearance('icons/hud/screen_gen.dmi', "[source.body_zone][bodyparts[source]]")
owner.hud_used.healthdoll.add_overlay(fake_overlay)
return COMPONENT_OVERRIDE_BODYPART_HEALTH_HUD
/// Signal proc for [COMSIG_BODYPART_CHECKED_FOR_INJURY]. Our bodyparts look a lot more wounded than they actually are.
/datum/hallucination/fake_health_doll/proc/on_bodypart_checked(obj/item/bodypart/source, mob/living/carbon/examiner, list/check_list, list/limb_damage)
SIGNAL_HANDLER
limb_damage[BRUTE] = bodyparts[source] * 0.2 * source.max_damage