333 lines
7.3 KiB
C#
333 lines
7.3 KiB
C#
using Dalamud.Plugin.Services;
|
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|
using LLib.GameData;
|
|
using LLib.GameUI;
|
|
using Lumina.Excel.Sheets;
|
|
|
|
namespace LLib.Shop;
|
|
|
|
public static class GcSupplyActions
|
|
{
|
|
private const string SelectStringAddon = "SelectString";
|
|
|
|
private const string SupplyListAddon = "GrandCompanySupplyList";
|
|
|
|
private const string SupplyRewardAddon = "GrandCompanySupplyReward";
|
|
|
|
private const string SelectYesnoAddon = "SelectYesno";
|
|
|
|
private const int ListRowSealRewardBase = 265;
|
|
|
|
private const int ListRowItemIdBase = 425;
|
|
|
|
public const int MaxListRows = 40;
|
|
|
|
public unsafe static bool IsSelectStringReady(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("SelectString", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
return LAddon.IsAddonReady(addonPtr);
|
|
}
|
|
|
|
public unsafe static bool TrySelectStringOption(IGameGui gameGui, int index)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("SelectString", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, index);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool TryCloseSelectString(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("SelectString", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, -1);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool IsSupplyListReady(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
return LAddon.IsAddonReady(addonPtr);
|
|
}
|
|
|
|
public unsafe static bool TrySwitchToExpertTab(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, 0, 2, 0);
|
|
return true;
|
|
}
|
|
|
|
private unsafe static bool IsListLoaded(AtkUnitBase* addon)
|
|
{
|
|
AtkValue atkValues = *addon->AtkValues;
|
|
return atkValues.Type switch
|
|
{
|
|
AtkValueType.UInt => atkValues.UInt == 2,
|
|
AtkValueType.Int => atkValues.Int == 2,
|
|
_ => false,
|
|
};
|
|
}
|
|
|
|
private unsafe static bool IsExpertTab(AtkUnitBase* addon)
|
|
{
|
|
AtkValue atkValue = addon->AtkValues[5];
|
|
return atkValue.Type switch
|
|
{
|
|
AtkValueType.UInt => atkValue.UInt == 2,
|
|
AtkValueType.Int => atkValue.Int == 2,
|
|
_ => false,
|
|
};
|
|
}
|
|
|
|
public unsafe static bool IsExpertTabActive(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (addonPtr->AtkValues == null || addonPtr->AtkValuesCount < 7)
|
|
{
|
|
return false;
|
|
}
|
|
return IsExpertTab(addonPtr);
|
|
}
|
|
|
|
public unsafe static int GetListItemCount(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
if (addonPtr->AtkValues == null || addonPtr->AtkValuesCount < 7)
|
|
{
|
|
return -1;
|
|
}
|
|
if (!IsListLoaded(addonPtr) || !IsExpertTab(addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
AtkValue atkValue = addonPtr->AtkValues[6];
|
|
if (atkValue.Type == AtkValueType.Int)
|
|
{
|
|
return atkValue.Int;
|
|
}
|
|
if (atkValue.Type == AtkValueType.UInt)
|
|
{
|
|
return (int)atkValue.UInt;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public unsafe static uint GetListItemId(IGameGui gameGui, int itemIndex)
|
|
{
|
|
if (itemIndex < 0 || itemIndex >= 40)
|
|
{
|
|
return 0u;
|
|
}
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return 0u;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return 0u;
|
|
}
|
|
if (addonPtr->AtkValues == null || addonPtr->AtkValuesCount <= 425 + itemIndex)
|
|
{
|
|
return 0u;
|
|
}
|
|
if (!IsListLoaded(addonPtr) || !IsExpertTab(addonPtr))
|
|
{
|
|
return 0u;
|
|
}
|
|
AtkValue atkValue = addonPtr->AtkValues[425 + itemIndex];
|
|
if (atkValue.Type == AtkValueType.UInt)
|
|
{
|
|
return atkValue.UInt;
|
|
}
|
|
if (atkValue.Type == AtkValueType.Int && atkValue.Int > 0)
|
|
{
|
|
return (uint)atkValue.Int;
|
|
}
|
|
return 0u;
|
|
}
|
|
|
|
public unsafe static int GetListItemSealReward(IGameGui gameGui, int itemIndex)
|
|
{
|
|
if (itemIndex < 0 || itemIndex >= 40)
|
|
{
|
|
return -1;
|
|
}
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
if (addonPtr->AtkValues == null || addonPtr->AtkValuesCount <= 265 + itemIndex)
|
|
{
|
|
return -1;
|
|
}
|
|
if (!IsListLoaded(addonPtr) || !IsExpertTab(addonPtr))
|
|
{
|
|
return -1;
|
|
}
|
|
AtkValue atkValue = addonPtr->AtkValues[265 + itemIndex];
|
|
if (atkValue.Type == AtkValueType.Int)
|
|
{
|
|
return atkValue.Int;
|
|
}
|
|
if (atkValue.Type == AtkValueType.UInt)
|
|
{
|
|
return (int)atkValue.UInt;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public unsafe static bool TrySelectItem(IGameGui gameGui, int itemIndex)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, 1, itemIndex, 0);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool TryForceRefresh(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, 2);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool TryCloseSupplyList(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyList", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, -1);
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool IsRewardDialogReady(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyReward", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
return LAddon.IsAddonReady(addonPtr);
|
|
}
|
|
|
|
public unsafe static bool TryConfirmTurnIn(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("GrandCompanySupplyReward", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.Fire(addonPtr, default(int));
|
|
return true;
|
|
}
|
|
|
|
public unsafe static bool IsHqConfirmReady(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("SelectYesno", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
return LAddon.IsAddonReady(addonPtr);
|
|
}
|
|
|
|
public unsafe static bool TryConfirmHqTrade(IGameGui gameGui)
|
|
{
|
|
if (!gameGui.TryGetAddonByName<AtkUnitBase>("SelectYesno", out var addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
if (!LAddon.IsAddonReady(addonPtr))
|
|
{
|
|
return false;
|
|
}
|
|
AddonCallback.ClickYes(addonPtr);
|
|
return true;
|
|
}
|
|
|
|
public static int GetCurrentSeals()
|
|
{
|
|
return GrandCompanyShop.GetCompanySeals();
|
|
}
|
|
|
|
public static int GetMaxSeals(IDataManager dataManager)
|
|
{
|
|
byte grandCompanyRank = GrandCompanyHelper.GetGrandCompanyRank();
|
|
if (grandCompanyRank == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
if (!dataManager.GetExcelSheet<GrandCompanyRank>().TryGetRow(grandCompanyRank, out var row))
|
|
{
|
|
return 0;
|
|
}
|
|
return (int)row.MaxSeals;
|
|
}
|
|
|
|
public static bool IsItemExpertDeliverable(IDataManager dataManager, uint itemId)
|
|
{
|
|
if (!dataManager.GetExcelSheet<Item>().TryGetRow(itemId, out var row))
|
|
{
|
|
return false;
|
|
}
|
|
if (row.Rarity < 2)
|
|
{
|
|
return false;
|
|
}
|
|
return row.Desynth > 0;
|
|
}
|
|
}
|