Seal purchase options

pull/3/head
Liza 2023-09-21 20:18:05 +02:00
parent b069af3a24
commit facac551ca
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 153 additions and 29 deletions

View File

@ -40,6 +40,7 @@ public class DeliverooPlugin : IDalamudPlugin
private Stage _currentStageInternal = Stage.Stop;
private DateTime _continueAt = DateTime.MinValue;
private SealPurchaseOption? _selectedPurchaseOption;
public DeliverooPlugin(DalamudPluginInterface pluginInterface, ChatGui chatGui, GameGui gameGui,
Framework framework, ClientState clientState, ObjectTable objectTable, TargetManager targetManager)
@ -70,6 +71,7 @@ public class DeliverooPlugin : IDalamudPlugin
{
PluginLog.Information($"Changing stage from {_currentStageInternal} to {value}");
_currentStageInternal = value;
_turnInWindow.Debug = CurrentStage.ToString();
}
}
}
@ -86,7 +88,6 @@ public class DeliverooPlugin : IDalamudPlugin
{
_turnInWindow.IsOpen = true;
_turnInWindow.Multiplier = GetSealMultiplier();
_turnInWindow.CurrentVentureCount = GetCurrentVentureCount();
if (!_turnInWindow.State)
{
@ -97,9 +98,21 @@ public class DeliverooPlugin : IDalamudPlugin
if (_turnInWindow.State && CurrentStage == Stage.Stop)
{
CurrentStage = Stage.TargetPersonnelOfficer;
_selectedPurchaseOption = _turnInWindow.SelectedOption;
if (_selectedPurchaseOption.ItemId == 0)
_selectedPurchaseOption = null;
else if (GetCurrentSealCount() > GetSealCap() / 2)
CurrentStage = Stage.TargetQuartermaster;
if (TryGetAddonByName<AddonGrandCompanySupplyList>("GrandCompanySupplyList", out var gcSupplyList) &&
IsAddonReady(&gcSupplyList->AtkUnitBase))
CurrentStage = Stage.SelectItemToTurnIn;
if (TryGetAddonByName<AtkUnitBase>("GrandCompanyExchange", out var gcExchange) &&
IsAddonReady(gcExchange))
CurrentStage = Stage.CloseGcExchange;
}
_turnInWindow.Debug = CurrentStage.ToString();
switch (CurrentStage)
{
case Stage.TargetPersonnelOfficer:
@ -159,6 +172,17 @@ public class DeliverooPlugin : IDalamudPlugin
break;
case Stage.TurnInSelected:
if (TryGetAddonByName<AddonSelectYesno>("SelectYesno", out var addonSelectYesno) &&
IsAddonReady(&addonSelectYesno->AtkUnitBase))
{
if (MemoryHelper.ReadSeString(&addonSelectYesno->PromptText->NodeText).ToString()
.StartsWith("Do you really want to trade a high-quality item?"))
{
addonSelectYesno->AtkUnitBase.FireCallbackInt(0);
break;
}
}
if (TryGetAddonByName<AddonGrandCompanySupplyReward>("GrandCompanySupplyReward",
out var addonSupplyReward) && IsAddonReady(&addonSupplyReward->AtkUnitBase))
{
@ -188,9 +212,17 @@ public class DeliverooPlugin : IDalamudPlugin
case Stage.CloseGcSupply:
if (SelectSelectString(3))
{
// you can occasionally get a 'not enough seals' warning lol
_continueAt = DateTime.Now.AddSeconds(1);
CurrentStage = Stage.TargetQuartermaster;
if (_selectedPurchaseOption == null)
{
_turnInWindow.State = false;
CurrentStage = Stage.Stop;
}
else
{
// you can occasionally get a 'not enough seals' warning lol
_continueAt = DateTime.Now.AddSeconds(1);
CurrentStage = Stage.TargetQuartermaster;
}
}
break;
@ -198,7 +230,12 @@ public class DeliverooPlugin : IDalamudPlugin
case Stage.CloseGcSupplyThenStop:
if (SelectSelectString(3))
{
if (GetCurrentSealCount() <= 2000 + 200)
if (_selectedPurchaseOption == null)
{
_turnInWindow.State = false;
CurrentStage = Stage.Stop;
}
else if (GetCurrentSealCount() <= 2000 + _selectedPurchaseOption!.SealCost)
{
_turnInWindow.State = false;
CurrentStage = Stage.Stop;
@ -234,7 +271,7 @@ public class DeliverooPlugin : IDalamudPlugin
var selectRank = stackalloc AtkValue[]
{
new() { Type = ValueType.Int, Int = 1 },
new() { Type = ValueType.Int, Int = 0 /* position within list */ },
new() { Type = ValueType.Int, Int = (int)_selectedPurchaseOption!.Rank },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
@ -259,13 +296,7 @@ public class DeliverooPlugin : IDalamudPlugin
var selectType = stackalloc AtkValue[]
{
new() { Type = ValueType.Int, Int = 2 },
/*
* 2 = weapons
* 3 = armor
* 1 = materiel
* 4 = materials
*/
new() { Type = ValueType.Int, Int = 1 /* position within list */ },
new() { Type = ValueType.Int, Int = (int)_selectedPurchaseOption!.Type },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
@ -288,20 +319,24 @@ public class DeliverooPlugin : IDalamudPlugin
if (TryGetAddonByName<AtkUnitBase>("GrandCompanyExchange", out var addonExchange) &&
IsAddonReady(addonExchange))
{
int venturesToBuy = (GetCurrentSealCount() - 2000) / 200;
venturesToBuy = Math.Min(venturesToBuy, 65000 - GetCurrentVentureCount());
if (venturesToBuy == 0)
int toBuy = (GetCurrentSealCount() - 2000) / _selectedPurchaseOption!.SealCost;
bool isVenture = _selectedPurchaseOption!.ItemId == 21072;
if (isVenture)
toBuy = Math.Min(toBuy, 65000 - GetCurrentVentureCount());
if (toBuy == 0)
{
_turnInWindow.State = false;
CurrentStage = Stage.Stop;
break;
}
_chatGui.Print($"Buying {venturesToBuy} ventures...");
_chatGui.Print($"Buying {toBuy}x {_selectedPurchaseOption!.Name}...");
var selectReward = stackalloc AtkValue[]
{
new() { Type = ValueType.Int, Int = 0 },
new() { Type = ValueType.Int, Int = 0 /* position within list?? */ },
new() { Type = ValueType.Int, Int = venturesToBuy },
new() { Type = ValueType.Int, Int = _selectedPurchaseOption!.Position },
new() { Type = ValueType.Int, Int = toBuy },
new() { Type = 0, Int = 0 },
new() { Type = ValueType.Bool, Byte = 1 },
new() { Type = ValueType.Bool, Byte = 0 },
@ -310,13 +345,22 @@ public class DeliverooPlugin : IDalamudPlugin
new() { Type = 0, Int = 0 }
};
addonExchange->FireCallback(9, selectReward);
_continueAt = DateTime.Now.AddSeconds(1);
CurrentStage = Stage.CloseGcExchange;
_continueAt = DateTime.Now.AddSeconds(0.5);
CurrentStage = Stage.ConfirmReward;
}
break;
}
case Stage.ConfirmReward:
if (SelectSelectYesno(0))
{
CurrentStage = Stage.CloseGcExchange;
_continueAt = DateTime.Now.AddSeconds(0.5);
}
break;
case Stage.CloseGcExchange:
{
if (TryGetAddonByName<AtkUnitBase>("GrandCompanyExchange", out var addonExchange) &&
@ -521,6 +565,18 @@ public class DeliverooPlugin : IDalamudPlugin
return false;
}
private unsafe bool SelectSelectYesno(int choice)
{
if (TryGetAddonByName<AddonSelectYesno>("SelectYesno", out var addonSelectYesno) &&
IsAddonReady(&addonSelectYesno->AtkUnitBase))
{
addonSelectYesno->AtkUnitBase.FireCallbackInt(choice);
return true;
}
return false;
}
private decimal GetSealMultiplier()
{
// priority seal allowance
@ -563,6 +619,7 @@ public class DeliverooPlugin : IDalamudPlugin
SelectRewardRank,
SelectRewardType,
SelectReward,
ConfirmReward,
CloseGcExchange,
Stop,

View File

@ -0,0 +1,39 @@
namespace Deliveroo;
internal sealed class SealPurchaseOption
{
public SealPurchaseOption(uint itemId, string name, PurchaseRank rank, PurchaseType type, int position,
int sealCost)
{
ItemId = itemId;
Name = name;
Rank = rank;
Type = type;
Position = position;
SealCost = sealCost;
}
public uint ItemId { get; }
public string Name { get; }
public PurchaseRank Rank { get; }
public PurchaseType Type { get; }
public int Position { get; }
public int SealCost { get; }
public enum PurchaseRank : int
{
First = 0,
Second = 1,
Third = 2,
Unknown = int.MaxValue,
}
public enum PurchaseType : int
{
Materiel = 1,
Weapons = 2,
Armor = 3,
Materials = 4,
Unknown = int.MaxValue,
}
}

View File

@ -1,14 +1,29 @@
using System.Numerics;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using FFXIVClientStructs.FFXIV.Client.Game;
using ImGuiNET;
namespace Deliveroo;
internal sealed class TurnInWindow : Window
{
private int _sealPurchaseSelected = 0;
private readonly List<SealPurchaseOption> _sealPurchaseOptions = new()
{
new SealPurchaseOption(0, "Buy Nothing", SealPurchaseOption.PurchaseRank.Unknown,
SealPurchaseOption.PurchaseType.Unknown, 0, 0),
new SealPurchaseOption(21072, "Venture", SealPurchaseOption.PurchaseRank.First,
SealPurchaseOption.PurchaseType.Materiel, 0, 200),
new SealPurchaseOption(5530, "Coke", SealPurchaseOption.PurchaseRank.Third,
SealPurchaseOption.PurchaseType.Materials, 31, 200),
};
public TurnInWindow()
: base("Turn In###DeliverooTurnIn")
: base("GC Delivery###DeliverooTurnIn")
{
Position = new Vector2(100, 100);
PositionCondition = ImGuiCond.FirstUseEver;
@ -17,9 +32,8 @@ internal sealed class TurnInWindow : Window
}
public bool State { get; set; }
public decimal Multiplier { get; set; }
public int CurrentVentureCount { get; set; }
public decimal Multiplier { private get; set; }
public SealPurchaseOption SelectedOption => _sealPurchaseOptions[_sealPurchaseSelected];
public string Debug { get; set; }
@ -42,12 +56,26 @@ internal sealed class TurnInWindow : Window
}
ImGui.Spacing();
int current = 0;
ImGui.Combo("", ref current, new string[] { $"Ventures ({CurrentVentureCount:N0})" }, 1);
ImGui.BeginDisabled(state);
string[] comboValues = _sealPurchaseOptions.Select(x =>
{
if (x.ItemId == 0)
return x.Name;
return $"{x.Name} ({GetItemCount(x.ItemId):N0}x)";
}).ToArray();
ImGui.Combo("", ref _sealPurchaseSelected, comboValues, comboValues.Length);
ImGui.EndDisabled();
ImGui.Unindent(27);
ImGui.Separator();
ImGui.Text($"Debug (State): {Debug}");
}
private unsafe int GetItemCount(uint itemId)
{
InventoryManager* inventoryManager = InventoryManager.Instance();
return inventoryManager->GetInventoryItemCount(itemId, false, false, false);
}
}