Skip to content

Commit

Permalink
Ignore already-dropped dice when applying modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawdl3y committed Mar 2, 2024
1 parent b4177cc commit ed8343a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/dice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ impl Modifier {
let mut to_explode = rolled
.rolls
.iter()
.filter(|r| {
if let Some(cond) = cond {
cond.check(r.val)
} else {
r.val == rolled.dice.sides
}
.filter(|r| !r.is_dropped())
.filter(|r| match cond {
Some(cond) => cond.check(r.val),
None => r.val == rolled.dice.sides,
})
.count();

Expand All @@ -148,12 +146,9 @@ impl Modifier {
.then(|| {
explosions
.iter()
.filter(|r| {
if let Some(cond) = cond {
cond.check(r.val)
} else {
r.val == rolled.dice.sides
}
.filter(|r| match cond {
Some(cond) => cond.check(r.val),
None => r.val == rolled.dice.sides,
})
.count()
})
Expand All @@ -167,7 +162,7 @@ impl Modifier {
}

Self::KeepHigh(count) => {
let mut refs = rolled.rolls.iter_mut().collect::<Vec<_>>();
let mut refs = rolled.rolls.iter_mut().filter(|r| !r.is_dropped()).collect::<Vec<_>>();
refs.sort();
refs.reverse();
refs.iter_mut()
Expand All @@ -176,7 +171,7 @@ impl Modifier {
}

Self::KeepLow(count) => {
let mut refs = rolled.rolls.iter_mut().collect::<Vec<_>>();
let mut refs = rolled.rolls.iter_mut().filter(|r| !r.is_dropped()).collect::<Vec<_>>();
refs.sort();
refs.iter_mut()
.skip(count.get() as usize)
Expand Down

0 comments on commit ed8343a

Please sign in to comment.