Exemplo n.º 1
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            switch (function)
            {
            case 0:     // Cancel
                return;

            case 1:
                int objectId = packet.ReadInt();
                if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
                {
                    return;     // Invalid NPC
                }
                // If NPC is a shop, load and open the shop
                if (npc.Value.IsShop())
                {
                    ShopHandler.HandleOpen(session, npc);
                    return;
                }
                else if (npc.Value.IsBank())
                {
                    session.Send(HomeBank.OpenBank());
                    return;
                }
                // Stellar Chest: 11004215
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, 0));
                break;

            case 2:                           // Continue chat?
                int index = packet.ReadInt(); // selection index
                session.Send(NpcTalkPacket.Close());
                break;
            }
        }
Exemplo n.º 2
0
        private static void HandleRespond(GameSession session, PacketReader packet)
        {
            List <QuestStatus> npcQuests = new List <QuestStatus>();
            int objectId = packet.ReadInt();

            if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
            {
                return; // Invalid NPC
            }
            foreach (QuestStatus item in session.Player.QuestList.Where(x => !x.Completed))
            {
                if (npc.Value.Id == item.StartNpcId)
                {
                    npcQuests.Add(item);
                }
                if (item.Started && npc.Value.Id == item.CompleteNpcId && !npcQuests.Contains(item))
                {
                    npcQuests.Add(item);
                }
            }
            session.Player.NpcTalk = new NpcTalk(npc.Value, npcQuests);
            // If NPC is a shop, load and open the shop
            if (npc.Value.IsShop())
            {
                ShopHandler.HandleOpen(session, npc);
                return;
            }
            else if (npc.Value.IsBank())
            {
                session.Send(HomeBank.OpenBank());
                return;
            }
            else if (npc.Value.IsBeauty())
            {
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                return;
            }

            QuestHelper.UpdateExplorationQuest(session, npc.Value.Id.ToString(), "talk_in");

            if (npcQuests.Count != 0)
            {
                session.Player.NpcTalk.ScriptId = 0;
                session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests));
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, session.Player.NpcTalk.ScriptId));
            }
            else
            {
                ScriptMetadata scriptMetadata = ScriptMetadataStorage.GetNpcScriptMetadata(npc.Value.Id);
                int            firstScript    = scriptMetadata.Options.First(x => x.Type == ScriptType.Script).Id;
                session.Player.NpcTalk.ScriptId = firstScript;

                Option option = scriptMetadata.Options.First(x => x.Id == firstScript);

                bool       hasNextScript = option.Goto.Count != 0;
                DialogType dialogType    = DialogType.CloseNext1;
                if (option.Goto.Count == 0)
                {
                    session.Player.NpcTalk.ContentIndex++;
                    dialogType = DialogType.CloseNext1;
                }

                if (!hasNextScript)
                {
                    dialogType = DialogType.Close1;
                }

                if (option.AmountContent > 1)
                {
                    dialogType = DialogType.CloseNext;
                }

                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk3, dialogType, firstScript));
            }
        }
