Skip to content

Commit

Permalink
navigation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CarnifexOptimus committed Dec 8, 2024
1 parent 869aba1 commit b9e17cd
Show file tree
Hide file tree
Showing 41 changed files with 108 additions and 118 deletions.
2 changes: 2 additions & 0 deletions BossMod/AI/AIBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ public void DrawDebug()
configModified |= ImGui.Checkbox("Follow out of combat", ref _config.FollowOutOfCombat);
ImGui.SameLine();
configModified |= ImGui.Checkbox("Follow target", ref _config.FollowTarget);
ImGui.SameLine();
configModified |= ImGui.Checkbox("Allow outside bounds", ref _config.AllowAIToBeOutsideBounds);

if (configModified)
_config.Modified.Fire();
Expand Down
3 changes: 3 additions & 0 deletions BossMod/AI/AIConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ sealed class AIConfig : ConfigNode
[PropertyDisplay("Auto AFK timer", tooltip: "Time in seconds out of combat until AFK mode enables. Any movement will reset timer or disable AFK mode if already active.")]
public float AFKModeTimer = 10;

[PropertyDisplay("Allow AI to be out of pathfinding map bounds")]
public bool AllowAIToBeOutsideBounds = false;

public string? AIAutorotPresetName;
}
12 changes: 8 additions & 4 deletions BossMod/BossModule/AOEShapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public enum OperandType
public sealed record class AOEShapeCustom(IEnumerable<Shape> Shapes1, IEnumerable<Shape>? DifferenceShapes = null, IEnumerable<Shape>? Shapes2 = null, bool InvertForbiddenZone = false, OperandType Operand = OperandType.Union, WPos Origin = default) : AOEShape
{
private RelSimplifiedComplexPolygon? polygon;
private PolygonWithHolesDistanceFunction? shapeDistance;
private readonly int hashkey = CreateCacheKey(Shapes1, Shapes2 ?? [], DifferenceShapes ?? [], Operand, Origin);
public static readonly Dictionary<int, RelSimplifiedComplexPolygon> Cache = [];
public static readonly LinkedList<int> CacheOrder = new();
Expand Down Expand Up @@ -304,20 +305,23 @@ public override void Outline(MiniArena arena, WPos origin, Angle rotation, uint

public override Func<WPos, float> Distance(WPos origin, Angle rotation)
{
var shapeDistance = new PolygonWithHolesDistanceFunction(origin, polygon ?? GetCombinedPolygon(origin)).Distance;
return InvertForbiddenZone ? p => -shapeDistance(p) : shapeDistance;
shapeDistance ??= new PolygonWithHolesDistanceFunction(origin, polygon ?? GetCombinedPolygon(origin));
var dis = shapeDistance.Value.Distance;
return InvertForbiddenZone ? p => -dis(p) : dis;
}
}

public sealed record class AOEShapeCustomAlt(RelSimplifiedComplexPolygon Poly, Angle DirectionOffset = default, bool InvertForbiddenZone = false) : AOEShape
{
private PolygonWithHolesDistanceFunction? shapeDistance;
public override string ToString() => $"Custom: off={DirectionOffset}, ifz={InvertForbiddenZone}";
public override bool Check(WPos position, WPos origin, Angle rotation) => Poly.Contains((position - origin).Rotate(-rotation - DirectionOffset));
public override void Draw(MiniArena arena, WPos origin, Angle rotation, uint color = 0) => arena.ZoneComplex(origin, rotation + DirectionOffset, Poly, color);
public override void Outline(MiniArena arena, WPos origin, Angle rotation, uint color = 0) => arena.AddComplexPolygon(origin, (rotation + DirectionOffset).ToDirection(), Poly, color);
public override Func<WPos, float> Distance(WPos origin, Angle rotation)
{
var shapeDistance = new PolygonWithHolesDistanceFunction(origin, Poly).Distance;
return InvertForbiddenZone ? p => -shapeDistance(p) : shapeDistance;
shapeDistance ??= new PolygonWithHolesDistanceFunction(origin, Poly);
var dis = shapeDistance.Value.Distance;
return InvertForbiddenZone ? p => -dis(p) : dis;
}
}
6 changes: 3 additions & 3 deletions BossMod/BossModule/ArenaBounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void AddToInstanceCache(object key, object value)
}
}

