Пример #1
0
        void RecvAcceptOrTurnInQuest(IIPSocket conn, BitStream r)
        {
            var providerIndex = r.ReadMapEntityIndex();
            var questID       = r.ReadQuestID();

            // Get the user
            User user;

            if ((user = TryGetUser(conn)) == null || user.Map == null)
            {
                return;
            }

            if (user.IsPeerTrading)
            {
                return;
            }

            // Get the provider
            var npc      = user.Map.GetDynamicEntity <Character>(providerIndex);
            var provider = npc as IQuestProvider <User>;

            if (provider == null)
            {
                return;
            }

            // Check the distance and state
            if (user.Map != npc.Map || user.Map == null || !npc.IsAlive || npc.IsDisposed ||
                user.GetDistance(npc) > GameData.MaxNPCChatDistance)
            {
                return;
            }

            // Get the quest
            var quest = _questManager.GetQuest(questID);

            if (quest == null)
            {
                return;
            }

            // Ensure this provider even provides this quest
            if (!provider.Quests.Contains(quest))
            {
                return;
            }

            // If the user already has the quest, try to turn it in
            if (user.ActiveQuests.Contains(quest))
            {
                // Quest already started, try to turn in
                var success = user.TryFinishQuest(quest);
                using (var pw = ServerPacket.AcceptOrTurnInQuestReply(questID, success, false))
                {
                    user.Send(pw, ServerMessageType.GUI);
                }
            }
            else
            {
                // Quest not started yet, try to add it
                var success = user.TryAddQuest(quest);
                using (var pw = ServerPacket.AcceptOrTurnInQuestReply(questID, success, true))
                {
                    user.Send(pw, ServerMessageType.GUI);
                }
            }
        }