[MIRROR] Refactor on_mob_death, death implants, implant permission (#2432)

* Refactor on_mob_death, death implants, implant permission (#55862)

* Refactor on_mob_death and death implants

There is a proc on `/obj/item` called `on_mob_death` called on all
items in the contents of a mob on that mob's death. It is currently used
for explosive implant detonation, and the deactivation of the
Peaceborg's projectile dampener.

Instead of using this old proc, both of them now instad use the
COMSIG_LIVING_DEATH signal, already emitted when their owner dies.

The activation of an explosive implant will now occur after the rest of
the death code has run, since it activates with an async applied
function, since some other implants may still want the mob's body
intact, and you shouldn't use `sleep()` (which it does in the "slow
explosion mode") in signal handlers.

In addition, the "can_be_implanted" proc for /mob/living (and overriden
for silicons, slimes and simple animals) has been folded into the
`/obj/item/implant/proc/can_be_implanted_to` proc. Some future implants
may want to be more permissive than the current permissions, but that
isn't possible when checking both procs.

* Refactor on_mob_death, death implants, implant permission

Co-authored-by: coiax <yellowbounder@gmail.com>
This commit is contained in:
SkyratBot
2021-01-01 22:17:15 +01:00
committed by GitHub
co-authored by coiax
parent 04e02c7c48
commit 4f2588e6bc
6 changed files with 31 additions and 31 deletions
+13 -16
View File
@@ -14,29 +14,26 @@
/obj/item/implant/proc/trigger(emote, mob/living/carbon/source)
return
/obj/item/implant/proc/on_death(emote, mob/living/carbon/source)
return
/obj/item/implant/proc/activate()
SEND_SIGNAL(src, COMSIG_IMPLANT_ACTIVATED)
/obj/item/implant/ui_action_click()
activate("action_button")
/obj/item/implant/proc/can_be_implanted_in(mob/living/target) // for human-only and other special requirements
/obj/item/implant/proc/can_be_implanted_in(mob/living/target)
if(issilicon(target))
return FALSE
if(isslime(target))
return TRUE
if(isanimal(target))
var/mob/living/simple_animal/animal = target
// Robots and most non-organics aren't healable.
return animal.healable
return TRUE
/mob/living/proc/can_be_implanted()
return TRUE
/mob/living/silicon/can_be_implanted()
return FALSE
/mob/living/simple_animal/can_be_implanted()
return healable //Applies to robots and most non-organics, exceptions can override.
//What does the implant do upon injection?
//return 1 if the implant injects
//return 0 if there is no room for implant / it fails
@@ -44,7 +41,7 @@
if(SEND_SIGNAL(src, COMSIG_IMPLANT_IMPLANTING, args) & COMPONENT_STOP_IMPLANTING)
return
LAZYINITLIST(target.implants)
if(!force && (!target.can_be_implanted() || !can_be_implanted_in(target)))
if(!force && !can_be_implanted_in(target))
return FALSE
for(var/X in target.implants)
var/obj/item/implant/imp_e = X
@@ -11,8 +11,14 @@
var/popup = FALSE // is the DOUWANNABLOWUP window open?
var/active = FALSE
/obj/item/implant/explosive/on_mob_death(mob/living/L, gibbed)
activate("death")
/obj/item/implant/explosive/proc/on_death(datum/source, gibbed)
SIGNAL_HANDLER
// There may be other signals that want to handle mob's death
// and the process of activating destroys the body, so let the other
// signal handlers at least finish. Also, the "delayed explosion"
// uses sleeps, which is bad for signal handlers to do.
INVOKE_ASYNC(src, .proc/activate, "death")
/obj/item/implant/explosive/get_data()
var/dat = {"<b>Implant Specifications:</b><BR>
@@ -61,9 +67,11 @@
imp_e.weak += weak
imp_e.delay += delay
qdel(src)
return 1
return TRUE
return ..()
. = ..()
if(.)
RegisterSignal(target, COMSIG_LIVING_DEATH, .proc/on_death)
/obj/item/implant/explosive/proc/timed_explosion()
imp_in.visible_message("<span class='warning'>[imp_in] starts beeping ominously!</span>")