From 1590be68574a629e972d7c9f6df9f7cd1fa61e48 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Mon, 2 Dec 2024 04:44:31 -0600 Subject: [PATCH 1/3] hmm --- .../Scripts/PersistentFactionObjectives.cs | 29 ++++++++++++------- .../Data/Scripts/QuestLogMessage.cs | 22 -------------- 2 files changed, 19 insertions(+), 32 deletions(-) delete mode 100644 DeltaVFactionQuestLog/Data/Scripts/QuestLogMessage.cs diff --git a/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs b/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs index c6fd6fe..e787c03 100644 --- a/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs +++ b/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs @@ -5,9 +5,22 @@ using System.Collections.Generic; using System; using VRage.Game; +using ProtoBuf; -namespace DeltaVQuestLog +namespace Invalid.DeltaVQuestLog { + [ProtoContract] + public class QuestLogMessage + { + [ProtoMember(1)] + public long FactionId { get; set; } + [ProtoMember(2)] + public List Objectives { get; set; } + [ProtoMember(3)] + public string Title { get; set; } + [ProtoMember(4)] + public int Duration { get; set; } + } [MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)] public class PersistentFactionObjectives : MySessionComponentBase @@ -24,31 +37,27 @@ public class PersistentFactionObjectives : MySessionComponentBase public override void LoadData() { - isServer = MyAPIGateway.Multiplayer.IsServer; // True for server instances (single-player, listen server host, dedicated server) - bool isDedicated = MyAPIGateway.Utilities.IsDedicated; // True only for dedicated servers + isServer = MyAPIGateway.Multiplayer.IsServer; + bool isDedicated = MyAPIGateway.Utilities.IsDedicated; if (isServer && !isDedicated) { - // Single-player or listen server host LoadObjectives(); } else if (isDedicated) { - // Dedicated server LoadObjectives(); } - // Register chat commands for all instances - MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; + // Remove this line as it's duplicated below + // MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; - // Register player connect events on the server side (for dedicated and listen servers) if (isServer) { MyVisualScriptLogicProvider.PlayerConnected += OnPlayerConnected; } MyAPIGateway.Multiplayer.RegisterMessageHandler(QuestLogMessageId, OnQuestLogMessageReceived); - MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; - + MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; // Keep only this one } protected override void UnloadData() diff --git a/DeltaVFactionQuestLog/Data/Scripts/QuestLogMessage.cs b/DeltaVFactionQuestLog/Data/Scripts/QuestLogMessage.cs deleted file mode 100644 index 8c689a0..0000000 --- a/DeltaVFactionQuestLog/Data/Scripts/QuestLogMessage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using ProtoBuf; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DeltaVQuestLog -{ - [ProtoContract] - public class QuestLogMessage - { - [ProtoMember(1)] - public long FactionId { get; set; } - [ProtoMember(2)] - public List Objectives { get; set; } - [ProtoMember(3)] - public string Title { get; set; } - [ProtoMember(4)] - public int Duration { get; set; } - } -} \ No newline at end of file From d31906675be1f6283f193710995301b9e88fa26c Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Mon, 2 Dec 2024 04:50:43 -0600 Subject: [PATCH 2/3] Update PersistentFactionObjectives.cs --- .../Scripts/PersistentFactionObjectives.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs b/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs index e787c03..1fc30e5 100644 --- a/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs +++ b/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs @@ -49,15 +49,12 @@ public override void LoadData() LoadObjectives(); } - // Remove this line as it's duplicated below - // MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; - if (isServer) { MyVisualScriptLogicProvider.PlayerConnected += OnPlayerConnected; } MyAPIGateway.Multiplayer.RegisterMessageHandler(QuestLogMessageId, OnQuestLogMessageReceived); - MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; // Keep only this one + MyAPIGateway.Utilities.MessageEntered += OnMessageEntered; } protected override void UnloadData() @@ -211,16 +208,15 @@ private void HandleAddObjective(string[] args, long factionId, long playerId) factionObjectives[factionId] = new List(); } - if (!factionObjectives[factionId].Contains(objectiveText)) // Avoid duplicates + if (!factionObjectives[factionId].Contains(objectiveText)) { factionObjectives[factionId].Add(objectiveText); SaveObjectives(); - // Get the player's name string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown"; - // Show updated quest log to all faction members - ShowQuestLogToFaction(factionId, 10, $"Faction Objectives [Added by {playerName}: {objectiveText}]"); + // Update to show quest log immediately after adding + ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Added by {playerName}: {objectiveText}]"); MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} added objective: {objectiveText}"); } @@ -295,11 +291,10 @@ private void HandleRemoveObjective(string[] args, long factionId, long playerId) factionObjectives[factionId].RemoveAt(index - 1); SaveObjectives(); - // Get the player's name string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown"; - // Show updated quest log to all faction members - ShowQuestLogToFaction(factionId, 10, $"Faction Objectives [Removed by {playerName}: {removedObjective}]"); + // Update to show quest log immediately after removing + ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Removed by {playerName}: {removedObjective}]"); MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} removed objective: {removedObjective}"); } @@ -391,11 +386,10 @@ private void HandleClearObjectives(long factionId, long playerId) factionObjectives[factionId].Clear(); SaveObjectives(); - // Get the player's name string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown"; - // Notify all faction members about the cleared objectives - ShowQuestLogToFaction(factionId, 10, $"[Cleared by {playerName}]"); + // Update to show empty quest log immediately after clearing + ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Cleared by {playerName}]"); MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} cleared all objectives."); } @@ -452,8 +446,15 @@ private void ShowQuestLogForPlayer(long factionId, long playerId, int duration, private void DisplayQuestLog(List objectives, string title, long playerId) { + if (objectives == null || objectives.Count == 0) + { + MyVisualScriptLogicProvider.SetQuestlog(false, "", playerId); + return; + } + MyVisualScriptLogicProvider.SetQuestlog(true, title, playerId); MyVisualScriptLogicProvider.RemoveQuestlogDetails(playerId); + foreach (var objective in objectives) { MyVisualScriptLogicProvider.AddQuestlogObjective(objective, false, true, playerId); From 920aec328ec2348f07ea7ad249f16a4d8634cfe9 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Mon, 2 Dec 2024 05:44:28 -0600 Subject: [PATCH 3/3] Update PersistentFactionObjectives.cs --- .../Scripts/PersistentFactionObjectives.cs | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs b/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs index 1fc30e5..19bed79 100644 --- a/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs +++ b/DeltaVFactionQuestLog/Data/Scripts/PersistentFactionObjectives.cs @@ -129,6 +129,9 @@ private void OnMessageEntered(string messageText, ref bool sendToOthers) { if (!messageText.StartsWith("/obj") && !messageText.StartsWith("/objective")) return; + // Only process commands on the client side + if (isServer && !MyAPIGateway.Multiplayer.IsServer) return; + sendToOthers = false; var args = messageText.Split(' '); @@ -214,9 +217,19 @@ private void HandleAddObjective(string[] args, long factionId, long playerId) SaveObjectives(); string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown"; + string title = $"Faction Objectives [Added by {playerName}: {objectiveText}]"; - // Update to show quest log immediately after adding - ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Added by {playerName}: {objectiveText}]"); + // In singleplayer or on client, show directly + if (!MyAPIGateway.Utilities.IsDedicated) + { + DisplayQuestLog(factionObjectives[factionId], title, playerId); + } + + // If server, broadcast to all faction members + if (isServer) + { + ShowQuestLogToFaction(factionId, 30, title); + } MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} added objective: {objectiveText}"); } @@ -292,9 +305,19 @@ private void HandleRemoveObjective(string[] args, long factionId, long playerId) SaveObjectives(); string playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown"; + string title = $"Faction Objectives [Removed by {playerName}: {removedObjective}]"; - // Update to show quest log immediately after removing - ShowQuestLogToFaction(factionId, 30, $"Faction Objectives [Removed by {playerName}: {removedObjective}]"); + // In singleplayer or on client, show directly + if (!MyAPIGateway.Utilities.IsDedicated) + { + DisplayQuestLog(factionObjectives[factionId], title, playerId); + } + + // If server, broadcast to all faction members + if (isServer) + { + ShowQuestLogToFaction(factionId, 30, title); + } MyAPIGateway.Utilities.ShowMessage("Objectives", $"{playerName} removed objective: {removedObjective}"); } @@ -317,8 +340,17 @@ private void HandleBroadcast(string[] args, long factionId) var playerName = MyAPIGateway.Session.Player?.DisplayName ?? "Unknown"; string customTitle = $"Faction Objectives [Broadcasted by {playerName}, {duration}s]"; - // Broadcast to faction members - ShowQuestLogToFaction(factionId, duration, customTitle); + // In singleplayer or on client, show directly + if (!MyAPIGateway.Utilities.IsDedicated) + { + DisplayQuestLog(factionObjectives[factionId], customTitle, MyAPIGateway.Session.Player.IdentityId); + } + + // If server, broadcast to all faction members + if (isServer) + { + ShowQuestLogToFaction(factionId, duration, customTitle); + } MyAPIGateway.Utilities.ShowMessage("Objectives", $"Broadcasting objectives for {duration} seconds by {playerName}."); }