public bool IsQuestComplete(uint questId)
        {
            var completeId = (ushort)(questId / 64);

            if (!CompletedQuests.ContainsKey(completeId))
            {
                return(false);
            }
            return(CompletedQuests[completeId].Body[(int)(questId - completeId * 64)]);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QuestPerformerStatusHelper"/> class.
        /// </summary>
        /// <param name="owner">The quest performer that this object will track the quest status of.</param>
        public QuestPerformerStatusHelper(User owner) : base(owner)
        {
            _questKillCounter = new QuestPerformerKillCounter(owner);

            // Send the initial quest status
            var completed = CompletedQuests.Select(x => x.QuestID);
            var active    = ActiveQuests.Select(x => x.QuestID);

            using (var pw = ServerPacket.QuestInfo(x => UserQuestInformation.WriteQuestInfo(x, completed, active)))
            {
                Owner.Send(pw, ServerMessageType.GUI);
            }
        }
예제 #3
0
        public void OnSavingColony(Colony c, JSONNode n)
        {
            if (!CompletedQuests.ContainsKey(c))
            {
                CompletedQuests.Add(c, new List <string>());
            }

            var colonySave = new ColonyQuestingSave()
            {
                ColonyId         = c.ColonyID,
                CompletedQuests  = CompletedQuests[c],
                InProgressQuests = new Dictionary <string, QuestingSave>()
            };

            var saveDir  = GameInitializer.SAVE_LOC + "Quests/";
            var saveFile = saveDir + c.ColonyID + ".json";

            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }

            if (File.Exists(saveFile))
            {
                File.Delete(saveFile);
            }

            foreach (var kvp in QuestPool)
            {
                colonySave.InProgressQuests.Add(kvp.Key, new QuestingSave()
                {
                    Name       = kvp.Key,
                    QuestSave  = kvp.Value.Save(c),
                    Objectives = new Dictionary <string, Newtonsoft.Json.Linq.JObject>()
                });

                foreach (var o in kvp.Value.QuestObjectives)
                {
                    var saveNode = o.Value.Save(kvp.Value, c);

                    if (saveNode != null)
                    {
                        colonySave.InProgressQuests[kvp.Key].Objectives.Add(o.Key, saveNode);
                    }
                }
            }

            File.WriteAllText(saveFile, JsonConvert.SerializeObject(colonySave));
        }
