Skip to content

Commit

Permalink
Add AutoTargetCrystal Script and fix bugs (#219)
Browse files Browse the repository at this point in the history
* [add] auto target crystal scripts

* [fix] some bugs

* [add] description about autotargetcrystal script

---------

Co-authored-by: Limiana <[email protected]>
  • Loading branch information
Garume and Limiana authored Dec 3, 2024
1 parent 3ee243a commit b4e9ed6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
Original file line number Diff line number Diff line change
@@ -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<uint>? ValidTerritories => [1238];
public override Metadata? Metadata => new(1, "Garume");

private IEnumerable<IBattleNpc> LightCrystals => Svc.Objects.Where(x => x.DataId == 0x45A3).OfType<IBattleNpc>();
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public enum State
private State _state = State.None;

public override HashSet<uint>? ValidTerritories => [1238];
public override Metadata? Metadata => new(3, "Garume");
public override Metadata? Metadata => new(4, "Garume");

public Config C => Controller.GetConfig<Config>();

Expand Down Expand Up @@ -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 };

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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)))
Expand All @@ -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);
Expand All @@ -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)))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -925,4 +936,4 @@ public class Config : IEzConfig
public bool ShowOther;
public Vector2 WaitRange = new(0.5f, 1.5f);
}
}
}

0 comments on commit b4e9ed6

Please sign in to comment.