fixed multi move gltiches, added hopscotch card

This commit is contained in:
2ManyProjects 2025-01-31 19:40:50 -06:00
parent 396298b492
commit e51fb4db20
5 changed files with 76 additions and 31 deletions

View file

@ -20,6 +20,5 @@ func apply_effect(target_piece = null, board_flow = null, game_state = null):
if !super.apply_effect(target_piece, board_flow, game_state): if !super.apply_effect(target_piece, board_flow, game_state):
return false return false
# Logic to allow second move would be implemented in Game.gd
attached_piece = target_piece attached_piece = target_piece
return true return true

View file

@ -0,0 +1,24 @@
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
unitWhitelist = []
func modify_moves() -> Dictionary:
return {
"extra_moves": 5,
"move_multiplier": 1
}
func apply_effect(target_piece = null, board_flow = null, game_state = null):
if !super.apply_effect(target_piece, board_flow, game_state):
return false
attached_piece = target_piece
return true

View file

@ -2,6 +2,7 @@ extends Node
class_name DeckManager class_name DeckManager
const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd") const DoubleTimeCard = preload("res://Systems/Cards/Doubletime.gd")
const HopscotchCard = preload("res://Systems/Cards/Hopscotch.gd")
var deck: Array = [] var deck: Array = []
@ -22,8 +23,9 @@ func _init():
initializeStartingDeck() initializeStartingDeck()
func initializeStartingDeck(): func initializeStartingDeck():
for i in range(10): for i in range(9):
deck.append(DoubleTimeCard.new()) deck.append(DoubleTimeCard.new())
deck.append(HopscotchCard.new())
shuffleDeck() shuffleDeck()
drawStartingHand() drawStartingHand()

View file

@ -357,8 +357,7 @@ func executeMove(targetLocation: String) -> void:
currentlyMovingPiece = piece currentlyMovingPiece = piece
resetHighlights() resetHighlights()
func resolveMoveEffects() -> void: func togglePieceChessEffect() -> void:
print("resolveMoveEffects", currentlyMovingPiece)
var piece = currentlyMovingPiece var piece = currentlyMovingPiece
if piece.name == "Pawn": if piece.name == "Pawn":
if piece.Double_Start: if piece.Double_Start:
@ -368,6 +367,10 @@ func resolveMoveEffects() -> void:
piece.Castling = false piece.Castling = false
elif piece.name == "Rook": elif piece.name == "Rook":
piece.Castling = false piece.Castling = false
func resolveMoveEffects() -> void:
print("resolveMoveEffects", currentlyMovingPiece)
togglePieceChessEffect()
selectedNode = "" selectedNode = ""
Turn = 1 if Turn == 0 else 0 Turn = 1 if Turn == 0 else 0

View file