public record class ArenaBoundsCircle(float Radius, float MapResolution = ArenaBounds.Half) : ArenaBounds(Radius, MapResolution)
public sealed record class ArenaBoundsCircle(float Radius, float MapResolution = ArenaBounds.Half) : ArenaBounds(Radius, MapResolution)
{
private Pathfinding.Map? _cachedMap;

Expand Down Expand Up @@ -170,7 +170,7 @@ public override WDir ClampToBounds(WDir offset)
}
}

public record class ArenaBoundsSquare(float Radius, Angle Rotation = default, float MapResolution = ArenaBounds.Half) : ArenaBoundsRect(Radius, Radius, Rotation, MapResolution) { }
public sealed record class ArenaBoundsSquare(float Radius, Angle Rotation = default, float MapResolution = ArenaBounds.Half) : ArenaBoundsRect(Radius, Radius, Rotation, MapResolution) { }

// custom complex polygon bounds
public record class ArenaBoundsCustom : ArenaBounds
Expand Down Expand Up @@ -336,7 +336,7 @@ private Pathfinding.Map BuildMap()
// for creating complex bounds by using two IEnumerable of shapes
// first IEnumerable contains platforms that will be united, second optional IEnumberale contains shapes that will be subtracted
// for convenience third list will optionally perform additional unions at the end
public record class ArenaBoundsComplex : ArenaBoundsCustom
public sealed record class ArenaBoundsComplex : ArenaBoundsCustom
{
public readonly WPos Center;
public ArenaBoundsComplex(Shape[] UnionShapes, Shape[]? DifferenceShapes = null, Shape[]? AdditionalShapes = null, float MapResolution = Half, float Offset = 0)
Expand Down
28 changes: 14 additions & 14 deletions BossMod/BossModule/Shapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract record class Shape
public RelSimplifiedComplexPolygon ToPolygon(WPos center) => new((List<RelPolygonWithHoles>)[new(Contour(center))]);
}

public record class Circle(WPos Center, float Radius) : Shape
public sealed record class Circle(WPos Center, float Radius) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand All @@ -29,7 +29,7 @@ public override List<WDir> Contour(WPos center)
}

// for custom polygons defined by an IEnumerable of vertices
public record class PolygonCustom(IEnumerable<WPos> Vertices) : Shape
public sealed record class PolygonCustom(IEnumerable<WPos> Vertices) : Shape
{
private readonly WPos[] points = [.. Vertices];
public override List<WDir> Contour(WPos center)
Expand All @@ -56,7 +56,7 @@ public override string ToString()
}

// for custom polygons defined by an IEnumerable of vertices with an offset, eg to account for hitbox radius
public record class PolygonCustomO(IEnumerable<WPos> Vertices, float Offset) : Shape
public sealed record class PolygonCustomO(IEnumerable<WPos> Vertices, float Offset) : Shape
{
private readonly WPos[] points = [.. Vertices];
private Path64? path;
Expand Down Expand Up @@ -106,7 +106,7 @@ public override string ToString()
}
}

public record class Donut(WPos Center, float InnerRadius, float OuterRadius) : Shape
public sealed record class Donut(WPos Center, float InnerRadius, float OuterRadius) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand Down Expand Up @@ -149,16 +149,16 @@ public override List<WDir> Contour(WPos center)
}