예제 #4
0
        public void OnTimedUpdate()
        {
            foreach (var quest in QuestPool)
            {
                foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.ValsRaw)
                {
                    if (!CompletedQuests.ContainsKey(colony))
                    {
                        CompletedQuests.Add(colony, new List <string>());
                    }

                    bool ok = true;

                    foreach (var pre in quest.Value.QuestPrerequisites)
                    {
                        if (!pre.MeetsPrerequisite(quest.Value, colony))
                        {
                            ok = false;
                        }
                    }

                    if (ok)
                    {
                        bool allComplete = true;

                        foreach (var objective in quest.Value.QuestObjectives.Values)
                        {
                            if (objective.GetProgress(quest.Value, colony) < 1f)
                            {
                                allComplete = false;
                            }
                        }

                        if (allComplete)
                        {
                            foreach (var reward in quest.Value.QuestRewards)
                            {
                                reward.IssueReward(quest.Value, colony);
                            }

                            if (!quest.Value.CanRepeat(colony) && !CompletedQuests[colony].Contains(quest.Value.QuestKey))
                            {
                                CompletedQuests[colony].Add(quest.Value.QuestKey);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine($"Completed => {string.Join(",", CompletedQuests.ToArray())}");
            builder.AppendLine("Started => ");
            StartedQuests.ForEach(q => {
                builder.AppendLine(q.ToString());
            });
            builder.AppendLine("Quest variables => ");
            foreach (var pair in QuestVariables)
            {
                builder.AppendLine($"{pair.Key} => {pair.Value}");
            }
            return(builder.ToString());
        }
        public void Complete(uint questId, int selected, bool supply = true)
        {
            if (!Quests.ContainsKey(questId))
            {
                _log.Warn("Complete not exist quest {0}", questId);
                return;
            }

            var quest = Quests[questId];
            var res   = quest.Complete(selected);

            if (res != 0)
            {
                if (supply)
                {
                    var supplies = QuestManager.Instance.GetSupplies(quest.Template.Level);
                    if (supplies != null)
                    {
                        Owner.AddExp(supplies.Exp, true);
                        Owner.Money += supplies.Copper;
                        Owner.SendPacket(
                            new SCItemTaskSuccessPacket(
                                ItemTaskType.QuestComplete,
                                new List <ItemTask>
                        {
                            new MoneyChange(supplies.Copper)
                        },
                                new List <ulong>())
                            );
                    }
                }

                var completeId = (ushort)(quest.TemplateId / 64);
                if (!CompletedQuests.ContainsKey(completeId))
                {
                    CompletedQuests.Add(completeId, new CompletedQuest(completeId));
                }
                var complete = CompletedQuests[completeId];
                complete.Body.Set((int)(quest.TemplateId - completeId * 64), true);
                var body = new byte[8];
                complete.Body.CopyTo(body, 0);
                Owner.SendPacket(new SCQuestContextCompletedPacket(quest.TemplateId, body, res));
                Quests.Remove(questId);
                _removed.Add(questId);
                OnQuestComplete(questId);
            }
        }
예제 #7
0
        /// <summary>
        /// Serialize the quest diary.
        /// </summary>
        /// <param name="packet">Packet stream.</param>
        public void Serialize(INetPacketStream packet)
        {
            packet.Write((byte)ActiveQuests.Count());
            foreach (QuestInfo quest in ActiveQuests)
            {
                quest.Serialize(packet);
            }

            packet.Write((byte)CompletedQuests.Count());
            foreach (QuestInfo quest in CompletedQuests)
            {
                packet.Write((short)quest.QuestId);
            }

            packet.Write((byte)CheckedQuests.Count());
            foreach (QuestInfo quest in CheckedQuests)
            {
                packet.Write((short)quest.QuestId);
            }
        }
예제 #8
0
        private void OnQuestReport(EventArgs arg0)
        {
            if (!(arg0 is IdArgs idArgs))
            {
                return;
            }
            var t = _quests.Find(x => x.Id == idArgs.Id);

            if (t == null)
            {
                return;
            }
            if (!t.IsComplete)
            {
                Debug.Log($"QuestLogController>>> Quest [{idArgs.Id}] Can't Reported, Quest is not complete");
                return;
            }
            QuestStorage.QuestCompleted(t.Id);
            AllTaskCompletedInQuests.Remove(t.Id);
            AllTaskCompletedInQuestsWithOptional.Remove(t.Id);
            _quests.Remove(t);
            ActiveQuests.Remove(t.Id);
            _completedQuest.Add(t);
            if (t.IsRepetable != 0)
            {
                SetQuestIsNotComplete(t.Id);
                _completedQuest.Remove(t);
                CompletedQuests.Remove(t.Id);
                foreach (var task in t.Tasks)
                {
                    CompletedTasks.Remove(task.Id);
                }
            }
#if UNITY_EDITOR
            Debug.Log($"QuestLogController>>> Quest [{idArgs.Id}] Reported");
            Debug.Log("Game saved");
#endif
            Services.SharedInstance.EventManager.TriggerEvent(GameEventTypes.QuestUpdated, null);
            QuestStorage.SaveGame("TestSave.bytes");
        }
        public void Load(MySqlConnection connection)
        {
            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM completed_quests WHERE `owner` = @owner";
                command.Parameters.AddWithValue("@owner", Owner.Id);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var quest = new CompletedQuest();
                        quest.Id   = reader.GetUInt16("id");
                        quest.Body = new BitArray((byte[])reader.GetValue("data"));
                        CompletedQuests.Add(quest.Id, quest);
                    }
                }
            }

            using (var command = connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM quests WHERE `owner` = @owner";
                command.Parameters.AddWithValue("@owner", Owner.Id);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var quest = new Quest();
                        quest.Id         = reader.GetUInt32("id");
                        quest.TemplateId = reader.GetUInt32("template_id");
                        quest.Status     = (QuestStatus)reader.GetByte("status");
                        quest.ReadData((byte[])reader.GetValue("data"));
                        quest.Owner    = Owner;
                        quest.Template = QuestManager.Instance.GetTemplate(quest.TemplateId);
                        quest.RecalcObjectives(false);
                        Quests.Add(quest.TemplateId, quest);
                    }
                }
            }
        }
예제 #10
0
        public void OnLoadingColony(Colony c, JSONNode n)
        {
            if (!CompletedQuests.ContainsKey(c))
            {
                CompletedQuests.Add(c, new List <string>());
            }

            var saveDir  = GameInitializer.SAVE_LOC + "Quests/";
            var saveFile = saveDir + c.ColonyID + ".json";

            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }

            if (File.Exists(saveFile))
            {
                var colonySave = JsonConvert.DeserializeObject <ColonyQuestingSave>(File.ReadAllText(saveFile));

                CompletedQuests[c] = colonySave.CompletedQuests;

                foreach (var kvp in colonySave.InProgressQuests)
                {
                    if (QuestPool.TryGetValue(kvp.Key, out var quest))
                    {
                        quest.Load(kvp.Value.QuestSave, c);

                        foreach (var o in kvp.Value.Objectives)
                        {
                            if (quest.QuestObjectives.TryGetValue(o.Key, out var objective))
                            {
                                objective.Load(o.Value, quest, c);
                            }
                        }
                    }
                }
            }
        }
