Add caltrop component for spikey floor objects (#33280)
* Add caltrop component for spikey floor objects The caltrop component now can be added to any crossable atom, and it'll act like a shard of glass, or a d4. Additional flags are possible for it to bypass shoes or ignore people who are walking. This means d4 don't reimplement shard logic, and also open the window for caltrop grenades later. Also, it taught me how components work. * Code review I * Caltrop damage is 4 * Cactus hurts * Whoops * Ignore restraints = true
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/datum/component/caltrop
|
||||
var/min_damage
|
||||
var/max_damage
|
||||
var/probability
|
||||
var/flags
|
||||
|
||||
var/cooldown = 0
|
||||
|
||||
/datum/component/caltrop/Initialize(_min_damage = 0, _max_damage = 0, _probability = 100, _flags = NONE)
|
||||
min_damage = _min_damage
|
||||
max_damage = max(_min_damage, _max_damage)
|
||||
probability = _probability
|
||||
flags = _flags
|
||||
|
||||
RegisterSignal(list(COMSIG_MOVABLE_CROSSED), .proc/Crossed)
|
||||
|
||||
/datum/component/caltrop/proc/Crossed(atom/movable/AM)
|
||||
var/atom/A = parent
|
||||
if(!A.has_gravity())
|
||||
return
|
||||
|
||||
if(!prob(probability))
|
||||
return
|
||||
|
||||
if(ishuman(AM))
|
||||
var/mob/living/carbon/human/H = AM
|
||||
if(PIERCEIMMUNE in H.dna.species.species_traits)
|
||||
return
|
||||
|
||||
if((flags & CALTROP_IGNORE_WALKERS) && H.m_intent == MOVE_INTENT_WALK)
|
||||
return
|
||||
|
||||
var/picked_def_zone = pick("l_leg", "r_leg")
|
||||
var/obj/item/bodypart/O = H.get_bodypart(picked_def_zone)
|
||||
if(!istype(O))
|
||||
return
|
||||
if(O.status == BODYPART_ROBOTIC)
|
||||
return
|
||||
|
||||
var/feetCover = (H.wear_suit && (H.wear_suit.body_parts_covered & FEET)) || (H.w_uniform && (H.w_uniform.body_parts_covered & FEET))
|
||||
|
||||
if(!(flags & CALTROP_BYPASS_SHOES) && (H.shoes || feetCover))
|
||||
return
|
||||
|
||||
if((H.movement_type & FLYING) || H.buckled)
|
||||
return
|
||||
|
||||
var/damage = rand(min_damage, max_damage)
|
||||
H.apply_damage(damage, BRUTE, picked_def_zone)
|
||||
|
||||
if(cooldown < world.time - 10) //cooldown to avoid message spam.
|
||||
if(!H.incapacitated(ignore_restraints = TRUE))
|
||||
H.visible_message("<span class='danger'>[H] steps on [A].</span>", \
|
||||
"<span class='userdanger'>You step on [A]!</span>")
|
||||
else
|
||||
H.visible_message("<span class='danger'>[H] slides on [A]!</span>", \
|
||||
"<span class='userdanger'>You slide on [A]!</span>")
|
||||
|
||||
cooldown = world.time
|
||||
H.Knockdown(60)
|
||||
Reference in New Issue
Block a user