Compare commits
No commits in common. "master" and "master" have entirely different histories.
2
LLib
2
LLib
@ -1 +1 @@
|
|||||||
Subproject commit e4bbc05ede6f6f01e7028b24614ed8cb333e909c
|
Subproject commit 93fac6efb01a1272192d929fd863328271512ea4
|
@ -4,8 +4,8 @@ using System.Text.RegularExpressions;
|
|||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using LLib;
|
using LLib;
|
||||||
using Lumina.Excel;
|
using Lumina.Excel;
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.CustomSheets;
|
||||||
using Lumina.Text.ReadOnly;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
|
||||||
namespace Workshoppa.GameData;
|
namespace Workshoppa.GameData;
|
||||||
|
|
||||||
@ -38,16 +38,7 @@ internal sealed class GameStrings
|
|||||||
|
|
||||||
[Sheet("custom/001/CmnDefCompanyManufactory_00150")]
|
[Sheet("custom/001/CmnDefCompanyManufactory_00150")]
|
||||||
[SuppressMessage("Performance", "CA1812")]
|
[SuppressMessage("Performance", "CA1812")]
|
||||||
private readonly struct WorkshopDialogue(ExcelPage page, uint offset, uint row)
|
private sealed class WorkshopDialogue : QuestDialogueText
|
||||||
: IQuestDialogueText, IExcelRow<WorkshopDialogue>
|
|
||||||
{
|
{
|
||||||
public uint RowId => row;
|
|
||||||
|
|
||||||
public ReadOnlySeString Key => page.ReadString(offset, offset);
|
|
||||||
public ReadOnlySeString Value => page.ReadString(offset + 4, offset);
|
|
||||||
|
|
||||||
static WorkshopDialogue IExcelRow<WorkshopDialogue>.Create(ExcelPage page, uint offset,
|
|
||||||
uint row) =>
|
|
||||||
new(page, offset, row);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.GeneratedSheets2;
|
||||||
|
|
||||||
namespace Workshoppa.GameData;
|
namespace Workshoppa.GameData;
|
||||||
|
|
||||||
@ -31,10 +31,9 @@ internal sealed class RecipeTree
|
|||||||
262211, // Z'ranmaia, upper decks
|
262211, // Z'ranmaia, upper decks
|
||||||
};
|
};
|
||||||
|
|
||||||
_shopItemsOnly = _dataManager.GetSubrowExcelSheet<GilShopItem>()
|
_shopItemsOnly = _dataManager.GetExcelSheet<GilShopItem>()!
|
||||||
.Flatten()
|
|
||||||
.Where(x => shopVendorIds.Contains(x.RowId))
|
.Where(x => shopVendorIds.Contains(x.RowId))
|
||||||
.Select(x => x.Item.RowId)
|
.Select(x => x.Item.Row)
|
||||||
.Where(x => x > 0)
|
.Where(x => x > 0)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList()
|
.ToList()
|
||||||
@ -122,32 +121,32 @@ internal sealed class RecipeTree
|
|||||||
|
|
||||||
for (int i = 0; i < 8; ++ i)
|
for (int i = 0; i < 8; ++ i)
|
||||||
{
|
{
|
||||||
var ingredient = recipe.Value.Ingredient[i];
|
var ingredient = recipe.Ingredient[i];
|
||||||
if (!ingredient.IsValid || ingredient.RowId == 0)
|
if (ingredient == null || ingredient.Row == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Item item = ingredient.Value;
|
Item? item = ingredient.Value;
|
||||||
if (!IsValidItem(item.RowId))
|
if (item == null || !IsValidItem(item.RowId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Recipe? ingredientRecipe = GetFirstRecipeForItem(ingredient.RowId);
|
Recipe? ingredientRecipe = GetFirstRecipeForItem(ingredient.Row);
|
||||||
|
|
||||||
//_pluginLog.Information($"Adding {item.Name}");
|
//_pluginLog.Information($"Adding {item.Name}");
|
||||||
ingredients.Add(new RecipeInfo
|
ingredients.Add(new RecipeInfo
|
||||||
{
|
{
|
||||||
ItemId = ingredient.RowId,
|
ItemId = ingredient.Row,
|
||||||
Name = item.Name.ToString(),
|
Name = item.Name,
|
||||||
TotalQuantity = material.TotalQuantity * recipe.Value.AmountIngredient[i],
|
TotalQuantity = material.TotalQuantity * recipe.AmountIngredient[i],
|
||||||
Type =
|
Type =
|
||||||
_shopItemsOnly.Contains(ingredient.RowId) ? Ingredient.EType.ShopItem :
|
_shopItemsOnly.Contains(ingredient.Row) ? Ingredient.EType.ShopItem :
|
||||||
ingredientRecipe != null ? Ingredient.EType.Craftable :
|
ingredientRecipe != null ? Ingredient.EType.Craftable :
|
||||||
GetGatheringItem(ingredient.RowId) != null ? Ingredient.EType.Gatherable :
|
GetGatheringItem(ingredient.Row) != null ? Ingredient.EType.Gatherable :
|
||||||
GetVentureItem(ingredient.RowId) != null ? Ingredient.EType.Gatherable :
|
GetVentureItem(ingredient.Row) != null ? Ingredient.EType.Gatherable :
|
||||||
Ingredient.EType.Other,
|
Ingredient.EType.Other,
|
||||||
|
|
||||||
AmountCrafted = ingredientRecipe?.AmountResult ?? 1,
|
AmountCrafted = ingredientRecipe?.AmountResult ?? 1,
|
||||||
DependsOn = ingredientRecipe?.Ingredient.Where(x => x.IsValid && IsValidItem(x.RowId))
|
DependsOn = ingredientRecipe?.Ingredient.Where(x => x != null && IsValidItem(x.Row))
|
||||||
.Select(x => x.RowId)
|
.Select(x => x.Row)
|
||||||
.ToList()
|
.ToList()
|
||||||
?? new(),
|
?? new(),
|
||||||
});
|
});
|
||||||
@ -171,9 +170,9 @@ internal sealed class RecipeTree
|
|||||||
Name = x.Ingredient.Name,
|
Name = x.Ingredient.Name,
|
||||||
TotalQuantity = x.Ingredient.TotalQuantity,
|
TotalQuantity = x.Ingredient.TotalQuantity,
|
||||||
Type = _shopItemsOnly.Contains(x.Ingredient.ItemId) ? Ingredient.EType.ShopItem : x.Ingredient.Type,
|
Type = _shopItemsOnly.Contains(x.Ingredient.ItemId) ? Ingredient.EType.ShopItem : x.Ingredient.Type,
|
||||||
AmountCrafted = x.Recipe!.Value.AmountResult,
|
AmountCrafted = x.Recipe!.AmountResult,
|
||||||
DependsOn = x.Recipe.Value.Ingredient.Where(y => y.IsValid && IsValidItem(y.RowId))
|
DependsOn = x.Recipe.Ingredient.Where(y => y != null && IsValidItem(y.Row))
|
||||||
.Select(y => y.RowId)
|
.Select(y => y.Row)
|
||||||
.ToList(),
|
.ToList(),
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -181,18 +180,18 @@ internal sealed class RecipeTree
|
|||||||
|
|
||||||
private Recipe? GetFirstRecipeForItem(uint itemId)
|
private Recipe? GetFirstRecipeForItem(uint itemId)
|
||||||
{
|
{
|
||||||
return _dataManager.GetExcelSheet<Recipe>().FirstOrDefault(x => x.RowId > 0 && x.ItemResult.RowId == itemId);
|
return _dataManager.GetExcelSheet<Recipe>()!.FirstOrDefault(x => x.RowId > 0 && x.ItemResult.Row == itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GatheringItem? GetGatheringItem(uint itemId)
|
private GatheringItem? GetGatheringItem(uint itemId)
|
||||||
{
|
{
|
||||||
return _dataManager.GetExcelSheet<GatheringItem>().FirstOrDefault(x => x.RowId > 0 && x.Item.RowId == itemId);
|
return _dataManager.GetExcelSheet<GatheringItem>()!.FirstOrDefault(x => x.RowId > 0 && x.Item.Row == itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RetainerTaskNormal? GetVentureItem(uint itemId)
|
private RetainerTaskNormal? GetVentureItem(uint itemId)
|
||||||
{
|
{
|
||||||
return _dataManager.GetExcelSheet<RetainerTaskNormal>()
|
return _dataManager.GetExcelSheet<RetainerTaskNormal>()!
|
||||||
.FirstOrDefault(x => x.RowId > 0 && x.Item.RowId == itemId);
|
.FirstOrDefault(x => x.RowId > 0 && x.Item.Row == itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsValidItem(uint itemId)
|
private static bool IsValidItem(uint itemId)
|
||||||
|
10
Workshoppa/GameData/Shops/ItemForSale.cs
Normal file
10
Workshoppa/GameData/Shops/ItemForSale.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace Workshoppa.GameData.Shops;
|
||||||
|
|
||||||
|
internal sealed class ItemForSale
|
||||||
|
{
|
||||||
|
public required int Position { get; init; }
|
||||||
|
public required uint ItemId { get; init; }
|
||||||
|
public required string? ItemName { get; init; }
|
||||||
|
public required uint Price { get; init; }
|
||||||
|
public required uint OwnedItems { get; init; }
|
||||||
|
}
|
19
Workshoppa/GameData/Shops/PurchaseState.cs
Normal file
19
Workshoppa/GameData/Shops/PurchaseState.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Workshoppa.GameData.Shops;
|
||||||
|
|
||||||
|
internal sealed class PurchaseState
|
||||||
|
{
|
||||||
|
public PurchaseState(int desiredItems, int ownedItems)
|
||||||
|
{
|
||||||
|
DesiredItems = desiredItems;
|
||||||
|
OwnedItems = ownedItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int DesiredItems { get; }
|
||||||
|
public int OwnedItems { get; set; }
|
||||||
|
public int ItemsLeftToBuy => Math.Max(0, DesiredItems - OwnedItems);
|
||||||
|
public bool IsComplete => ItemsLeftToBuy == 0;
|
||||||
|
public bool IsAwaitingYesNo { get; set; }
|
||||||
|
public DateTime NextStep { get; set; } = DateTime.MinValue;
|
||||||
|
}
|
@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
|
||||||
namespace Workshoppa.GameData;
|
namespace Workshoppa.GameData;
|
||||||
|
|
||||||
@ -16,45 +15,41 @@ internal sealed class WorkshopCache
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Dictionary<uint, Item> itemMapping = dataManager.GetExcelSheet<CompanyCraftSupplyItem>()
|
Dictionary<ushort, Item> itemMapping = dataManager.GetExcelSheet<CompanyCraftSupplyItem>()!
|
||||||
.Where(x => x.RowId > 0)
|
.Where(x => x.RowId > 0)
|
||||||
.ToDictionary(x => x.RowId, x => x.Item.Value);
|
.ToDictionary(x => (ushort)x.RowId, x => x.Item.Value!);
|
||||||
|
|
||||||
Crafts = dataManager.GetExcelSheet<CompanyCraftSequence>()
|
Crafts = dataManager.GetExcelSheet<CompanyCraftSequence>()!
|
||||||
.Where(x => x.RowId > 0)
|
.Where(x => x.RowId > 0)
|
||||||
.Select(x => new WorkshopCraft
|
.Select(x => new WorkshopCraft
|
||||||
{
|
{
|
||||||
WorkshopItemId = x.RowId,
|
WorkshopItemId = x.RowId,
|
||||||
ResultItem = x.ResultItem.RowId,
|
ResultItem = x.ResultItem.Row,
|
||||||
Name = x.ResultItem.Value.Name.ToString(),
|
Name = x.ResultItem.Value!.Name.ToString(),
|
||||||
IconId = x.ResultItem.Value.Icon,
|
IconId = x.ResultItem.Value!.Icon,
|
||||||
Category = (WorkshopCraftCategory)x.CompanyCraftDraftCategory.RowId,
|
Category = (WorkshopCraftCategory)x.CompanyCraftDraftCategory.Row,
|
||||||
Type = x.CompanyCraftType.RowId,
|
Type = x.CompanyCraftType.Row,
|
||||||
Phases = x.CompanyCraftPart.Where(part => part.RowId != 0)
|
Phases = x.CompanyCraftPart.Where(part => part.Row != 0)
|
||||||
.SelectMany(part =>
|
.SelectMany(part =>
|
||||||
part.Value.CompanyCraftProcess
|
part.Value!.CompanyCraftProcess
|
||||||
.Select(y => new WorkshopCraftPhase
|
.Where(y => y.Value!.UnkData0.Any(z => z.SupplyItem > 0))
|
||||||
|
.Select(y => (Type: part.Value!.CompanyCraftType.Value, Process: y)))
|
||||||
|
.Select(y => new WorkshopCraftPhase
|
||||||
|
{
|
||||||
|
Name = y.Type!.Name.ToString(),
|
||||||
|
Items = y.Process.Value!.UnkData0
|
||||||
|
.Where(item => item.SupplyItem > 0)
|
||||||
|
.Select(item => new WorkshopCraftItem
|
||||||
{
|
{
|
||||||
Name = part.Value.CompanyCraftType.Value.Name.ToString(),
|
ItemId = itemMapping[item.SupplyItem].RowId,
|
||||||
Items = Enumerable.Range(0, y.Value.SupplyItem.Count)
|
Name = itemMapping[item.SupplyItem].Name.ToString(),
|
||||||
.Select(i => new
|
IconId = itemMapping[item.SupplyItem].Icon,
|
||||||
{
|
SetQuantity = item.SetQuantity,
|
||||||
SupplyItem = y.Value.SupplyItem[i],
|
SetsRequired = item.SetsRequired,
|
||||||
SetsRequired = y.Value.SetsRequired[i],
|
})
|
||||||
SetQuantity = y.Value.SetQuantity[i],
|
.ToList()
|
||||||
})
|
.AsReadOnly(),
|
||||||
.Where(item => item.SupplyItem.RowId > 0)
|
})
|
||||||
.Select(item => new WorkshopCraftItem
|
|
||||||
{
|
|
||||||
ItemId = itemMapping[item.SupplyItem.RowId].RowId,
|
|
||||||
Name = itemMapping[item.SupplyItem.RowId].Name.ToString(),
|
|
||||||
IconId = itemMapping[item.SupplyItem.RowId].Icon,
|
|
||||||
SetQuantity = item.SetQuantity,
|
|
||||||
SetsRequired = item.SetsRequired,
|
|
||||||
})
|
|
||||||
.ToList()
|
|
||||||
.AsReadOnly(),
|
|
||||||
}))
|
|
||||||
.ToList()
|
.ToList()
|
||||||
.AsReadOnly(),
|
.AsReadOnly(),
|
||||||
})
|
})
|
||||||
|
@ -5,9 +5,10 @@ using Dalamud.Interface.Components;
|
|||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
using LLib;
|
||||||
using LLib.GameUI;
|
using LLib.GameUI;
|
||||||
using LLib.Shop.Model;
|
|
||||||
using Workshoppa.External;
|
using Workshoppa.External;
|
||||||
|
using Workshoppa.GameData.Shops;
|
||||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||||
|
|
||||||
namespace Workshoppa.Windows;
|
namespace Workshoppa.Windows;
|
||||||
@ -16,6 +17,7 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
{
|
{
|
||||||
private const int CeruleumTankItemId = 10155;
|
private const int CeruleumTankItemId = 10155;
|
||||||
|
|
||||||
|
private readonly WorkshopPlugin _plugin;
|
||||||
private readonly IPluginLog _pluginLog;
|
private readonly IPluginLog _pluginLog;
|
||||||
private readonly Configuration _configuration;
|
private readonly Configuration _configuration;
|
||||||
private readonly IChatGui _chatGui;
|
private readonly IChatGui _chatGui;
|
||||||
@ -24,31 +26,28 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
private int _buyStackCount;
|
private int _buyStackCount;
|
||||||
private bool _buyPartialStacks = true;
|
private bool _buyPartialStacks = true;
|
||||||
|
|
||||||
public CeruleumTankWindow(
|
public CeruleumTankWindow(WorkshopPlugin plugin, IPluginLog pluginLog, IGameGui gameGui,
|
||||||
IPluginLog pluginLog,
|
IAddonLifecycle addonLifecycle, Configuration configuration, ExternalPluginHandler externalPluginHandler,
|
||||||
IGameGui gameGui,
|
|
||||||
IAddonLifecycle addonLifecycle,
|
|
||||||
Configuration configuration,
|
|
||||||
ExternalPluginHandler externalPluginHandler,
|
|
||||||
IChatGui chatGui)
|
IChatGui chatGui)
|
||||||
: base("Ceruleum Tanks###WorkshoppaCeruleumTankWindow", "FreeCompanyCreditShop", pluginLog, gameGui,
|
: base("Ceruleum Tanks###WorkshoppaCeruleumTankWindow", "FreeCompanyCreditShop", plugin, pluginLog, gameGui,
|
||||||
addonLifecycle, externalPluginHandler)
|
addonLifecycle, externalPluginHandler)
|
||||||
{
|
{
|
||||||
|
_plugin = plugin;
|
||||||
_pluginLog = pluginLog;
|
_pluginLog = pluginLog;
|
||||||
_chatGui = chatGui;
|
_chatGui = chatGui;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsEnabled => _configuration.EnableCeruleumTankCalculator;
|
protected override bool Enabled => _configuration.EnableCeruleumTankCalculator;
|
||||||
|
|
||||||
public override unsafe void UpdateShopStock(AtkUnitBase* addon)
|
protected override unsafe void UpdateShopStock(AtkUnitBase* addon)
|
||||||
{
|
{
|
||||||
if (addon->AtkValuesCount != 170)
|
if (addon->AtkValuesCount != 170)
|
||||||
{
|
{
|
||||||
_pluginLog.Error(
|
_pluginLog.Error(
|
||||||
$"Unexpected amount of atkvalues for FreeCompanyCreditShop addon ({addon->AtkValuesCount})");
|
$"Unexpected amount of atkvalues for FreeCompanyCreditShop addon ({addon->AtkValuesCount})");
|
||||||
_companyCredits = 0;
|
_companyCredits = 0;
|
||||||
Shop.ItemForSale = null;
|
ItemForSale = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,11 +57,11 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
uint itemCount = atkValues[9].UInt;
|
uint itemCount = atkValues[9].UInt;
|
||||||
if (itemCount == 0)
|
if (itemCount == 0)
|
||||||
{
|
{
|
||||||
Shop.ItemForSale = null;
|
ItemForSale = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shop.ItemForSale = Enumerable.Range(0, (int)itemCount)
|
ItemForSale = Enumerable.Range(0, (int)itemCount)
|
||||||
.Select(i => new ItemForSale
|
.Select(i => new ItemForSale
|
||||||
{
|
{
|
||||||
Position = i,
|
Position = i,
|
||||||
@ -74,18 +73,18 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
.FirstOrDefault(x => x.ItemId == CeruleumTankItemId);
|
.FirstOrDefault(x => x.ItemId == CeruleumTankItemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetCurrencyCount() => _companyCredits;
|
protected override int GetCurrencyCount() => _companyCredits;
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
if (Shop.ItemForSale == null)
|
if (ItemForSale == null)
|
||||||
{
|
{
|
||||||
IsOpen = false;
|
IsOpen = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ceruleumTanks = Shop.GetItemCount(CeruleumTankItemId);
|
int ceruleumTanks = GetItemCount(CeruleumTankItemId);
|
||||||
int freeInventorySlots = Shop.CountFreeInventorySlots();
|
int freeInventorySlots = _plugin.CountFreeInventorySlots();
|
||||||
|
|
||||||
ImGui.Text("Inventory");
|
ImGui.Text("Inventory");
|
||||||
ImGui.Indent();
|
ImGui.Indent();
|
||||||
@ -95,7 +94,7 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
||||||
if (Shop.PurchaseState == null)
|
if (PurchaseState == null)
|
||||||
{
|
{
|
||||||
ImGui.SetNextItemWidth(100);
|
ImGui.SetNextItemWidth(100);
|
||||||
ImGui.InputInt("Stacks to Buy", ref _buyStackCount);
|
ImGui.InputInt("Stacks to Buy", ref _buyStackCount);
|
||||||
@ -109,27 +108,27 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
if (_buyPartialStacks && ceruleumTanks % 999 > 0)
|
if (_buyPartialStacks && ceruleumTanks % 999 > 0)
|
||||||
missingItems += (999 - ceruleumTanks % 999);
|
missingItems += (999 - ceruleumTanks % 999);
|
||||||
|
|
||||||
if (Shop.PurchaseState != null)
|
if (PurchaseState != null)
|
||||||
{
|
{
|
||||||
Shop.HandleNextPurchaseStep();
|
HandleNextPurchaseStep();
|
||||||
if (Shop.PurchaseState != null)
|
if (PurchaseState != null)
|
||||||
{
|
{
|
||||||
ImGui.Text($"Buying {FormatStackCount(Shop.PurchaseState.ItemsLeftToBuy)}...");
|
ImGui.Text($"Buying {FormatStackCount(PurchaseState.ItemsLeftToBuy)}...");
|
||||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
||||||
Shop.CancelAutoPurchase();
|
CancelAutoPurchase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int toPurchase = Math.Min(Shop.GetMaxItemsToPurchase(), missingItems);
|
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);
|
||||||
if (toPurchase > 0)
|
if (toPurchase > 0)
|
||||||
{
|
{
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.DollarSign,
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.DollarSign,
|
||||||
$"Auto-Buy {FormatStackCount(toPurchase)} for {Shop.ItemForSale.Price * toPurchase:N0} CC"))
|
$"Auto-Buy {FormatStackCount(toPurchase)} for {ItemForSale.Price * toPurchase:N0} CC"))
|
||||||
{
|
{
|
||||||
Shop.StartAutoPurchase(toPurchase);
|
StartAutoPurchase(toPurchase);
|
||||||
Shop.HandleNextPurchaseStep();
|
HandleNextPurchaseStep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,12 +144,12 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
return $"{fullStacks:N0} {stacks}";
|
return $"{fullStacks:N0} {stacks}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public override unsafe void TriggerPurchase(AtkUnitBase* addonShop, int buyNow)
|
protected override unsafe void FirePurchaseCallback(AtkUnitBase* addonShop, int buyNow)
|
||||||
{
|
{
|
||||||
var buyItem = stackalloc AtkValue[]
|
var buyItem = stackalloc AtkValue[]
|
||||||
{
|
{
|
||||||
new() { Type = ValueType.Int, Int = 0 },
|
new() { Type = ValueType.Int, Int = 0 },
|
||||||
new() { Type = ValueType.UInt, UInt = (uint)Shop.ItemForSale!.Position },
|
new() { Type = ValueType.UInt, UInt = (uint)ItemForSale!.Position },
|
||||||
new() { Type = ValueType.UInt, UInt = (uint)buyNow },
|
new() { Type = ValueType.UInt, UInt = (uint)buyNow },
|
||||||
};
|
};
|
||||||
addonShop->FireCallback(3, buyItem);
|
addonShop->FireCallback(3, buyItem);
|
||||||
@ -164,9 +163,9 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int freeInventorySlots = Shop.CountFreeInventorySlots();
|
int freeInventorySlots = _plugin.CountFreeInventorySlots();
|
||||||
stackCount = Math.Min(freeInventorySlots, stackCount);
|
stackCount = Math.Min(freeInventorySlots, stackCount);
|
||||||
missingQuantity = Math.Min(Shop.GetMaxItemsToPurchase(), stackCount * 999);
|
missingQuantity = Math.Min(GetMaxItemsToPurchase(), stackCount * 999);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,25 +177,25 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int freeInventorySlots = Shop.CountFreeInventorySlots();
|
int freeInventorySlots = _plugin.CountFreeInventorySlots();
|
||||||
int partialStacks = Shop.CountInventorySlotsWithCondition(CeruleumTankItemId, q => q < 999);
|
int partialStacks = _plugin.CountInventorySlotsWithCondition(CeruleumTankItemId, q => q < 999);
|
||||||
int fullStacks = Shop.CountInventorySlotsWithCondition(CeruleumTankItemId, q => q == 999);
|
int fullStacks = _plugin.CountInventorySlotsWithCondition(CeruleumTankItemId, q => q == 999);
|
||||||
|
|
||||||
int tanks = Math.Min((fullStacks + partialStacks + freeInventorySlots) * 999,
|
int tanks = Math.Min((fullStacks + partialStacks + freeInventorySlots) * 999,
|
||||||
Math.Max(stackCount * 999, (fullStacks + partialStacks) * 999));
|
Math.Max(stackCount * 999, (fullStacks + partialStacks) * 999));
|
||||||
_pluginLog.Information("T: " + tanks);
|
_pluginLog.Information("T: " + tanks);
|
||||||
int owned = Shop.GetItemCount(CeruleumTankItemId);
|
int owned = GetItemCount(CeruleumTankItemId);
|
||||||
if (tanks <= owned)
|
if (tanks <= owned)
|
||||||
missingQuantity = 0;
|
missingQuantity = 0;
|
||||||
else
|
else
|
||||||
missingQuantity = Math.Min(Shop.GetMaxItemsToPurchase(), tanks - owned);
|
missingQuantity = Math.Min(GetMaxItemsToPurchase(), tanks - owned);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartPurchase(int quantity)
|
public void StartPurchase(int quantity)
|
||||||
{
|
{
|
||||||
if (!IsOpen || Shop.ItemForSale == null)
|
if (!IsOpen || ItemForSale == null)
|
||||||
{
|
{
|
||||||
_chatGui.PrintError("Could not start purchase, shop window is not open.");
|
_chatGui.PrintError("Could not start purchase, shop window is not open.");
|
||||||
return;
|
return;
|
||||||
@ -209,7 +208,7 @@ internal sealed class CeruleumTankWindow : ShopWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
_chatGui.Print($"Starting purchase of {FormatStackCount(quantity)} ceruleum tanks.");
|
_chatGui.Print($"Starting purchase of {FormatStackCount(quantity)} ceruleum tanks.");
|
||||||
Shop.StartAutoPurchase(quantity);
|
StartAutoPurchase(quantity);
|
||||||
Shop.HandleNextPurchaseStep();
|
HandleNextPurchaseStep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ internal sealed class MainWindow : LWindow, IPersistableWindowConfig
|
|||||||
public ButtonState State { get; set; } = ButtonState.None;
|
public ButtonState State { get; set; } = ButtonState.None;
|
||||||
|
|
||||||
private bool IsDiscipleOfHand =>
|
private bool IsDiscipleOfHand =>
|
||||||
_clientState.LocalPlayer != null && _clientState.LocalPlayer.ClassJob.RowId is >= 8 and <= 15;
|
_clientState.LocalPlayer != null && _clientState.LocalPlayer.ClassJob.Id is >= 8 and <= 15;
|
||||||
|
|
||||||
public WindowConfig WindowConfig => _configuration.MainWindowConfig;
|
public WindowConfig WindowConfig => _configuration.MainWindowConfig;
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ using Dalamud.Plugin.Services;
|
|||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using LLib.GameUI;
|
using LLib.GameUI;
|
||||||
using LLib.Shop.Model;
|
|
||||||
using Workshoppa.External;
|
using Workshoppa.External;
|
||||||
|
using Workshoppa.GameData.Shops;
|
||||||
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
||||||
|
|
||||||
namespace Workshoppa.Windows;
|
namespace Workshoppa.Windows;
|
||||||
@ -21,32 +21,29 @@ internal sealed class RepairKitWindow : ShopWindow
|
|||||||
private readonly IPluginLog _pluginLog;
|
private readonly IPluginLog _pluginLog;
|
||||||
private readonly Configuration _configuration;
|
private readonly Configuration _configuration;
|
||||||
|
|
||||||
public RepairKitWindow(
|
public RepairKitWindow(WorkshopPlugin plugin, IPluginLog pluginLog,
|
||||||
IPluginLog pluginLog,
|
IGameGui gameGui, IAddonLifecycle addonLifecycle, Configuration configuration,
|
||||||
IGameGui gameGui,
|
|
||||||
IAddonLifecycle addonLifecycle,
|
|
||||||
Configuration configuration,
|
|
||||||
ExternalPluginHandler externalPluginHandler)
|
ExternalPluginHandler externalPluginHandler)
|
||||||
: base("Repair Kits###WorkshoppaRepairKitWindow", "Shop", pluginLog, gameGui, addonLifecycle, externalPluginHandler)
|
: base("Repair Kits###WorkshoppaRepairKitWindow", "Shop", plugin, pluginLog, gameGui, addonLifecycle, externalPluginHandler)
|
||||||
{
|
{
|
||||||
_pluginLog = pluginLog;
|
_pluginLog = pluginLog;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsEnabled => _configuration.EnableRepairKitCalculator;
|
protected override bool Enabled => _configuration.EnableRepairKitCalculator;
|
||||||
|
|
||||||
public override unsafe void UpdateShopStock(AtkUnitBase* addon)
|
protected override unsafe void UpdateShopStock(AtkUnitBase* addon)
|
||||||
{
|
{
|
||||||
if (GetDarkMatterClusterCount() == 0)
|
if (GetDarkMatterClusterCount() == 0)
|
||||||
{
|
{
|
||||||
Shop.ItemForSale = null;
|
ItemForSale = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addon->AtkValuesCount != 625)
|
if (addon->AtkValuesCount != 625)
|
||||||
{
|
{
|
||||||
_pluginLog.Error($"Unexpected amount of atkvalues for Shop addon ({addon->AtkValuesCount})");
|
_pluginLog.Error($"Unexpected amount of atkvalues for Shop addon ({addon->AtkValuesCount})");
|
||||||
Shop.ItemForSale = null;
|
ItemForSale = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,18 +52,18 @@ internal sealed class RepairKitWindow : ShopWindow
|
|||||||
// Check if on 'Current Stock' tab?
|
// Check if on 'Current Stock' tab?
|
||||||
if (atkValues[0].UInt != 0)
|
if (atkValues[0].UInt != 0)
|
||||||
{
|
{
|
||||||
Shop.ItemForSale = null;
|
ItemForSale = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint itemCount = atkValues[2].UInt;
|
uint itemCount = atkValues[2].UInt;
|
||||||
if (itemCount == 0)
|
if (itemCount == 0)
|
||||||
{
|
{
|
||||||
Shop.ItemForSale = null;
|
ItemForSale = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shop.ItemForSale = Enumerable.Range(0, (int)itemCount)
|
ItemForSale = Enumerable.Range(0, (int)itemCount)
|
||||||
.Select(i => new ItemForSale
|
.Select(i => new ItemForSale
|
||||||
{
|
{
|
||||||
Position = i,
|
Position = i,
|
||||||
@ -78,14 +75,14 @@ internal sealed class RepairKitWindow : ShopWindow
|
|||||||
.FirstOrDefault(x => x.ItemId == DarkMatterCluster6ItemId);
|
.FirstOrDefault(x => x.ItemId == DarkMatterCluster6ItemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetDarkMatterClusterCount() => Shop.GetItemCount(10335);
|
private int GetDarkMatterClusterCount() => GetItemCount(10335);
|
||||||
|
|
||||||
public override int GetCurrencyCount() => Shop.GetItemCount(1);
|
protected override int GetCurrencyCount() => GetItemCount(1);
|
||||||
|
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
int darkMatterClusters = GetDarkMatterClusterCount();
|
int darkMatterClusters = GetDarkMatterClusterCount();
|
||||||
if (Shop.ItemForSale == null || darkMatterClusters == 0)
|
if (ItemForSale == null || darkMatterClusters == 0)
|
||||||
{
|
{
|
||||||
IsOpen = false;
|
IsOpen = false;
|
||||||
return;
|
return;
|
||||||
@ -94,43 +91,43 @@ internal sealed class RepairKitWindow : ShopWindow
|
|||||||
ImGui.Text("Inventory");
|
ImGui.Text("Inventory");
|
||||||
ImGui.Indent();
|
ImGui.Indent();
|
||||||
ImGui.Text($"Dark Matter Clusters: {darkMatterClusters:N0}");
|
ImGui.Text($"Dark Matter Clusters: {darkMatterClusters:N0}");
|
||||||
ImGui.Text($"Grade 6 Dark Matter: {Shop.ItemForSale.OwnedItems:N0}");
|
ImGui.Text($"Grade 6 Dark Matter: {ItemForSale.OwnedItems:N0}");
|
||||||
ImGui.Unindent();
|
ImGui.Unindent();
|
||||||
|
|
||||||
int missingItems = Math.Max(0, darkMatterClusters * 5 - (int)Shop.ItemForSale.OwnedItems);
|
int missingItems = Math.Max(0, darkMatterClusters * 5 - (int)ItemForSale.OwnedItems);
|
||||||
ImGui.TextColored(missingItems == 0 ? ImGuiColors.HealerGreen : ImGuiColors.DalamudRed,
|
ImGui.TextColored(missingItems == 0 ? ImGuiColors.HealerGreen : ImGuiColors.DalamudRed,
|
||||||
$"Missing Grade 6 Dark Matter: {missingItems:N0}");
|
$"Missing Grade 6 Dark Matter: {missingItems:N0}");
|
||||||
|
|
||||||
if (Shop.PurchaseState != null)
|
if (PurchaseState != null)
|
||||||
{
|
{
|
||||||
Shop.HandleNextPurchaseStep();
|
HandleNextPurchaseStep();
|
||||||
if (Shop.PurchaseState != null)
|
if (PurchaseState != null)
|
||||||
{
|
{
|
||||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.Times, "Cancel Auto-Buy"))
|
||||||
Shop.CancelAutoPurchase();
|
CancelAutoPurchase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int toPurchase = Math.Min(Shop.GetMaxItemsToPurchase(), missingItems);
|
int toPurchase = Math.Min(GetMaxItemsToPurchase(), missingItems);
|
||||||
if (toPurchase > 0)
|
if (toPurchase > 0)
|
||||||
{
|
{
|
||||||
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.DollarSign,
|
if (ImGuiComponents.IconButtonWithText(FontAwesomeIcon.DollarSign,
|
||||||
$"Auto-Buy missing Dark Matter for {Shop.ItemForSale.Price * toPurchase:N0}{SeIconChar.Gil.ToIconString()}"))
|
$"Auto-Buy missing Dark Matter for {ItemForSale.Price * toPurchase:N0}{SeIconChar.Gil.ToIconString()}"))
|
||||||
{
|
{
|
||||||
Shop.StartAutoPurchase(toPurchase);
|
StartAutoPurchase(toPurchase);
|
||||||
Shop.HandleNextPurchaseStep();
|
HandleNextPurchaseStep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override unsafe void TriggerPurchase(AtkUnitBase* addonShop, int buyNow)
|
protected override unsafe void FirePurchaseCallback(AtkUnitBase* addonShop, int buyNow)
|
||||||
{
|
{
|
||||||
var buyItem = stackalloc AtkValue[]
|
var buyItem = stackalloc AtkValue[]
|
||||||
{
|
{
|
||||||
new() { Type = ValueType.Int, Int = 0 },
|
new() { Type = ValueType.Int, Int = 0 },
|
||||||
new() { Type = ValueType.Int, Int = Shop.ItemForSale!.Position },
|
new() { Type = ValueType.Int, Int = ItemForSale!.Position },
|
||||||
new() { Type = ValueType.Int, Int = buyNow },
|
new() { Type = ValueType.Int, Int = buyNow },
|
||||||
new() { Type = 0, Int = 0 }
|
new() { Type = 0, Int = 0 }
|
||||||
};
|
};
|
||||||
|
@ -1,49 +1,198 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using Dalamud.Game.Addon.Lifecycle;
|
||||||
|
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
|
||||||
using Dalamud.Plugin.Services;
|
using Dalamud.Plugin.Services;
|
||||||
|
using FFXIVClientStructs.FFXIV.Client.Game;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
using LLib.GameUI;
|
||||||
using LLib.ImGui;
|
using LLib.ImGui;
|
||||||
using LLib.Shop;
|
|
||||||
using Workshoppa.External;
|
using Workshoppa.External;
|
||||||
|
using Workshoppa.GameData.Shops;
|
||||||
|
|
||||||
namespace Workshoppa.Windows;
|
namespace Workshoppa.Windows;
|
||||||
|
|
||||||
internal abstract class ShopWindow : LWindow, IShopWindow, IDisposable
|
internal abstract class ShopWindow : LWindow, IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly string _addonName;
|
||||||
|
private readonly WorkshopPlugin _plugin;
|
||||||
|
private readonly IPluginLog _pluginLog;
|
||||||
|
private readonly IGameGui _gameGui;
|
||||||
|
private readonly IAddonLifecycle _addonLifecycle;
|
||||||
private readonly ExternalPluginHandler _externalPluginHandler;
|
private readonly ExternalPluginHandler _externalPluginHandler;
|
||||||
|
|
||||||
protected ShopWindow(
|
protected ItemForSale? ItemForSale;
|
||||||
string windowName,
|
protected PurchaseState? PurchaseState;
|
||||||
string addonName,
|
|
||||||
IPluginLog pluginLog,
|
protected ShopWindow(string name, string addonName, WorkshopPlugin plugin, IPluginLog pluginLog,
|
||||||
IGameGui gameGui,
|
IGameGui gameGui, IAddonLifecycle addonLifecycle, ExternalPluginHandler externalPluginHandler)
|
||||||
IAddonLifecycle addonLifecycle,
|
: base(name)
|
||||||
ExternalPluginHandler externalPluginHandler)
|
|
||||||
: base(windowName)
|
|
||||||
{
|
{
|
||||||
|
_addonName = addonName;
|
||||||
|
_plugin = plugin;
|
||||||
|
_pluginLog = pluginLog;
|
||||||
|
_gameGui = gameGui;
|
||||||
|
_addonLifecycle = addonLifecycle;
|
||||||
_externalPluginHandler = externalPluginHandler;
|
_externalPluginHandler = externalPluginHandler;
|
||||||
Shop = new RegularShopBase(this, addonName, pluginLog, gameGui, addonLifecycle);
|
|
||||||
|
|
||||||
Position = new Vector2(100, 100);
|
Position = new Vector2(100, 100);
|
||||||
PositionCondition = ImGuiCond.Always;
|
PositionCondition = ImGuiCond.Always;
|
||||||
Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoCollapse;
|
Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoNav | ImGuiWindowFlags.NoCollapse;
|
||||||
|
|
||||||
|
_addonLifecycle.RegisterListener(AddonEvent.PostSetup, _addonName, ShopPostSetup);
|
||||||
|
_addonLifecycle.RegisterListener(AddonEvent.PreFinalize, _addonName, ShopPreFinalize);
|
||||||
|
_addonLifecycle.RegisterListener(AddonEvent.PostUpdate, _addonName, ShopPostUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() => Shop.Dispose();
|
public bool AutoBuyEnabled => PurchaseState != null;
|
||||||
|
|
||||||
|
protected abstract bool Enabled { get; }
|
||||||
|
|
||||||
public bool AutoBuyEnabled => Shop.AutoBuyEnabled;
|
|
||||||
public bool IsAwaitingYesNo
|
public bool IsAwaitingYesNo
|
||||||
{
|
{
|
||||||
get { return Shop.IsAwaitingYesNo; }
|
get => PurchaseState?.IsAwaitingYesNo ?? false;
|
||||||
set { Shop.IsAwaitingYesNo = value; }
|
set => PurchaseState!.IsAwaitingYesNo = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RegularShopBase Shop { get; }
|
private unsafe void ShopPostSetup(AddonEvent type, AddonArgs args)
|
||||||
public abstract bool IsEnabled { get; }
|
{
|
||||||
public abstract int GetCurrencyCount();
|
if (!Enabled)
|
||||||
public abstract unsafe void UpdateShopStock(AtkUnitBase* addon);
|
{
|
||||||
public abstract unsafe void TriggerPurchase(AtkUnitBase* addonShop, int buyNow);
|
ItemForSale = null;
|
||||||
public void SaveExternalPluginState() => _externalPluginHandler.Save();
|
IsOpen = false;
|
||||||
public void RestoreExternalPluginState() => _externalPluginHandler.Restore();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateShopStock((AtkUnitBase*)args.Addon);
|
||||||
|
PostUpdateShopStock();
|
||||||
|
if (ItemForSale != null)
|
||||||
|
IsOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShopPreFinalize(AddonEvent type, AddonArgs args)
|
||||||
|
{
|
||||||
|
PurchaseState = null;
|
||||||
|
_externalPluginHandler.Restore();
|
||||||
|
|
||||||
|
IsOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private unsafe void ShopPostUpdate(AddonEvent type, AddonArgs args)
|
||||||
|
{
|
||||||
|
if (!Enabled)
|
||||||
|
{
|
||||||
|
ItemForSale = null;
|
||||||
|
IsOpen = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateShopStock((AtkUnitBase*)args.Addon);
|
||||||
|
PostUpdateShopStock();
|
||||||
|
if (ItemForSale != null)
|
||||||
|
{
|
||||||
|
AtkUnitBase* addon = (AtkUnitBase*)args.Addon;
|
||||||
|
short x = 0, y = 0;
|
||||||
|
addon->GetPosition(&x, &y);
|
||||||
|
|
||||||
|
short width = 0, height = 0;
|
||||||
|
addon->GetSize(&width, &height, true);
|
||||||
|
x += width;
|
||||||
|
|
||||||
|
if ((short)Position!.Value.X != x || (short)Position!.Value.Y != y)
|
||||||
|
Position = new Vector2(x, y);
|
||||||
|
|
||||||
|
IsOpen = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
IsOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract unsafe void UpdateShopStock(AtkUnitBase* addon);
|
||||||
|
|
||||||
|
private void PostUpdateShopStock()
|
||||||
|
{
|
||||||
|
if (ItemForSale != null && PurchaseState != null)
|
||||||
|
{
|
||||||
|
int ownedItems = (int)ItemForSale.OwnedItems;
|
||||||
|
if (PurchaseState.OwnedItems != ownedItems)
|
||||||
|
{
|
||||||
|
PurchaseState.OwnedItems = ownedItems;
|
||||||
|
PurchaseState.NextStep = DateTime.Now.AddSeconds(0.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected unsafe int GetItemCount(uint itemId)
|
||||||
|
{
|
||||||
|
InventoryManager* inventoryManager = InventoryManager.Instance();
|
||||||
|
return inventoryManager->GetInventoryItemCount(itemId, checkEquipped: false, checkArmory: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract int GetCurrencyCount();
|
||||||
|
|
||||||
|
protected int GetMaxItemsToPurchase()
|
||||||
|
{
|
||||||
|
if (ItemForSale == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int currency = GetCurrencyCount();
|
||||||
|
return (int)(currency / ItemForSale!.Price);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void CancelAutoPurchase()
|
||||||
|
{
|
||||||
|
PurchaseState = null;
|
||||||
|
_externalPluginHandler.Restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void StartAutoPurchase(int toPurchase)
|
||||||
|
{
|
||||||
|
PurchaseState = new((int)ItemForSale!.OwnedItems + toPurchase, (int)ItemForSale.OwnedItems);
|
||||||
|
_externalPluginHandler.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected unsafe void HandleNextPurchaseStep()
|
||||||
|
{
|
||||||
|
if (ItemForSale == null || PurchaseState == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int maxStackSize = _plugin.DetermineMaxStackSize(ItemForSale.ItemId);
|
||||||
|
if (maxStackSize == 0 && !_plugin.HasFreeInventorySlot())
|
||||||
|
{
|
||||||
|
_pluginLog.Warning($"No free inventory slots, can't buy more {ItemForSale.ItemName}");
|
||||||
|
PurchaseState = null;
|
||||||
|
_externalPluginHandler.Restore();
|
||||||
|
}
|
||||||
|
else if (!PurchaseState.IsComplete)
|
||||||
|
{
|
||||||
|
if (PurchaseState.NextStep <= DateTime.Now &&
|
||||||
|
_gameGui.TryGetAddonByName(_addonName, out AtkUnitBase* addonShop))
|
||||||
|
{
|
||||||
|
int buyNow = Math.Min(PurchaseState.ItemsLeftToBuy, maxStackSize);
|
||||||
|
_pluginLog.Information($"Buying {buyNow}x {ItemForSale.ItemName}");
|
||||||
|
|
||||||
|
FirePurchaseCallback(addonShop, buyNow);
|
||||||
|
|
||||||
|
PurchaseState.NextStep = DateTime.MaxValue;
|
||||||
|
PurchaseState.IsAwaitingYesNo = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_pluginLog.Information(
|
||||||
|
$"Stopping item purchase (desired = {PurchaseState.DesiredItems}, owned = {PurchaseState.OwnedItems})");
|
||||||
|
PurchaseState = null;
|
||||||
|
_externalPluginHandler.Restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract unsafe void FirePurchaseCallback(AtkUnitBase* addonShop, int buyNow);
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_addonLifecycle.UnregisterListener(AddonEvent.PostSetup, _addonName, ShopPostSetup);
|
||||||
|
_addonLifecycle.UnregisterListener(AddonEvent.PreFinalize, _addonName, ShopPreFinalize);
|
||||||
|
_addonLifecycle.UnregisterListener(AddonEvent.PostUpdate, _addonName, ShopPostUpdate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,4 +225,81 @@ partial class WorkshopPlugin
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool HasFreeInventorySlot() => CountFreeInventorySlots() > 0;
|
||||||
|
|
||||||
|
public unsafe int CountFreeInventorySlots()
|
||||||
|
{
|
||||||
|
var inventoryManger = InventoryManager.Instance();
|
||||||
|
if (inventoryManger == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (InventoryType t = InventoryType.Inventory1; t <= InventoryType.Inventory4; ++t)
|
||||||
|
{
|
||||||
|
var container = inventoryManger->GetInventoryContainer(t);
|
||||||
|
for (int i = 0; i < container->Size; ++i)
|
||||||
|
{
|
||||||
|
var item = container->GetInventorySlot(i);
|
||||||
|
if (item == null || item->ItemId == 0)
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe int CountInventorySlotsWithCondition(uint itemId, Predicate<int> predicate)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(predicate);
|
||||||
|
|
||||||
|
var inventoryManager = InventoryManager.Instance();
|
||||||
|
if (inventoryManager == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (InventoryType t = InventoryType.Inventory1; t <= InventoryType.Inventory4; ++t)
|
||||||
|
{
|
||||||
|
var container = inventoryManager->GetInventoryContainer(t);
|
||||||
|
for (int i = 0; i < container->Size; ++i)
|
||||||
|
{
|
||||||
|
var item = container->GetInventorySlot(i);
|
||||||
|
if (item == null || item->ItemId == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item->ItemId == itemId && predicate((int)item->Quantity))
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe int DetermineMaxStackSize(uint itemId)
|
||||||
|
{
|
||||||
|
var inventoryManger = InventoryManager.Instance();
|
||||||
|
if (inventoryManger == null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int max = 0;
|
||||||
|
for (InventoryType t = InventoryType.Inventory1; t <= InventoryType.Inventory4; ++t)
|
||||||
|
{
|
||||||
|
var container = inventoryManger->GetInventoryContainer(t);
|
||||||
|
for (int i = 0; i < container->Size; ++i)
|
||||||
|
{
|
||||||
|
var item = container->GetInventorySlot(i);
|
||||||
|
if (item == null || item->ItemId == 0)
|
||||||
|
return 99;
|
||||||
|
|
||||||
|
if (item->ItemId == itemId)
|
||||||
|
{
|
||||||
|
max += (999 - (int)item->Quantity);
|
||||||
|
if (max >= 99)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.Min(99, max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,10 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin
|
|||||||
_windowSystem.AddWindow(_mainWindow);
|
_windowSystem.AddWindow(_mainWindow);
|
||||||
_configWindow = new(_pluginInterface, _configuration);
|
_configWindow = new(_pluginInterface, _configuration);
|
||||||
_windowSystem.AddWindow(_configWindow);
|
_windowSystem.AddWindow(_configWindow);
|
||||||
_repairKitWindow = new(_pluginLog, _gameGui, addonLifecycle, _configuration,
|
_repairKitWindow = new(this, _pluginLog, _gameGui, addonLifecycle, _configuration,
|
||||||
_externalPluginHandler);
|
_externalPluginHandler);
|
||||||
_windowSystem.AddWindow(_repairKitWindow);
|
_windowSystem.AddWindow(_repairKitWindow);
|
||||||
_ceruleumTankWindow = new(_pluginLog, _gameGui, addonLifecycle, _configuration,
|
_ceruleumTankWindow = new(this, _pluginLog, _gameGui, addonLifecycle, _configuration,
|
||||||
_externalPluginHandler, _chatGui);
|
_externalPluginHandler, _chatGui);
|
||||||
_windowSystem.AddWindow(_ceruleumTankWindow);
|
_windowSystem.AddWindow(_ceruleumTankWindow);
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Dalamud.NET.Sdk/11.0.0">
|
<Project Sdk="Dalamud.NET.Sdk/9.0.2">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>7.0</Version>
|
<Version>6.2</Version>
|
||||||
<OutputPath>dist</OutputPath>
|
<OutputPath>dist</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
"net8.0-windows7.0": {
|
"net8.0-windows7.0": {
|
||||||
"DalamudPackager": {
|
"DalamudPackager": {
|
||||||
"type": "Direct",
|
"type": "Direct",
|
||||||
"requested": "[11.0.0, )",
|
"requested": "[2.1.13, )",
|
||||||
"resolved": "11.0.0",
|
"resolved": "2.1.13",
|
||||||
"contentHash": "bjT7XUlhIJSmsE/O76b7weUX+evvGQctbQB8aKXt94o+oPWxHpCepxAGMs7Thow3AzCyqWs7cOpp9/2wcgRRQA=="
|
"contentHash": "rMN1omGe8536f4xLMvx9NwfvpAc9YFFfeXJ1t4P4PE6Gu8WCIoFliR1sh07hM+bfODmesk/dvMbji7vNI+B/pQ=="
|
||||||
},
|
},
|
||||||
"DotNet.ReproducibleBuilds": {
|
"DotNet.ReproducibleBuilds": {
|
||||||
"type": "Direct",
|
"type": "Direct",
|
||||||
@ -79,7 +79,7 @@
|
|||||||
"llib": {
|
"llib": {
|
||||||
"type": "Project",
|
"type": "Project",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"DalamudPackager": "[11.0.0, )"
|
"DalamudPackager": "[2.1.13, )"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user