Пример #1
0
        private void CollectCommandsAndSend(TankNode tankNode, WeaponNode weaponNode, MoveCommandType commandType)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;

            if (((commandType & MoveCommandType.TANK) != MoveCommandType.NONE) && (tankMovementSender.LastSentMovementTime >= PreciseTime.Time))
            {
                commandType ^= MoveCommandType.TANK;
            }
            if (((commandType & MoveCommandType.WEAPON) != MoveCommandType.NONE) && (tankMovementSender.LastSentWeaponRotationTime >= PreciseTime.Time))
            {
                commandType ^= MoveCommandType.WEAPON;
            }
            Movement?nullable  = null;
            float?   nullable3 = null;

            if ((commandType & MoveCommandType.TANK) != MoveCommandType.NONE)
            {
                nullable = new Movement?(this.GetMovement(tankNode));
            }
            if ((commandType & MoveCommandType.WEAPON) != MoveCommandType.NONE)
            {
                nullable3 = new float?(weaponNode.weaponRotationControl.Rotation);
            }
            MoveCommand moveCommand = new MoveCommand {
                Movement              = nullable,
                WeaponRotation        = nullable3,
                TankControlVertical   = this.GetMoveAxis(tankNode),
                TankControlHorizontal = this.GetTurnAxis(tankNode),
                WeaponRotationControl = this.GetWeaponControl(weaponNode),
                ClientTime            = (int)(PreciseTime.Time * 1000.0)
            };

            this.SendCommand(tankNode, moveCommand);
        }
Пример #2
0
        private void SendCommand(TankNode tankNode, MoveCommand moveCommand)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;
            Movement?movement = moveCommand.Movement;

            if (movement != null)
            {
                if (!PhysicsUtil.ValidateMovement(movement.Value))
                {
                    return;
                }
                tankMovementSender.LastSentMovement     = movement;
                tankMovementSender.LastSentMovementTime = PreciseTime.Time;
                base.Log.Debug("SEND MOVEMENT");
            }
            if (moveCommand.WeaponRotation != null)
            {
                if (!PhysicsUtil.IsValidFloat(moveCommand.WeaponRotation.Value))
                {
                    LoggerProvider.GetLogger(typeof(PhysicsUtil)).ErrorFormat("Invalid WeaponRotation. StackTrace:[{0}]", Environment.StackTrace);
                    return;
                }
                tankMovementSender.LastSentWeaponRotationTime = PreciseTime.Time;
                base.Log.Debug("SEND WEAPON_ROTATION");
            }
            base.ScheduleEvent(new MoveCommandEvent(moveCommand), tankNode.Entity);
            base.Log.Debug("SEND DISCRETE");
        }
Пример #3
0
        public void OnAfterFixedUpdate(AfterFixedUpdateEvent e, TankNode tankNode, [JoinByTank] WeaponNode weaponNode)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;
            Rigidbody rigidbody = tankNode.rigidbody.Rigidbody;
            Vector3   velocity  = rigidbody.velocity;
            float     num       = this.SqrMagnitudeXZ(velocity);
            Vector3   vector    = tankMovementSender.LastPhysicsMovement.Velocity;

            if (((((tankMovementSender.LastSentMovement == null) || (((Mathf.Clamp(velocity.y, 0f, float.MaxValue) - Mathf.Clamp(vector.y, 0f, float.MaxValue)) / Time.fixedDeltaTime) > 20f)) || ((this.SqrMagnitudeXZ(vector) > (num + 0.01)) && ((this.SqrMagnitudeXZ(tankMovementSender.LastSentMovement.Value.Velocity) + 0.01) < this.SqrMagnitudeXZ(vector)))) || this.IsXZDistanceTooLarge(tankMovementSender.LastSentMovement.Value.Position, rigidbody.position)) || this.IsYDistanceTooLarge(tankMovementSender.LastSentMovement.Value.Position, rigidbody.position))
            {
                this.CollectCommandsAndSend(tankNode, weaponNode, MoveCommandType.TANK);
            }
        }
Пример #4
0
        private bool NeedMandatoryCorrection(TankNode tankNode)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;

            if (tankMovementSender.LastSentMovement != null)
            {
                if (tankNode.tankCollision.HasCollision == tankMovementSender.LastHasCollision)
                {
                    return(false);
                }
                tankMovementSender.LastHasCollision = tankNode.tankCollision.HasCollision;
            }
            return(true);
        }
Пример #5
0
        private bool NeedRegularCorrection(TankNode tankNode)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;

            return(PreciseTime.Time >= (tankMovementSender.LastSentMovementTime + 2.0));
        }