#region File Description
//-----------------------------------------------------------------------------
// Quest.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework.Content;
#endregion
namespace RolePlayingGameData
{
///
/// A quest that the party can embark on, with goals and rewards.
///
public class Quest : ContentObject
#if WINDOWS
, ICloneable
#endif
{
#region Quest Stage
///
/// The possible stages of a quest.
///
public enum QuestStage
{
NotStarted,
InProgress,
RequirementsMet,
Completed
};
///
/// The current stage of this quest.
///
private QuestStage stage = QuestStage.NotStarted;
///
/// The current stage of this quest.
///
[ContentSerializerIgnore]
public QuestStage Stage
{
get { return stage; }
set { stage = value; }
}
#endregion
#region Description
///
/// The name of the quest.
///
private string name;
///
/// The name of the quest.
///
public string Name
{
get { return name; }
set { name = value; }
}
///
/// A description of the quest.
///
private string description;
///
/// A description of the quest.
///
public string Description
{
get { return description; }
set { description = value; }
}
///
/// A message describing the objective of the quest,
/// presented when the player receives the quest.
///
private string objectiveMessage;
///
/// A message describing the objective of the quest,
/// presented when the player receives the quest.
///
public string ObjectiveMessage
{
get { return objectiveMessage; }
set { objectiveMessage = value; }
}
///
/// A message announcing the completion of the quest,
/// presented when the player reaches the goals of the quest.
///
private string completionMessage;
public string CompletionMessage
{
get { return completionMessage; }
set { completionMessage = value; }
}
#endregion
#region Requirements
///
/// The gear that the player must have to finish the quest.
///
private List> gearRequirements =
new List>();
///
/// The gear that the player must have to finish the quest.
///
public List> GearRequirements
{
get { return gearRequirements; }
set { gearRequirements = value; }
}
///
/// The monsters that must be killed to finish the quest.
///
private List> monsterRequirements =
new List>();
///
/// The monsters that must be killed to finish the quest.
///
public List> MonsterRequirements
{
get { return monsterRequirements; }
set { monsterRequirements = value; }
}
///
/// Returns true if all requirements for this quest have been met.
///
public bool AreRequirementsMet
{
get
{
foreach (QuestRequirement gearRequirement in gearRequirements)
{
if (gearRequirement.CompletedCount < gearRequirement.Count)
{
return false;
}
}
foreach (QuestRequirement monsterRequirement
in monsterRequirements)
{
if (monsterRequirement.CompletedCount < monsterRequirement.Count)
{
return false;
}
}
return true;
}
}
#endregion
#region Quest Content
///
/// The fixed combat encounters added to the world when this quest is active.
///
private List> fixedCombatEntries =
new List>();
///
/// The fixed combat encounters added to the world when this quest is active.
///
public List> FixedCombatEntries
{
get { return fixedCombatEntries; }
set { fixedCombatEntries = value; }
}
///
/// The chests added to thew orld when this quest is active.
///
private List> chestEntries = new List>();
///
/// The chests added to thew orld when this quest is active.
///
public List> ChestEntries
{
get { return chestEntries; }
set { chestEntries = value; }
}
#endregion
#region Destination
///
/// The map with the destination Npc, if any.
///
private string destinationMapContentName;
///
/// The map with the destination Npc, if any.
///
[ContentSerializer(Optional = true)]
public string DestinationMapContentName
{
get { return destinationMapContentName; }
set { destinationMapContentName = value; }
}
///
/// The Npc that the party must visit to finish the quest, if any.
///
private string destinationNpcContentName;
///
/// The Npc that the party must visit to finish the quest, if any.
///
[ContentSerializer(Optional = true)]
public string DestinationNpcContentName
{
get { return destinationNpcContentName; }
set { destinationNpcContentName = value; }
}
///
/// The message shown when the party is eligible to complete the quest, if any.
///
private string destinationObjectiveMessage;
///
/// The message shown when the party is eligible to complete the quest, if any.
///
[ContentSerializer(Optional = true)]
public string DestinationObjectiveMessage
{
get { return destinationObjectiveMessage; }
set { destinationObjectiveMessage = value; }
}
#endregion
#region Reward
///
/// The number of experience points given to each party member as a reward.
///
private int experienceReward;
///
/// The number of experience points given to each party member as a reward.
///
[ContentSerializer(Optional = true)]
public int ExperienceReward
{
get { return experienceReward; }
set { experienceReward = value; }
}
///
/// The amount of gold given to the party as a reward.
///
private int goldReward;
///
/// The amount of gold given to the party as a reward.
///
[ContentSerializer(Optional = true)]
public int GoldReward
{
get { return goldReward; }
set { goldReward = value; }
}
///
/// The content names of the gear given to the party as a reward.
///
private List gearRewardContentNames = new List();
///
/// The content names of the gear given to the party as a reward.
///
[ContentSerializer(Optional = true)]
public List GearRewardContentNames
{
get { return gearRewardContentNames; }
set { gearRewardContentNames = value; }
}
///
/// The gear given to the party as a reward.
///
private List gearRewards = new List();
///
/// The gear given to the party as a reward.
///
[ContentSerializerIgnore]
public List GearRewards
{
get { return gearRewards; }
set { gearRewards = value; }
}
#endregion
#region Content Type Reader
///
/// Reads a Quest object from the content pipeline.
///
public class QuestReader : ContentTypeReader
{
///
/// Reads a Quest object from the content pipeline.
///
protected override Quest Read(ContentReader input, Quest existingInstance)
{
Quest quest = existingInstance;
if (quest == null)
{
quest = new Quest();
}
quest.AssetName = input.AssetName;
quest.Name = input.ReadString();
quest.Description = input.ReadString();
quest.ObjectiveMessage = input.ReadString();
quest.CompletionMessage = input.ReadString();
quest.GearRequirements.AddRange(
input.ReadObject>>());
quest.MonsterRequirements.AddRange(
input.ReadObject>>());
// load the fixed combat entries
Random random = new Random();
quest.FixedCombatEntries.AddRange(
input.ReadObject>>());
foreach (WorldEntry fixedCombatEntry in
quest.FixedCombatEntries)
{
fixedCombatEntry.Content =
input.ContentManager.Load(
System.IO.Path.Combine(@"Maps\FixedCombats",
fixedCombatEntry.ContentName));
// clone the map sprite in the entry, as there may be many entries
// per FixedCombat
fixedCombatEntry.MapSprite =
fixedCombatEntry.Content.Entries[0].Content.MapSprite.Clone()
as AnimatingSprite;
// play the idle animation
fixedCombatEntry.MapSprite.PlayAnimation("Idle",
fixedCombatEntry.Direction);
// advance in a random amount so the animations aren't synchronized
fixedCombatEntry.MapSprite.UpdateAnimation(
4f * (float)random.NextDouble());
}
quest.ChestEntries.AddRange(
input.ReadObject>>());
foreach (WorldEntry chestEntry in quest.ChestEntries)
{
chestEntry.Content = input.ContentManager.Load(
System.IO.Path.Combine(@"Maps\Chests",
chestEntry.ContentName)).Clone() as Chest;
}
quest.DestinationMapContentName = input.ReadString();
quest.DestinationNpcContentName = input.ReadString();
quest.DestinationObjectiveMessage = input.ReadString();
quest.experienceReward = input.ReadInt32();
quest.goldReward = input.ReadInt32();
quest.GearRewardContentNames.AddRange(
input.ReadObject>());
foreach (string contentName in quest.GearRewardContentNames)
{
quest.GearRewards.Add(input.ContentManager.Load(
Path.Combine("Gear", contentName)));
}
return quest;
}
}
#endregion
#region ICloneable Members
public object Clone()
{
Quest quest = new Quest();
quest.AssetName = AssetName;
foreach (WorldEntry chestEntry in chestEntries)
{
WorldEntry worldEntry = new WorldEntry();
worldEntry.Content = chestEntry.Content.Clone() as Chest;
worldEntry.ContentName = chestEntry.ContentName;
worldEntry.Count = chestEntry.Count;
worldEntry.Direction = chestEntry.Direction;
worldEntry.MapContentName = chestEntry.MapContentName;
worldEntry.MapPosition = chestEntry.MapPosition;
quest.chestEntries.Add(worldEntry);
}
quest.completionMessage = completionMessage;
quest.description = description;
quest.destinationMapContentName = destinationMapContentName;
quest.destinationNpcContentName = destinationNpcContentName;
quest.destinationObjectiveMessage = destinationObjectiveMessage;
quest.experienceReward = experienceReward;
quest.fixedCombatEntries.AddRange(fixedCombatEntries);
quest.gearRequirements.AddRange(gearRequirements);
quest.gearRewardContentNames.AddRange(gearRewardContentNames);
quest.gearRewards.AddRange(gearRewards);
quest.goldReward = goldReward;
quest.monsterRequirements.AddRange(monsterRequirements);
quest.name = name;
quest.objectiveMessage = objectiveMessage;
quest.stage = stage;
return quest;
}
#endregion
}
}