/
damage_procs.dm
349 lines (299 loc) · 11.9 KB
/
damage_procs.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
339
340
341
342
343
344
345
346
347
348
349
/mob/living/carbon/apply_damage(
damage = 0,
damagetype = BRUTE,
def_zone = null,
blocked = 0,
forced = FALSE,
spread_damage = FALSE,
wound_bonus = 0,
bare_wound_bonus = 0,
sharpness = NONE,
attack_direction = null,
attacking_item,
)
// Spread damage should always have def zone be null
if(spread_damage)
def_zone = null
// Otherwise if def zone is null, we'll get a random bodypart / zone to hit.
// ALso we'll automatically covnert string def zones into bodyparts to pass into parent call.
else if(!isbodypart(def_zone))
var/random_zone = check_zone(def_zone || get_random_valid_zone(def_zone))
def_zone = get_bodypart(random_zone) || bodyparts[1]
. = ..()
// Taking brute or burn to bodyparts gives a damage flash
if(def_zone && (damagetype == BRUTE || damagetype == BURN))
damageoverlaytemp += .
return .
/mob/living/carbon/human/get_damage_mod(damage_type)
if (!dna?.species?.damage_modifier)
return ..()
var/species_mod = (100 - dna.species.damage_modifier) / 100
return ..() * species_mod
/mob/living/carbon/human/apply_damage(
damage = 0,
damagetype = BRUTE,
def_zone = null,
blocked = 0,
forced = FALSE,
spread_damage = FALSE,
wound_bonus = 0,
bare_wound_bonus = 0,
sharpness = NONE,
attack_direction = null,
attacking_item,
)
// Add relevant DR modifiers into blocked value to pass to parent
blocked += physiology?.damage_resistance
blocked += dna?.species?.damage_modifier
return ..()
/mob/living/carbon/human/get_incoming_damage_modifier(
damage = 0,
damagetype = BRUTE,
def_zone = null,
sharpness = NONE,
attack_direction = null,
attacking_item,
)
var/final_mod = ..()
switch(damagetype)
if(BRUTE)
final_mod *= physiology.brute_mod
if(BURN)
final_mod *= physiology.burn_mod
if(TOX)
final_mod *= physiology.tox_mod
if(OXY)
final_mod *= physiology.oxy_mod
if(STAMINA)
final_mod *= physiology.stamina_mod
if(BRAIN)
final_mod *= physiology.brain_mod
return final_mod
//These procs fetch a cumulative total damage from all bodyparts
/mob/living/carbon/getBruteLoss()
var/amount = 0
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
amount += BP.brute_dam
return amount
/mob/living/carbon/getFireLoss()
var/amount = 0
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
amount += BP.burn_dam
return amount
/mob/living/carbon/adjustBruteLoss(amount, updating_health = TRUE, forced = FALSE, required_bodytype)
if(!can_adjust_brute_loss(amount, forced, required_bodytype))
return 0
if(amount > 0)
. = take_overall_damage(brute = amount, updating_health = updating_health, forced = forced, required_bodytype = required_bodytype)
else
. = heal_overall_damage(brute = abs(amount), required_bodytype = required_bodytype, updating_health = updating_health, forced = forced)
/mob/living/carbon/setBruteLoss(amount, updating_health = TRUE, forced = FALSE, required_bodytype)
if(!forced && (status_flags & GODMODE))
return FALSE
var/current = getBruteLoss()
var/diff = amount - current
if(!diff)
return FALSE
return adjustBruteLoss(diff, updating_health, forced, required_bodytype)
/mob/living/carbon/adjustFireLoss(amount, updating_health = TRUE, forced = FALSE, required_bodytype)
if(!can_adjust_fire_loss(amount, forced, required_bodytype))
return 0
if(amount > 0)
. = take_overall_damage(burn = amount, updating_health = updating_health, forced = forced, required_bodytype = required_bodytype)
else
. = heal_overall_damage(burn = abs(amount), required_bodytype = required_bodytype, updating_health = updating_health, forced = forced)
/mob/living/carbon/setFireLoss(amount, updating_health = TRUE, forced = FALSE, required_bodytype)
if(!forced && (status_flags & GODMODE))
return FALSE
var/current = getFireLoss()
var/diff = amount - current
if(!diff)
return FALSE
return adjustFireLoss(diff, updating_health, forced, required_bodytype)
/mob/living/carbon/adjustToxLoss(amount, updating_health = TRUE, forced = FALSE, required_biotype = ALL)
if(!can_adjust_tox_loss(amount, forced, required_biotype))
return 0
if(!forced && HAS_TRAIT(src, TRAIT_TOXINLOVER)) //damage becomes healing and healing becomes damage
amount = -amount
if(HAS_TRAIT(src, TRAIT_TOXIMMUNE)) //Prevents toxin damage, but not healing
amount = min(amount, 0)
if(amount > 0)
blood_volume = max(blood_volume - (5*amount), 0)
else
blood_volume = max(blood_volume - amount, 0)
else if(!forced && HAS_TRAIT(src, TRAIT_TOXIMMUNE)) //Prevents toxin damage, but not healing
amount = min(amount, 0)
return ..()
/mob/living/carbon/adjustStaminaLoss(amount, updating_stamina, forced, required_biotype = ALL)
. = ..()
if(amount > 0)
stam_regen_start_time = world.time + STAMINA_REGEN_BLOCK_TIME
/**
* If an organ exists in the slot requested, and we are capable of taking damage (we don't have [GODMODE] on), call the damage proc on that organ.
*
* Arguments:
* * slot - organ slot, like [ORGAN_SLOT_HEART]
* * amount - damage to be done
* * maximum - currently an arbitrarily large number, can be set so as to limit damage
* * required_organ_flag - targets only a specific organ type if set to ORGAN_ORGANIC or ORGAN_ROBOTIC
*
* Returns: The net change in damage from apply_organ_damage()
*/
/mob/living/carbon/adjustOrganLoss(slot, amount, maximum, required_organ_flag = NONE)
var/obj/item/organ/affected_organ = get_organ_slot(slot)
if(!affected_organ || (status_flags & GODMODE))
return FALSE
if(required_organ_flag && !(affected_organ.organ_flags & required_organ_flag))
return FALSE
return affected_organ.apply_organ_damage(amount, maximum)
/**
* If an organ exists in the slot requested, and we are capable of taking damage (we don't have [GODMODE] on), call the set damage proc on that organ, which can
* set or clear the failing variable on that organ, making it either cease or start functions again, unlike adjustOrganLoss.
*
* Arguments:
* * slot - organ slot, like [ORGAN_SLOT_HEART]
* * amount - damage to be set to
* * required_organ_flag - targets only a specific organ type if set to ORGAN_ORGANIC or ORGAN_ROBOTIC
*
* Returns: The net change in damage from set_organ_damage()
*/
/mob/living/carbon/setOrganLoss(slot, amount, required_organ_flag = NONE)
var/obj/item/organ/affected_organ = get_organ_slot(slot)
if(!affected_organ || (status_flags & GODMODE))
return FALSE
if(required_organ_flag && !(affected_organ.organ_flags & required_organ_flag))
return FALSE
if(affected_organ.damage == amount)
return FALSE
return affected_organ.set_organ_damage(amount)
/**
* If an organ exists in the slot requested, return the amount of damage that organ has
*
* Arguments:
* * slot - organ slot, like [ORGAN_SLOT_HEART]
*/
/mob/living/carbon/get_organ_loss(slot)
var/obj/item/organ/affected_organ = get_organ_slot(slot)
if(affected_organ)
return affected_organ.damage
////////////////////////////////////////////
///Returns a list of damaged bodyparts
/mob/living/carbon/proc/get_damaged_bodyparts(brute = FALSE, burn = FALSE, required_bodytype = NONE, target_zone = null)
var/list/obj/item/bodypart/parts = list()
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
if(required_bodytype && !(BP.bodytype & required_bodytype))
continue
if(!isnull(target_zone) && BP.body_zone != target_zone)
continue
if((brute && BP.brute_dam) || (burn && BP.burn_dam))
parts += BP
return parts
///Returns a list of damageable bodyparts
/mob/living/carbon/proc/get_damageable_bodyparts(required_bodytype)
var/list/obj/item/bodypart/parts = list()
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
if(required_bodytype && !(BP.bodytype & required_bodytype))
continue
if(BP.brute_dam + BP.burn_dam < BP.max_damage)
parts += BP
return parts
///Returns a list of bodyparts with wounds (in case someone has a wound on an otherwise fully healed limb)
/mob/living/carbon/proc/get_wounded_bodyparts(required_bodytype)
var/list/obj/item/bodypart/parts = list()
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
if(required_bodytype && !(BP.bodytype & required_bodytype))
continue
if(LAZYLEN(BP.wounds))
parts += BP
return parts
/**
* Heals ONE bodypart randomly selected from damaged ones.
* It automatically updates damage overlays if necessary
*
* It automatically updates health status
*/
/mob/living/carbon/heal_bodypart_damage(brute = 0, burn = 0, updating_health = TRUE, required_bodytype = NONE, target_zone = null)
. = FALSE
var/list/obj/item/bodypart/parts = get_damaged_bodyparts(brute, burn, required_bodytype, target_zone)
if(!parts.len)
return
var/obj/item/bodypart/picked = pick(parts)
var/damage_calculator = picked.get_damage() //heal_damage returns update status T/F instead of amount healed so we dance gracefully around this
if(picked.heal_damage(abs(brute), abs(burn), required_bodytype = required_bodytype))
update_damage_overlays()
return (damage_calculator - picked.get_damage())
/**
* Damages ONE bodypart randomly selected from damagable ones.
*
* It automatically updates damage overlays if necessary
*
* It automatically updates health status
*/
/mob/living/carbon/take_bodypart_damage(brute = 0, burn = 0, updating_health = TRUE, required_bodytype, check_armor = FALSE, wound_bonus = 0, bare_wound_bonus = 0, sharpness = NONE)
. = FALSE
if(status_flags & GODMODE)
return
var/list/obj/item/bodypart/parts = get_damageable_bodyparts(required_bodytype)
if(!parts.len)
return
var/obj/item/bodypart/picked = pick(parts)
var/damage_calculator = picked.get_damage()
if(picked.receive_damage(abs(brute), abs(burn), check_armor ? run_armor_check(picked, (brute ? MELEE : burn ? FIRE : null)) : FALSE, wound_bonus = wound_bonus, bare_wound_bonus = bare_wound_bonus, sharpness = sharpness))
update_damage_overlays()
return (damage_calculator - picked.get_damage())
/mob/living/carbon/heal_overall_damage(brute = 0, burn = 0, stamina = 0, required_bodytype, updating_health = TRUE, forced = FALSE)
. = FALSE
// treat negative args as positive
brute = abs(brute)
burn = abs(burn)
var/list/obj/item/bodypart/parts = get_damaged_bodyparts(brute, burn, required_bodytype)
var/update = NONE
while(parts.len && (brute > 0 || burn > 0))
var/obj/item/bodypart/picked = pick(parts)
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam
. += picked.get_damage()
update |= picked.heal_damage(brute, burn, updating_health = FALSE, forced = forced, required_bodytype = required_bodytype)
. -= picked.get_damage() // return the net amount of damage healed
brute = round(brute - (brute_was - picked.brute_dam), DAMAGE_PRECISION)
burn = round(burn - (burn_was - picked.burn_dam), DAMAGE_PRECISION)
parts -= picked
if(!.) // no change? no need to update anything
return
if(updating_health)
updatehealth()
if(update)
update_damage_overlays()
/mob/living/carbon/take_overall_damage(brute = 0, burn = 0, stamina = 0, updating_health = TRUE, forced = FALSE, required_bodytype)
. = FALSE
if(!forced && (status_flags & GODMODE))
return
// treat negative args as positive
brute = abs(brute)
burn = abs(burn)
var/list/obj/item/bodypart/parts = get_damageable_bodyparts(required_bodytype)
var/update = NONE
while(parts.len && (brute > 0 || burn > 0))
var/obj/item/bodypart/picked = pick(parts)
var/brute_per_part = round(brute/parts.len, DAMAGE_PRECISION)
var/burn_per_part = round(burn/parts.len, DAMAGE_PRECISION)
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam
. += picked.get_damage()
// disabling wounds from these for now cuz your entire body snapping cause your heart stopped would suck
update |= picked.receive_damage(brute_per_part, burn_per_part, blocked = FALSE, updating_health = FALSE, forced = forced, required_bodytype = required_bodytype, wound_bonus = CANT_WOUND)
. -= picked.get_damage() // return the net amount of damage healed
brute = round(brute - (picked.brute_dam - brute_was), DAMAGE_PRECISION)
burn = round(burn - (picked.burn_dam - burn_was), DAMAGE_PRECISION)
parts -= picked
if(!.) // no change? no need to update anything
return
if(updating_health)
updatehealth()
if(update)
update_damage_overlays()