Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handicap cards #95

Merged
merged 16 commits into from
Dec 26, 2024
4 changes: 4 additions & 0 deletions WildWestOnline/Core/Bang/Sources/Game/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public struct Card: Equatable, Codable, Sendable {
case healthZero
case gameOver
case currentTurn
case drawMatching(_ regex: String)
case drawNotMatching(_ regex: String)
}

/// Required event conditions to trigger a card
Expand All @@ -91,11 +93,13 @@ public struct Card: Equatable, Codable, Sendable {
case setTarget(TargetGroup)
case setCard(CardGroup)
case chooseOne(ChooseOneElement, resolved: ChooseOneResolved? = nil, selection: String? = nil)
case verify(StateReq)

public enum Number: Equatable, Codable, Sendable {
case value(Int)
case activePlayers
case excessHand
case drawCards
}

public enum TargetGroup: String, Codable, Sendable {
Expand Down
60 changes: 33 additions & 27 deletions WildWestOnline/Core/Bang/Sources/Game/GameAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public struct GameAction: Action, Equatable, Codable {
case discardInPlay
case stealHand
case stealInPlay
case passInPlay
case heal
case damage
case shoot
case counterShot
case endTurn
case startTurn
case eliminate
Expand All @@ -39,6 +41,7 @@ public struct GameAction: Action, Equatable, Codable {
case increaseRemoteness
case setHandLimit
case setPlayLimitPerTurn
case setDrawCards

@available(*, deprecated, message: "use .discardHand or .discardInPlay instead")
case discard
Expand Down Expand Up @@ -91,7 +94,6 @@ public struct GameAction: Action, Equatable, Codable {
}

public extension GameAction {
/// Move: play a card
static func play(_ card: String, player: String) -> Self {
.init(
kind: .play,
Expand All @@ -102,7 +104,6 @@ public extension GameAction {
)
}

/// Move: choose an option
static func choose(_ selection: String, player: String) -> Self {
.init(
kind: .choose,
Expand All @@ -113,15 +114,15 @@ public extension GameAction {
)
}

/// Draw top deck card and put to discard
static var draw: Self {
static func draw(player: String) -> Self {
.init(
kind: .draw,
payload: .init()
payload: .init(
target: player
)
)
}

/// Draw top deck card
static func drawDeck(player: String) -> Self {
.init(
kind: .drawDeck,
Expand All @@ -131,15 +132,13 @@ public extension GameAction {
)
}

/// Draw top discard
static func drawDiscard(player: String) -> Self {
.init(
kind: .drawDiscard,
payload: .init(target: player)
)
}

/// Draw discovered deck card
static func drawDiscovered(_ card: String, player: String) -> Self {
.init(
kind: .drawDiscovered,
Expand All @@ -150,15 +149,13 @@ public extension GameAction {
)
}

/// Discover top deck cards
static func discover(player: String) -> Self {
.init(
kind: .discover,
payload: .init(target: player)
)
}

/// Restore player's health, limited to maxHealth
static func heal(_ amount: Int, player: String) -> Self {
.init(
kind: .heal,
Expand All @@ -169,7 +166,6 @@ public extension GameAction {
)
}

/// Deals damage to a player, attempting to reduce its Health by the stated amount
static func damage(_ amount: Int, player: String) -> Self {
.init(
kind: .damage,
Expand All @@ -180,7 +176,6 @@ public extension GameAction {
)
}

/// Discard a player's hand card
static func discardHand(_ card: String, player: String) -> Self {
.init(
kind: .discardHand,
Expand All @@ -191,7 +186,6 @@ public extension GameAction {
)
}

/// Discard a player's inPlay card
static func discardInPlay(_ card: String, player: String) -> Self {
.init(
kind: .discardInPlay,
Expand All @@ -202,7 +196,6 @@ public extension GameAction {
)
}

/// Draw card from other player's hand
static func stealHand(_ card: String, target: String, player: String) -> Self {
.init(
kind: .stealHand,
Expand All @@ -214,7 +207,6 @@ public extension GameAction {
)
}

/// Draw card from other player's inPlay
static func stealInPlay(_ card: String, target: String, player: String) -> Self {
.init(
kind: .stealInPlay,
Expand All @@ -226,7 +218,17 @@ public extension GameAction {
)
}

/// Shoot a player
static func passInPlay(_ card: String, target: String, player: String) -> Self {
.init(
kind: .passInPlay,
payload: .init(
actor: player,
target: target,
card: card
)
)
}

static func shoot(_ target: String, player: String) -> Self {
.init(
kind: .shoot,
Expand All @@ -237,7 +239,15 @@ public extension GameAction {
)
}

/// Start turn
static func counterShoot(player: String) -> Self {
.init(
kind: .counterShot,
payload: .init(
target: player
)
)
}

static func startTurn(player: String) -> Self {
.init(
kind: .startTurn,
Expand All @@ -247,7 +257,6 @@ public extension GameAction {
)
}

/// End turn
static func endTurn(player: String) -> Self {
.init(
kind: .endTurn,
Expand All @@ -257,7 +266,6 @@ public extension GameAction {
)
}

/// Eliminate
static func eliminate(player: String) -> Self {
.init(
kind: .eliminate,
Expand All @@ -267,7 +275,6 @@ public extension GameAction {
)
}

/// End game
static func endGame(player: String) -> Self {
.init(
kind: .endGame,
Expand All @@ -277,15 +284,13 @@ public extension GameAction {
)
}

/// Expose active cards
static func activate(_ cards: [String], player: String) -> Self {
.init(
kind: .activate,
payload: .init(target: player, cards: cards)
)
}

/// Discard just played card
static func discardPlayed(_ card: String, player: String) -> Self {
.init(
kind: .discardPlayed,
Expand All @@ -296,7 +301,6 @@ public extension GameAction {
)
}

/// Equip a card
static func equip(_ card: String, player: String) -> Self {
.init(
kind: .equip,
Expand All @@ -307,7 +311,6 @@ public extension GameAction {
)
}

/// Handicap a target with a card
static func handicap(_ card: String, target: String, player: String) -> Self {
.init(
kind: .handicap,
Expand All @@ -319,7 +322,6 @@ public extension GameAction {
)
}

/// Set Weapon
static func setWeapon(_ weapon: Int, player: String) -> Self {
.init(
kind: .setWeapon,
Expand Down Expand Up @@ -401,9 +403,11 @@ private extension GameAction.Kind {
.drawDeck: "💰",
.drawDiscard: "💰",
.drawDiscovered: "💰",
.steal: "‼️",
.stealHand: "‼️",
.stealInPlay: "‼️",
.discardHand: "❌",
.discardInPlay: "❌",
.passInPlay: "💣",
.draw: "🎲",
.discover: "🎁",
.shoot: "🔫",
Expand All @@ -416,6 +420,8 @@ private extension GameAction.Kind {
.discardPlayed: "🟠",
.equip: "🔵",
.queue: "➕",
.setWeapon: "😎"
.setWeapon: "😎",
.increaseMagnifying: "😎",
.increaseRemoteness: "😎"
]
}
10 changes: 9 additions & 1 deletion WildWestOnline/Core/Bang/Sources/Game/GameState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public struct Player: Equatable, Codable, Sendable {
public var abilities: [String]
public var handLimit: Int
public var playLimitPerTurn: [String: Int]
public var drawCards: Int
}

public extension GameState {
Expand Down Expand Up @@ -146,6 +147,7 @@ public extension Player {
private var abilities: [String] = []
private var handLimit: Int = 0
private var playLimitPerTurn: [String: Int] = [:]
private var drawCards: Int = 0

public func build() -> Player {
.init(
Expand All @@ -158,7 +160,8 @@ public extension Player {
weapon: weapon,
abilities: abilities,
handLimit: handLimit,
playLimitPerTurn: playLimitPerTurn
playLimitPerTurn: playLimitPerTurn,
drawCards: drawCards
)
}

Expand Down Expand Up @@ -211,6 +214,11 @@ public extension Player {
playLimitPerTurn = value
return self
}

public func withDrawCards(_ value: Int) -> Self {
drawCards = value
return self
}
}

static func makeBuilder() -> Builder {
Expand Down
Loading