/// <summary>
        /// Starts a quest. Yep. That's it.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="id"></param>
        public void StartQuest(MabiPC character, uint id)
        {
            // This would prevent restarting of quests.
            //if (this.HasQuest(client, id))
            //{
            //    Logger.Warning("Trying to start quest '{0}' for '{1}' twice.", id, client.Character.Name);
            //    return;
            //}

            // Remove quest if it's aleady there and not completed,
            // or it will be shown twice till next relog.
            var exiQuest = character.GetQuestOrNull(id);
            if (exiQuest != null && exiQuest.State < MabiQuestState.Complete)
                WorldManager.Instance.CreatureCompletesQuest(character, character.Quests[id], false);

            // Check here, before we add a quest that doesn't even exist.
            if (!MabiData.QuestDb.Exists(id))
            {
                Logger.Warning("Quest '{0}' does not exist.", id);
                return;
            }

            var quest = new MabiQuest(id);
            character.Quests[id] = quest;

            // Owl
            WorldManager.Instance.Broadcast(new MabiPacket(Op.QuestOwlNew, character.Id).PutLong(quest.Id), SendTargets.Range, character);

            // Quest item (required to complete quests)
            Send.ItemInfo(character.Client, character, quest.QuestItem);

            // Quest info
            Send.QuestNew(character, quest);
        }
Beispiel #2
0
        public static void QuestUpdate(MabiCreature creature, MabiQuest quest)
        {
            var packet = new MabiPacket(Op.QuestUpdate, creature.Id);
            packet.AddQuestProgress(quest);

            creature.Client.Send(packet);
        }
Beispiel #3
0
        public static void QuestNew(MabiPC character, MabiQuest quest)
        {
            var packet = new MabiPacket(Op.QuestNew, character.Id);
            packet.AddQuest(quest);

            character.Client.Send(packet);
        }
Beispiel #4
0
        /// <summary>
        /// Looks for follow up quests and starts them,
        /// if the prerequisites are met.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="quest"></param>
        public virtual void OnCompleted(WorldClient client, MabiQuest quest)
        {
            var character = client.Character as MabiPC;

            foreach (var followUp in ScriptManager.Instance.GetFollowUpQuestScripts(this.Id))
                followUp.CheckPrerequisites(character);
        }
Beispiel #5
0
        public MabiItem(MabiQuest quest)
            : this(70024, false)
        {
            this.Id = quest.Id - Aura.Shared.Const.Id.QuestItemOffset;
            this.Info.Pocket = (byte)Pocket.Quest;
            this.OptionInfo.Flag = 1;

            this.QuestId = quest.Id;
            //this.AdditionalInfo = quest.ToolTip;
        }
Beispiel #6
0
        public void CreatureCompletesQuest(MabiCreature creature, MabiQuest quest, bool rewards)
        {
            if (rewards)
            {
                // Owl
                WorldManager.Instance.Broadcast(new MabiPacket(Op.QuestOwlComplete, creature.Id).PutLong(quest.Id), SendTargets.Range, creature);

                // Rewards
                foreach (var reward in quest.Info.Rewards)
                {
                    switch (reward.Type)
                    {
                        case RewardType.Exp:
                            creature.GiveExp(reward.Amount);
                            creature.Client.Send(PacketCreator.AcquireExp(creature, reward.Amount));
                            this.CreatureStatsUpdate(creature);
                            break;

                        case RewardType.Gold:
                            creature.GiveItem(2000, reward.Amount);
                            creature.Client.Send(PacketCreator.AcquireItem(creature, reward.Id, reward.Amount));
                            break;

                        case RewardType.Item:
                            creature.GiveItem(reward.Id, reward.Amount);
                            creature.Client.Send(PacketCreator.AcquireItem(creature, reward.Id, reward.Amount));
                            break;

                        case RewardType.Skill:
                            var id = (SkillConst)reward.Id;
                            var rank = (SkillRank)reward.Amount;

                            // Only give skill if char doesn't have it or rank is lower.
                            var skill = creature.Skills.Get(id);
                            if (skill == null || skill.Rank < rank)
                            {
                                creature.Skills.Give(id, rank);
                                WorldManager.Instance.CreatureStatsUpdate(creature);
                            }
                            break;

                        default:
                            Logger.Warning("Unsupported reward type '{0}'.", reward.Type);
                            break;
                    }
                }

                // Only call this if there were rewards, we're using this
                // method to clear quests as well.
                var script = ScriptManager.Instance.GetQuestScript(quest.Info.Id);
                if (script != null)
                    script.OnCompleted(creature.Client as WorldClient, quest);
            }

            Send.ItemInfo(creature.Client, creature, quest.QuestItem);

            // Remove from quest log.
            creature.Client.Send(new MabiPacket(Op.QuestClear, creature.Id).PutLong(quest.Id));
        }
