From 3093328757f2af4577bc9c3053cc87ce513933da Mon Sep 17 00:00:00 2001 From: Jacquerel Date: Mon, 24 Jun 2024 22:54:36 +0100 Subject: [PATCH] Minebots will no longer attempt to stop you from committing suicide by killing you (#83919) ## About The Pull Request The `/datum/pet_command/protect_owner` behaviour did not have any validation for if the person who attacked you was yourself. The three mobs which used this behaviour would sometimes be capable of seeing you accidentally slap yourself with a burrito and decide that this meant that you needed to be protected from this hideous and violent aggressor (yourself), and would then start trying to kill you. If you had multiple minebots they would then start attacking each other in a fit of jealous and protective rage, which I think was quite funny but isn't supposed to be how the game works. --- code/__DEFINES/ai/ai_blackboard.dm | 3 +++ code/__DEFINES/ai/pet_commands.dm | 4 ++-- .../datums/components/pet_commands/pet_commands_basic.dm | 9 +++++++++ code/modules/mob/living/basic/icemoon/wolf/wolf_ai.dm | 7 ++++++- code/modules/mob/living/basic/minebots/minebot_ai.dm | 7 +++++++ code/modules/mob/living/basic/vermin/cockroach.dm | 4 ++++ code/modules/mob/living/basic/vermin/frog.dm | 4 ++++ code/modules/mob/living/basic/vermin/mouse.dm | 5 +++++ code/modules/mob/living/emote.dm | 2 +- code/modules/mob/mob_say.dm | 2 +- 10 files changed, 42 insertions(+), 5 deletions(-) diff --git a/code/__DEFINES/ai/ai_blackboard.dm b/code/__DEFINES/ai/ai_blackboard.dm index 23c16bdcd0b..90a9b55ba17 100644 --- a/code/__DEFINES/ai/ai_blackboard.dm +++ b/code/__DEFINES/ai/ai_blackboard.dm @@ -162,3 +162,6 @@ // Used to hold state without making bigass lists /// For /datum/ai_behavior/find_potential_targets, what if any field are we using currently #define BB_FIND_TARGETS_FIELD(type) "bb_find_targets_field_[type]" + +///mothroach next meal key! +#define BB_MOTHROACH_NEXT_EAT "mothroach_next_eat" diff --git a/code/__DEFINES/ai/pet_commands.dm b/code/__DEFINES/ai/pet_commands.dm index 7404cb9acda..5f03bf1a5b0 100644 --- a/code/__DEFINES/ai/pet_commands.dm +++ b/code/__DEFINES/ai/pet_commands.dm @@ -7,6 +7,6 @@ #define BB_PET_TARGETING_STRATEGY "BB_pet_targeting" /// Typecache of weakrefs to mobs this mob is friends with, will follow their instructions and won't attack them #define BB_FRIENDS_LIST "BB_friends_list" +/// List of strings we might say to encourage someone to make better choices. +#define BB_OWNER_SELF_HARM_RESPONSES "BB_self_harm_responses" -///mothroach next meal key! -#define BB_MOTHROACH_NEXT_EAT "mothroach_next_eat" diff --git a/code/datums/components/pet_commands/pet_commands_basic.dm b/code/datums/components/pet_commands/pet_commands_basic.dm index 5ff476a85b9..d9ce0ccb56a 100644 --- a/code/datums/components/pet_commands/pet_commands_basic.dm +++ b/code/datums/components/pet_commands/pet_commands_basic.dm @@ -222,6 +222,8 @@ var/protect_range = 9 ///the behavior we will use when he is attacked var/protect_behavior = /datum/ai_behavior/basic_melee_attack + ///message cooldown to prevent too many people from telling you not to commit suicide + COOLDOWN_DECLARE(self_harm_message_cooldown) /datum/pet_command/protect_owner/add_new_friend(mob/living/tamer) RegisterSignal(tamer, COMSIG_ATOM_WAS_ATTACKED, PROC_REF(set_attacking_target)) @@ -252,6 +254,13 @@ var/mob/living/basic/owner = weak_parent.resolve() if(isnull(owner)) return + if(source == attacker) + var/list/interventions = owner.ai_controller?.blackboard[BB_OWNER_SELF_HARM_RESPONSES] || list() + if (length(interventions) && COOLDOWN_FINISHED(src, self_harm_message_cooldown) && prob(30)) + COOLDOWN_START(src, self_harm_message_cooldown, 5 SECONDS) + var/chosen_statement = pick(interventions) + INVOKE_ASYNC(owner, TYPE_PROC_REF(/atom/movable, say), chosen_statement) + return var/mob/living/current_target = owner.ai_controller?.blackboard[BB_CURRENT_PET_TARGET] if(attacker == current_target) //we are already dealing with this target return diff --git a/code/modules/mob/living/basic/icemoon/wolf/wolf_ai.dm b/code/modules/mob/living/basic/icemoon/wolf/wolf_ai.dm index f0809d2ec86..423a33bb476 100644 --- a/code/modules/mob/living/basic/icemoon/wolf/wolf_ai.dm +++ b/code/modules/mob/living/basic/icemoon/wolf/wolf_ai.dm @@ -7,7 +7,12 @@ BB_BASIC_MOB_FLEE_DISTANCE = 30, BB_VISION_RANGE = 9, BB_TARGET_MINIMUM_STAT = HARD_CRIT, - BB_REINFORCEMENTS_EMOTE = "unleashes a chilling howl, calling for aid!" + BB_REINFORCEMENTS_EMOTE = "unleashes a chilling howl, calling for aid!", + BB_OWNER_SELF_HARM_RESPONSES = list( + "*me howls in dissaproval.", + "*me whines sadly.", + "*me attempts to take your hand in its mouth." + ) ) ai_movement = /datum/ai_movement/basic_avoidance diff --git a/code/modules/mob/living/basic/minebots/minebot_ai.dm b/code/modules/mob/living/basic/minebots/minebot_ai.dm index 959049f957d..62aeaf3aa79 100644 --- a/code/modules/mob/living/basic/minebots/minebot_ai.dm +++ b/code/modules/mob/living/basic/minebots/minebot_ai.dm @@ -9,6 +9,13 @@ BB_MINEBOT_AUTO_DEFEND = TRUE, BB_BLACKLIST_MINERAL_TURFS = list(/turf/closed/mineral/gibtonite), BB_AUTOMATED_MINING = FALSE, + BB_OWNER_SELF_HARM_RESPONSES = list( + "Please stop hurting yourself.", + "There is no need to do that.", + "Your actions are illogical.", + "Please make better choices.", + "Remember, you have beaten your worst days before." + ) ) ai_movement = /datum/ai_movement/basic_avoidance diff --git a/code/modules/mob/living/basic/vermin/cockroach.dm b/code/modules/mob/living/basic/vermin/cockroach.dm index 224c7161539..0680de631cb 100644 --- a/code/modules/mob/living/basic/vermin/cockroach.dm +++ b/code/modules/mob/living/basic/vermin/cockroach.dm @@ -68,6 +68,10 @@ blackboard = list( BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic, BB_PET_TARGETING_STRATEGY = /datum/targeting_strategy/basic/not_friends, + BB_OWNER_SELF_HARM_RESPONSES = list( + "*me waves its antennae in disapproval.", + "*me chitters sadly." + ) ) ai_traits = STOP_MOVING_WHEN_PULLED diff --git a/code/modules/mob/living/basic/vermin/frog.dm b/code/modules/mob/living/basic/vermin/frog.dm index 65b5dcbb277..a674169dbd5 100644 --- a/code/modules/mob/living/basic/vermin/frog.dm +++ b/code/modules/mob/living/basic/vermin/frog.dm @@ -111,6 +111,10 @@ blackboard = list( BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic, BB_PET_TARGETING_STRATEGY = /datum/targeting_strategy/basic/not_friends, + BB_OWNER_SELF_HARM_RESPONSES = list( + "*me licks its own eyeballs in disapproval.", + "*me croaks sadly." + ) ) ai_movement = /datum/ai_movement/basic_avoidance diff --git a/code/modules/mob/living/basic/vermin/mouse.dm b/code/modules/mob/living/basic/vermin/mouse.dm index f951b8c4898..3cce5e34817 100644 --- a/code/modules/mob/living/basic/vermin/mouse.dm +++ b/code/modules/mob/living/basic/vermin/mouse.dm @@ -416,6 +416,11 @@ BB_BASIC_MOB_CURRENT_TARGET = null, // heathen BB_CURRENT_HUNTING_TARGET = null, // cheese BB_LOW_PRIORITY_HUNTING_TARGET = null, // cable + BB_OWNER_SELF_HARM_RESPONSES = list( + "*me cleans its whiskers in disapproval.", + "*me squeaks sadly.", + "*me sheds a single small tear." + ) ) ai_traits = STOP_MOVING_WHEN_PULLED diff --git a/code/modules/mob/living/emote.dm b/code/modules/mob/living/emote.dm index 68175333519..67358fa912a 100644 --- a/code/modules/mob/living/emote.dm +++ b/code/modules/mob/living/emote.dm @@ -679,7 +679,7 @@ if(!can_run_emote(user, TRUE, intentional)) return FALSE - if(is_banned_from(user.ckey, "Emote")) + if(!isnull(user.ckey) && is_banned_from(user.ckey, "Emote")) to_chat(user, span_boldwarning("You cannot send custom emotes (banned).")) return FALSE diff --git a/code/modules/mob/mob_say.dm b/code/modules/mob/mob_say.dm index 7caa4489095..568aee66902 100644 --- a/code/modules/mob/mob_say.dm +++ b/code/modules/mob/mob_say.dm @@ -181,7 +181,7 @@ var/customsaypos = findtext(message, "*") if(!customsaypos) return message - if (is_banned_from(ckey, "Emote")) + if (!isnull(ckey) && is_banned_from(ckey, "Emote")) return copytext(message, customsaypos + 1) mods[MODE_CUSTOM_SAY_EMOTE] = copytext(message, 1, customsaypos) message = copytext(message, customsaypos + 1)