Exemplo n.º 3
0
        private static void HandleRespond(GameSession session, PacketReader packet)
        {
            List <QuestStatus> npcQuests = new List <QuestStatus>();
            int objectId = packet.ReadInt();

            // Find if npc object id exists in field manager
            if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
            {
                return;
            }

            // Get all quests for this npc
            foreach (QuestStatus item in session.Player.QuestList.Where(x => !x.Completed))
            {
                if (npc.Value.Id == item.StartNpcId)
                {
                    npcQuests.Add(item);
                }
                if (item.Started && npc.Value.Id == item.CompleteNpcId && !npcQuests.Contains(item))
                {
                    npcQuests.Add(item);
                }
            }
            session.Player.NpcTalk = new NpcTalk(npc.Value, npcQuests);
            ScriptLoader scriptLoader = new ScriptLoader($"Npcs/{npc.Value.Id}", session);

            // If NPC is a shop, load and open the shop
            if (npc.Value.IsShop())
            {
                ShopHandler.HandleOpen(session, npc);
                return;
            }
            else if (npc.Value.IsBank())
            {
                session.Send(HomeBank.OpenBank());
                return;
            }
            else if (npc.Value.IsBeauty())
            {
                NpcMetadata npcTarget = NpcMetadataStorage.GetNpc(session.Player.NpcTalk.Npc.Id);
                if (npcTarget.ShopId == 507) // mirror
                {
                    session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 0));
                    HandleBeauty(session);
                    return;
                }

                session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                return;
            }

            // Check if npc has an exploration quest
            QuestHelper.UpdateExplorationQuest(session, npc.Value.Id.ToString(), "talk_in");

            // If npc has quests, send quests and talk option
            if (npcQuests.Count != 0)
            {
                session.Player.NpcTalk.ScriptId = 0;
                session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests));
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, session.Player.NpcTalk.ScriptId));
                return;
            }

            ScriptMetadata scriptMetadata = ScriptMetadataStorage.GetNpcScriptMetadata(npc.Value.Id);

            if (!scriptMetadata.Options.Exists(x => x.Type == ScriptType.Script))
            {
                return;
            }

            int firstScriptId = GetFirstScriptId(scriptLoader, scriptMetadata);

            session.Player.NpcTalk.ScriptId = firstScriptId;

            Option option = scriptMetadata.Options.First(x => x.Id == firstScriptId);

            DialogType dialogType = DialogType.None;

            if (option.Contents[0].Goto.Count == 0)
            {
                dialogType = DialogType.Close1;
            }
            else
            {
                dialogType = DialogType.CloseNextWithDistractor;
            }

            session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk3, dialogType, firstScriptId));

            // If npc has buttonset roulette, send roulette id 13.
            // TODO: Send the correct roulette id
            if (scriptMetadata.Options.Any(x => x.ButtonSet == "roulette"))
            {
                session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "RouletteDialog", "13"));
            }
        }
Exemplo n.º 4
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            byte function = packet.ReadByte();

            switch (function)
            {
            case 0:     // Cancel
                return;

            case 1:
                int objectId = packet.ReadInt();
                if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out IFieldObject <Npc> npc))
                {
                    return;     // Invalid NPC
                }
                session.Player.NpcTalk = npc;
                // If NPC is a shop, load and open the shop
                if (npc.Value.IsShop())
                {
                    ShopHandler.HandleOpen(session, npc);
                    return;
                }
                else if (npc.Value.IsBank())
                {
                    session.Send(HomeBank.OpenBank());
                    return;
                }
                else if (npc.Value.IsBeauty())
                {
                    session.Send(NpcTalkPacket.Respond(npc, NpcType.Default, DialogType.Beauty, 1));
                    return;
                }
                // Stellar Chest: 11004215
                session.Send(NpcTalkPacket.Respond(npc, NpcType.Unk2, DialogType.TalkOption, 0));
                break;

            case 2:                                                                                                                 // Continue chat?
                int index = packet.ReadInt();                                                                                       // selection index

                if (session.Player.NpcTalk.Value.IsBeauty())                                                                        // This may need a cleaner method
                {
                    MapPortal portal = MapEntityStorage.GetPortals(session.Player.MapId).FirstOrDefault(portal => portal.Id == 99); // unsure how the portalId is determined
                    session.Send(NpcTalkPacket.Action(ActionType.Portal, "", "", portal.Id));
                    NpcMetadata npcTarget = NpcMetadataStorage.GetNpc(session.Player.NpcTalk.Value.Id);

                    switch (npcTarget.ShopId)
                    {
                    case 500:                                                                                  // Dr Dixon
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "face")); // unsure how these strings are determined
                        break;

                    case 501:         // Dr Zenko
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "skin"));
                        break;

                    case 504:         // Rosetta
                    case 509:         //Lolly
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,style"));
                        break;

                    case 505:         // Ren
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "makeup"));
                        break;

                    case 506:         // Douglas
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "itemcolor"));
                        break;

                    case 507:         // Mirror
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "mirror"));
                        break;

                    case 508:         // Paulie
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,random"));
                        break;

                    case 510:         // Mino
                        session.Send(NpcTalkPacket.Action(ActionType.OpenWindow, "BeautyShopDialog", "hair,styleSave"));
                        break;
                    }
                    session.Send(UserMoveByPortalPacket.Move(session, portal.Coord.ToFloat(), portal.Rotation.ToFloat()));
                }
                session.Send(NpcTalkPacket.Close());
                session.Player.NpcTalk = null;
                break;
            }
        }