Files
Bubberstation/code/datums/components/cuff_n_stun.dm
MrMelbert 135a09182b Refactors obscured (#92779)
## About The Pull Request

Fixes #85028

Obscured flags and covered flags are tracked on carbons, updated as
items are equipped and unequipped. It's that shrimple.

Closes #92760

Just removes the species exception checks for not making sense

Also refactors handcuffs / legcuffs removal. In all of these situations
they were hardcoded when they could easily just use an inventory proc to
work.

## Why It's Good For The Game

Stops a million excessive calls to `check_obscured_slots`

Makes obscured behavior more consistent

Makes obscured behavior easier to use

Cleans up human rendering (There was some cursed stuff before with
render item -> updated obscured -> update body -> cause side effects)

## Changelog

🆑 Melbert
del: Golems which somehow manage to grow wings and somehow manage to
equip something that covers their jumpsuit can no longer fly.
(Seriously, this will not affect anyone)
refactor: Refactored clothing obscurity entirely. Items should be a
loooot more consistent and what covers what, and should update a lot
snappier. As always, report any oddities, like mysteriously disappearing
articles of clothing, hair, or species parts
refactored: Refactored handcuffs and legcuffs a bit, report any odd
situations with cuffs like getting stuck restrained
/🆑
2025-09-07 09:24:34 +02:00

101 lines
3.2 KiB
Plaintext

/*
* A component to stun and cuff targets
*/
/datum/component/stun_n_cuff
/// mobs we cannot stun nor cuff
var/list/blacklist_mobs
///sound to play when stunning
var/stun_sound
///time to stun the target for
var/stun_timer
///time it takes for us to handcuff the target
var/handcuff_timer
///callback after we have stunned someone
var/datum/callback/post_stun_callback
///callback after we have arrested someone
var/datum/callback/post_arrest_callback
///time until we can stun again
var/stun_cooldown_timer
///type of cuffs we use
var/handcuff_type
///cooldown until we can stun again
COOLDOWN_DECLARE(stun_cooldown)
/datum/component/stun_n_cuff/Initialize(list/blacklist_mobs = list(),
stun_sound = 'sound/items/weapons/egloves.ogg',
stun_timer = 8 SECONDS,
handcuff_timer = 4 SECONDS,
stun_cooldown_timer = 10 SECONDS,
handcuff_type = /obj/item/restraints/handcuffs/cable/zipties/used,
post_stun_callback,
post_arrest_callback,
)
if(!isliving(parent))
return COMPONENT_INCOMPATIBLE
src.blacklist_mobs = blacklist_mobs
src.stun_sound = stun_sound
src.stun_timer = stun_timer
src.handcuff_timer = handcuff_timer
src.handcuff_type = handcuff_type
src.stun_cooldown_timer = stun_cooldown_timer
src.post_stun_callback = post_stun_callback
src.post_arrest_callback = post_arrest_callback
/datum/component/stun_n_cuff/RegisterWithParent()
RegisterSignal(parent, COMSIG_HOSTILE_PRE_ATTACKINGTARGET, PROC_REF(on_unarmed_attack))
/datum/component/stun_n_cuff/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_HOSTILE_PRE_ATTACKINGTARGET)
REMOVE_TRAIT(parent, TRAIT_MOB_BREEDER, REF(src))
post_stun_callback = null
post_arrest_callback = null
/datum/component/stun_n_cuff/proc/on_unarmed_attack(mob/living/source, atom/target)
SIGNAL_HANDLER
if(target == source || !iscarbon(target))
return NONE
if(is_type_in_typecache(target, blacklist_mobs))
return NONE
var/mob/living/carbon/living_target = target
if(living_target.IsParalyzed())
INVOKE_ASYNC(src, PROC_REF(cuff_target), target)
else
stun_target(target)
return COMPONENT_HOSTILE_NO_ATTACK
/datum/component/stun_n_cuff/proc/cuff_target(mob/living/carbon/human_target)
if(human_target.handcuffed)
var/mob/living/living_parent = parent
living_parent.balloon_alert(human_target, "already cuffed!")
return
playsound(parent, 'sound/items/weapons/cablecuff.ogg', 30, TRUE)
human_target.visible_message(span_danger("[parent] is trying to put zipties on [human_target]!"),\
span_danger("[parent] is trying to put zipties on you!"))
if(!do_after(parent, handcuff_timer, human_target))
return
human_target.set_handcuffed(new handcuff_type(human_target))
post_arrest_callback?.Invoke(human_target)
/datum/component/stun_n_cuff/proc/stun_target(mob/living/carbon/human_target)
if(!COOLDOWN_FINISHED(src, stun_cooldown))
return
playsound(parent, stun_sound, 50, TRUE)
human_target.Paralyze(stun_timer)
human_target.set_stutter(40 SECONDS)
log_combat(parent, human_target, "honked")
human_target.visible_message(
span_danger("[parent] stuns [human_target]!"), \
span_userdanger("[parent] stuns you!"), \
)
COOLDOWN_START(src, stun_cooldown, stun_cooldown_timer)
post_stun_callback?.Invoke(human_target)