Mafia update: Return to body when the game ends (#75258)

## About The Pull Request

Mafia players are now sent to their last body when the Mafia game ends,
and in the meantime they have text saying why they are dead.
They can still be revived during this period, and when the game is up
they'll be forced back into their body if alive, if they are dead then
they'll just be able to re-enter their corpse as normal.

Also since I was poking around in Mafia stuff:
- I removed mafia observing because it was unused (this previously was
used to allow ghosts to see Changeling chat).
- I fixed it being a Draw when there was one Town or Changeling left.
- I fixed the role list showing some roles multiple times
- I fixed the Chaplain not being able to use their night ability (and
therefore being completely useless)
- I added prevention to prevent Admins from causing runtimes or straight
up crashing the server, with a very real chance it can happen purely by
accident, through the Admin UI.

I'm hoping to change how this actually does the job because I find it to
be very bad coding practices, but my problem is that everyone who signs
up for Mafia is a ghost, and they are added into the game through their
CLIENTS, so we don't have access on the mafia controller or the role, to
the player's previous body or mind, without this shit.

Also adds a new mafia board icon

Made by tatax and I find it fits more the theme of Mafia than the
current one.

New UI
This commit is contained in:
John Willard
2023-06-05 13:18:20 -05:00
committed by GitHub
parent d01b433ab1
commit 0f22bb001e
10 changed files with 107 additions and 63 deletions
+55
View File
@@ -0,0 +1,55 @@
/**
* ##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
/datum/component/temporary_body/Initialize(datum/mind/old_mind, mob/living/old_body)
if(!isliving(parent) || !isliving(old_body))
return COMPONENT_INCOMPATIBLE
ADD_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
src.old_mind_ref = WEAKREF(old_mind)
src.old_body_ref = WEAKREF(old_body)
/datum/component/temporary_body/RegisterWithParent()
RegisterSignal(parent, COMSIG_PARENT_QDELETING, PROC_REF(on_parent_destroy))
/datum/component/temporary_body/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_PARENT_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()
if(!old_mind || !old_body)
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)
REMOVE_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
old_mind = null
old_body = null