// for rectangles defined by a start point, end point and halfwidth
public record class RectangleSE(WPos Start, WPos End, float HalfWidth) : Rectangle(
public sealed record class RectangleSE(WPos Start, WPos End, float HalfWidth) : Rectangle(
Center: new((Start.X + End.X) * Half, (Start.Z + End.Z) * Half),
HalfWidth: HalfWidth,
HalfHeight: (End - Start).Length() * Half,
Rotation: new Angle(MathF.Atan2(End.Z - Start.Z, End.X - Start.X)) + 90.Degrees()
);

public record class Square(WPos Center, float HalfSize, Angle Rotation = default) : Rectangle(Center, HalfSize, HalfSize, Rotation);
public sealed record class Square(WPos Center, float HalfSize, Angle Rotation = default) : Rectangle(Center, HalfSize, HalfSize, Rotation);

public record class Cross(WPos Center, float Length, float HalfWidth, Angle Rotation = default) : Shape
public sealed record class Cross(WPos Center, float Length, float HalfWidth, Angle Rotation = default) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand Down Expand Up @@ -197,7 +197,7 @@ public override List<WDir> Contour(WPos center)
}

// Equilateral triangle defined by center, sidelength and rotation
public record class TriangleE(WPos Center, float SideLength, Angle Rotation = default) : Shape
public sealed record class TriangleE(WPos Center, float SideLength, Angle Rotation = default) : Shape
{
private static readonly float heightFactor = MathF.Sqrt(3) * Half;

Expand Down Expand Up @@ -230,7 +230,7 @@ public override List<WDir> Contour(WPos center)
}

// for polygons with edge count number of lines of symmetry, eg. pentagons, hexagons and octagons
public record class Polygon(WPos Center, float Radius, int Edges, Angle Rotation = default) : Shape
public sealed record class Polygon(WPos Center, float Radius, int Edges, Angle Rotation = default) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand Down Expand Up @@ -279,7 +279,7 @@ public override List<WDir> Contour(WPos center)
}

// for cones defined by radius, direction and half angle
public record class ConeHA(WPos Center, float Radius, Angle CenterDir, Angle HalfAngle) : Cone(Center, Radius, CenterDir - HalfAngle, CenterDir + HalfAngle);
public sealed record class ConeHA(WPos Center, float Radius, Angle CenterDir, Angle HalfAngle) : Cone(Center, Radius, CenterDir - HalfAngle, CenterDir + HalfAngle);

// for donut segments defined by inner and outer radius, direction, start angle and end angle
public record class DonutSegment(WPos Center, float InnerRadius, float OuterRadius, Angle StartAngle, Angle EndAngle) : Shape
Expand All @@ -300,11 +300,11 @@ public override List<WDir> Contour(WPos center)
}

// for donut segments defined by inner and outer radius, direction and half angle
public record class DonutSegmentHA(WPos Center, float InnerRadius, float OuterRadius, Angle CenterDir, Angle HalfAngle) : DonutSegment(Center, InnerRadius, OuterRadius,
public sealed record class DonutSegmentHA(WPos Center, float InnerRadius, float OuterRadius, Angle CenterDir, Angle HalfAngle) : DonutSegment(Center, InnerRadius, OuterRadius,
CenterDir - HalfAngle, CenterDir + HalfAngle);

// Approximates a cone with a customizable number of edges for the circle arc
public record class ConeV(WPos Center, float Radius, Angle CenterDir, Angle HalfAngle, int Edges) : Shape
public sealed record class ConeV(WPos Center, float Radius, Angle CenterDir, Angle HalfAngle, int Edges) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand Down Expand Up @@ -333,7 +333,7 @@ public override List<WDir> Contour(WPos center)
}

// Approximates a donut segment with a customizable number of edges per circle arc
public record class DonutSegmentV(WPos Center, float InnerRadius, float OuterRadius, Angle CenterDir, Angle HalfAngle, int Edges) : Shape
public sealed record class DonutSegmentV(WPos Center, float InnerRadius, float OuterRadius, Angle CenterDir, Angle HalfAngle, int Edges) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand Down Expand Up @@ -366,7 +366,7 @@ public override List<WDir> Contour(WPos center)
public override string ToString() => $"DonutSegmentV:{Center.X},{Center.Z},{InnerRadius},{OuterRadius},{CenterDir},{HalfAngle},{Edges}";
}

