diff --git a/RebornToolbox.sln.DotSettings.user b/RebornToolbox.sln.DotSettings.user index 0146692..e09602c 100644 --- a/RebornToolbox.sln.DotSettings.user +++ b/RebornToolbox.sln.DotSettings.user @@ -1,4 +1,5 @@  + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/RebornToolbox/Common/IpcSubscribers.cs b/RebornToolbox/Common/IpcSubscribers.cs index 833e167..280131d 100644 --- a/RebornToolbox/Common/IpcSubscribers.cs +++ b/RebornToolbox/Common/IpcSubscribers.cs @@ -226,12 +226,6 @@ internal static bool IsEnabled [EzIPC("AllaganTools.GetCharacterItemsByType", applyPrefix: false)] internal static readonly Func> GetCharacterItemsByType; - [EzIPC("AllaganTools.ItemAdded", applyPrefix: false)] - internal static readonly Func<(uint, InventoryItem.ItemFlags, ulong, uint), bool> ItemAdded; - - [EzIPC("AllaganTools.ItemRemoved", applyPrefix: false)] - internal static readonly Func<(uint, InventoryItem.ItemFlags, ulong, uint), bool> ItemRemoved; - [EzIPC("AllaganTools.GetCraftLists", applyPrefix: false)] internal static readonly Func> GetCraftLists; diff --git a/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs b/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs index 6f0e9e0..c766d2c 100644 --- a/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs +++ b/RebornToolbox/Features/MBShoppingList/MBShoppingList.cs @@ -1,13 +1,16 @@ using System.Numerics; using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Game.Inventory; using Dalamud.Game.Inventory.InventoryEventArgTypes; using Dalamud.Interface.Windowing; +using Dalamud.Plugin.Ipc; using ECommons; using ECommons.Automation; using ECommons.Automation.NeoTaskManager; using ECommons.Commands; using ECommons.DalamudServices; using ECommons.GameHelpers; +using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game.Control; using Lumina.Excel.GeneratedSheets; using Newtonsoft.Json; @@ -49,23 +52,32 @@ public MBShoppingList() TaskManager = new TaskManager(DefaultTaskConfig); LoadList(); - Svc.GameInventory.InventoryChanged += OnInventoryChanged; + _OnItemAdded = + Svc.PluginInterface.GetIpcSubscriber<(uint, InventoryItem.ItemFlags, ulong, uint), bool>( + "AllaganTools.ItemAdded"); + _OnItemRemoved = + Svc.PluginInterface.GetIpcSubscriber<(uint, InventoryItem.ItemFlags, ulong, uint), bool>( + "AllaganTools.ItemRemoved"); + + _OnItemAdded.Subscribe(OnItemAdded); } - private void OnInventoryChanged(IReadOnlyCollection events) + private static ICallGateSubscriber<(uint, InventoryItem.ItemFlags, ulong, uint), bool>? _OnItemAdded; + private static ICallGateSubscriber<(uint, InventoryItem.ItemFlags, ulong, uint), bool>? _OnItemRemoved; + + private void OnItemAdded((uint, InventoryItem.ItemFlags, ulong, uint) itemDetails) { - if (!Plugin.Configuration.ShoppingListConfig.RemoveQuantityAutomatically || !Plugin.Configuration.ShoppingListConfig.Enabled) + if (!Plugin.Configuration.ShoppingListConfig.RemoveQuantityAutomatically || + !Plugin.Configuration.ShoppingListConfig.Enabled) + return; + var wantedItem = WantedItems.FirstOrDefault(i => i.ItemId == itemDetails.Item1); + if (wantedItem is null) return; - foreach (var eventItem in events) - { - var wantedItem = WantedItems.FirstOrDefault(i => i.ItemId == eventItem.Item.ItemId); - if (wantedItem == null) - continue; - wantedItem.Quantity =- wantedItem.InventoryCount; - } + wantedItem.Quantity -= itemDetails.Item4; } + public void SaveList() { var path = Path.Combine(Svc.PluginInterface.ConfigDirectory.FullName, "shoppinglist.json"); @@ -98,6 +110,7 @@ public void QueueMoveToMarketboardTasks() Svc.Chat.PrintError($"[Reborn Toolbox] VNavmesh is required for automatic movement"); return; } + switch (Svc.ClientState.TerritoryType) { case 129: @@ -122,7 +135,8 @@ private void QueueUldahMoveToMarketboardTasks() TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.Nav_IsReady()); TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.SimpleMove_PathfindAndMoveTo(uldahTransitionPosition, false)); TaskManager.EnqueueDelay(5000); - TaskManager.Enqueue(() => !VNavmesh_IPCSubscriber.Path_IsRunning() && !VNavmesh_IPCSubscriber.Nav_PathfindInProgress()); + TaskManager.Enqueue(() => + !VNavmesh_IPCSubscriber.Path_IsRunning() && !VNavmesh_IPCSubscriber.Nav_PathfindInProgress()); TaskManager.Enqueue(GenericHelpers.IsScreenReady); TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.Nav_IsReady()); TaskManager.Enqueue(MoveToNearestMarketboard); @@ -132,15 +146,20 @@ private void QueueUldahMoveToMarketboardTasks() private Vector3 oldGridTransitionPosition = new Vector3(11.458f, 1.275f, -15.702f); private Vector3 oldGridBowerHousePosition = new Vector3(141.558f, 13.571f, -97.028f); + private void QueueGridMoveToMarketboardTasks() { TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.Nav_IsReady()); - TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.SimpleMove_PathfindAndMoveTo(oldGridTransitionPosition, false)); - TaskManager.Enqueue(() => !VNavmesh_IPCSubscriber.Path_IsRunning() && !VNavmesh_IPCSubscriber.Nav_PathfindInProgress()); + TaskManager.Enqueue(() => + VNavmesh_IPCSubscriber.SimpleMove_PathfindAndMoveTo(oldGridTransitionPosition, false)); + TaskManager.Enqueue(() => + !VNavmesh_IPCSubscriber.Path_IsRunning() && !VNavmesh_IPCSubscriber.Nav_PathfindInProgress()); TaskManager.Enqueue(GenericHelpers.IsScreenReady); TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.Nav_IsReady()); - TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.SimpleMove_PathfindAndMoveTo(oldGridBowerHousePosition, false)); - TaskManager.Enqueue(() => !VNavmesh_IPCSubscriber.Path_IsRunning() && !VNavmesh_IPCSubscriber.Nav_PathfindInProgress()); + TaskManager.Enqueue(() => + VNavmesh_IPCSubscriber.SimpleMove_PathfindAndMoveTo(oldGridBowerHousePosition, false)); + TaskManager.Enqueue(() => + !VNavmesh_IPCSubscriber.Path_IsRunning() && !VNavmesh_IPCSubscriber.Nav_PathfindInProgress()); TaskManager.Enqueue(() => VNavmesh_IPCSubscriber.Path_Stop()); TaskManager.Enqueue(MoveToNearestMarketboard); } @@ -169,6 +188,7 @@ private unsafe void InteractWithObject(IGameObject obj) { Svc.Log.Error($"TargetSystem was null."); } + targetSystem->OpenObjectInteraction( (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)obj.Address); }