From 3e6e64476cd192e7a449819f64cdcb76507a4e82 Mon Sep 17 00:00:00 2001
From: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
Date: Mon, 26 Feb 2024 14:44:22 -0500
Subject: [PATCH] Icewalkers and ghosts can now tell who joined and who left
the Icemoon Dweller hole (#1062)
* Lets icewalkers and ghosts tell who joined and who left their hole spawner in the round via examining it twice
* Fixes a missing argument in examine()
* Apply suggestions from code review
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
* Update modular_nova/modules/primitive_catgirls/code/spawner.dm
* Fixes the leave and log cache print logic
---------
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
Co-authored-by: SomeRandomOwl <2568378+SomeRandomOwl@users.noreply.github.com>
---
.../primitive_catgirls/code/spawner.dm | 64 ++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
diff --git a/modular_nova/modules/primitive_catgirls/code/spawner.dm b/modular_nova/modules/primitive_catgirls/code/spawner.dm
index fc75e53354d..3f25038194f 100644
--- a/modular_nova/modules/primitive_catgirls/code/spawner.dm
+++ b/modular_nova/modules/primitive_catgirls/code/spawner.dm
@@ -25,6 +25,12 @@
uses = 12
deletes_on_zero_uses_left = FALSE
+ /// The list of real names of those that have gone back into the hole.
+ /// Should get modified automatically by `create()` and `put_back_in()`.
+ var/list/went_back_to_sleep = list()
+ /// The cached string to display for additional info on who joined and who left.
+ /// Nulled every time someone joins or leaves to ensure it gets re-generated.
+ var/join_and_leave_log_cache = null
/// The minimum time someone needs to be SSD before they can be put back in
var/ssd_time = 30 MINUTES
@@ -39,7 +45,7 @@
team = null
return ..()
-/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/examine()
+/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/examine(mob/user)
. = ..()
if(uses)
@@ -47,8 +53,53 @@
else
. += span_notice("It looks pretty empty.")
+ if(isprimitivedemihuman(user) || isobserver(user))
+ . += span_notice("You could examine it more thoroughly...")
+
return .
+
+/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/examine_more(mob/user)
+ . = ..()
+
+ if(!isprimitivedemihuman(user) && !isobserver(user))
+ return
+
+ . += get_joined_and_left_log()
+
+
+/**
+ * Returns the `join_and_leave_log_cache` string if it already exists, otherwise
+ * generates and returns it.
+ */
+/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/proc/get_joined_and_left_log()
+ if(join_and_leave_log_cache)
+ return join_and_leave_log_cache
+
+ var/list/joined_player_names = list()
+
+ for(var/datum/mind/joined_mind in team.members)
+ joined_player_names += joined_mind.name
+
+ if(!length(joined_player_names) && !length(went_back_to_sleep))
+ join_and_leave_log_cache = span_notice("Everyone still seems to be sleeping peacefully in the hole.")
+ return join_and_leave_log_cache
+
+ var/nobody_joined = !length(joined_player_names)
+ var/nobody_returned = !length(went_back_to_sleep)
+ var/should_add_newline = !nobody_returned && !nobody_joined // if we have both missing kin and kin who went back to sleep, add a newline
+
+ join_and_leave_log_cache = span_notice( \
+ "[nobody_joined ? "" : "You smell that the following kin are missing from the hole:\n\
+ [joined_player_names.Join(", ")]"]\
+ [should_add_newline ? "\n\n" : ""]\
+ [nobody_returned ? "" : "You catch the scent of the following kin having recently went back to sleep:\n\
+ [went_back_to_sleep.Join(", ")]"]" \
+ )
+
+ return join_and_leave_log_cache
+
+
/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/allow_spawn(mob/user, silent = FALSE)
if(!(user.key in team.players_spawned)) // One spawn per person
return TRUE
@@ -56,6 +107,15 @@
to_chat(user, span_warning("It'd be weird if there were multiple of you in that cave, wouldn't it?"))
return FALSE
+
+/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/create(mob/mob_possessor, newname)
+ . = ..()
+
+ // We remove their name from there if they come back.
+ went_back_to_sleep -= newname
+ join_and_leave_log_cache = null
+
+
// This stuff is put on equip because it turns out /special sometimes just don't get called because Nova
/obj/effect/mob_spawn/ghost_role/human/primitive_catgirl/equip(mob/living/carbon/human/spawned_human)
. = ..()
@@ -153,6 +213,8 @@
// or whatever.
team.players_spawned -= (target.key)
team.remove_member(target.mind)
+ went_back_to_sleep += target.real_name
+ join_and_leave_log_cache = null
for(var/list/record in GLOB.ghost_records)
if(record["name"] == target.real_name)