qstbak/Questionable/Questionable.Functions/ChatFunctions.cs
2026-08-17 20:29:32 +10:00

56 lines
1.6 KiB
C#

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Plugin.Services;
using LLib;
using Lumina.Excel.Sheets;
using Questionable.Model.Questing;
namespace Questionable.Functions;
internal sealed class ChatFunctions
{
private readonly ReadOnlyDictionary<EEmote, string> _emoteCommands;
private readonly GameFunctions _gameFunctions;
private readonly ITargetManager _targetManager;
public ChatFunctions(IDataManager dataManager, GameFunctions gameFunctions, ITargetManager targetManager)
{
_gameFunctions = gameFunctions;
_targetManager = targetManager;
_emoteCommands = (from x in dataManager.GetExcelSheet<Emote>()
where x.RowId != 0
where x.TextCommand.IsValid
select (RowId: x.RowId, Command: x.TextCommand.Value.Command.ToString()) into x
where !string.IsNullOrEmpty(x.Command) && x.Command.StartsWith('/')
select x).ToDictionary<(uint, string), EEmote, string>(((uint RowId, string Command) x) => (EEmote)x.RowId, ((uint RowId, string Command) x) => x.Command).AsReadOnly();
}
public static void ExecuteCommand(string command)
{
if (command.StartsWith('/'))
{
ChatHelper.SendCommand(command);
}
}
public bool UseEmote(uint dataId, EEmote emote)
{
IGameObject gameObject = _gameFunctions.FindObjectByDataId(dataId);
if (gameObject != null)
{
_targetManager.Target = gameObject;
ExecuteCommand(_emoteCommands[emote] + " motion");
return true;
}
return false;
}
public void UseEmote(EEmote emote)
{
ExecuteCommand(_emoteCommands[emote] + " motion");
}
}