Skip to content

Commit

Permalink
Merge pull request #558 from FFXIV-CombatReborn/mergeWIP
Browse files Browse the repository at this point in the history
some LINQ removal
  • Loading branch information
CarnifexOptimus authored Jan 14, 2025
2 parents a6e3dfe + dc1edff commit ea6b975
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 42 deletions.
4 changes: 2 additions & 2 deletions BossMod/Components/Cleave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignme
if (actor != target)
hints.AddForbiddenZone(Shape, origin.Position, angle, NextExpected);
else
AddTargetSpecificHints(actor, origin, angle, hints);
AddTargetSpecificHints(actor, origin, hints);
}

private void AddTargetSpecificHints(Actor actor, Actor source, Angle angle, AIHints hints)
private void AddTargetSpecificHints(Actor actor, Actor source, AIHints hints)
{
foreach (var a in Raid.WithoutSlot().Exclude(actor))
switch (Shape)
Expand Down
48 changes: 39 additions & 9 deletions BossMod/Components/Exaflare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,52 @@ public class Line
public uint FutureColor = Colors.AOE;
public readonly List<Line> Lines = [];

public bool Active => Lines.Count > 0;
public bool Active => Lines.Count != 0;

public Exaflare(BossModule module, float radius, ActionID aid = new()) : this(module, new AOEShapeCircle(radius), aid) { }

public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
foreach (var (c, t, r) in FutureAOEs())
yield return new(Shape, c, r, t, FutureColor);
foreach (var (c, t, r) in ImminentAOEs())
yield return new(Shape, c, r, t, ImminentColor);
var linesCount = Lines.Count;
if (linesCount == 0)
return [];
var futureAOEs = FutureAOEs(linesCount);
var imminentAOEs = ImminentAOEs(linesCount);
var futureCount = futureAOEs.Count;
var imminentCount = imminentAOEs.Count;

List<AOEInstance> aoes = new(futureCount + imminentCount);
for (var i = 0; i < futureCount; ++i)
{
var aoe = futureAOEs[i];
aoes.Add(new(Shape, aoe.Item1, aoe.Item3, aoe.Item2, FutureColor));
}

for (var i = 0; i < imminentCount; ++i)
{
var aoe = imminentAOEs[i];
aoes.Add(new(Shape, aoe.Item1, aoe.Item3, aoe.Item2, ImminentColor));
}
return aoes;
}

protected IEnumerable<(WPos, DateTime, Angle)> ImminentAOEs() => Lines.Where(l => l.ExplosionsLeft > 0).Select(l => (l.Next, l.NextExplosion, l.Rotation));
protected List<(WPos, DateTime, Angle)> ImminentAOEs(int count)
{
var exas = new List<(WPos, DateTime, Angle)>(count);

for (var i = 0; i < count; ++i)
{
var l = Lines[i];
if (l.ExplosionsLeft != 0)
exas.Add((l.Next, l.NextExplosion, l.Rotation));
}
return exas;
}

protected IEnumerable<(WPos, DateTime, Angle)> FutureAOEs()
protected List<(WPos, DateTime, Angle)> FutureAOEs(int count)
{
for (var i = 0; i < Lines.Count; ++i)
var exas = new List<(WPos, DateTime, Angle)>(count);
for (var i = 0; i < count; ++i)
{
var l = Lines[i];
var num = Math.Min(l.ExplosionsLeft, l.MaxShownExplosions);
Expand All @@ -45,9 +74,10 @@ public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
pos += l.Advance;
time = time.AddSeconds(l.TimeToMove);
yield return (pos, time, l.Rotation);
exas.Add((pos, time, l.Rotation));
}
}
return exas;
}

protected void AdvanceLine(Line l, WPos pos)
Expand Down
2 changes: 1 addition & 1 deletion BossMod/Components/LineOfSightAOE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void AddHints(int slot, Actor actor, TextHints hints)
public override void OnCastStarted(Actor caster, ActorCastInfo spell)
{
if (spell.Action == WatchedAction)
AddSafezone(Module.CastFinishAt(spell), caster.Rotation);
AddSafezone(Module.CastFinishAt(spell), spell.Rotation);
}

