Skip to content

Commit

Permalink
Memorize player's world
Browse files Browse the repository at this point in the history
  • Loading branch information
SlashNephy committed May 7, 2024
1 parent 28680e8 commit dd8161f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions FaloopIntegration/FaloopIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public sealed class FaloopIntegration : DivinationPlugin<FaloopIntegration, Plug
private readonly FaloopSocketIOClient socket = new();
private readonly FaloopSession session = new();
public readonly ActiveMobUi Ui;
private World? currentWorld;
private World? homeWorld;

public FaloopIntegration(DalamudPluginInterface pluginInterface) : base(pluginInterface)
{
Expand All @@ -48,6 +50,9 @@ public FaloopIntegration(DalamudPluginInterface pluginInterface) : base(pluginIn
socket.OnPing += OnPing;
socket.OnPong += OnPong;

OnLogin();
Dalamud.ClientState.Login += OnLogin;

var ipc = new AetheryteLinkInChatIpc(pluginInterface, Divination.Chat);
Ui = new ActiveMobUi(ipc, Divination.Chat, Dalamud.GameGui, Config, Dalamud.Condition)
{
Expand All @@ -59,6 +64,12 @@ public FaloopIntegration(DalamudPluginInterface pluginInterface) : base(pluginIn
CleanSpawnHistories();
}

private void OnLogin()
{
currentWorld = Dalamud.ClientState.LocalPlayer?.CurrentWorld?.GameData;
homeWorld = Dalamud.ClientState.LocalPlayer?.HomeWorld?.GameData;
}

private void OnConnected()
{
Divination.Chat.Print(Localization.Connected);
Expand Down Expand Up @@ -195,14 +206,12 @@ private bool CheckSpawnNotificationCondition(PluginConfig.PerRankConfig config,
return false;
}

var currentWorld = Dalamud.ClientState.LocalPlayer?.CurrentWorld.GameData;
var currentDataCenter = currentWorld?.DataCenter?.Value;
var homeDataCenter = Dalamud.ClientState.LocalPlayer?.HomeWorld?.GameData?.DataCenter.Value;
var homeDataCenter = homeWorld?.DataCenter.Value;
if (currentWorld == default || currentDataCenter == default || homeDataCenter == default)
{
// return true if LocalPlayer cannot be obtained
DalamudLog.Log.Debug("OnMobReport: currentWorld == null || currentDataCenter == null");
return true;
DalamudLog.Log.Debug("OnMobReport: currentWorld == null || currentDataCenter == null || homeDataCenter == null");
return false;
}

switch ((Jurisdiction)config.Jurisdiction)
Expand Down Expand Up @@ -388,6 +397,7 @@ protected override void ReleaseManaged()
socket.Dispose();
Ui.Dispose();
Dalamud.PluginInterface.UiBuilder.Draw -= Ui.Draw;
Dalamud.ClientState.Login -= OnLogin;
}

public string MainCommandPrefix => "/faloop";
Expand Down

0 comments on commit dd8161f

Please sign in to comment.