Ejemplo n.º 1
0
        public void Execute()
        {
            foreach (var inputEntity in attackGroup)
            {
                ushort           playerId     = inputEntity.playerInput.playerEntityId;
                ServerGameEntity playerEntity = gameContext.GetEntityWithPlayer(playerId);

                shootingHelper.Shoot(playerEntity, inputEntity);
            }
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            foreach (var inputEntity in inputGroup)
            {
                if (!inputEntity.hasAttack)
                {
                    log.Error("Нет компонента атаки.");
                    continue;
                }

                float desiredAngle = inputEntity.attack.direction;
                if (float.IsNaN(desiredAngle))
                {
                    log.Info("Неправильное значение угла атаки.");
                    continue;
                }

                ushort           playerId     = inputEntity.playerInput.playerEntityId;
                ServerGameEntity playerEntity = gameContext.GetEntityWithPlayer(playerId);
                if (playerEntity == null)
                {
                    log.Error($"Нет такого игрока. {nameof(playerId)} {playerId}");
                    continue;
                }

                if (!playerEntity.hasRigidbody)
                {
                    log.Error($"Нет rigidbody");
                    continue;
                }

                if (float.IsNaN(desiredAngle))
                {
                    playerEntity.rigidbody.value.angularVelocity = Vector3.zero;
                    continue;
                }

                if (!playerEntity.hasAngularVelocity)
                {
                    log.Error("У сущности должен быть AngularVelocity");
                    continue;
                }

                float deltaTimeSec = tickDeltaTimeStorage.GetDeltaTimeSec();

                // float angularVelocity = playerEntity.angularVelocity.value;
                float angularVelocity = 90;
                physicsRotationManager.ApplyRotation(playerEntity.rigidbody.value, desiredAngle, angularVelocity,
                                                     deltaTimeSec);
            }
        }
Ejemplo n.º 3
0
        public void Execute()
        {
            Dictionary <ushort, List <Vector3> > playerDirection = new Dictionary <ushort, List <Vector3> >();

            foreach (var inputEntity in inputGroup)
            {
                Vector2 playerJoystickInput = inputEntity.movement.value;
                ushort  playerId            = inputEntity.playerInput.playerEntityId;
                if (!playerDirection.ContainsKey(playerId))
                {
                    playerDirection.Add(playerId, new List <Vector3>());
                }

                Vector3 inputVector = new Vector3(playerJoystickInput.x, 0, playerJoystickInput.y);
                playerDirection[playerId].Add(inputVector);
            }

            foreach (var pair in playerDirection)
            {
                ushort           playerId     = pair.Key;
                ServerGameEntity playerEntity = gameContext.GetEntityWithPlayer(playerId);
                if (playerEntity == null)
                {
                    string message = $"Пришло сообщение о движении от игрока, которого нет в комнате. " +
                                     $"Данные игнорируются. {nameof(playerId)} {playerId}";
                    log.Error(message);
                    return;
                }

                if (!playerEntity.hasRigidbody)
                {
                    log.Error("Нет rigidbody");
                    continue;
                }

                Rigidbody rigidbody = playerEntity.rigidbody.value;
                if (rigidbody.velocity != Vector3.zero)
                {
                    var vector = rigidbody.velocity;
                    throw new Exception($"Не нулевая скорость {vector.x} {vector.y} {vector.z}");
                }

                float          maxSpeed           = 10;
                List <Vector3> inputValues        = pair.Value;
                Vector3        averageInputVector = vector3Utils.GetVelocityVector(inputValues);
                physicsVelocityManager.ApplyVelocity(rigidbody, averageInputVector, maxSpeed);
            }
        }