2022-01-21 23:13:16 +00:00
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.QuantumSync.Messages;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace QSB.QuantumSync.WorldObjects
|
2021-02-26 14:19:42 +00:00
|
|
|
|
{
|
2021-02-26 22:26:17 +00:00
|
|
|
|
internal class QSBQuantumMoon : QSBQuantumObject<QuantumMoon>
|
2021-02-26 14:19:42 +00:00
|
|
|
|
{
|
2022-01-12 03:21:45 +00:00
|
|
|
|
protected override bool HostControls => true;
|
2022-01-21 23:13:16 +00:00
|
|
|
|
|
|
|
|
|
public override void SendResyncInfo(uint to)
|
|
|
|
|
{
|
2022-01-21 23:22:29 +00:00
|
|
|
|
base.SendResyncInfo(to);
|
|
|
|
|
|
2022-01-21 23:13:16 +00:00
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
|
|
|
|
var moon = AttachedObject;
|
|
|
|
|
var moonBody = moon._moonBody;
|
|
|
|
|
var stateIndex = moon.GetStateIndex();
|
|
|
|
|
var orbit = moon._orbits.First(y => y.GetStateIndex() == stateIndex);
|
|
|
|
|
var orbitBody = orbit.GetAttachedOWRigidbody();
|
|
|
|
|
var relPos = moonBody.GetWorldCenterOfMass() - orbitBody.GetWorldCenterOfMass();
|
|
|
|
|
var relVel = moonBody.GetVelocity() - orbitBody.GetVelocity();
|
|
|
|
|
var onUnitSphere = relPos.normalized;
|
|
|
|
|
var perpendicular = Vector3.Cross(relPos, Vector3.up).normalized;
|
|
|
|
|
var orbitAngle = (int)OWMath.WrapAngle(OWMath.Angle(perpendicular, relVel, relPos));
|
|
|
|
|
|
|
|
|
|
new MoonStateChangeMessage(stateIndex, onUnitSphere, orbitAngle) { To = to }.Send();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-26 14:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|