[][src]Struct critfail::AttackOutcomeBuilder

pub struct AttackOutcomeBuilder { /* fields omitted */ }

This is used to create a 'fudged' AttackOutcome without actually randomly generating anything.

use critfail::AttackOutcomeBuilder;
// To create a result that could come from rolling 'r+4?3d10+1'
let outcome = AttackOutcomeBuilder::new()
    .check(5)
    .check_modifier(4)
    .damage_dice(3, vec![5, 8, 10])
    .damage_modifier(1)
    .build();

assert_eq!(outcome.check().score(), 9);
assert_eq!(outcome.damage().score(), 24);
assert_eq!(
    format!("{:?}", outcome),
    "(5)+4 ? [5+8+10]+1"
);

Implementations

impl AttackOutcomeBuilder[src]

pub fn new() -> Self[src]

Create a new AttackOutcomeBuilder.

pub fn check_adv(self, r1: Score, r2: Score) -> Self[src]

Set the check roll with advantage.

use critfail::AttackOutcomeBuilder;

// To create a result that could come from rolling 'a?2d8'
let outcome = AttackOutcomeBuilder::new()
    .check_adv(10, 12)
    .damage_dice(8, vec![4, 5])
    .build();

assert_eq!(outcome.check().score(), 12);
assert_eq!(
    format!("{:?}", outcome),
    "(12/10) ? [4+5]"
);

pub fn check_dis(self, r1: Score, r2: Score) -> Self[src]

Set the check roll with disadvantage.

use critfail::AttackOutcomeBuilder;


// To create a result that could come from rolling 'd?2d8'
let outcome = AttackOutcomeBuilder::new()
    .check_dis(10, 12)
    .damage_dice(8, vec![4, 5])
    .build();

assert_eq!(outcome.check().score(), 10);
assert_eq!(
    format!("{:?}", outcome),
    "(10/12) ? [4+5]"
);

pub fn check(self, r: Score) -> Self[src]

Set the check roll without advantage or disadvantage.

use critfail::AttackOutcomeBuilder;

// To create a result that could come from rolling 'r?2d8'
let outcome = AttackOutcomeBuilder::new()
    .check(8)
    .damage_dice(8, vec![4, 5])
    .build();

assert_eq!(outcome.check().score(), 8);
assert_eq!(
    format!("{:?}", outcome),
    "(8) ? [4+5]"
);

pub fn check_modifier(self, modifier: Score) -> Self[src]

Add a constant modifier to the check part of this attack roll. This method can be chained multiple times for multiple modifiers.

use critfail::AttackOutcomeBuilder;

// To create a result that could come from rolling 'r-2+6?2d8'
let outcome = AttackOutcomeBuilder::new()
    .check(10)
    .check_modifier(-2)
    .check_modifier(6)
    .damage_dice(8, vec![4, 5])
    .build();

assert_eq!(outcome.check().score(), 14);
assert_eq!(
    format!("{:?}", outcome),
    "(10)-2+6 ? [4+5]"
);

pub fn check_dice(self, sides: Sides, scores: Vec<Score>) -> Self[src]

Add a dice modifier to the check part of this attack roll. This method can be chained multiple times for multiple modifiers. sides specifies the die that was rolled.

use critfail::AttackOutcomeBuilder;

// To create a result that could come from rolling 'r-2d4+1d6?2d8'
let outcome = AttackOutcomeBuilder::new()
    .check(10)
    .check_dice(-4, vec![1, 2])
    .check_dice(6, vec![5])
    .damage_dice(8, vec![4, 5])
    .build();

assert_eq!(outcome.check().score(), 12);
assert_eq!(
    format!("{:?}", outcome),
    "(10)-[1+2]+[5] ? [4+5]"
);

pub fn damage_modifier(self, modifier: Score) -> Self[src]

Add a constant modifier to the damage part of this attack roll. This method can be chained multiple times for multiple modifiers.

use critfail::AttackOutcomeBuilder;

// To create a result that could come from rolling 'r?2d8+6-4'
let outcome = AttackOutcomeBuilder::new()
    .check(10)
    .damage_dice(8, vec![1,6])
    .damage_modifier(6)
    .damage_modifier(-4)
    .build();

assert_eq!(outcome.damage().score(), 9);
assert_eq!(
    format!("{:?}", outcome),
    "(10) ? [1+6]+6-4"
);

pub fn damage_dice(self, sides: Sides, scores: Vec<Score>) -> Self[src]

Add a dice modifier to the damage part of this attack roll. This method can be chained multiple times for multiple modifiers. sides specifies the die that was rolled.

use critfail::AttackOutcomeBuilder;

// To create a result that could come from rolling 'r?2d6+3d10-1d4'
let outcome = AttackOutcomeBuilder::new()
    .check(10)
    .damage_dice(6, vec![5, 1])
    .damage_dice(10, vec![4, 9, 2])
    .damage_dice(-4, vec![3])
    .build();

assert_eq!(outcome.damage().score(), 18);
assert_eq!(
    format!("{:?}", outcome),
    "(10) ? [5+1]+[4+9+2]-[3]"
);

pub fn build(self) -> AttackOutcome[src]

Create an AttackOutcome from this builder.

Trait Implementations

impl Default for AttackOutcomeBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,