/
living_defense.dm
427 lines (344 loc) · 14.3 KB
/
living_defense.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/mob/living/proc/modify_damage_by_armor(def_zone, damage, damage_type, damage_flags, mob/living/victim, armor_pen, silent = FALSE)
var/list/armors = get_armors_by_zone(def_zone, damage_type, damage_flags)
. = args.Copy(2)
for(var/armor in armors)
var/datum/extension/armor/armor_datum = armor
. = armor_datum.apply_damage_modifications(arglist(.))
/mob/living/proc/get_blocked_ratio(def_zone, damage_type, damage_flags, armor_pen, damage)
var/list/armors = get_armors_by_zone(def_zone, damage_type, damage_flags)
. = 0
for(var/armor in armors)
var/datum/extension/armor/armor_datum = armor
. = 1 - (1 - .) * (1 - armor_datum.get_blocked(damage_type, damage_flags, armor_pen, damage)) // multiply the amount we let through
. = min(1, .)
/mob/living/proc/get_armors_by_zone(def_zone, damage_type, damage_flags)
. = list()
var/natural_armor = get_extension(src, /datum/extension/armor)
if(natural_armor)
. += natural_armor
if(psi)
. += get_extension(psi, /datum/extension/armor)
/mob/living/bullet_act(obj/item/projectile/P, def_zone)
if (status_flags & GODMODE)
return PROJECTILE_FORCE_MISS
//Being hit while using a deadman switch
var/obj/item/device/assembly/signaler/signaler = get_active_hand()
if(istype(signaler) && signaler.deadman)
log_and_message_admins("has triggered a signaler deadman's switch")
visible_message(SPAN_WARNING("[src] triggers their deadman's switch"))
signaler.signal()
//Armor
var/damage = P.damage
var/flags = P.damage_flags()
var/damaged
if(!P.nodamage)
damaged = apply_damage(damage, P.damage_type, def_zone, flags, P, P.armor_penetration)
bullet_impact_visuals(P, def_zone, damaged)
if(damaged || P.nodamage) // Run the block computation if we did damage or if we only use armor for effects (nodamage)
. = get_blocked_ratio(def_zone, P.damage_type, flags, P.armor_penetration, P.damage)
P.on_hit(src, ., def_zone)
if(ai_holder && P.firer)
ai_holder.react_to_attack(P.firer)
// For visuals and blood splatters etc
/mob/living/proc/bullet_impact_visuals(obj/item/projectile/P, def_zone, damage)
var/list/impact_sounds = LAZYACCESS(P.impact_sounds, get_bullet_impact_effect_type(def_zone))
if(length(impact_sounds))
playsound(src, pick(impact_sounds), 75)
/mob/living/get_bullet_impact_effect_type(def_zone)
return BULLET_IMPACT_MEAT
/**
* Checks the mob for auras and interactions of the given type.
*
* Calls one of the `aura_check_*` procs for each aura in the mobs `auras` list, based on type provided.
* All parameters after `type` are passed on to the called proc.
*
* **Parameters**:
* - `type` (String - One of `AURA_TYPE_*`) - The type of check to be performed any any found auras.
* - Additional parameters depend on aura type:
* - `AURA_TYPE_WEAPON (obj/item/weapon, mob/user, click_params)`:
* - `weapon` - The item used to attack/interact with the mob.
* - `attacker` - The mob performing the attack/interaction.
* - `click_params` - List of click parameters.
* - `AURA_TYPE_BULLET (obj/item/projectile/proj, def_zone)`:
* - `proj` - Projectile impacting the mob.
* - `def_zone` - Impacted body part target zone.
* - `AURA_TYPE_THROWN (atom/movable/thrown_atom, datum/thrownthing/thrown_datum)`:
* - `thrown_atom` - Atom impacting the mob.
* - `thrown_datum` - thrownthing datum instance for the throw chain.
* - `AURA_TYPE_LIFE` (No additional parameters)
*
* Returns boolean - `TRUE` if no auras were found or if no auras passed `AURA_FALSE` in their checks.
* Generally, a `FALSE` return value means the aura blocks further interaction.
*/
/mob/living/proc/aura_check(type)
if(!auras)
return TRUE
. = TRUE
var/list/newargs = args - args[1]
for(var/a in auras)
var/obj/aura/aura = a
var/result = EMPTY_BITFIELD
switch(type)
if(AURA_TYPE_WEAPON)
result = aura.aura_check_weapon(arglist(newargs))
if(AURA_TYPE_BULLET)
result = aura.aura_check_bullet(arglist(newargs))
if(AURA_TYPE_THROWN)
result = aura.aura_check_thrown(arglist(newargs))
if(AURA_TYPE_LIFE)
result = aura.aura_check_life()
if(result & AURA_FALSE)
. = FALSE
if(result & AURA_CANCEL)
break
//Handles the effects of "stun" weapons
/mob/living/proc/stun_effect_act(stun_amount, agony_amount, def_zone, used_weapon=null)
flash_pain()
if (stun_amount)
Stun(stun_amount)
Weaken(stun_amount)
apply_effect(stun_amount, EFFECT_STUTTER)
apply_effect(stun_amount, EFFECT_EYE_BLUR)
if (agony_amount)
apply_damage(agony_amount, DAMAGE_PAIN, def_zone, used_weapon = used_weapon)
apply_effect(agony_amount/10, EFFECT_STUTTER)
apply_effect(agony_amount/10, EFFECT_EYE_BLUR)
/mob/living/proc/electrocute_act(shock_damage, obj/source, siemens_coeff = 1.0, def_zone = null)
return FALSE //only carbon liveforms have this proc
/mob/living/emp_act(severity)
if (status_flags & GODMODE)
return
var/list/L = get_contents()
for(var/obj/O in L)
O.emp_act(severity)
..()
/mob/living/proc/resolve_item_attack(obj/item/I, mob/living/user, target_zone)
return target_zone
///Called when the mob is hit with an item in combat. Returns the blocked result
/mob/living/proc/hit_with_weapon(obj/item/I, mob/living/user, effective_force, hit_zone)
if(!effective_force)
return FALSE
var/damage_flags = I.damage_flags()
return apply_damage(effective_force, I.damtype, hit_zone, damage_flags, used_weapon=I, armor_pen=I.armor_penetration)
/mob/living/post_use_item(obj/item/tool, mob/living/user, interaction_handled, use_call)
if (interaction_handled && ai_holder && (use_call == "use" || use_call == "weapon"))
ai_holder.react_to_attack(user)
..()
//this proc handles being hit by a thrown atom
/mob/living/hitby(atom/movable/AM, datum/thrownthing/TT)
if(isliving(AM))
var/mob/living/M = AM
playsound(loc, 'sound/weapons/pierce.ogg', 25, 1, -1)
if(skill_fail_prob(SKILL_COMBAT, 75))
Weaken(rand(3,5))
if(M.skill_fail_prob(SKILL_HAULING, 100))
M.Weaken(rand(4,8))
M.visible_message(SPAN_DANGER("\The [M] collides with \the [src]!"))
if (!aura_check(AURA_TYPE_THROWN, AM, TT))
return
if(isobj(AM))
var/obj/O = AM
var/dtype = O.damtype
var/throw_damage = O.throwforce*(TT.speed/THROWFORCE_SPEED_DIVISOR)
var/miss_chance = max(15*(TT.dist_travelled-2),0)
if (prob(miss_chance) || (istype(src, /mob/living/exosuit) && prob(miss_chance * 0.75)))
visible_message(SPAN_NOTICE("\The [O] misses [src] narrowly!"))
return
visible_message(SPAN_WARNING("\The [src] has been hit by \the [O]."))
apply_damage(throw_damage, dtype, null, O.damage_flags(), O)
if(TT.thrower)
var/client/assailant = TT.thrower.client
if(assailant)
admin_attack_log(TT.thrower, src, "Threw \an [O] at the victim.", "Had \an [O] thrown at them.", "threw \an [O] at")
if (ai_holder)
ai_holder.react_to_attack(TT.thrower)
if(O.can_embed() && (throw_damage > 5*O.w_class)) //Handles embedding for non-humans and simple_animals.
embed(O)
process_momentum(AM, TT)
/mob/living/momentum_power(atom/movable/AM, datum/thrownthing/TT)
if(anchored || buckled)
return 0
. = (AM.get_mass()*TT.speed)/(get_mass()*min(AM.throw_speed,2))
if(has_gravity() || check_space_footing())
. *= 0.5
/mob/living/momentum_do(power, datum/thrownthing/TT, atom/movable/AM)
if(power >= 0.75) //snowflake to enable being pinned to walls
var/direction = TT.init_dir
throw_at(get_edge_target_turf(src, direction), min((TT.maxrange - TT.dist_travelled) * power, 10), throw_speed * min(power, 1.5), callback = new Callback(src,/mob/living/proc/pin_to_wall,AM,direction))
visible_message(SPAN_DANGER("\The [src] staggers under the impact!"),SPAN_DANGER("You stagger under the impact!"))
return
. = ..()
/mob/living/proc/pin_to_wall(obj/O, direction)
if(!istype(O) || O.loc != src || !O.can_embed())//Projectile is suitable for pinning.
return
var/turf/T = near_wall(direction,2)
if(T)
forceMove(T)
visible_message(SPAN_DANGER("[src] is pinned to the wall by [O]!"),SPAN_DANGER("You are pinned to the wall by [O]!"))
src.anchored = TRUE
src.pinned += O
/mob/living/proc/embed(obj/O, def_zone=null, datum/wound/supplied_wound)
O.forceMove(src)
embedded += O
verbs += /mob/proc/yank_out_object
//This is called when the mob is thrown into a dense turf
/mob/living/proc/turf_collision(turf/T, speed)
visible_message(SPAN_DANGER("[src] slams into \the [T]"))
playsound(T, 'sound/effects/bangtaper.ogg', 50, 1, 1)//so it plays sounds on the turf instead, makes for awesome carps to hull collision and such
apply_damage(speed * 2, DAMAGE_BRUTE)
/mob/living/proc/near_wall(direction,distance=1)
var/turf/T = get_step(get_turf(src),direction)
var/turf/last_turf = loc
var/i = 1
while(i>0 && i<=distance)
if(!T || T.density) //Turf is a wall or map edge.
return last_turf
i++
last_turf = T
T = get_step(T,direction)
return FALSE
// End BS12 momentum-transfer code.
/mob/living/attack_generic(mob/user, damage, attack_message)
if(!damage || !istype(user))
return
adjustBruteLoss(damage)
admin_attack_log(user, src, "Attacked", "Was attacked", "attacked")
visible_message(SPAN_DANGER("\The [user] has [attack_message] \the [src]"))
user.do_attack_animation(src)
spawn(1) updatehealth()
if (ai_holder)
ai_holder.react_to_attack(user)
/mob/living/proc/IgniteMob()
if(fire_stacks > 0 && !on_fire)
on_fire = 1
set_light(4, 0.6, l_color = COLOR_ORANGE)
update_fire()
/mob/living/proc/ExtinguishMob()
if(on_fire)
on_fire = 0
fire_stacks = 0
set_light(0)
update_fire()
/mob/living/proc/update_fire()
return
/mob/living/proc/adjust_fire_stacks(add_fire_stacks) //Adjusting the amount of fire_stacks we have on person
fire_stacks = clamp(fire_stacks + add_fire_stacks, FIRE_MIN_STACKS, FIRE_MAX_STACKS)
/mob/living/proc/handle_fire()
if(fire_stacks < 0)
fire_stacks = min(0, ++fire_stacks) //If we've doused ourselves in water to avoid fire, dry off slowly
if(!on_fire)
return TRUE
else if(fire_stacks <= 0)
ExtinguishMob() //Fire's been put out.
return TRUE
fire_stacks = max(0, fire_stacks - 0.2) //I guess the fire runs out of fuel eventually
var/datum/gas_mixture/G = loc.return_air() // Check if we're standing in an oxygenless environment
if(G.get_by_flag(XGM_GAS_OXIDIZER) < 1)
ExtinguishMob() //If there's no oxygen in the tile we're on, put out the fire
return TRUE
var/turf/location = get_turf(src)
location.hotspot_expose(fire_burn_temperature(), 50, 1)
/mob/living/fire_act(datum/gas_mixture/air, exposed_temperature, exposed_volume)
if (status_flags & GODMODE)
return
//once our fire_burn_temperature has reached the temperature of the fire that's giving fire_stacks, stop adding them.
//allow fire_stacks to go up to 4 for fires cooler than 700 K, since are being immersed in flame after all.
if(fire_stacks <= 4 || fire_burn_temperature() < exposed_temperature)
adjust_fire_stacks(2)
IgniteMob()
/mob/living/proc/get_cold_protection()
return FALSE
/mob/living/proc/get_heat_protection()
return FALSE
//Finds the effective temperature that the mob is burning at.
/mob/living/proc/fire_burn_temperature()
if (fire_stacks <= 0)
return FALSE
//Scale quadratically so that single digit numbers of fire stacks don't burn ridiculously hot.
//lower limit of 700 K, same as matches and roughly the temperature of a cool flame.
return max(2.25*round(FIRESUIT_MAX_HEAT_PROTECTION_TEMPERATURE*(fire_stacks/FIRE_MAX_FIRESUIT_STACKS)**2), 700)
/mob/living/proc/reagent_permeability()
return TRUE
/mob/living/proc/handle_actions()
//Pretty bad, i'd use picked/dropped instead but the parent calls in these are nonexistent
for(var/datum/action/A in actions)
if(A.CheckRemoval(src))
A.Remove(src)
for(var/obj/item/I in src)
if(I.action_button_name)
if(!I.action)
I.action = new I.default_action_type
I.action.name = I.action_button_name
I.action.SetTarget(I)
I.action.Grant(src)
return
/mob/living/update_action_buttons()
if(!hud_used) return
if(!client) return
if(hud_used.hud_shown != 1) //Hud toggled to minimal
return
client.screen -= hud_used.hide_actions_toggle
for(var/datum/action/A in actions)
if(A.button)
client.screen -= A.button
if(hud_used.action_buttons_hidden)
if(!hud_used.hide_actions_toggle)
hud_used.hide_actions_toggle = new(hud_used)
hud_used.hide_actions_toggle.UpdateIcon()
if(!hud_used.hide_actions_toggle.moved)
hud_used.hide_actions_toggle.screen_loc = hud_used.ButtonNumberToScreenCoords(1)
//hud_used.SetButtonCoords(hud_used.hide_actions_toggle,1)
client.screen += hud_used.hide_actions_toggle
return
var/button_number = 0
for(var/datum/action/A in actions)
button_number++
if(isnull(A.button))
var/obj/screen/movable/action_button/N = new(hud_used, A)
A.button = N
var/obj/screen/movable/action_button/B = A.button
B.UpdateIcon()
B.SetName(A.UpdateName())
client.screen += B
if(!B.moved)
B.screen_loc = hud_used.ButtonNumberToScreenCoords(button_number)
//hud_used.SetButtonCoords(B,button_number)
if(button_number > 0)
if(!hud_used.hide_actions_toggle)
hud_used.hide_actions_toggle = new(hud_used)
hud_used.hide_actions_toggle.InitialiseIcon(src)
if(!hud_used.hide_actions_toggle.moved)
hud_used.hide_actions_toggle.screen_loc = hud_used.ButtonNumberToScreenCoords(button_number+1)
//hud_used.SetButtonCoords(hud_used.hide_actions_toggle,button_number+1)
client.screen += hud_used.hide_actions_toggle
/mob/living/lava_act(datum/gas_mixture/air, temperature, pressure)
if (status_flags & GODMODE)
return
fire_act(air, temperature)
FireBurn(0.4*vsc.fire_firelevel_multiplier, temperature, pressure)
. = (health <= 0) ? ..() : FALSE
// Applies direct "cold" damage while checking protection against the cold.
/mob/living/proc/inflict_cold_damage(amount)
amount *= 1 - get_cold_protection(50) // Within spacesuit protection.
if(amount > 0)
adjustFireLoss(amount)
// Ditto, but for "heat".
/mob/living/proc/inflict_heat_damage(amount)
amount *= 1 - get_heat_protection(10000) // Within firesuit protection.
if(amount > 0)
adjustFireLoss(amount)
// and one for electricity because why not
/mob/living/proc/inflict_shock_damage(amount)
electrocute_act(amount, null, 1, pick(BP_HEAD, BP_CHEST, BP_GROIN))
// also one for water (most things resist it entirely, except for slimes)
/mob/living/proc/inflict_water_damage(amount)
amount *= 1
if(amount > 0)
adjustToxLoss(amount)
// one for abstracted away ""poison"" (mostly because simplemobs shouldn't handle reagents)
/mob/living/proc/inflict_poison_damage(amount)
if(isSynthetic())
return
amount *= 1
if(amount > 0)
adjustToxLoss(amount)