//----------------------------------------------------------------------------- // QuestLine.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; namespace RolePlaying.Data { /// /// A line of quests, presented to the player in order. /// /// /// In other words, only one quest is presented at a time and /// must be competed before the line can continue. /// public class QuestLine : ContentObject #if WINDOWS , ICloneable #endif { /// /// The name of the quest line. /// private string name; /// /// The name of the quest line. /// public string Name { get { return name; } set { name = value; } } /// /// An ordered list of content names of quests that will be presented in order. /// private List questContentNames = new List(); /// /// An ordered list of content names of quests that will be presented in order. /// public List QuestContentNames { get { return questContentNames; } set { questContentNames = value; } } /// /// An ordered list of quests that will be presented in order. /// private List quests = new List(); /// /// An ordered list of quests that will be presented in order. /// [ContentSerializerIgnore] public List Quests { get { return quests; } set { quests = value; } } /// /// Reads a QuestLine object from the content pipeline. /// public class QuestLineReader : ContentTypeReader { /// /// Reads a QuestLine object from the content pipeline. /// protected override QuestLine Read(ContentReader input, QuestLine existingInstance) { QuestLine questLine = existingInstance; if (questLine == null) { questLine = new QuestLine(); } questLine.AssetName = input.AssetName; questLine.Name = input.ReadString(); questLine.QuestContentNames.AddRange(input.ReadObject>()); foreach (string contentName in questLine.QuestContentNames) { questLine.quests.Add(input.ContentManager.Load(Path.Combine("Quests", contentName))); } return questLine; } } public object Clone() { QuestLine questLine = new QuestLine(); questLine.AssetName = AssetName; questLine.name = name; questLine.questContentNames.AddRange(questContentNames); foreach (Quest quest in quests) { questLine.quests.Add(quest.Clone() as Quest); } return questLine; } public static QuestLine Load(string questPath, ContentManager contentManager) { var asset = XmlHelper.GetAssetElementFromXML(questPath); var loadedQuestLine = new QuestLine { Name = asset.Element("Name").Value, QuestContentNames = asset.Element("QuestContentNames")? .Elements("Item") .Select(x => (string)x) .ToList(), }; loadedQuestLine.Quests = loadedQuestLine.QuestContentNames .Select(x => Quest.Load(x, contentManager)) .ToList() ?? new List(); return loadedQuestLine; } } }