2023-10-13 20:08:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2023-10-19 07:22:21 +00:00
|
|
|
|
using Dalamud.Game.Text;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
using Dalamud.Interface;
|
|
|
|
|
using Dalamud.Interface.Colors;
|
|
|
|
|
using Dalamud.Interface.Components;
|
|
|
|
|
using Dalamud.Plugin;
|
|
|
|
|
using Dalamud.Plugin.Services;
|
|
|
|
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|
|
|
|
using ImGuiNET;
|
|
|
|
|
using LLib;
|
|
|
|
|
using LLib.GameUI;
|
2023-10-19 18:46:01 +00:00
|
|
|
|
using Workshoppa.External;
|
2023-10-24 22:19:42 +00:00
|
|
|
|
using Workshoppa.GameData.Shops;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
|
|
|
|
|
|
|
|
|
namespace Workshoppa.Windows;
|
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
internal sealed class RepairKitWindow : ShopWindow
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
|
|
|
|
private const int DarkMatterCluster6ItemId = 10386;
|
|
|
|
|
|
|
|
|
|
private readonly DalamudPluginInterface _pluginInterface;
|
|
|
|
|
private readonly IPluginLog _pluginLog;
|
|
|
|
|
private readonly Configuration _configuration;
|
|
|
|
|
|
2023-10-19 18:46:01 +00:00
|
|
|
|
public RepairKitWindow(WorkshopPlugin plugin, DalamudPluginInterface pluginInterface, IPluginLog pluginLog,
|
|
|
|
|
IGameGui gameGui, IAddonLifecycle addonLifecycle, Configuration configuration,
|
|
|
|
|
ExternalPluginHandler externalPluginHandler)
|
2023-10-24 22:19:42 +00:00
|
|
|
|
: base("Repair Kits###WorkshoppaRepairKitWindow", "Shop", plugin, pluginLog, gameGui, addonLifecycle, externalPluginHandler)
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
|
|
|
|
_pluginInterface = pluginInterface;
|
|
|
|
|
_pluginLog = pluginLog;
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
protected override bool Enabled => _configuration.EnableRepairKitCalculator;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
protected override unsafe void UpdateShopStock(AtkUnitBase* addon)
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (GetDarkMatterClusterCount() == 0)
|
|
|
|
|
{
|
2023-10-24 22:19:42 +00:00
|
|
|
|
ItemForSale = null;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (addon->AtkValuesCount != 625)
|
|
|
|
|
{
|
|
|
|
|
_pluginLog.Error($"Unexpected amount of atkvalues for Shop addon ({addon->AtkValuesCount})");
|
2023-10-24 22:19:42 +00:00
|
|
|
|
ItemForSale = null;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var atkValues = addon->AtkValues;
|
|
|
|
|
|
|
|
|
|
// Check if on 'Current Stock' tab?
|
|
|
|
|
if (atkValues[0].UInt != 0)
|
|
|
|
|
{
|
2023-10-24 22:19:42 +00:00
|
|
|
|
ItemForSale = null;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint itemCount = atkValues[2].UInt;
|
|
|
|
|
if (itemCount == 0)
|
|
|
|
|
{
|
2023-10-24 22:19:42 +00:00
|
|
|
|
ItemForSale = null;
|
2023-10-13 20:08:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
ItemForSale = Enumerable.Range(0, (int)itemCount)
|
2023-10-13 20:08:22 +00:00
|
|
|
|
.Select(i => new ItemForSale
|
|
|
|
|
{
|
|
|
|
|
Position = i,
|
|
|
|
|
ItemName = atkValues[14 + i].ReadAtkString(),
|
|
|
|
|
Price = atkValues[75 + i].UInt,
|
|
|
|
|
OwnedItems = atkValues[136 + i].UInt,
|
|
|
|
|
ItemId = atkValues[441 + i].UInt,
|
|
|
|
|
})
|
|
|
|
|
.FirstOrDefault(x => x.ItemId == DarkMatterCluster6ItemId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetDarkMatterClusterCount() => GetItemCount(10335);
|
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
protected override int GetCurrencyCount() => GetItemCount(1);
|
2023-10-13 20:08:22 +00:00
|
|
|
|
|
|
|
|
|
public override void Draw()
|
|
|
|
|
{
|
|
|
|
|
int darkMatterClusters = GetDarkMatterClusterCount();
|
2023-10-24 22:19:42 +00:00
|
|
|
|
if (ItemForSale == null || darkMatterClusters == 0)
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
|
|
|
|
IsOpen = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LImGui.AddPatreonIcon(_pluginInterface);
|
|
|
|
|
|
|
|
|
|
ImGui.Text("Inventory");
|
|
|
|
|
ImGui.Indent();
|
|
|
|
|
ImGui.Text($"Dark Matter Clusters: {darkMatterClusters:N0}");
|
2023-10-24 22:19:42 +00:00
|
|
|
|
ImGui.Text($"Grade 6 Dark Matter: {ItemForSale.OwnedItems:N0}");
|
2023-10-13 20:08:22 +00:00
|
|
|
|
ImGui.Unindent();
|
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
int missingItems = Math.Max(0, darkMatterClusters * 5 - (int)ItemForSale.OwnedItems);
|
2023-10-19 18:46:01 +00:00
|
|
|
|
ImGui.TextColored(missingItems == 0 ? ImGuiColors.HealerGreen : ImGuiColors.DalamudRed,
|
|
|
|
|
$"Missing Grade 6 Dark Matter: {missingItems:N0}");
|
2023-10-13 20:08:22 +00:00
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
if (PurchaseState != null)
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
|
|
|
|
HandleNextPurchaseStep();
|
|
|
|
|
|
|
|
|
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
2023-10-24 22:19:42 +00:00
|
|
|
|
CancelAutoPurchase();
|
2023-10-13 20:08:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);
|
|
|
|
|
if (toPurchase > 0)
|
|
|
|
|
{
|
2023-10-19 18:46:01 +00:00
|
|
|
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.DollarSign,
|
2023-10-24 22:19:42 +00:00
|
|
|
|
$"Auto-Buy missing Dark Matter for {ItemForSale.Price * toPurchase:N0}{SeIconChar.Gil.ToIconString()}"))
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
2023-10-24 22:19:42 +00:00
|
|
|
|
StartAutoPurchase(toPurchase);
|
2023-10-13 20:08:22 +00:00
|
|
|
|
HandleNextPurchaseStep();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-24 22:19:42 +00:00
|
|
|
|
protected override unsafe void FirePurchaseCallback(AtkUnitBase* addonShop, int buyNow)
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
2023-10-24 22:19:42 +00:00
|
|
|
|
var buyItem = stackalloc AtkValue[]
|
2023-10-13 20:08:22 +00:00
|
|
|
|
{
|
2023-10-24 22:19:42 +00:00
|
|
|
|
new() { Type = ValueType.Int, Int = 0 },
|
|
|
|
|
new() { Type = ValueType.Int, Int = ItemForSale!.Position },
|
|
|
|
|
new() { Type = ValueType.Int, Int = buyNow },
|
|
|
|
|
new() { Type = 0, Int = 0 }
|
|
|
|
|
};
|
|
|
|
|
addonShop->FireCallback(4, buyItem);
|
2023-10-13 20:08:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|