Beispiel #1
0
    public DialogLinkNode CreateLinkNode(DialogLink link)
    {
        DialogLinkNode linkNode = new DialogLinkNode();

        if (link != null)
        {
            linkNode.link       = link;
            linkNode.windowRect = link.nodePosition;
        }
        else
        {
            GameObject goLink = new GameObject("Link");
            goLink.transform.parent = choose.transform;
            DialogLink newLink = goLink.AddComponent <DialogLink>();
            choose.links.Add(newLink);
            linkNode.link = newLink;
            newLink.input = choose;
            Selection.activeGameObject     = newLink.gameObject;
            DialogEditor.editor.selectLink = linkNode;
            DialogEditor.editor.linkMod    = true;
        }
        outputLinks.Add(linkNode);
        linkNode.parentChoose = this;
        linkNode.parentPhrase = parentNode;
        linkNode.id           = DialogEditor.editor.id;
        DialogEditor.editor.id++;
        DialogEditor.editor.links.Add(linkNode);
        return(linkNode);
    }
Beispiel #2
0
        public IRenderService DrawDialogLink(string SpriteFontKey, DialogLink Link, Vector2 Position, int MaxDisplayWidth, int MaxLength = -1, float Opacity = 1f)
        {
            if (Link == null || MaxLength == 0)
            {
                return(this);
            }
            SpriteFont font          = GameService.GetService <IContentService>().GetxAsset <SpriteFont>(SpriteFontKey);
            float      offsetX       = 0;
            float      offsetY       = 0;
            int        lengthCounter = 0;

            foreach (DialogSegment segment in Link.Segments)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < segment.Text.Length; i++)
                {
                    lengthCounter++;
                    char c = segment.Text[i];
                    sb.Append(c);
                    Vector2 size = font.MeasureString(sb);
                    if (size.X <= (MaxDisplayWidth - offsetX) || c == ' ')
                    {
                        if (i == (segment.Text.Length - 1) || lengthCounter == MaxLength)
                        {
                            DrawString(SpriteFontKey, sb.ToString(), new Vector2(Position.X + offsetX, Position.Y + offsetY), segment.GetRealColor() * Opacity);
                            offsetX += size.X;
                            if (lengthCounter == MaxLength)
                            {
                                return(this);
                            }
                        }
                        continue;
                    }
                    else
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }
                    while (sb[sb.Length - 1] != ' ')
                    {
                        i--;
                        lengthCounter--;
                        sb = sb.Remove(sb.Length - 1, 1);
                    }
                    DrawString(SpriteFontKey, sb.ToString(), new Vector2(Position.X + offsetX, Position.Y + offsetY), segment.GetRealColor() * Opacity);
                    offsetX  = 0;
                    offsetY += size.Y + 2;
                    i--;
                    lengthCounter--;
                    sb.Clear();
                }
            }
            return(this);
        }
Beispiel #3
0
        /// <summary>
        /// Open a NPC dialog box.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="e"></param>
        private void OpenDialog(IPlayerEntity player, NpcDialogOpenEventArgs e)
        {
            var npcEntity = player.Context.FindEntity <INpcEntity>(e.NpcObjectId);

            if (npcEntity == null)
            {
                Logger.Error("DialogSystem: Cannot find NPC with id: {0}", e.NpcObjectId);
                return;
            }

            if (!npcEntity.Data.HasDialog)
            {
                Logger.Error("DialogSystem: NPC '{0}' doesn't have a dialog.", npcEntity.Object.Name);
                return;
            }

            string dialogText = npcEntity.Data.Dialog.IntroText;

            if (!string.IsNullOrEmpty(e.DialogKey))
            {
                if (e.DialogKey == "BYE")
                {
                    WorldPacketFactory.SendChatTo(npcEntity, player, npcEntity.Data.Dialog.ByeText);
                    WorldPacketFactory.SendCloseDialog(player);
                    return;
                }
                else
                {
                    DialogLink dialogLink = npcEntity.Data.Dialog.Links?.FirstOrDefault(x => x.Id == e.DialogKey);

                    if (dialogLink == null)
                    {
                        Logger.Error("DialogSystem: Cannot find dialog key: '{0}' for NPC '{1}'", e.DialogKey, npcEntity.Object.Name);
                        return;
                    }

                    dialogText = dialogLink.Text;
                }
            }

            WorldPacketFactory.SendDialog(player, dialogText, npcEntity.Data.Dialog.Links);
        }
