-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathflasher.dm
217 lines (183 loc) · 6.07 KB
/
flasher.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// It is a gizmo that flashes a small area
/obj/machinery/flasher
name = "mounted flash"
desc = "A wall-mounted flashbulb device."
icon = 'icons/obj/stationobjs.dmi'
icon_state = "mflash1"
max_integrity = 250
integrity_failure = 100
var/obj/item/assembly/flash/handheld/bulb
var/id = null
/// How far this flash reaches. Affects both proximity distance and the actual stun effect.
var/flash_range = 2 //this is roughly the size of a brig cell.
var/last_flash = 0 //Don't want it getting spammed like regular flashes
/// How strong Paralyze()'d targets are when flashed.
var/strength = 10 SECONDS
var/base_state = "mflash"
/obj/machinery/flasher/portable //Portable version of the flasher. Only flashes when anchored
name = "portable flasher"
desc = "A portable flashing device. Wrench to activate and deactivate. Cannot detect slow movements."
icon_state = "pflash1-p"
strength = 80
anchored = FALSE
base_state = "pflash"
density = TRUE
/obj/machinery/flasher/Initialize(mapload, ndir = 0, built = 0)
. = ..() // ..() is EXTREMELY IMPORTANT, never forget to add it
if(built)
setDir(ndir)
pixel_x = (dir & 3)? 0 : (dir == 4 ? -28 : 28)
pixel_y = (dir & 3)? (dir ==1 ? -28 : 28) : 0
else
bulb = new(src)
/obj/machinery/flasher/connect_to_shuttle(mapload, obj/docking_port/mobile/port, obj/docking_port/stationary/dock)
id = "[port.shuttle_id]_[id]"
/obj/machinery/flasher/Destroy()
QDEL_NULL(bulb)
return ..()
/obj/machinery/flasher/powered()
if(!anchored || !bulb)
return FALSE
return ..()
/obj/machinery/flasher/update_icon_state()
. = ..()
if(!powered())
icon_state = "[base_state]1-p"
return
if(bulb.burnt_out)
icon_state = "[base_state]1-p"
else
icon_state = "[base_state]1"
//Don't want to render prison breaks impossible
/obj/machinery/flasher/attackby(obj/item/W, mob/user, params)
add_fingerprint(user)
if (W.tool_behaviour == TOOL_WIRECUTTER)
if (bulb)
user.visible_message("[user] begins to disconnect [src]'s flashbulb.", span_notice("You begin to disconnect [src]'s flashbulb..."))
if(W.use_tool(src, user, 30, volume=50) && bulb)
user.visible_message("[user] has disconnected [src]'s flashbulb!", span_notice("You disconnect [src]'s flashbulb."))
bulb.forceMove(loc)
bulb = null
power_change()
else if (istype(W, /obj/item/assembly/flash/handheld))
if (!bulb)
if(!user.transferItemToLoc(W, src))
return
user.visible_message("[user] installs [W] into [src].", span_notice("You install [W] into [src]."))
bulb = W
power_change()
else
to_chat(user, span_warning("A flashbulb is already installed in [src]!"))
else if (W.tool_behaviour == TOOL_WRENCH)
if(!bulb)
to_chat(user, span_notice("You start unsecuring the flasher frame..."))
if(W.use_tool(src, user, 40, volume=50))
to_chat(user, span_notice("You unsecure the flasher frame."))
deconstruct(TRUE)
else
to_chat(user, span_warning("Remove a flashbulb from [src] first!"))
else
return ..()
//Let the AI trigger them directly.
/obj/machinery/flasher/attack_ai()
if (anchored)
return flash()
/obj/machinery/flasher/run_atom_armor(damage_amount, damage_type, damage_flag = 0, attack_dir)
if(damage_flag == MELEE && damage_amount < 10) //any melee attack below 10 dmg does nothing
return 0
. = ..()
/obj/machinery/flasher/proc/flash()
if (!powered() || !bulb)
return
if (bulb.burnt_out || (last_flash && world.time < src.last_flash + 150))
return
if(!bulb.flash_recharge(30)) //Bulb can burn out if it's used too often too fast
power_change()
return
playsound(src.loc, 'sound/weapons/flash.ogg', 100, 1)
flick("[base_state]_flash", src)
set_light_on(TRUE)
addtimer(CALLBACK(src, PROC_REF(flash_end)), FLASH_LIGHT_DURATION, TIMER_OVERRIDE|TIMER_UNIQUE)
last_flash = world.time
use_power(1000)
var/flashed = FALSE
for (var/mob/living/L in viewers(src, null))
if (get_dist(src, L) > flash_range)
continue
if(L.flash_act(affect_silicon = 1))
if(iscarbon(L))
bulb.flash_carbon(L, src, strength / 10, TRUE)
else if(iscyborg(L) && bulb.borgstun)
bulb.flash_borg(L, src)
flashed = TRUE
if(flashed)
bulb.times_used++
return 1
/obj/machinery/flasher/proc/flash_end()
set_light_on(FALSE)
/obj/machinery/flasher/emp_act(severity)
. = ..()
if(!(stat & (BROKEN|NOPOWER)) && !(. & EMP_PROTECT_SELF))
if(bulb && prob(8 * severity))
flash()
bulb.burn_out()
power_change()
/obj/machinery/flasher/atom_break(damage_flag)
. = ..()
if(. && bulb)
bulb.burn_out()
power_change()
/obj/machinery/flasher/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
if(bulb)
bulb.forceMove(loc)
bulb = null
if(disassembled)
var/obj/item/wallframe/flasher/F = new(get_turf(src))
transfer_fingerprints_to(F)
F.id = id
playsound(loc, 'sound/items/deconstruct.ogg', 50, 1)
else
new /obj/item/stack/sheet/metal (loc, 2)
qdel(src)
/obj/machinery/flasher/portable/Initialize(mapload)
. = ..()
proximity_monitor = new(src, 0)
/obj/machinery/flasher/portable/HasProximity(atom/movable/AM)
if (last_flash && world.time < last_flash + 150)
return
if(istype(AM, /mob/living/carbon))
var/mob/living/carbon/M = AM
if (M.m_intent != MOVE_INTENT_WALK && anchored)
flash()
/obj/machinery/flasher/portable/attackby(obj/item/W, mob/user, params)
if (W.tool_behaviour == TOOL_WRENCH)
W.play_tool_sound(src, 100)
if (!anchored && !isinspace())
to_chat(user, span_notice("[src] is now secured."))
add_overlay("[base_state]-s")
setAnchored(TRUE)
power_change()
proximity_monitor.SetRange(flash_range)
else
to_chat(user, span_notice("[src] can now be moved."))
cut_overlays()
setAnchored(FALSE)
power_change()
proximity_monitor.SetRange(0)
else
return ..()
/obj/item/wallframe/flasher
name = "mounted flash frame"
desc = "Used for building wall-mounted flashers."
icon = 'icons/obj/stationobjs.dmi'
icon_state = "mflash_frame"
result_path = /obj/machinery/flasher
var/id = null
/obj/item/wallframe/flasher/examine(mob/user)
. = ..()
. += span_notice("Its channel ID is '[id]'.")
/obj/item/wallframe/flasher/after_attach(obj/O)
..()
var/obj/machinery/flasher/F = O
F.id = id