Example #1
0
		private static void EmblazonRuneBladeQuestFinished(Quest obj)
		{
			var chr = obj.Owner;
			if(chr == null)
				return;

			foreach (var spell in _emblazonRunebladeLearnSpellIds.Select(SpellHandler.Get).Where(spell => spell != null))
			{
				chr.PlayerSpells.AddSpellRequirements(spell);
				chr.Spells.AddSpell(spell);
			}
		}
Example #2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="QuestLog"/> class.
		/// </summary>
		/// <param name="owner">The owner.</param>
		public QuestLog(Character owner)
		{
			m_timedQuest = null;
			m_escortQuest = null;
			//m_questTimer = null;
			m_Owner = owner;

			m_ActiveQuests = new Quest[MaxQuestCount];
			m_DailyQuestsToday = new List<QuestTemplate>();
			//TODO: load from questlog, and it has to be loaded from update fields
			//m_CurrentDailyCount = 0;
			m_FinishedQuests = new HashSet<uint>();
		}
Example #3
0
 /// <summary>
 /// Sends the quest update add kill, this should actually cover both GameObject interaction 
 /// together with killing the objectBase.
 /// </summary>
 /// <param name="quest">The QST.</param>
 /// <param name="chr">The client.</param>
 /// <param name="obj">The unit.</param>
 public static void SendUpdateInteractionCount(Quest quest,
     ObjectBase obj, QuestInteractionTemplate interaction, uint currentCount, Character chr)
 {
     using (var pckt = new RealmPacketOut(RealmServerOpCode.SMSG_QUESTUPDATE_ADD_KILL))
     {
         pckt.Write(quest.Template.Id);
         pckt.Write(interaction.RawId);								// ID of interaction
         pckt.Write(currentCount);									// current count
         pckt.Write(interaction.Amount);								// total count
         pckt.Write(obj != null ? obj.EntityId : EntityId.Zero);		// guid of object
         chr.Client.Send(pckt);
     }
 }
Example #4
0
        /// <summary>
        /// Sends the quest update failed timer.
        /// </summary>
        /// <param name="qst">The QST.</param>
        /// <param name="chr">The character</param>
        public static void SendQuestUpdateFailedTimer(Character chr, Quest qst)
        {
            using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_QUESTUPDATE_FAILEDTIMER))
            {
                packet.Write(qst.Template.Id);

                chr.Send(packet);
            }
        }
Example #5
0
		private static void DeathComesFromOnHighCancelled(Quest quest, bool failed)
		{
			var chr = quest.Owner;
			if(chr != null)
				CleanUpEyeOfAcherus(chr);
		}
Example #6
0
		/// <summary>
		/// If we want this method to be public, 
		/// it should update all Quests correctly (remove non-existant ones etc)
		/// </summary>
		internal void Load()
		{
			QuestRecord[] records;
			try
			{
				records = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low).ToArray();
			}
			catch (Exception e)
			{
				RealmWorldDBMgr.OnDBError(e);
				records = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low).ToArray();
			}

			if (records != null)
			{
				foreach (var record in records)
				{
				    var templ = QuestMgr.GetTemplate(record.QuestTemplateId);
				    if (templ != null)
				    {
				        var quest = new Quest(this, record, templ);
				        AddQuest(quest);

                        //Cancel any quests relating to inactive events
				        if(templ.EventIds.Count > 0)
				        {
				            if(!templ.EventIds.Where(WorldEventMgr.IsEventActive).Any())
				                quest.Cancel(false);
				        }
				    }
				    else
				    {
				        log.Error("Character {0} had Invalid Quest: {1} (Record: {2})", Owner,
				                  record.QuestTemplateId, record.QuestRecordId);
				    }
				}
			}
		}
