Use Lifestream for firmament teleporting

This commit is contained in:
Liza 2024-11-19 19:01:53 +01:00
parent 472aeac04a
commit 1d9198eacd
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 29 additions and 60 deletions

View File

@ -98,7 +98,6 @@ internal sealed class InteractionUiController : IDisposable
_addonLifecycle.RegisterListener(AddonEvent.PostSetup, "SelectYesno", SelectYesnoPostSetup); _addonLifecycle.RegisterListener(AddonEvent.PostSetup, "SelectYesno", SelectYesnoPostSetup);
_addonLifecycle.RegisterListener(AddonEvent.PostSetup, "PointMenu", PointMenuPostSetup); _addonLifecycle.RegisterListener(AddonEvent.PostSetup, "PointMenu", PointMenuPostSetup);
_addonLifecycle.RegisterListener(AddonEvent.PostSetup, "HousingSelectBlock", HousingSelectBlockPostSetup); _addonLifecycle.RegisterListener(AddonEvent.PostSetup, "HousingSelectBlock", HousingSelectBlockPostSetup);
_addonLifecycle.RegisterListener(AddonEvent.PostSetup, "TelepotTown", TeleportTownPostSetup);
unsafe unsafe
{ {
@ -848,46 +847,6 @@ internal sealed class InteractionUiController : IDisposable
addon->FireCallbackInt(0); addon->FireCallbackInt(0);
} }
private void TeleportTownPostSetup(AddonEvent type, AddonArgs args)
{
if (ShouldHandleUiInteractions &&
_questController.HasCurrentTaskMatching(out AethernetShortcut.Task? aethernetShortcut) &&
aethernetShortcut.From.IsFirmamentAetheryte())
{
// this might be better via atkvalues; but this works for now
uint toIndex = aethernetShortcut.To switch
{
EAetheryteLocation.FirmamentMendicantsCourt => 0,
EAetheryteLocation.FirmamentMattock => 1,
EAetheryteLocation.FirmamentNewNest => 2,
EAetheryteLocation.FirmanentSaintRoellesDais => 3,
EAetheryteLocation.FirmamentFeatherfall => 4,
EAetheryteLocation.FirmamentHoarfrostHall => 5,
EAetheryteLocation.FirmamentWesternRisensongQuarter => 6,
EAetheryteLocation.FIrmamentEasternRisensongQuarter => 7,
_ => uint.MaxValue,
};
if (toIndex == uint.MaxValue)
return;
_logger.LogInformation("Teleporting to {ToName} with menu index {ToIndex}", aethernetShortcut.From,
toIndex);
unsafe
{
var teleportToDestination = stackalloc AtkValue[]
{
new() { Type = ValueType.Int, Int = 11 },
new() { Type = ValueType.UInt, UInt = toIndex }
};
var addon = (AtkUnitBase*)args.Addon;
addon->FireCallback(2, teleportToDestination);
addon->FireCallback(2, teleportToDestination, true);
}
}
}
private StringOrRegex? ResolveReference(Quest? quest, string? excelSheet, ExcelRef? excelRef, bool isRegExp) private StringOrRegex? ResolveReference(Quest? quest, string? excelSheet, ExcelRef? excelRef, bool isRegExp)
{ {
if (excelRef == null) if (excelRef == null)
@ -905,7 +864,6 @@ internal sealed class InteractionUiController : IDisposable
public void Dispose() public void Dispose()
{ {
_addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "TelepotTown", TeleportTownPostSetup);
_addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "HousingSelectBlock", HousingSelectBlockPostSetup); _addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "HousingSelectBlock", HousingSelectBlockPostSetup);
_addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "PointMenu", PointMenuPostSetup); _addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "PointMenu", PointMenuPostSetup);
_addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "SelectYesno", SelectYesnoPostSetup); _addonLifecycle.UnregisterListener(AddonEvent.PostSetup, "SelectYesno", SelectYesnoPostSetup);

View File

