Ejemplo n.º 1
0
        public override IEnumerator <RumorYield> Exec(Engine.Rumor rumor)
        {
            var value = Evaluate(rumor);

            if (value != null &&
                (value.IsBool() && value.AsBool() ||
                 value.IsFloat() && value.AsFloat() != 0 ||
                 value.IsInt() && value.AsInt() != 0 ||
                 value.IsString() && value.AsString() != "" ||
                 value.IsObject() && value.AsObject() != null))
            {
                rumor.EnterBlock(Children);
            }
            else
            {
                if (elif != null)
                {
                    var yield = elif.Exec(rumor);
                    while (yield.MoveNext())
                    {
                        yield return(yield.Current);
                    }
                }
            }

            yield return(null);
        }
Ejemplo n.º 2
0
        public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
        {
            int   number   = EvaluateNumber(rumor);
            float time     = EvaluateTime(rumor);
            int   @default = EvaluateDefault(rumor);

            yield return(new ForChoice(number, time, @default));

            rumor.State.ClearChoices();
        }
Ejemplo n.º 3
0
        public string EvaluateText(Engine.Rumor rumor)
        {
            if (text == null)
            {
                return("");
            }
            var value = text.Evaluate(rumor) ?? new ObjectValue(null);

            return((value.AsObject() ?? "").ToString());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Evaluates the speaker of this node in the specified Rumor.
        /// </summary>
        /// <param name="rumor">The Rumor to evaluate against.</param>
        /// <returns>The speaker.</returns>
        public object EvaluateSpeaker(Engine.Rumor rumor)
        {
            if (speaker == null)
            {
                return(rumor.Scope.DefaultSpeaker);
            }
            var ret = speaker.Evaluate(rumor) ?? new ObjectValue(null);

            return(ret.AsObject() ?? rumor.Scope.DefaultSpeaker);
        }
Ejemplo n.º 5
0
        public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
        {
            var speaker = EvaluateSpeaker(rumor);
            var text    = EvaluateText(rumor);

            rumor.State.SetDialog(speaker, text);

            if (!noWait)
            {
                yield return(new ForAdvance());
            }
        }
Ejemplo n.º 6
0
        public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
        {
            var value = seconds.Evaluate(rumor) ?? new ObjectValue(null);

            if (value.AsFloat() > 0)
            {
                yield return(new ForSeconds(value.AsFloat(), cantSkip));
            }
            else
            {
                yield return(new ForAdvance());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Starts or resumes execution of the stack frame. Note that this
        /// does not actually run the stack frame, but instead returns an
        /// IEnumerator that can be used to wait on the completion of a yield
        /// that was returned by a node.
        ///
        /// After the stack frame has been exhausted, calling this method
        /// again will return immediately.
        /// </returns>
        /// <param name="rumor">The rumor that owns this stack frame.</param>
        /// <returns>
        /// Returns a IEnumerator that can be used to run the current yield.
        /// The IEnumerator will return true for MoveNext until the yield has
        /// terminated.
        /// </returns>
        internal IEnumerator <RumorYield> Run(Engine.Rumor rumor)
        {
            if (index < nodes.Count)
            {
                var yield = nodes[index].Run(rumor);

                if (OnNextNode != null)
                {
                    OnNextNode(nodes[index]);
                }

                ++index;
                while (yield.MoveNext())
                {
                    yield return(yield.Current);
                }
            }
        }
Ejemplo n.º 8
0
        public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
        {
            switch (type)
            {
            case ClearType.ALL:
                rumor.State.Clear();
                break;

            case ClearType.CHOICES:
                rumor.State.ClearChoices();
                break;

            case ClearType.DIALOG:
                rumor.State.ClearDialog();
                break;
            }
            yield return(null);
        }
Ejemplo n.º 9
0
        public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
        {
            var    dialog  = rumor.State.Dialog;
            var    speaker = EvaluateSpeaker(rumor);
            string text    = EvaluateText(rumor);

            if (string.IsNullOrEmpty(dialog[speaker]) ||
                dialog[speaker].EndsWith(" ") ||
                dialog[speaker].EndsWith("\t") ||
                dialog[speaker].EndsWith("\n"))
            {
                rumor.State.AddDialog(speaker, text);
            }
            else if (!string.IsNullOrEmpty(text))
            {
                rumor.State.AddDialog(speaker, " " + text);
            }
            yield return(new ForAdvance());
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Runs the current conditional.
 /// </summary>
 /// <returns>
 /// A IEnumerator that can be used to continue execution of the
 /// conditional.
 /// </returns>
 public abstract IEnumerator <RumorYield> Exec(Engine.Rumor rumor);
Ejemplo n.º 11
0
 /// <summary>
 /// Returns the value of the expression evaluated against the scope in
 /// the passed Rumor.
 /// </summary>
 /// <param name="rumor">
 /// The rumor to evaluate the expression against.
 /// </param>
 /// <returns>The value of the expression.</returns>
 protected Value Evaluate(Engine.Rumor rumor)
 {
     return(expression.Evaluate(rumor));
 }
Ejemplo n.º 12
0
 public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
 {
     rumor.State.AddChoice(EvaluateText(rumor), this.Children);
     yield return(null);
 }
Ejemplo n.º 13
0
        public static void SmokeTest1()
        {
            string script =
                "Alice: Hello? Are you there?\n" +
                "Eve: Yes, yes, just... one moment.\n" +
                "add(4)\n" +
                ": The line briefly emits a sharp static. Then, silence.\n" +

                "choice [hangup]\n" +
                "  > Hang up.\n" +
                "  : Alice hangs up.\n" +

                "choice [wait]\n" +
                "  > Wait.\n" +
                "  waited = { true }\n" +
                "  : Alice waits\n" +

                "choose\n" +

                "if { waited }\n" +
                "  Eve: There we go. Sorry about that.\n" +
                "  Alice: No problem.\n" +
                "  add(4)\n";

            var nodes = new RumorCompiler()
                        .SetTabSize(2)
                        .LinkAction("add", ValueType.Number)
                        .Compile(script);

            double number = 0;
            var    rumor  = new Engine.Rumor(nodes);

            rumor.Bindings.Bind <double>("add", (x) => number += x);
            rumor.Start();

            Assert.AreEqual(
                new Dictionary <string, string>
            {
                { "Alice", "Hello? Are you there?" },
            },
                rumor.State.GetDialog()
                );

            rumor.Advance();

            Assert.AreEqual(
                new Dictionary <string, string>
            {
                { "Eve", "Yes, yes, just... one moment." },
            },
                rumor.State.GetDialog()
                );

            // Simulate saving and loading the game
            rumor = SerializationUtil.Reserialize(rumor);
            rumor.Bindings.Bind <double>("add", (x) => number += x);

            rumor.Advance();

            Assert.AreEqual(4, number);
            Assert.AreEqual(
                new Dictionary <string, string>
            {
                { "_narrator", "The line briefly emits a sharp static. Then, silence." },
            },
                rumor.State.GetDialog()
                );

            rumor.Advance();
            rumor.Choose("hangup");

            Assert.AreEqual(
                new Dictionary <string, string>
            {
                { "_narrator", "Alice hangs up." },
            },
                rumor.State.GetDialog()
                );

            rumor.Advance();
            Assert.IsFalse(rumor.Executing);
        }
Ejemplo n.º 14
0
 public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
 {
     rumor.JumpToLabel(to);
     yield return(null);
 }
Ejemplo n.º 15
0
 public int EvaluateDefault(Engine.Rumor rumor)
 {
     return((@default.Evaluate(rumor) ?? new IntValue(0)).AsInt(0));
 }
Ejemplo n.º 16
0
 public float EvaluateTime(Engine.Rumor rumor)
 {
     return((seconds.Evaluate(rumor) ?? new FloatValue(0)).AsFloat(0));
 }
Ejemplo n.º 17
0
 public int EvaluateNumber(Engine.Rumor rumor)
 {
     return((number.Evaluate(rumor) ?? new IntValue(1)).AsInt(1));
 }
Ejemplo n.º 18
0
 public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
 {
     return(conditional.Exec(rumor));
 }
Ejemplo n.º 19
0
 public override IEnumerator <RumorYield> Exec(Engine.Rumor rumor)
 {
     rumor.EnterBlock(Children);
     yield return(null);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Evaluates this expression.
 /// </summary>
 /// <param name="rumor">The rumor to evaluate with.</param>
 /// <returns>The result of this expression when evaluated.</returns>
 public Value Evaluate(Engine.Rumor rumor)
 {
     return(Evaluate(rumor.Scope, rumor.Bindings));
 }
Ejemplo n.º 21
0
 public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
 {
     rumor.ExitBlock();
     yield return(null);
 }
Ejemplo n.º 22
0
 public override IEnumerator <RumorYield> Run(Engine.Rumor rumor)
 {
     expression.Evaluate(rumor);
     yield return(null);
 }