mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 10:11:09 +00:00
Adds SIGNAL_HANDLER, a macro that sets SHOULD_NOT_SLEEP(TRUE). This should ideally be required on all new signal callbacks. Adds BLOCKING_SIGNAL_HANDLER, a macro that does nothing except symbolize "this is an older signal that didn't necessitate a code rewrite". It should not be allowed for new work. This comes from discussion around #52735, which yields by calling input, and (though it sets the return type beforehand) will not properly return the flag to prevent attack from slapping. To fix 60% of the yielding cases, WrapAdminProcCall no longer waits for another admin's proc call to finish. I'm not an admin, so I don't know how many behinds this has saved, but if this is problematic for admins I can just make it so that it lets you do it anyway. I'm not sure what the point of this babysitting was anyway. Requested by @optimumtact. Changelog cl admin: Calling a proc while another admin is calling one will no longer wait for the first to finish. You will simply just have to call it again. /cl
51 lines
1.7 KiB
Plaintext
51 lines
1.7 KiB
Plaintext
//Items with these will have a chance to get knocked off when disarming
|
|
/datum/component/knockoff
|
|
var/knockoff_chance = 100 //Chance to knockoff
|
|
var/list/target_zones //Aiming for these zones will cause the knockoff, null means all zones allowed
|
|
var/list/slots_knockoffable //Can be only knocked off from these slots, null means all slots allowed
|
|
|
|
/datum/component/knockoff/Initialize(knockoff_chance,zone_override,slots_knockoffable)
|
|
if(!isitem(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED,.proc/OnEquipped)
|
|
RegisterSignal(parent, COMSIG_ITEM_DROPPED,.proc/OnDropped)
|
|
|
|
src.knockoff_chance = knockoff_chance
|
|
|
|
if(zone_override)
|
|
target_zones = zone_override
|
|
|
|
if(slots_knockoffable)
|
|
src.slots_knockoffable = slots_knockoffable
|
|
|
|
/datum/component/knockoff/proc/Knockoff(mob/living/attacker,zone)
|
|
SIGNAL_HANDLER
|
|
|
|
var/obj/item/I = parent
|
|
var/mob/living/carbon/human/wearer = I.loc
|
|
if(!istype(wearer))
|
|
return
|
|
if(target_zones && !(zone in target_zones))
|
|
return
|
|
if(!prob(knockoff_chance))
|
|
return
|
|
if(!wearer.dropItemToGround(I))
|
|
return
|
|
|
|
wearer.visible_message("<span class='warning'>[attacker] knocks off [wearer]'s [I.name]!</span>","<span class='userdanger'>[attacker] knocks off your [I.name]!</span>")
|
|
|
|
/datum/component/knockoff/proc/OnEquipped(datum/source, mob/living/carbon/human/H,slot)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!istype(H))
|
|
return
|
|
if(slots_knockoffable && !(slot in slots_knockoffable))
|
|
UnregisterSignal(H, COMSIG_HUMAN_DISARM_HIT)
|
|
return
|
|
RegisterSignal(H, COMSIG_HUMAN_DISARM_HIT, .proc/Knockoff, TRUE)
|
|
|
|
/datum/component/knockoff/proc/OnDropped(datum/source, mob/living/M)
|
|
SIGNAL_HANDLER
|
|
|
|
UnregisterSignal(M, COMSIG_HUMAN_DISARM_HIT)
|