From d15d7ad31672820bc232996091ba013ce53ad6b5 Mon Sep 17 00:00:00 2001 From: GiR_Zippo Date: Wed, 17 Jul 2024 23:08:09 +0200 Subject: [PATCH] Add party leave --- .../GameFunctions/MovementFactory.cs | 9 ++---- HypnotoadPlugin/GameFunctions/Party.cs | 32 +++++++++++++++++-- HypnotoadPlugin/HypnotoadPlugin.csproj | 2 +- HypnotoadPlugin/IPC/IPCProvider.cs | 1 + 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/HypnotoadPlugin/GameFunctions/MovementFactory.cs b/HypnotoadPlugin/GameFunctions/MovementFactory.cs index a1513a0..eebd801 100644 --- a/HypnotoadPlugin/GameFunctions/MovementFactory.cs +++ b/HypnotoadPlugin/GameFunctions/MovementFactory.cs @@ -38,8 +38,6 @@ public void Initialize(Vector3 position, float rotation) { DesiredPosition = position; DesiredRotation = new Angle(rotation); - - Api.PluginLog.Debug(DesiredRotation.ToString()); } public Vector3 getVector3(string rString) @@ -70,9 +68,6 @@ public void Move() move.Precision = 0.05f; move.DesiredPosition = DesiredPosition; - //cam.DesiredAzimuth = DesiredRotation; - //cam.Enabled = true; - Api.Framework.RunOnTick(delegate { cancelMovementToken = new CancellationTokenSource(); @@ -132,7 +127,7 @@ private async Task RunMoveTask(CancellationToken token) else round = 4; //4 rounds until we give up - //check if we reached out position + //check if we reached our position var dist = move.DesiredPosition - Api.ClientState.LocalPlayer.Position; dist.Y = 0.0f; if (dist.LengthSquared() <= move.Precision * move.Precision) @@ -141,7 +136,7 @@ private async Task RunMoveTask(CancellationToken token) cam.Enabled = true; move.Enabled = false; - await Task.Delay(300, token).ContinueWith(static tsk => { }, token); + await Task.Delay(800, token).ContinueWith(static tsk => { }, token); cam.Enabled = false; break; } diff --git a/HypnotoadPlugin/GameFunctions/Party.cs b/HypnotoadPlugin/GameFunctions/Party.cs index 22d71f3..78f3fda 100644 --- a/HypnotoadPlugin/GameFunctions/Party.cs +++ b/HypnotoadPlugin/GameFunctions/Party.cs @@ -9,13 +9,21 @@ using FFXIVClientStructs.FFXIV.Client.Game.Object; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Info; +using HypnotoadPlugin.Offsets; using HypnotoadPlugin.Utils; using System; +using System.Threading; namespace HypnotoadPlugin.GameFunctions; public class Party : IDisposable { + public enum AcceptFlags + { + Accept_Teleport = 0b00000001, + Accept_GroupInv = 0b00000010, + } + private static readonly Lazy LazyInstance = new(static () => new Party()); private Party() @@ -25,6 +33,9 @@ private Party() private AutoSelect.AutoSelectYes YesNoAddon { get; set; } = null; + private byte AcceptLock { get; set; } = 0; + + public void Initialize() { YesNoAddon = new AutoSelect.AutoSelectYes(); @@ -36,11 +47,17 @@ public void Dispose() YesNoAddon = null; } + public bool IsAcceptFlagSet(AcceptFlags flag) => ((AcceptFlags)AcceptLock & flag) == flag; + + public void ClearFlags() => AcceptLock = 0; + + public void SetFlag(AcceptFlags flag) => AcceptLock |= (byte)flag; + public unsafe void PartyInvite(string message) { if (message == "") { - AcceptPartyInviteEnable(); + YesNoAddon.Enable(); return; } string character = message.Split(';')[0]; @@ -84,8 +101,19 @@ public unsafe void Teleport(bool showMenu) YesNoAddon.Enable(); } + public unsafe void PartyLeave() + { + YesNoAddon.Enable(); + + Api.Framework.RunOnTick(delegate + { + Chat.SendMessage("/leave"); + }, default(TimeSpan), 10, default(CancellationToken)); + } + public unsafe void AcceptDisable() { - YesNoAddon.Disable(); + //if (AcceptLock == 0) + YesNoAddon.Disable(); } } diff --git a/HypnotoadPlugin/HypnotoadPlugin.csproj b/HypnotoadPlugin/HypnotoadPlugin.csproj index e49e662..f7498dd 100644 --- a/HypnotoadPlugin/HypnotoadPlugin.csproj +++ b/HypnotoadPlugin/HypnotoadPlugin.csproj @@ -10,7 +10,7 @@ BardMusicPlayer & LightAmp companion for enhanced functionality. https://github.com/GiR-Zippo/Hypnotoad-Plugin - 0.0.1.36 + 0.0.1.37 diff --git a/HypnotoadPlugin/IPC/IPCProvider.cs b/HypnotoadPlugin/IPC/IPCProvider.cs index 627e21e..82998d9 100644 --- a/HypnotoadPlugin/IPC/IPCProvider.cs +++ b/HypnotoadPlugin/IPC/IPCProvider.cs @@ -23,6 +23,7 @@ public IPCProvider(Hypnotoad toad) Register("PartyInvite", (string data) => { Party.Instance.PartyInvite(data); }); Register("PartyInviteAccept", () => Party.Instance.AcceptPartyInviteEnable()); Register("PartySetLead", (string data) => Party.Instance.PromoteCharacter(data)); + Register("PartyLeave", () => Party.Instance.PartyLeave()); Register("PartyEnterHouse", () => Party.Instance.EnterHouse()); Register("PartyTeleport", (bool showMenu) => Party.Instance.Teleport(showMenu)); Register("PartyFollow", (string data) => FollowSystem.FollowCharacter(data.Split(';')[0], Convert.ToUInt16(data.Split(';')[1])));