Skip to content

Commit

Permalink
Merge pull request #2 from FFXIV-CombatReborn/day-1-fixes
Browse files Browse the repository at this point in the history
Fix inventory tracking
  • Loading branch information
NostraThomas99 authored Oct 7, 2024
2 parents cf33081 + 655038b commit c17b63d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
1 change: 1 addition & 0 deletions RebornToolbox.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGameInventoryPluginScoped_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F143d856c0ace4d09837da2885c8fbd2f362010_003F82_003F977b6a9f_003FGameInventoryPluginScoped_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AImGuiListClipper_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0b6ec17a3ce0423189bf77950a2c62728b010_003F76_003F2d477a2b_003FImGuiListClipper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AInventoryItem_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fed17561d1c2649f9b4c9ee353d95fd0f545810_003F87_003Fffbb7fb9_003FInventoryItem_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASeStringDrawParams_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F143d856c0ace4d09837da2885c8fbd2f362010_003Fd5_003F88123e6e_003FSeStringDrawParams_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
Expand Down
6 changes: 0 additions & 6 deletions RebornToolbox/Common/IpcSubscribers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@ internal static bool IsEnabled
[EzIPC("AllaganTools.GetCharacterItemsByType", applyPrefix: false)]
internal static readonly Func<ulong, uint, HashSet<ulong[]>> 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<Dictionary<string, string>> GetCraftLists;

Expand Down
50 changes: 35 additions & 15 deletions RebornToolbox/Features/MBShoppingList/MBShoppingList.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<InventoryEventArgs> 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");
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c17b63d

Please sign in to comment.