예제 #1
0
        public void MoveToSocket(uint playerId, int socketId, Quaternion localRotation)
        {
            var qsbSocket = socketId.GetWorldObject <QSBQuantumSocket>();

            if (qsbSocket == null)
            {
                DebugLog.ToConsole($"Couldn't find socket id {socketId}", MessageType.Error);
                return;
            }

            var socket = qsbSocket.AttachedObject;

            if (socket == null)
            {
                DebugLog.ToConsole($"QSBSocket id {socketId} has no attached socket.", MessageType.Error);
                return;
            }

            var wasEntangled = AttachedObject.IsPlayerEntangled();
            var component    = Locator.GetPlayerTransform().GetComponent <OWRigidbody>();
            var location     = new RelativeLocationData(Locator.GetPlayerTransform().GetComponent <OWRigidbody>(), AttachedObject.transform);

            AttachedObject.MoveToSocket(socket);

            if (wasEntangled)
            {
                component.MoveToRelativeLocation(location, AttachedObject.transform);
            }

            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;
            }
        }
        public void MoveToSocket(SocketStateChangeMessage message)
        {
            var qsbSocket = QSBWorldSync.GetWorldFromId <QSBQuantumSocket>(message.SocketId);

            if (qsbSocket == null)
            {
                DebugLog.ToConsole($"Couldn't find socket id {message.SocketId}", MessageType.Error);
                return;
            }
            var socket = qsbSocket.AttachedObject;

            if (socket == null)
            {
                DebugLog.ToConsole($"QSBSocket id {message.SocketId} has no attached socket.", MessageType.Error);
                return;
            }

            var wasEntangled = AttachedObject.IsPlayerEntangled();
            var component    = Locator.GetPlayerTransform().GetComponent <OWRigidbody>();
            var location     = new RelativeLocationData(Locator.GetPlayerTransform().GetComponent <OWRigidbody>(), AttachedObject.transform);

            AttachedObject.GetType().GetMethod("MoveToSocket", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(AttachedObject, new object[] { socket });

            if (wasEntangled)
            {
                component.MoveToRelativeLocation(location, AttachedObject.transform);
            }

            if (QuantumManager.Instance.Shrine != AttachedObject)
            {
                AttachedObject.transform.localRotation = message.LocalRotation;
            }
            else
            {
                var playerToShrine = QSBPlayerManager.GetPlayer(message.FromId).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;
            }
        }
        public override void SendInitialState(uint to)
        {
            base.SendInitialState(to);

            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();
            }
        }