added modal reroll

This commit is contained in:
Rory Hinnen
2026-09-07 10:07:07 -05:00
parent 17f2b0a288
commit a4d1634df7
5 changed files with 153 additions and 18 deletions
+81
View File
@@ -78,6 +78,19 @@ enum Appearance: Int, CaseIterable, Identifiable {
}
}
enum RerollMode: Int, CaseIterable {
case none, ones, failed, all
var label: String {
switch self {
case .none: return "None"
case .ones: return "1s"
case .failed: return "Failed"
case .all: return "All"
}
}
}
// MARK: Structs
struct Event: Identifiable {
let id: UUID
@@ -129,6 +142,14 @@ class Roll: ObservableObject {
@Published var invulnerable = false
@Published var currentPage: String
@Published var hitRerollMode = RerollMode.none
@Published var woundRerollMode = RerollMode.none
@Published var saveRerollMode = RerollMode.none
@Published var hitHasRerolled = false
@Published var woundHasRerolled = false
@Published var saveHasRerolled = false
// calculated variables
var totalDigits: [Int] {
@@ -208,6 +229,22 @@ class Roll: ObservableObject {
return self.dice.armour(die: total, invulnerable: self.invulnerable, save: self.armourSave, armourPenetration: self.armourPenetration)
}
}
var currentRerollMode: RerollMode {
switch state {
case .hit: return hitRerollMode
case .wound: return woundRerollMode
case .armour: return saveRerollMode
}
}
var currentHasRerolled: Bool {
switch state {
case .hit: return hitHasRerolled
case .wound: return woundHasRerolled
case .armour: return saveHasRerolled
}
}
// init
init() {
@@ -295,17 +332,61 @@ class Roll: ObservableObject {
case .hit:
self.total = hit
self.state = .wound
woundHasRerolled = false
case .wound:
self.total = wound
self.state = .armour
saveHasRerolled = false
case .armour:
self.total = save
self.state = .hit
hitHasRerolled = false
}
self.dice.roll(howMany: self.total)
}
// MARK: extra
func resetPool() {
dice.roll(howMany: total)
hitHasRerolled = false
}
func applyReroll() {
guard !currentHasRerolled else { return }
let mode: RerollMode
let cutoff: Int
switch state {
case .hit:
mode = hitRerollMode
cutoff = hitCutoff.rawValue
case .wound:
mode = woundRerollMode
cutoff = woundCutoff
case .armour:
mode = saveRerollMode
cutoff = invulnerable ? armourSave : (armourSave - armourPenetration)
}
switch mode {
case .none:
return
case .ones:
dice.reroll(dice: .one)
case .failed:
dice.rerollBelow(cutoff: cutoff)
case .all:
dice.roll(howMany: total)
}
switch state {
case .hit: hitHasRerolled = true
case .wound: woundHasRerolled = true
case .armour: saveHasRerolled = true
}
}
func add(howMuch: Int) {
var newTotal: Int = 0
newTotal = self.total + howMuch