update view, still work to do
This commit is contained in:
@@ -151,6 +151,11 @@ class Roll: ObservableObject {
|
||||
@Published var woundHasRerolled = false
|
||||
@Published var saveHasRerolled = false
|
||||
|
||||
// Snapshot of dice before the current phase's reroll was applied.
|
||||
// Restored when the user switches reroll modes, so the new mode
|
||||
// always applies to the original un-rerolled results.
|
||||
@Published var preRerollDice: Dice? = nil
|
||||
|
||||
@Published var blowupUsed = false
|
||||
@Published var torrent = false
|
||||
@Published var psychic = false
|
||||
@@ -209,17 +214,7 @@ class Roll: ObservableObject {
|
||||
case .hit:
|
||||
return hitCutoff
|
||||
case .wound:
|
||||
if Float(self.strength) / Float(self.toughness) >= 2.0 {
|
||||
return .two
|
||||
} else if Float(self.strength) / Float(self.toughness) > 1.0 {
|
||||
return .three
|
||||
} else if Float(self.strength) / Float(self.toughness) == 1 {
|
||||
return .four
|
||||
} else if Float(self.strength) / Float(self.toughness) <= 0.5 {
|
||||
return .six
|
||||
} else {
|
||||
return .five
|
||||
}
|
||||
return Dice.DiceType(rawValue: woundCutoff) ?? .four
|
||||
case .armour:
|
||||
return Dice.DiceType(rawValue: self.armourSave) ?? .one
|
||||
}
|
||||
@@ -376,6 +371,7 @@ class Roll: ObservableObject {
|
||||
self.total = max(0, hit - autoWoundsCarried) + sustained
|
||||
self.state = .wound
|
||||
woundHasRerolled = false
|
||||
preRerollDice = nil
|
||||
case .wound:
|
||||
let mortals = critWoundCount
|
||||
mortalWoundsTotal = mortals
|
||||
@@ -383,10 +379,12 @@ class Roll: ObservableObject {
|
||||
autoWoundsCarried = 0
|
||||
self.state = .armour
|
||||
saveHasRerolled = false
|
||||
preRerollDice = nil
|
||||
case .armour:
|
||||
self.total = save
|
||||
self.state = .hit
|
||||
hitHasRerolled = false
|
||||
preRerollDice = nil
|
||||
blowupUsed = false
|
||||
mortalWoundsTotal = 0
|
||||
}
|
||||
@@ -397,6 +395,7 @@ class Roll: ObservableObject {
|
||||
func resetPool() {
|
||||
dice.roll(howMany: total)
|
||||
hitHasRerolled = false
|
||||
preRerollDice = nil
|
||||
blowupUsed = false
|
||||
}
|
||||
|
||||
@@ -414,8 +413,6 @@ class Roll: ObservableObject {
|
||||
}
|
||||
|
||||
func applyReroll() {
|
||||
guard !currentHasRerolled else { return }
|
||||
|
||||
let mode: RerollMode
|
||||
let cutoff: Int
|
||||
|
||||
@@ -431,9 +428,19 @@ class Roll: ObservableObject {
|
||||
cutoff = invulnerable ? armourSave : (armourSave + armourPenetration)
|
||||
}
|
||||
|
||||
guard mode != .none else { return }
|
||||
|
||||
// If a reroll was already applied this phase, restore the original dice first
|
||||
// so the new mode always operates on the un-rerolled results.
|
||||
if let snapshot = preRerollDice {
|
||||
dice = snapshot
|
||||
} else {
|
||||
preRerollDice = dice
|
||||
}
|
||||
|
||||
switch mode {
|
||||
case .none:
|
||||
return
|
||||
break
|
||||
case .ones:
|
||||
dice.reroll(dice: .one)
|
||||
case .failed:
|
||||
@@ -449,6 +456,18 @@ class Roll: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
// Restores dice to pre-reroll state when the user selects None.
|
||||
func undoReroll() {
|
||||
guard let snapshot = preRerollDice else { return }
|
||||
dice = snapshot
|
||||
preRerollDice = nil
|
||||
switch state {
|
||||
case .hit: hitHasRerolled = false
|
||||
case .wound: woundHasRerolled = false
|
||||
case .armour: saveHasRerolled = false
|
||||
}
|
||||
}
|
||||
|
||||
func add(howMuch: Int) {
|
||||
var newTotal: Int = 0
|
||||
newTotal = self.total + howMuch
|
||||
|
||||
Reference in New Issue
Block a user