Skip to content

Commit

Permalink
Fixed bug in reveal, disabled medbay reveal to see if it works withou…
Browse files Browse the repository at this point in the history
…t it
  • Loading branch information
Jimmacle committed Jun 7, 2017
1 parent 3760167 commit ca69f35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Concealment/ConcealGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ConcealGroup
/// Entity ID of the first grid in the group.
/// </summary>
public long Id { get; }
public DateTime ConcealTime { get; set; }
public bool IsConcealed { get; set; }
public BoundingBoxD WorldAABB { get; private set; }
public List<MyCubeGrid> Grids { get; }
public List<MyMedicalRoom> MedicalRooms { get; } = new List<MyMedicalRoom>();
Expand All @@ -38,6 +38,7 @@ public string GridNames

public void UpdatePostConceal()
{
IsConcealed = true;
UpdateAABB();
CacheSpawns();
HookOnClosing();
Expand Down
29 changes: 21 additions & 8 deletions Concealment/ConcealmentPlugin.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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> Settings { get; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ca69f35

Please sign in to comment.