qstbak/Questionable/Questionable.Controller.Steps.Common/SendNotification.cs
2025-10-09 07:47:19 +10:00

159 lines
4.3 KiB
C#

using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Plugin.Services;
using Questionable.Data;
using Questionable.External;
using Questionable.Model;
using Questionable.Model.Questing;
namespace Questionable.Controller.Steps.Common;
internal static class SendNotification
{
internal sealed class Factory(AutomatonIpc automatonIpc, AutoDutyIpc autoDutyIpc, BossModIpc bossModIpc, TerritoryData territoryData) : SimpleTaskFactory()
{
public override ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step)
{
switch (step.InteractionType)
{
case EInteractionType.Snipe:
if (!automatonIpc.IsAutoSnipeEnabled)
{
return new Task(step.InteractionType, step.Comment);
}
break;
case EInteractionType.Duty:
if (!autoDutyIpc.IsConfiguredToRunContent(step.DutyOptions))
{
EInteractionType interactionType = step.InteractionType;
uint? num = step.DutyOptions?.ContentFinderConditionId;
object comment;
if (num.HasValue)
{
uint valueOrDefault = num.GetValueOrDefault();
comment = territoryData.GetContentFinderCondition(valueOrDefault)?.Name;
}
else
{
comment = step.Comment;
}
return new Task(interactionType, (string?)comment);
}
break;
case EInteractionType.SinglePlayerDuty:
if (!bossModIpc.IsConfiguredToRunSoloInstance(quest.Id, step.SinglePlayerDutyOptions))
{
return new Task(step.InteractionType, quest.Info.Name);
}
break;
}
return null;
}
}
internal sealed record Task(EInteractionType InteractionType, string? Comment) : ITask
{
public override string ToString()
{
return "SendNotification";
}
}
internal sealed class Executor(NotificationMasterIpc notificationMasterIpc, IChatGui chatGui, Configuration configuration) : TaskExecutor<Task>()
{
protected override bool Start()
{
if (!configuration.Notifications.Enabled)
{
return false;
}
string text;
switch (base.Task.InteractionType)
{
case EInteractionType.Duty:
text = "Duty";
break;
case EInteractionType.SinglePlayerDuty:
text = "Single player duty";
break;
case EInteractionType.WaitForManualProgress:
case EInteractionType.Snipe:
case EInteractionType.Instruction:
text = "Manual interaction required";
break;
default:
text = $"{base.Task.InteractionType}";
break;
}
string text2 = text;
if (!string.IsNullOrEmpty(base.Task.Comment))
{
text2 = text2 + " - " + base.Task.Comment;
}
if (configuration.Notifications.ChatType != XivChatType.None)
{
XivChatEntry xivChatEntry;
switch (configuration.Notifications.ChatType)
{
case XivChatType.Say:
case XivChatType.Shout:
case XivChatType.TellOutgoing:
case XivChatType.TellIncoming:
case XivChatType.Party:
case XivChatType.Alliance:
case XivChatType.Ls1:
case XivChatType.Ls2:
case XivChatType.Ls3:
case XivChatType.Ls4:
case XivChatType.Ls5:
case XivChatType.Ls6:
case XivChatType.Ls7:
case XivChatType.Ls8:
case XivChatType.FreeCompany:
case XivChatType.NoviceNetwork:
case XivChatType.Yell:
case XivChatType.CrossParty:
case XivChatType.PvPTeam:
case XivChatType.CrossLinkShell1:
case XivChatType.NPCDialogue:
case XivChatType.NPCDialogueAnnouncements:
case XivChatType.CrossLinkShell2:
case XivChatType.CrossLinkShell3:
case XivChatType.CrossLinkShell4:
case XivChatType.CrossLinkShell5:
case XivChatType.CrossLinkShell6:
case XivChatType.CrossLinkShell7:
case XivChatType.CrossLinkShell8:
xivChatEntry = new XivChatEntry
{
Message = text2,
Type = configuration.Notifications.ChatType,
Name = new SeStringBuilder().AddUiForeground("Questionable", 576).Build()
};
break;
default:
xivChatEntry = new XivChatEntry
{
Message = new SeStringBuilder().AddUiForeground("[Questionable] ", 576).Append(text2).Build(),
Type = configuration.Notifications.ChatType
};
break;
}
XivChatEntry chat = xivChatEntry;
chatGui.Print(chat);
}
notificationMasterIpc.Notify(text2);
return true;
}
public override ETaskResult Update()
{
return ETaskResult.TaskComplete;
}
public override bool ShouldInterruptOnDamage()
{
return false;
}
}
}