Professional Documents
Culture Documents
Introduction
In this tutorial, you are going to add a quest to an instance in the Role-Playing Game
(RPG) Sample. You can apply this tutorial to an instance of the sample without any
other modifications.
What is a Quest?
Quests are an important part of a role-playing game. A quest defines the storyline
that takes the player through the game content. In the RPG Sample, quests provide
additional dangers and rewards to the player. They provide access to the next
element in the story line.
Quests are specified as XML files. They are located in the Content\Quests directory
in the Sample. These XML files are built by the XNA Content Pipeline. They are
loaded at run time into a Quest object. They are defined in Quests\Quest.cs in the
RolePlayingGameData project for your platform.
As each quest is completed, the next quest in the quest line immediately begins
until there are no more quests.
Outer Tags
The outermost tags are required for the XNA Content Pipeline, but they are not very
interesting to us. They must be present in all XML files that describe quests.
Otherwise, the XNA Content Pipeline cannot load the file.
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="RolePlayingGameData.Quest">
</Asset>
</XnaContent>
Add the rest of the tags inside the Asset tag. The order of the content is
significant. Your quest will fail to build (typically with a missing tag error where it
expected to find certain information) if all of the required information is not present
in the correct order.
The <Description> tag is the longer description displayed when the quest-detail
screen appears in-game when the quest is started or updated or after selecting a
quest in the quest log screen.
<Description>I do not think that you are quite ready for combat yet. Find me
one more Glimmering Ruby, and I will reward you again. Then, we shall see how
you fare in combat.</Description>
The text within the <CompletionMessage> tag is shown in one of two situations:
1) There is a destination NPC that the party must visit to finish the quest. In this
case, the completion message is shown as the NPCs dialogue when the party
visits him or her.
2) There is not a destination NPC. In this case, the completion dialogue is shown
in a Quest Complete dialogue screen as soon as all requirements are met,
and before the rewards screen is shown.
Like the <Description> and <ObjectiveMessage> tags, it is mandatory, though it
may be empty.
<CompletionMessage>Thank you for the Glimmering Ruby. I shall reward you with
the Hide Helmet. Go to the Inventory screen and equip it now!
</CompletionMessage>
Quest Requirements
All quests must have two requirement list tags:
Each requirement in each list is loaded by the XNA Content Pipeline at runtime into
a QuestRequirement object, defined in Quests\QuestRequirement.cs in the
RolePlayingGameData project for your platform. Each item in the XML file has a
<ContentName> tag, which is specified using theXNA Content Pipeline content
name property (relative to the Content\Gear folder for gear requirements and
Content\Characters\Monsters folder for monster requirements). Also, each item has
a <Count> tag with the required number of gear or monsters for the requirement to
be met.
Like all list tags in the RPG Sample content files, each entry in the list is contained
with an <Item> tag. Like the earlier messages, both tags are required, but either or
both may be empty.
<GearRequirements>
<Item>
<ContentName>Items\GlimmeringRuby</ContentName>
<Count>1</Count>
</Item>
</GearRequirements>
<MonsterRequirements />
Though this quest will not require any monsters, here is an example of a non-empty
monster tag. Do not add this to your quest it will be difficult to complete.
<MonsterRequirements>
<Item>
<ContentName>SirShire</ContentName>
<Count>1</Count>
</Item>
</MonsterRequirements>
Quest Entries
When a quest is active, it can add map entries to the world, in any map it wants. A
quest must have two kinds of entry list tags:
These entries typically are added to ensure the player can find the monsters and
gear required by the quest.
Each entry has a <ContentName> tag, which is specified using theXNA Content
Pipeline content names property (relative to the Content\Map\FixedCombats folder
for fixed-combat entries and Content\Maps\Chests folder for treasure-chest entries).
Also, each item has a <MapPosition> and <MapContentName> tag (relative to the
Content\Maps folder) to specify the location of each entry. Finally, each fixedcombat entry has a <Direction> tag with the direction that the monster is facing on
the world map.
Like all list tags in the RPG Sample content files, each entry in the list is contained
with an <Item> tag. Like the earlier messages, both tags are required, but either or
both may be empty.
<FixedCombatEntries />
<ChestEntries>
<Item>
<ContentName>Ruby</ContentName>
<MapPosition>13 9</MapPosition>
<MapContentName>Map001</MapContentName>
</Item>
</ChestEntries>
Though this quest will not require any monsters, here is an example of a non-empty
monster tag. Do not add this to your quest it will be difficult to complete.
<FixedCombatEntries>
<Item>
<ContentName>SirShire</ContentName>
<MapPosition>9 19</MapPosition>
<Direction>North</Direction>
<MapContentName>Map001</MapContentName>
</Item>
</FixedCombatEntries>
Optional Destination
When all requirements have been met, some quests require the party to return to a
particular NPC to receive the reward. When the party interacts with this NPC, the
party receives one final dialogue. Then the rewards screen appears.
There are three tags to specify this destination.
<DestinationMap>, containing the content name of the map that the NPC
is on (relative to the Content\Maps folder).
<DestinationNpc>, containing the content name of the quest NPC with
which the party must interact (relative to the Content\Characters\QuestNPCs
folder). Note that if more than one of that quests NPC is on the specified
map, then any one of them will complete the quest.
<DestinationObjectiveMessage>, containing the message shown under
the Current Objective heading in the Quest Detail screen after all
requirements have been met.
Each of these tags is optional, so the quest will build if they are not present. If they
are present, they must still appear in the order listed above.
Both the <DestinationMap> and <DestinationNpc> must be present and non-empty
for the destination to be valid. If the destination is valid, then the Quest Detail
screen appears when the requirements are met. The message in the
<DestinationObjectMessage> tag appears under the Current Objective heading.
When the party meets with the destination NPC, the message in the
<CompletionMessage> tag is shown as the NPCs dialogue. If the destination is not
valid, the message in the <Completion> tag appears in its own screen when the
requirements are met, and the quest concludes immediately.
<DestinationMapContentName>Map001</DestinationMapContentName>
<DestinationNpcContentName>Sheddarr</DestinationNpcContentName>
<DestinationObjectiveMessage>Go and speak with Shed-darr the
Wise.</DestinationObjectiveMessage>
Optional Rewards
When all requirements are met, and the destination NPC has been met (or, if there
is no destination NPC, the Quest Complete dialogue screen has been dismissed),
the rewards screen appears and a sound effect plays. Quests provide three kinds of
rewards tags:
Each of these tags are optional, so the quest will build if they are not present. If
they are present, they must still appear in the order listed above.
<ExperienceReward>50</ExperienceReward>
<GoldReward>50</GoldReward>
<GearRewardContentNames>
<Item>Armor\HideHelmet</Item>
</GearRewardContentNames>
Lets Review
Lets take a look at the whole XML file we constructed with our new quest.
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="RolePlayingGameData.Quest">
<Name>And Now, A Helmet</Name>
<Description>I do not think that you are quite ready for combat yet. Find me
one more Glimmering Ruby, and I will reward you again. Then, we shall see how
you fare in combat.</Description>
<ObjectiveMessage>Look for another nearby chest that contains the Glimmering
Ruby.</ObjectiveMessage>
<CompletionMessage>Thank you for the Glimmering Ruby. I shall reward you with
the Hide Helmet. Go to the Inventory screen and equip it now!
</CompletionMessage>
<GearRequirements>
<Item>
<ContentName>Items\GlimmeringRuby</ContentName>
<Count>1</Count>
</Item>
</GearRequirements>
<MonsterRequirements />
<FixedCombatEntries />
<ChestEntries>
<Item>
<ContentName>Ruby</ContentName>
<MapPosition>13 9</MapPosition>
<MapContentName>Map001</MapContentName>
</Item>
</ChestEntries>
<DestinationMapContentName>Map001</DestinationMapContentName>
<DestinationNpcContentName>Sheddarr</DestinationNpcContentName>
<DestinationObjectiveMessage>Go and speak with Shed-darr the
Wise.</DestinationObjectiveMessage>
<ExperienceReward>50</ExperienceReward>
<GoldReward>50</GoldReward>
<GearRewardContentNames>
<Item>Armor\HideHelmet</Item>
</GearRewardContentNames>
</Asset>
</XnaContent>
Make sure the XML file is part of your RolePlayingGame project for your platform, in
the Content\Quests folder. Now you can build your project. If you get any errors at
build-time, make sure your quest file matches the text given above.
Lets insert this quest to the list just before the test battle, using its content name
(relative to the Content\Quests folder):
<Item>ShortSword</Item>
<Item>AndNowAHelmet</Item>
<Item>TestBattle</Item>
Save the quest line XML file, and build the project. As before, if you get any errors
at build-time, make sure that your file matches the text given above.
Lets Play!
Start up the game. Either start a new game or load a saved game from before the
Short Sword quest was completed. The first few quests can be completed quickly,
and then the new quest will be activated. Congratulations! Youre playing your own
quest!
Conclusion
The power of the quest system in the RPG Sample is obvious, but there are certain
limits to how quests are defined and executed. However, you can modify the code
in the quest system. You can add the ability to have secondary simultaneous quest
lines, more quest entries, more quest requirements, different behavior for quest
completion or requirement checks, and so on. Think about what your ideal quest
line would require from such a system, and make it happen!
By this time, the power of the quest system should be clear. It should allow you to
define your own storyline within the RPG Sample. The only limit is your
imagination!