Add 'purchase once'/'keep stocked' option as in ARC
This commit is contained in:
parent
eea9825723
commit
11420ab403
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
|
using Dalamud.Game.Text;
|
||||||
using Deliveroo.GameData;
|
using Deliveroo.GameData;
|
||||||
|
|
||||||
namespace Deliveroo;
|
namespace Deliveroo;
|
||||||
@ -29,6 +30,23 @@ internal sealed class Configuration : IPluginConfiguration
|
|||||||
public uint ItemId { get; set; }
|
public uint ItemId { get; set; }
|
||||||
public int Limit { get; set; }
|
public int Limit { get; set; }
|
||||||
public bool Enabled { get; set; } = true;
|
public bool Enabled { get; set; } = true;
|
||||||
|
public PurchaseType Type { get; set; } = PurchaseType.KeepStocked;
|
||||||
|
|
||||||
|
public string GetIcon()
|
||||||
|
{
|
||||||
|
return Type switch
|
||||||
|
{
|
||||||
|
PurchaseType.PurchaseOneTime => SeIconChar.BoxedNumber1.ToIconString(),
|
||||||
|
PurchaseType.KeepStocked => SeIconChar.Circle.ToIconString(),
|
||||||
|
_ => SeIconChar.BoxedQuestionMark.ToIconString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PurchaseType
|
||||||
|
{
|
||||||
|
PurchaseOneTime,
|
||||||
|
KeepStocked,
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddVentureIfNoItemToPurchaseSelected()
|
public bool AddVentureIfNoItemToPurchaseSelected()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
<Version>2.26</Version>
|
<Version>3.0</Version>
|
||||||
<LangVersion>11.0</LangVersion>
|
<LangVersion>11.0</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
@ -38,9 +38,17 @@ partial class DeliverooPlugin
|
|||||||
toBuy = Math.Min(toBuy, 99);
|
toBuy = Math.Min(toBuy, 99);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request.Type == Configuration.PurchaseType.KeepStocked)
|
||||||
|
{
|
||||||
if (GetItemCount(request.ItemId) + toBuy < request.EffectiveLimit)
|
if (GetItemCount(request.ItemId) + toBuy < request.EffectiveLimit)
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (toBuy < request.EffectiveLimit)
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -139,7 +147,10 @@ partial class DeliverooPlugin
|
|||||||
{
|
{
|
||||||
_pluginLog.Information($"Selecting item {itemId}, {i}");
|
_pluginLog.Information($"Selecting item {itemId}, {i}");
|
||||||
long toBuy = (GetCurrentSealCount() - EffectiveReservedSealCount) / item.SealCost;
|
long toBuy = (GetCurrentSealCount() - EffectiveReservedSealCount) / item.SealCost;
|
||||||
|
if (item.Type == Configuration.PurchaseType.KeepStocked)
|
||||||
toBuy = Math.Min(toBuy, item.EffectiveLimit - GetItemCount(item.ItemId));
|
toBuy = Math.Min(toBuy, item.EffectiveLimit - GetItemCount(item.ItemId));
|
||||||
|
else
|
||||||
|
toBuy = Math.Min(toBuy, item.EffectiveLimit);
|
||||||
|
|
||||||
if (item.ItemId != ItemIds.Venture && !_configuration.IgnoreCertainLimitations)
|
if (item.ItemId != ItemIds.Venture && !_configuration.IgnoreCertainLimitations)
|
||||||
toBuy = Math.Min(toBuy, 99);
|
toBuy = Math.Min(toBuy, 99);
|
||||||
@ -150,6 +161,7 @@ partial class DeliverooPlugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item.TemporaryPurchaseQuantity = toBuy;
|
||||||
_chatGui.Print(new SeString(new TextPayload($"Buying {toBuy}x "))
|
_chatGui.Print(new SeString(new TextPayload($"Buying {toBuy}x "))
|
||||||
.Append(SeString.CreateItemLink(item.ItemId))
|
.Append(SeString.CreateItemLink(item.ItemId))
|
||||||
.Append(new TextPayload("...")));
|
.Append(new TextPayload("...")));
|
||||||
|
@ -27,9 +27,12 @@ partial class DeliverooPlugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_pluginLog.Information($"Selecting 'yes' ({text})");
|
_pluginLog.Information($"Selecting 'yes' ({text}) (callback = {item.OnPurchase}, qty = {item.TemporaryPurchaseQuantity})");
|
||||||
addonSelectYesNo->AtkUnitBase.FireCallbackInt(0);
|
addonSelectYesNo->AtkUnitBase.FireCallbackInt(0);
|
||||||
|
|
||||||
|
item.OnPurchase?.Invoke((int)item.TemporaryPurchaseQuantity);
|
||||||
|
item.TemporaryPurchaseQuantity = 0;
|
||||||
|
|
||||||
var nextItem = GetNextItemToPurchase(item);
|
var nextItem = GetNextItemToPurchase(item);
|
||||||
if (nextItem != null && GetCurrentSealCount() >= EffectiveReservedSealCount + nextItem.SealCost)
|
if (nextItem != null && GetCurrentSealCount() >= EffectiveReservedSealCount + nextItem.SealCost)
|
||||||
CurrentStage = Stage.SelectRewardTier;
|
CurrentStage = Stage.SelectRewardTier;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Deliveroo.GameData;
|
using System;
|
||||||
|
using Deliveroo.GameData;
|
||||||
|
|
||||||
namespace Deliveroo;
|
namespace Deliveroo;
|
||||||
|
|
||||||
@ -6,9 +7,13 @@ internal sealed class PurchaseItemRequest
|
|||||||
{
|
{
|
||||||
public required uint ItemId { get; init; }
|
public required uint ItemId { get; init; }
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
public required uint EffectiveLimit { get; init; }
|
public required uint EffectiveLimit { get; set; }
|
||||||
public required uint SealCost { get; init; }
|
public required uint SealCost { get; init; }
|
||||||
public required RewardTier Tier { get; init; }
|
public required RewardTier Tier { get; init; }
|
||||||
public required RewardSubCategory SubCategory { get; init; }
|
public required RewardSubCategory SubCategory { get; init; }
|
||||||
public required uint StackSize { get; init; }
|
public required uint StackSize { get; init; }
|
||||||
|
public required Configuration.PurchaseType Type { get; init; }
|
||||||
|
|
||||||
|
public Action<int>? OnPurchase { get; set; }
|
||||||
|
public long TemporaryPurchaseQuantity { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace Deliveroo.Windows;
|
|||||||
|
|
||||||
internal sealed class TurnInWindow : LImGui.LWindow
|
internal sealed class TurnInWindow : LImGui.LWindow
|
||||||
{
|
{
|
||||||
private readonly IReadOnlyList<InventoryType> _inventoryTypes = new[]
|
private static readonly IReadOnlyList<InventoryType> InventoryTypes = new[]
|
||||||
{
|
{
|
||||||
InventoryType.Inventory1,
|
InventoryType.Inventory1,
|
||||||
InventoryType.Inventory2,
|
InventoryType.Inventory2,
|
||||||
@ -40,6 +40,8 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
InventoryType.EquippedItems
|
InventoryType.EquippedItems
|
||||||
}.AsReadOnly();
|
}.AsReadOnly();
|
||||||
|
|
||||||
|
private static readonly string[] StockingTypeLabels = { "Purchase Once", "Keep in Stock" };
|
||||||
|
|
||||||
private readonly DeliverooPlugin _plugin;
|
private readonly DeliverooPlugin _plugin;
|
||||||
private readonly DalamudPluginInterface _pluginInterface;
|
private readonly DalamudPluginInterface _pluginInterface;
|
||||||
private readonly Configuration _configuration;
|
private readonly Configuration _configuration;
|
||||||
@ -116,10 +118,13 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
return ItemsWrapper.GetItemsToPurchase()
|
return ItemsWrapper.GetItemsToPurchase()
|
||||||
.Where(x => x.ItemId != GcRewardItem.None.ItemId)
|
.Where(x => x.ItemId != GcRewardItem.None.ItemId)
|
||||||
.Where(x => x.Enabled)
|
.Where(x => x.Enabled)
|
||||||
|
.Where(x => x.Type == Configuration.PurchaseType.KeepStocked || x.Limit > 0)
|
||||||
.Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(x.ItemId) })
|
.Select(x => new { Item = x, Reward = _gcRewardsCache.GetReward(x.ItemId) })
|
||||||
.Where(x => x.Reward.GrandCompanies.Contains(grandCompany))
|
.Where(x => x.Reward.GrandCompanies.Contains(grandCompany))
|
||||||
.Where(x => x.Reward.RequiredRank <= rank)
|
.Where(x => x.Reward.RequiredRank <= rank)
|
||||||
.Select(x => new PurchaseItemRequest
|
.Select(x =>
|
||||||
|
{
|
||||||
|
var request = new PurchaseItemRequest
|
||||||
{
|
{
|
||||||
ItemId = x.Item.ItemId,
|
ItemId = x.Item.ItemId,
|
||||||
Name = x.Reward.Name,
|
Name = x.Reward.Name,
|
||||||
@ -132,6 +137,19 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
Tier = x.Reward.Tier,
|
Tier = x.Reward.Tier,
|
||||||
SubCategory = x.Reward.SubCategory,
|
SubCategory = x.Reward.SubCategory,
|
||||||
StackSize = x.Reward.StackSize,
|
StackSize = x.Reward.StackSize,
|
||||||
|
Type = x.Item.Type,
|
||||||
|
};
|
||||||
|
if (x.Item.Type == Configuration.PurchaseType.PurchaseOneTime)
|
||||||
|
{
|
||||||
|
request.OnPurchase = qty =>
|
||||||
|
{
|
||||||
|
request.EffectiveLimit -= (uint)qty;
|
||||||
|
x.Item.Limit -= qty;
|
||||||
|
ItemsWrapper.Save();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -153,7 +171,8 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
ImGui.TextColored(ImGuiColors.DalamudRed, "You do not have the required rank for Expert Delivery.");
|
ImGui.TextColored(ImGuiColors.DalamudRed, "You do not have the required rank for Expert Delivery.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (_configuration.BehaviorOnOtherWorld == Configuration.EBehaviorOnOtherWorld.DisableTurnIn && !IsOnHomeWorld)
|
else if (_configuration.BehaviorOnOtherWorld == Configuration.EBehaviorOnOtherWorld.DisableTurnIn &&
|
||||||
|
!IsOnHomeWorld)
|
||||||
{
|
{
|
||||||
State = false;
|
State = false;
|
||||||
ImGui.TextColored(ImGuiColors.DalamudRed, "You are not on your home world.");
|
ImGui.TextColored(ImGuiColors.DalamudRed, "You are not on your home world.");
|
||||||
@ -248,17 +267,40 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
for (int i = 0; i < itemsWrapper.GetItemsToPurchase().Count; ++i)
|
for (int i = 0; i < itemsWrapper.GetItemsToPurchase().Count; ++i)
|
||||||
{
|
{
|
||||||
ImGui.PushID($"ItemToBuy{i}");
|
ImGui.PushID($"ItemToBuy{i}");
|
||||||
var item = itemsWrapper.GetItemsToPurchase()[i];
|
Configuration.PurchasePriority item = itemsWrapper.GetItemsToPurchase()[i];
|
||||||
|
|
||||||
|
float indentX = ImGui.GetCursorPosX();
|
||||||
bool enabled = item.Enabled;
|
bool enabled = item.Enabled;
|
||||||
ImGui.PushID($"Enable{i}");
|
int popColors = 0;
|
||||||
if (ImGui.Checkbox("", ref enabled))
|
if (!enabled)
|
||||||
|
{
|
||||||
|
ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(1f, 0.5f, 0.35f, 1f));
|
||||||
|
popColors++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.Button($"{item.GetIcon()}"))
|
||||||
|
ImGui.OpenPopup($"Configure{i}");
|
||||||
|
|
||||||
|
ImGui.PopStyleColor(popColors);
|
||||||
|
|
||||||
|
if (ImGui.BeginPopup($"Configure{i}"))
|
||||||
|
{
|
||||||
|
if (ImGui.Checkbox($"Enabled##Enabled{i}", ref enabled))
|
||||||
{
|
{
|
||||||
item.Enabled = enabled;
|
item.Enabled = enabled;
|
||||||
itemsWrapper.Save();
|
itemsWrapper.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.PopID();
|
ImGui.SetNextItemWidth(150 * ImGuiHelpers.GlobalScale);
|
||||||
|
int type = (int)item.Type;
|
||||||
|
if (ImGui.Combo($"##Type{i}", ref type, StockingTypeLabels, StockingTypeLabels.Length))
|
||||||
|
{
|
||||||
|
item.Type = (Configuration.PurchaseType)type;
|
||||||
|
itemsWrapper.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.SameLine(0, 3);
|
ImGui.SameLine(0, 3);
|
||||||
ImGui.BeginDisabled(!enabled);
|
ImGui.BeginDisabled(!enabled);
|
||||||
@ -280,6 +322,8 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
ImGui.SameLine(0, 3);
|
ImGui.SameLine(0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
indentX = ImGui.GetCursorPosX() - indentX;
|
||||||
|
|
||||||
if (ImGui.Combo("", ref comboValueIndex, comboValues.Select(x => x.Name).ToArray(), comboValues.Count))
|
if (ImGui.Combo("", ref comboValueIndex, comboValues.Select(x => x.Name).ToArray(), comboValues.Count))
|
||||||
{
|
{
|
||||||
comboItem = comboValues[comboValueIndex];
|
comboItem = comboValues[comboValueIndex];
|
||||||
@ -318,13 +362,16 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
ImGui.Indent(52);
|
ImGui.Indent(indentX);
|
||||||
if (comboValueIndex > 0)
|
if (comboValueIndex > 0)
|
||||||
{
|
{
|
||||||
ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 130);
|
ImGui.SetNextItemWidth(ImGuiHelpers.GlobalScale * 130);
|
||||||
int limit = Math.Min(item.Limit, (int)comboItem.Item.InventoryLimit);
|
int limit = Math.Min(item.Limit, (int)comboItem.Item.InventoryLimit);
|
||||||
int stepSize = comboItem.Item.StackSize < 99 ? 1 : 50;
|
int stepSize = comboItem.Item.StackSize < 99 ? 1 : 50;
|
||||||
if (ImGui.InputInt("Maximum items to buy", ref limit, stepSize, stepSize * 10))
|
string label = item.Type == Configuration.PurchaseType.KeepStocked
|
||||||
|
? "Maximum items to buy"
|
||||||
|
: "Remaining items to buy";
|
||||||
|
if (ImGui.InputInt(label, ref limit, stepSize, stepSize * 10))
|
||||||
{
|
{
|
||||||
item.Limit = Math.Min(Math.Max(0, limit), (int)comboItem.Item.InventoryLimit);
|
item.Limit = Math.Min(Math.Max(0, limit), (int)comboItem.Item.InventoryLimit);
|
||||||
itemsWrapper.Save();
|
itemsWrapper.Save();
|
||||||
@ -350,7 +397,7 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Unindent(52);
|
ImGui.Unindent(indentX);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.PopID();
|
ImGui.PopID();
|
||||||
@ -403,7 +450,7 @@ internal sealed class TurnInWindow : LImGui.LWindow
|
|||||||
{
|
{
|
||||||
uint slotsThatCanBeUsed = 0;
|
uint slotsThatCanBeUsed = 0;
|
||||||
InventoryManager* inventoryManager = InventoryManager.Instance();
|
InventoryManager* inventoryManager = InventoryManager.Instance();
|
||||||
foreach (var inventoryType in _inventoryTypes)
|
foreach (var inventoryType in InventoryTypes)
|
||||||
{
|
{
|
||||||
var container = inventoryManager->GetInventoryContainer(inventoryType);
|
var container = inventoryManager->GetInventoryContainer(inventoryType);
|
||||||
for (int i = 0; i < container->Size; ++i)
|
for (int i = 0; i < container->Size; ++i)
|
||||||
|
Loading…
Reference in New Issue
Block a user