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); } // 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); } 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 (!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); } 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)); }
/// <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()) { // 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 (!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 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); } // 所有在这个地点的怪物的总出现概率 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)); }
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)); }
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 void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { MonstersHere.First(m => m.MonsterID == monsterID).ChanceOfEncountering = chanceOfEncountering; } else { MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int encounterRate) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // This monster is already available at this location, so overwrite its encounter rate with the new value MonstersHere.First(m => m.MonsterID == monsterID).EncounterRate = encounterRate; } else { MonstersHere.Add(new MonsterEncounter(monsterID, encounterRate)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // 这个怪物已经被加入这个地点,所以覆盖ChanceOfEncountering的值 MonstersHere.First(m => m.MonsterID == monsterID).ChanceOfEncountering = chanceOfEncountering; } else { // 这个怪物不在这个地点里,所以把他添加进去 MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterId, int encounterChance) { //if monster already exists in location if (MonstersHere.Exists(m => m.MonsterId == monsterId)) { //change the chance of encounter only MonstersHere.First(m => m.MonsterId == monsterId).EncounterChance = encounterChance; } else { MonstersHere.Add(new MonsterEncounter(monsterId, encounterChance)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // This monster already exists at this location so overwrite the Encounter chance with the new number MonstersHere.First(m => m.MonsterID == monsterID).ChanceOfEncountering = chanceOfEncountering; } else { //The monster isn't already here so add it. MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { //Monster je vec dodan u tu lokaciju pa overwritaj chanceofencounter MonstersHere.First(m => m.MonsterID == monsterID).ChanceOfEncountering = chanceOfEncountering; } else { //Monster nije na lokaciji, dodaj ga MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // Monster already exists, update ChanceOfEncountering MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceOfEncountering; } else { // Monster does not already exist, add it MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceofEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { //This monster has already loaded so overwrite the chanceOfEncountering with the new number MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceofEncountering; } else { //This monster needs to loaded so add it MonstersHere.Add(new MonsterEncounter(monsterID, chanceofEncountering)); } }
public void AddMonster(int monsterid, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterid)) { //This monster has already been added to this location //So, overwrite the changeOfEncountering with the new number MonstersHere.First(m => m.MonsterID == monsterid).ChanceOfEncounter = chanceOfEncountering; } else { //this monster is not already here, so add it MonstersHere.Add(new MonsterEncounter(monsterid, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // This monster has already been added to this location. MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceOfEncountering; } else { // This monster is not already at this location, so add it. MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // if this monster is already in list: // overwrite ChanceOfEncountering with new value MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceOfEncountering; } else { // otherwise add to list MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEnocountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { //This monsted has already been added to the location //So,overwrite the ChanceOfEncountering with the new number. MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceOfEnocountering; } else { //This monster is not already at this locationg so add it. MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEnocountering)); } }
/// <summary> /// 根据怪物ID和出现概率添加怪物 /// </summary> /// <param name="monsterId">怪物ID</param> /// <param name="chanceOfEncountering">出现概率</param> public void AddMonster(int monsterId, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterId == monsterId)) { //这个怪物已经被添加到这个位置。 //所以,用这个新数字来表示遇到的可能性。 MonstersHere.First(m => m.MonsterId == monsterId) .ChanceOfEncountering = chanceOfEncountering; } else { // 这个怪物还没有在这个位置,所以添加它。 MonstersHere.Add(new MonsterEncounter(monsterId, chanceOfEncountering)); } }
public void AddMonster(int monsterId, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterId == monsterId)) { // this monster has already been added to this location. // override the chance to see them with a new value MonstersHere.First(m => m.MonsterId == monsterId) .ChanceOfEncountering = chanceOfEncountering; } else { // monster new to the area MonstersHere.Add(new MonsterEncounter(monsterId, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { // Det her monster er allerede sat in på lokalitionerne. // So vi ændre "ChanceofEnountering" med et nyt nummer. MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceOfEncountering; } else { // This monster is not already at this location, so add it. MonstersHere.Add(new MonsterEncounter(monsterID, chanceOfEncountering)); } }
public void AddMonster(int monsterID, int chanceOfEncountering) { if (MonstersHere.Exists(m => m.MonsterID == monsterID)) { //Monster already at this location //Only chance of encountering monster is updated MonstersHere.First(m => m.MonsterID == monsterID) .ChanceOfEncountering = chanceOfEncountering; } else { //The monster doesn't exist at this location, so add monster and is chance of being encountering MonstersHere.Add(new MonsterEncouter(monsterID, chanceOfEncountering)); } }