/// <summary>
 /// Uses specified choice to activate redirection to new page.
 /// </summary>
 /// <param name="id">Choice number (zero-based) at choices list of current page.</param>
 public void MakeChoice(QuestChoice choice)
 {
     if (IsChoiceVisible(choice))
     {
         this.SetCurrentPage(choice.link);
     }
 }
        static void ParsePageChoices(QuestPage page, QuestStream stream)
        {
            var lineId = stream.pointer;

            while (true)
            {
                var line = stream.Next();
                if (line.Length == 0)
                {
                    break;
                }
                if (line[0] != '*')
                {
                    stream.Previous(); break;
                }
                var matching = Regex.Match(line, "\\*(.*?)->\\s*?(\\b.+)");
                if (!matching.Success)
                {
                    throw new Exception(string.Format("Invalid choice syntax at line: {0}", lineId));
                }
                lineId = stream.pointer;
                var choice = new QuestChoice();
                choice.link = matching.Groups[2].Value.ToLowerInvariant();
                var rawChoiceText = matching.Groups[1].Value;
                if (!string.IsNullOrEmpty(rawChoiceText))
                {
                    var matchingCond = Regex.Match(rawChoiceText, "\\{(.*?)\\}(.+)");
                    if (!matchingCond.Success)
                    {
                        choice.text = rawChoiceText.Trim();
                    }
                    else
                    {
                        choice.condition = ParseLogic(QuestLogicFilter.Expression, matchingCond.Groups[1].Value, lineId);
                        choice.text      = matchingCond.Groups[2].Value.Trim();
                    }
                }
                page.choices.Add(choice);
            }
            if (page.choices.Count == 0)
            {
                throw new Exception(string.Format("No choices at line: {0}", lineId));
            }
            if (page.choices.Count == 1 && page.choices[0].condition != null)
            {
                throw new Exception(string.Format("Auto choice cant use condition at line: {0}", lineId));
            }
        }
 /// <summary>
 /// Checks choice visibility with respect optional condition.
 /// </summary>
 /// <param name="choice">Choice to test.</param>
 public bool IsChoiceVisible(QuestChoice choice)
 {
     return(choice != null && (choice.condition == null || ProcessLogic(choice.condition)));
 }