From 6aa87c24566059dfa2a91b7d64d342a0f2c95c9d Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 25 Aug 2023 03:23:11 +0200 Subject: [PATCH] [MIRROR] fixes regal rats not running away [MDB IGNORE] (#23304) * fixes regal rats not running away (#77888) ## About The Pull Request fixes the regal rat not running away from whoever attacked him. also adds a new pet command behavior which makes the king's minions drop whatever they are doing and defend their king from whoever has attacked him. ## Why It's Good For The Game the rats now behave right ## Changelog :cl: fix: regal rats now run away from whoever attacked them add: new pet behavior which makes pets defend their owners if they got attacked /:cl: * fixes regal rats not running away --------- Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> --- code/__DEFINES/traits.dm | 3 ++ .../pet_commands/pet_commands_basic.dm | 40 +++++++++++++++++++ code/datums/elements/relay_attackers.dm | 2 + .../regal_rat/regal_rat_actions.dm | 5 +++ .../space_fauna/regal_rat/regal_rat_ai.dm | 5 ++- 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/code/__DEFINES/traits.dm b/code/__DEFINES/traits.dm index 5dcb3252f63..5a09eb0c122 100644 --- a/code/__DEFINES/traits.dm +++ b/code/__DEFINES/traits.dm @@ -1288,3 +1288,6 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai /// This means the "caster" of the spell is changed to the mob's loc /// Note this doesn't mean all spells are guaranteed to work or the mob is guaranteed to cast #define TRAIT_CASTABLE_LOC "castable_loc" + +///Trait given by /datum/element/relay_attacker +#define TRAIT_RELAYING_ATTACKER "relaying_attacker" diff --git a/code/datums/components/pet_commands/pet_commands_basic.dm b/code/datums/components/pet_commands/pet_commands_basic.dm index fb6dde9bc8d..40ec41aa3d6 100644 --- a/code/datums/components/pet_commands/pet_commands_basic.dm +++ b/code/datums/components/pet_commands/pet_commands_basic.dm @@ -164,3 +164,43 @@ // We also don't check if the cooldown is over because there's no way a pet owner can know that, the behaviour will handle it controller.queue_behavior(/datum/ai_behavior/pet_use_ability, pet_ability_key, BB_CURRENT_PET_TARGET) return SUBTREE_RETURN_FINISH_PLANNING + +/datum/pet_command/protect_owner + command_name = "Protect owner" + command_desc = "Your pet will run to your aid." + hidden = TRUE + ///the range our owner needs to be in for us to protect him + var/protect_range = 9 + ///the behavior we will use when he is attacked + var/protect_behavior = /datum/ai_behavior/basic_melee_attack + +/datum/pet_command/protect_owner/add_new_friend(mob/living/tamer) + RegisterSignal(tamer, COMSIG_ATOM_WAS_ATTACKED, PROC_REF(set_attacking_target)) + if(!HAS_TRAIT(tamer, TRAIT_RELAYING_ATTACKER)) + tamer.AddElement(/datum/element/relay_attackers) + +/datum/pet_command/protect_owner/remove_friend(mob/living/unfriended) + UnregisterSignal(unfriended, COMSIG_ATOM_WAS_ATTACKED) + +/datum/pet_command/protect_owner/execute_action(datum/ai_controller/controller) + var/datum/targetting_datum/basic/targetting = controller.blackboard[BB_TARGETTING_DATUM] + var/mob/living/victim = controller.blackboard[BB_CURRENT_PET_TARGET] + if(victim.stat > targetting.stat_attack) + controller.clear_blackboard_key(BB_ACTIVE_PET_COMMAND) + return + controller.queue_behavior(protect_behavior, BB_CURRENT_PET_TARGET, BB_PET_TARGETTING_DATUM) + return SUBTREE_RETURN_FINISH_PLANNING + +/datum/pet_command/protect_owner/set_command_active(mob/living/parent, mob/living/victim) + . = ..() + set_command_target(parent, victim) + +/datum/pet_command/protect_owner/proc/set_attacking_target(atom/source, mob/living/attacker) + var/mob/living/basic/owner = weak_parent.resolve() + if(isnull(owner)) + 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 + if(isliving(attacker) && can_see(owner, attacker, protect_range)) + set_command_active(owner, attacker) diff --git a/code/datums/elements/relay_attackers.dm b/code/datums/elements/relay_attackers.dm index 9bae3beb7e5..9f134daf71b 100644 --- a/code/datums/elements/relay_attackers.dm +++ b/code/datums/elements/relay_attackers.dm @@ -15,6 +15,7 @@ RegisterSignal(target, COMSIG_ATOM_PREHITBY, PROC_REF(on_hitby)) RegisterSignal(target, COMSIG_ATOM_HULK_ATTACK, PROC_REF(on_attack_hulk)) RegisterSignal(target, COMSIG_ATOM_ATTACK_MECH, PROC_REF(on_attack_mech)) + ADD_TRAIT(target, TRAIT_RELAYING_ATTACKER, REF(src)) /datum/element/relay_attackers/Detach(datum/source, ...) . = ..() @@ -30,6 +31,7 @@ COMSIG_ATOM_HULK_ATTACK, COMSIG_ATOM_ATTACK_MECH, )) + REMOVE_TRAIT(source, TRAIT_RELAYING_ATTACKER, REF(src)) /datum/element/relay_attackers/proc/after_attackby(atom/target, obj/item/weapon, mob/attacker) SIGNAL_HANDLER diff --git a/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_actions.dm b/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_actions.dm index 6f18856e790..609d80fc4df 100644 --- a/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_actions.dm +++ b/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_actions.dm @@ -54,6 +54,7 @@ var/static/list/mouse_commands = list( /datum/pet_command/idle, /datum/pet_command/free, + /datum/pet_command/protect_owner, /datum/pet_command/follow, /datum/pet_command/point_targetting/attack/mouse ) @@ -61,6 +62,7 @@ var/static/list/glockroach_commands = list( /datum/pet_command/idle, /datum/pet_command/free, + /datum/pet_command/protect_owner/glockroach, /datum/pet_command/follow, /datum/pet_command/point_targetting/attack/glockroach ) @@ -243,3 +245,6 @@ else if(prob(5)) C.vomit() return ..() + +/datum/pet_command/protect_owner/glockroach + protect_behavior = /datum/ai_planning_subtree/basic_ranged_attack_subtree/glockroach diff --git a/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_ai.dm b/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_ai.dm index 2a1db00b0e4..ef92c7b3b76 100644 --- a/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_ai.dm +++ b/code/modules/mob/living/basic/space_fauna/regal_rat/regal_rat_ai.dm @@ -1,7 +1,7 @@ /datum/ai_controller/basic_controller/regal_rat blackboard = list( BB_TARGETTING_DATUM = new /datum/targetting_datum/basic, - BB_BASIC_MOB_FLEEING = FALSE, + BB_BASIC_MOB_FLEEING = TRUE, BB_FLEE_TARGETTING_DATUM = new /datum/targetting_datum/basic/ignore_faction, ) @@ -13,7 +13,7 @@ planning_subtrees = list( /datum/ai_planning_subtree/target_retaliate/to_flee, /datum/ai_planning_subtree/targeted_mob_ability/riot, - /datum/ai_planning_subtree/flee_target, + /datum/ai_planning_subtree/flee_target/from_flee_key, /datum/ai_planning_subtree/attack_obstacle_in_path, /datum/ai_planning_subtree/basic_melee_attack_subtree, /datum/ai_planning_subtree/use_mob_ability/domain, @@ -22,6 +22,7 @@ /datum/ai_planning_subtree/targeted_mob_ability/riot target_key = BB_BASIC_MOB_FLEE_TARGET // we only want to trigger this when provoked, manpower is low nowadays ability_key = BB_RAISE_HORDE_ABILITY + finish_planning = FALSE /datum/ai_planning_subtree/use_mob_ability/domain ability_key = BB_DOMAIN_ABILITY