-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathlight_eater.dm
175 lines (159 loc) · 6.43 KB
/
light_eater.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* Makes anything it attaches to capable of permanently removing something's ability to produce light.
*
* The temporary equivalent is [/datum/component/light_eater]
*/
/datum/element/light_eater
var/static/list/blacklisted_areas = typecacheof(list(
/turf/open/space,
/turf/open/lava,
))
/datum/element/light_eater/Attach(datum/target)
if(isatom(target))
if(ismovable(target))
if(ismachinery(target) || isstructure(target))
RegisterSignal(target, COMSIG_PROJECTILE_ON_HIT, PROC_REF(on_projectile_hit))
RegisterSignal(target, COMSIG_MOVABLE_IMPACT, PROC_REF(on_throw_impact))
if(isitem(target))
if(isgun(target))
RegisterSignal(target, COMSIG_PROJECTILE_ON_HIT, PROC_REF(on_projectile_hit))
RegisterSignal(target, COMSIG_ITEM_AFTERATTACK, PROC_REF(on_afterattack))
RegisterSignal(target, COMSIG_ITEM_POST_BLOCK, PROC_REF(on_block))
else if(isprojectile(target))
RegisterSignal(target, COMSIG_PROJECTILE_SELF_ON_HIT, PROC_REF(on_projectile_self_hit))
else if(isprojectilespell(target))
RegisterSignal(target, COMSIG_PROJECTILE_ON_HIT, PROC_REF(on_projectile_hit))
else
return ELEMENT_INCOMPATIBLE
return ..()
/datum/element/light_eater/Detach(datum/source)
UnregisterSignal(source, list(
COMSIG_MOVABLE_IMPACT,
COMSIG_ITEM_AFTERATTACK,
COMSIG_ITEM_POST_BLOCK,
COMSIG_PROJECTILE_ON_HIT,
))
return ..()
/**
* Makes the light eater consume all of the lights attached to the target atom.
*
* Arguments:
* - [food][/atom]: The atom to start the search for lights at.
* - [eater][/datum]: The light eater being used in this case.
*/
/datum/element/light_eater/proc/eat_lights(atom/food, datum/eater)
var/list/buffet = table_buffet(food)
if(!LAZYLEN(buffet))
return 0
. = 0
for(var/morsel in buffet)
. += devour(morsel, eater)
if(!.)
return
food.visible_message(
span_danger("Something dark in [eater] lashes out at [food] and [food.p_their()] light goes out in an instant!"),
span_userdanger("You feel something dark in [eater] lash out and gnaw through your light in an instant! It recedes just as fast, but you can feel that [eater.p_theyve()] left something hungry behind."),
span_danger("You feel a gnawing pulse eat at your sight.")
)
/**
* Aggregates a list of the light sources attached to the target atom.
*
* Arguments:
* - [comissary][/atom]: The origin node of all of the light sources to search through.
* - [devourer][/datum]: The light eater this element is attached to. Since the element is compatible with reagents this needs to be a datum.
*/
/datum/element/light_eater/proc/table_buffet(atom/commisary, datum/devourer)
. = list()
SEND_SIGNAL(commisary, COMSIG_LIGHT_EATER_QUEUE, ., devourer)
for(var/datum/light_source/morsel as anything in commisary.light_sources)
.[morsel.source_atom] = TRUE
/**
* Consumes the light on the target, permanently rendering it incapable of producing light
*
* Arguments:
* - [morsel][/atom]: The light-producing thing we are eating
* - [eater][/datum]: The light eater eating the morsel. This is the datum that the element is attached to that started this chain.
*/
/datum/element/light_eater/proc/devour(atom/morsel, datum/eater)
if(is_type_in_typecache(morsel, blacklisted_areas))
return FALSE
if(istransparentturf(morsel))
return FALSE
if(morsel.light_power <= 0 || morsel.light_range <= 0 || !morsel.light_on)
return FALSE
if(SEND_SIGNAL(morsel, COMSIG_LIGHT_EATER_ACT, eater) & COMPONENT_BLOCK_LIGHT_EATER)
return FALSE // Either the light eater can't eat it or it had special behaviors.
morsel.AddElement(/datum/element/light_eaten)
SEND_SIGNAL(src, COMSIG_LIGHT_EATER_DEVOUR, morsel)
return TRUE
/////////////////////
// SIGNAL HANDLERS //
/////////////////////
/**
* Called when a movable source is thrown and strikes a target
*
* Arugments:
* - [source][/atom/movable]: The movable atom that was thrown
* - [hit_atom][/atom]: The target atom that was struck by the source in flight
* - [thrownthing][/datum/thrownthing]: A datum containing the information for the throw
*/
/datum/element/light_eater/proc/on_throw_impact(atom/movable/source, atom/hit_atom, datum/thrownthing/thrownthing)
SIGNAL_HANDLER
eat_lights(hit_atom, source)
return NONE
/**
* Called when a target is attacked with a source item
*
* Arguments:
* - [source][/obj/item]: The item what was used to strike the target
* - [target][/atom]: The atom being struck by the user with the source
* - [user][/mob/living]: The mob using the source to strike the target
* - proximity: Whether the strike was in melee range so you can't eat lights from cameras
*/
/datum/element/light_eater/proc/on_afterattack(obj/item/source, atom/target, mob/living/user, proximity)
SIGNAL_HANDLER
if(!proximity)
return NONE
eat_lights(target, source)
return COMPONENT_AFTERATTACK_PROCESSED_ITEM
/**
* Called when a source object is used to block a thrown object, projectile, or attack
*
* Arguments:
* - [source][/obj/item]: The item what was used to block the target
* - [defender][/mob/living/carbon/human]: The mob that blocked the target with the source
* - [incoming][/atom/movable]: The movable that was blocked by the owner with the source
* - damage: The damage of the incoming attack
* - attack_type: The type of attack that was blocked
*/
/datum/element/light_eater/proc/on_block(obj/item/source, mob/living/defender, atom/movable/incoming, damage, attack_type)
SIGNAL_HANDLER
eat_lights(incoming, source)
return NONE
/**
* Called when a produced projectile strikes a target atom
*
* Arguments:
* - [source][/datum]: The thing that created the projectile
* - [firer][/atom/movable]: The movable atom that fired the projectile
* - [target][/atom]: The atom that was struck by the projectile
* - angle: The angle the target was struck at
*/
/datum/element/light_eater/proc/on_projectile_hit(datum/source, atom/movable/firer, atom/target, angle)
SIGNAL_HANDLER
eat_lights(target, source)
return NONE
/**
* Called when a source projectile strikes a target atom
*
* Arguments:
* - [source][/obj/projectile]: The projectile striking the target atom
* - [firer][/atom/movable]: The movable atom that fired the projectile
* - [target][/atom]: The atom that was struck by the projectile
* - angle: The angle the target was struck at
* - hit_limb: The limb that was hit, if the target was a carbon
*/
/datum/element/light_eater/proc/on_projectile_self_hit(obj/projectile/source, atom/movable/firer, atom/target, angle, hit_limb)
SIGNAL_HANDLER
eat_lights(target, source)
return NONE