예제 #1
0
 public void RemoveItem(int index)
 {
     Items[index].UpdateTower(null);
     AllEffects.RemoveWhere(effect => effect.Item == Items[index]);
     Items.RemoveAt(index);
     UpdateStats();
     OnItemRemoved?.Invoke(this, index);
 }
예제 #2
0
        private void Update()
        {
            if (GameState.Instance.IsPaused || GameState.Instance.IsGameOver)
            {
                return;
            }

            AllEffects.RemoveWhere(effect => !effect.IsConstant && (effect.Duration.Value -= Time.deltaTime) <= 0f);

            var statusColors = new SortedDictionary <string, Color>();

            foreach (var effect in AllEffects)
            {
                if (effect.UpdateTimer(Time.deltaTime) && effect.Source is TowerBase tower)
                {
                    var damage = effect switch
                    {
                        PoisonEffect _ => effect.Amount.Value,
                        BleedEffect _ => Health *effect.Amount.Value / 100f,
                         _ => 0f
                    };

                    tower.EnemyAttacked(Math.Min(damage, Health));
                    if (UpdateHealth(-damage))
                    {
                        tower.EnemyKilled(this);
                    }
                }
                statusColors[effect.Name] = effect.StatusColor;
            }

            var index = 0;

            foreach (var statusColor in statusColors.Values)
            {
                _statusIndicators[index].color   = statusColor;
                _statusIndicators[index].enabled = true;
                index++;
            }
            for (var i = index; i < _statusIndicators.Length; i++)
            {
                _statusIndicators[i].enabled = false;
            }
        }