50 lines
1.2 KiB
C#
50 lines
1.2 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> _getEnduranceStatus;
|
|
|
|
public ArtisanIpc(IDalamudPluginInterface pluginInterface, ILogger<ArtisanIpc> logger)
|
|
{
|
|
_logger = logger;
|
|
_craftItem = pluginInterface.GetIpcSubscriber<ushort, int, object>("Artisan.CraftItem");
|
|
_getEnduranceStatus = pluginInterface.GetIpcSubscriber<bool>("Artisan.GetEnduranceStatus");
|
|
}
|
|
|
|
public bool CraftItem(ushort recipeId, int quantity)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation("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 bool IsCrafting()
|
|
{
|
|
try
|
|
{
|
|
return _getEnduranceStatus.InvokeFunc();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to check for Artisan endurance status");
|
|
return false;
|
|
}
|
|
}
|
|
}
|