Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Cleans up signal use in bitrunning #420

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions code/__DEFINES/dcs/signals/signals_bitrunning.dm
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
/// from /obj/machinery/netpod/default_pry_open() : (mob/living/intruder)
#define COMSIG_BITRUNNER_CROWBAR_ALERT "bitrunner_crowbar"
/// from /atom/movable/screen/alert/bitrunning/qserver_domain_complete
#define COMSIG_BITRUNNER_ALERT_SEVER "bitrunner_alert_sever"

/// from /obj/effect/bitrunning/loot_signal: (points)
#define COMSIG_BITRUNNER_GOAL_POINT "bitrunner_goal_point"

/// from /obj/machinery/quantum_server/on_goal_turf_entered(): (atom/entered, reward_points)
#define COMSIG_BITRUNNER_DOMAIN_COMPLETE "bitrunner_complete"
// Netpods

/// from /obj/machinery/netpod/sever_connection()
#define COMSIG_BITRUNNER_NETPOD_SEVER "bitrunner_netpod_sever"

/// from /obj/machinery/netpod/default_pry_open() : (mob/living/intruder)
#define COMSIG_BITRUNNER_CROWBAR_ALERT "bitrunner_crowbar"

/// from /obj/machinery/netpod/on_take_damage()
/// from /obj/machinery/netpod/on_damage_taken()
#define COMSIG_BITRUNNER_NETPOD_INTEGRITY "bitrunner_netpod_damage"

/// from /obj/structure/hololadder and complete alert
#define COMSIG_BITRUNNER_SAFE_DISCONNECT "bitrunner_disconnect"
/// from /obj/machinery/netpod/open_machine()
#define COMSIG_BITRUNNER_NETPOD_OPENED "bitrunner_netpod_opened"

// Server

/// from /obj/machinery/quantum_server/on_goal_turf_entered(): (atom/entered, reward_points)
#define COMSIG_BITRUNNER_DOMAIN_COMPLETE "bitrunner_complete"

/// from /obj/machinery/quantum_server/generate_loot()
#define COMSIG_BITRUNNER_CACHE_SEVER "bitrunner_cache_sever"

/// from /obj/machinery/netpod/open_machine(), /obj/machinery/quantum_server, etc (obj/machinery/netpod)
#define COMSIG_BITRUNNER_SEVER_AVATAR "bitrunner_sever"
/// from /obj/machinery/quantum_server/sever_connection()
#define COMSIG_BITRUNNER_QSRV_SEVER "bitrunner_qserver_sever"

/// from /obj/machinery/quantum_server/shutdown() : (mob/living)
#define COMSIG_BITRUNNER_SHUTDOWN_ALERT "bitrunner_shutdown"

// Notifies the bitrunners
/// from /datum/antagonist/cyber_police/proc/notify() :
/// from /obj/machinery/quantum_server/notify_threat()
#define COMSIG_BITRUNNER_THREAT_CREATED "bitrunner_threat"

// Informs the server to up the threat count
/// from event spawns: (mob/living)
#define COMSIG_BITRUNNER_SPAWN_GLITCH "bitrunner_spawn_glitch"

/// from /obj/machinery/quantum_server/refreshParts(): (servo rating)
#define COMSIG_BITRUNNER_SERVER_UPGRADED "bitrunner_server_upgraded"

/// from /obj/machinery/quantum_server/scrub_vdom()
#define COMSIG_BITRUNNER_DOMAIN_SCRUBBED "bitrunner_domain_scrubbed"

/// from /obj/machinery/netpod/open_machine()
#define COMSIG_BITRUNNER_NETPOD_OPENED "bitrunner_netpod_opened"
/// from /obj/machienry/quantum_server/station_spawn()
#define COMSIG_BITRUNNER_STATION_SPAWN "bitrunner_station_spawn"

// Ladder
/// from /obj/structure/hololadder/disconnect()
#define COMSIG_BITRUNNER_LADDER_SEVER "bitrunner_ladder_sever"


/// deprecated
#define COMSIG_BITRUNNER_SPAWN_GLITCH "bitrunner_spawn_glitch"
23 changes: 2 additions & 21 deletions code/modules/bitrunning/alerts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@
icon_state = "template"
timeout = 10 SECONDS

/atom/movable/screen/alert/bitrunning/netpod_crowbar
name = "Forced Entry"
desc = "Someone is prying open the netpod door. Find an exit."

/atom/movable/screen/alert/bitrunning/netpod_damaged
name = "Integrity Compromised"
desc = "The netpod is damaged. Find an exit."

/atom/movable/screen/alert/bitrunning/qserver_shutting_down
name = "Domain Rebooting"
desc = "The domain is rebooting. Find an exit."

/atom/movable/screen/alert/bitrunning/qserver_threat_deletion
name = "Queue Deletion"
desc = "The server is resetting. Oblivion awaits."

/atom/movable/screen/alert/bitrunning/qserver_threat_spawned
name = "Threat Detected"
desc = "Data stream abnormalities present."

/atom/movable/screen/alert/bitrunning/qserver_domain_complete
name = "Domain Completed"
desc = "The domain is completed. Activate to exit."
Expand All @@ -37,4 +17,5 @@
return

if(tgui_alert(living_owner, "Disconnect safely?", "Server Message", list("Exit", "Remain"), 10 SECONDS) == "Exit")
SEND_SIGNAL(living_owner, COMSIG_BITRUNNER_SAFE_DISCONNECT)
SEND_SIGNAL(living_owner, COMSIG_BITRUNNER_ALERT_SEVER)

67 changes: 44 additions & 23 deletions code/modules/bitrunning/components/avatar_connection.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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,
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion code/modules/bitrunning/objects/hololadder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

balloon_alert(user, "disconnecting...")
if(do_after(user, travel_time, src))
SEND_SIGNAL(user, COMSIG_BITRUNNER_SAFE_DISCONNECT)
SEND_SIGNAL(user, COMSIG_BITRUNNER_LADDER_SEVER)

/// Helper for times when you dont have hands (gondola??)
/obj/structure/hololadder/proc/on_enter(datum/source, atom/movable/arrived, turf/old_loc)
Expand Down
Loading
Loading