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)); }
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)); }
public Monster GetMonster() { if (!MonstersHere.Any()) { return(null); } // add the percentages of all monsters at location 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 an instance of the monster by its ID, if there was a problem return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID)); }
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)); }
/// <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); } //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)); }
public Monster GetMonster() { if (!MonstersHere.Any()) { return(null); } // Suma szans na spotkanie stworka w tej lokacji int totalChances = MonstersHere.Sum(m => m.ChanceOfEncountering); // Wybierz losowy numer, pod warunkiem, że szansa nie równa się 100% int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances); // Kiedy losowy numer jest mniejszy lub równy od runningTotal, który rośnie po każdej pętli // to zwróc takiego stworka int runningTotal = 0; foreach (MonsterEncounter monsterEncounter in MonstersHere) { runningTotal += monsterEncounter.ChanceOfEncountering; if (randomNumber <= runningTotal) { return(MonsterFactory.GetMonster(monsterEncounter.MonsterID)); } } // Jeśli pojawi się problem, zwróć ostatniego stworka z listy return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID)); }
public Monster GetMonster() { if (!MonstersHere.Any()) // if no monsters encounter objects { return(null); } // Toatal the percentages of all monsters at this locations , monsters at this location int totalChances = MonstersHere.Sum(m => m.ChanceOfEncoutering); // Select the random number between 1 and the total int randomNumber = RandomNumberGenerator.NumberBetween(1, totalChances); int runningTotal = 0; foreach (MonsterEncounter monsterEncounter in MonstersHere) { runningTotal += monsterEncounter.ChanceOfEncoutering; // chance of encountering on last monster more than on first if (randomNumber <= runningTotal) { return(MonsterFactory.GetMonster(monsterEncounter.MonsterID)); } } // if no return any monster for assure return last monster return(MonsterFactory.GetMonster(MonstersHere.Last().MonsterID)); }
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)); }
public Monster GetMonster() { if (!monsterHere.Any()) { return(null); } //total percentages of all monsters at location int totalChance = monsterHere.Sum(m => m.encounterChance); //select random number between 1 and total int randomNumber = RandomNumberGenerator.numberBetween(1, totalChance); //loop thru monster list adding monster's percentage chance of appearing to runningtotal var //when random num is lower than running total, monster returns int runningTotal = 0; foreach (MonsterEncounter monsterEncounter in monsterHere) { runningTotal += monsterEncounter.encounterChance; if (randomNumber <= runningTotal) { return(MonsterFactory.GetMonster(monsterEncounter.monsterID)); } } //if there was a problem, return last monster in list return(MonsterFactory.GetMonster(monsterHere.Last().monsterID)); }
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)); }
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)); }
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)); }
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)); }
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 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)); }
public Monster GetMonster() { if (!MONSTERSHERE.Any()) { return(null); } //total the percentages of all monsters at this location int totalChances = MONSTERSHERE.Sum(m => m.ENCOUNTERCHANCE); //select a random numbet 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 the runningTotal var //when randomNumber is lower than runningTotal //that is the monster to return int runningTotal = 0; foreach (MonsterEncounter monsterEncounter in MONSTERSHERE) { runningTotal += monsterEncounter.ENCOUNTERCHANCE; 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)); }
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)); }