added modal reroll
This commit is contained in:
@@ -278,6 +278,25 @@ struct Dice {
|
||||
self.add(pool: rerolls)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func rerollBelow(cutoff: Int) {
|
||||
var count = 0
|
||||
for faceValue in 1..<cutoff {
|
||||
guard let face = DiceType(rawValue: faceValue) else { continue }
|
||||
count += value(which: face)
|
||||
switch face {
|
||||
case .one: one = 0
|
||||
case .two: two = 0
|
||||
case .three: three = 0
|
||||
case .four: four = 0
|
||||
case .five: five = 0
|
||||
case .six: six = 0
|
||||
}
|
||||
}
|
||||
var rerolls = Dice()
|
||||
rerolls.roll(howMany: count)
|
||||
add(pool: rerolls)
|
||||
}
|
||||
|
||||
mutating func blowup(dice: DiceType) {
|
||||
var rolls = Dice()
|
||||
@@ -291,4 +310,3 @@ struct Dice {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user