Esempio n. 1
0
        // Recalculate the experience reward for this encounter.
        private void RecalculateExperienceReward()
        {
            // Recalulate total xp.
            int totalXp = 0;

            foreach (MonsterDefinition monster in Monsters)
            {
                totalXp += EncounterBalanceData.GetExperienceReward(monster.ChallengeRating);
            }

            // Apply experience adjustments.
            int multiplier = EncounterBalanceData.GetExperienceMultiplier(PlayerCharacters.Count, Monsters.Count);

            totalXp = totalXp * multiplier / 100;

            // Apply total experience reward.
            TotalExperienceReward = totalXp;
            ExperiencePerPlayer   = PlayerCharacters.Count > 0 ? TotalExperienceReward / PlayerCharacters.Count : 0;
        }
Esempio n. 2
0
        // Called when the PlayerCharacters collection changes.
        private void OnPlayerCharactersChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // Prepare to recalculate player data.
            var pcs = sender as ObservableCollection <PlayerCharacter>;

            // Count player levels.
            int totalPlayerLevel = 0;

            // Measure XP threshold for each difficulty.
            var difficulties = Enum.GetValues(typeof(EncounterDifficulty)) as EncounterDifficulty[];

            int[] experienceThresholds = new int[difficulties.Length];

            // Do math on each player's data.
            foreach (PlayerCharacter pc in pcs)
            {
                // Update total level.
                totalPlayerLevel += pc.Level;

                // Update XP threshold.
                foreach (var difficulty in difficulties)
                {
                    int experienceThreshold = EncounterBalanceData.GetExperienceThreshold(pc.Level, difficulty);
                    experienceThresholds[(int)difficulty] += experienceThreshold;
                }
            }

            // Recalculate average player level.
            double preciseAveragePlayerLevel = (double)totalPlayerLevel / pcs.Count;

            AveragePlayerLevel = (int)Math.Round(preciseAveragePlayerLevel);

            // Update experience thresholds.
            ExperienceThresholds = experienceThresholds;

            // Reevaluate the difficulty of the encounter.
            RecalculateExperienceReward();
            RecalculateDifficulty();
        }