v1.5.7.0 (Summer Update)

This commit is contained in:
Regalis11
2024-06-18 16:49:51 +03:00
parent 4a63dacbce
commit 230d1b6e78
263 changed files with 7792 additions and 2845 deletions
@@ -8,8 +8,8 @@ namespace Barotrauma
class AIObjectiveCheckStolenItems : AIObjective
{
public override Identifier Identifier { get; set; } = "check stolen items".ToIdentifier();
public override bool AllowOutsideSubmarine => false;
public override bool AllowInAnySub => false;
protected override bool AllowOutsideSubmarine => false;
protected override bool AllowInAnySub => false;
public float FindStolenItemsProbability = 1.0f;
@@ -21,36 +21,38 @@ namespace Barotrauma
Done
}
private float inspectDelay;
private float warnDelay;
private const float InspectTime = 5.0f;
private const float NormalWarnDelay = 5.0f;
private const float CriminalWarnDelay = 3.0f;
private float inspectTimer;
private float warnTimer;
private float currentWarnDelay;
private State currentState;
public readonly Character TargetCharacter;
public readonly Character Target;
private AIObjectiveGoTo? goToObjective;
private readonly List<Item> stolenItems = new List<Item>();
public AIObjectiveCheckStolenItems(Character character, Character targetCharacter, AIObjectiveManager objectiveManager, float priorityModifier = 1) :
public AIObjectiveCheckStolenItems(Character character, Character target, AIObjectiveManager objectiveManager, float priorityModifier = 1) :
base(character, objectiveManager, priorityModifier)
{
TargetCharacter = targetCharacter;
inspectDelay = 5.0f;
warnDelay = 5.0f;
}
public override bool IsLoop
{
get => false;
set => throw new Exception("Trying to set the value for IsLoop from: " + Environment.StackTrace.CleanupStackTrace());
Target = target;
InitTimers();
}
protected override bool CheckObjectiveSpecific() => false;
protected override float GetPriority()
{
if (!Abandon && !IsCompleted && objectiveManager.IsOrder(this))
if (character.IsClimbing)
{
// Target is climbing -> stop following the objective (soft abandon, without ignoring the target).
Priority = 0;
}
else if (!Abandon && !IsCompleted && objectiveManager.IsOrder(this))
{
Priority = objectiveManager.GetOrderPriority(this);
}
@@ -70,22 +72,32 @@ namespace Barotrauma
{
switch (currentState)
{
case State.Done:
IsCompleted = true;
break;
case State.GotoTarget:
TryAddSubObjective(ref goToObjective,
constructor: () =>
constructor: () => new AIObjectiveGoTo(Target, character, objectiveManager, repeat: false)
{
return new AIObjectiveGoTo(TargetCharacter, character, objectiveManager, repeat: false)
{
SpeakIfFails = false
};
SpeakIfFails = false
},
onCompleted: () =>
{
RemoveSubObjective(ref goToObjective);
currentState = State.Inspect;
stolenItems.Clear();
TargetCharacter.Inventory.FindAllItems(it => it.SpawnedInCurrentOutpost && !it.AllowStealing, recursive: true, stolenItems);
character.Speak(TextManager.Get("dialogcheckstolenitems").Value);
if (character.IsClimbing)
{
// Shouldn't start inspecting characters when they climb, nor get here, because the priority should be 0,
// but if this still happens, we'll have to abandon the objective
// because it's not currently possible to hold to characters and ladders at the same time.
Abandon = true;
}
else
{
currentState = State.Inspect;
stolenItems.Clear();
Target.Inventory.FindAllItems(it => it.Illegitimate, recursive: true, stolenItems);
character.Speak(TextManager.Get(Target.IsCriminal ? "dialogcheckstolenitems.criminal" : "dialogcheckstolenitems").Value);
}
},
onAbandon: () =>
{
@@ -103,10 +115,23 @@ namespace Barotrauma
private void Inspect(float deltaTime)
{
if (inspectDelay > 0.0f)
if (inspectTimer > 0.0f)
{
character.SelectCharacter(TargetCharacter);
inspectDelay -= deltaTime;
character.SelectCharacter(Target);
inspectTimer -= deltaTime;
if (inspectTimer < InspectTime - 1)
{
if (Target.AnimController.IsMovingFast)
{
ArrestFleeing();
}
else if (Math.Abs(Target.AnimController.TargetMovement.X) > 1.0f)
{
// If the target moves, reset the inspect timer and tell to hold still
character.Speak(TextManager.Get("dialogcheckstolenitems.holdstill").Value, identifier: "holdstill".ToIdentifier(), minDurationBetweenSimilar: 3f);
inspectTimer = InspectTime;
}
}
return;
}
@@ -118,7 +143,7 @@ namespace Barotrauma
}
else
{
character.Speak(TextManager.Get("dialogcheckstolenitems.nostolenitems").Value);
character.Speak(TextManager.Get(Target.IsCriminal ? "dialogcheckstolenitems.nostolenitems.criminal" : "dialogcheckstolenitems.nostolenitems").Value);
currentState = State.Done;
IsCompleted = true;
}
@@ -127,16 +152,23 @@ namespace Barotrauma
private void Warn(float deltaTime)
{
if (warnDelay > 0.0f)
if (warnTimer > 0.0f)
{
warnDelay -= deltaTime;
warnTimer -= deltaTime;
if (warnTimer < currentWarnDelay - 1)
{
if (Target.AnimController.IsMovingFast)
{
ArrestFleeing();
}
}
return;
}
var stolenItemsOnCharacter = stolenItems.Where(it => it.GetRootInventoryOwner() == TargetCharacter);
var stolenItemsOnCharacter = stolenItems.Where(it => it.GetRootInventoryOwner() == Target);
if (stolenItemsOnCharacter.Any())
{
character.Speak(TextManager.Get("dialogcheckstolenitems.arrest").Value);
HumanAIController.AddCombatObjective(AIObjectiveCombat.CombatMode.Arrest, TargetCharacter);
character.Speak(TextManager.Get(character.IsCriminal ? "dialogcheckstolenitems.arrest.criminal" : "dialogcheckstolenitems.arrest").Value);
Arrest(abortWhenItemsDropped: true, allowHoldFire: true);
foreach (var stolenItem in stolenItemsOnCharacter)
{
HumanAIController.ApplyStealingReputationLoss(stolenItem);
@@ -156,5 +188,44 @@ namespace Barotrauma
currentState = State.Done;
IsCompleted = true;
}
private void ArrestFleeing()
{
character.Speak(TextManager.Get("dialogcheckstolenitems.arrest").Value);
currentState = State.Done;
IsCompleted = true;
Arrest(abortWhenItemsDropped: false, allowHoldFire: false);
}
private void Arrest(bool abortWhenItemsDropped, bool allowHoldFire)
{
bool isCriminal = Target.IsCriminal;
Func<AIObjective, bool>? abortCondition = null;
if (abortWhenItemsDropped && !isCriminal)
{
abortCondition = obj => Target.Inventory.FindItem(it => it.Illegitimate, recursive: true) == null;
}
HumanAIController.AddCombatObjective(AIObjectiveCombat.CombatMode.Arrest, Target, allowHoldFire: allowHoldFire && !isCriminal, speakWarnings: !isCriminal, abortCondition: abortCondition);
}
public override void OnDeselected()
{
base.OnDeselected();
character.DeselectCharacter();
}
public override void Reset()
{
base.Reset();
currentState = State.GotoTarget;
InitTimers();
}
private void InitTimers()
{
inspectTimer = InspectTime;
currentWarnDelay = Target.IsCriminal ? CriminalWarnDelay : NormalWarnDelay;
warnTimer = currentWarnDelay;
}
}
}