public record class DonutV(WPos Center, float InnerRadius, float OuterRadius, int Edges) : Shape
public sealed record class DonutV(WPos Center, float InnerRadius, float OuterRadius, int Edges) : Shape
{
public override List<WDir> Contour(WPos center)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public A13ArkAngelsStates(A13ArkAngels module) : base(module)
{
_module = module;
DeathPhase(0, SinglePhase)
.ActivateOnEnter<Components.StayInBounds>()
.Raw.Update = () => module.Enemies(A13ArkAngels.Bosses).All(x => x.IsDeadOrDestroyed);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ class TeraSlash(BossModule module) : Components.CastCounter(module, ActionID.Mak
class DoomArc(BossModule module) : Components.RaidwideCast(module, ActionID.MakeSpell(AID.DoomArc));
class UnbridledRage(BossModule module) : Components.BaitAwayIcon(module, new AOEShapeRect(100, 4), (uint)IconID.UnbridledRage, ActionID.MakeSpell(AID.UnbridledRageAOE), 5.9f);
class DarkNova(BossModule module) : Components.SpreadFromCastTargets(module, ActionID.MakeSpell(AID.DarkNova), 6);
public class StayInBounds(BossModule module) : BossComponent(module)
{
public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignment assignment, AIHints hints)
{
if (!Arena.InBounds(actor.Position))
hints.AddForbiddenZone(ShapeDistance.InvertedDonut(Arena.Center, 11, 12));
}
}

[ModuleInfo(BossModuleInfo.Maturity.Verified, Contributors = "The Combat Reborn Team (Malediktus, LTS)", GroupType = BossModuleInfo.GroupType.CFC, GroupID = 1015, NameID = 13653, SortOrder = 8)]
public class A14ShadowLord(WorldState ws, Actor primary) : BossModule(ws, primary, ArenaCenter, DefaultBounds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public A14ShadowLordStates(BossModule module) : base(module)
// these timelines seem to not work correctly, too much variations, possibly also depends on raid DPS
// DeathPhase(0, SinglePhase);
TrivialPhase()
.ActivateOnEnter<StayInBounds>()
.ActivateOnEnter<UmbraSmash>()
.ActivateOnEnter<Implosion>()
.ActivateOnEnter<GigaSlash>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ class D023GurfurlurStates : StateMachineBuilder
public D023GurfurlurStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<HeavingHaymakerArenaChange>()
.ActivateOnEnter<HeavingHaymaker>()
.ActivateOnEnter<Whirlwind>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ public enum AID : uint
Ashlayer = 36712 // Helper->self, no cast, range 60 circle
}

class StayInBounds(BossModule module) : BossComponent(module)
{
private static readonly WDir offset = new(0, 19);

public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignment assignment, AIHints hints)
{
hints.AddForbiddenZone(ShapeDistance.InvertedRect(Arena.Center + offset, Arena.Center - offset, 19));
}
}

class Stonecarver(BossModule module) : Components.GenericAOEs(module)
{
private readonly List<AOEInstance> _aoes = [];
Expand Down Expand Up @@ -252,7 +242,6 @@ class D033MaulskullStates : StateMachineBuilder
public D033MaulskullStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<StayInBounds>()
.ActivateOnEnter<Stonecarver>()
.ActivateOnEnter<Impact1>()
.ActivateOnEnter<Impact2>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ class D071BarreltenderStates : StateMachineBuilder
public D071BarreltenderStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<HeavyweightNeedlesArenaChange>()
.ActivateOnEnter<NeedleStormSuperstormHeavyWeightNeedles>()
.ActivateOnEnter<PricklyRight>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ class D074GreatestSerpentOfTuralStates : StateMachineBuilder
public D074GreatestSerpentOfTuralStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<DubiousTulidisasterArenaChange>()
.ActivateOnEnter<DubiousTulidisaster>()
.ActivateOnEnter<ScreesOfFury>()
Expand Down
1 change: 0 additions & 1 deletion BossMod/Modules/Dawntrail/Quest/MSQ/TakingAStand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class TakingAStandStates : StateMachineBuilder
public TakingAStandStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<RoarArenaChange>()
.ActivateOnEnter<Roar1>()
.ActivateOnEnter<Roar2>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,4 @@ public override void OnEventEnvControl(byte index, uint state)
}
}
}

