3 using System.Collections.Generic;
14 public Identifier
NPCTag {
get;
set; }
16 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Tag of the item to operate. If it's not something AI characters can or know how to operate, such as a cabinet or an engine, the NPC will just select it.")]
19 [
Serialize(
"Controller",
IsPropertySaveable.Yes, description:
"Name of the component to operate. For example, the Controller component of a periscope or the Reactor component of a nuclear reactor.")]
22 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Identifier of the option, if there are several ways the item can be operated. For example, \"powerup\" or \"shutdown\" when operating a reactor.")]
25 [
Serialize(
false,
IsPropertySaveable.Yes, description:
"Should the character equip the item before attempting to operate it (only valid if the item is equippable).")]
31 [
Serialize(-1,
IsPropertySaveable.Yes, description:
"Maximum number of NPCs the action can target. For example, you could only make a specific number of security officers man a periscope.")]
34 [
Serialize(100,
IsPropertySaveable.Yes, description:
"Priority of operating the item (0-100). Higher values will make the AI prefer operating the item over other orders (priority 60-70) or e.g. reacting to emergencies (priority 90).")]
37 [
Serialize(
true,
IsPropertySaveable.Yes, description:
"The event actions reset when a GoTo action makes the event jump to a different point. Should the NPC stop operating the item when the event resets?")]
40 private bool isFinished =
false;
44 private List<Character> affectedNpcs =
null;
45 private Item target =
null;
47 public override void Update(
float deltaTime)
49 if (isFinished) {
return; }
52 var nonSelectedItems = potentialTargets.Where(it => it.GetComponent<
Controller>()?.
User ==
null);
55 nonSelectedItems.Any() ?
56 nonSelectedItems.GetRandomUnsynced() :
57 potentialTargets.GetRandomUnsynced();
58 if (target ==
null) {
return; }
62 foreach (var npc
in affectedNpcs)
64 if (npc.Removed) {
continue; }
70 if (itemComponent ==
null)
72 DebugConsole.AddWarning($
"Error in NPCOperateItemAction: could not find the component \"{ItemComponentName}\" in item \"{target.Name}\".");
80 humanAiController.ObjectiveManager.AddObjective(newObjective);
81 humanAiController.ObjectiveManager.WaitTimer = 0.0f;
82 humanAiController.ObjectiveManager.Objectives.RemoveAll(o => o is
AIObjectiveGoTo gotoOjective);
87 foreach (var objective
in humanAiController.ObjectiveManager.Objectives)
91 objective.Abandon =
true;
113 foreach (var npc
in affectedNpcs)
115 if (npc.Removed || npc.AIController is not
HumanAIController humanAiController) {
continue; }
116 foreach (var operateItemObjective
in humanAiController.ObjectiveManager.GetActiveObjectives<
AIObjectiveOperateItem>())
118 if (operateItemObjective.Component.Item == target)
120 operateItemObjective.Abandon =
true;
132 return $
"{ToolBox.GetDebugSymbol(isFinished)} {nameof(AIObjectiveOperateItem)} -> (NPCTag: {NPCTag.ColorizeObject()}, TargetTag: {TargetTag.ColorizeObject()}, Operate: {Operate.ColorizeObject()})";
readonly ScriptedEvent ParentEvent
List< ItemComponent > Components
Makes an NPC select an item, and operate it if it's something AI characters can operate.
override bool IsFinished(ref string goTo)
Has the action finished.
Identifier ItemComponentName
override string ToDebugString()
Rich test to display in debugdraw
NPCOperateItemAction(ScriptedEvent parentEvent, ContentXElement element)
override void Update(float deltaTime)
IEnumerable< Entity > GetTargets(Identifier tag)