Beispiel #4
0
        /// <inheritdoc />
        public void OpenNpcDialog(IPlayerEntity player, uint npcObjectId, string dialogKey, int questId = 0)
        {
            var npc = player.FindEntity <INpcEntity>(npcObjectId);

            if (npc == null)
            {
                _logger.LogError($"Cannot find NPC with id: {npcObjectId}.");
                return;
            }

            _logger.LogTrace($"{npc.Object.Name}: '{dialogKey}'/{questId}");

            if (string.IsNullOrEmpty(dialogKey))
            {
                if (npc.Quests.Any())
                {
                    IEnumerable <IQuestScript> availableQuests = npc.Quests.Where(x => _questSystem.CanStartQuest(player, npc, x));

                    if (availableQuests.Count() == 1)
                    {
                        IQuestScript firstQuest = availableQuests.First();
                        var          questState = _questSystem.CanStartQuest(player, npc, firstQuest) ? QuestStateType.Suggest : QuestStateType.End;

                        _questSystem.ProcessQuest(player, npc, firstQuest, questState);
                        return;
                    }
                }

                IEnumerable <IQuestScript> questsToBeFinished = player.QuestDiary.ActiveQuests.Where(x => npc.Object.Name.Equals(x.Script.EndCharacter, StringComparison.OrdinalIgnoreCase)).Select(x => x.Script);

                if (questsToBeFinished.Any())
                {
                    _questSystem.ProcessQuest(player, npc, questsToBeFinished.First(), QuestStateType.End);
                    return;
                }

                if (!npc.NpcData.HasDialog)
                {
                    _logger.LogError($"NPC '{npc.Object.Name}' doesn't have a dialog.");
                    return;
                }

                SendNpcDialog(player, npc, npc.NpcData.Dialog.IntroText, npc.NpcData.Dialog.Links);
            }
            else
            {
                if (questId != 0)
                {
                    // Check if the quest exists for the current NPC
                    IQuestScript quest = npc.Quests.FirstOrDefault(x => x.Id == questId);

                    if (quest == null)
                    {
                        // If not, check if the npc is the end character of player's active quest
                        quest = player.QuestDiary.ActiveQuests.Where(x => x.QuestId == questId && npc.Object.Name.Equals(x.Script.EndCharacter, StringComparison.OrdinalIgnoreCase)).Select(x => x.Script).FirstOrDefault();

                        if (quest == null)
                        {
                            _logger.LogError($"Cannot find quest with id '{questId}' at npc '{npc}' for player '{player}'.");
                            return;
                        }
                    }

                    _questSystem.ProcessQuest(player, npc, quest, dialogKey.ToEnum <QuestStateType>());
                }
                else
                {
                    if (!npc.NpcData.HasDialog)
                    {
                        _logger.LogError($"NPC '{npc.Object.Name}' doesn't have a dialog.");
                        return;
                    }

                    if (dialogKey == DialogConstants.Bye)
                    {
                        _chatPacketFactory.SendChatTo(npc, player, npc.NpcData.Dialog.ByeText);
                        _npcDialogPacketFactory.SendCloseDialog(player);
                        return;
                    }
                    else
                    {
                        DialogLink dialogLink = npc.NpcData.Dialog.Links?.FirstOrDefault(x => x.Id == dialogKey);

                        if (dialogLink == null)
                        {
                            _logger.LogError($"Cannot find dialog key: '{dialogKey}' for NPC '{npc.Object.Name}'.");
                            return;
                        }

                        SendNpcDialog(player, npc, dialogLink.Texts, npc.NpcData.Dialog.Links);
                    }
                }
            }
        }