public void Write(BioQuest quest) { if (quest == null) { throw new ArgumentNullException(nameof(quest)); } Write(quest.InstanceVersion); Write(quest.IsMission.ToInt32()); // Goals Write(quest.Goals.Count); foreach (var goal in quest.Goals) { Write(goal); } // Tasks Write(quest.Tasks.Count); foreach (var task in quest.Tasks) { Write(task); } // Plot Items Write(quest.PlotItems.Count); foreach (var plotItem in quest.PlotItems) { Write(plotItem); } }
/// <summary> /// </summary> /// <param name="other"></param> public BioQuest(BioQuest other) : base(other) { IsMission = other.IsMission; Goals = other.Goals != null ? other.Goals.Select(goal => new BioQuestGoal(goal)).ToList() : new List<BioQuestGoal>(); PlotItems = other.PlotItems != null ? other.PlotItems.Select(item => new BioQuestPlotItem(item)).ToList() : new List<BioQuestPlotItem>(); Tasks = other.Tasks != null ? other.Tasks.Select(task => new BioQuestTask(task)).ToList() : new List<BioQuestTask>(); }
/// <summary> /// </summary> /// <param name="other"></param> public BioQuest(BioQuest other) : base(other) { IsMission = other.IsMission; Goals = other.Goals != null?other.Goals.Select(goal => new BioQuestGoal(goal)).ToList() : new List <BioQuestGoal>(); PlotItems = other.PlotItems != null?other.PlotItems.Select(item => new BioQuestPlotItem(item)).ToList() : new List <BioQuestPlotItem>(); Tasks = other.Tasks != null?other.Tasks.Select(task => new BioQuestTask(task)).ToList() : new List <BioQuestTask>(); }
public BioQuest ReadQuest() { var quest = new BioQuest { InstanceVersion = ReadInt32(), IsMission = ReadInt32().ToBoolean() }; // Goals var goalsCount = ReadInt32(); quest.Goals = new List <BioQuestGoal>(); for (var i = 0; i < goalsCount; i++) { var goal = ReadQuestGoal(); quest.Goals.Add(goal); } // Tasks var tasksCount = ReadInt32(); quest.Tasks = new List <BioQuestTask>(); for (var i = 0; i < tasksCount; i++) { var task = ReadQuestTask(); quest.Tasks.Add(task); } // Plot Items var plotItemsCount = ReadInt32(); quest.PlotItems = new List <BioQuestPlotItem>(); for (var i = 0; i < plotItemsCount; i++) { var plotItem = ReadQuestPlotItem(); quest.PlotItems.Add(plotItem); } return(quest); }
public static IDictionary <int, BioQuest> ReadQuests(XElement root) { if (root == null) { ThrowHelper.ThrowArgumentNullException(nameof(root)); } var quests = new Dictionary <int, BioQuest>(); var questsElement = root.Element("Quests"); if (questsElement == null) { return(quests); } var xQuests = from el in questsElement.Elements("Quest") select el; foreach (var xQuest in xQuests) { var id = (int?)xQuest.Attribute("Id"); if (id == null) { continue; } var quest = new BioQuest { InstanceVersion = (int?)xQuest.Attribute("InstanceVersion") ?? BioQuest.DefaultInstanceVersion, IsMission = (bool?)xQuest.Attribute("IsMission") ?? BioQuest.DefaultIsMission }; var questGoalsElement = questsElement.Element("Goals"); var questPlotItemsElement = questsElement.Element("PlotItems"); var questTasksElement = questsElement.Element("Tasks"); if (questGoalsElement != null) { var xQuestGoals = from el in questsElement.Elements("Goal") select el; foreach (var questGoal in xQuestGoals .Select(xQuestGoal => new BioQuestGoal { Conditional = (int?)xQuestGoal.Attribute("Conditional") ?? BioQuestGoal.DefaultConditional, Description = (int?)xQuestGoal.Attribute("Description") ?? BioQuestGoal.DefaultDescription, InstanceVersion = (int?)xQuestGoal.Attribute("InstanceVersion") ?? BioQuestGoal.DefaultInstanceVersion, Name = (int?)xQuestGoal.Attribute("Name") ?? BioQuestGoal.DefaultName, State = (int?)xQuestGoal.Attribute("State") ?? BioQuestGoal.DefaultState })) { quest.Goals.Add(questGoal); } } if (questPlotItemsElement != null) { var xQuestPlotItems = from el in questsElement.Elements("PlotItem") select el; foreach (var questPlotItem in xQuestPlotItems .Select(xQuestPlotItem => new BioQuestPlotItem { Conditional = (int?)xQuestPlotItem.Attribute("Conditional") ?? BioQuestPlotItem.DefaultConditional, IconIndex = (int?)xQuestPlotItem.Attribute("IconIndex") ?? BioQuestPlotItem.DefaultIconIndex, InstanceVersion = (int?)xQuestPlotItem.Attribute("InstanceVersion") ?? BioQuestPlotItem.DefaultInstanceVersion, Name = (int?)xQuestPlotItem.Attribute("Name") ?? BioQuestPlotItem.DefaultName, State = (int?)xQuestPlotItem.Attribute("State") ?? BioQuestPlotItem.DefaultState, TargetItems = (int?)xQuestPlotItem.Attribute("TargetItems") ?? BioQuestPlotItem.DefaultTargetItems })) { quest.PlotItems.Add(questPlotItem); } } if (questTasksElement != null) { var xQuestTasks = from el in questsElement.Elements("Task") select el; foreach (var xQuestTask in xQuestTasks) { var questTask = new BioQuestTask { Description = (int?)xQuestTask.Attribute("Conditional") ?? BioQuestTask.DefaultDescription, Name = (int?)xQuestTask.Attribute("Name") ?? BioQuestTask.DefaultName, InstanceVersion = (int?)xQuestTask.Attribute("InstanceVersion") ?? BioQuestTask.DefaultInstanceVersion, PlanetName = (int?)xQuestTask.Attribute("IconIndex") ?? BioQuestTask.DefaultPlanetName, PlanetNameFlags = (int?)xQuestTask.Attribute("IconIndex") ?? BioQuestTask.DefaultPlanetNameFlags, QuestCompleteTask = (bool?)xQuestTask.Attribute("State") ?? BioQuestTask.DefaultQuestCompleteTask, // ReSharper disable once ConstantNullCoalescingCondition WaypointTag = (string)xQuestTask.Attribute("TargetItems") ?? BioQuestTask.DefaultWaypointTag }; var questTaskPlotItemIndicesElement = questsElement.Element("PlotItemIndices"); if (questTaskPlotItemIndicesElement != null) { var xQuestTaskPlotItemIndices = from el in questsElement.Elements("PlotItemIndex") select el; foreach (var xQuestTaskPlotItemIndex in xQuestTaskPlotItemIndices.Where(xQuestTaskPlotItemIndex => !string.IsNullOrEmpty(xQuestTaskPlotItemIndex.Value))) { questTask.PlotItemIndices.Add(xQuestTaskPlotItemIndex.Value.ToInt32()); } } quest.Tasks.Add(questTask); } } quests.Add((int)id, quest); } return(quests); }
public void Write(BioQuest quest) { if (quest == null) { throw new ArgumentNullException(nameof(quest)); } Write(quest.InstanceVersion); Write(quest.IsMission.ToInt32()); // Goals Write(quest.Goals.Count); foreach (var goal in quest.Goals) { Write(goal); } // Tasks Write(quest.Tasks.Count); foreach (var task in quest.Tasks) { Write(task); } // Plot Items Write(quest.PlotItems.Count); foreach (var plotItem in quest.PlotItems) { Write(plotItem); } }
public BioQuest ReadQuest() { var quest = new BioQuest { InstanceVersion = ReadInt32(), IsMission = ReadInt32().ToBoolean() }; // Goals var goalsCount = ReadInt32(); quest.Goals = new List<BioQuestGoal>(); for (var i = 0; i < goalsCount; i++) { var goal = ReadQuestGoal(); quest.Goals.Add(goal); } // Tasks var tasksCount = ReadInt32(); quest.Tasks = new List<BioQuestTask>(); for (var i = 0; i < tasksCount; i++) { var task = ReadQuestTask(); quest.Tasks.Add(task); } // Plot Items var plotItemsCount = ReadInt32(); quest.PlotItems = new List<BioQuestPlotItem>(); for (var i = 0; i < plotItemsCount; i++) { var plotItem = ReadQuestPlotItem(); quest.PlotItems.Add(plotItem); } return quest; }
public static IDictionary<int, BioQuest> ReadQuests(XElement root) { if (root == null) { ThrowHelper.ThrowArgumentNullException(nameof(root)); } var quests = new Dictionary<int, BioQuest>(); var questsElement = root.Element("Quests"); if (questsElement == null) { return quests; } var xQuests = from el in questsElement.Elements("Quest") select el; foreach (var xQuest in xQuests) { var id = (int?) xQuest.Attribute("Id"); if (id == null) { continue; } var quest = new BioQuest { InstanceVersion = (int?) xQuest.Attribute("InstanceVersion") ?? BioQuest.DefaultInstanceVersion, IsMission = (bool?) xQuest.Attribute("IsMission") ?? BioQuest.DefaultIsMission }; var questGoalsElement = questsElement.Element("Goals"); var questPlotItemsElement = questsElement.Element("PlotItems"); var questTasksElement = questsElement.Element("Tasks"); if (questGoalsElement != null) { var xQuestGoals = from el in questsElement.Elements("Goal") select el; foreach (var questGoal in xQuestGoals .Select(xQuestGoal => new BioQuestGoal { Conditional = (int?) xQuestGoal.Attribute("Conditional") ?? BioQuestGoal.DefaultConditional, Description = (int?) xQuestGoal.Attribute("Description") ?? BioQuestGoal.DefaultDescription, InstanceVersion = (int?) xQuestGoal.Attribute("InstanceVersion") ?? BioQuestGoal.DefaultInstanceVersion, Name = (int?) xQuestGoal.Attribute("Name") ?? BioQuestGoal.DefaultName, State = (int?) xQuestGoal.Attribute("State") ?? BioQuestGoal.DefaultState })) { quest.Goals.Add(questGoal); } } if (questPlotItemsElement != null) { var xQuestPlotItems = from el in questsElement.Elements("PlotItem") select el; foreach (var questPlotItem in xQuestPlotItems .Select(xQuestPlotItem => new BioQuestPlotItem { Conditional = (int?) xQuestPlotItem.Attribute("Conditional") ?? BioQuestPlotItem.DefaultConditional, IconIndex = (int?) xQuestPlotItem.Attribute("IconIndex") ?? BioQuestPlotItem.DefaultIconIndex, InstanceVersion = (int?) xQuestPlotItem.Attribute("InstanceVersion") ?? BioQuestPlotItem.DefaultInstanceVersion, Name = (int?) xQuestPlotItem.Attribute("Name") ?? BioQuestPlotItem.DefaultName, State = (int?) xQuestPlotItem.Attribute("State") ?? BioQuestPlotItem.DefaultState, TargetItems = (int?) xQuestPlotItem.Attribute("TargetItems") ?? BioQuestPlotItem.DefaultTargetItems })) { quest.PlotItems.Add(questPlotItem); } } if (questTasksElement != null) { var xQuestTasks = from el in questsElement.Elements("Task") select el; foreach (var xQuestTask in xQuestTasks) { var questTask = new BioQuestTask { Description = (int?) xQuestTask.Attribute("Conditional") ?? BioQuestTask.DefaultDescription, Name = (int?) xQuestTask.Attribute("Name") ?? BioQuestTask.DefaultName, InstanceVersion = (int?) xQuestTask.Attribute("InstanceVersion") ?? BioQuestTask.DefaultInstanceVersion, PlanetName = (int?) xQuestTask.Attribute("IconIndex") ?? BioQuestTask.DefaultPlanetName, PlanetNameFlags = (int?) xQuestTask.Attribute("IconIndex") ?? BioQuestTask.DefaultPlanetNameFlags, QuestCompleteTask = (bool?) xQuestTask.Attribute("State") ?? BioQuestTask.DefaultQuestCompleteTask, // ReSharper disable once ConstantNullCoalescingCondition WaypointTag = (string) xQuestTask.Attribute("TargetItems") ?? BioQuestTask.DefaultWaypointTag }; var questTaskPlotItemIndicesElement = questsElement.Element("PlotItemIndices"); if (questTaskPlotItemIndicesElement != null) { var xQuestTaskPlotItemIndices = from el in questsElement.Elements("PlotItemIndex") select el; foreach (var xQuestTaskPlotItemIndex in xQuestTaskPlotItemIndices.Where(xQuestTaskPlotItemIndex => !xQuestTaskPlotItemIndex.Value.IsNullOrWhiteSpace())) { questTask.PlotItemIndices.Add(xQuestTaskPlotItemIndex.Value.ToInt32()); } } quest.Tasks.Add(questTask); } } quests.Add((int) id, quest); } return quests; }