From ed47373938df26a454973ef9e3c55a573a328ffd Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Fri, 31 Jan 2025 22:28:44 -0600 Subject: [PATCH] added Drunkdriving effect --- Systems/Card.gd | 4 +- Systems/Cards/Drunkdriving.gd | 58 ++++++++++++++++--- Systems/Cards/Hopscotch.gd | 3 +- Systems/DeckManager.gd | 7 ++- Systems/Game/ChessGame.gd | 8 --- .../StateMachine/GameStates/AttachCards.gd | 4 +- addons/Chess/Scripts/Pawn.gd | 1 - 7 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Systems/Card.gd b/Systems/Card.gd index b6df7db..19f12d4 100644 --- a/Systems/Card.gd +++ b/Systems/Card.gd @@ -25,12 +25,14 @@ func _init(): # print(id) func can_attach_to_piece(piece: Pawn) -> bool: + # print(unitWhitelist, " | ", piece.name , " | ", unitWhitelist.has(piece.name)) if unitWhitelist.is_empty(): return true return unitWhitelist.has(piece.name) func apply_effect(target_piece = null, board_flow = null, game_state = null): if burned || (target_piece && !can_attach_to_piece(target_piece)): + # print("CARD CANT APPLY AFFECT") return false remaining_turns = duration @@ -42,7 +44,7 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null): Rank.RANK_2: pass Rank.RANK_3: pass - return modify_moves() + return true func update_duration(): if remaining_turns > 0: diff --git a/Systems/Cards/Drunkdriving.gd b/Systems/Cards/Drunkdriving.gd index 936c440..d51b11d 100644 --- a/Systems/Cards/Drunkdriving.gd +++ b/Systems/Cards/Drunkdriving.gd @@ -1,20 +1,60 @@ class_name DrunkDrivingCard extends Card + func _init(): super._init() - # id = Utils.generate_guid() cardName = "Drunk Driving" rank = Rank.RANK_1 + duration = 1 effectType = EffectType.SPECIAL_ACTION - description = "Force Rook to move to opposite end" - unitWhitelist = ["Rook"] # Can only be attached to Rooks + description = "Force Rook to careen towards the enemy side, capturing all pieces in its path" + unitWhitelist = ["Rook"] func apply_effect(target_piece = null, board_flow = null, game_state = null): if !super.apply_effect(target_piece, board_flow, game_state): + print("FAILED DEFAULT FN") return false - if target_piece: - var current_pos = target_piece.get_parent().name.split("-") - var target_x = current_pos[0] - var target_y = "0" if target_piece.Item_Color == 0 else "7" - return [target_x + "-" + target_y] - return false + if !target_piece or !board_flow or !game_state: + print("FAILED DEFAULT FN 2") + return false + + + var current_pos = target_piece.get_parent().name.split("-") + var current_x = int(current_pos[0]) + var current_y = int(current_pos[1]) + + + var target_y = 7 if target_piece.Item_Color == 1 else 0 + + + var y_direction = 1 if target_y > current_y else -1 + + + var tiles_to_check = [] + var y = current_y + y_direction + while y != target_y + y_direction: + tiles_to_check.append(str(current_x) + "-" + str(y)) + y += y_direction + + + for tile_name in tiles_to_check: + var tile = board_flow.get_node(tile_name) + if tile.get_child_count() > 0: + var piece_to_capture = tile.get_child(0) + game_state.updatePoints(piece_to_capture) + piece_to_capture.queue_free() + + + var final_tile = board_flow.get_node(str(current_x) + "-" + str(target_y)) + target_piece.reparent(final_tile) + target_piece.position = Vector2(25, 25) + + + game_state.currentlyMovingPiece = target_piece + + burned = true + + game_state.resolveMoveEffects(); + game_state.stateMachine.transitionToNextState(Constants.POST_MOVE) + + return true \ No newline at end of file diff --git a/Systems/Cards/Hopscotch.gd b/Systems/Cards/Hopscotch.gd index 4621a3a..44b8e10 100644 --- a/Systems/Cards/Hopscotch.gd +++ b/Systems/Cards/Hopscotch.gd @@ -2,12 +2,11 @@ class_name HopscotchCard extends Card func _init(): super._init() - # id = Utils.generate_guid() cardName = "HopScotch" rank = Rank.RANK_0 effectType = EffectType.MOVEMENT_MODIFIER description = "Peice can move 5 times per turn" - duration = 2 # Lasts for 2 turns + duration = 2 unitWhitelist = [] func modify_moves() -> Dictionary: diff --git a/Systems/DeckManager.gd b/Systems/DeckManager.gd index 2af9739..8f3f039 100644 --- a/Systems/DeckManager.gd +++ b/Systems/DeckManager.gd @@ -3,7 +3,7 @@ class_name DeckManager const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd") const HopscotchCard = preload("res://Systems/Cards/Hopscotch.gd") - +const DrunkDrivingCard = preload("res://Systems/Cards/Drunkdriving.gd") var deck: Array = [] var hand: Array = [] @@ -24,8 +24,9 @@ func _init(): func initializeStartingDeck(): deck.clear(); - for i in range(4): + for i in range(3): deck.append(DoubleTimeCard.new()) + deck.append(DrunkDrivingCard.new()) deck.append(HopscotchCard.new()) shuffleDeck() drawStartingHand() @@ -64,6 +65,7 @@ signal hand_updated func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = null): if !hand.has(card): + # print("Failed Play Card 1") return false if card.duration > 0: attached_cards[target_piece.get_instance_id()] = card @@ -76,6 +78,7 @@ func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = nu return true + # print("Failed Play Card 2") return false func updateCardDurations(): diff --git a/Systems/Game/ChessGame.gd b/Systems/Game/ChessGame.gd index 15f94d5..e2e7236 100644 --- a/Systems/Game/ChessGame.gd +++ b/Systems/Game/ChessGame.gd @@ -258,14 +258,6 @@ func applyTileEffects() -> void: if tile.has_effect(): tile.apply_effect(piece) -func attachSelectedCards() -> void: - # Logic for attaching selected cards to pieces - var selectedCard = cardDisplay.getSelectedCard() - if selectedCard and selectedNode: - var piece = get_node("Flow/" + selectedNode).get_child(0) - if piece and selectedCard.can_attach_to_piece(piece) and !deckManager.attached_cards.has(get_instance_id()): - deckManager.playCard(selectedCard, piece, boardContainer, self) - func applyCardEffects() -> void: pass diff --git a/Systems/StateMachine/GameStates/AttachCards.gd b/Systems/StateMachine/GameStates/AttachCards.gd index 81e21ef..c970bd8 100644 --- a/Systems/StateMachine/GameStates/AttachCards.gd +++ b/Systems/StateMachine/GameStates/AttachCards.gd @@ -13,11 +13,13 @@ func _ready() -> void: func enter(_previous: String, _data := {}) -> void: print("ENTERING STATE ", Constants.ATTACH_CARDS) + if(game.currentPlayer == game.BLACK): + _on_timer_timeout() if !game.boardContainer.is_connected("tile_pressed", handleTilePressed): game.boardContainer.connect("tile_pressed", handleTilePressed) timer.start(ATTACHMENT_PHASE_DURATION) - if game.deckManager.hand.is_empty() or (game.currentPlayer == game.BLACK): + if game.deckManager.hand.is_empty(): complete_attachment_phase() func exit() -> void: diff --git a/addons/Chess/Scripts/Pawn.gd b/addons/Chess/Scripts/Pawn.gd index f97dd55..f7a0197 100644 --- a/addons/Chess/Scripts/Pawn.gd +++ b/addons/Chess/Scripts/Pawn.gd @@ -42,7 +42,6 @@ func _init() -> void: add_child(duration_label) duration_label.hide() - func update_appearance() -> void: # print("update_appearance") if !is_instance_valid(get_tree()) || !get_tree().get_root().has_node("Board"):