예제 #11
0
        public void ParseInfo(Hashtable info)
        {
            CompletedQuests.Clear();
            if (info.ContainsKey((int)SPC.CompletedQuests))
            {
                string[] arr = info[(int)SPC.CompletedQuests] as string[];
                CompletedQuests.AddRange(arr);
            }

            StartedQuests.Clear();
            if (info.ContainsKey((int)SPC.StartedQuests))
            {
                Hashtable[] hashArr = info[(int)SPC.StartedQuests] as Hashtable[];
                if (hashArr != null)
                {
                    foreach (Hashtable questHash in hashArr)
                    {
                        QuestInfo quest = new QuestInfo(dataCollection);
                        quest.ParseInfo(questHash);
                        StartedQuests.Add(quest);
                    }
                }
            }

            QuestVariables.Clear();
            if (info.ContainsKey((int)SPC.Variables))
            {
                Hashtable varHash = info[(int)SPC.Variables] as Hashtable;
                if (varHash != null)
                {
                    foreach (System.Collections.DictionaryEntry entry in varHash)
                    {
                        QuestVariables.Add(entry.Key.ToString(), entry.Value);
                    }
                }
            }
        }
예제 #12
0
        public void Execute()
        {
            if (Profile == null)
            {
                return;
            }

            if (!UpdatedCompletedQuests)
            {
                if (WowInterface.EventHookManager.EventDictionary.All(e => e.Key != "QUEST_QUERY_COMPLETE"))
                {
                    WowInterface.EventHookManager.Subscribe("QUEST_QUERY_COMPLETE", OnGetQuestsCompleted);
                }

                if (QueryCompletedQuestsEvent.Run())
                {
                    WowInterface.HookManager.LuaQueryQuestsCompleted();
                }

                return;
            }

            if (Profile.Quests.Count > 0)
            {
                // do i need to recover my hp
                if (WowInterface.ObjectManager.Player.HealthPercentage < Config.EatUntilPercent &&
                    WowInterface.ObjectManager.GetNearEnemies <WowUnit>(WowInterface.ObjectManager.Player.Position, 60.0).Any())
                {
                    // wait or eat something
                    if (WowInterface.CharacterManager.HasItemTypeInBag <WowFood>() || WowInterface.CharacterManager.HasItemTypeInBag <WowRefreshment>())
                    {
                        StateMachine.SetState(BotState.Eating);
                        return;
                    }
                }

                IEnumerable <IBotQuest> selectedQuests = Profile.Quests.Peek().Where(e => !e.Returned && !CompletedQuests.Contains(e.Id));

                // Drop all quest that are not selected
                if (WowInterface.ObjectManager.Player.QuestlogEntries.Count() == 25 && DateTime.Now.Subtract(LastAbandonQuestTime).TotalSeconds > 30)
                {
                    WowInterface.HookManager.LuaAbandonQuestsNotIn(selectedQuests.Select(q => q.Name));
                    LastAbandonQuestTime = DateTime.Now;
                }

                if (selectedQuests.Any())
                {
                    IBotQuest notAcceptedQuest = selectedQuests.FirstOrDefault(e => !e.Accepted);

                    // make sure we got all quests
                    if (notAcceptedQuest != null)
                    {
                        if (!notAcceptedQuest.Accepted)
                        {
                            notAcceptedQuest.AcceptQuest();
                            return;
                        }
                    }
                    else
                    {
                        // do the quests if not all of them are finished
                        if (selectedQuests.Any(e => !e.Finished))
                        {
                            IBotQuest activeQuest = selectedQuests.FirstOrDefault(e => !e.Finished);
                            activeQuest?.Execute();
                        }
                        else
                        {
                            // make sure we return all quests
                            IBotQuest notReturnedQuest = selectedQuests.FirstOrDefault(e => !e.Returned);

                            if (notReturnedQuest != null)
                            {
                                if (notReturnedQuest.CompleteQuest())
                                {
                                    CompletedQuests.Add(notReturnedQuest.Id);
                                }

                                return;
                            }
                        }
                    }
                }
                else
                {
                    CompletedQuests.AddRange(Profile.Quests.Dequeue().Select(e => e.Id));
                    return;
                }
            }

            // filter duplicates
            CompletedQuests = CompletedQuests.Distinct().ToList();
        }
 public CompletedQuest GetCompletedQuest(ushort id)
 {
     return(CompletedQuests.ContainsKey(id) ? CompletedQuests[id] : null);
 }
 public void AddCompletedQuest(CompletedQuest quest)
 {
     CompletedQuests.Add(quest.Id, quest);
 }
