/// <summary>
 /// </summary>
 /// <param name="node">
 /// </param>
 protected void SetRootNode(KnuBotDialogTree node)
 {
     node.ValidateTree();
     this.rootNode     = node;
     this.selectedNode = this.rootNode;
     this.rootNode.SetKnuBot(this);
 }
        public KnuBotItemGiver(Identity identity)
            : base(identity)
        {
            this.InitializeItemSets();

            KnuBotDialogTree rootNode = new KnuBotDialogTree(
                "0",
                this.Condition0,
                new[]
                {
                    this.CAS(this.DialogGM0, "self"), this.CAS(this.TransferToRKArmorSet, "RKArmorSet"),
                    this.CAS(this.TransferToSLArmorSet, "SLArmorSet"), this.CAS(this.GoodBye, "self")
                });
            this.SetRootNode(rootNode);

            KnuBotDialogTree lastNode =
                rootNode.AddNode(
                    new KnuBotDialogTree(
                        "RKArmorSet",
                        this.Condition01,
                        new[]
                        {
                            this.CAS(this.DialogShowRKArmorSets, "self"),
                            this.CAS(this.ChooseQlFromSet, "QLChoiceRKArmorSet"), this.CAS(this.BackToRoot, "root")
                        }));

            lastNode.AddNode(
                new KnuBotDialogTree(
                    "QLChoiceRKArmorSet",
                    this.QLCondition,
                    new[]
                    {
                        this.CAS(this.ShowQLs, "self"), this.CAS(this.GiveItemSet, "root"),
                        this.CAS(this.BackToRoot, "parent")
                    }));

            lastNode =
                rootNode.AddNode(
                    new KnuBotDialogTree(
                        "SLArmorSet",
                        this.ConditionSL,
                        new[]
                        {
                            this.CAS(this.DialogShowSLArmorSets, "self"),
                            this.CAS(this.ChooseQlFromSet, "QLChoiceSLArmorSet"), this.CAS(this.BackToRoot, "root")
                        }));

            lastNode.AddNode(
                new KnuBotDialogTree(
                    "QLChoiceSLArmorSet",
                    this.QLCondition,
                    new[]
                    {
                        this.CAS(this.ShowQLs, "self"), this.CAS(this.GiveItemSet, "root"),
                        this.CAS(this.BackToRoot, "parent")
                    }));
        }
        /// <summary>
        /// </summary>
        /// <param name="answer">
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        public void Answer(int answer)
        {
            KnuBotDialogTree oldNode = this.selectedNode;

            // Only do talk if window is still open
            if (answer != (int)KnuBotOptionId.WindowClosed)
            {
                string nextId = this.selectedNode.Execute((KnuBotOptionId)answer);
                LogUtil.Debug(
                    DebugInfoDetail.KnuBot,
                    string.Format(
                        "Received KnuBot Answer {0} for node {1} -> {2}",
                        answer,
                        this.selectedNode.id,
                        nextId));
                if (nextId == "parent")
                {
                    this.selectedNode = this.selectedNode.Parent;
                }
                else
                {
                    if (nextId == "root")
                    {
                        this.selectedNode = this.rootNode;
                    }
                    else
                    {
                        if (nextId != "self")
                        {
                            KnuBotDialogTree nextSelectedNode = this.selectedNode.GetNode(nextId);
                            if (nextSelectedNode == null)
                            {
                                throw new Exception(
                                          "Could not find dialog id '" + nextId + "' in tree '"
                                          + string.Join(Environment.NewLine, this.selectedNode.FlattenDialogIds()) + "'");
                            }

                            this.selectedNode = nextSelectedNode;
                        }
                    }
                }

                // Only start over if its not the same node or option
                if (this.Character.Target != null)
                {
                    if ((answer != (int)KnuBotOptionId.DialogStart) || (oldNode != this.selectedNode))
                    {
                        this.Answer(KnuBotOptionId.DialogStart);
                    }
                }
            }
            else
            {
                // Remove link to conversation partner
                this.Character = new WeakReference <ICharacter>(null);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="character">
        /// </param>
        /// <returns>
        /// </returns>
        public bool StartDialog(ICharacter character)
        {
            // Does the starting character exist?
            if (character is null)
            {
                return(false);
            }

            this.Character.SetTarget(character);
            this.selectedNode = this.rootNode;
            this.OpenWindow();
            this.Answer(KnuBotOptionId.DialogStart);
            LogUtil.Debug(DebugInfoDetail.KnuBot, string.Format("KnuBut Start Dialog"));

            return(true);
        }
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        /// <exception cref="Exception">
        /// </exception>
        private BaseKnuBot GetBaseKnuBot()
        {
            // Get down to root
            KnuBotDialogTree temp = this;

            while (temp.Parent != null)
            {
                temp = temp.Parent;
            }

            BaseKnuBot knu = this.knuBot;

            if (knu == null)
            {
                throw new Exception("Base KnuBot gone away.");
            }

            return(knu);
        }
        public KnuBotFlappy(Identity identity)
            : base(identity)
        {
            KnuBotDialogTree temp = new KnuBotDialogTree(
                "0",
                this.TreeCondition0,
                new[]
                {
                    // This is the main dialog (send text in here)
                    this.CAS(this.StartDialog, "self"),
                    // This will be called on the first option
                    this.CAS(this.Option0_1, "01"),
                    // this will be called on the second option
                    this.CAS(this.Option0_2, "02")
                });

            // SetRootNode needs to be done after building the first node, so AddNode can put in neccesary information in subsequent nodes
            this.SetRootNode(temp);

            temp.AddNode(
                new KnuBotDialogTree(
                    "01",
                    this.TreeCondition01,
                    new[]
                    {
                        // This is the main dialog (send text in here)
                        this.CAS(this.Dialog1, "self"),
                        // This will be called on the first option
                        this.CAS(this.Option01_1, "root"),
                        // this will be called on the second option
                        this.CAS(this.Option01_2, "self")
                    }));
            temp.AddNode(
                new KnuBotDialogTree(
                    "02",
                    this.TreeCondition02,
                    new[]
                    {
                        // This sends only back to the root node
                        this.CAS(this.Dialog02, "root")
                    }));
        }
        /// <summary>
        /// </summary>
        /// <param name="dialogTree">
        /// </param>
        /// <returns>
        /// </returns>
        public KnuBotDialogTree AddNode(KnuBotDialogTree dialogTree)
        {
            this.nodes.Add(dialogTree);
            dialogTree.Parent = this;
            dialogTree.SetKnuBot(this.GetBaseKnuBot());

            // Get down to root node
            KnuBotDialogTree temp = this;

            while (temp.Parent != null)
            {
                temp = temp.Parent;
            }

            // And lets validate the whole tree again
            // Better to do this on add, so we see from the stacktrace where it really happened
            temp.ValidateTree();

            return(dialogTree);
        }
        /// <summary>
        /// </summary>
        /// <param name="character">
        /// </param>
        /// <returns>
        /// </returns>
        public bool StartDialog(ICharacter character)
        {
            bool result = false;

            // Does the starting character exist?
            if (character != null)
            {
                // if (this.GetCharacter() == null)
                {
                    // OK, no one is talking, lets initialize
                    result = true;
                    this.Character.Target = character;
                    this.selectedNode     = this.rootNode;
                    this.OpenWindow();
                    this.Answer(KnuBotOptionId.DialogStart);
                    LogUtil.Debug(DebugInfoDetail.KnuBot, string.Format("KnuBut Start Dialog"));
                }
            }

            return(result);
        }
 /// <summary>
 /// </summary>
 /// <param name="knubotIdentity">
 /// </param>
 /// <param name="root">
 /// </param>
 protected BaseKnuBot(Identity knubotIdentity, KnuBotDialogTree root)
     : this(knubotIdentity)
 {
     this.SetRootNode(root);
 }
 /// <summary>
 /// </summary>
 /// <param name="knubotIdentity">
 /// </param>
 /// <param name="root">
 /// </param>
 protected BaseKnuBot(Identity knubotIdentity, KnuBotDialogTree root)
     : this(knubotIdentity)
 {
     this.SetRootNode(root);
 }
 /// <summary>
 /// </summary>
 /// <param name="node">
 /// </param>
 protected void SetRootNode(KnuBotDialogTree node)
 {
     node.ValidateTree();
     this.rootNode = node;
     this.selectedNode = this.rootNode;
     this.rootNode.SetKnuBot(this);
 }
        /// <summary>
        /// </summary>
        /// <param name="character">
        /// </param>
        /// <returns>
        /// </returns>
        public bool StartDialog(ICharacter character)
        {
            bool result = false;

            // Does the starting character exist?
            if (character != null)
            {
                // if (this.GetCharacter() == null)
                {
                    // OK, no one is talking, lets initialize
                    result = true;
                    this.Character.Target = character;
                    this.selectedNode = this.rootNode;
                    this.OpenWindow();
                    this.Answer(KnuBotOptionId.DialogStart);
                    LogUtil.Debug(DebugInfoDetail.KnuBot, string.Format("KnuBut Start Dialog"));
                }
            }

            return result;
        }
        /// <summary>
        /// </summary>
        /// <param name="answer">
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        public void Answer(int answer)
        {
            KnuBotDialogTree oldNode = this.selectedNode;
            // Only do talk if window is still open
            if (answer != (int)KnuBotOptionId.WindowClosed)
            {
                string nextId = this.selectedNode.Execute((KnuBotOptionId)answer);
                LogUtil.Debug(
                    DebugInfoDetail.KnuBot,
                    string.Format(
                        "Received KnuBot Answer {0} for node {1} -> {2}",
                        answer,
                        this.selectedNode.id,
                        nextId));
                if (nextId == "parent")
                {
                    this.selectedNode = this.selectedNode.Parent;
                }
                else
                {
                    if (nextId == "root")
                    {
                        this.selectedNode = this.rootNode;
                    }
                    else
                    {
                        if (nextId != "self")
                        {
                            KnuBotDialogTree nextSelectedNode = this.selectedNode.GetNode(nextId);
                            if (nextSelectedNode == null)
                            {
                                throw new Exception(
                                    "Could not find dialog id '" + nextId + "' in tree '"
                                    + string.Join(Environment.NewLine, this.selectedNode.FlattenDialogIds()) + "'");
                            }

                            this.selectedNode = nextSelectedNode;
                        }
                    }
                }

                // Only start over if its not the same node or option
                if (this.Character.Target != null)
                {
                    if ((answer != (int)KnuBotOptionId.DialogStart) || (oldNode != this.selectedNode))
                    {
                        this.Answer(KnuBotOptionId.DialogStart);
                    }
                }
            }
            else
            {
                // Remove link to conversation partner
                this.Character = new WeakReference<ICharacter>(null);
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="dialogTree">
        /// </param>
        /// <returns>
        /// </returns>
        public KnuBotDialogTree AddNode(KnuBotDialogTree dialogTree)
        {
            this.nodes.Add(dialogTree);
            dialogTree.Parent = this;
            dialogTree.SetKnuBot(this.GetBaseKnuBot());

            // Get down to root node
            KnuBotDialogTree temp = this;
            while (temp.Parent != null)
            {
                temp = temp.Parent;
            }

            // And lets validate the whole tree again
            // Better to do this on add, so we see from the stacktrace where it really happened
            temp.ValidateTree();

            return dialogTree;
        }
        public InfoBotKnu(Identity identity)
            : base(identity)
        {
            KnuBotDialogTree temp = new KnuBotDialogTree(
                "0",
                this.TreeCondition0,
                new[]
                {
                    // This is the main dialog
                    this.CAS(this.MainDialog, "self"),
                    // This will be called if the player asks for commands in the main dialog
                    this.CAS(this.ChatCommands, "self"),
                    // this will be called if the player selects goodbye in the main dialog
                    this.CAS(this.GoodBye, "self")
                });

            // SetRootNode needs to be done after building the first node, so AddNode can put in neccesary information in subsequent nodes
            this.SetRootNode(temp);
        }