示例#1
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }
            else
            {
                int randomPercentage = RandomNumberGenerator.NumberBetween(1, 100);

                foreach (MonsterEncounter encounter in MonstersHere)
                {
                    if (randomPercentage <= encounter.ChanceOfEncountering)
                    {
                        return(MonsterFactory.Clone(encounter.MonsterId));
                    }
                }
            }

            return(null);
        }
示例#2
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            int runningTotal = 0;

            foreach (MonsterEncounter monsterEncounter in MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;
                if (randomNumber <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterID));
                }
            }
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
示例#3
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));
        }