Example #1
0
        public Monster GetMonster()
        {
            //If there are no MonsterEncounters, return null (no monster at location)
            if (!MonstersHere.Any())
            {
                return(null);
            }

            //Sum the percentages of all monsters at this location
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            //Select a random number between 1 and the total
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            //Loop through the monster list, adding the monster's percentage chance of appearing
            //to runningTotal. When randomNumber < runningTotal, the monster is returned.
            int runningTotal = 0;

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

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

            //If there was a problem, return the last monster in the list. This should never happen
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #2
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())//if there are no montsers here
            {
                return(null);
            }

            //total percentage of all monsters in this location
            int total = MonstersHere.Sum(m => m.EncounterChance);

            //random number between 1 and total chanches
            int randChance = RandNumGen.NumBetween(1, total);

            //when random chance is less than running total, return that monster
            int runningTotal = 0;

            foreach (MonsterEncounter me in MonstersHere)
            {
                runningTotal += me.EncounterChance;

                if (randChance <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(me.MonsterId));
                }
            }
            //in case of a problem return last
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterId));
        }
Example #3
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            // Total chance of encountering any monster
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            // Get random number between 1 and totalChances
            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));
                }
            }

            // In case of issue, return last monster in list
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #4
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                // No monsters here
                return(null);
            }
            else
            {
                // Total encounter rate for all monsters in this location
                int totalEncounterPercentage = MonstersHere.Sum(m => m.EncounterRate);

                // Select a random number in range
                int randomNumber = RandomNumberGenerator.NumberBetween(1, totalEncounterPercentage);

                // Loop through the monster list,
                // adding the monster's percentage chance of appearing 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 MonstersHere)
                {
                    runningTotal += monsterEncounter.EncounterRate;

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

            // if a problem occured, return last monster in the collection
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #5
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

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

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

            // Loop through the monster list,
            // adding the monster's percentage chance of appearing 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 MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;

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

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

            //Total percentages of all monster encounter chances here
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            //select random number between 1 and total
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            //Iterate through monster list
            //Create a running total of monster percentages
            //Once the random number < running total
            //return the monster iterator is currently on
            int runningTotal = 0;

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

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

            //If something happened then return the last monster in the list
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #7
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.GetMonsterByID(monsterEncounter.MonsterID));
                }
            }

            //En cas de problème
            return(MonsterFactory.GetMonsterByID(MonstersHere.Last().MonsterID));
        }
Example #8
0
        /// <summary>
        /// 获取怪物
        /// </summary>
        /// <returns></returns>
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            // 计算此位置所有怪物的概率
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            // 选择一个介于1和总数之间的随机数(以防总数不是100)。
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            //运行总数
            int runningTotal = 0;

            //循环遍历怪物列表,将怪物出现的概率百分比添加到runningTotal变量中。
            //当随机数低于运行总数时,这就是要返回的怪物。
            foreach (MonsterEncounter monsterEncounter in MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;

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

            // 如果有问题,返回列表的最后一个怪物
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterId));
        }
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            // 所有在这个地点的怪物的总出现概率
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            // 从 1 - 总概率(总概率不一定是100) 中随机一个号码
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            // 遍历MonstersHere列表,将列表里怪物的出现率加到runningTotal变量里,
            // 当随机数小于runningTotal,那么就返回该怪物
            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));
        }
Example #10
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            var totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

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

            var runningTotal = 0;

            foreach (var monsterEncounter in MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;

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

            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #11
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            //Total percentages of all monsters at this location
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

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

            //Loop through the monster list,
            //adding the monster's percentage chance of appearing to the runningTotal variable.
            // When the random number is lower than the runningTotal,
            // that us the monster to return.
            int runningTotal = 0;

            // This allows multiple monsters at a location. For each monster spawn at a location
            // there is a random check to see if the monster actually spawns.
            // The odds of encountering a given monster type is dependent on the monster type's
            //given encounter rate and the rate of monsters spawn at a given location.
            foreach (MonsterEncouter monsterEncounter in MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;
                if (randomNumber <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterID));
                }
            }

            //On the off chance there was a problem, returns the last monster in the list.
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #12
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }



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


            // tager et random tal mellem 1 og totalen (Som ikke er 100 i det her tilfælde.)
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);


            // går i loop igennem monster listen,
            // hvor den smider Monsteres procent chance for at være der i "runningTotal" variablen.
            // når det random nummer er mindre end "runningTotal",
            // så er det, det monster der kommer.
            int runningTotal = 0;

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

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

            // Hvis der opstår et problem, send sidste monster på listen ind.
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #13
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            //Total percentage od svih monstera u lokaciji
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            //Selectaj random number izmedu 1 i percentage monstera u lokaciji
            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));
        }
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            // Total percentages of all monsters at this location.
            int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering);

            // Select a random number between 1 and that total in case it isn't 100.
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances);

            // Loop through the monster list, adding percentage chances to the running total. When the random number is lower than the total, that is the
            // chosen monster.
            int runningTotal = 0;

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

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

            // If there's any problems, return the last monster in the list.
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
Example #15
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }
            int totalChance  = MonstersHere.Sum(x => x.ChanceOfEncounter);
            int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChance);

            int runningTotal = 0;

            foreach (MonsterEncounter monsterEncounter in MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncounter;
                if (randomNumber <= runningTotal)
                {
                    MonsterFactory.GetMonster(monsterEncounter.MonsterID);
                }
            }
            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
            //if there was a problem, get the monster from the last of list
        }
Example #16
0
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            int chances      = MonstersHere.Sum(m => m.ChanceOfEncounter);
            int randomNumber = RandomNumberGenerator.NumberBetween(1, chances);
            int total        = 0;

            foreach (MonsterEncounter monsterEncounter in MonstersHere)
            {
                total += monsterEncounter.ChanceOfEncounter;

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

            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID));
        }
        public Monster GetMonster()
        {
            if (!MonstersHere.Any())
            {
                return(null);
            }

            int totalEncounterChance = MonstersHere.Sum(m => m.ChanceOfEncountering);
            int rng = RandomNumberGenerator.NumberBetween(1, totalEncounterChance);

            int runningTotal = 0;

            foreach (var monsterEncounter in MonstersHere)
            {
                runningTotal += monsterEncounter.ChanceOfEncountering;

                if (rng <= runningTotal)
                {
                    return(MonsterFactory.GetMonster(monsterEncounter.MonsterId));
                }
            }

            return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterId));
        }