Example #7
0
		/// <summary>
		/// Removes the given quest.
		/// Internal - Use <see cref="Quest.Cancel"/> instead.
		/// </summary>
		internal void RemoveQuest(Quest quest)
		{
			if (m_timedQuest == quest)
			{
				// TODO: Timed quest logic
				m_timedQuest = null;
			}

			var qt = quest.Template;
			if (qt.HasGOEvent)
			{
				m_RequireGOsQuests.Remove(quest);
			}
			if (qt.HasNPCInteractionEvent)
			{
				m_NPCInteractionQuests.Remove(quest);
			}
			if (qt.RequiresSpellCasts)
			{
				m_RequireSpellCastsQuests.Remove(quest);
			}

			if (quest.CollectedItems != null)
			{
				m_RequireItemsQuests.Remove(quest);
				var amt = quest.Template.CollectableItems.Length;
				for (var i = 0; i < amt; i++)
				{
					// remove all collected Items
					m_Owner.Inventory.Consume((uint)quest.Template.CollectableItems[i].ItemId, true, quest.CollectedItems[i]);
				}
			}

            if (quest.CollectedSourceItems != null)
            {
                m_RequireItemsQuests.Remove(quest);
                var amt = quest.Template.CollectableSourceItems.Length;
                for (var i = 0; i < amt; i++)
                {
                    // remove all source Items
                    m_Owner.Inventory.Consume((uint)quest.Template.CollectableSourceItems[i].ItemId, true, quest.CollectedSourceItems[i]);
                }
            }

			// remove all provided Items
			if (quest.Template.ProvidedItems.Count > 0)
			{
				var amt = quest.Template.ProvidedItems.Count;
				for (var i = 0; i < amt; i++)
				{
					var template = quest.Template.ProvidedItems[i];
					m_Owner.Inventory.Consume((uint)template.ItemId, true, template.Amount);
				}
			}

			// remove starter Item
			foreach (var starter in quest.Template.Starters)
			{
				if (starter is ItemTemplate)
				{
					m_Owner.Inventory.Consume(((ItemTemplate)starter).ItemId, true);
				}
			}

			// TODO: remove other Items that belong to this Quest
			RealmServer.IOQueue.AddMessage(new Message(quest.Delete));

			m_activeQuestCount--;
			m_ActiveQuests[quest.Slot] = null;
			Owner.ResetQuest(quest.Slot);
		}
Example #8
0
		void UpdateInteractionCount(Quest quest, QuestInteractionTemplate interaction, WorldObject obj)
		{
			var count = quest.Interactions[interaction.Index];
			if (count < interaction.Amount)
			{
				++quest.Interactions[interaction.Index];
				m_Owner.SetQuestCount(quest.Slot, interaction.Index, (byte)(count+1));
				QuestHandler.SendUpdateInteractionCount(quest, obj, interaction, count+1, m_Owner);
				quest.UpdateStatus();
			}
			//quest.Template.NotifyGOUsed(quest, go);
		}
Example #9
0
		public Quest AddQuest(Quest quest)
		{
			var qt = quest.Template;

			if (!quest.IsSaved)
			{
				if (!qt.GiveInitialItems(m_Owner))
				{
					// could not add all required items
					QuestHandler.SendQuestInvalid(m_Owner, QuestInvalidReason.NoRequiredItems);
					return null;
				}
			}

			if ((qt.TimeLimit > 0) && m_timedQuest == null)
			{
				m_timedQuest = quest;
				//m_questTimer = new SimpleTimer(qt.TimeLimit);
			}
			Owner.SetQuestId((byte)quest.Slot, quest.Template.Id);
			m_ActiveQuests[quest.Slot] = quest;
			m_activeQuestCount++;

			if (qt.HasGOEvent)
			{
				m_RequireGOsQuests.Add(quest);
			}
			if (qt.HasNPCInteractionEvent)
			{
				m_NPCInteractionQuests.Add(quest);
			}
			if (qt.RequiresSpellCasts)
			{
				m_RequireSpellCastsQuests.Add(quest);
			}

			if (quest.CollectedItems != null)
			{
				m_RequireItemsQuests.Add(quest);
				for (var i = 0; i < quest.Template.CollectableItems.Length; i++)
				{
					var item = quest.Template.CollectableItems[i];
					if (item.ItemId != ItemId.None)
					{
						// find items that are already there
						quest.CollectedItems[i] = m_Owner.Inventory.GetAmount(item.ItemId);
					}
				}
			}

            if (quest.CollectedSourceItems != null)
            {
                if(!m_RequireItemsQuests.Contains(quest))
                    m_RequireItemsQuests.Add(quest);
                for (var i = 0; i < quest.Template.CollectableSourceItems.Length; i++)
                {
                    var item = quest.Template.CollectableSourceItems[i];
                    if (item.ItemId != ItemId.None)
                    {
                        // find items that are already there
                        quest.CollectedSourceItems[i] = m_Owner.Inventory.GetAmount(item.ItemId);
                    }
                }
            }

			quest.UpdateStatus();

			qt.NotifyStarted(quest);
			return quest;
		}
