Exemple #1
0
        public Monster GetMonster()
        {
            if (!MonsterHere.Any())
            {
                return(null);
            }

            // Total the percentages of all monsters at this location
            int totalChances = MonsterHere.Sum(m => m.ChanceOfEncounter);

            // Select a random number between 1 and the total (in case the total
            //chance is not 100
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            // Loop through the monster list
            // adding the monster's percentage chance of operating to the runningTotal variable
            // When the random number is lower than the runningTotal
            // That is the monster to return
            int runningTotal = 0;

            foreach (MonsterEncounter monsterEncounter in MonsterHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncounter;

                if (randomNumber <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterID));
                }
            }

            // If there was a problem, return the last monster in the list.
            return(MonsterFactory.GetMonster(MonsterHere.Last().MonsterID));
        }
Exemple #2
0
        public Monster GetMonster()
        {
            if (!MonsterHere.Any())
            {
                return(null);
            }

            int totalChances = MonsterHere.Sum(m => m.ChanceOfEncountering);

            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            int runningTotal = 0;

            foreach (MonsterEncounter monsterEncounter in MonsterHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;

                if (randomNumber <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterID));
                }
            }

            return(MonsterFactory.GetMonster(MonsterHere.Last().MonsterID));
        }
Exemple #3
0
 public bool MonsterOnLocation()
 {
     if (MonsterHere.Any())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #4
0
 public void AddMonster(int monsterID, int chanceOfEncountering)
 {
     if (MonsterHere.Exists(m => m.MonsterID == monsterID))
     {
         MonsterHere.First(m => m.MonsterID == monsterID)
         .ChanceOfEncountering = chanceOfEncountering;
     }
     else
     {
         MonsterHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering));
     }
 }
Exemple #5
0
 public void AddMonster(int monsterID, int chanceOfEncountering)
 {
     if (MonsterHere.Exists(m => m.MonsterID == monsterID))
     {
         //Hvis monster er her, reset gammel værdi med ny værdi.
         MonsterHere.First(m => m.MonsterID == monsterID).ChanceOfEncountering = chanceOfEncountering;
     }
     else
     {
         //Hvis der ikke er noget monster, tilføj monster.
         MonsterHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering));
     }
 }
Exemple #6
0
 public void AddMonster(int monsterID, int chanceOfEncounter)
 {
     if (MonsterHere.Exists(m => m.MonsterID == monsterID))
     {
         // This monster has already been loaded in this location
         // so, overwrite the ChanceOfEncounter with the new number
         MonsterHere.First(m => m.MonsterID == monsterID)
         .ChanceOfEncounter = chanceOfEncounter;
     }
     else
     {
         // This monster is not already at this location, so add it.
         MonsterHere.Add(new MonsterEncounter(monsterID, chanceOfEncounter));
     }
 }
Exemple #7
0
        public Monster GetMonster()
        {
            if (!MonsterHere.Any())
            {
                return(null);
            }
            // Procenten af monster på given location
            int totalChances = MonsterHere.Sum(m => m.ChanceOfEncountering);
            // Finder et nummer mellem 1 og maks
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            int runningTotal = 0;

            foreach (MonsterEncounter monsterEncounter in MonsterHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;
                if (randomNumber <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterID));
                }
            }
            // Hvis der er en fejl i listen, giver den sidste kendte id
            return(MonsterFactory.GetMonster(MonsterHere.Last().MonsterID));
        }