Schafkopf-Server/Sources/App/Model/Players/BiddingPlayer.swift
2021-12-09 11:11:17 +01:00

52 lines
1004 B
Swift

import Foundation
import WebSocketKit
final class BiddingPlayer {
let name: String
var socket: WebSocket?
let cards: [PlayableCard]
var isStillBidding = true
var isAllowedToOfferWedding = true
var offersWedding = false
var wouldAcceptWedding = false
init(player: DealingPlayer, cards: [PlayableCard]) {
self.name = player.name
self.socket = player.socket
self.cards = cards
}
}
extension BiddingPlayer: Player {
var canOfferWedding: Bool {
rawCards.canOfferWedding
}
var rawCards: [Card] {
cards.map { $0.card }
}
var actions: [PlayerAction] {
guard isStillBidding else {
return []
}
guard canOfferWedding, isAllowedToOfferWedding, !offersWedding else {
return [.increaseOrMatchGame, .withdrawFromAuction]
}
return [.increaseOrMatchGame, .withdrawFromAuction, .offerWedding]
}
var playedCard: Card? {
nil
}
}