Workship/Workshoppa/WorkshopPlugin.CraftingLog.cs

131 lines
4.5 KiB
C#
Raw Permalink Normal View History

2023-10-01 20:50:21 +00:00
using System;
using System.Linq;
using Dalamud.Game.ClientState.Objects.Types;
using FFXIVClientStructs.FFXIV.Component.GUI;
using LLib.GameUI;
2023-10-01 20:50:21 +00:00
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
namespace Workshoppa;
partial class WorkshopPlugin
{
2024-07-04 10:04:50 +00:00
private void InteractWithFabricationStation(IGameObject fabricationStation)
2023-10-19 18:46:01 +00:00
=> InteractWithTarget(fabricationStation);
2023-10-01 20:50:21 +00:00
private void TakeItemFromQueue()
{
if (_configuration.CurrentlyCraftedItem == null)
{
while (_configuration.ItemQueue.Count > 0 && _configuration.CurrentlyCraftedItem == null)
{
var firstItem = _configuration.ItemQueue[0];
if (firstItem.Quantity > 0)
{
_configuration.CurrentlyCraftedItem = new Configuration.CurrentItem
{
WorkshopItemId = firstItem.WorkshopItemId,
};
if (firstItem.Quantity > 1)
firstItem.Quantity--;
else
_configuration.ItemQueue.Remove(firstItem);
}
else
_configuration.ItemQueue.Remove(firstItem);
}
_pluginInterface.SavePluginConfig(_configuration);
if (_configuration.CurrentlyCraftedItem != null)
CurrentStage = Stage.TargetFabricationStation;
else
CurrentStage = Stage.RequestStop;
}
else
CurrentStage = Stage.TargetFabricationStation;
}
private void OpenCraftingLog()
{
if (SelectSelectString("craftlog", 0, s => s == _gameStrings.ViewCraftingLog))
CurrentStage = Stage.SelectCraftCategory;
}
2023-10-01 20:50:21 +00:00
private unsafe void SelectCraftCategory()
{
AtkUnitBase* addonCraftingLog = GetCompanyCraftingLogAddon();
if (addonCraftingLog == null)
return;
var craft = GetCurrentCraft();
2023-10-04 22:07:36 +00:00
_pluginLog.Information($"Selecting category {craft.Category} and type {craft.Type}");
2023-10-01 20:50:21 +00:00
var selectCategory = stackalloc AtkValue[]
{
new() { Type = ValueType.Int, Int = 2 },
new() { Type = 0, Int = 0 },
new() { Type = ValueType.UInt, UInt = (uint)craft.Category },
new() { Type = ValueType.UInt, UInt = craft.Type },
new() { Type = ValueType.UInt, Int = 0 },
new() { Type = ValueType.UInt, Int = 0 },
new() { Type = ValueType.UInt, Int = 0 },
new() { Type = 0, Int = 0 }
};
addonCraftingLog->FireCallback(8, selectCategory);
CurrentStage = Stage.SelectCraft;
_continueAt = DateTime.Now.AddSeconds(0.1);
}
private unsafe void SelectCraft()
{
AtkUnitBase* addonCraftingLog = GetCompanyCraftingLogAddon();
if (addonCraftingLog == null)
return;
var craft = GetCurrentCraft();
var atkValues = addonCraftingLog->AtkValues;
uint shownItemCount = atkValues[13].UInt;
var visibleItems = Enumerable.Range(0, (int)shownItemCount)
.Select(i => new
{
WorkshopItemId = atkValues[14 + 4 * i].UInt,
Name = atkValues[17 + 4 * i].ReadAtkString(),
2023-10-01 20:50:21 +00:00
})
.ToList();
if (visibleItems.All(x => x.WorkshopItemId != craft.WorkshopItemId))
{
2023-10-04 22:07:36 +00:00
_pluginLog.Error($"Could not find {craft.Name} in current list, is it unlocked?");
2023-10-01 20:50:21 +00:00
CurrentStage = Stage.RequestStop;
return;
}
2023-10-04 22:07:36 +00:00
_pluginLog.Information($"Selecting craft {craft.WorkshopItemId}");
2023-10-01 20:50:21 +00:00
var selectCraft = stackalloc AtkValue[]
{
new() { Type = ValueType.Int, Int = 1 },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
new() { Type = ValueType.UInt, UInt = craft.WorkshopItemId },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 },
new() { Type = 0, Int = 0 }
};
addonCraftingLog->FireCallback(8, selectCraft);
CurrentStage = Stage.ConfirmCraft;
_continueAt = DateTime.Now.AddSeconds(0.1);
}
private void ConfirmCraft()
{
2024-03-20 18:52:54 +00:00
if (SelectSelectYesno(0, s => s.StartsWith("Craft ", StringComparison.Ordinal)))
2023-10-01 20:50:21 +00:00
{
_configuration.CurrentlyCraftedItem!.StartedCrafting = true;
_pluginInterface.SavePluginConfig(_configuration);
CurrentStage = Stage.TargetFabricationStation;
}
}
}