Exemple #1
0
        void RecvStartNPCChatDialog(IIPSocket conn, BitStream r)
        {
            var npcIndex             = r.ReadMapEntityIndex();
            var forceSkipQuestDialog = r.ReadBool();

            User user;
            Map  map;

            if (!TryGetMap(conn, out user, out map))
            {
                return;
            }

            if (user.IsPeerTrading)
            {
                return;
            }

            var npc = map.GetDynamicEntity <NPC>(npcIndex);

            if (npc == 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;
            }

            // If the NPC provides any quests that this user can do or turn in, show that instead
            if (!forceSkipQuestDialog && !npc.Quests.IsEmpty())
            {
                IQuest <User>[] availableQuests;
                IQuest <User>[] turnInQuests;
                QuestHelper.GetAvailableQuests(user, npc, out availableQuests, out turnInQuests);

                if (availableQuests.Length > 0 || turnInQuests.Length > 0)
                {
                    using (
                        var pw = ServerPacket.StartQuestChatDialog(npcIndex, availableQuests.Select(x => x.QuestID),
                                                                   turnInQuests.Select(x => x.QuestID)))
                    {
                        user.Send(pw, ServerMessageType.GUI);
                    }
                    return;
                }
            }

            // Force-skipped the quest dialog, or there was no available quests, so start the chat dialog
            user.ChatState.StartChat(npc);
        }