Faction Test 100.4.0.0

This commit is contained in:
Markus Isberg
2022-11-14 18:28:28 +02:00
parent 87426b68b2
commit c772b61fc1
412 changed files with 16984 additions and 5530 deletions
@@ -8,6 +8,12 @@ namespace Barotrauma
{
class TriggerAction : EventAction
{
public enum TriggerType
{
Inside,
Outside
}
[Serialize("", IsPropertySaveable.Yes, description: "Tag of the first entity that will be used for trigger checks.")]
public Identifier Target1Tag { get; set; }
@@ -23,7 +29,10 @@ namespace Barotrauma
[Serialize("", IsPropertySaveable.Yes, description: "Tag to apply to the second entity when the trigger check succeeds.")]
public Identifier ApplyToTarget2 { get; set; }
[Serialize(0.0f, IsPropertySaveable.Yes, description: "Range both entities must be within to activate the trigger.")]
[Serialize(TriggerType.Inside, IsPropertySaveable.Yes, description: "Determines if the targets must be inside or outside of the radius.")]
public TriggerType Type { get; set; }
[Serialize(0.0f, IsPropertySaveable.Yes, description: "Range to activate the trigger.")]
public float Radius { get; set; }
[Serialize(true, IsPropertySaveable.Yes, description: "If true, characters who are being targeted by some enemy cannot trigger the action.")]
@@ -38,6 +47,9 @@ namespace Barotrauma
[Serialize(false, IsPropertySaveable.Yes, description: "If true, the action can be triggered by interacting with any matching target (not just the 1st one).")]
public bool AllowMultipleTargets { get; set; }
[Serialize(false, IsPropertySaveable.Yes, description: "If true and using multiple targets, all targets must be inside/outside the radius.")]
public bool CheckAllTargets { get; set; }
private float distance;
public TriggerAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
@@ -57,6 +69,8 @@ namespace Barotrauma
public bool isRunning = false;
private readonly List<Either<Character, Item>> npcsOrItems = new List<Either<Character, Item>>();
private readonly List<(Entity e1, Entity e2)> triggerers = new List<(Entity e1, Entity e2)>();
public override void Update(float deltaTime)
{
@@ -66,18 +80,44 @@ namespace Barotrauma
var targets1 = ParentEvent.GetTargets(Target1Tag);
if (!targets1.Any()) { return; }
triggerers.Clear();
foreach (Entity e1 in targets1)
{
if (DisableInCombat && IsInCombat(e1)) { continue; }
if (DisableIfTargetIncapacitated && e1 is Character character1 && (character1.IsDead || character1.IsIncapacitated)) { continue; }
if (DisableInCombat && IsInCombat(e1))
{
if (CheckAllTargets)
{
return;
}
continue;
}
if (DisableIfTargetIncapacitated && e1 is Character character1 && (character1.IsDead || character1.IsIncapacitated))
{
if (CheckAllTargets)
{
return;
}
continue;
}
if (!TargetModuleType.IsEmpty)
{
if (IsCloseEnoughToHull(e1, out Hull hull))
if (!CheckAllTargets && CheckDistanceToHull(e1, out Hull hull))
{
Trigger(e1, hull);
return;
}
else if (CheckAllTargets)
{
if (CheckDistanceToHull(e1, out hull))
{
triggerers.Add((e1, hull));
}
else
{
return;
}
}
continue;
}
@@ -85,9 +125,26 @@ namespace Barotrauma
foreach (Entity e2 in targets2)
{
if (e1 == e2) { continue; }
if (DisableInCombat && IsInCombat(e2)) { continue; }
if (DisableIfTargetIncapacitated && e2 is Character character2 && (character2.IsDead || character2.IsIncapacitated)) { continue; }
if (e1 == e2)
{
continue;
}
if (DisableInCombat && IsInCombat(e2))
{
if (CheckAllTargets)
{
return;
}
continue;
}
if (DisableIfTargetIncapacitated && e2 is Character character2 && (character2.IsDead || character2.IsIncapacitated))
{
if (CheckAllTargets)
{
return;
}
continue;
}
if (WaitForInteraction)
{
@@ -173,16 +230,35 @@ namespace Barotrauma
Vector2 pos1 = e1.WorldPosition;
Vector2 pos2 = e2.WorldPosition;
distance = Vector2.Distance(pos1, pos2);
if (((e1 is MapEntity m1) && Submarine.RectContains(m1.WorldRect, pos2)) ||
((e2 is MapEntity m2) && Submarine.RectContains(m2.WorldRect, pos1)) ||
Vector2.DistanceSquared(pos1, pos2) < Radius * Radius)
if ((Type == TriggerType.Inside) == IsWithinRadius())
{
if (!CheckAllTargets)
{
Trigger(e1, e2);
return;
}
else
{
triggerers.Add((e1, e2));
}
}
else if (CheckAllTargets)
{
Trigger(e1, e2);
return;
}
bool IsWithinRadius() =>
((e1 is MapEntity m1) && Submarine.RectContains(m1.WorldRect, pos2)) ||
((e2 is MapEntity m2) && Submarine.RectContains(m2.WorldRect, pos1)) ||
Vector2.DistanceSquared(pos1, pos2) < Radius * Radius;
}
}
}
}
foreach (var (e1, e2) in triggerers)
{
Trigger(e1, e2);
}
}
private void ResetTargetIcons()
@@ -205,7 +281,7 @@ namespace Barotrauma
}
}
private bool IsCloseEnoughToHull(Entity e, out Hull hull)
private bool CheckDistanceToHull(Entity e, out Hull hull)
{
hull = null;
if (Radius <= 0)
@@ -213,36 +289,35 @@ namespace Barotrauma
if (e is Character character && character.CurrentHull != null && character.CurrentHull.OutpostModuleTags.Contains(TargetModuleType))
{
hull = character.CurrentHull;
return true;
return Type == TriggerType.Inside;
}
else if (e is Item item && item.CurrentHull != null && item.CurrentHull.OutpostModuleTags.Contains(TargetModuleType))
{
hull = item.CurrentHull;
return true;
return Type == TriggerType.Inside;
}
return false;
return Type == TriggerType.Outside;
}
else
{
foreach (Hull potentialHull in Hull.HullList)
{
if (!potentialHull.OutpostModuleTags.Contains(TargetModuleType)) { continue; }
Rectangle hullRect = potentialHull.WorldRect;
hullRect.Inflate(Radius, Radius);
if (Submarine.RectContains(hullRect, e.WorldPosition))
{
hull = potentialHull;
return true;
return Type == TriggerType.Inside;
}
}
return false;
return Type == TriggerType.Outside;
}
}
private bool IsInCombat(Entity entity)
private static bool IsInCombat(Entity entity)
{
if (!(entity is Character character)) { return false; }
if (entity is not Character character) { return false; }
foreach (Character c in Character.CharacterList)
{
if (c.IsDead || c.Removed || c.IsIncapacitated || !c.Enabled) { continue; }