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); }
private IEnumerable <string> AddOrUpdateStat(Node node, ParsingContext context, string sectionId, bool isUpdate) { var errors = ParseStat(node, context, sectionId, out var stat); if (!errors.Any()) { if (isUpdate) { errors = errors.Concat(_statService.AddOrUpdate(stat).FormatErrors(node)); } else { errors = errors.Concat(_statService.Add(stat).FormatErrors(node)); } } if (!errors.Any()) { if (!isUpdate || !_sections[sectionId].Stats.Contains(stat)) { _sections[sectionId].Stats.Add(stat !); } else { _sections[sectionId].Stats[_sections[sectionId].Stats.IndexOf(stat)] = stat !; } } return(errors); }
private void Home_Load(object sender, EventArgs e) { var typeList = MyEnumHelper.GetEnumList <TypeEnum>(); cbType.DataSource = typeList; cbType.DisplayMember = "Name"; cbType.ValueMember = "Id"; cbType.SelectedIndex = 0; statService.Add(); Bind(); }
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 AddEmpty() { _statService.Add("FOR").Should().BeEmpty(); }