From ca69f35077529581ebb3b25d58013311916ef70a Mon Sep 17 00:00:00 2001 From: John Gross Date: Wed, 7 Jun 2017 12:25:26 -0700 Subject: [PATCH] Fixed bug in reveal, disabled medbay reveal to see if it works without it --- Concealment/ConcealGroup.cs | 3 ++- Concealment/ConcealmentPlugin.cs | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Concealment/ConcealGroup.cs b/Concealment/ConcealGroup.cs index 4006167..2f48a5b 100644 --- a/Concealment/ConcealGroup.cs +++ b/Concealment/ConcealGroup.cs @@ -17,7 +17,7 @@ public class ConcealGroup /// Entity ID of the first grid in the group. /// public long Id { get; } - public DateTime ConcealTime { get; set; } + public bool IsConcealed { get; set; } public BoundingBoxD WorldAABB { get; private set; } public List Grids { get; } public List MedicalRooms { get; } = new List(); @@ -38,6 +38,7 @@ public string GridNames public void UpdatePostConceal() { + IsConcealed = true; UpdateAABB(); CacheSpawns(); HookOnClosing(); diff --git a/Concealment/ConcealmentPlugin.cs b/Concealment/ConcealmentPlugin.cs index ca158bb..85fce07 100644 --- a/Concealment/ConcealmentPlugin.cs +++ b/Concealment/ConcealmentPlugin.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; using NLog; @@ -22,7 +24,7 @@ namespace Concealment { - [Plugin("Concealment", "1.0", "17f44521-b77a-4e85-810f-ee73311cf75d")] + [Plugin("Concealment", "1.1", "17f44521-b77a-4e85-810f-ee73311cf75d")] public class ConcealmentPlugin : TorchPluginBase, IWpfPlugin { public Persistent Settings { get; } @@ -74,7 +76,7 @@ public override void Update() if (_init) return; - MySession.Static.Players.PlayerRequesting += RevealSpawns; + //MySession.Static.Players.PlayerRequesting += RevealSpawns; MyMultiplayer.Static.ClientJoined += RevealCryoPod; _init = true; @@ -183,18 +185,18 @@ private int ConcealGroup(ConcealGroup group) if (_concealGroups.Any(g => g.Id == group.Id)) return 0; - Log.Info($"Concealing grids: {string.Join(", ", group.Grids.Select(g => g.DisplayName))}"); - group.ConcealTime = DateTime.Now; + Log.Info($"Concealing grids: {group.GridNames}"); group.Grids.ForEach(ConcealEntity); + var aabb = group.WorldAABB; + group.ProxyId = _concealedAabbTree.AddProxy(ref aabb, group, 0); + group.Closing += Group_Closing; Task.Run(() => { group.UpdatePostConceal(); - var aabb = group.WorldAABB; - group.ProxyId = _concealedAabbTree.AddProxy(ref aabb, group, 0); Log.Debug($"Group {group.Id} cached"); + group.IsConcealed = true; Torch.Invoke(() => _concealGroups.Add(group)); }); - group.Closing += Group_Closing; return group.Grids.Count; } @@ -205,7 +207,13 @@ private void Group_Closing(ConcealGroup group) public int RevealGroup(ConcealGroup group) { - Log.Info($"Revealing grids: {string.Join(", ", group.Grids.Select(g => g.DisplayName))}"); + if (!group.IsConcealed) + { + Log.Warn($"Attempted to reveal a group that wasn't concealed: {group.GridNames}"); + Log.Warn(new StackTrace()); + return 0; + } + Log.Debug($"Revealing grids: {group.GridNames}"); group.Grids.ForEach(RevealEntity); _concealGroups.Remove(group); _concealedAabbTree.RemoveProxy(group.ProxyId); @@ -232,6 +240,8 @@ public int RevealNearbyGrids(double distanceFromPlayers) foreach (var sphere in playerSpheres) revealed += RevealGridsInSphere(sphere); + if (revealed != 0) + Log.Info($"Revealed {revealed} grids near players."); return revealed; } @@ -260,6 +270,9 @@ public int ConcealDistantGrids(double distanceFromPlayers) concealed += ConcealGroup(group); } + if (concealed != 0) + Log.Info($"Concealed {concealed} grids distant from players."); + return concealed; }