private static void HandleBegin(GameSession session, PacketReader packet) { int objectId = packet.ReadInt(); List <QuestStatus> npcQuests = new(); int contentIndex = 0; // Find if npc object id exists in field manager if (!session.FieldManager.State.Npcs.TryGetValue(objectId, out Npc npc)) { return; } // Get all quests for this npc foreach (QuestStatus item in session.Player.QuestData.Values.Where(x => x.State is not QuestState.Completed)) { if (npc.Value.Id == item.StartNpcId) { npcQuests.Add(item); } if (item.State is QuestState.Started && npc.Value.Id == item.CompleteNpcId && !npcQuests.Contains(item)) { npcQuests.Add(item); } } session.Player.NpcTalk = new(npc.Value, npcQuests); NpcTalk npcTalk = session.Player.NpcTalk; ScriptMetadata scriptMetadata = ScriptMetadataStorage.GetNpcScriptMetadata(npc.Value.Id); NpcKind kind = npc.Value.NpcMetadataBasic.Kind; // need to find script properly before continuing NpcScript npcScript = GetFirstScript(session, scriptMetadata, npcTalk, npcQuests); switch (kind) { // reputation NPCs only have UI Dialog Type even if they have quests to accept/accepted. case NpcKind.SkyLumiknightCommander: case NpcKind.SkyGreenHoodCommander: case NpcKind.SkyDarkWindCommander: case NpcKind.SkyMapleAllianceCommander: case NpcKind.SkyRoyalGuardCommander: case NpcKind.KritiasLumiknightCommander: case NpcKind.KritiasGreenHoodCommander: case NpcKind.KritiasMapleAllianceCommander: case NpcKind.Humanitas: npcTalk.DialogType = DialogType.UI; ShopHandler.HandleOpen(session, npc, npc.Value.Id); break; case NpcKind.BalmyShop: case NpcKind.FixedShop: case NpcKind.RotatingShop: ShopHandler.HandleOpen(session, npc, npc.Value.Id); break; case NpcKind.Storage: case NpcKind.BlackMarket: case NpcKind.Birthday: // TODO: needs a special case? select if birthday. script if not npcTalk.DialogType = DialogType.UI; break; } npcTalk.ScriptId = npcScript?.Id ?? 0; ResponseSelection responseSelection = GetResponseSelection(kind, npcTalk.DialogType, contentIndex, npcScript); if (npcTalk.DialogType.HasFlag(DialogType.Quest)) { session.Send(QuestPacket.SendDialogQuest(objectId, npcQuests)); } QuestManager.OnTalkNpc(session.Player, npc.Value.Id, npcTalk.ScriptId); session.Send(NpcTalkPacket.Respond(npc, npcTalk.DialogType, contentIndex, responseSelection, npcTalk.ScriptId)); if (npcScript != null) { npcTalk.TalkFunction(session, npcScript.Contents[npcTalk.ContentIndex].FunctionId, "preTalkActions"); } }