Beispiel #7
0
        private static void AddQuest(this MabiPacket packet, MabiQuest quest)
        {
            if (quest.Info == null)
                return;

            packet.PutLong(quest.Id);
            packet.PutByte(0);

            packet.PutLong(quest.ItemId);

            packet.PutByte(2); // 0 = blue icon, 7 (shadow? changes structure slightly)

            packet.PutInt(quest.Info.Id); // 200076, range important for the tabs.

            packet.PutString(quest.Info.Name);
            packet.PutString(quest.Info.Description);
            packet.PutString(quest.Info.AdditionalInfo);

            packet.PutInt(1);
            packet.PutInt(70024); // Item "Hunting Quest" ?
            packet.PutByte(quest.Info.Cancelable);
            packet.PutByte(0);
            packet.PutByte(0); // 1 = blue icon
            packet.PutByte(0);

            // [180300, NA166 (18.09.2013)] ?
            {
                packet.PutByte(0);
                packet.PutByte(0);
                packet.PutByte(0);
            }

            packet.PutString(""); // data\gfx\image\gui_temporary_quest.dds
            packet.PutInt(0);     // 4, x y ?
            packet.PutInt(0);
            packet.PutString(""); // <xml soundset="4" npc="GUI_NPCportrait_Lanier"/>
            packet.PutString("QMBEXP:f:1.000000;QMBGLD:f:1.000000;QMSMEXP:f:1.000000;QMSMGLD:f:1.000000;QMAMEXP:f:1.000000;QMAMGLD:f:1.000000;QMBHDCTADD:4:0;QMGNRB:f:1.000000;QMGNRB:f:1.000000;");

            packet.PutInt(0);
            packet.PutInt(0);
            // Alternative, PTJ
            //020 [........00000002] Int    : 2
            //021 [........0000000C] Int    : 12
            //022 [........00000010] Int    : 16
            //023 [........00000015] Int    : 21
            //024 [000039BF89671150] Long   : 63494806770000 // Timestamp

            packet.PutSInt(quest.Info.Objectives.Count);
            foreach (DictionaryEntry de in quest.Info.Objectives)
            {
                var key = de.Key as string;
                var objective = de.Value as QuestObjectiveInfo;
                var progress = quest.Progresses[key] as MabiQuestProgress;

                packet.PutByte((byte)objective.Type);
                packet.PutString(objective.Description);
                packet.PutString(objective.ToString());

                // 3  - TARGECHAR:s:shamala;TARGETCOUNT:4:1; - Ask Shamala about collecting transformations
                // 14 - TARGETITEM:4:40183;TARGETCOUNT:4:1; - Break a nearby tree
                // 1  - TGTSID:s:/brownphysisfoxkid/;TARGETCOUNT:4:10;TGTCLS:2:0; - Hunt 10 Young Brown Physis Foxes
                // 9  - TGTSKL:2:23002;TGTLVL:2:1;TARGETCOUNT:4:1; - Combat Mastery rank F reached
                // 19 - TGTCLS:2:3906;TARGETCOUNT:4:1; - Win at least one match in the preliminaries or the finals of the Jousting Tournament.
                // 18 - TGTCLS:2:3502;TARGETCOUNT:4:1; - Read the Author's Notebook.
                // 4  - TARGECHAR:s:duncan;TARGETITEM:4:75473;TARGETCOUNT:4:1; - Deliver the Author's Notebook to Duncan.
                // 15 - TGTLVL:2:15;TARGETCOUNT:4:1; - Reach Lv. 15
                // 2  - TARGETITEM:4:52027;TARGETCOUNT:4:10;QO_FLAG:4:1; - Harvest 10 Bundles of Wheat
                // 22 - TGTSID:s:/ski/start/;TARGETITEM:4:0;EXCNT:4:0;TGITM2:4:0;EXCNT2:4:0;TARGETCOUNT:4:1; - Click on the Start Flag.
                // 47 - TARGETCOUNT:4:1;TGTCLS:4:730205; - Clear the Monkey Mash Mission.
                // 52 - QO_FLAG:b:true;TARGETCOUNT:4:1; - Collect for the Transformation Diary
                // 50 - TARGETRACE:4:9;TARGETCOUNT:4:1; - Transform into a Kiwi.
                // 54 - TARGETRACE:4:9;TARGETCOUNT:4:1; - Collect Frail Green Kiwi perfectly.

                // Type theory:
                // 1  : Kill x of y
                // 2  : Collect x of y
                // 3  : Talk to x
                // 4  : Bring x to y
                // 9  : Reach rank x on skill y
                // 14 : ?
                // 15 : Reach lvl x
                // 18 : Do something with item x ?
                // 19 : Clear something, like jousting or a dungeon?

                // Progress
                packet.PutInt(progress.Count);
                packet.PutByte(progress.Done);
                packet.PutByte(progress.Unlocked);

                // Target location
                if (objective.Region > 0)
                {
                    packet.PutByte(1);
                    packet.PutInt(objective.Region);
                    packet.PutInt(objective.X);
                    packet.PutInt(objective.Y);
                }
                else
                {
                    packet.PutByte(0);
                }
            }

            packet.PutByte(1);
            packet.PutByte(0);
            packet.PutByte(0);
            packet.PutByte(1);

            // Rewards
            packet.PutByte((byte)quest.Info.Rewards.Count);
            foreach (var reward in quest.Info.Rewards)
            {
                packet.PutByte((byte)reward.Type);
                packet.PutString(reward.ToString());
                packet.PutByte(reward.Group);
                packet.PutByte(1);
                packet.PutByte(1);
            }

            packet.PutByte(0);
        }
Beispiel #8
0
        private static void AddQuestProgress(this MabiPacket packet, MabiQuest quest)
        {
            packet.PutLong(quest.Id);
            packet.PutByte(1);

            packet.PutSInt(quest.Progresses.Count);
            foreach (MabiQuestProgress p in quest.Progresses.Values)
            {
                packet.PutInt(p.Count);
                packet.PutByte(p.Done);
                packet.PutByte(p.Unlocked);
            }

            packet.PutByte(0);
            packet.PutByte(0);
        }