public void AddSafezone(DateTime activation, Angle rotation = default)
Expand Down
39 changes: 34 additions & 5 deletions BossMod/Components/PersistentVoidzone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ public class PersistentVoidzone(BossModule module, float radius, Func<BossModule

public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
return Sources(Module).Select(s => new AOEInstance(Shape, s.Position, s.Rotation));
var aoes = new List<AOEInstance>();
foreach (var source in Sources(Module))
{
aoes.Add(new(Shape, source.Position, source.Rotation));
}
return aoes;
}

public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignment assignment, AIHints hints)
Expand All @@ -21,7 +26,19 @@ public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignme
var forbidden = new List<Func<WPos, float>>();
foreach (var s in Sources(Module))
forbidden.Add(Shape.Distance(s.Position, s.Rotation));
hints.AddForbiddenZone(p => forbidden.Min(f => f(p)));
hints.AddForbiddenZone(minDistanceFunc);

float minDistanceFunc(WPos pos)
{
var minDistance = float.MaxValue;
for (var i = 0; i < forbidden.Count; ++i)
{
var distance = forbidden[i](pos);
if (distance < minDistance)
minDistance = distance;
}
return minDistance;
}
}
}

Expand Down Expand Up @@ -98,14 +115,26 @@ public override void AddHints(int slot, Actor actor, TextHints hints)

public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignment assignment, AIHints hints)
{
var shapes = Sources(Module).Select(s => Shape.Distance(s.Position, s.Rotation)).ToList();
var shapes = new List<Func<WPos, float>>();

foreach (var source in Sources(Module))
{
var shape = Shape.Distance(source.Position, source.Rotation);
shapes.Add(shape);
}
if (shapes.Count == 0)
return;

float distance(WPos p)
{
var dist = shapes.Select(s => s(p)).Min();
return Inverted ? -dist : dist;
var minDistance = float.MaxValue;
for (var i = 0; i < shapes.Count; ++i)
{
var distance = shapes[i](p);
if (distance < minDistance)
minDistance = distance;
}
return Inverted ? -minDistance : minDistance;
}
hints.AddForbiddenZone(distance, InvertResolveAt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
if (Casters.Count == 0)
yield break;
return [];

var reaver = Module.FindComponent<CrossReaver>();
var check = _aoe != null && _aoe.Casters.Count != 0;
var check2 = reaver != null && reaver.Casters.Count != 0;

yield return Casters[0] with { Color = check2 ? Colors.Danger : Colors.AOE, Risky = !check };
return [Casters[0] with { Color = check2 ? Colors.Danger : Colors.AOE, Risky = !check }];
}
}

Expand All @@ -41,9 +41,9 @@ public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
if (Casters.Count == 0)
yield break;
return [];
var chain = Module.FindComponent<LightsChain>();
var check = chain != null && chain.Casters.Count != 0;
yield return Casters[0] with { Risky = !check };
return [Casters[0] with { Risky = !check }];
}
}
15 changes: 12 additions & 3 deletions BossMod/Modules/Dawntrail/Alliance/A14ShadowLord/UmbraSmash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ namespace BossMod.Dawntrail.Alliance.A14ShadowLord;
private static readonly HashSet<AID> casts = [AID.UmbraSmashAOE1, AID.UmbraSmashAOE2, AID.UmbraSmashAOE3, AID.UmbraSmashAOE4, AID.UmbraSmashAOEClone];
public override void AddAIHints(int slot, Actor actor, PartyRolesConfig.Assignment assignment, AIHints hints)
{
var linesCount = Lines.Count;
if (linesCount == 0)
return;

var imminentAOEs = ImminentAOEs(linesCount);

// use only imminent aoes for hints
foreach (var (c, t, r) in ImminentAOEs())
hints.AddForbiddenZone(Shape, c, r, t);
for (var i = 0; i < imminentAOEs.Count; ++i)
{
var aoe = imminentAOEs[i];
hints.AddForbiddenZone(Shape, aoe.Item1, aoe.Item3, aoe.Item2);
}
}

