[MIRROR] Cleans up signal use in bitrunning [NO GBP] [MDB IGNORE] (#24738)

* Cleans up signal use in bitrunning [NO GBP]

* Update avatar_connection.dm

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-11-02 17:47:36 -04:00
committed by GitHub
co-authored by Jeremiah Bloop
parent 347d9f9f0e
commit 8495b00be9
13 changed files with 169 additions and 170 deletions
@@ -36,12 +36,18 @@
ADD_TRAIT(avatar, TRAIT_NO_MINDSWAP, REF(src)) // do not remove this one
ADD_TRAIT(old_body, TRAIT_MIND_TEMPORARILY_GONE, REF(src))
/**
* Things that will disconnect forcefully:
* - Server shutdown / broken
* - Netpod power loss / broken
* - Pilot dies/ is moved / falls unconscious
*/
RegisterSignals(old_body, list(COMSIG_LIVING_DEATH, COMSIG_MOVABLE_MOVED, COMSIG_LIVING_STATUS_UNCONSCIOUS), PROC_REF(on_sever_connection))
RegisterSignal(pod, COMSIG_BITRUNNER_CROWBAR_ALERT, PROC_REF(on_netpod_crowbar))
RegisterSignal(pod, COMSIG_BITRUNNER_NETPOD_INTEGRITY, PROC_REF(on_netpod_damaged))
RegisterSignal(pod, COMSIG_BITRUNNER_SEVER_AVATAR, PROC_REF(on_sever_connection))
RegisterSignal(pod, COMSIG_BITRUNNER_NETPOD_SEVER, PROC_REF(on_sever_connection))
RegisterSignal(server, COMSIG_BITRUNNER_DOMAIN_COMPLETE, PROC_REF(on_domain_completed))
RegisterSignal(server, COMSIG_BITRUNNER_SEVER_AVATAR, PROC_REF(on_sever_connection))
RegisterSignal(server, COMSIG_BITRUNNER_QSRV_SEVER, PROC_REF(on_sever_connection))
RegisterSignal(server, COMSIG_BITRUNNER_SHUTDOWN_ALERT, PROC_REF(on_shutting_down))
RegisterSignal(server, COMSIG_BITRUNNER_THREAT_CREATED, PROC_REF(on_threat_created))
#ifndef UNIT_TESTS
@@ -69,18 +75,26 @@
/datum/component/avatar_connection/RegisterWithParent()
ADD_TRAIT(parent, TRAIT_TEMPORARY_BODY, REF(src))
RegisterSignal(parent, COMSIG_BITRUNNER_SAFE_DISCONNECT, PROC_REF(on_safe_disconnect))
/**
* Things that cause safe disconnection:
* - Click the alert
* - Mailed in a cache
* - Click / Stand on the ladder
*/
RegisterSignals(parent, list(COMSIG_BITRUNNER_ALERT_SEVER, COMSIG_BITRUNNER_CACHE_SEVER, COMSIG_BITRUNNER_LADDER_SEVER), PROC_REF(on_safe_disconnect))
RegisterSignal(parent, COMSIG_LIVING_DEATH, PROC_REF(on_sever_connection))
RegisterSignal(parent, COMSIG_MOB_APPLY_DAMAGE, PROC_REF(on_linked_damage))
/datum/component/avatar_connection/UnregisterFromParent()
REMOVE_TRAIT(parent, TRAIT_TEMPORARY_BODY, REF(src))
UnregisterSignal(parent, COMSIG_BITRUNNER_SAFE_DISCONNECT)
UnregisterSignal(parent, COMSIG_BITRUNNER_ALERT_SEVER)
UnregisterSignal(parent, COMSIG_BITRUNNER_CACHE_SEVER)
UnregisterSignal(parent, COMSIG_BITRUNNER_LADDER_SEVER)
UnregisterSignal(parent, COMSIG_LIVING_DEATH)
UnregisterSignal(parent, COMSIG_MOB_APPLY_DAMAGE)
/// Disconnects the avatar and returns the mind to the old_body.
/datum/component/avatar_connection/proc/full_avatar_disconnect(forced = FALSE, datum/source)
/datum/component/avatar_connection/proc/full_avatar_disconnect(cause_damage = FALSE, datum/source)
#ifndef UNIT_TESTS
return_to_old_body()
#endif
@@ -89,7 +103,7 @@
if(isnull(hosting_netpod) && istype(source, /obj/machinery/netpod))
hosting_netpod = source
hosting_netpod?.disconnect_occupant(forced)
hosting_netpod?.disconnect_occupant(cause_damage)
var/obj/machinery/quantum_server/server = server_ref?.resolve()
server?.avatar_connection_refs.Remove(WEAKREF(src))
@@ -101,7 +115,7 @@
SIGNAL_HANDLER
var/mob/living/avatar = parent
avatar.playsound_local(avatar, 'sound/machines/terminal_success.ogg', 50, TRUE)
avatar.playsound_local(avatar, 'sound/machines/terminal_success.ogg', 50, vary = TRUE)
avatar.throw_alert(
ALERT_BITRUNNER_COMPLETED,
/atom/movable/screen/alert/bitrunning/qserver_domain_complete,
@@ -113,12 +127,11 @@
SIGNAL_HANDLER
var/mob/living/carbon/old_body = old_body_ref?.resolve()
if(isnull(old_body) || damage_type == STAMINA || damage_type == OXYLOSS)
return
if(damage >= (old_body.health + (ishuman(old_body) ? HUMAN_MAXHEALTH : MAX_LIVING_HEALTH))) // SKYRAT EDIT CHANGE - ORIGINAL: if(damage >= (old_body.health + MAX_LIVING_HEALTH))
full_avatar_disconnect(forced = TRUE)
full_avatar_disconnect(cause_damage = TRUE)
return
if(damage > 30 && prob(30))
@@ -127,7 +140,7 @@
old_body.apply_damage(damage, damage_type, def_zone, blocked, wound_bonus = CANT_WOUND)
if(old_body.stat > SOFT_CRIT) // KO!
full_avatar_disconnect(forced = TRUE)
full_avatar_disconnect(cause_damage = TRUE)
/// Handles minds being swapped around in subsequent avatars
/datum/component/avatar_connection/proc/on_mind_transfer(datum/mind/source, mob/living/previous_body)
@@ -144,58 +157,66 @@
SIGNAL_HANDLER
var/mob/living/avatar = parent
avatar.playsound_local(avatar, 'sound/machines/terminal_alert.ogg', 50, TRUE)
avatar.throw_alert(
avatar.playsound_local(avatar, 'sound/machines/terminal_alert.ogg', 50, vary = TRUE)
var/atom/movable/screen/alert/bitrunning/alert = avatar.throw_alert(
ALERT_BITRUNNER_CROWBAR,
/atom/movable/screen/alert/bitrunning/netpod_crowbar,
/atom/movable/screen/alert/bitrunning,
new_master = intruder
)
alert.name = "Netpod Breached"
alert.desc = "Someone is prying open the netpod. Find an exit."
/// Triggers when the netpod is taking damage and is under 50%
/datum/component/avatar_connection/proc/on_netpod_damaged(datum/source)
SIGNAL_HANDLER
var/mob/living/avatar = parent
avatar.throw_alert(
var/atom/movable/screen/alert/bitrunning/alert = avatar.throw_alert(
ALERT_BITRUNNER_INTEGRITY,
/atom/movable/screen/alert/bitrunning/netpod_damaged,
/atom/movable/screen/alert/bitrunning,
new_master = source
)
alert.name = "Integrity Compromised"
alert.desc = "The netpod is damaged. Find an exit."
/// Safely exits without forced variables, etc
/// Triggers when a safe disconnect is called
/datum/component/avatar_connection/proc/on_safe_disconnect(datum/source)
SIGNAL_HANDLER
full_avatar_disconnect()
/// Helper for calling sever with forced variables
/// Received message to sever connection
/datum/component/avatar_connection/proc/on_sever_connection(datum/source)
SIGNAL_HANDLER
full_avatar_disconnect(forced = TRUE, source = source)
full_avatar_disconnect(cause_damage = TRUE, source = source)
/// Triggers when the server is shutting down
/datum/component/avatar_connection/proc/on_shutting_down(datum/source, mob/living/hackerman)
SIGNAL_HANDLER
var/mob/living/avatar = parent
avatar.playsound_local(avatar, 'sound/machines/terminal_alert.ogg', 50, TRUE)
avatar.throw_alert(
avatar.playsound_local(avatar, 'sound/machines/terminal_alert.ogg', 50, vary = TRUE)
var/atom/movable/screen/alert/bitrunning/alert = avatar.throw_alert(
ALERT_BITRUNNER_SHUTDOWN,
/atom/movable/screen/alert/bitrunning/qserver_shutting_down,
/atom/movable/screen/alert/bitrunning,
new_master = hackerman,
)
alert.name = "Domain Rebooting"
alert.desc = "The domain is rebooting. Find an exit."
/// Server has spawned a ghost role threat
/datum/component/avatar_connection/proc/on_threat_created(datum/source)
SIGNAL_HANDLER
var/mob/living/avatar = parent
avatar.throw_alert(
var/atom/movable/screen/alert/bitrunning/alert = avatar.throw_alert(
ALERT_BITRUNNER_THREAT,
/atom/movable/screen/alert/bitrunning/qserver_threat_spawned,
/atom/movable/screen/alert/bitrunning,
new_master = source,
)
alert.name = "Threat Detected"
alert.desc = "Data stream abnormalities present."
/// Returns the mind to the old body
/datum/component/avatar_connection/proc/return_to_old_body()