This commit is contained in:
Mister_Nebula 2020-12-07 18:49:51 +00:00
parent 6c30b536cb
commit a1b5744adf
8 changed files with 58 additions and 24 deletions

View File

@ -6,15 +6,21 @@ namespace QSB.Animation
{ {
private Animator _attachedAnimator; private Animator _attachedAnimator;
private Transform _lookBase; private Transform _lookBase;
private bool _isSetUp;
public void Init(Transform lookBase) public void Init(Transform lookBase)
{ {
_attachedAnimator = GetComponent<Animator>(); _attachedAnimator = GetComponent<Animator>();
_lookBase = lookBase; _lookBase = lookBase;
_isSetUp = true;
} }
private void LateUpdate() private void LateUpdate()
{ {
if (!_isSetUp)
{
return;
}
var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head); var bone = _attachedAnimator.GetBoneTransform(HumanBodyBones.Head);
// Get the camera's local rotation with respect to the player body // Get the camera's local rotation with respect to the player body
var lookLocalRotation = Quaternion.Inverse(_attachedAnimator.transform.rotation) * _lookBase.rotation; var lookLocalRotation = Quaternion.Inverse(_attachedAnimator.transform.rotation) * _lookBase.rotation;

View File

@ -5,28 +5,28 @@ using QSB.WorldSync.Events;
namespace QSB.OrbSync.Events namespace QSB.OrbSync.Events
{ {
public class OrbSlotEvent : QSBEvent<BoolWorldObjectMessage> public class OrbSlotEvent : QSBEvent<OrbSlotMessage>
{ {
public override EventType Type => EventType.OrbSlot; public override EventType Type => EventType.OrbSlot;
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbSlot, Handler); public override void SetupListener() => GlobalMessenger<int, int, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler); public override void CloseListener() => GlobalMessenger<int, int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state)); private void Handler(int slotId, int orbId, bool slotState) => SendEvent(CreateMessage(slotId, orbId, slotState));
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage private OrbSlotMessage CreateMessage(int slotId, int orbId, bool slotState) => new OrbSlotMessage
{ {
AboutId = LocalPlayerId, AboutId = LocalPlayerId,
ObjectId = id, SlotId = slotId,
State = state OrbId = orbId,
SlotState = slotState
}; };
public override void OnReceiveRemote(BoolWorldObjectMessage message) public override void OnReceiveRemote(OrbSlotMessage message)
{ {
DebugLog.DebugWrite($"receive slot {message.ObjectId} to {message.State}"); var orbSlot = WorldRegistry.GetObject<QSBOrbSlot>(message.SlotId);
var orbSlot = WorldRegistry.GetObject<QSBOrbSlot>(message.ObjectId); orbSlot?.SetState(message.SlotState, message.OrbId);
orbSlot?.SetState(message.State);
} }
} }
} }

View File

@ -0,0 +1,32 @@
using QSB.Messaging;
using QuantumUNET;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.OrbSync.Events
{
public class OrbSlotMessage : PlayerMessage
{
public int SlotId { get; set; }
public int OrbId { get; set; }
public bool SlotState { get; set; }
public override void Deserialize(QSBNetworkReader reader)
{
base.Deserialize(reader);
SlotId = reader.ReadInt32();
OrbId = reader.ReadInt32();
SlotState = reader.ReadBoolean();
}
public override void Serialize(QSBNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(SlotId);
writer.Write(OrbId);
writer.Write(SlotState);
}
}
}

View File

