[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
🆑
fix: regal rats now run away from whoever attacked them
add: new pet behavior which makes pets defend their owners if they got
attacked
/🆑

* fixes regal rats not running away

---------

Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
This commit is contained in:
SkyratBot
2023-08-24 21:23:11 -04:00
committed by GitHub
co-authored by Ben10Omintrix
parent 1f04d51005
commit 6aa87c2456
5 changed files with 53 additions and 2 deletions
+3
View File
@@ -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"
@@ -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)
+2
View File
@@ -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
@@ -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
@@ -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