public void TestConstructor() { EffectExpression expression = new EffectExpression(); Target target = new Target(expression, TargetType.Enemy, Where.Unspecified); Assert.That(target.TargetType, Is.EqualTo(TargetType.Enemy)); Assert.That(target.Expression, Is.SameAs(expression)); Assert.That(target.Where, Is.EqualTo(Where.Unspecified)); }
/// <summary> /// Create a new <see cref="EffectComponent"/>. /// </summary> /// <param name="target"> /// The <see cref="Target"/> this effect component acts on. This /// cannot be null. /// </param> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> protected EffectComponent(Target target) { if (target == null) { throw new ArgumentNullException("target"); } this.Expression = target.Expression; this.Target = target; }
public void TestConstructor() { EffectExpression expression = new EffectExpression(); Dice dice = 1.D20(); Target target = new Target(expression, TargetType.Ally, Where.WithinSquares(5, Of.Target)); DiceDamageEffect effect = new DiceDamageEffect(target, dice); Assert.That(effect.Expression, Is.SameAs(expression)); Assert.That(effect.Target, Is.SameAs(target)); Assert.That(effect.Dice, Is.SameAs(dice)); }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="firstTarget"></param> /// <param name="addSpan"></param> /// <returns></returns> private void ParseTarget(Target target, bool firstTarget, Action<EffectSpan> addSpan) { if (target == null) { throw new ArgumentNullException("target"); } if (addSpan == null) { throw new ArgumentNullException("addSpan"); } switch (target.TargetType) { case TargetType.Ally: addSpan(new EffectSpan(string.Format( "one ally within {0} squares of {1}", target.Where.Squares, target.Where.Of == Of.Target ? "the target" : "you"))); break; case TargetType.Creature: if (target.Where == Where.Unspecified) { addSpan(new EffectSpan("one creature")); } else { addSpan(new EffectSpan(string.Format("one creature within {0} squares of {1}", target.Where.Squares, OfHelper.ToString(target.Where.Of)))); } break; case TargetType.Enemy: addSpan(new EffectSpan("one enemy")); break; case TargetType.TheTarget: if (firstTarget) { addSpan(new EffectSpan("the target")); } // else do nothing break; case TargetType.You: addSpan(new EffectSpan("you")); break; case TargetType.YouOrAlly: addSpan(new EffectSpan(string.Format( "you or one ally within {0} squares of {1}", target.Where.Squares, target.Where.Of == Of.Target ? "the target" : "you"))); break; default: throw new ArgumentException( string.Format("Unknown or missing target '{0}'", target.TargetType), "target"); } }