예제 #15
0
        public void Execute()
        {
            if (Profile == null)
            {
                return;
            }

            if (!UpdatedCompletedQuests)
            {
                if (QueryCompletedQuestsEvent.Run())
                {
                    WowInterface.HookManager.QueryQuestsCompleted();
                }

                return;
            }

            if (Profile.Quests.Count > 0)
            {
                List <BotQuest> quests         = Profile.Quests.Peek();
                List <BotQuest> selectedQuests = quests.Where(e => (!e.Returned && !CompletedQuests.Contains(e.Id)) || WowInterface.ObjectManager.Player.QuestlogEntries.Any(x => x.Id == e.Id)).ToList();

                if (selectedQuests != null && selectedQuests.Count > 0)
                {
                    BotQuest notAcceptedQuest = selectedQuests.FirstOrDefault(e => !e.Accepted);

                    // make sure we got all quests
                    if (notAcceptedQuest != null)
                    {
                        if (!notAcceptedQuest.Accepted)
                        {
                            notAcceptedQuest.AcceptQuest();
                            return;
                        }
                    }
                    else
                    {
                        // do the quests if not all of them are finished
                        if (selectedQuests.Any(e => !e.Finished))
                        {
                            BotQuest activeQuest = selectedQuests.FirstOrDefault(e => !e.Finished);

                            if (activeQuest != null)
                            {
                                activeQuest.Execute();
                            }
                        }
                        else
                        {
                            // make sure we return all quests
                            BotQuest notReturnedQuest = selectedQuests.FirstOrDefault(e => !e.Returned);

                            if (notReturnedQuest != null)
                            {
                                notReturnedQuest.CompleteQuest();
                                CompletedQuests.Add(notReturnedQuest.Id);
                                return;
                            }
                        }
                    }
                }
                else
                {
                    CompletedQuests.AddRange(Profile.Quests.Dequeue().Select(e => e.Id));
                    return;
                }
            }

            // filter duplicates
            CompletedQuests = CompletedQuests.Distinct().ToList();
        }
예제 #16
0
        public void Execute()
        {
            if (Profile == null)
            {
                return;
            }

            if (!UpdatedCompletedQuests)
            {
                if (Bot.Wow.Events.Events.All(e => e.Key != "QUEST_QUERY_COMPLETE"))
                {
                    Bot.Wow.Events.Subscribe("QUEST_QUERY_COMPLETE", OnGetQuestsCompleted);
                }

                if (QueryCompletedQuestsEvent.Run())
                {
                    Bot.Wow.QueryQuestsCompleted();
                }

                return;
            }

            if (Profile.Quests.Count > 0)
            {
                IEnumerable <IBotQuest> selectedQuests = Profile.Quests.Peek().Where(e => !e.Returned && !CompletedQuests.Contains(e.Id));

                // drop all quest that are not selected
                if (Bot.Player.QuestlogEntries.Count() == 25 && DateTime.UtcNow.Subtract(LastAbandonQuestTime).TotalSeconds > 30)
                {
                    Bot.Wow.AbandonQuestsNotIn(selectedQuests.Select(q => q.Name));
                    LastAbandonQuestTime = DateTime.UtcNow;
                }

                if (selectedQuests.Any())
                {
                    IBotQuest notAcceptedQuest = selectedQuests.FirstOrDefault(e => !e.Accepted);

                    // make sure we got all quests
                    if (notAcceptedQuest != null)
                    {
                        if (!notAcceptedQuest.Accepted)
                        {
                            notAcceptedQuest.AcceptQuest();
                            return;
                        }
                    }
                    else
                    {
                        // do the quests if not all of them are finished
                        if (selectedQuests.Any(e => !e.Finished))
                        {
                            IBotQuest activeQuest = selectedQuests.FirstOrDefault(e => !e.Finished);
                            activeQuest?.Execute();
                        }
                        else
                        {
                            // make sure we return all quests
                            IBotQuest notReturnedQuest = selectedQuests.FirstOrDefault(e => !e.Returned);

                            if (notReturnedQuest != null)
                            {
                                if (notReturnedQuest.CompleteQuest())
                                {
                                    CompletedQuests.Add(notReturnedQuest.Id);
                                }

                                return;
                            }
                        }
                    }
                }
                else
                {
                    CompletedQuests.AddRange(Profile.Quests.Dequeue().Select(e => e.Id));
                    return;
                }
            }

            // filter duplicates
            CompletedQuests = CompletedQuests.Distinct().ToList();
        }