public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignment assignment, AIHints hints)
{
if (Arena.Bounds == DefaultBounds) // prevent AI from accidently leaving the arena
hints.AddForbiddenZone(ShapeDistance.InvertedRect(Module.Center + new WDir(0, 19.5f), Module.Center + new WDir(0, -19.5f), 19.5f));
else
hints.AddForbiddenZone(ShapeDistance.InvertedRect(Module.Center + new WDir(0, 19.5f), Module.Center + new WDir(0, -19.5f), 4.5f));
}
}
11 changes: 6 additions & 5 deletions BossMod/Modules/Dawntrail/Raid/M04NWickedThunder/WitchHunt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class WitchHunt(BossModule module) : Components.GenericAOEs(module)

public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
if (_aoes.Count > 0)
for (var i = 0; i < _aoes.Count / 2; ++i)
var count = _aoes.Count;
if (count > 0)
for (var i = 0; i < count / 2; ++i)
yield return _aoes[i] with { Color = Colors.Danger };
for (var i = _aoes.Count / 2; i < _aoes.Count; ++i)
yield return _aoes[i] with { Risky = _aoes.Count < 12 };
for (var i = count / 2; i < count; ++i)
yield return _aoes[i] with { Risky = count < 12 };
}

public override void OnCastStarted(Actor caster, ActorCastInfo spell)
Expand All @@ -22,7 +23,7 @@ public override void OnCastStarted(Actor caster, ActorCastInfo spell)

public override void OnEventCast(Actor caster, ActorCastEvent spell)
{
if (_aoes.Count > 0 && (AID)spell.Action.ID == AID.WitchHunt)
if (_aoes.Count != 0 && (AID)spell.Action.ID == AID.WitchHunt)
_aoes.RemoveAt(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class T02ZoraalJaP2States : StateMachineBuilder
public T02ZoraalJaP2States(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<DawnOfAnAgeArenaChange>()
.ActivateOnEnter<SmitingCircuitDonut>()
.ActivateOnEnter<SmitingCircuitCircle>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class D021BarnabasStates : StateMachineBuilder
public D021BarnabasStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<ArenaChange>()
.ActivateOnEnter<Magnetism>()
.ActivateOnEnter<ElectromagneticRelease1>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class D032WreckerStates : StateMachineBuilder
public D032WreckerStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<QueerBubble>()
.ActivateOnEnter<AetherSprayWater>()
.ActivateOnEnter<AetherSprayWaterKB>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ class D033SvarbhanuStates : StateMachineBuilder
public D033SvarbhanuStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<ChaoticUndercurrent>()
.ActivateOnEnter<CosmicKissSpread>()
.ActivateOnEnter<CosmicKissCircle>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class D043HermesStates : StateMachineBuilder
public D043HermesStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<TrismegistosArenaChange>()
.ActivateOnEnter<TrueBraveryInterruptHint>()
.ActivateOnEnter<CosmicKiss>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class D062PeacekeeperStates : StateMachineBuilder
public D062PeacekeeperStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<DecimationArenaChange>()
.ActivateOnEnter<ElectromagneticRepellant>()
.ActivateOnEnter<InfantryDeterrent>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ class D093KapikuluStates : StateMachineBuilder
public D093KapikuluStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<BillowingBoltsArenaChange>()
.ActivateOnEnter<ManaExplosion>()
.ActivateOnEnter<BastingBlade>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ class D113CagnazzoStates : StateMachineBuilder
public D113CagnazzoStates(BossModule module) : base(module)
{
TrivialPhase()
.ActivateOnEnter<Components.StayInBounds>()
.ActivateOnEnter<StygianDelugeArenaChange>()
.ActivateOnEnter<Voidcleaver>()
.ActivateOnEnter<Lifescleaver>()
Expand Down
Loading

0 comments on commit b9e17cd

Please sign in to comment.