-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathdamage_procs.dm
265 lines (228 loc) · 10.2 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
/mob/living/carbon/apply_damage(damage, damagetype = BRUTE, def_zone = null, blocked = FALSE, wound_bonus = 0, bare_wound_bonus = 0, sharpness = SHARP_NONE, attack_direction = null)
SEND_SIGNAL(src, COMSIG_MOB_APPLY_DAMAGE, damage, damagetype, def_zone)
var/hit_percent = (100-blocked)/100
if(!damage || hit_percent <= 0)
return 0
var/obj/item/bodypart/BP = null
if(isbodypart(def_zone)) //we specified a bodypart object
BP = def_zone
else
if(!def_zone)
def_zone = ran_zone(def_zone)
BP = get_bodypart(check_zone(def_zone))
if(!BP)
BP = bodyparts[1]
switch(damagetype)
if(BRUTE)
if(BP)
if(BP.receive_damage(damage * hit_percent, 0, wound_bonus = wound_bonus, bare_wound_bonus = bare_wound_bonus, sharpness = sharpness, attack_direction = attack_direction))
update_damage_overlays()
else //no bodypart, we deal damage with a more general method.
adjustBruteLoss(damage * hit_percent)
if(BURN)
if(BP)
if(BP.receive_damage(0, damage * hit_percent, wound_bonus = wound_bonus, bare_wound_bonus = bare_wound_bonus, sharpness = sharpness, attack_direction = attack_direction))
update_damage_overlays()
else
adjustFireLoss(damage * hit_percent)
if(TOX)
adjustToxLoss(damage * hit_percent)
if(OXY)
adjustOxyLoss(damage * hit_percent)
if(CLONE)
adjustCloneLoss(damage * hit_percent)
if(STAMINA)
if(BP)
if(BP.receive_damage(0, 0, damage * hit_percent))
update_damage_overlays()
else
adjustStaminaLoss(damage * hit_percent)
return TRUE
//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_status)
if(!forced && (status_flags & GODMODE))
return FALSE
if(amount > 0)
take_overall_damage(amount, 0, 0, updating_health, required_status)
else
if(!required_status)
required_status = forced ? null : BODYPART_ORGANIC
heal_overall_damage(abs(amount), 0, 0, required_status, updating_health)
return amount
/mob/living/carbon/adjustFireLoss(amount, updating_health = TRUE, forced = FALSE, required_status)
if(!forced && (status_flags & GODMODE))
return FALSE
if(amount > 0)
take_overall_damage(0, amount, 0, updating_health, required_status)
else
if(!required_status)
required_status = forced ? null : BODYPART_ORGANIC
heal_overall_damage(0, abs(amount), 0, required_status, updating_health)
return amount
/mob/living/carbon/adjustToxLoss(amount, updating_health = TRUE, forced = FALSE)
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(HAS_TRAIT(src, TRAIT_TOXIMMUNE)) //Prevents toxin damage, but not healing
amount = min(amount, 0)
return ..()
/mob/living/carbon/adjustCloneLoss(amount, updating_health, forced)
if(HAS_TRAIT(src, TRAIT_NOCLONE)) // Can't have clone damage if you can't be cloned
amount = min(amount, 0) // but you can still heal it so you don't get stuck forever
return ..()
/mob/living/carbon/getStaminaLoss()
. = 0
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
. += round(BP.stamina_dam * BP.stam_damage_coeff, DAMAGE_PRECISION)
/mob/living/carbon/adjustStaminaLoss(amount, updating_health = TRUE, forced = FALSE)
if(!forced && (status_flags & GODMODE))
return FALSE
if(amount > 0)
take_overall_damage(0, 0, amount, updating_health)
else
heal_overall_damage(0, 0, abs(amount), null, updating_health)
return amount
/mob/living/carbon/setStaminaLoss(amount, updating_health = TRUE, forced = FALSE)
var/current = getStaminaLoss()
var/diff = amount - current
if(!diff)
return
adjustStaminaLoss(diff, updating_health, forced)
/** adjustOrganLoss
* inputs: slot (organ slot, like ORGAN_SLOT_HEART), amount (damage to be done), and maximum (currently an arbitrarily large number, can be set so as to limit damage)
* outputs:
* description: 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.
*/
/mob/living/carbon/adjustOrganLoss(slot, amount, maximum = 500)
var/obj/item/organ/O = getorganslot(slot)
if(O && !(status_flags & GODMODE))
O.applyOrganDamage(amount, maximum)
/** setOrganLoss
* inputs: slot (organ slot, like ORGAN_SLOT_HEART), amount(damage to be set to)
* outputs:
* description: 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.
*/
/mob/living/carbon/setOrganLoss(slot, amount)
var/obj/item/organ/O = getorganslot(slot)
if(O && !(status_flags & GODMODE))
O.setOrganDamage(amount)
/** getOrganLoss
* inputs: slot (organ slot, like ORGAN_SLOT_HEART)
* outputs: organ damage
* description: If an organ exists in the slot requested, return the amount of damage that organ has
*/
/mob/living/carbon/getOrganLoss(slot)
var/obj/item/organ/O = getorganslot(slot)
if(O)
return O.damage
////////////////////////////////////////////
//Returns a list of damaged bodyparts
/mob/living/carbon/proc/get_damaged_bodyparts(brute = FALSE, burn = FALSE, stamina = FALSE, status)
var/list/obj/item/bodypart/parts = list()
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
if(!(status == BODYPART_ANY) && (status && (BP.status != status))) //yogs - allows robot limb healing override
continue
if((brute && BP.brute_dam) || (burn && BP.burn_dam) || (stamina && BP.stamina_dam))
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(brute = FALSE, burn = FALSE, stamina = FALSE, status)
var/list/obj/item/bodypart/parts = list()
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
if(LAZYLEN(BP.wounds))
parts += BP
return parts
//Returns a list of damageable bodyparts
/mob/living/carbon/proc/get_damageable_bodyparts(status)
var/list/obj/item/bodypart/parts = list()
for(var/X in bodyparts)
var/obj/item/bodypart/BP = X
if(status && (BP.status != status))
continue
if(BP.brute_dam + BP.burn_dam < BP.max_damage)
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, stamina = 0, updating_health = TRUE, required_status)
var/list/obj/item/bodypart/parts = get_damaged_bodyparts(brute,burn,stamina,required_status ? required_status : BODYPART_ORGANIC)
if(!parts.len)
return
var/obj/item/bodypart/picked = pick(parts)
if(picked.heal_damage(brute, burn, stamina, required_status ? required_status : BODYPART_ORGANIC))
update_damage_overlays()
//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, stamina = 0, updating_health = TRUE, required_status, check_armor = FALSE, wound_bonus = 0, bare_wound_bonus = 0, sharpness = SHARP_NONE)
var/list/obj/item/bodypart/parts = get_damageable_bodyparts(required_status)
if(!parts.len)
return
var/obj/item/bodypart/picked = pick(parts)
if(picked.receive_damage(brute, burn, stamina,check_armor ? run_armor_check(picked, (brute ? MELEE : burn ? FIRE : stamina ? BULLET : null)) : FALSE, wound_bonus = wound_bonus, bare_wound_bonus = bare_wound_bonus, sharpness = sharpness))
update_damage_overlays()
//Heal MANY bodyparts, in random order
/mob/living/carbon/heal_overall_damage(brute = 0, burn = 0, stamina = 0, required_status, updating_health = TRUE)
var/list/obj/item/bodypart/parts = get_damaged_bodyparts(brute, burn, stamina, required_status)
var/update = NONE
while(parts.len && (brute > 0 || burn > 0 || stamina > 0))
var/obj/item/bodypart/picked = pick(parts)
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam
var/stamina_was = picked.stamina_dam
update |= picked.heal_damage(brute, burn, stamina, required_status, FALSE)
brute = round(brute - (brute_was - picked.brute_dam), DAMAGE_PRECISION)
burn = round(burn - (burn_was - picked.burn_dam), DAMAGE_PRECISION)
stamina = round(stamina - (stamina_was - picked.stamina_dam), DAMAGE_PRECISION)
parts -= picked
if(updating_health)
updatehealth()
update_stamina()
if(update)
update_damage_overlays()
// damage MANY bodyparts, in random order
/mob/living/carbon/take_overall_damage(brute = 0, burn = 0, stamina = 0, updating_health = TRUE, required_status)
if(status_flags & GODMODE)
return //godmode
var/list/obj/item/bodypart/parts = get_damageable_bodyparts(required_status)
var/update = 0
while(parts.len && (brute > 0 || burn > 0 || stamina > 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/stamina_per_part = round(stamina/parts.len, DAMAGE_PRECISION)
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam
var/stamina_was = picked.stamina_dam
update |= picked.receive_damage(brute_per_part, burn_per_part, stamina_per_part, FALSE, required_status, wound_bonus = CANT_WOUND) // disabling wounds from these for now cuz your entire body snapping cause your heart stopped would suck)
brute = round(brute - (picked.brute_dam - brute_was), DAMAGE_PRECISION)
burn = round(burn - (picked.burn_dam - burn_was), DAMAGE_PRECISION)
stamina = round(stamina - (picked.stamina_dam - stamina_was), DAMAGE_PRECISION)
parts -= picked
if(updating_health)
updatehealth()
if(update)
update_damage_overlays()
update_stamina()