@ -1,7 +1,7 @@
extends "res://Systems/StateMachine/ChessGameState.gd" extends "res://Systems/StateMachine/ChessGameState.gd"
var moves_remaining = {} var moves_remaining = {}
var multiMoving = false var multiMoving = ""
func _ready() -> void: func _ready() -> void:
print("Movement state ready") print("Movement state ready")
@ -16,10 +16,10 @@ func enter(_previous: String, _data := {}) -> void:
game.getMovableAreas() game.getMovableAreas()
moves_remaining.clear() moves_remaining.clear()
multiMoving = false multiMoving = ""
for piece_id in game.deckManager.attached_cards: for piece_id in game.deckManager.attached_cards:
var card = game.deckManager.attached_cards[piece_id] var card = game.deckManager.attached_cards[piece_id]
if card is DoubleTimeCard: if card.effectType == Card.EffectType.MOVEMENT_MODIFIER:
var effects = card.modify_moves() var effects = card.modify_moves()
moves_remaining[piece_id] = effects.get("extra_moves", 0) + 1 moves_remaining[piece_id] = effects.get("extra_moves", 0) + 1
@ -28,18 +28,33 @@ func exit() -> void:
game.boardContainer.disconnect("tile_pressed", handleMovement) game.boardContainer.disconnect("tile_pressed", handleMovement)
func handleMovement(location: String) -> void: func handleMovement(location: String) -> void:
# print("HANDLING MOVEMENT ", location) # we need to prevent swapping of focus between peices after the double move process has started
# maybe once u start nmoving a peice global stat var is set
# and any moving peice needs ot match that
print("HANDLING MOVEMENT ", location, " | ", multiMoving, " | ", game.selectedNode)
var node = game.get_node("Flow/" + location) var node = game.get_node("Flow/" + location)
var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
var piece_id = piece.get_instance_id()
print(piece_id)
var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1
if multiMoving.length() > 0:
if node.get_child_count() > 0 and is_instance_valid(node.get_child(0)):
var attempting_piece = node.get_child(0)
print("Checking Str comp ", str(attempting_piece.get_instance_id()), " ", multiMoving)
# Only block if it's a different piece of the same color
if str(attempting_piece.get_instance_id()) != multiMoving and attempting_piece.Item_Color == game.Turn:
print("early return - can't select different piece of same color during multi-move")
return
if game.selectedNode == "": if game.selectedNode == "":
if node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn: if node.get_child_count() != 0 && node.get_child(0).Item_Color == game.Turn:
print("SELECTED NODE ", location)
game.selectedNode = location game.selectedNode = location
game.getMovableAreas() game.getMovableAreas()
return return
var piece = game.get_node("Flow/" + game.selectedNode).get_child(0)
var piece_id = piece.get_instance_id()
var is_multi_moving = piece_id in moves_remaining and moves_remaining[piece_id] > 1
# print(moves_remaining, " | ", piece_id, " | ",is_multi_moving) # print(moves_remaining, " | ", piece_id, " | ",is_multi_moving)
var consumeMove = true; var consumeMove = true;
@ -53,7 +68,7 @@ func handleMovement(location: String) -> void:
# finished.emit(Constants.POST_MOVE) # finished.emit(Constants.POST_MOVE)
if game.selectedNode == location: if game.selectedNode == location:
if !is_multi_moving and !multiMoving: if !is_multi_moving and multiMoving == "":
print("CLEAR SELECTION*************") print("CLEAR SELECTION*************")
game.clearSelection() game.clearSelection()
elif isCastlingMove(node, location): elif isCastlingMove(node, location):
@ -64,7 +79,7 @@ func handleMovement(location: String) -> void:
handleEnPassant(node) handleEnPassant(node)
# Reselect piece # Reselect piece
elif isReselectMove(node): elif isReselectMove(node):
if !is_multi_moving and !multiMoving: if !is_multi_moving and multiMoving == "":
print("RESELECT SELECTION*************") print("RESELECT SELECTION*************")
game.selectedNode = location game.selectedNode = location
game.getMovableAreas() game.getMovableAreas()
@ -80,24 +95,23 @@ func handleMovement(location: String) -> void:
if game.isValidMove(location): if game.isValidMove(location):
# executeMove(location) # executeMove(location)
handleRegularMove(node, consumeMove) handleRegularMove(node, consumeMove)
if consumeMove: if consumeMove:
multiMoving = false multiMoving = ""
game.clearSelection() game.clearSelection()
finished.emit(Constants.POST_MOVE) print("Consuming move")
else: finished.emit(Constants.POST_MOVE)
multiMoving = true elif is_multi_moving:
game.selectedNode = location # Keep the piece selected for another move
multiMoving = str(piece_id)
game.selectedNode = location # Keep the piece selected for another move # game.selectedNode = ""
game.hasMoved = false
# game.selectedNode = "" game.currentlyMovingPiece = null
game.hasMoved = false print("ANOTHER MOVE")
game.currentlyMovingPiece = null game.resetHighlights()
game.getMovableAreas() if game.selectedNode != "":
print("ANOTHER MOVE") game.getMovableAreas()
game.resetHighlights() # finished.emit(Constants.POST_MOVE)
if game.selectedNode != "":
game.getMovableAreas()
# finished.emit(Constants.POST_MOVE)
@ -173,6 +187,9 @@ func handleRegularMove(node: Node, consume: bool) -> void:
if consume: if consume:
game.currentlyMovingPiece = piece game.currentlyMovingPiece = piece
game.resolveMoveEffects() game.resolveMoveEffects()
else:
game.currentlyMovingPiece = piece
game.togglePieceChessEffect();