Пример #1
0
        private void SpawnBomb()
        {
            float rarityRatio = Random.Range(0f, 1f);
            float rarityIndex = 0;

            foreach (var pair in _bombsRarity)
            {
                if (pair.Key < rarityRatio && pair.Key > rarityIndex)
                {
                    rarityIndex = pair.Key;
                }
            }

            int        bombIndex  = _bombsRarity[rarityIndex];
            BombConfig bombConfig = _configStorage.Get <BombConfig>(bombIndex);
            Vector3    position   = new Vector3(Random.Range(_spawnArea.xMin, _spawnArea.xMax), 45,
                                                Random.Range(_spawnArea.yMin, _spawnArea.yMax));

            BombModel      bomb           = new BombModel(bombConfig, position, this);
            BombController bombController = _controllerFactor.Create(bomb);

            bombController.transform.SetParent(_container, true);
            _bombs[bomb] = bombController;

            if (MaxSCount < _bombs.Count)
            {
                MaxSCount = _bombs.Count;
            }
            Debug.Log($"{_bombs.Count}/{MaxSCount}");
        }
Пример #2
0
        public void HandleExplosion(BombModel bomb)
        {
            if (!_bombs.ContainsKey(bomb))
            {
                return;
            }

            Collider[] colliders = Physics.OverlapSphere(bomb.Position, bomb.Config.DamageRadius);
            foreach (Collider collider in colliders)
            {
                CharController charController = collider.GetComponent <CharController>();
                if (charController != null && IsDirectImpact(charController.transform.position, bomb.Position))
                {
                    charController.Model.ReceiveDamage(bomb.Config.Damage);
                }
            }

            BombController bombController = _bombs[bomb];

            _bombs.Remove(bomb);
            _controllerFactor.Release(bombController);
        }