//adds a new quest to the log public void Add(Quest newQuest) { log[newQuest.Name] = newQuest; }
/// <summary> /// Adds quests to a quest log /// </summary> /// <param name="questToAdd">The quest</param> /// <param name="prerequisites">A list of prerequisite Quests</param> public void Add(Quest questToAdd, params Quest [] prerequisites) { if(head == null && prerequisites.Length != 0) { throw new ArgumentException("The first quest cannot have prerequisites"); } else if(head == null) { head = new QuestNode(questToAdd); } }
public bool ContainsQuest(Quest quest) { return log.ContainsValue(quest); }
//constructor public QuestNode(Quest quest) { data = quest; nextQuests = new List<Quest>(); prerQuests = new List<Quest>(); }
/// <summary> /// Takes a path to a quest file and parses it to a quest object /// </summary> /// <param name="filename">the file path</param> /// <returns>A quest</returns> public static Quest ParseQuest(string filename) { Quest quest = null; Console.WriteLine("Quest file name: \n\t" + filename); using (StreamReader input = new StreamReader(filename)) { string data = input.ReadToEnd(); if (data.Substring(5, 12).Contains("Storyline")) { /* //load individual quests int index, end; index = data.IndexOf("Folder") + 8; end = data.IndexOf('"', index); string folder = data.Substring(index, end - index); storylineFolder = QUEST_DIRECTORY + folder; Storyline newStoryline; string[] files = Directory.GetFiles(storylineFolder); Quest loaded; //loop through all of the files in the directory foreach (string path in files) { //try and parse the quest from each file loaded = ParseQuest(path); //if the parse was successfull, add it to the log if (loaded != null) { newStoryline.Add(loaded); } } */ } else { int index, end; string attribute; //get name index = data.IndexOf("Name:") + 6; end = data.IndexOf('"', index); string name = data.Substring(index, end - index); //get world key index = data.IndexOf("World:") + 7; end = data.IndexOf('"', index); string key = data.Substring(index, end - index); //get the description index = data.IndexOf("Description:") + 13; end = data.IndexOf('"', index); string description = data.Substring(index, end - index); //get objective index = data.IndexOf("Objective:") + 11; end = data.IndexOf('"', index); string objective = data.Substring(index, end - index); //get reward index = data.IndexOf("Reward:"); index = data.IndexOf("Cash:", index) + 5; end = data.IndexOf("\n", index); attribute = data.Substring(index, end - index); int cash; if (!int.TryParse(attribute, out cash)) cash = 0; index = data.IndexOf("Q-Points:", index) + 9; end = data.IndexOf("\n", index); attribute = data.Substring(index, end - index); int qPoints; if (!int.TryParse(attribute, out qPoints)) qPoints = 0; //get start point index = data.IndexOf("Start:"); index = data.IndexOf("X:", index) + 2; end = data.IndexOf("\n", index); attribute = data.Substring(index, end - index); int X; if (!int.TryParse(attribute, out X)) X = 10; index = data.IndexOf("Y:", index) + 2; end = data.IndexOf("\r", index); attribute = data.Substring(index, end - index); int Y; if (!int.TryParse(attribute, out Y)) Y = 10; Vector2 start = new Vector2(X, Y); //get the win condition index = data.IndexOf("Condition:") + 10; end = data.IndexOf("\r", index); attribute = data.Substring(index, end - index); WinCondition condition; //win state switch (attribute) { case "EnemyDies": condition = WinCondition.EnemyDies; break; case "ObtainItem": condition = WinCondition.ObtainItem; break; case "DeliverItem": condition = WinCondition.DeliverItem; break; case "AllEnemiesDead": default: condition = WinCondition.AllEnemiesDead; break; } //get the id of the entity or item that satisfies the quest condition string target = ""; string recipient = ""; switch (condition) { case WinCondition.EnemyDies: case WinCondition.ObtainItem: //get the name of the entity index = data.IndexOf("Target:") + 7; string test = data.Substring(index); end = data.IndexOf('\n', index) - 1; target = data.Substring(index, end - index); break; case WinCondition.DeliverItem: //get the target item index = data.IndexOf("Target:") + 7; target = data.Substring(index); //get destination index = data.IndexOf("Recipient:") + 10; end = data.IndexOf('\n'); recipient = data.Substring(index, index - end); break; } #region Read Enemies //read all of the living entities Dictionary<string, Entity.LivingEntity> livingEntities = new Dictionary<string, Entity.LivingEntity>(); int endEntity = data.Length; FloatRectangle EntityRect; AI.AI ai; //string test = data.Substring(index, 10); index = 1; while((index = data.IndexOf("Living Entity:", index)) > 0) { ai = null; endEntity = data.IndexOf("End Living Enity", index); //get the id index = data.IndexOf("ID:", index) + 3; end = data.IndexOf('\r', index); string id = data.Substring(index, end - index); //get the start position //get start point index = data.IndexOf("Start:", index); index = data.IndexOf("X:", index) + 2; end = data.IndexOf("\n", index); attribute = data.Substring(index, end - index); int sX; if (!int.TryParse(attribute, out sX)) sX = 10; index = data.IndexOf("Y:", index) + 2; end = data.IndexOf("\r", index); attribute = data.Substring(index, end - index); int sY; if (!int.TryParse(attribute, out sY)) sY = 10; //get texture index = data.IndexOf("Texture:", index) + 9; end = data.IndexOf('"', index); string texturePath = data.Substring(index, end - index); GUI.Sprite sprite = GUI.Sprites.spritesDictionary[texturePath]; //create rectangle EntityRect = new FloatRectangle(sX, sY, sprite.Width, sprite.Height); //get the health index = data.IndexOf("Health:", index) + 7; end = data.IndexOf('\n', index); attribute = data.Substring(index, end - index); int health; if(!int.TryParse(attribute, out health)) { health = 0; } livingEntities[id] = new Entity.LivingEntity(EntityRect, sprite, health, null); livingEntities[id].Name = id; //get the ai index = data.IndexOf("AI:", index) + 3; end = data.IndexOf('\n', index) - 1; if (index >= 0) { attribute = data.Substring(index, end - index); switch (attribute) { case "Low": ai = new AI.LowAI(livingEntities[id]); break; case "Mid": ai = new AI.HighAI(livingEntities[id]); break; case "High": ai = new AI.HighAI(livingEntities[id]); break; default: ai = null; break; } livingEntities[id].ai = ai; livingEntities[id].inventory.Add(new Item.Weapon(50, 1, 10, "Bam", 100, 0.5)); livingEntities[id].inventory.ActiveWeapon = 0; } } #endregion #region Read Items Dictionary<string, QuestItem> items = new Dictionary<string,QuestItem>(); index = 0; int endItem = data.Length; while((index = data.IndexOf("Item:", index)) > 0) { endItem = data.IndexOf("End Item", index); //get the id index = data.IndexOf("ID:", index) + 3; end = data.IndexOf('\n', index); string id = data.Substring(index, end - index); //get the texture index = data.IndexOf("Texture:", index) + 9; end = data.IndexOf('"', index); string texturePath = data.Substring(index, end - index); GUI.Sprite sprite = GUI.Sprites.spritesDictionary[texturePath]; //create item items[id] = new QuestItem(id); items[id].Item = new Item.Item(); items[id].Item.previewSprite = sprite; } #endregion //Create the quest quest = new Quest(name, objective, description, start, null, condition, qPoints, cash); quest.worldKey = key; quest.Status = 1; //add the entities to the quests entitiy list foreach (Entity.LivingEntity entity in livingEntities.Values.ToList()) { quest.entitites.Add(entity); } //items too /* Quest needs to be updated foreach(Item.Item item in items.Values.ToArray()) { quest. } */ switch (condition) { case WinCondition.EnemyDies: quest.EnemyToKill = livingEntities[target]; break; case WinCondition.AllEnemiesDead: break; case WinCondition.ObtainItem: quest.FindThis = items[target].Item; break; case WinCondition.DeliverItem: quest.Delivery = items[target].Item; quest.Recipient = livingEntities[recipient]; break; default: break; } } } return quest; }
/// <summary> /// Load the quest you want to view. /// </summary> /// <param name="quest"></param> public void Load(Quest quest) { // load the quest currentQuest = quest; // load text questNameLabel.Text = currentQuest.Name; questRewardMoneyLabel.Text = "$" + currentQuest.CashReward + ""; questRewardPointLabel.Text = "@" + currentQuest.Reward + ""; switch(quest.Status) { //0: Unavailable, 1: Unstarted, 2: In progress, 3: complete case 0: questStatusLabel.Text = "Unavailable"; questStatusLabel.Color = Color.Gray; IsActive = false; break; case 1: questStatusLabel.Text = "Available"; questStatusLabel.Color = Color.Blue; break; case 2: questStatusLabel.Text = "In Progress"; questStatusLabel.Color = Color.Yellow; break; case 3: questStatusLabel.Text = "Complete"; questStatusLabel.Color = Color.Green; break; } }
/// <summary> /// Load the quest you want to view. /// </summary> /// <param name="quest"></param> public void Load(Quest quest) { // load the quest currentQuest = quest; // load text name.Text = currentQuest.Name; description.Text = currentQuest.Description; cashReward.Text = "$" + currentQuest.CashReward + ""; pointReward.Text = "@" + currentQuest.Reward + ""; // load objectives ObjectivesUI tmpObjective = null; switch(quest.WinCondition) { case WinCondition.AllEnemiesDead: // enemies to kill? (not sure about this one) // foreach for # // tmp dict. /* Dictionary<string, Entity.LivingEntity> objectiveEntities = new Dictionary<string, Entity.LivingEntity>(); foreach(Entity.Entity ent in quest.entitites) { Console.WriteLine(ent.GetType()); } */ // Currently no way to get entity names or group them by types (no mugger class etc...) (?) tmpObjective = new ObjectivesUI(objectivesContainer.Size); string namesOfEnemies = ""; foreach (Entity.Entity e in quest.entitites) namesOfEnemies += e.Name + "\n"; tmpObjective.Load("Kill these enemies:\n" + namesOfEnemies, "", quest.entitites[0].sprite.Texture); //tmpObjective.parent = objectivesContainer; objectivesContainer.Add(tmpObjective); break; case WinCondition.DeliverItem: // deliver some item to some recipient tmpObjective = new ObjectivesUI(new Vector2(objectivesContainer.Size.X, objectivesContainer.Size.Y / 2)); tmpObjective.Load("Deliver this", quest.Delivery.name, quest.Delivery.previewSprite.Texture); //tmpObjective.parent = objectivesContainer; objectivesContainer.Add(tmpObjective); tmpObjective.Load("Recipient", quest.Recipient.Name, quest.Recipient.sprite.Texture); tmpObjective.Location = new Vector2(0, objectivesContainer.Size.Y / 2); //tmpObjective.parent = objectivesContainer; objectivesContainer.Add(tmpObjective); break; case WinCondition.EnemyDies: // kill some enemy tmpObjective = new ObjectivesUI(objectivesContainer.Size); tmpObjective.Load("Kill this enemy", quest.EnemyToKill.Name, quest.EnemyToKill.sprite.Texture); //tmpObjective.parent = objectivesContainer; objectivesContainer.Add(tmpObjective); break; case WinCondition.ObtainItem: // find this tmpObjective = new ObjectivesUI(objectivesContainer.Size); tmpObjective.Load("Find this item", quest.FindThis.name, quest.FindThis.previewSprite.Texture); //tmpObjective.parent = objectivesContainer; objectivesContainer.Add(tmpObjective); break; } }
public void Close() { name.Text = "Quest Name"; description.Text = String.Empty; cashReward.Text = "$000"; pointReward.Text = "@000"; currentQuest = null; }