mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 09:39:56 +00:00
fix sectors in a TERRIBLE TERRIBLE WAY
This commit is contained in:
parent
10597859e5
commit
ff94ecab3b
@ -50,11 +50,6 @@ namespace QSB.Player.Events
|
||||
MessageType.Error);
|
||||
return;
|
||||
}
|
||||
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
||||
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
|
||||
{
|
||||
QSBEventManager.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -204,6 +204,7 @@
|
||||
<Compile Include="QuantumSync\QuantumManager.cs" />
|
||||
<Compile Include="QuantumSync\Patches\QuantumVisibilityPatches.cs" />
|
||||
<Compile Include="QuantumSync\Patches\ServerQuantumPatches.cs" />
|
||||
<Compile Include="SectorSync\FakeSector.cs" />
|
||||
<Compile Include="StatueSync\Events\StartStatueEvent.cs" />
|
||||
<Compile Include="StatueSync\Events\StartStatueMessage.cs" />
|
||||
<Compile Include="StatueSync\Patches\StatuePatches.cs" />
|
||||
|
@ -150,13 +150,11 @@ namespace QSB
|
||||
}
|
||||
|
||||
var offset3 = 10f;
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Current sectors :");
|
||||
GUI.Label(new Rect(420, offset3, 200f, 20f), $"Current closest sector :");
|
||||
offset3 += _debugLineSpacing;
|
||||
var sector = PlayerTransformSync.LocalInstance.SectorSync.GetClosestSector(Locator.GetPlayerTransform());
|
||||
GUI.Label(new Rect(420, offset3, 400f, 20f), $"- {sector.AttachedObject.name} : {sector.IsFakeSector}");
|
||||
offset3 += _debugLineSpacing;
|
||||
foreach (var obj in PlayerTransformSync.LocalInstance?.SectorSync.SectorList)
|
||||
{
|
||||
GUI.Label(new Rect(420, offset3, 400f, 20f), $"- {obj.AttachedObject.name} : {Vector3.Distance(obj.Position, Locator.GetPlayerTransform().position)}");
|
||||
offset3 += _debugLineSpacing;
|
||||
}
|
||||
|
||||
var offset2 = 10f;
|
||||
GUI.Label(new Rect(620, offset2, 200f, 20f), $"Owned Objects :");
|
||||
|
@ -174,7 +174,6 @@ namespace QSB
|
||||
|
||||
QSBEventManager.Init();
|
||||
|
||||
gameObject.AddComponent<QSBSectorManager>();
|
||||
gameObject.AddComponent<RespawnOnDeath>();
|
||||
|
||||
if (QSBSceneManager.IsInUniverse)
|
||||
|
7
QSB/SectorSync/FakeSector.cs
Normal file
7
QSB/SectorSync/FakeSector.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace QSB.SectorSync
|
||||
{
|
||||
public class FakeSector : Sector
|
||||
{
|
||||
public Sector AttachedSector;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using QSB.Player;
|
||||
using QSB.SectorSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@ -13,6 +14,7 @@ namespace QSB.SectorSync
|
||||
{
|
||||
public static QSBSectorManager Instance { get; private set; }
|
||||
public bool IsReady { get; private set; }
|
||||
public List<QSBSector> FakeSectors = new List<QSBSector>();
|
||||
|
||||
private void OnEnable() => RepeatingManager.Repeatings.Add(this);
|
||||
private void OnDisable() => RepeatingManager.Repeatings.Remove(this);
|
||||
@ -25,6 +27,12 @@ namespace QSB.SectorSync
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
DebugLog.ToConsole("Error - Cannot have multiple QSBSectorManagers!", MessageType.Error);
|
||||
Destroy(this);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => RebuildSectors();
|
||||
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
|
||||
@ -33,9 +41,25 @@ namespace QSB.SectorSync
|
||||
public void OnDestroy()
|
||||
=> QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
|
||||
|
||||
|
||||
public void RebuildSectors()
|
||||
{
|
||||
DebugLog.DebugWrite("Rebuilding sectors...", MessageType.Warning);
|
||||
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
|
||||
{
|
||||
var timeLoopRing = GameObject.Find("TimeLoopRing_Body");
|
||||
if (timeLoopRing != null)
|
||||
{
|
||||
if (timeLoopRing.GetComponent<FakeSector>() == null)
|
||||
{
|
||||
timeLoopRing.AddComponent<FakeSector>().AttachedSector = GameObject.Find("Sector_TimeLoopInterior").GetComponent<Sector>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLog.ToConsole($"Error - TimeLoopRing_Body not found!", MessageType.Error);
|
||||
}
|
||||
}
|
||||
QSBWorldSync.Init<QSBSector, Sector>();
|
||||
IsReady = QSBWorldSync.GetWorldObjects<QSBSector>().Any();
|
||||
}
|
||||
|
@ -86,6 +86,16 @@ namespace QSB.SectorSync
|
||||
var ordered = activeNotNullNotBlacklisted
|
||||
.OrderBy(sector => Vector3.Distance(sector.Position, trans.position))
|
||||
.ThenBy(sector => GetRadius(sector));
|
||||
|
||||
if (
|
||||
QSBSectorManager.Instance.FakeSectors.Any(
|
||||
x => OWMath.ApproxEquals(Vector3.Distance(x.Position, trans.position), Vector3.Distance(ordered.FirstOrDefault().Position, trans.position), 0.01f)
|
||||
&& activeNotNullNotBlacklisted.Any(
|
||||
y => y.AttachedObject == (x.AttachedObject as FakeSector).AttachedSector)))
|
||||
{
|
||||
return QSBSectorManager.Instance.FakeSectors.First(x => OWMath.ApproxEquals(Vector3.Distance(x.Position, trans.position), Vector3.Distance(ordered.FirstOrDefault().Position, trans.position), 0.01f));
|
||||
}
|
||||
|
||||
return ordered.FirstOrDefault();
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,24 @@ namespace QSB.SectorSync.WorldObjects
|
||||
public Sector.Name Type => AttachedObject.GetName();
|
||||
public Transform Transform => AttachedObject.transform;
|
||||
public Vector3 Position => Transform.position;
|
||||
public bool IsFakeSector => AttachedObject.GetType() == typeof(FakeSector);
|
||||
|
||||
public override void Init(Sector sector, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
AttachedObject = sector;
|
||||
if (IsFakeSector)
|
||||
{
|
||||
QSBSectorManager.Instance.FakeSectors.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemoval()
|
||||
{
|
||||
if (IsFakeSector)
|
||||
{
|
||||
QSBSectorManager.Instance.FakeSectors.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user