Example #10
0
		/// <summary>
		/// Adds the given Quest as new active Quest
		/// Returns null if inital Items could not be handed out.
		/// </summary>
		/// <param name="qt"></param>
		/// <param name="slot"></param>
		/// <returns></returns>
		public Quest AddQuest(QuestTemplate qt, int slot)
		{
			var quest = new Quest(this, qt, slot);

			AddQuest(quest);

			return quest;
		}
Example #11
0
		private static void AutoComplete(Quest quest, Character chr)
		{
			quest.CompleteStatus = QuestCompleteStatus.Completed;
			QuestHandler.SendComplete(quest.Template, chr);
			QuestHandler.SendQuestGiverOfferReward(chr, quest.Template, chr);
		}
Example #12
0
		/// <summary>
		/// If we want this method to be public, 
		/// it should update all Quests correctly (remove non-existant ones etc)
		/// </summary>
		internal void Load()
		{
			QuestRecord[] records;
			try
			{
				records = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low);
			}
			catch (Exception e)
			{
				RealmDBUtil.OnDBError(e);
				records = QuestRecord.GetQuestRecordForCharacter(Owner.EntityId.Low);
			}

			if (records != null)
			{
				for (var i = 0; i < records.Length; i++)
				{
					var record = records[i];
					var templ = QuestMgr.GetTemplate(record.QuestTemplateId);
					if (templ != null)
					{
						var quest = new Quest(this, record, templ);
						AddQuest(quest);
					}
					else
					{
						log.Error("Character {0} had Invalid Quest: {1} (Record: {2})", Owner,
							record.QuestTemplateId, record.QuestRecordId);
					}
				}
			}
		}
Example #13
0
		/// <summary>
		/// Removes the given quest.
		/// Internal - Use <see cref="Quest.Cancel"/> instead.
		/// </summary>
		internal void RemoveQuest(Quest quest)
		{
			if (m_timedQuest == quest)
			{
				// TODO: Timed quest logic
				m_timedQuest = null;
			}

			if (quest.UsedGOs != null)
			{
				m_RequireGOsQuests.Remove(quest);
			}
			if (quest.KilledNPCs != null)
			{
				m_NPCInteractionQuests.Remove(quest);
			}

			if (quest.CollectedItems != null)
			{
				m_RequireItemsQuests.Remove(quest);
				var amt = quest.Template.CollectableItems.Length;
				for (var i = 0; i < amt; i++)
				{
					// remove all collected Items
					m_Owner.Inventory.Consume(true, (uint)quest.Template.CollectableItems[i].ItemId, quest.CollectedItems[i]);
				}
			}

			if (quest.Template.InitialItems.Count > 0)
			{
				var amt = quest.Template.InitialItems.Count;
				for (var i = 0; i < amt; i++)
				{
					// remove all initial Items
					m_Owner.Inventory.Consume(true, (uint)quest.Template.InitialItems[i].ItemId, quest.Template.InitialItems[i].Amount);
				}
			}

			// TODO: remove other Items that belong to this Quest
			RealmServer.Instance.AddMessage(new Message(quest.Delete));

			m_activeQuestCount--;
			m_ActiveQuests[quest.Slot] = null;
			Owner.ResetQuest(quest.Slot);
		}