2023-10-01 20:50:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|
|
|
|
using Workshoppa.GameData;
|
|
|
|
|
using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType;
|
|
|
|
|
|
|
|
|
|
namespace Workshoppa;
|
|
|
|
|
|
|
|
|
|
partial class WorkshopPlugin
|
|
|
|
|
{
|
|
|
|
|
private uint? _contributingItemId;
|
|
|
|
|
|
|
|
|
|
private void SelectCraftBranch()
|
|
|
|
|
{
|
|
|
|
|
if (SelectSelectString("contrib", 0, s => s.StartsWith("Contribute materials.")))
|
2023-10-01 21:33:21 +00:00
|
|
|
|
{
|
2023-10-01 20:50:21 +00:00
|
|
|
|
CurrentStage = Stage.ContributeMaterials;
|
2023-10-01 21:33:21 +00:00
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(1);
|
|
|
|
|
}
|
2023-10-01 20:50:21 +00:00
|
|
|
|
else if (SelectSelectString("advance", 0, s => s.StartsWith("Advance to the next phase of production.")))
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Information("Phase is complete");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
CurrentStage = Stage.TargetFabricationStation;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(3);
|
|
|
|
|
}
|
|
|
|
|
else if (SelectSelectString("complete", 0, s => s.StartsWith("Complete the construction of")))
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Information("Item is almost complete, confirming last cutscene");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
CurrentStage = Stage.TargetFabricationStation;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(3);
|
|
|
|
|
}
|
|
|
|
|
else if (SelectSelectString("collect", 0, s => s == "Collect finished product."))
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Information("Item is complete");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
CurrentStage = Stage.ConfirmCollectProduct;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(0.25);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private unsafe void ContributeMaterials()
|
|
|
|
|
{
|
|
|
|
|
AtkUnitBase* addonMaterialDelivery = GetMaterialDeliveryAddon();
|
|
|
|
|
if (addonMaterialDelivery == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CraftState? craftState = ReadCraftState(addonMaterialDelivery);
|
|
|
|
|
if (craftState == null || craftState.ResultItem == 0)
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Warning("Could not parse craft state");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < craftState.Items.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
var item = craftState.Items[i];
|
|
|
|
|
if (item.Finished)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!HasItemInSingleSlot(item.ItemId, item.ItemCountPerStep))
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Error($"Can't contribute item {item.ItemId} to craft, couldn't find {item.ItemCountPerStep}x in a single inventory slot");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
CurrentStage = Stage.RequestStop;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Information($"Contributing {item.ItemCountPerStep}x {item.ItemName}");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
_contributingItemId = item.ItemId;
|
|
|
|
|
var contributeMaterial = stackalloc AtkValue[]
|
|
|
|
|
{
|
|
|
|
|
new() { Type = ValueType.Int, Int = 0 },
|
|
|
|
|
new() { Type = ValueType.UInt, Int = i },
|
|
|
|
|
new() { Type = ValueType.UInt, UInt = item.ItemCountPerStep },
|
|
|
|
|
new() { Type = 0, Int = 0 }
|
|
|
|
|
};
|
|
|
|
|
addonMaterialDelivery->FireCallback(4, contributeMaterial);
|
|
|
|
|
CurrentStage = Stage.ConfirmMaterialDelivery;
|
2023-10-01 21:33:21 +00:00
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(0.5);
|
2023-10-01 20:50:21 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private unsafe void ConfirmMaterialDelivery()
|
|
|
|
|
{
|
|
|
|
|
AtkUnitBase* addonMaterialDelivery = GetMaterialDeliveryAddon();
|
|
|
|
|
if (addonMaterialDelivery == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CraftState? craftState = ReadCraftState(addonMaterialDelivery);
|
|
|
|
|
if (craftState == null || craftState.ResultItem == 0)
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Warning("Could not parse craft state");
|
2023-10-01 20:50:21 +00:00
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 22:07:36 +00:00
|
|
|
|
if (SelectSelectYesno(0, s => s == "Do you really want to trade a high-quality item?"))
|
|
|
|
|
{
|
|
|
|
|
_pluginLog.Information("Confirming HQ item turn in");
|
|
|
|
|
CurrentStage = Stage.ConfirmMaterialDelivery;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(0.1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-01 20:50:21 +00:00
|
|
|
|
if (SelectSelectYesno(0, s => s.StartsWith("Contribute") && s.EndsWith("to the company project?")))
|
|
|
|
|
{
|
|
|
|
|
var item = craftState.Items.Single(x => x.ItemId == _contributingItemId);
|
|
|
|
|
item.StepsComplete++;
|
|
|
|
|
if (craftState.IsPhaseComplete())
|
|
|
|
|
{
|
|
|
|
|
CurrentStage = Stage.TargetFabricationStation;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(0.5);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CurrentStage = Stage.ContributeMaterials;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-01 21:33:21 +00:00
|
|
|
|
else if (DateTime.Now > _continueAt.AddSeconds(20))
|
|
|
|
|
{
|
2023-10-04 22:07:36 +00:00
|
|
|
|
_pluginLog.Warning("No confirmation dialog, falling back to previous stage");
|
2023-10-01 21:33:21 +00:00
|
|
|
|
CurrentStage = Stage.ContributeMaterials;
|
|
|
|
|
}
|
2023-10-01 20:50:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ConfirmCollectProduct()
|
|
|
|
|
{
|
|
|
|
|
if (SelectSelectYesno(0, s => s.StartsWith("Retrieve")))
|
|
|
|
|
{
|
|
|
|
|
_configuration.CurrentlyCraftedItem = null;
|
|
|
|
|
_pluginInterface.SavePluginConfig(_configuration);
|
|
|
|
|
|
|
|
|
|
CurrentStage = Stage.TakeItemFromQueue;
|
|
|
|
|
_continueAt = DateTime.Now.AddSeconds(0.5);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|