[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
+22 -24
View File
@@ -7,27 +7,24 @@
rewards_base += servo_bonus
rewards_base += (domain_threats * 2)
rewards_base += (length(spawned_threat_refs) * 2)
for(var/index in 2 to length(avatar_connection_refs))
rewards_base += multiplayer_bonus
return rewards_base
/// Generates a reward based on the given domain
/obj/machinery/quantum_server/proc/generate_loot()
var/list/obj/machinery/byteforge/nearby_forges = get_nearby_forges()
if(isnull(nearby_forges))
say(src, "No nearby byteforges detected.")
return FALSE
/// Handles spawning the (new) crate and deleting the former
/obj/machinery/quantum_server/proc/generate_loot(obj/cache, obj/machinery/byteforge/chosen_forge)
for(var/mob/person in cache.contents)
SEND_SIGNAL(person, COMSIG_BITRUNNER_CACHE_SEVER)
spark_at_location(cache) // abracadabra!
qdel(cache) // and it's gone!
SEND_SIGNAL(src, COMSIG_BITRUNNER_DOMAIN_COMPLETE, cache, generated_domain.reward_points)
points += generated_domain.reward_points
playsound(src, 'sound/machines/terminal_success.ogg', 30, 2)
var/obj/machinery/byteforge/chosen_forge = pick(nearby_forges)
if(isnull(chosen_forge))
stack_trace("Failed to find a turf to spawn loot crate on.")
return FALSE
playsound(src, 'sound/machines/terminal_success.ogg', 30, vary = TRUE)
var/bonus = calculate_rewards()
@@ -36,11 +33,11 @@
certificate.name = "certificate of domain completion"
certificate.update_appearance()
var/obj/structure/closet/crate/secure/bitrunning/decrypted/reward_crate = new(src, generated_domain, bonus)
reward_crate.manifest = certificate
reward_crate.update_appearance()
var/obj/structure/closet/crate/secure/bitrunning/decrypted/reward_cache = new(src, generated_domain, bonus)
reward_cache.manifest = certificate
reward_cache.update_appearance()
chosen_forge.start_to_spawn(reward_crate)
chosen_forge.start_to_spawn(reward_cache)
return TRUE
/// Returns the markdown text containing domain completion information
@@ -51,18 +48,20 @@
var/bonuses = calculate_rewards()
var/domain_threats = length(spawned_threat_refs)
var/time_difference = world.time - generated_domain.start_time
var/completion_time = "### Completion Time: [DisplayTimeText(time_difference)]\n"
var/grade = "\n---\n\n# Rating: [grade_completion(generated_domain.difficulty, domain_threats, base_points, domain_randomized, time_difference)]"
var/grade = "\n---\n\n# Rating: [grade_completion(time_difference)]"
var/text = "# Certificate of Domain Completion\n\n---\n\n"
text += "### [generated_domain.name][domain_randomized ? " (Randomized)" : ""]\n"
text += "- **Difficulty:** [generated_domain.difficulty]\n"
text += "- **Threats:** [domain_threats]\n"
text += "- **Base Points:** [base_points][domain_randomized ? " +1" : ""]\n\n"
text += "- **Base Reward:** [base_points][domain_randomized ? " +1" : ""]\n\n"
text += "- **Total Bonus:** [bonuses]x\n\n"
if(bonuses <= 1)
@@ -91,12 +90,11 @@
return text
/// Grades the player's run based on several factors
/obj/machinery/quantum_server/proc/grade_completion(difficulty, threats, points, randomized, completion_time)
var/score = threats * 5
score += points
score += randomized ? 1 : 0
/obj/machinery/quantum_server/proc/grade_completion(completion_time)
var/score = length(spawned_threat_refs) * 5
score += generated_domain.reward_points
var/base = difficulty + 1
var/base = generated_domain.difficulty + 1
var/time_score = 1
if(completion_time <= 1 MINUTES)
@@ -142,7 +142,7 @@
/obj/machinery/quantum_server/proc/reset(fast = FALSE)
is_ready = FALSE
SEND_SIGNAL(src, COMSIG_BITRUNNER_SEVER_AVATAR)
sever_connections()
if(!fast)
notify_spawned_threats()
@@ -155,12 +155,11 @@
update_use_power(IDLE_POWER_USE)
domain_randomized = FALSE
domain_threats = 0
retries_spent = 0
/// Deletes all the tile contents
/obj/machinery/quantum_server/proc/scrub_vdom()
SEND_SIGNAL(src, COMSIG_BITRUNNER_SEVER_AVATAR) /// just in case someone's connected
sever_connections() /// just in case someone's connected
SEND_SIGNAL(src, COMSIG_BITRUNNER_DOMAIN_SCRUBBED) // avatar cleanup just in case
if(length(generated_domain.reservations))
@@ -16,12 +16,8 @@
var/datum/lazy_template/virtual_domain/generated_domain
/// The loaded safehouse, map_template/safehouse
var/datum/map_template/safehouse/generated_safehouse
/// The connected console
var/datum/weakref/console_ref
/// If the current domain was a random selection
var/domain_randomized = FALSE
/// If any threats were spawned, adds to rewards
var/domain_threats = 0
/// Prevents multiple user actions. Handled by loading domains and cooldowns
var/is_ready = TRUE
/// List of available domains
@@ -57,9 +53,6 @@
/obj/machinery/quantum_server/LateInitialize()
. = ..()
if(isnull(console_ref))
find_console()
radio = new(src)
radio.set_frequency(FREQ_SUPPLY)
radio.subspace_transmission = TRUE
@@ -146,4 +139,3 @@
servo_bonus = servo_rating
SEND_SIGNAL(src, COMSIG_BITRUNNER_SERVER_UPGRADED, servo_rating)
@@ -2,10 +2,7 @@
/obj/machinery/quantum_server/proc/on_broken(datum/source)
SIGNAL_HANDLER
if(isnull(generated_domain))
return
SEND_SIGNAL(src, COMSIG_BITRUNNER_SEVER_AVATAR)
sever_connections()
/// Whenever a corpse spawner makes a new corpse, add it to the list of potential mutations
/obj/machinery/quantum_server/proc/on_corpse_spawned(datum/source, mob/living/corpse)
@@ -18,7 +15,7 @@
SIGNAL_HANDLER
if(generated_domain)
SEND_SIGNAL(src, COMSIG_BITRUNNER_SEVER_AVATAR)
sever_connections()
scrub_vdom()
if(is_ready)
@@ -49,25 +46,14 @@
/obj/machinery/quantum_server/proc/on_goal_turf_entered(datum/source, atom/movable/arrived, atom/old_loc, list/atom/old_locs)
SIGNAL_HANDLER
if(!istype(arrived, /obj/structure/closet/crate/secure/bitrunning/encrypted))
var/obj/machinery/byteforge/chosen_forge = get_random_nearby_forge()
if(isnull(chosen_forge))
return
var/obj/structure/closet/crate/secure/bitrunning/encrypted/loot_crate = arrived
if(!istype(loot_crate))
if(istype(arrived, /obj/structure/closet/crate/secure/bitrunning/encrypted))
generate_loot(arrived, chosen_forge)
return
for(var/mob/person in loot_crate.contents)
if(isnull(person.mind))
person.forceMove(get_turf(loot_crate))
var/datum/component/avatar_connection/connection = person.GetComponent(/datum/component/avatar_connection)
connection?.full_avatar_disconnect()
spark_at_location(loot_crate)
qdel(loot_crate)
SEND_SIGNAL(src, COMSIG_BITRUNNER_DOMAIN_COMPLETE, arrived, generated_domain.reward_points)
generate_loot()
/// Handles examining the server. Shows cooldown time and efficiency.
/obj/machinery/quantum_server/proc/on_goal_turf_examined(datum/source, mob/examiner, list/examine_text)
SIGNAL_HANDLER
@@ -105,6 +91,4 @@
/obj/machinery/quantum_server/proc/on_threat_created(datum/source, mob/living/threat)
SIGNAL_HANDLER
domain_threats += 1
spawned_threat_refs.Add(WEAKREF(threat))
SEND_SIGNAL(src, COMSIG_BITRUNNER_THREAT_CREATED) // notify players
add_threats(threat)
+21
View File
@@ -0,0 +1,21 @@
/// Adds threats to the list and notifies players
/obj/machinery/quantum_server/proc/add_threats(mob/living/threat)
spawned_threat_refs.Add(WEAKREF(threat))
SEND_SIGNAL(src, COMSIG_BITRUNNER_THREAT_CREATED)
/// Finds any mobs with minds in the zones and gives them the bad news
/obj/machinery/quantum_server/proc/notify_spawned_threats()
for(var/datum/weakref/baddie_ref as anything in spawned_threat_refs)
var/mob/living/baddie = baddie_ref.resolve()
if(isnull(baddie?.mind) || baddie.stat >= UNCONSCIOUS)
continue
var/atom/movable/screen/alert/bitrunning/alert = baddie.throw_alert(
ALERT_BITRUNNER_RESET,
/atom/movable/screen/alert/bitrunning,
new_master = src,
)
alert.name = "Queue Deletion"
alert.desc = "The server is resetting. Oblivion awaits."
to_chat(baddie, span_userdanger("You have been flagged for deletion! Thank you for your service."))
+14 -26
View File
@@ -7,19 +7,6 @@
update_appearance()
radio.talk_into(src, "Thermal systems within operational parameters. Proceeding to domain configuration.", RADIO_CHANNEL_SUPPLY)
/// Attempts to connect to a quantum console
/obj/machinery/quantum_server/proc/find_console()
var/obj/machinery/computer/quantum_console/console = console_ref?.resolve()
if(console)
return console
for(var/direction in GLOB.cardinals)
var/obj/machinery/computer/quantum_console/nearby_console = locate(/obj/machinery/computer/quantum_console, get_step(src, direction))
if(nearby_console)
console_ref = WEAKREF(nearby_console)
nearby_console.server_ref = WEAKREF(src)
return nearby_console
/// Compiles a list of available domains.
/obj/machinery/quantum_server/proc/get_available_domains()
var/list/levels = list()
@@ -91,6 +78,15 @@
domain_randomized = TRUE
return available["id"]
/// Locates any turfs with forges on them, returns a random one
/obj/machinery/quantum_server/proc/get_random_nearby_forge()
var/list/nearby_forges = list()
for(var/obj/machinery/byteforge/forge in oview(MAX_DISTANCE, src))
nearby_forges += forge
return pick(nearby_forges)
/// Gets all mobs originally generated by the loaded domain and returns a list that are capable of being antagged
/obj/machinery/quantum_server/proc/get_valid_domain_targets()
// A: No one is playing
@@ -116,20 +112,12 @@
return nearby_forges
/// Finds any mobs with minds in the zones and gives them the bad news
/obj/machinery/quantum_server/proc/notify_spawned_threats()
for(var/datum/weakref/baddie_ref as anything in spawned_threat_refs)
var/mob/living/baddie = baddie_ref.resolve()
if(isnull(baddie) || baddie.stat >= UNCONSCIOUS || isnull(baddie.mind))
continue
/// Severs any connected users
/obj/machinery/quantum_server/proc/sever_connections()
if(isnull(generated_domain) || !length(avatar_connection_refs))
return
baddie.throw_alert(
ALERT_BITRUNNER_RESET,
/atom/movable/screen/alert/bitrunning/qserver_threat_deletion,
new_master = src,
)
to_chat(baddie, span_userdanger("You have been flagged for deletion! Thank you for your service."))
SEND_SIGNAL(src, COMSIG_BITRUNNER_QSRV_SEVER)
/// Do some magic teleport sparks
/obj/machinery/quantum_server/proc/spark_at_location(obj/cache)