Exemple #1
0
        public bool CheckCompletedStatus()
        {
            if (Template.CompleteHandler != null && Template.CompleteHandler(this))
            {
                return(true);
            }
            for (int index = 0; index < Template.CollectableItems.Length; ++index)
            {
                if (CollectedItems[index] < Template.CollectableItems[index].Amount)
                {
                    return(false);
                }
            }

            if (Template.HasObjectOrSpellInteractions)
            {
                for (int index = 0; index < Template.ObjectOrSpellInteractions.Length; ++index)
                {
                    QuestInteractionTemplate spellInteraction = Template.ObjectOrSpellInteractions[index];
                    if (spellInteraction != null && spellInteraction.IsValid)
                    {
                        uint interaction = Interactions[index];
                        bool flag        = spellInteraction.ObjectType != ObjectTypeId.None || spellInteraction.Amount == 0;
                        if (!flag && interaction == 0U || flag && interaction <
                            Template.ObjectOrSpellInteractions[index].Amount)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemple #2
0
        /// <summary>Load Quest progress</summary>
        internal Quest(QuestLog log, QuestRecord record, QuestTemplate template)
            : this(log, template, record)
        {
            m_saved = true;
            if (template.HasObjectOrSpellInteractions)
            {
                if (Interactions == null ||
                    template.ObjectOrSpellInteractions
                    .Count() != Interactions.Count())
                {
                    Interactions = new uint[template.ObjectOrSpellInteractions.Length];
                }
                for (int index = 0; index < Template.ObjectOrSpellInteractions.Length; ++index)
                {
                    QuestInteractionTemplate spellInteraction = Template.ObjectOrSpellInteractions[index];
                    if (spellInteraction != null && spellInteraction.IsValid)
                    {
                        log.Owner.SetQuestCount(Slot, spellInteraction.Index,
                                                (byte)Interactions[index]);
                    }
                }
            }

            UpdateStatus();
        }
Exemple #3
0
        /// <summary>Load Quest progress</summary>
        internal Quest(QuestLog log, QuestRecord record, QuestTemplate template)
            : this(log, template, record)
        {
            this.m_saved = true;
            if (template.HasObjectOrSpellInteractions)
            {
                if (this.Interactions == null ||
                    ((IEnumerable <QuestInteractionTemplate>)template.ObjectOrSpellInteractions)
                    .Count <QuestInteractionTemplate>() != ((IEnumerable <uint>) this.Interactions).Count <uint>())
                {
                    this.Interactions = new uint[template.ObjectOrSpellInteractions.Length];
                }
                for (int index = 0; index < this.Template.ObjectOrSpellInteractions.Length; ++index)
                {
                    QuestInteractionTemplate spellInteraction = this.Template.ObjectOrSpellInteractions[index];
                    if (spellInteraction != null && spellInteraction.IsValid)
                    {
                        log.Owner.SetQuestCount(this.Slot, spellInteraction.Index,
                                                (ushort)(byte)this.Interactions[index]);
                    }
                }
            }

            this.UpdateStatus();
        }
Exemple #4
0
        internal void OnSpellCast(SpellCast cast)
        {
            if (m_RequireSpellCastsQuests.Count <= 0)
            {
                return;
            }
            foreach (Quest requireSpellCastsQuest in m_RequireSpellCastsQuests)
            {
                foreach (QuestInteractionTemplate spellInteraction in requireSpellCastsQuest.Template.SpellInteractions)
                {
                    QuestInteractionTemplate interaction = spellInteraction;
                    if (interaction.RequiredSpellId == cast.Spell.SpellId)
                    {
                        switch (interaction.ObjectType)
                        {
                        case ObjectTypeId.Unit:
                            WorldObject worldObject1 = cast.Targets.FirstOrDefault(
                                target =>
                            {
                                if (target is NPC)
                                {
                                    return(interaction.TemplateId.Contains(
                                               target.EntryId));
                                }
                                return(false);
                            });
                            if (worldObject1 != null)
                            {
                                UpdateInteractionCount(requireSpellCastsQuest, interaction, worldObject1);
                            }

                            continue;

                        case ObjectTypeId.GameObject:
                            WorldObject worldObject2 = cast.Targets.FirstOrDefault(
                                target =>
                            {
                                if (target is GameObject)
                                {
                                    return(interaction.TemplateId.Contains(
                                               target.EntryId));
                                }
                                return(false);
                            });
                            if (worldObject2 != null)
                            {
                                UpdateInteractionCount(requireSpellCastsQuest, interaction, worldObject2);
                            }

                            continue;

                        default:
                            UpdateInteractionCount(requireSpellCastsQuest, interaction, null);
                            continue;
                        }
                    }
                }
            }
        }
Exemple #5
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);
        }
Exemple #6
0
        private void UpdateInteractionCount(Quest quest, QuestInteractionTemplate interaction, WorldObject obj)
        {
            uint interaction1 = quest.Interactions[interaction.Index];

            if (interaction1 >= interaction.Amount)
            {
                return;
            }
            ++quest.Interactions[interaction.Index];
            m_Owner.SetQuestCount(quest.Slot, interaction.Index, (byte)(interaction1 + 1U));
            QuestHandler.SendUpdateInteractionCount(quest, obj, interaction, interaction1 + 1U,
                                                    m_Owner);
            quest.UpdateStatus();
        }
Exemple #7
0
        private void UpdateInteractionCount(Quest quest, QuestInteractionTemplate interaction, WorldObject obj)
        {
            uint interaction1 = quest.Interactions[interaction.Index];

            if ((long)interaction1 >= (long)interaction.Amount)
            {
                return;
            }
            ++quest.Interactions[interaction.Index];
            this.m_Owner.SetQuestCount(quest.Slot, interaction.Index, (ushort)(byte)(interaction1 + 1U));
            QuestHandler.SendUpdateInteractionCount(quest, (ObjectBase)obj, interaction, interaction1 + 1U,
                                                    this.m_Owner);
            quest.UpdateStatus();
        }
Exemple #8
0
 /// <summary>
 /// Is called when the owner of this QuestLog used the given GameObject
 /// </summary>
 /// <param name="go"></param>
 public void OnUse(GameObject go)
 {
     foreach (Quest requireGosQuest in m_RequireGOsQuests)
     {
         if (requireGosQuest.Template.GOInteractions != null)
         {
             for (int index = 0; index < requireGosQuest.Template.GOInteractions.Length; ++index)
             {
                 QuestInteractionTemplate goInteraction = requireGosQuest.Template.GOInteractions[index];
                 if (goInteraction.TemplateId.Contains(go.Entry.Id))
                 {
                     UpdateInteractionCount(requireGosQuest, goInteraction, go);
                 }
             }
         }
     }
 }
Exemple #9
0
 /// <summary>
 /// Is called when the owner of this QuestLog did
 /// the required interaction with the given NPC (usually killing)
 /// </summary>
 /// <param name="npc"></param>
 internal void OnNPCInteraction(NPC npc)
 {
     foreach (Quest interactionQuest in m_NPCInteractionQuests)
     {
         if (interactionQuest.Template.NPCInteractions != null)
         {
             for (int index = 0; index < interactionQuest.Template.NPCInteractions.Length; ++index)
             {
                 QuestInteractionTemplate npcInteraction = interactionQuest.Template.NPCInteractions[index];
                 if (npcInteraction.TemplateId.Contains(npc.Entry.Id))
                 {
                     UpdateInteractionCount(interactionQuest, npcInteraction, npc);
                 }
             }
         }
     }
 }
Exemple #10
0
 /// <summary>
 /// Is called when the owner of this QuestLog used the given GameObject
 /// </summary>
 /// <param name="go"></param>
 public void OnUse(GameObject go)
 {
     foreach (Quest requireGosQuest in this.m_RequireGOsQuests)
     {
         if (requireGosQuest.Template.GOInteractions != null)
         {
             for (int index = 0; index < requireGosQuest.Template.GOInteractions.Length; ++index)
             {
                 QuestInteractionTemplate goInteraction = requireGosQuest.Template.GOInteractions[index];
                 if (((IEnumerable <uint>)goInteraction.TemplateId).Contains <uint>(go.Entry.Id))
                 {
                     this.UpdateInteractionCount(requireGosQuest, goInteraction, (WorldObject)go);
                 }
             }
         }
     }
 }
Exemple #11
0
 /// <summary>
 /// Is called when the owner of this QuestLog did
 /// the required interaction with the given NPC (usually killing)
 /// </summary>
 /// <param name="npc"></param>
 internal void OnNPCInteraction(NPC npc)
 {
     foreach (Quest interactionQuest in this.m_NPCInteractionQuests)
     {
         if (interactionQuest.Template.NPCInteractions != null)
         {
             for (int index = 0; index < interactionQuest.Template.NPCInteractions.Length; ++index)
             {
                 QuestInteractionTemplate npcInteraction = interactionQuest.Template.NPCInteractions[index];
                 if (((IEnumerable <uint>)npcInteraction.TemplateId).Contains <uint>(npc.Entry.Id))
                 {
                     this.UpdateInteractionCount(interactionQuest, npcInteraction, (WorldObject)npc);
                 }
             }
         }
     }
 }
Exemple #12
0
        internal void OnSpellCast(SpellCast cast)
        {
            if (this.m_RequireSpellCastsQuests.Count <= 0)
            {
                return;
            }
            foreach (Quest requireSpellCastsQuest in this.m_RequireSpellCastsQuests)
            {
                foreach (QuestInteractionTemplate spellInteraction in requireSpellCastsQuest.Template.SpellInteractions)
                {
                    QuestInteractionTemplate interaction = spellInteraction;
                    if (interaction.RequiredSpellId == cast.Spell.SpellId)
                    {
                        switch (interaction.ObjectType)
                        {
                        case ObjectTypeId.Unit:
                            WorldObject worldObject1 = cast.Targets.FirstOrDefault <WorldObject>(
                                (Func <WorldObject, bool>)(target =>
                            {
                                if (target is NPC)
                                {
                                    return(((IEnumerable <uint>)interaction.TemplateId).Contains <uint>(
                                               target.EntryId));
                                }
                                return(false);
                            }));
                            if (worldObject1 != null)
                            {
                                this.UpdateInteractionCount(requireSpellCastsQuest, interaction, worldObject1);
                                continue;
                            }

                            continue;

                        case ObjectTypeId.GameObject:
                            WorldObject worldObject2 = cast.Targets.FirstOrDefault <WorldObject>(
                                (Func <WorldObject, bool>)(target =>
                            {
                                if (target is GameObject)
                                {
                                    return(((IEnumerable <uint>)interaction.TemplateId).Contains <uint>(
                                               target.EntryId));
                                }
                                return(false);
                            }));
                            if (worldObject2 != null)
                            {
                                this.UpdateInteractionCount(requireSpellCastsQuest, interaction, worldObject2);
                                continue;
                            }

                            continue;

                        default:
                            this.UpdateInteractionCount(requireSpellCastsQuest, interaction, (WorldObject)null);
                            continue;
                        }
                    }
                }
            }
        }