public override void OnCastStarted(Actor caster, ActorCastInfo spell)
{
if ((AID)spell.Action.ID is AID.UmbraSmashAOE1 or AID.UmbraSmashAOE2 or AID.UmbraSmashAOE3 or AID.UmbraSmashAOE4 or AID.UmbraSmashAOEClone)
{
var dir = spell.Rotation.ToDirection();
var origin = spell.LocXZ + 30 * dir;
var origin = caster.Position + 30 * dir;
Lines.Add(new() { Next = origin, Advance = 5 * dir.OrthoL(), Rotation = spell.Rotation + 90.Degrees(), NextExplosion = Module.CastFinishAt(spell), TimeToMove = 2.3f, ExplosionsLeft = 6, MaxShownExplosions = 2 });
Lines.Add(new() { Next = origin, Advance = 5 * dir.OrthoR(), Rotation = spell.Rotation - 90.Degrees(), NextExplosion = Module.CastFinishAt(spell), TimeToMove = 2.3f, ExplosionsLeft = 6, MaxShownExplosions = 2 });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public override void OnCastStarted(Actor caster, ActorCastInfo spell)
{
var advance1 = spell.Rotation.ToDirection().OrthoR() * 7.5f;
var advance2 = spell.Rotation.ToDirection().OrthoR() * 5;
Lines.Add(new() { Next = spell.LocXZ + advance1, Advance = advance2, Rotation = spell.Rotation, NextExplosion = Module.CastFinishAt(spell), TimeToMove = 2, ExplosionsLeft = 5, MaxShownExplosions = 2 });
Lines.Add(new() { Next = spell.LocXZ - advance1, Advance = -advance2, Rotation = (spell.Rotation + 180.Degrees()).Normalized(), NextExplosion = Module.CastFinishAt(spell), TimeToMove = 2, ExplosionsLeft = 5, MaxShownExplosions = 2 });
var pos = caster.Position;
Lines.Add(new() { Next = pos + advance1, Advance = advance2, Rotation = spell.Rotation, NextExplosion = Module.CastFinishAt(spell), TimeToMove = 2, ExplosionsLeft = 5, MaxShownExplosions = 2 });
Lines.Add(new() { Next = pos - advance1, Advance = -advance2, Rotation = (spell.Rotation + 180.Degrees()).Normalized(), NextExplosion = Module.CastFinishAt(spell), TimeToMove = 2, ExplosionsLeft = 5, MaxShownExplosions = 2 });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void OnCastStarted(Actor caster, ActorCastInfo spell)
if ((AID)spell.Action.ID is AID.NUpwellFirst or AID.SUpwellFirst)
{
var advance = spell.Rotation.ToDirection().OrthoR() * 5;
var pos = spell.LocXZ;
var pos = caster.Position;
var activation = Module.CastFinishAt(spell);
_lines.Add(new() { NextOrigin = pos, Advance = advance, Rotation = spell.Rotation, NextActivation = activation, NextShape = _shapeWide });
_lines.Add(new() { NextOrigin = pos, Advance = -advance, Rotation = (spell.Rotation + 180.Degrees()).Normalized(), NextActivation = activation });
Expand Down
31 changes: 24 additions & 7 deletions BossMod/Modules/Endwalker/Variant/V02MR/V022Moko/Upwell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,37 @@ class UpwellFirst : Components.SimpleAOEs
{
public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
var linesCount = Lines.Count;
if (linesCount == 0)
return [];
var futureAOEs = FutureAOEs(linesCount);
var imminentAOEs = ImminentAOEs(linesCount);
var futureCount = futureAOEs.Count;
var imminentCount = imminentAOEs.Count;
var imminentDeadline = WorldState.FutureTime(5);
foreach (var (c, t, r) in FutureAOEs())
if (t <= imminentDeadline)
yield return new(Shape, c, r, t, FutureColor);
foreach (var (c, t, r) in ImminentAOEs())
if (t <= imminentDeadline)
yield return new(Shape, c, r, t, ImminentColor);

List<AOEInstance> aoes = new(futureCount + imminentCount);
for (var i = 0; i < futureCount; ++i)
{
var aoe = futureAOEs[i];
if (aoe.Item2 <= imminentDeadline)
aoes.Add(new(Shape, aoe.Item1, aoe.Item3, aoe.Item2, FutureColor));
}

for (var i = 0; i < imminentCount; ++i)
{
var aoe = imminentAOEs[i];
if (aoe.Item2 <= imminentDeadline)
aoes.Add(new(Shape, aoe.Item1, aoe.Item3, aoe.Item2, ImminentColor));
}
return aoes;
}

public override void OnCastStarted(Actor caster, ActorCastInfo spell)
{
if ((AID)spell.Action.ID == AID.UpwellFirst)
{
var pos = spell.LocXZ;
var pos = caster.Position;
var check = pos.AlmostEqual(Arena.Center, 1);
var isNorth = pos.Z == 530;
var isSouth = pos.Z == 550;
Expand Down
33 changes: 25 additions & 8 deletions BossMod/Modules/Shadowbringers/Dungeon/D01Holminster/D013Philia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,31 @@ class FierceBeating(BossModule module) : Components.Exaflare(module, 4)

public override IEnumerable<AOEInstance> ActiveAOEs(int slot, Actor actor)
{
foreach (var (c, t, r) in FutureAOEs())
yield return new(Shape, c, r, t, FutureColor);
foreach (var (c, t, r) in ImminentAOEs())
yield return new(Shape, c, r, t, ImminentColor);
if (Lines.Count > 0 && linesstartedcount1 < 8)
yield return new(circle, WPos.RotateAroundOrigin(linesstartedcount1 * 45, D013Philia.ArenaCenter, _casters[0]), default, _activation.AddSeconds(linesstartedcount1 * 3.7f));
if (Lines.Count > 1 && linesstartedcount2 < 8)
yield return new(circle, WPos.RotateAroundOrigin(linesstartedcount2 * 45, D013Philia.ArenaCenter, _casters[1]), default, _activation.AddSeconds(linesstartedcount2 * 3.7f));
var linesCount = Lines.Count;
if (linesCount == 0)
return [];
var futureAOEs = FutureAOEs(linesCount);
var imminentAOEs = ImminentAOEs(linesCount);
var futureCount = futureAOEs.Count;
var imminentCount = imminentAOEs.Count;

List<AOEInstance> aoes = new(futureCount + imminentCount + 2);
for (var i = 0; i < futureCount; ++i)
{
var aoe = futureAOEs[i];
aoes.Add(new(Shape, aoe.Item1, aoe.Item3, aoe.Item2, FutureColor));
}

for (var i = 0; i < imminentCount; ++i)
{
var aoe = imminentAOEs[i];
aoes.Add(new(Shape, aoe.Item1, aoe.Item3, aoe.Item2, ImminentColor));
}
if (linesstartedcount1 < 8)
aoes.Add(new(circle, WPos.RotateAroundOrigin(linesstartedcount1 * 45, D013Philia.ArenaCenter, _casters[0]), default, _activation.AddSeconds(linesstartedcount1 * 3.7f)));
if (linesCount > 1 && linesstartedcount2 < 8)
aoes.Add(new(circle, WPos.RotateAroundOrigin(linesstartedcount2 * 45, D013Philia.ArenaCenter, _casters[1]), default, _activation.AddSeconds(linesstartedcount2 * 3.7f)));
return aoes;
}

public override void Update()
Expand Down

0 comments on commit ea6b975

Please sign in to comment.