fixed multi move gltiches, added hopscotch card
This commit is contained in:
parent
396298b492
commit
e51fb4db20
5 changed files with 76 additions and 31 deletions
|
|
@ -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
|
||||||
24
Systems/Cards/Hopscotch.gd
Normal file
24
Systems/Cards/Hopscotch.gd
Normal 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
|
||||||
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
@ -369,6 +368,10 @@ func resolveMoveEffects() -> void:
|
||||||
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
|
||||||
updateTurnIndicator()
|
updateTurnIndicator()
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -81,18 +96,17 @@ func handleMovement(location: String) -> void:
|
||||||
# executeMove(location)
|
# executeMove(location)
|
||||||
handleRegularMove(node, consumeMove)
|
handleRegularMove(node, consumeMove)
|
||||||
if consumeMove:
|
if consumeMove:
|
||||||
multiMoving = false
|
multiMoving = ""
|
||||||
game.clearSelection()
|
game.clearSelection()
|
||||||
|
print("Consuming move")
|
||||||
finished.emit(Constants.POST_MOVE)
|
finished.emit(Constants.POST_MOVE)
|
||||||
else:
|
elif is_multi_moving:
|
||||||
multiMoving = true
|
|
||||||
|
|
||||||
game.selectedNode = location # Keep the piece selected for another move
|
game.selectedNode = location # Keep the piece selected for another move
|
||||||
|
multiMoving = str(piece_id)
|
||||||
|
|
||||||
# game.selectedNode = ""
|
# game.selectedNode = ""
|
||||||
game.hasMoved = false
|
game.hasMoved = false
|
||||||
game.currentlyMovingPiece = null
|
game.currentlyMovingPiece = null
|
||||||
game.getMovableAreas()
|
|
||||||
print("ANOTHER MOVE")
|
print("ANOTHER MOVE")
|
||||||
game.resetHighlights()
|
game.resetHighlights()
|
||||||
if game.selectedNode != "":
|
if game.selectedNode != "":
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue