/
surgery_step.dm
234 lines (199 loc) · 9.72 KB
/
surgery_step.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
/datum/surgery_step
var/name
/// What tools can be used in this surgery, format is path = probability of success.
var/list/implements = list()
/// The current type of implement used. This has to be stored, as the actual typepath of the tool may not match the list type.
var/implement_type = null
/// Does the surgery step require an open hand? If true, ignores implements. Compatible with accept_any_item.
var/accept_hand = FALSE
/// Does the surgery step accept any item? If true, ignores implements. Compatible with require_hand.
var/accept_any_item = FALSE
/// How long does the step take?
var/time = 1 SECONDS
/// Can this step be repeated? Make sure it isn't last step, or it used in surgery with `can_cancel = 1`. Or surgion will be stuck in the loop
var/repeatable = FALSE
/// List of chems needed to complete the step. Even on success, the step will have no effect if there aren't the chems required in the mob. Use *require_all_chems* to specify if its any on the list or all on the list
var/list/chems_needed = list()
/// If *chems_needed* requires all chems in the list or one chem in the list.
var/require_all_chems = TRUE
var/silicons_obey_prob = FALSE
/// Sound played when the step is started
var/preop_sound
/// Sound played if the step succeeded
var/success_sound
/// Sound played if the step fails
var/failure_sound
/// The amount of experience given for successfully completing the step.
var/experience_given = MEDICAL_SKILL_EASY
/datum/surgery_step/proc/try_op(mob/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery, try_to_fail = FALSE)
var/success = FALSE
if(accept_hand)
if(!tool)
success = TRUE
if(iscyborg(user))
success = TRUE
if(accept_any_item)
if(tool && tool_check(user, tool))
success = TRUE
else if(tool)
for(var/key in implements)
var/match = FALSE
if(ispath(key) && istype(tool, key))
match = TRUE
else if(tool.tool_behaviour == key)
match = TRUE
if(match)
implement_type = key
if(tool_check(user, tool))
success = TRUE
break
if(success)
if(target_zone == surgery.location)
if(get_location_accessible(target, target_zone) || surgery.ignore_clothes)
initiate(user, target, target_zone, tool, surgery, try_to_fail)
else
to_chat(user, "<span class='warning'>You need to expose [target]'s [parse_zone(target_zone)] to perform surgery on it!</span>")
return TRUE //returns TRUE so we don't stab the guy in the dick or wherever.
if(repeatable)
var/datum/surgery_step/next_step = surgery.get_surgery_next_step()
if(next_step)
surgery.status++
if(next_step.try_op(user, target, user.zone_selected, user.get_active_held_item(), surgery))
return TRUE
else
surgery.status--
return FALSE
#define SURGERY_SLOWDOWN_CAP_MULTIPLIER 2 //increase to make surgery slower but fail less, and decrease to make surgery faster but fail more
/datum/surgery_step/proc/initiate(mob/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery, try_to_fail = FALSE)
surgery.step_in_progress = TRUE
var/speed_mod = 1
var/fail_prob = 0//100 - fail_prob = success_prob
var/advance = FALSE
if(preop(user, target, target_zone, tool, surgery) == -1)
surgery.step_in_progress = FALSE
return FALSE
play_preop_sound(user, target, target_zone, tool, surgery)
if(tool)
speed_mod = tool.toolspeed
var/implement_speed_mod = 1
if(implement_type) //this means it isn't a require hand or any item step.
implement_speed_mod = implements[implement_type] / 100.0
speed_mod /= (get_location_modifier(target) * (1 + surgery.speed_modifier) * implement_speed_mod)
var/modded_time = time * speed_mod * user.mind.get_skill_modifier(/datum/skill/healing, SKILL_SPEED_MODIFIER)
fail_prob = min(max(0, modded_time - (time * SURGERY_SLOWDOWN_CAP_MULTIPLIER)),99)//if modded_time > time * modifier, then fail_prob = modded_time - time*modifier. starts at 0, caps at 99
modded_time = min(modded_time, time * SURGERY_SLOWDOWN_CAP_MULTIPLIER)//also if that, then cap modded_time at time*modifier
if(iscyborg(user))//any immunities to surgery slowdown should go in this check.
modded_time = time
var/was_sleeping = (target.stat != DEAD && target.IsSleeping())
if(do_after(user, modded_time, target = target))
var/chem_check_result = chem_check(target)
if((prob(100-fail_prob) || (iscyborg(user) && !silicons_obey_prob)) && chem_check_result && !try_to_fail)
if(success(user, target, target_zone, tool, surgery))
play_success_sound(user, target, target_zone, tool, surgery)
advance = TRUE
else
if(failure(user, target, target_zone, tool, surgery, fail_prob))
play_failure_sound(user, target, target_zone, tool, surgery)
advance = TRUE
if(chem_check_result)
return .(user, target, target_zone, tool, surgery, try_to_fail) //automatically re-attempt if failed for reason other than lack of required chemical
if(advance && !repeatable)
surgery.status++
if(surgery.status > surgery.steps.len)
surgery.complete()
if(target.stat == DEAD && was_sleeping && user.client)
user.client.give_award(/datum/award/achievement/misc/sandman, user)
surgery.step_in_progress = FALSE
return advance
/datum/surgery_step/proc/preop(mob/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery)
display_results(user, target, "<span class='notice'>You begin to perform surgery on [target]...</span>",
"<span class='notice'>[user] begins to perform surgery on [target].</span>",
"<span class='notice'>[user] begins to perform surgery on [target].</span>")
/datum/surgery_step/proc/play_preop_sound(mob/user, mob/living/carbon/target, target_zone, obj/item/tool, datum/surgery/surgery)
if(!preop_sound)
return
var/sound_file_use
if(islist(preop_sound))
for(var/typepath in preop_sound)//iterate and assign subtype to a list, works best if list is arranged from subtype first and parent last
if(istype(tool, typepath))
sound_file_use = preop_sound[typepath]
break
else
sound_file_use = preop_sound
playsound(get_turf(target), sound_file_use, 75, TRUE, falloff_exponent = 12, falloff_distance = 1)
/datum/surgery_step/proc/success(mob/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery, default_display_results = TRUE)
if(default_display_results)
display_results(user, target, "<span class='notice'>You succeed.</span>",
"<span class='notice'>[user] succeeds!</span>",
"<span class='notice'>[user] finishes.</span>")
user?.mind.adjust_experience(/datum/skill/healing, round(experience_given))
return TRUE
/datum/surgery_step/proc/play_success_sound(mob/user, mob/living/carbon/target, target_zone, obj/item/tool, datum/surgery/surgery)
if(!success_sound)
return
var/sound_file_use
if(islist(success_sound))
for(var/typepath in success_sound) //iterate and assign subtype to a list, works best if list is arranged from subtype first and parent last
if(istype(tool, typepath))
sound_file_use = success_sound [typepath]
break
else
sound_file_use = success_sound
playsound(get_turf(target), sound_file_use, 75, TRUE, falloff_exponent = 12, falloff_distance = 1)
/datum/surgery_step/proc/failure(mob/user, mob/living/target, target_zone, obj/item/tool, datum/surgery/surgery, fail_prob = 0)
var/screwedmessage = ""
switch(fail_prob)
if(0 to 24)
screwedmessage = " You almost had it, though."
if(50 to 74)//25 to 49 = no extra text
screwedmessage = " This is hard to get right in these conditions..."
if(75 to 99)
screwedmessage = " This is practically impossible in these conditions..."
display_results(user, target, "<span class='warning'>You screw up![screwedmessage]</span>",
"<span class='warning'>[user] screws up!</span>",
"<span class='notice'>[user] finishes.</span>", TRUE) //By default the patient will notice if the wrong thing has been cut
return FALSE
/datum/surgery_step/proc/play_failure_sound(mob/user, mob/living/carbon/target, target_zone, obj/item/tool, datum/surgery/surgery)
if(!failure_sound)
return
var/sound_file_use
if(islist(failure_sound))
for(var/typepath in failure_sound)//iterate and assign subtype to a list, works best if list is arranged from subtype first and parent last
if(istype(tool, typepath))
sound_file_use = failure_sound[typepath]
break
else
sound_file_use = failure_sound
playsound(get_turf(target), sound_file_use, 75, TRUE, falloff_exponent = 12, falloff_distance = 1)
/datum/surgery_step/proc/tool_check(mob/user, obj/item/tool)
return TRUE
/datum/surgery_step/proc/chem_check(mob/living/target)
if(!LAZYLEN(chems_needed))
return TRUE
if(require_all_chems)
. = TRUE
for(var/R in chems_needed)
if(!target.reagents.has_reagent(R))
return FALSE
else
. = FALSE
for(var/R in chems_needed)
if(target.reagents.has_reagent(R))
return TRUE
/datum/surgery_step/proc/get_chem_list()
if(!LAZYLEN(chems_needed))
return
var/list/chems = list()
for(var/R in chems_needed)
var/datum/reagent/temp = GLOB.chemical_reagents_list[R]
if(temp)
var/chemname = temp.name
chems += chemname
return english_list(chems, and_text = require_all_chems ? " and " : " or ")
//Replaces visible_message during operations so only people looking over the surgeon can tell what they're doing, allowing for shenanigans.
/datum/surgery_step/proc/display_results(mob/user, mob/living/carbon/target, self_message, detailed_message, vague_message, target_detailed = FALSE)
var/list/detailed_mobs = get_hearers_in_view(1, user) //Only the surgeon and people looking over his shoulder can see the operation clearly
if(!target_detailed)
detailed_mobs -= target //The patient can't see well what's going on, unless it's something like getting cut
user.visible_message(detailed_message, self_message, vision_distance = 1, ignored_mobs = target_detailed ? null : target)
user.visible_message(vague_message, "", ignored_mobs = detailed_mobs)