32 lines
1.0 KiB
C#
Raw Normal View History

2022-01-21 15:13:16 -08:00
using QSB.Messaging;
using QSB.QuantumSync.Messages;
using System.Linq;
using UnityEngine;
2022-03-02 19:46:33 -08:00
namespace QSB.QuantumSync.WorldObjects;
internal class QSBQuantumMoon : QSBQuantumObject<QuantumMoon>
2021-02-26 14:19:42 +00:00
{
2022-03-02 19:46:33 -08:00
protected override bool HostControls => true;
public override void SendInitialState(uint to)
2021-02-26 14:19:42 +00:00
{
2022-03-02 19:46:33 -08:00
base.SendInitialState(to);
2022-01-21 15:13:16 -08:00
2022-03-02 19:46:33 -08:00
if (QSBCore.IsHost)
2022-01-21 15:13:16 -08:00
{
2022-03-02 19:46:33 -08:00
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));
2022-01-21 15:13:16 -08:00
2022-03-02 19:46:33 -08:00
new MoonStateChangeMessage(stateIndex, onUnitSphere, orbitAngle) { To = to }.Send();
2022-01-21 15:13:16 -08:00
}
2021-02-26 14:19:42 +00:00
}
}