示例#1
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);
        }