XNA Creators Club Online
Page 1 of 1 (9 items)
Sort Posts: Previous Next

Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

Last post 8/12/2009 7:18 AM by Colossal. 8 replies.
  • 8/11/2009 4:06 AM

    Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    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.
  • 8/11/2009 9:24 AM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    From what I remember of the code, randomCombat contains all th monsters that your party encounters (spawn point). The combat engine then uses a weighted calculation to determine which of those monster is actually going to attack you in this combat round, in doing so it generates a list of CombatantMonsters. It's not working with the XML files directly, just the randomCombat list.

    Your idea could work, the only thing to think about is what guides the generation on what Monsters and how many to Generate.
  • 8/11/2009 3:38 PM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    What would I need to get something like this to work?

    /// <summary>  
    /// Generates a list of CombatantMonster objects  
    /// </summary>  
    private static List<CombatantMonster> GenerateCombatantMonsters()  
    {  
          List<CombatantMonster> generatedMonsters = new List<CombatantMonster>();  
      
          // something here? //  
      
          return generatedMonsters;  
    }  

    what needs to be passed into generated monsters? Would it be something like generatedMonster.add(new Combatant); ?
  • 8/11/2009 8:34 PM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    That might work, but reason that the list of potential monsters are kept in the map files is so that you can have a different group of monsters spawn based on the map. If you're in a dungeon, then dungeon mobs would randomly appear, if you were in the forest then forest mobs would randomly appear, etc.
  • 8/11/2009 8:51 PM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    Okay I see, thank you very much for your help thus far guys.

    When I say I am trying to isolate the combat engine, I mean completely. I really am trying to see how standalone I can make it without interacting with the Tile Engine at all. I will try out the new Combatant stuff and see if it works.
  • 8/11/2009 9:11 PM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    Okay I tried this method:

    private static List<CombatantMonster> GenerateCombatantMonsters() 
          List<CombatantMonster> generatedMonsters = new List<CombatantMonster>(); 
     
          for(int i = 0; i < 3; i++) 
          { 
                 generatedMonsters.Add(new CombatantMonster(new Monster())); 
          } 
          return generatedMonsters; 

    and this did not work at all.

    I get an exception here, in CombatantMonster.cs

    this.combatSprite = monster.CombatSprite.Clone() as AnimatingSprite; 

    which is part of the CombatantMonster constructor. It's not as simple as that apparently, since it doesnt know what sprites to associate itself with. :/
  • 8/11/2009 10:40 PM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    I don't understand at all how the Monster Objects are generated when you invoke new Monster(),

    Where is it pulling in its sprite data and statistics normally throughout the program? There HAS TO BE some kind of XML interaction deep down, but I can't figure how.
  • 8/12/2009 6:12 AM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    You need to look at the MonsterReader class which calls the FightingCharacterReader class which calls the CharacterReader class and finally the WorldObjectReader class. If you create a new monster, then you need to make sure to set all of the properties of Character and FightingCharacter and WorldObject.

    These reader classes are what reads the XML files to create the objects.

    The default constructor for those classes should have been made private, but it was just a sample and not for technique. You can't invoke the default constructor since it doesn't set any of the properties. You should read up on the Content Pipeline and how it handles XML if you get lost trying to figure out the ContentReader classes.
  • 8/12/2009 7:18 AM In reply to

    Re: Technical question with starter RPG Kit *WARNING: VERY SPECIFIC*

    I think the Combat Engine may be too specifically made for me to have any use from it :/
Page 1 of 1 (9 items) Previous Next