2022-01-29 04:49:07 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using OWML.Common;
|
2021-01-29 15:29:50 +00:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Utility;
|
2021-01-26 14:07:17 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-12-28 18:06:34 +00:00
|
|
|
|
using System;
|
2022-01-29 04:49:07 +00:00
|
|
|
|
using System.Threading;
|
2021-01-26 14:07:17 +00:00
|
|
|
|
using UnityEngine;
|
2020-12-22 21:39:53 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.QuantumSync.WorldObjects;
|
|
|
|
|
|
2023-07-28 18:30:57 +00:00
|
|
|
|
public class QSBSocketedQuantumObject : QSBQuantumObject<SocketedQuantumObject>
|
2020-12-22 21:39:53 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override async UniTask Init(CancellationToken ct)
|
2020-12-22 21:39:53 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
await base.Init(ct);
|
|
|
|
|
AttachedObject._randomYRotation = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ReturnLabel()
|
|
|
|
|
{
|
|
|
|
|
var socket = AttachedObject.GetCurrentSocket();
|
|
|
|
|
if (socket != null)
|
2020-12-22 21:39:53 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var socketObj = socket.GetWorldObject<QSBQuantumSocket>();
|
2022-03-07 20:34:35 +00:00
|
|
|
|
return $"{base.ReturnLabel()}SocketId:{socketObj.ObjectId}";
|
2021-01-26 14:07:17 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
else
|
2021-01-26 14:07:17 +00:00
|
|
|
|
{
|
2022-03-07 20:34:35 +00:00
|
|
|
|
return $"{base.ReturnLabel()}SocketId:NULL";
|
2021-02-21 18:25:25 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-01-26 05:08:04 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public override void SendInitialState(uint to)
|
|
|
|
|
{
|
|
|
|
|
base.SendInitialState(to);
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
// todo SendInitialState
|
|
|
|
|
}
|
2021-06-18 21:38:32 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public void MoveToSocket(uint playerId, int socketId, Quaternion localRotation)
|
|
|
|
|
{
|
|
|
|
|
var qsbSocket = socketId.GetWorldObject<QSBQuantumSocket>();
|
|
|
|
|
if (qsbSocket == null)
|
2022-02-25 06:04:54 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
DebugLog.ToConsole($"Couldn't find socket id {socketId}", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-31 19:50:01 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var socket = qsbSocket.AttachedObject;
|
|
|
|
|
if (socket == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"QSBSocket id {socketId} has no attached socket.", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-31 19:50:01 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var wasEntangled = AttachedObject.IsPlayerEntangled();
|
|
|
|
|
var component = Locator.GetPlayerTransform().GetComponent<OWRigidbody>();
|
|
|
|
|
var location = new RelativeLocationData(Locator.GetPlayerTransform().GetComponent<OWRigidbody>(), AttachedObject.transform);
|
2021-01-31 19:50:01 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
AttachedObject.MoveToSocket(socket);
|
2021-01-31 19:50:01 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (wasEntangled)
|
|
|
|
|
{
|
|
|
|
|
component.MoveToRelativeLocation(location, AttachedObject.transform);
|
|
|
|
|
}
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
if (QuantumManager.Shrine != AttachedObject)
|
|
|
|
|
{
|
|
|
|
|
AttachedObject.transform.localRotation = localRotation;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var playerToShrine = QSBPlayerManager.GetPlayer(playerId).Body.transform.position - AttachedObject.transform.position;
|
|
|
|
|
var projectOnPlace = Vector3.ProjectOnPlane(playerToShrine, AttachedObject.transform.up);
|
|
|
|
|
var angle = OWMath.Angle(AttachedObject.transform.forward, projectOnPlace, AttachedObject.transform.up);
|
|
|
|
|
angle = OWMath.RoundToNearestMultiple(angle, 120f);
|
|
|
|
|
AttachedObject.transform.rotation = Quaternion.AngleAxis(angle, AttachedObject.transform.up) * AttachedObject.transform.rotation;
|
2020-12-22 21:39:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-23 10:43:13 +00:00
|
|
|
|
}
|