Пример #1
0
 public void HaveAStack()
 {
     AddFunction("$F", "-$1").Should().BeEmpty();
     AddFunction("$G", "$F -$1").Should().BeEmpty();
     _statService.Add("A", "$G 1 + $G 2").Should().BeEmpty();
     _statService.GetValue("A").Should().Be(3);
 }
        public void ANIMA_DICE_WHOOOOOO()
        {
            var rand = A.Fake <Random>();

            A.CallTo(rand)
            .WithReturnType <int>()
            .ReturnsNextFromSequence(
                50,                  // simple roll
                1, 100,              // critical failure
                95, 96, 95           // two critical success
                );

            var functionService = new FunctionService(rand);
            var statService     = new StatService(functionService);

            new Parser().Parse(out var expression,
                               @"
(
$IF{			$1 >= 95 + $2, 
					$1 + $D{1, 100, $ANIMA_DICE{$1, $IF {$2 = 5, 5, $2 + 1}}},
				$1 < 5,
					$1 - $D{1, 100},

					$1
			 }
)
",
                               new ParsingContext(statService, functionService)
            {
                FunctionId = new FunctionId("$ANIMA_DICE")
            }
                               ).Should().BeEmpty();
            functionService.Add(new UserFunction(new FunctionId("$ANIMA_DICE"), expression !));

            statService.Add("ROLL", "$D {1, 100, $ANIMA_DICE{$1, 0}}").Should().BeEmpty();

            statService.GetValue("ROLL").Should().Be(50);
            statService.GetValue("ROLL").Should().Be(-99);
            statService.GetValue("ROLL").Should().Be(286);
        }
        public void ParseDiceWithReroll()
        {
            var rand = A.Fake <Random>();

            A.CallTo(rand)
            .WithReturnType <int>()
            .ReturnsNextFromSequence(100, 17);

            var functionService = new FunctionService(rand);
            var statService     = new StatService(functionService);

            new Parser().Parse(out var expression,
                               @"$D{ 1, 100, $IF{ $1 >= 50, $F{ 0, $1 + $2 }, $1 + $2}",                             //reroll while rolling 50+
                               new ParsingContext(_statService, functionService)
            {
                FunctionId = new FunctionId("$F")
            }
                               ).Should().BeEmpty();

            functionService.Add(new UserFunction(new FunctionId("$F"), expression !)).Should().BeEmpty();
            statService.Add("A", "$F{ 0, 0 }").Should().BeEmpty();
            statService.GetValue("A").Should().Be(117);
        }
 public void AddShortVariable()
 {
     _statService.Add("FOR", ".base").Should().BeEmpty();
     _statService.GetValue("FOR.base").Should().Be(0);
 }
Пример #5
0
 public void ImportIntStat()
 {
     _book.Populate(@"FOR: 2").Should().BeEmpty();
     _statService.GetValue("FOR").Should().Be(2);
 }
Пример #6
0
 public override double GetValue() => _statService.GetValue(Id);