Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephtelolahy committed Nov 24, 2023
1 parent 6df48b0 commit 5f86a2d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion GameKit/Sources/Game/DSL/Modifiers/Card+Modifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public extension Card {
prototype: Card? = nil,
silent: [String] = [],
attributes: [String: Int] = [:],
alias: [String: String] = [:],
alias: [CardAlias] = [],
priority: Int = 0,
@CardRuleBuilder content: () -> [CardRule] = { [] }
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ extension GameState {
func alias(for card: String, player: String) -> String? {
let playerObj = self.player(player)
let figure = playerObj.figure
let cardAlias = self.cardRef[figure]?.alias ?? [:]
guard let matched = cardAlias.first(where: { card.matches(regex: $0.value ) }) else {
let cardAlias = self.cardRef[figure]?.alias ?? []
guard let matched = cardAlias.first(where: {
card.matches(regex: $0.regex)
}) else {
return nil
}

return matched.key
return matched.card
}
}
21 changes: 18 additions & 3 deletions GameKit/Sources/Game/State/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public struct Card: Codable, Equatable {
public let attributes: [String: Int]

/// Playable card alias
/// - key: card effect
/// - value: regex of played card
public let alias: [String: String]
public let alias: [CardAlias]

/// Effect priority
public let priority: Int
Expand All @@ -29,3 +27,20 @@ public struct CardRule: Codable, Equatable {
/// Conditions to trigger the card effect
let playReqs: [PlayReq]
}

public struct CardAlias: Codable, Equatable {
/// Name of card having the play effect
let card: String

/// Regex of alias card
let regex: String

/// Conditions to trigger the card alias
let playReqs: [PlayReq]

public init(card: String, regex: String, playReqs: [PlayReq] = []) {
self.card = card
self.regex = regex
self.playReqs = playReqs
}
}
6 changes: 5 additions & 1 deletion GameKit/Sources/Inventory/CardList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,11 @@ private extension CardList {

static let luckyDuke = Card(.luckyDuke, prototype: pDefault, attributes: [.maxHealth: 4, .flippedCards: 2])

static let calamityJanet = Card(.calamityJanet, prototype: pDefault, attributes: [.maxHealth: 4], alias: [.bang: .missed, .missed: .bang])
private static let playBangAsMissedAndViceVersa: [CardAlias] = [
CardAlias(card: .bang, regex: .missed),
CardAlias(card: .missed, regex: .bang)
]
static let calamityJanet = Card(.calamityJanet, prototype: pDefault, attributes: [.maxHealth: 4], alias: playBangAsMissedAndViceVersa)

static let bartCassidy = Card(.bartCassidy, prototype: pDefault, attributes: [.maxHealth: 4]) {
CardEffect.drawDeck
Expand Down
2 changes: 1 addition & 1 deletion GameKit/Tests/GameTests/DSL/CardTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class CardTests: XCTestCase {
"name": "c1",
"priority": 1,
"attributes": {},
"alias": {},
"alias": [],
"rules": []
}
"""
Expand Down

0 comments on commit 5f86a2d

Please sign in to comment.