public void UpdateExperience(int delta) { var experienceAmount = AllEffects .Where(effect => effect is ExperienceEffect) .Select(effect => effect.Amount.Value) .Prepend(100f) .Max(); Experience += (int)(delta * experienceAmount / 100f); if (Experience >= ExperienceRequired) { Level++; Experience -= ExperienceRequired; ExperienceRequired += 100; foreach (var effect in Effects) { effect.LevelUp(); } UpdateStats(); OnLevelUp?.Invoke(this, EventArgs.Empty); } }
private void Update() { if (GameState.Instance.IsPaused || GameState.Instance.IsGameOver) { return; } foreach (var effect in AllEffects.Where(effect => effect.UpdateTimer(Time.deltaTime))) { if (GameState.Instance.IsWaveActive) { switch (effect) { case ExperienceTrickleEffect _: UpdateExperience((int)effect.Amount.Value); break; case GoldTrickleEffect _: GameState.Instance.UpdateGold((int)effect.Amount.Value, this); break; } } } }