I am currently trying to isolate the Combat Engine in the kit, however I have run into a little trouble with a particular key method:
| public static void StartNewCombat(RandomCombat randomCombat) |
located in CombatEngine.cs
I am specifically looking at this location in the code:
| // determine the total probability |
| int totalWeight = 0; |
| foreach (WeightedContentEntry<Monster> entry in randomCombat.Entries) |
| { |
| totalWeight += entry.Weight; |
| } |
| |
| // generate each monster |
| List<CombatantMonster> generatedMonsters = new List<CombatantMonster>(); |
| for (int i = 0; i < monsterCount; i++) |
| { |
| int monsterChoice = Session.Random.Next(10); |
| foreach (WeightedContentEntry<Monster> entry in randomCombat.Entries) |
| { |
| if (monsterChoice < entry.Weight) |
| { |
| generatedMonsters.Add( |
| new CombatantMonster(entry.Content)); |
| break; |
| } |
| else |
| { |
| monsterChoice -= entry.Weight; |
| } |
| } |
| } |
How exactly is this code creating a random list of Monsters? Specifically at:
| foreach (WeightedContentEntry<Monster> entry in randomCombat.Entries) |
Is this code somehow interacting with the XML meta files? Or is something else happening? Is there an easier way to generating a random list of monster on our own without depending on the Map.cs file? Maybe something like this?
| /// <summary> |
| /// Generates a list of CombatantMonster objects |
| /// </summary> |
| private static List<CombatantMonster> GenerateCombatantMonsters() |
| { |
| List<CombatantMonster> generatedMonsters = new List<CombatantMonster>(); |
| |
| // something here? // |
| |
| return generatedMonsters; |
| } |
Any insight on this problem would be helpful.