125 lines
2.8 KiB
C#
125 lines
2.8 KiB
C#
using Dalamud.Plugin;
|
|
using Dalamud.Plugin.Ipc;
|
|
using Dalamud.Plugin.Ipc.Exceptions;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Questionable.External;
|
|
|
|
internal sealed class ArtisanIpc
|
|
{
|
|
private readonly ILogger<ArtisanIpc> _logger;
|
|
|
|
private readonly ICallGateSubscriber<ushort, int, object> _craftItem;
|
|
|
|
private readonly ICallGateSubscriber<bool> _isBusy;
|
|
|
|
private readonly ICallGateSubscriber<bool> _getEnduranceStatus;
|
|
|
|
private readonly ICallGateSubscriber<bool, object> _setEnduranceStatus;
|
|
|
|
private readonly ICallGateSubscriber<bool> _getStopRequest;
|
|
|
|
private readonly ICallGateSubscriber<bool, object> _setStopRequest;
|
|
|
|
public ArtisanIpc(IDalamudPluginInterface pluginInterface, ILogger<ArtisanIpc> logger)
|
|
{
|
|
_logger = logger;
|
|
_craftItem = pluginInterface.GetIpcSubscriber<ushort, int, object>("Artisan.CraftItem");
|
|
_isBusy = pluginInterface.GetIpcSubscriber<bool>("Artisan.IsBusy");
|
|
_getEnduranceStatus = pluginInterface.GetIpcSubscriber<bool>("Artisan.GetEnduranceStatus");
|
|
_setEnduranceStatus = pluginInterface.GetIpcSubscriber<bool, object>("Artisan.SetEnduranceStatus");
|
|
_getStopRequest = pluginInterface.GetIpcSubscriber<bool>("Artisan.GetStopRequest");
|
|
_setStopRequest = pluginInterface.GetIpcSubscriber<bool, object>("Artisan.SetStopRequest");
|
|
}
|
|
|
|
public bool IsAvailable()
|
|
{
|
|
try
|
|
{
|
|
_isBusy.InvokeFunc();
|
|
return true;
|
|
}
|
|
catch (IpcError)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool IsBusy()
|
|
{
|
|
try
|
|
{
|
|
return _isBusy.InvokeFunc();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to check Artisan busy status");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool IsCrafting()
|
|
{
|
|
try
|
|
{
|
|
return _isBusy.InvokeFunc() || _getEnduranceStatus.InvokeFunc();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to check Artisan crafting status");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool CraftItem(ushort recipeId, int quantity)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogDebug("Attempting to craft {Quantity} items with recipe {RecipeId} with Artisan", quantity, recipeId);
|
|
_craftItem.InvokeAction(recipeId, quantity);
|
|
return true;
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to craft items");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void SetEnduranceStatus(bool enabled)
|
|
{
|
|
try
|
|
{
|
|
_setEnduranceStatus.InvokeAction(enabled);
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to set Artisan endurance status");
|
|
}
|
|
}
|
|
|
|
public bool GetStopRequest()
|
|
{
|
|
try
|
|
{
|
|
return _getStopRequest.InvokeFunc();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to check Artisan stop request");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void SetStopRequest(bool stop)
|
|
{
|
|
try
|
|
{
|
|
_setStopRequest.InvokeAction(stop);
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to set Artisan stop request");
|
|
}
|
|
}
|
|
}
|