1 using Microsoft.Xna.Framework;
2 using System.Collections.Generic;
15 [
Serialize(
false,
IsPropertySaveable.Yes, description:
"Did this NPC start the fight (as an aggressor)? Attacking instigators doesn't reduce reputation or trigger outpost security.")]
25 public Identifier
NPCTag {
get;
set; }
33 private bool isFinished =
false;
36 private IEnumerable<Character> affectedNpcs =
null;
40 public override void Update(
float deltaTime)
42 if (isFinished) {
return; }
46 foreach (var npc
in affectedNpcs)
48 if (npc.Removed) {
continue; }
52 float closestDist =
float.MaxValue;
55 if (target is not
Character character) {
continue; }
56 float dist = Vector2.DistanceSquared(npc.WorldPosition, target.
WorldPosition);
57 if (dist < closestDist)
63 if (enemy ==
null) {
continue; }
67 var objectiveManager = humanAiController.ObjectiveManager;
68 foreach (var goToObjective
in objectiveManager.GetActiveObjectives<
AIObjectiveGoTo>())
70 goToObjective.Abandon =
true;
84 if (affectedNpcs !=
null)
86 foreach (var npc
in affectedNpcs)
88 if (npc.Removed || npc.AIController is not
HumanAIController humanAiController) {
continue; }
89 foreach (var combatObjective
in humanAiController.ObjectiveManager.GetActiveObjectives<
AIObjectiveCombat>())
91 combatObjective.Abandon =
true;
101 return $
"{ToolBox.GetDebugSymbol(isFinished)} {nameof(CombatAction)} -> (Cooldown: {CoolDown.ColorizeObject()}, CombatMode: {CombatMode.ColorizeObject()}, NPCTag: {NPCTag.ColorizeObject()}, EnemyTag: {EnemyTag.ColorizeObject()})";
CombatAction CombatAction
Makes an NPC switch to a combat state (with options for different kinds of behaviors,...
AIObjectiveCombat.CombatMode WitnessReaction
override void Update(float deltaTime)
override bool IsFinished(ref string goTo)
Has the action finished.
AIObjectiveCombat.CombatMode GuardReaction
AIObjectiveCombat.CombatMode CombatMode
CombatAction(ScriptedEvent parentEvent, ContentXElement element)
override string ToDebugString()
Rich test to display in debugdraw
virtual Vector2 WorldPosition
readonly ScriptedEvent ParentEvent
IEnumerable< Entity > GetTargets(Identifier tag)