Example #1
0
    private static List <ScriptContent> ParseContents(List <Content> contents)
    {
        List <ScriptContent> scriptContents = new();

        foreach (Content content in contents)
        {
            int functionId = content.functionID;
            ResponseSelection responseSelection = (ResponseSelection)content.buttonSet;

            List <ScriptDistractor> distractors = new();
            foreach (Distractor distractor in content.distractor)
            {
                List <int> gotoList     = [email protected](',').ToList();
                List <int> gotoFailList = distractor.gotoFail.SplitAndParseToInt(',').ToList();
                distractors.Add(new(gotoList, gotoFailList));
            }
            List <ScriptEvent> scriptEvents = new();
            foreach (Event eventContent in content.@event)
            {
                int eventId = eventContent.id;
                List <EventContent> eventContents = new();
                foreach (Content subContent in eventContent.content)
                {
                    eventContents.Add(new(subContent.voiceID, subContent.illust, subContent.text));
                }
                scriptEvents.Add((new(eventId, eventContents)));
            }

            scriptContents.Add(new(functionId, responseSelection, scriptEvents, distractors));
        }
        return(scriptContents);
    }
Example #2
0
    public static PacketWriter ContinueChat(int scriptId, DialogType dialogType, ResponseSelection responseSelection, int contentIndex, int questId = 0)
    {
        PacketWriter pWriter = PacketWriter.Of(SendOp.NpcTalk);

        pWriter.Write(NpcTalkMode.Continue);
        pWriter.Write(dialogType);
        pWriter.WriteInt(questId);
        pWriter.WriteInt(scriptId);
        pWriter.WriteInt(contentIndex); // used when there is multiple contents for the same script id
        pWriter.Write(responseSelection);

        return(pWriter);
    }
Example #3
0
    public static PacketWriter Respond(IFieldObject <NpcMetadata> npc, DialogType dialogType, int contentIndex, ResponseSelection responseSelection, int scriptId)
    {
        PacketWriter pWriter = PacketWriter.Of(SendOp.NpcTalk);

        pWriter.Write(NpcTalkMode.Respond);
        pWriter.WriteInt(npc.ObjectId);
        pWriter.Write(dialogType);
        pWriter.WriteInt(scriptId);
        pWriter.WriteInt(contentIndex);
        pWriter.Write(responseSelection);

        return(pWriter);
    }
Example #4
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");
        }
    }