public Quest(int id, bool isQuestComplete, string name, string description , int limitLvMin, int limitLvMax, NpcKind npcKind, int exp, int itemcode, int itemAmount, QuestType questType, int questAmount, NpcKind questNpc, int questItemId, int gold) { this.id = id; this.isQuestComplete = isQuestComplete; this.name = name; this.description = description; this.limitLvMin = limitLvMin; this.limitLvMax = limitLvMax; this.npcKind = npcKind; this.exp = exp; this.itemCode = itemcode; this.itemAmount = itemAmount; this.questType = questType; this.questAmount = questAmount; this.questNpc = questNpc; this.questItemId = questItemId; this.gold = gold; this.progress = 0; }
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"); } }
private static ResponseSelection GetResponseSelection(NpcKind npcKind, DialogType type, int contentIndex, NpcScript npcScript) { if (npcScript?.Contents[contentIndex]?.ButtonSet != 0 && npcScript != null) { return(npcScript.Contents[contentIndex].ButtonSet); } if (type.HasFlag(DialogType.Options)) { if (npcScript?.Contents.Count > 0) { return(ResponseSelection.SelectableTalk); } return(ResponseSelection.None); } if (type.HasFlag(DialogType.UI) && npcScript?.Type == ScriptType.Select) { return(ResponseSelection.None); } if (npcScript?.Contents[contentIndex].Distractor.Count > 0) { return(ResponseSelection.SelectableDistractor); } if (npcScript?.Contents.ElementAtOrDefault(contentIndex + 1) is not null) { return(ResponseSelection.Next); } switch (npcScript?.Type) { case ScriptType.Job: switch (npcKind) { case NpcKind.Travel: return(ResponseSelection.TakeBoat); case NpcKind.BeautyDye: case NpcKind.BeautyHair: case NpcKind.BeautyFaceAndSkin: case NpcKind.BeautyFaceDecoration: case NpcKind.Mirror: return(ResponseSelection.Beauty); case NpcKind.JobAdvancement: return(ResponseSelection.JobAdvance); case NpcKind.Wheel: return(ResponseSelection.Roulette); } break; case ScriptType.Select: switch (npcKind) { case NpcKind.Storage: case NpcKind.FixedShop: case NpcKind.BalmyShop: case NpcKind.RotatingShop: return(ResponseSelection.None); } break; } if (type == DialogType.Quest) { ScriptIdType questScriptIdType = (ScriptIdType)(npcScript.Id / 100); return(questScriptIdType switch { ScriptIdType.Start => ResponseSelection.QuestAccept, ScriptIdType.Continue => ResponseSelection.QuestProgress, ScriptIdType.End => ResponseSelection.QuestComplete, _ => ResponseSelection.Close });