Search Unity

WIP: Quest Log

Discussion in 'Scripting' started by novashot, Dec 7, 2010.

  1. novashot

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
    Hey, I been contemplating a quest log system for a while and I narrowed down how I believe I want it to work, but I want to throw some ideas against the forum wall here to shake out anything I may have over looked before I'm too far buried. Anyway, I'm thinking about having all of my quest data in an xml file so quests could be easily added or altered independently of the game.

    Here is an example of how I figured my test xml document would be:
    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8" ?>
    3. <AllQuests>
    4.   <MainQuests>
    5.     <Quest>
    6.       <Number> 0 </Number>
    7.       <Name> Tutorial </Name>
    8.       <NumSteps> 3 </NumSteps>
    9.       <Steps>
    10.         <Step> Talk to Someone </Step>
    11.         <Step> Get Item for Someone </Step>
    12.         <Step> Return to Someone </Step>
    13.       </Steps>
    14.       <xpReward> 100 </xpReward>
    15.       <goldReward> 100 </goldReward>
    16.     </Quest>    
    17.   </MainQuests>
    18.   <SideQuests>
    19.     <Quest>
    20.       <Number>   </Number>
    21.       <Name>   </Name>
    22.       <NumSteps>   </NumSteps>
    23.       <Steps>
    24.         <Step>   </Step>
    25.       </Steps>
    26.       <xpReward>   </xpReward>
    27.       <goldReward>   </goldReward>
    28.     </Quest>
    29.   </SideQuests>
    30. </AllQuests>
    31.  
    In game I figured Id make a quest structure that held the quest info read from the xml something like this:
    Code (csharp):
    1.  
    2. //C#
    3. struct Quest
    4. {
    5.     public int questNumber;      // quest number
    6.     public string questName;     // quest name
    7.     public int numberOfSteps;    // how many steps in this quest
    8.     public string[] questSteps;  // string array of step details
    9.     public int questXP;          // xp reward
    10.     public int questGold;        // gold reward
    11.     public int currentStep;      // current step of quest player is on
    12.     public bool isActive;        // is this quest active
    13.     public bool isCompleted;     // has this quest been completed
    14. }
    15.  
    My quest log in game I figured I could do one of two ways, not sure which was better so was one of the reasons I made this post.

    Option 1: Read in entire quest list xml into an array of Quests and either build a second array based on quests the player has activated or somehow only have visible the active quest elements in the array.

    Option 2: As the Player activates a quest, rebuild his quest array to accept 1 more quest and reread in the xml only importing elements that say active(if possible).... or if not build an array big enough to hold all quest elements from the start, but just filling the array one at a time as the player activates a quest....finding the quest by quest number in the xml and importing that quest element into the array.

    So option 1 reads and imports the whole xml from the beginning and option 2 reads the xml every time a new quest is activated and only imports a single quest element. Any ideas on which is a better approach? Am I over thinking the process and maybe there's an easier way? Maybe I'm thinking about this the wrong way.... I'm looking for any input anyone has in this matter... any help or direction is appreciated and the code I come up with will be posted for all.

    Thanks.