@ -27,10 +27,6 @@ namespace QSB.OrbSync.Events
public override void OnServerReceive(WorldObjectMessage message) public override void OnServerReceive(WorldObjectMessage message)
{ {
var fromPlayer = QSBNetworkServer.connections.First(x => x.GetPlayer().PlayerId == message.FromId); var fromPlayer = QSBNetworkServer.connections.First(x => x.GetPlayer().PlayerId == message.FromId);
foreach (var item in QSBNetworkServer.connections)
{
DebugLog.DebugWrite(item.GetPlayer().PlayerId.ToString());
}
if (WorldRegistry.OrbSyncList.Count == 0) if (WorldRegistry.OrbSyncList.Count == 0)
{ {
DebugLog.ToConsole($"Error - OrbSyncList is empty. (ID {message.ObjectId})", MessageType.Error); DebugLog.ToConsole($"Error - OrbSyncList is empty. (ID {message.ObjectId})", MessageType.Error);
@ -55,10 +51,8 @@ namespace QSB.OrbSync.Events
} }
if (orbIdentity.ClientAuthorityOwner != null && orbIdentity.ClientAuthorityOwner != fromPlayer) if (orbIdentity.ClientAuthorityOwner != null && orbIdentity.ClientAuthorityOwner != fromPlayer)
{ {
DebugLog.DebugWrite($"Removed authority of orb {message.ObjectId} from {orbIdentity.ClientAuthorityOwner.GetPlayer().PlayerId}");
orbIdentity.RemoveClientAuthority(orbIdentity.ClientAuthorityOwner); orbIdentity.RemoveClientAuthority(orbIdentity.ClientAuthorityOwner);
} }
DebugLog.DebugWrite($"Assigned authority of orb {message.ObjectId} to player {message.FromId}.");
orbIdentity.AssignClientAuthority(fromPlayer); orbIdentity.AssignClientAuthority(fromPlayer);
orb.enabled = true; orb.enabled = true;
} }

View File

@ -1,4 +1,5 @@
using QSB.EventsCore; using OWML.ModHelper.Events;
using QSB.EventsCore;
using QSB.WorldSync; using QSB.WorldSync;
namespace QSB.OrbSync namespace QSB.OrbSync
@ -18,20 +19,22 @@ namespace QSB.OrbSync
WorldRegistry.AddObject(this); WorldRegistry.AddObject(this);
} }
public void HandleEvent(bool state) public void HandleEvent(bool state, int orbId)
{ {
if (QSB.HasWokenUp) if (QSB.HasWokenUp)
{ {
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, state); GlobalMessenger<int, int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, orbId, state);
} }
} }
public void SetState(bool state) public void SetState(bool state, int orbId)
{ {
if (!_initialized) if (!_initialized)
{ {
return; return;
} }
var occOrb = state ? WorldRegistry.OldOrbList[orbId] : null;
InterfaceSlot.SetValue("_occupyingOrb", occOrb);
var ev = state ? "OnSlotActivated" : "OnSlotDeactivated"; var ev = state ? "OnSlotActivated" : "OnSlotDeactivated";
WorldRegistry.RaiseEvent(InterfaceSlot, ev); WorldRegistry.RaiseEvent(InterfaceSlot, ev);
Activated = state; Activated = state;

View File

@ -150,6 +150,7 @@
<Compile Include="Instruments\InstrumentsManager.cs" /> <Compile Include="Instruments\InstrumentsManager.cs" />
<Compile Include="MessagesCore\EnumMessage.cs" /> <Compile Include="MessagesCore\EnumMessage.cs" />
<Compile Include="MessagesCore\FloatMessage.cs" /> <Compile Include="MessagesCore\FloatMessage.cs" />
<Compile Include="OrbSync\Events\OrbSlotMessage.cs" />
<Compile Include="OrbSync\OrbManager.cs" /> <Compile Include="OrbSync\OrbManager.cs" />
<Compile Include="OrbSync\Events\OrbSlotEvent.cs" /> <Compile Include="OrbSync\Events\OrbSlotEvent.cs" />
<Compile Include="OrbSync\OrbPatches.cs" /> <Compile Include="OrbSync\OrbPatches.cs" />

View File

@ -18,8 +18,6 @@ namespace QSB.Utility
var warpCore = GameObject.Find("Prefab_NOM_WarpCoreVessel").GetComponent<WarpCoreItem>(); var warpCore = GameObject.Find("Prefab_NOM_WarpCoreVessel").GetComponent<WarpCoreItem>();
var socket = GameObject.Find("Interactibles_VesselBridge").GetComponentInChildren<WarpCoreSocket>(); var socket = GameObject.Find("Interactibles_VesselBridge").GetComponentInChildren<WarpCoreSocket>();
socket.PlaceIntoSocket(warpCore); socket.PlaceIntoSocket(warpCore);
GetComponent<NomaiCoordinateInterface>().SetPillarRaised(true, true);
} }
private void Update() private void Update()

View File

@ -55,7 +55,7 @@ namespace QSB.WorldSync
orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb); orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb);
if (orbSync.HasAuthority) if (orbSync.HasAuthority)
{ {
qsbSlot.HandleEvent(state); qsbSlot.HandleEvent(state, OldOrbList.IndexOf(affectingOrb));
} }
} }
catch catch