/
iv_drip.dm
338 lines (297 loc) · 9.45 KB
/
iv_drip.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/obj/structure/iv_stand
name = "\improper IV drip"
icon = 'icons/obj/structures/iv_drip.dmi'
icon_state = "unhooked"
anchored = FALSE
density = FALSE
/// The IV stand is configured to remove reagents from the attached mob.
var/const/MODE_EXTRACT = 0
/// The IV stand is configured to add reagents to the attached mob.
var/const/MODE_INJECT = 1
/// One of the IV stand's MODE_* constants.
var/drip_mode = MODE_INJECT
/// The mob currently attached to this IV stand, if any.
var/mob/living/carbon/human/patient
/// The IV bag currently attached to this IV stand, if any.
var/obj/item/reagent_containers/ivbag/iv_bag
/// The color of the last reagent mix placed on the IV stand.
var/last_reagent_color = "#ffffff"
/obj/structure/iv_stand/Destroy()
patient = null
QDEL_NULL(iv_bag)
return ..()
/obj/structure/iv_stand/Initialize()
. = ..()
update_icon()
/obj/structure/iv_stand/on_update_icon()
if (!patient)
icon_state = "unhooked"
else
icon_state = "hooked"
ClearOverlays()
if (!iv_bag)
return
var/image/reagents_overlay = image(icon, icon_state = "reagent0")
reagents_overlay.color = last_reagent_color
var/image/light_overlay = image(icon, icon_state = "light_low")
light_overlay.plane = EFFECTS_ABOVE_LIGHTING_PLANE
light_overlay.layer = ABOVE_LIGHTING_LAYER
switch (Percent(iv_bag.reagents.total_volume, iv_bag.volume, 0))
if (-INFINITY to 9)
reagents_overlay.icon_state = "reagent0"
light_overlay.icon_state = "light_low"
if (10 to 24)
reagents_overlay.icon_state = "reagent10"
light_overlay.icon_state = "light_low"
if (25 to 49)
reagents_overlay.icon_state = "reagent25"
light_overlay.icon_state = "light_mid"
if (50 to 74)
reagents_overlay.icon_state = "reagent50"
light_overlay.icon_state = "light_mid"
if (75 to 79)
reagents_overlay.icon_state = "reagent75"
light_overlay.icon_state = "light_full"
if (80 to 90)
reagents_overlay.icon_state = "reagent80"
light_overlay.icon_state = "light_full"
if (91 to INFINITY)
reagents_overlay.icon_state = "reagent100"
light_overlay.icon_state = "light_full"
AddOverlays(reagents_overlay)
AddOverlays(light_overlay)
/obj/structure/iv_stand/MouseDrop(atom/over_atom, source_loc, over_loc)
if (!usr)
return
if (!over_atom)
return
if (!Adjacent(usr) || !over_atom.Adjacent(usr))
return
if (isliving(over_atom))
MouseDrop_T(over_atom, usr)
else
over_atom.MouseDrop_T(src, usr)
/obj/structure/iv_stand/MouseDrop_T(atom/dropped, mob/living/user)
if (src == dropped && user.canClick())
user.ClickOn(src)
return
if (!CheckDexterity(user))
to_chat(user, SPAN_WARNING("You're not dextrous enough to do that."))
return
if (user.incapacitated())
to_chat(user, SPAN_WARNING("You're in no condition to do that."))
return
if (patient == dropped)
RemoveDrip(user)
else if (ishuman(dropped))
AttachDrip(dropped, user)
/obj/structure/iv_stand/use_tool(obj/item/tool, mob/user, list/click_params)
// IV Bag - Attach
if (istype(tool, /obj/item/reagent_containers/ivbag))
if (iv_bag)
USE_FEEDBACK_FAILURE("\The [src] already has \a [iv_bag] attached.")
return TRUE
if (!user.unEquip(tool, src))
FEEDBACK_UNEQUIP_FAILURE(user, tool)
return TRUE
user.visible_message(
SPAN_NOTICE("\The [user] attaches \a [tool] to \a [src]."),
SPAN_NOTICE("You attach \the [tool] to \the [src]."),
range = 5
)
iv_bag = tool
last_reagent_color = iv_bag.reagents.get_color()
update_icon()
return TRUE
return ..()
/obj/structure/iv_stand/Process()
if (!patient)
return PROCESS_KILL
if (!Adjacent(patient))
RipDrip()
return PROCESS_KILL
if (!iv_bag)
return
if (SSobj.times_fired & 1)
return
if (!iv_bag.transfer_amount)
return
if (drip_mode == MODE_INJECT)
if (!iv_bag.reagents.total_volume)
if (prob(15))
playsound(src, 'sound/effects/3beep.ogg', 50, TRUE)
audible_message(
SPAN_NOTICE("\The [src] pings."),
hearing_distance = 5
)
return
iv_bag.reagents.trans_to_mob(patient, iv_bag.transfer_amount, CHEM_BLOOD)
update_icon()
return
if (drip_mode == MODE_EXTRACT)
var/difference = clamp(iv_bag.volume - iv_bag.reagents.total_volume, 0, iv_bag.transfer_amount)
if (!difference)
if (prob(15))
playsound(src, 'sound/effects/3beep.ogg', 50, TRUE)
audible_message(
SPAN_NOTICE("\The [src] pings."),
hearing_distance = 5
)
return
if (!patient.should_have_organ(BP_HEART))
return
if (patient.get_blood_volume() < BLOOD_VOLUME_SAFE)
if (prob(30))
playsound(src, 'sound/effects/3beep.ogg', 50, TRUE)
audible_message(
SPAN_NOTICE("\The [src] pings."),
hearing_distance = 5
)
if (patient.take_blood(iv_bag, difference))
update_icon()
return
/obj/structure/iv_stand/attack_hand(mob/living/user)
if (iv_bag)
iv_bag.dropInto(loc)
iv_bag = null
update_icon()
return
if (patient)
RemoveDrip(user)
return
return ..()
/obj/structure/iv_stand/attack_robot(mob/living/silicon/user)
if (!Adjacent(user))
return
attack_hand(user)
/obj/structure/iv_stand/examine(mob/user, distance)
. = ..()
if (distance >= 2 && !isghost(user))
return
if (patient)
to_chat(user, "\The [patient] is hooked up to it.")
if (!iv_bag)
to_chat(user, "It has no IV bag attached.")
return
var/volume = floor(iv_bag.reagents.total_volume)
if (!volume)
to_chat(user, "It has an empty [iv_bag] attached.")
return
to_chat(user, "It has \a [iv_bag] attached with [volume] units of liquid inside.")
to_chat(user, {"\
It is set to [drip_mode == MODE_INJECT ? "inject" : drip_mode == MODE_EXTRACT ? "extract" : ""] \
[iv_bag.transfer_amount]u of fluid per cycle.\
"})
/obj/structure/iv_stand/CheckDexterity(mob/living/user)
return ishuman(user) || isrobot(user)
/obj/structure/iv_stand/proc/AttachDrip(mob/living/carbon/human/target, mob/living/user)
if (patient)
to_chat(user, SPAN_WARNING("\The [patient] is already hooked up to \the [src]."))
return
user.visible_message(
SPAN_ITALIC("\The [user] starts to hook up \the [target] to \the [src]."),
SPAN_ITALIC("You start to hook up \the [target] to \the [src]."),
range = 5
)
if (!user.do_skilled(3 SECONDS, SKILL_MEDICAL, target))
return
if (prob(user.skill_fail_chance(SKILL_MEDICAL, 67, SKILL_BASIC)))
user.visible_message(
SPAN_DANGER("\The [user] fishes for a vein on \the [target] and fails, stabbing them instead!"),
SPAN_DANGER("You fish inexpertly for a vein on \the [target] and stab them instead!"),
range = 5
)
target.apply_damage(rand(2, 6), DAMAGE_BRUTE, pick(BP_R_ARM, BP_L_ARM), damage_flags = DAMAGE_FLAG_SHARP, armor_pen = 100)
return
START_PROCESSING(SSobj, src)
user.visible_message(
SPAN_ITALIC("\The [user] successfully inserts \a [src]'s cannula into \the [target]."),
SPAN_NOTICE("You successfully insert \the [src]'s cannula into \the [target]."),
range = 1
)
patient = target
update_icon()
/obj/structure/iv_stand/proc/RemoveDrip(mob/living/user)
if (!patient)
return
user.visible_message(
SPAN_ITALIC("\The [user] starts unhooking \the [patient] from \a [src]."),
SPAN_ITALIC("You start extracting \the [src]'s cannula from \the [patient]."),
range = 5
)
if (!user.do_skilled(1.5 SECONDS, SKILL_MEDICAL, patient))
return
if (!user.skill_check(SKILL_MEDICAL, SKILL_BASIC))
RipDrip(user)
return
STOP_PROCESSING(SSobj, src)
user.visible_message(
SPAN_WARNING("\The [user] extracts \the [src]'s cannula from \the [patient]."),
SPAN_NOTICE("You successfully unhook \the [patient] from \the [src]."),
range = 1
)
patient = null
update_icon()
/obj/structure/iv_stand/proc/RipDrip(mob/living/user)
if (!patient)
return
STOP_PROCESSING(SSobj, src)
patient.visible_message(
SPAN_WARNING("\The cannula from \a [src] is ripped out of \the [patient][user ? " by \the [user]" : ""]!"),
SPAN_DANGER("\The cannula from \the [src] is ripped out of you[user ? " by \the [user]": ""]!"),
range = 5
)
patient.custom_pain(power = 20)
patient.apply_damage(rand(1, 3), DAMAGE_BRUTE, pick(BP_R_ARM, BP_L_ARM), damage_flags = DAMAGE_FLAG_SHARP, armor_pen = 100)
patient = null
update_icon()
/obj/structure/iv_stand/verb/TransferAmountVerb()
set name = "Set IV Bag Rate"
set category = "Object"
set src in range(1)
var/mob/living/user = usr
if (!istype(user))
return
if (!Adjacent(user) || user.incapacitated())
to_chat(user, SPAN_WARNING("You're in no condition to do that."))
return
if (!iv_bag)
to_chat(user, SPAN_WARNING("\The [src] does not have an attached IV bag."))
return
iv_bag.UpdateTransferAmount(user, src)
/obj/structure/iv_stand/verb/RemoveDripVerb()
set category = "Object"
set name = "Detach Stand IV Drip"
set src in range(1)
var/mob/living/user = usr
if (!istype(user))
return
if (!patient)
to_chat(user, SPAN_WARNING("\The [src] is not hooked up to anyone."))
return
if (!Adjacent(user) || user.incapacitated())
to_chat(user, SPAN_WARNING("You're in no condition do that."))
RemoveDrip(user)
/obj/structure/iv_stand/verb/ToggleModeVerb()
set category = "Object"
set name = "Toggle Stand IV Mode"
set src in view(1)
var/mob/living/user = usr
if (!istype(user))
return
if (!Adjacent(user) || user.incapacitated())
to_chat(user, SPAN_WARNING("You're in no condition to do that."))
return
var/action_word
switch (drip_mode)
if (MODE_EXTRACT)
action_word = "inject"
drip_mode = MODE_INJECT
else
action_word = "extract"
drip_mode = MODE_EXTRACT
user.visible_message(
SPAN_ITALIC("\The [user] adjusts \a [src] to [action_word] fluids."),
SPAN_ITALIC("You adjust \the [src] to [action_word] fluids."),
range = 3
)