Schafkopf-Server/Sources/App/Model/Players/BiddingPlayer.swift
2021-12-18 15:08:43 +01:00

62 lines
1.4 KiB
Swift

import Foundation
import WebSocketKit
final class BiddingPlayer: Player {
var isStillBidding = true
var isAllowedToOfferWedding: Bool
var selectsGame = false
init(player: DealingPlayer) {
isAllowedToOfferWedding = true
super.init(player: player)
}
init(player: WeddingPlayer) {
isStillBidding = !player.offersWedding
isAllowedToOfferWedding = false
super.init(player: player)
}
func canPlay(game: GameType) -> Bool {
guard let suit = game.calledSuit else {
if game == .hochzeit {
return canOfferWedding
}
return true
}
let sorter = game.sortingType
guard sorter.hasCardToCall(suit, in: cards) else {
// Player needs at least one card of the called suit
return false
}
let ace = Card(suit, .ass)
return !cards.contains(ace)
}
override var actions: [PlayerAction] {
guard isStillBidding else {
return []
}
var actions: [PlayerAction] = isNextActor ? [.increaseOrMatchGame, .withdrawFromAuction] : []
if canOfferWedding {
actions.append(.offerWedding)
}
return actions
}
override var points: Int? {
get { nil }
set { }
}
}
extension BiddingPlayer {
var canOfferWedding: Bool {
cards.canOfferWedding
}
}