2 using Microsoft.Xna.Framework;
23 private const float WaitTimeBeforeRepair = 0.5f;
24 private float waitTimer;
27 private readonly
bool isPriority;
35 this.isPriority = isPriority;
64 float distanceFactor = 1;
71 bool isSelected = IsRepairing();
72 float selectedBonus = isSelected ? 100 -
MaxDevotion : 0;
74 float reduction = isPriority ? 1 : isSelected ? 2 : 3;
76 float highestWeight = -1;
81 highestWeight = weight;
84 if (highestWeight == -1)
89 Priority = MathHelper.Lerp(0, max, MathHelper.Clamp(devotion + (severity * distanceFactor * highestWeight *
PriorityModifier), 0, 1));
104 protected override void Act(
float deltaTime)
125 getItemObjective.Abandoned += () =>
character.
Speak(TextManager.Get(
"dialogcannotfindrequireditemtorepair").Value,
null, 0.0f,
"dialogcannotfindrequireditemtorepair".ToIdentifier(), 10.0f);
134 if (repairTool ==
null)
138 if (repairTool !=
null)
145 DebugConsole.ThrowError($
"{character.Name}: AIObjectiveRepairItem failed - the item \"{repairTool}\" has no proper inventory.");
152 foreach (
RelatedItem requiredItem
in requiredItems)
156 if (fuel !=
null) {
break; }
160 RemoveSubObjective(ref goToObjective);
163 RemoveExisting = true
165 onCompleted: () => RemoveSubObjective(ref refuelObjective),
166 onAbandon: () =>
Abandon =
true);
173 waitTimer += deltaTime;
174 if (waitTimer < WaitTimeBeforeRepair) {
return; }
178 bool repairThroughRepairInterface =
false;
194 repairThroughRepairInterface =
true;
201 CheckPreviousCondition(deltaTime);
217 repairThroughRepairInterface =
true;
222 if (!repairThroughRepairInterface && repairTool !=
null && !
Abandon)
224 OperateRepairTool(deltaTime);
230 RemoveSubObjective(ref refuelObjective);
232 TryAddSubObjective(ref goToObjective,
238 SpeakCannotReachCondition = () => isPriority
240 if (repairTool !=
null)
257 private const float conditionCheckDelay = 1;
258 private float conditionCheckTimer;
259 private float previousCondition;
260 private void CheckPreviousCondition(
float deltaTime)
263 conditionCheckTimer -= deltaTime;
264 if (conditionCheckTimer > 0) {
return; }
265 conditionCheckTimer = conditionCheckDelay;
266 if (previousCondition > -1 &&
Item.
Condition < previousCondition)
278 private void FindRepairTool()
284 foreach (RelatedItem requiredItem
in kvp.Value)
288 if (requiredItem.MatchesItem(item))
298 private void OperateRepairTool(
float deltaTime)
310 if (fromToolToTarget.LengthSquared() < MathUtils.Pow(repairTool.
Range / 2, 2))
319 if (VectorExtensions.Angle(VectorExtensions.Forward(repairTool.
Item.
body.
TransformedRotation), fromToolToTarget) < MathHelper.PiOver4)
328 goToObjective =
null;
329 refuelObjective =
null;
SteeringManager SteeringManager
void FaceTarget(ISpatialEntity target)
static float CalculateReach(RepairTool repairTool, Character character)
float Priority
Final priority value after all calculations.
readonly Character character
virtual float MaxDevotion
readonly List< AIObjective > subObjectives
readonly AIObjectiveManager objectiveManager
static float GetDistanceFactor(Vector2 selfPos, Vector2 targetWorldPos, float factorAtMaxDistance, float verticalDistanceMultiplier=3, float maxDistance=10000.0f, float factorAtMinDistance=1.0f)
Get a normalized value representing how close the target position is. The value is a rough estimation...
const float LowestOrderPriority
Maximum priority of an order given to the character (rightmost order in the crew list)
override bool KeepDivingGearOn
static bool IsRepairing(Character character, Item item)
override bool AllowInFriendlySubs
override void Act(float deltaTime)
override Identifier Identifier
override bool CheckObjectiveState()
Should return whether the objective is completed or not.
override float GetPriority()
AIObjectiveRepairItem(Character character, Item item, AIObjectiveManager objectiveManager, float priorityModifier=1, bool isPriority=false)
override bool AllowWhileHandcuffed
const float RequiredSuccessFactor
override float GetTargetPriority()
Returns a priority value based on the current targets (e.g. high prio when there's lots of severe fir...
void SetInput(InputType inputType, bool hit, bool held)
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)
virtual AIController AIController
override Vector2? SimPosition
Item????????? SelectedItem
The primary selected item. It can be any device that character interacts with. This excludes items li...
CharacterInventory Inventory
bool IsItemRepairedByAnother(Item target, out Character other)
virtual IEnumerable< Item > AllItems
All items contained in the inventory. Stacked items are returned as individual instances....
override Vector2? SimPosition
ItemInventory OwnInventory
List< Repairable > Repairables
override Vector2? Position
bool IgnoreByAI(Character character)
bool TryInteract(Character user, bool ignoreRequiredItems=false, bool forceSelectKey=false, bool forceUseKey=false)
bool? IsClaimedByBallastFlora
bool RequireAimToUse
If true, the user has to hold the "aim" key before use is registered. False by default.
override string Name
Note that this is not a LocalizedString instance, just the current name of the item as a string....
override ImmutableHashSet< Identifier > Tags
virtual bool HasRequiredItems(Character character, bool addMessage, LocalizedString msg=null)
float DegreeOfSuccess(Character character)
Returns 0.0f-1.0f based on how well the Character can use the itemcomponent
Dictionary< RelatedItem.RelationType, List< RelatedItem > > RequiredItems
bool StopRepairing(Character character)
bool StartRepairing(Character character, FixActions action)
static IReadOnlyDictionary< Identifier, float > ItemRepairPriorities
Tag -> priority.
float TransformedRotation
Takes flipping (Dir) into account.
void SteeringManual(float deltaTime, Vector2 velocity)
override Vector2? Position