@ -205,17 +205,9 @@ internal static class AethernetShortcut
private void DoTeleport() private void DoTeleport()
{ {
if (Task.From.IsFirmamentAetheryte()) logger.LogInformation("Using lifestream to teleport to {Destination}", Task.To);
{ lifestreamIpc.Teleport(Task.To);
logger.LogInformation("Using manual teleport interaction"); _teleported = true;
_teleported = gameFunctions.InteractWith((uint)Task.From, ObjectKind.EventObj);
}
else
{
logger.LogInformation("Using lifestream to teleport to {Destination}", Task.To);
lifestreamIpc.Teleport(Task.To);
_teleported = true;
}
} }
public override ETaskResult Update() public override ETaskResult Update()

View File

@ -1,5 +1,9 @@
using Dalamud.Plugin; using System.Collections.Generic;
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc;
using Dalamud.Plugin.Services;
using Lumina.Excel.Sheets;
using Microsoft.Extensions.Logging;
using Questionable.Data; using Questionable.Data;
using Questionable.Model.Common; using Questionable.Model.Common;
@ -8,25 +12,40 @@ namespace Questionable.External;
internal sealed class LifestreamIpc internal sealed class LifestreamIpc
{ {
private readonly AetheryteData _aetheryteData; private readonly AetheryteData _aetheryteData;
private readonly IDataManager _dataManager;
private readonly ILogger<LifestreamIpc> _logger;
private readonly ICallGateSubscriber<string, bool> _aethernetTeleport; private readonly ICallGateSubscriber<string, bool> _aethernetTeleport;
public LifestreamIpc(IDalamudPluginInterface pluginInterface, AetheryteData aetheryteData) public LifestreamIpc(IDalamudPluginInterface pluginInterface, AetheryteData aetheryteData, IDataManager dataManager, ILogger<LifestreamIpc> logger)
{ {
_aetheryteData = aetheryteData; _aetheryteData = aetheryteData;
_dataManager = dataManager;
_logger = logger;
_aethernetTeleport = pluginInterface.GetIpcSubscriber<string, bool>("Lifestream.AethernetTeleport"); _aethernetTeleport = pluginInterface.GetIpcSubscriber<string, bool>("Lifestream.AethernetTeleport");
} }
public bool Teleport(EAetheryteLocation aetheryteLocation) public bool Teleport(EAetheryteLocation aetheryteLocation)
{ {
if (aetheryteLocation == EAetheryteLocation.IshgardFirmament) string? name = aetheryteLocation switch
{ {
// TODO does this even work on non-EN clients? EAetheryteLocation.IshgardFirmament => "Firmament",
return _aethernetTeleport.InvokeFunc("Firmament"); EAetheryteLocation.FirmamentMendicantsCourt => GetPlaceName(3436),
} EAetheryteLocation.FirmamentMattock => GetPlaceName(3473),
EAetheryteLocation.FirmamentNewNest => GetPlaceName(3475),
EAetheryteLocation.FirmanentSaintRoellesDais => GetPlaceName(3474),
EAetheryteLocation.FirmamentFeatherfall => GetPlaceName(3525),
EAetheryteLocation.FirmamentHoarfrostHall => GetPlaceName(3528),
EAetheryteLocation.FirmamentWesternRisensongQuarter => GetPlaceName(3646),
EAetheryteLocation.FIrmamentEasternRisensongQuarter => GetPlaceName(3645),
_ => _aetheryteData.AethernetNames.GetValueOrDefault(aetheryteLocation),
};
if (!_aetheryteData.AethernetNames.TryGetValue(aetheryteLocation, out string? name)) if (name == null)
return false; return false;
_logger.LogInformation("Teleporting to '{Name}'", name);
return _aethernetTeleport.InvokeFunc(name); return _aethernetTeleport.InvokeFunc(name);
} }
private string GetPlaceName(uint rowId) => _dataManager.GetExcelSheet<PlaceName>().GetRow(rowId).Name.ToString();
} }