protected bool WereStatsIncreased(IncreaseStatsKind kind) { if (StatsIncreased.ContainsKey(kind)) { return(StatsIncreased[kind]); } return(false); }
/// <summary> /// Increases the player's XP. /// Increases the player's level and updates stats if XP is high enough. /// Invokes the <see cref="StatsIncreased"/> event. /// </summary> /// <param name="amount">The amount of XP to give to the player</param> /// <returns>True if the player leveled up; false otherwise</returns> public bool GiveXP(int amount) { List <StatIncrease> increasedStats = new(); int curLevel = Level; bool leveledUp = false; XP += amount; increasedStats.Add(new(Stats.XP, amount, XP)); for (int i = 0; i < XP_TO_LEVEL_UP.Length; i++) { int newLevel = i + 2; // Player has enough xp to reach level [i+2] if (XP > XP_TO_LEVEL_UP[i]) { if (newLevel > Level) { Level = newLevel; leveledUp = true; } } else { break; } } if (leveledUp) { increasedStats.Add(new StatIncrease(Stats.LEVEL, Level - curLevel, Level)); increasedStats.AddRange(UpdateStats()); increasedStats = OrderStatsList(increasedStats); } StatsIncreased?.Invoke(this, new StatsIncreasedEventArgs() { StatsIncreased = increasedStats }); return(leveledUp); }