Skip to content

Commit

Permalink
Merge pull request #281 from ari-steas/QuestLogNetworking
Browse files Browse the repository at this point in the history
Tentative fix for persistent questlogs on faction leave/join
  • Loading branch information
ari-steas authored Dec 7, 2024
2 parents 7bf6961 + 61ba60d commit 09d51f8
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Sandbox.ModAPI;
using VRage.Game;
using VRage.Game.Components;
using VRage.Game.ModAPI;
using VRage.Utils;

namespace Invalid.DeltaVQuestLog
Expand Down Expand Up @@ -38,13 +39,26 @@ public override void LoadData()

if (isServer)
{
MyAPIGateway.Session.Factions.FactionStateChanged += FactionsOnFactionStateChanged;
MyVisualScriptLogicProvider.PlayerConnected += OnPlayerConnected;
}

CommandHandler.Init();
Networking = new QuestLogNetworking();
}

private void FactionsOnFactionStateChanged(MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
{
if (action == MyFactionStateChange.FactionMemberAcceptJoin)
{
GetFactionManger(fromFactionId)?.SendNetworkUpdate();
}
if (action == MyFactionStateChange.FactionMemberLeave || action == MyFactionStateChange.FactionMemberKick)
{
MyVisualScriptLogicProvider.SetQuestlog(false, "", playerId);
}
}

protected override void UnloadData()
{
Networking.Close();
Expand All @@ -54,6 +68,7 @@ protected override void UnloadData()
{
SaveObjectives();
MyVisualScriptLogicProvider.PlayerConnected -= OnPlayerConnected;
MyAPIGateway.Session.Factions.FactionStateChanged -= FactionsOnFactionStateChanged;
}

I = null;
Expand All @@ -70,15 +85,6 @@ public override void UpdateAfterSimulation()
manager.Update10();
}

public override void BeforeStart()
{
if (MyAPIGateway.Session.Player == null)
return;

if (MyAPIGateway.Session.Factions.TryGetPlayerFaction(MyAPIGateway.Session.Player.IdentityId) == null)
MyVisualScriptLogicProvider.RemoveQuestlogDetails(MyAPIGateway.Session.Player.IdentityId);
}

private void OnPlayerConnected(long playerId)
{
if (!isServer) return;
Expand All @@ -87,6 +93,7 @@ private void OnPlayerConnected(long playerId)
if (playerFaction == null) return;

var factionId = playerFaction.FactionId;
MyVisualScriptLogicProvider.SetQuestlog(false, "", playerId);
GetFactionManger(factionId)?.SendNetworkUpdate();
}

Expand Down

0 comments on commit 09d51f8

Please sign in to comment.