public void HandlesDieTermWithChooseAndScalar() { const string expression = "2 + 3*4d6k3"; DiceExpression diceExpression = _diceParser.Parse(expression); Assert.AreEqual(expression, diceExpression.ToString()); }
Dictionary <string, int> get_damage_expression_breakdown() { Dictionary <string, int> breakdown = new Dictionary <string, int>(); foreach (CreaturePower power in fPowers) { DiceExpression exp = DiceExpression.Parse(power.Damage); if (exp == null) { continue; } if (exp.Maximum == 0) { continue; } string dmg = exp.ToString(); if (!breakdown.ContainsKey(dmg)) { breakdown[dmg] = 0; } breakdown[dmg] += 1; } return(breakdown); }
public void Parse_NegativeScaler_ExpectedExpression() { const string expression = "2 + -2*1d6"; DiceExpression diceExpression = _diceParser.Parse(expression); Assert.AreEqual(expression, diceExpression.ToString()); }
public void Parse_DiceTermWithChooseAndScalar_ExpectedExpression() { const string expression = "2 + 3*4d6k3"; DiceExpression diceExpression = _diceParser.Parse(expression); Assert.AreEqual(expression, diceExpression.ToString()); }
public void ToString_ExpressionBuiltFluently_ReturnsTermsSeparatedByPlus() { DiceExpression diceExpression = new DiceExpression().Constant( 10 ).Die( 8, -1 ); string toString = diceExpression.ToString(); Assert.AreEqual( "10 + -1*1d8", toString ); }
public void HandlesNegativeScalar() { const string expression = "2 + -2*1d6"; DiceExpression diceExpression = _diceParser.Parse(expression); Assert.AreEqual(expression, diceExpression.ToString()); }
public void ToStringReturnsTermsSeparatedByPlus() { DiceExpression diceExpression = new DiceExpression().Constant(10).Die(8, -1); string toString = diceExpression.ToString(); Assert.AreEqual("10 + -1*1d8", toString); }
public void Parse_DiceTermWithImplicitMultiplicityOfOne_ExpectedExpression() { const string expression = "2 + 2*d6"; const string expectedExpression = "2 + 2*1d6"; DiceExpression diceExpression = _diceParser.Parse(expression); Assert.AreEqual(expectedExpression, diceExpression.ToString()); }
public void HandlesDieWithImplicitMultiplicityOf1() { const string expression = "2 + 2*d6"; const string expectedExpression = "2 + 2*1d6"; DiceExpression diceExpression = _diceParser.Parse(expression); Assert.AreEqual(expectedExpression, diceExpression.ToString()); }
private Dictionary <string, int> get_damage_expression_breakdown() { Dictionary <string, int> strs = new Dictionary <string, int>(); foreach (CreaturePower fPower in this.fPowers) { DiceExpression diceExpression = DiceExpression.Parse(fPower.Damage); if (diceExpression == null || diceExpression.Maximum == 0) { continue; } string str = diceExpression.ToString(); if (!strs.ContainsKey(str)) { strs[str] = 0; } Dictionary <string, int> item = strs; Dictionary <string, int> strs1 = item; string str1 = str; item[str1] = strs1[str1] + 1; } return(strs); }
public void Parse_DiceTermPlusConstant_ExpectedExpression() { DiceExpression diceExpression = _diceParser.Parse("3d6+5"); Assert.AreEqual("3d6 + 5", diceExpression.ToString()); }
public void Parse_OneDiceTerm_ExpectedExpression() { DiceExpression diceExpression = _diceParser.Parse("3d6"); Assert.AreEqual("3d6", diceExpression.ToString()); }
/// <summary> /// Adjusts the trap's level and attack data. /// </summary> /// <param name="delta">The level adjustment delta.</param> public void AdjustLevel(int delta) { fLevel += delta; fLevel = Math.Max(1, fLevel); if (fInitiative != int.MinValue) { Initiative += delta; fInitiative = Math.Max(1, fInitiative); } foreach (TrapAttack ta in fAttacks) { if (ta.Attack != null) { ta.Attack.Bonus += delta; ta.Attack.Bonus = Math.Max(1, ta.Attack.Bonus); } string hit_dmg = AI.ExtractDamage(ta.OnHit); if (hit_dmg != "") { DiceExpression exp = DiceExpression.Parse(hit_dmg); if (exp != null) { DiceExpression exp_adj = exp.Adjust(delta); if ((exp_adj != null) && (exp.ToString() != exp_adj.ToString())) { ta.OnHit = ta.OnHit.Replace(hit_dmg, exp_adj + " damage"); } } } string miss_dmg = AI.ExtractDamage(ta.OnMiss); if (miss_dmg != "") { DiceExpression exp = DiceExpression.Parse(miss_dmg); if (exp != null) { DiceExpression exp_adj = exp.Adjust(delta); if ((exp_adj != null) && (exp.ToString() != exp_adj.ToString())) { ta.OnMiss = ta.OnMiss.Replace(miss_dmg, exp_adj + " damage"); } } } string effect_dmg = AI.ExtractDamage(ta.Effect); if (effect_dmg != "") { DiceExpression exp = DiceExpression.Parse(effect_dmg); if (exp != null) { DiceExpression exp_adj = exp.Adjust(delta); if ((exp_adj != null) && (exp.ToString() != exp_adj.ToString())) { ta.Effect = ta.Effect.Replace(effect_dmg, exp_adj + " damage"); } } } } foreach (TrapSkillData tsd in fSkills) { tsd.DC += delta; } }
public void HandlesDieTermPlusConstant() { DiceExpression diceExpression = _diceParser.Parse("3d6+5"); Assert.AreEqual("3d6 + 5", diceExpression.ToString()); }
public void HandlesOneDieTerm() { DiceExpression diceExpression = _diceParser.Parse("3d6"); Assert.AreEqual("3d6", diceExpression.ToString()); }
public void AdjustLevel(int delta) { this.fLevel += delta; this.fLevel = Math.Max(1, this.fLevel); if (this.fInitiative != -2147483648) { Trap initiative = this; initiative.Initiative = initiative.Initiative + delta; this.fInitiative = Math.Max(1, this.fInitiative); } foreach (TrapAttack fAttack in this.fAttacks) { if (fAttack.Attack != null) { PowerAttack attack = fAttack.Attack; attack.Bonus = attack.Bonus + delta; fAttack.Attack.Bonus = Math.Max(1, fAttack.Attack.Bonus); } string str = AI.ExtractDamage(fAttack.OnHit); if (str != "") { DiceExpression diceExpression = DiceExpression.Parse(str); if (diceExpression != null) { DiceExpression diceExpression1 = diceExpression.Adjust(delta); if (diceExpression1 != null && diceExpression.ToString() != diceExpression1.ToString()) { fAttack.OnHit = fAttack.OnHit.Replace(str, string.Concat(diceExpression1, " damage")); } } } string str1 = AI.ExtractDamage(fAttack.OnMiss); if (str1 != "") { DiceExpression diceExpression2 = DiceExpression.Parse(str1); if (diceExpression2 != null) { DiceExpression diceExpression3 = diceExpression2.Adjust(delta); if (diceExpression3 != null && diceExpression2.ToString() != diceExpression3.ToString()) { fAttack.OnMiss = fAttack.OnMiss.Replace(str1, string.Concat(diceExpression3, " damage")); } } } string str2 = AI.ExtractDamage(fAttack.Effect); if (str2 == "") { continue; } DiceExpression diceExpression4 = DiceExpression.Parse(str2); if (diceExpression4 == null) { continue; } DiceExpression diceExpression5 = diceExpression4.Adjust(delta); if (diceExpression5 == null || !(diceExpression4.ToString() != diceExpression5.ToString())) { continue; } fAttack.Effect = fAttack.Effect.Replace(str2, string.Concat(diceExpression5, " damage")); } foreach (TrapSkillData fSkill in this.fSkills) { TrapSkillData dC = fSkill; dC.DC = dC.DC + delta; } }
/// <summary> /// Converts <see cref="DiceExpression"/> to <see cref="DiceExpressionSerialized"/>. /// </summary> /// <param name="expression"/> /// <returns/> public static DiceExpressionSerialized FromDiceExpression(DiceExpression expression) => new DiceExpressionSerialized { Expression = expression.ToString() };