From b4e9ed66f8d979082346d3c207ea0daa728d3815 Mon Sep 17 00:00:00 2001 From: Garume <80187947+Garume@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:54:12 +0900 Subject: [PATCH] Add AutoTargetCrystal Script and fix bugs (#219) * [add] auto target crystal scripts * [fix] some bugs * [add] description about autotargetcrystal script --------- Co-authored-by: Limiana <5073202+Limiana@users.noreply.github.com> --- .../Phase 2 - Usurper of Frost.md | 6 +++ .../P2 AutoTargetCrystal.cs | 41 ++++++++++++++++ .../P3 Ultimate Relativity.cs | 47 ++++++++++++------- 3 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P2 AutoTargetCrystal.cs diff --git a/Presets/Dawntrail/Raids/Ultimate - The Futures Rewritten/Phase 2 - Usurper of Frost.md b/Presets/Dawntrail/Raids/Ultimate - The Futures Rewritten/Phase 2 - Usurper of Frost.md index 7641d26e..774c006b 100644 --- a/Presets/Dawntrail/Raids/Ultimate - The Futures Rewritten/Phase 2 - Usurper of Frost.md +++ b/Presets/Dawntrail/Raids/Ultimate - The Futures Rewritten/Phase 2 - Usurper of Frost.md @@ -56,6 +56,12 @@ D4 - D1 > D2 > D3 Thanks for Braum Oak +## [WIP] [Script] AutoTargetCrystal +Auto-targets nearest light crystal, then auto-targets the center crystal after all light crystals are destroyed. +No configuration needed. +``` +https://github.com/PunishXIV/Splatoon/raw/main/SplatoonScripts/Duties/Dawntrail/The%20Futures%20Rewritten/P2%20AutoTargetCrystal.cs +``` ## Flower-like explosions Will show after knockback, to not obstruct your view. Feel free to edit that out but good luck seeing anything... diff --git a/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P2 AutoTargetCrystal.cs b/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P2 AutoTargetCrystal.cs new file mode 100644 index 00000000..66f155fe --- /dev/null +++ b/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P2 AutoTargetCrystal.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using Dalamud.Game.ClientState.Objects.Types; +using ECommons.DalamudServices; +using ECommons.DalamudServices.Legacy; +using ECommons.GameHelpers; +using ECommons.Throttlers; +using ImGuiNET; +using Splatoon.SplatoonScripting; + +namespace SplatoonScriptsOfficial.Duties.Dawntrail.The_Futures_Rewritten; + +public class P2_AutoTargetCrystal : SplatoonScript +{ + public override HashSet? ValidTerritories => [1238]; + public override Metadata? Metadata => new(1, "Garume"); + + private IEnumerable LightCrystals => Svc.Objects.Where(x => x.DataId == 0x45A3).OfType(); + private IBattleNpc? IceCrystal => Svc.Objects.FirstOrDefault(x => x.DataId == 0x45A5) as IBattleNpc; + + public override void OnSettingsDraw() + { + ImGui.Text("Light Crystals"); + foreach (var crystal in LightCrystals) ImGui.Text(crystal.Name.ToString()); + } + + public override void OnUpdate() + { + if (EzThrottler.Throttle("AutoTargetCrystal", 200)) SetNearTarget(); + } + + private void SetNearTarget() + { + if (LightCrystals.Where(x => x.CurrentHp != 0) + .MinBy(x => Vector3.Distance(x.Position, Player.Position)) is { } target) + Svc.Targets.SetTarget(target); + else if (IceCrystal is { } ice) + Svc.Targets.SetTarget(ice); + } +} \ No newline at end of file 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 c1287dcf..7a15294d 100644 --- a/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P3 Ultimate Relativity.cs +++ b/SplatoonScripts/Duties/Dawntrail/The Futures Rewritten/P3 Ultimate Relativity.cs @@ -107,7 +107,7 @@ public enum State private State _state = State.None; public override HashSet? ValidTerritories => [1238]; - public override Metadata? Metadata => new(3, "Garume"); + public override Metadata? Metadata => new(4, "Garume"); public Config C => Controller.GetConfig(); @@ -364,7 +364,7 @@ public override void OnGainBuffEffect(uint sourceId, Status Status) var position = sourceId.GetObject()?.Position ?? throw new InvalidOperationException(); var direction = GetDirection(position); var basedDirection = (Direction)((int)direction - (int)_baseDirection.Value - 90); - if (basedDirection < 0) basedDirection += 360; + while (basedDirection < 0) basedDirection += 360; _hourglasses[basedDirection] = new Hourglass { Clockwise = clockwise, Direction = direction }; @@ -412,7 +412,7 @@ public void BaitHourglass(Direction direction) } } - public void GoCenter(Direction direction,float radius = 2f) + public void GoCenter(Direction direction, float radius = 2f) { if (_baseDirection == null) return; var center = new Vector2(100f, 100f); @@ -423,7 +423,7 @@ public void GoCenter(Direction direction,float radius = 2f) element.SetOffPosition(center.ToVector3(0f)); } } - + public void GoNearCenter(Direction direction) { var radius = 1f; @@ -460,7 +460,7 @@ public void GoOutside(Direction direction) } } - public void PlaceReturnToHourglass(Direction direction,float radius) + public void PlaceReturnToHourglass(Direction direction, float radius) { if (_baseDirection == null) return; var basedDirection = (Direction)(((int)direction + (int)_baseDirection.Value + 90) % 360); @@ -477,10 +477,20 @@ public void PlaceReturnToHourglass(Direction direction,float radius) } } - public void PlaceReturnToHourglass(Direction direction) => PlaceReturnToHourglass(direction, 10f); - - public void PlaceReturnToHourglassOutside(Direction direction) => PlaceReturnToHourglass(direction, 12f); - public void PlaceReturnToHourglassInside(Direction direction) => PlaceReturnToHourglass(direction, 8f); + public void PlaceReturnToHourglass(Direction direction) + { + PlaceReturnToHourglass(direction, 10f); + } + + public void PlaceReturnToHourglassOutside(Direction direction) + { + PlaceReturnToHourglass(direction, 11f); + } + + public void PlaceReturnToHourglassInside(Direction direction) + { + PlaceReturnToHourglass(direction, 8f); + } public override void OnSetup() @@ -732,9 +742,10 @@ public override void OnUpdate() x.Value.Enabled = C.ShowOther; }); - var myDirection = _playerDatas.First(x => x.Value.PlayerName == Player.Name).Value.Direction.ToString(); + var myDirection = _playerDatas.FirstOrDefault(x => x.Value.PlayerName == Player.Name).Value?.Direction + .ToString(); if (myDirection == null) return; - if (Controller.TryGetElementByName(myDirection!, out var myElement) && myElement.offX != 0f) + if (Controller.TryGetElementByName(myDirection, out var myElement) && myElement.offX != 0f) { myElement.color = GradientColor.Get(C.BaitColor1, C.BaitColor2).ToUint(); myElement.tether = true; @@ -749,7 +760,7 @@ public override void OnUpdate() GoCenter(Direction.SouthEast); if (_playerDatas.Any(x => x.Value is { KindFire: KindFire.Blizzard, Direction: Direction.South })) - GoCenter(Direction.South,1f); + GoCenter(Direction.South, 1f); else GoOutside(Direction.South); @@ -760,7 +771,7 @@ public override void OnUpdate() else if (_state == State.BaitEarlyHourglass) { BaitHourglass(Direction.North); - + var northEastPlayer = _playerDatas.FirstOrDefault(x => x.Value.Direction == Direction.East); if (FakeParty.Get().Where(x => x.Name.ToString() == northEastPlayer.Value.PlayerName) .Any(x => x.StatusList.Any(y => y.StatusId == (uint)Debuff.Eruption))) @@ -775,14 +786,14 @@ public override void OnUpdate() else PlaceReturnToHourglass(Direction.East); BaitHourglass(Direction.SouthEast); - + var southPlayer = _playerDatas.FirstOrDefault(x => x.Value.Direction == Direction.East); if (FakeParty.Get().Where(x => x.Name.ToString() == southPlayer.Value.PlayerName) .Any(x => x.StatusList.Any(y => y.StatusId == (uint)Debuff.Eruption))) PlaceReturnToHourglassOutside(Direction.South); else PlaceReturnToHourglassInside(Direction.South); - + BaitHourglass(Direction.SouthWest); var westPlayer = _playerDatas.FirstOrDefault(x => x.Value.Direction == Direction.West); @@ -791,7 +802,7 @@ public override void OnUpdate() GoNearCenter(Direction.West); else PlaceReturnToHourglass(Direction.West); - + var northWestPlayer = _playerDatas.FirstOrDefault(x => x.Value.Direction == Direction.NorthWest); if (FakeParty.Get().Where(x => x.Name.ToString() == northWestPlayer.Value.PlayerName) .Any(x => x.StatusList.Any(y => y.StatusId == (uint)Debuff.Eruption))) @@ -824,7 +835,7 @@ public override void OnUpdate() else if (_state == State.ThirdFire) { if (_playerDatas.Any(x => x.Value is { KindFire: KindFire.Blizzard, Direction: Direction.North })) - GoCenter(Direction.North,1f); + GoCenter(Direction.North, 1f); else GoOutside(Direction.North); @@ -925,4 +936,4 @@ public class Config : IEzConfig public bool ShowOther; public Vector2 WaitRange = new(0.5f, 1.5f); } -} +} \ No newline at end of file