mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 10:11:09 +00:00
## About The Pull Request IDK if temporary body is broken or split personality is broken but it seems like this code simply doesn't work, as split personalities are consistently being ghosted and forced DNR ## Changelog 🆑 Melbert fix: Blackout drunk / Split personality no longer ghosts you /🆑
64 lines
2.1 KiB
Plaintext
64 lines
2.1 KiB
Plaintext
/**
|
|
* ##temporary_body
|
|
*
|
|
* Used on living mobs when they are meant to be a 'temporary body'
|
|
* Holds a reference to an old mind & body, to put them back in
|
|
* once the body this component is attached to, is being deleted.
|
|
*/
|
|
/datum/component/temporary_body
|
|
///The old mind we will be put back into when parent is being deleted.
|
|
var/datum/weakref/old_mind_ref
|
|
///The old body we will be put back into when parent is being deleted.
|
|
var/datum/weakref/old_body_ref
|
|
/// Returns the mind if the parent dies by any means
|
|
var/delete_on_death = FALSE
|
|
|
|
/datum/component/temporary_body/Initialize(datum/mind/old_mind, mob/living/old_body, delete_on_death = FALSE)
|
|
if(!isliving(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
src.old_mind_ref = WEAKREF(old_mind)
|
|
if(istype(old_body))
|
|
ADD_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
|
|
src.old_body_ref = WEAKREF(old_body)
|
|
src.delete_on_death = delete_on_death
|
|
|
|
/datum/component/temporary_body/RegisterWithParent()
|
|
RegisterSignal(parent, COMSIG_QDELETING, PROC_REF(on_parent_destroy))
|
|
|
|
if(delete_on_death)
|
|
RegisterSignal(parent, COMSIG_LIVING_DEATH, PROC_REF(on_parent_destroy))
|
|
|
|
/datum/component/temporary_body/UnregisterFromParent()
|
|
UnregisterSignal(parent, COMSIG_QDELETING)
|
|
|
|
/**
|
|
* Sends the mind of the temporary body back into their previous host
|
|
* If the previous host is alive, we'll force them into the body.
|
|
* Otherwise we'll let them hang out as a ghost still.
|
|
*/
|
|
/datum/component/temporary_body/proc/on_parent_destroy()
|
|
SIGNAL_HANDLER
|
|
var/datum/mind/old_mind = old_mind_ref?.resolve()
|
|
var/mob/living/old_body = old_body_ref?.resolve() || old_mind.current
|
|
|
|
if(!old_mind)
|
|
return
|
|
|
|
var/mob/living/living_parent = parent
|
|
var/mob/dead/observer/ghost = living_parent.ghostize()
|
|
if(!ghost)
|
|
ghost = living_parent.get_ghost()
|
|
if(!ghost)
|
|
CRASH("[src] belonging to [parent] was completely unable to find a ghost to put back into a body!")
|
|
ghost.mind = old_mind
|
|
if(old_body?.stat != DEAD)
|
|
old_mind.transfer_to(old_body, force_key_move = TRUE)
|
|
else
|
|
old_mind.set_current(old_body)
|
|
|
|
if(old_body)
|
|
REMOVE_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
|
|
|
|
old_mind = null
|
|
old_body = null
|