From e5a7d5bb1b5fb7cdadede25164a41b87de9edd15 Mon Sep 17 00:00:00 2001 From: Garume <80187947+Garume@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:31:33 +0900 Subject: [PATCH] Add lazer aoe (#225) * [add] lazer aoe * [fix] refactoring * Update P3 Ultimate Relativity.cs --------- Co-authored-by: Limiana <5073202+Limiana@users.noreply.github.com> --- .../P3 Ultimate Relativity.cs | 328 +++++++++++------- 1 file changed, 205 insertions(+), 123 deletions(-) diff --git a/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P3 Ultimate Relativity.cs b/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P3 Ultimate Relativity.cs index 7a15294d..6c80e924 100644 --- a/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P3 Ultimate Relativity.cs +++ b/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P3 Ultimate Relativity.cs @@ -12,6 +12,7 @@ using ECommons.DalamudServices; using ECommons.GameFunctions; using ECommons.GameHelpers; +using ECommons.Hooks.ActionEffectTypes; using ECommons.ImGuiMethods; using ECommons.Logging; using ECommons.MathHelpers; @@ -31,17 +32,6 @@ public enum Clockwise CounterClockwise } - public enum Debuff : uint - { - Holy = 0x996, - Fire = 0x997, - ShadowEye = 0x998, - Eruption = 0x99C, - DarkWater = 0x99D, - Blizzard = 0x99E, - Return = 0x9A0 - } - public enum Direction { East = 0, @@ -62,37 +52,12 @@ public enum KindFire Blizzard } - public enum MarkerType : uint - { - Attack1 = 0, - Attack2 = 1, - Attack3 = 2, - Bind1 = 5, - Bind2 = 6, - Bind3 = 7, - Ignore1 = 8, - Ignore2 = 9 - } - public enum Mode { Marker, Priority } - public enum State - { - None, - Start, - FirstFire, - BaitEarlyHourglass, - SecondFire, - BaitNoTetherHourglass, - ThirdFire, - BaitLateHourglass, - End - } - private readonly List _earlyHourglassList = []; private readonly Dictionary _hourglasses = new(); @@ -104,17 +69,27 @@ public enum State private Direction? _baseDirection; + private bool _showSinboundMeltdown; + private State _state = State.None; public override HashSet? ValidTerritories => [1238]; - public override Metadata? Metadata => new(4, "Garume"); + public override Metadata? Metadata => new(5, "Garume"); - public Config C => Controller.GetConfig(); + private Config C => Controller.GetConfig(); public override void OnStartingCast(uint source, uint castId) { if (_state == State.End) return; if (castId == 40266) _state = State.Start; + if (castId == 40291) _showSinboundMeltdown = true; + } + + public override void OnActionEffectEvent(ActionEffectSet set) + { + if (_state == State.End || set.Action == null) return; + var castId = set.Action.Value.RowId; + if (castId is 40291 or 40235) _showSinboundMeltdown = false; } public override void OnTetherCreate(uint source, uint target, uint data2, uint data3, uint data5) @@ -145,7 +120,7 @@ public override void OnTetherCreate(uint source, uint target, uint data2, uint d } } - public Direction GetDirection(Vector3 position) + private static Direction GetDirection(Vector3 position) { var isNorth = position.Z < 95f; var isEast = position.X > 105f; @@ -391,7 +366,7 @@ public override void OnRemoveBuffEffect(uint sourceId, Status Status) }; } - public void BaitHourglass(Direction direction) + private void BaitHourglass(Direction direction) { if (_baseDirection == null) return; var basedDirection = (Direction)(((int)direction + (int)_baseDirection.Value + 90) % 360); @@ -412,7 +387,7 @@ public void BaitHourglass(Direction direction) } } - public void GoCenter(Direction direction, float radius = 2f) + private void GoCenter(Direction direction, float radius = 2f) { if (_baseDirection == null) return; var center = new Vector2(100f, 100f); @@ -424,9 +399,9 @@ public void GoCenter(Direction direction, float radius = 2f) } } - public void GoNearCenter(Direction direction) + private void GoNearCenter(Direction direction) { - var radius = 1f; + const float radius = 1f; if (_baseDirection == null) return; var basedDirection = (Direction)(((int)direction + (int)_baseDirection.Value + 90) % 360); var center = new Vector2(100, 100); @@ -442,9 +417,9 @@ public void GoNearCenter(Direction direction) } } - public void GoOutside(Direction direction) + private void GoOutside(Direction direction) { - var radius = 18f; + const float radius = 18f; if (_baseDirection == null) return; var basedDirection = (Direction)(((int)direction + (int)_baseDirection.Value + 90) % 360); var center = new Vector2(100, 100); @@ -460,7 +435,7 @@ public void GoOutside(Direction direction) } } - public void PlaceReturnToHourglass(Direction direction, float radius) + private void PlaceReturnToHourglass(Direction direction, float radius) { if (_baseDirection == null) return; var basedDirection = (Direction)(((int)direction + (int)_baseDirection.Value + 90) % 360); @@ -477,21 +452,77 @@ public void PlaceReturnToHourglass(Direction direction, float radius) } } - public void PlaceReturnToHourglass(Direction direction) + private void PlaceReturnToHourglass(Direction direction) { PlaceReturnToHourglass(direction, 10f); } - public void PlaceReturnToHourglassOutside(Direction direction) + private void PlaceReturnToHourglassOutside(Direction direction) { PlaceReturnToHourglass(direction, 11f); } - public void PlaceReturnToHourglassInside(Direction direction) + private void PlaceReturnToHourglassInside(Direction direction) { PlaceReturnToHourglass(direction, 8f); } + private void ShowSinboundMeltdown() + { + var hourGlassesList = Svc.Objects + .Where(x => x is IBattleNpc npc && npc is { CastActionId: 40291, IsCasting: true }).ToList(); + if (!hourGlassesList.Any()) return; + PluginLog.Information($"hourGlassesList.Count(): {hourGlassesList.Count()}"); + + var pcs = FakeParty.Get().ToList(); + if (pcs.Count != 8) return; + + var i = 0; + foreach (var hourglass in hourGlassesList) + { + // Search for the closest player + var closestPlayer = pcs.MinBy(x => Vector3.Distance(x.Position, hourglass.Position)); + + // Show Element + if (Controller.TryGetElementByName($"SinboundMeltdown{i}", out var element) && closestPlayer != null) + { + var extPos = GetExtendedAndClampedPosition(hourglass.Position, closestPlayer.Position, 20f, 20f); + element.SetRefPosition(hourglass.Position); + element.SetOffPosition(extPos); + element.Enabled = true; + i++; + } + } + } + + public void HideSinboundMeltdown() + { + for (var i = 0; i < 3; ++i) + if (Controller.TryGetElementByName($"SinboundMeltdown{i}", out var element)) + element.Enabled = false; + } + + private static Vector3 GetExtendedAndClampedPosition(Vector3 center, Vector3 currentPos, float extensionLength, + float? limit) + { + // Calculate the normalized direction vector from the center to the current position + var direction = Vector3.Normalize(currentPos - center); + + // Extend the position by the specified length + var extendedPos = currentPos + direction * extensionLength; + + // If limit is null, return the extended position without clamping + if (!limit.HasValue) return extendedPos; + + // Calculate the distance from the center to the extended position + var distanceFromCenter = Vector3.Distance(center, extendedPos); + + // If the extended position exceeds the limit, clamp it within the limit + if (distanceFromCenter > limit.Value) return center + direction * limit.Value; + + // If within the limit, return the extended position as is + return extendedPos; + } public override void OnSetup() { @@ -513,11 +544,24 @@ public override void OnSetup() overlayVOffset = 5f, radius = 0f }); + + for (var i = 0; i < 3; ++i) + { + var element = new Element(2) + { + thicc = 2f, + radius = 2.5f, + fillIntensity = 0.25f, + Filled = true + }; + Controller.RegisterElement($"SinboundMeltdown{i}", element); + } } public override void OnReset() { _state = State.None; + _showSinboundMeltdown = false; _playerDatas.Clear(); _hourglasses.Clear(); _baseDirection = null; @@ -653,77 +697,77 @@ public override void OnActorControl(uint sourceId, uint command, uint p1, uint p uint p6, ulong targetId, byte replaying) { - if (_state is not (State.None or State.End)) - if (command == 502) - { - var player = Svc.Objects.FirstOrDefault(x => x.GameObjectId == p2); - if (player == null) PluginLog.Warning("Error: Cannot find player"); + if (_state is State.None or State.End) return; + if (command == 502) + { + var player = Svc.Objects.FirstOrDefault(x => x.GameObjectId == p2); + if (player == null) PluginLog.Warning("Error: Cannot find player"); - _playerDatas[p2] = p1 switch + _playerDatas[p2] = p1 switch + { + (uint)MarkerType.Attack1 => new PlayerData { - (uint)MarkerType.Attack1 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Early, - Number = 1, - Direction = SwapAsOrientation(C.Attack1Direction) - }, - (uint)MarkerType.Attack2 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Early, - Number = 2, - Direction = SwapAsOrientation(C.Attack2Direction) - }, - (uint)MarkerType.Attack3 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Early, - Number = 3, - Direction = SwapAsOrientation(C.Attack3Direction) - }, - (uint)MarkerType.Bind1 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Late, - Number = 1, - Direction = SwapAsOrientation(C.Bind1Direction) - }, - (uint)MarkerType.Bind2 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Late, - Number = 2, - Direction = SwapAsOrientation(C.Bind2Direction) - }, - (uint)MarkerType.Bind3 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Late, - Number = 3, - Direction = SwapAsOrientation(C.Bind3Direction) - }, - (uint)MarkerType.Ignore1 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Middle, - Number = 1, - Direction = SwapAsOrientation(C.Ignore1Direction) - }, - (uint)MarkerType.Ignore2 => new PlayerData - { - PlayerName = player?.Name.ToString(), - KindFire = KindFire.Middle, - Number = 2, - Direction = SwapAsOrientation(C.Ignore2Direction) - }, - _ => _playerDatas[p2] - }; - - if (player is IPlayerCharacter playerCharacter && - playerCharacter.StatusList.Any(x => x.StatusId == (uint)Debuff.Blizzard)) - _playerDatas[p2].KindFire = KindFire.Blizzard; - } + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Early, + Number = 1, + Direction = SwapAsOrientation(C.Attack1Direction) + }, + (uint)MarkerType.Attack2 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Early, + Number = 2, + Direction = SwapAsOrientation(C.Attack2Direction) + }, + (uint)MarkerType.Attack3 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Early, + Number = 3, + Direction = SwapAsOrientation(C.Attack3Direction) + }, + (uint)MarkerType.Bind1 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Late, + Number = 1, + Direction = SwapAsOrientation(C.Bind1Direction) + }, + (uint)MarkerType.Bind2 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Late, + Number = 2, + Direction = SwapAsOrientation(C.Bind2Direction) + }, + (uint)MarkerType.Bind3 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Late, + Number = 3, + Direction = SwapAsOrientation(C.Bind3Direction) + }, + (uint)MarkerType.Ignore1 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Middle, + Number = 1, + Direction = SwapAsOrientation(C.Ignore1Direction) + }, + (uint)MarkerType.Ignore2 => new PlayerData + { + PlayerName = player?.Name.ToString(), + KindFire = KindFire.Middle, + Number = 2, + Direction = SwapAsOrientation(C.Ignore2Direction) + }, + _ => _playerDatas[p2] + }; + + if (player is IPlayerCharacter playerCharacter && + playerCharacter.StatusList.Any(x => x.StatusId == (uint)Debuff.Blizzard)) + _playerDatas[p2].KindFire = KindFire.Blizzard; + } } @@ -863,9 +907,11 @@ public override void OnUpdate() element.overlayText = C.LookOutsideText.Get(); } } + + if (_showSinboundMeltdown) ShowSinboundMeltdown(); } - public KindFire GetKindFire(StatusList statuses) + private static KindFire GetKindFire(StatusList statuses) { foreach (var status in statuses) switch (status.StatusId) @@ -887,13 +933,49 @@ public KindFire GetKindFire(StatusList statuses) return KindFire.Early; } - public record Hourglass + private enum Debuff : uint + { + Holy = 0x996, + Fire = 0x997, + ShadowEye = 0x998, + Eruption = 0x99C, + DarkWater = 0x99D, + Blizzard = 0x99E, + Return = 0x9A0 + } + + private enum MarkerType : uint + { + Attack1 = 0, + Attack2 = 1, + Attack3 = 2, + Bind1 = 5, + Bind2 = 6, + Bind3 = 7, + Ignore1 = 8, + Ignore2 = 9 + } + + private enum State + { + None, + Start, + FirstFire, + BaitEarlyHourglass, + SecondFire, + BaitNoTetherHourglass, + ThirdFire, + BaitLateHourglass, + End + } + + private record Hourglass { public Clockwise Clockwise { get; init; } public Direction Direction { get; init; } } - public record PlayerData + private record PlayerData { public string? PlayerName { init; get; } public KindFire KindFire { set; get; } @@ -906,7 +988,7 @@ public override int GetHashCode() } } - public class Config : IEzConfig + private class Config : IEzConfig { public Direction Attack1Direction = Direction.NorthWest; public Direction Attack2Direction = Direction.NorthEast; @@ -936,4 +1018,4 @@ public class Config : IEzConfig public bool ShowOther; public Vector2 WaitRange = new(0.5f, 1.5f); } -} \ No newline at end of file +}