2 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
12 public override string DebugTag => $
"{Identifier} {component.Name}";
21 private readonly
Entity operateTarget;
22 private readonly
bool requireEquip;
23 private readonly
bool useController;
39 public override bool CanBeCompleted => base.CanBeCompleted && (!useController || controller !=
null);
41 public override bool IsDuplicate<T>(T otherObjective) => base.IsDuplicate(otherObjective) && otherObjective is
AIObjectiveOperateItem operateObjective && operateObjective.component == component;
49 private bool isDoneOperating;
61 if (!isOrder && component.Item.ConditionPercentage <= 0)
77 if (targetItem ==
null)
80 DebugConsole.ThrowError(
"Item or component of AI Objective Operate item was null. This shouldn't happen.");
91 var reactor = component?.Item.GetComponent<
Reactor>();
103 switch (
Option.Value.ToLowerInvariant())
106 if (!reactor.PowerOn)
120 bool IsAnotherOrderTargetingSameItem(
AIObjective objective)
129 var steering = component?.Item.GetComponent<
Steering>();
142 || component.Item.IgnoreByAI(
character) || useController && controller.Item.IgnoreByAI(
character))
152 Priority = MathHelper.Clamp(value, 0, max);
158 if (reactor !=
null && reactor.PowerOn && reactor.FissionRate > 1 && reactor.AutoTemp &&
Option ==
"powerup")
163 Priority = MathHelper.Clamp(value, 0, max);
171 Entity operateTarget =
null,
bool useController =
false,
ItemComponent controller =
null,
float priorityModifier = 1)
174 component = item ??
throw new ArgumentNullException(
"item",
"Attempted to create an AIObjectiveOperateItem with a null target.");
175 this.requireEquip = requireEquip;
176 this.operateTarget = operateTarget;
177 this.useController = useController;
178 if (useController) { this.controller = controller ?? component?.Item?.FindController(); }
184 throw new Exception(
"target null");
187 else if (!target.Item.IsInteractable(
character))
193 protected override void Act(
float deltaTime)
201 if (useController && controller ==
null)
205 character.
Speak(TextManager.GetWithVariable(
"DialogCantFindController",
"[item]", component.Item.Name).Value, delay: 2.0f, identifier:
"cantfindcontroller".ToIdentifier(), minDurationBetweenSimilar: 30.0f);
210 if (operateTarget !=
null)
239 if (component.CrewAIOperate(deltaTime,
character,
this))
248 TargetName = target.Item.Name,
249 endNodeFilter = EndNodeFilter ?? AIObjectiveGetItem.CreateEndNodeFilter(target.Item)
251 onAbandon: () =>
Abandon =
true,
252 onCompleted: () => RemoveSubObjective(ref goToObjective));
257 if (component.Item.GetComponent<
Pickable>() ==
null)
266 onAbandon: () =>
Abandon =
true,
267 onCompleted: () => RemoveSubObjective(ref getItemObjective));
274 var holdable = component.Item.GetComponent<
Holdable>();
275 if (holdable ==
null)
278 DebugConsole.ThrowError($
"{character.Name}: AIObjectiveOperateItem failed - equipping item " + component.Item +
" is required but the item has no Holdable component");
290 if (existingItem !=
null)
293 if (!existingItem.AllowedSlots.Contains(
InvSlotType.Any) ||
307 if (component.CrewAIOperate(deltaTime,
character,
this))
320 goToObjective =
null;
321 getItemObjective =
null;
SteeringManager SteeringManager
void FaceTarget(ISpatialEntity target)
float Priority
Final priority value after all calculations.
readonly Character character
readonly Identifier Option
readonly AIObjectiveManager objectiveManager
AIObjective GetActiveObjective()
const float LowestOrderPriority
Maximum priority of an order given to the character (rightmost order in the crew list)
List< Order > CurrentOrders
float GetOrderPriority(AIObjective objective)
bool IsOrder(AIObjective objective)
override Identifier Identifier
override bool AllowAutomaticItemUnequipping
ItemComponent GetTarget()
override bool CanBeCompleted
override bool PrioritizeIfSubObjectivesActive
override bool AllowMultipleInstances
override bool IsDuplicate< T >(T otherObjective)
Func< PathNode, bool > EndNodeFilter
If undefined, a default filter will be used.
override float GetPriority()
override void Act(float deltaTime)
bool Repeat
When true, the operate objective is never completed, unless it's abandoned.
Func< bool > completionCondition
override bool AllowWhileHandcuffed
override bool CheckObjectiveState()
Should return whether the objective is completed or not.
override bool AllowInAnySub
AIObjectiveOperateItem(ItemComponent item, Character character, AIObjectiveManager objectiveManager, Identifier option, bool requireEquip, Entity operateTarget=null, bool useController=false, ItemComponent controller=null, float priorityModifier=1)
void Speak(string message, ChatMessageType? messageType=null, float delay=0.0f, Identifier identifier=default, float minDurationBetweenSimilar=0.0f)
bool CanInteractWith(Character c, float maxDist=200.0f, bool checkVisibility=true, bool skipDistanceCheck=false)
bool HasEquippedItem(Item item, InvSlotType? slotType=null, Func< InvSlotType, bool > predicate=null)
Item????????? SelectedItem
The primary selected item. It can be any device that character interacts with. This excludes items li...
static readonly List< Character > CharacterList
Character SelectedCharacter
CharacterInventory Inventory
Item SelectedSecondaryItem
The secondary selected item. It's an item other than a device (see SelectedItem), e....
override bool TryPutItem(Item item, Character user, IEnumerable< InvSlotType > allowedSlots=null, bool createNetworkEvent=true, bool ignoreCondition=false)
If there is room, puts the item in the inventory and returns true, otherwise returns false
InvSlotType[] SlotTypes
Slot type for each inventory slot. Vanilla package has one type for each slot, although it is technic...
List< FireSource > FireSources
static bool IsTrueForAnyBotInTheCrew(Character character, Func< HumanAIController, bool > predicate)
bool IsItemOperatedByAnother(ItemComponent target, out Character other)
static bool IsActive(Character c)
bool IsTrueForAnyCrewMember(Func< Character, bool > predicate, bool onlyActive=true, bool onlyConnectedSubs=false)
Including the player characters in the same team.
AIObjectiveManager ObjectiveManager
static bool IsFriendly(Character me, Character other, bool onlySameTeam=false)
bool Contains(Item item)
Is the item contained in this inventory. Does not recursively check items inside items.
Item GetItemAt(int index)
Get the item stored in the specified inventory slot. If the slot contains a stack of items,...
void Drop(Character dropper, bool createNetworkEvent=true, bool setTransform=true)
bool TryInteract(Character user, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceUseKey=false)
bool? IsClaimedByBallastFlora
The base class for components holding the different functionalities of the item