Example #1
0
        public void Apply(GameObject player)
        {
            Debug.Assert(NetworkServer.active);
            var controller = player.GetComponent <TankController>();

            if (controller == null)
            {
                Debug.LogWarning("Тут предполагался только игрок!");
                return;
            }

            DelayedExecutor.IDelayedTask appliedBonus;
            if (_appliedBonuses.TryGetValue(player, out appliedBonus))
            {
                appliedBonus.TimeRemaining = _effects.MoveSpeedBonusDuration;
            }
            else
            {
                var oldSpeed = controller.Speed;
                controller.Speed = _effects.MoveSpeedBonusValue;
                appliedBonus     = _delayedExecutor.Add(() =>
                {
                    _appliedBonuses.Remove(controller.gameObject);
                    if (controller.gameObject != null)
                    {
                        controller.Speed = oldSpeed;
                    }
                },
                                                        _effects.MoveSpeedBonusDuration);

                _appliedBonuses.Add(player, appliedBonus);
            }
        }
Example #2
0
        // Update is called once per frame
        private void Update()
        {
            if (isLocalPlayer)
            {
                // клиент: сообщаем на сервер положение кнопки
                var doFire = _input.Fire();
                if (doFire ^ _isFiring)
                {
                    CmdFire(doFire);
                }
            }

            if (isServer)
            {
                // сервер: стреляем
                if (_isFiring && _canFire)
                {
                    var projectile = _pool.Spawn();
                    projectile.Launch(ProjectileSpawn, gameObject);

                    // кулдаун
                    _canFire = false;
                    _delayedExecutor.Add(() => _canFire = true, Cooldown);
                }
            }
        }
Example #3
0
 public void DestroyAndRespawn(NetworkConnection connection, GameObject playerObject)
 {
     _spawnedPlayers.Remove(playerObject);
     NetworkServer.Destroy(playerObject);
     _respawningSignal.FireOnClient(connection, new RespawningSignal.Msg {
         Time = _settings.RespawnSeconds
     });
     _delayedExecutor.Add(() => Respawn(connection), _settings.RespawnSeconds);
 }
Example #4
0
        private void ServerRespawnBonus(Vector2 position)
        {
            var bonus = _pool.GetOrSpawn(position);

            bonus.ServerChangeBonusKind(GetBonusKind());

            var respawnTask = _delayedExecutor.Add(() => ServerRespawnBonus(position), _settings.RespawnIfNotPickedSeconds);

            _respawnTasks[position] = respawnTask;
        }
Example #5
0
        private void RpcLaunch(Vector2 position, Quaternion rotation, GameObject owner)
        {
            _owner       = owner;
            _ownerPlayer = owner.GetComponent <PlayerInfo>().Player;

            transform.position = position;
            transform.rotation = rotation;
            _rb2D.velocity     = transform.up * Speed;

            _despawned   = false;
            _autoDespawn = _delayedExecutor.Add(TryDespawn, TTL);
        }