Skip to content

Commit

Permalink
more checking for sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
misternebula committed Mar 12, 2021
1 parent cc0f5bc commit beb861e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
7 changes: 3 additions & 4 deletions QSB/ItemSync/Patches/ItemPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using QSB.Events;
using OWML.Common;
using QSB.Events;
using QSB.Patches;
using QSB.Utility;
using QSB.WorldSync;
Expand Down Expand Up @@ -94,9 +95,7 @@ public static bool ItemTool_DropItem(RaycastHit hit, OWRigidbody targetRigidbody
QSBEventManager.FireEvent(EventNames.QSBDropItem, objectId, localPos, hit.normal, parentSector);
return false;
}
DebugLog.ToConsole($"Warning - no sector found for rigidbody {targetRigidbody.name}.", OWML.Common.MessageType.Warning);
var localPosition = sector.transform.InverseTransformPoint(hit.point);
QSBEventManager.FireEvent(EventNames.QSBDropItem, objectId, localPosition, hit.normal, sector);
DebugLog.ToConsole($"Error - No sector found for rigidbody {targetRigidbody.name}!.", MessageType.Error);
return false;
}
}
Expand Down
15 changes: 10 additions & 5 deletions QSB/SectorSync/SectorSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class SectorSync : MonoBehaviour
public List<QSBSector> SectorList = new List<QSBSector>();

private SectorDetector _sectorDetector;
private readonly Sector.Name[] _sectorBlacklist = { Sector.Name.Ship };

public void SetSectorDetector(SectorDetector detector)
{
Expand All @@ -36,7 +35,7 @@ private void AddSector(Sector sector)
}
if (SectorList.Contains(worldObject))
{
DebugLog.ToConsole($"Warning - Trying to add {sector.name}, but is already in list", MessageType.Warning);
DebugLog.ToConsole($"Warning - Trying to add {sector.name} for {gameObject.name}, but is already in list", MessageType.Warning);
return;
}
SectorList.Add(worldObject);
Expand All @@ -52,7 +51,7 @@ private void RemoveSector(Sector sector)
}
if (!SectorList.Contains(worldObject))
{
DebugLog.ToConsole($"Warning - Trying to remove {sector.name}, but is not in list!", MessageType.Warning);
DebugLog.ToConsole($"Warning - Trying to remove {sector.name} for {gameObject.name}, but is not in list!", MessageType.Warning);
return;
}
SectorList.Remove(worldObject);
Expand All @@ -66,7 +65,7 @@ public QSBSector GetClosestSector(Transform trans) // trans rights \o/
return null;
}

var listToCheck = SectorList.Count == 0
var listToCheck = SectorList.Count(x => x.ShouldSyncTo()) == 0
? QSBWorldSync.GetWorldObjects<QSBSector>()
: SectorList;

Expand All @@ -81,8 +80,14 @@ public QSBSector GetClosestSector(Transform trans) // trans rights \o/
*/

var activeNotNullNotBlacklisted = listToCheck.Where(sector => sector.AttachedObject != null
&& !_sectorBlacklist.Contains(sector.Type)
&& sector.ShouldSyncTo()
&& sector.Transform.gameObject.activeInHierarchy);
if (activeNotNullNotBlacklisted.Count() == 0)
{
DebugLog.ToConsole(
$"Error - Zero available sectors for {trans.name} to sync to! Current QSBSector count : {QSBWorldSync.GetWorldObjects<QSBSector>().Count()}",
MessageType.Error);
}
var ordered = activeNotNullNotBlacklisted
.OrderBy(sector => Vector3.Distance(sector.Position, trans.position))
.ThenBy(sector => GetRadius(sector));
Expand Down
14 changes: 14 additions & 0 deletions QSB/SectorSync/WorldObjects/QSBSector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,19 @@ public override void OnRemoval()
QSBSectorManager.Instance.FakeSectors.Remove(this);
}
}

public bool ShouldSyncTo()
{
if (Type == Sector.Name.Ship)
{
return false;
}
if ((AttachedObject.name == "Sector_Shuttle" || AttachedObject.name == "Sector_NomaiShuttleInterior")
&& !AttachedObject.gameObject.GetComponentInParent<NomaiShuttleController>().IsPlayerInside())
{
return false;
}
return true;
}
}
}

0 comments on commit beb861e

Please sign in to comment.