debugging supernova
This commit is contained in:
parent
c127574e51
commit
7ec39b6c28
5 changed files with 148 additions and 15 deletions
|
|
@ -32,7 +32,7 @@ func can_attach_to_piece(piece: Pawn) -> bool:
|
|||
|
||||
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")
|
||||
print("CARD CANT APPLY AFFECT", burned, " ", target_piece)
|
||||
return false
|
||||
|
||||
remaining_turns = duration
|
||||
|
|
|
|||
|
|
@ -1,21 +1,149 @@
|
|||
class_name SupernovaCard extends Card
|
||||
|
||||
const CAPTURE_RADIUS = 4
|
||||
|
||||
func _init():
|
||||
duration = 5
|
||||
super._init()
|
||||
# id = Utils.generate_guid()
|
||||
cardName = "Supernova"
|
||||
rank = Rank.RANK_0
|
||||
effectType = EffectType.PIECE_EFFECT
|
||||
description = "Remove all abilities from enemy pieces"
|
||||
unitWhitelist = ["King"] # Can only be used by Kings
|
||||
description = "All enemy units within 4 radius are captured"
|
||||
unitWhitelist = ["King"]
|
||||
|
||||
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
||||
if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
print(cardName, " APPLY EFFECT ")
|
||||
# if !super.apply_effect(target_piece, board_flow, game_state):
|
||||
# print(cardName, " super apply false ")
|
||||
# return false
|
||||
|
||||
remaining_turns = duration
|
||||
attached_piece = target_piece
|
||||
if !target_piece or !board_flow or !game_state:
|
||||
print(cardName, " missing input param ")
|
||||
return false
|
||||
|
||||
if board_flow:
|
||||
for cell in board_flow.get_children():
|
||||
if cell.get_child_count() > 0:
|
||||
var piece = cell.get_child(0)
|
||||
if piece.Item_Color != target_piece.Item_Color:
|
||||
pass
|
||||
# Get king's position
|
||||
var king_pos = target_piece.get_parent().name.split("-")
|
||||
var king_x = int(king_pos[0])
|
||||
var king_y = int(king_pos[1])
|
||||
|
||||
# Collect all tiles within radius to check
|
||||
var tiles_to_check = []
|
||||
|
||||
# Check in all directions (up, down, left, right and diagonals)
|
||||
for dx in range(-CAPTURE_RADIUS, CAPTURE_RADIUS + 1):
|
||||
for dy in range(-CAPTURE_RADIUS, CAPTURE_RADIUS + 1):
|
||||
# Skip if outside Manhattan distance
|
||||
if abs(dx) + abs(dy) > CAPTURE_RADIUS:
|
||||
continue
|
||||
|
||||
# Calculate target coordinates
|
||||
var target_x = king_x + dx
|
||||
var target_y = king_y + dy
|
||||
|
||||
# Skip if outside board bounds
|
||||
if target_x < 0 or target_x >= 8 or target_y < 0 or target_y >= 8:
|
||||
continue
|
||||
|
||||
# Skip king's own position
|
||||
if dx == 0 and dy == 0:
|
||||
continue
|
||||
|
||||
# Add tile to check list
|
||||
tiles_to_check.append(str(target_x) + "-" + str(target_y))
|
||||
|
||||
print(tiles_to_check)
|
||||
# reset_tile_styles(board_flow, tiles_to_check)
|
||||
# Process each tile and capture pieces
|
||||
for tile_name in tiles_to_check:
|
||||
var tile = board_flow.get_node(tile_name)
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(1, 0, 0, 0.3) # Red tint
|
||||
tile.remove_theme_stylebox_override("normal")
|
||||
tile.add_theme_stylebox_override("normal", style)
|
||||
|
||||
if tile.get_child_count() > 0:
|
||||
var piece = tile.get_child(0)
|
||||
# print("Process", piece.name, " | ", piece.Item_Color, " | ", target_piece.Item_Color)
|
||||
if piece.Item_Color != target_piece.Item_Color: # Only capture enemy pieces
|
||||
game_state.updatePoints(piece)
|
||||
piece.queue_free()
|
||||
|
||||
var timer = Timer.new()
|
||||
board_flow.add_child(timer)
|
||||
timer.wait_time = 0.5
|
||||
timer.one_shot = true
|
||||
timer.timeout.connect(func():
|
||||
reset_tile_styles(board_flow, tiles_to_check)
|
||||
timer.queue_free()
|
||||
)
|
||||
timer.start()
|
||||
# Visual feedback
|
||||
# for tile_name in tiles_to_check:
|
||||
# var tile = board_flow.get_node(tile_name)
|
||||
# var style = StyleBoxFlat.new()
|
||||
# style.bg_color = Color(1, 0, 0, 0.3) # Red tint
|
||||
# tile.add_theme_stylebox_override("normal", style)
|
||||
|
||||
# var timer = Timer.new()
|
||||
# board_flow.add_child(timer)
|
||||
# timer.wait_time = 0.5
|
||||
# timer.one_shot = true
|
||||
# timer.timeout.connect(func():
|
||||
# tile.remove_theme_stylebox_override("normal")
|
||||
# timer.queue_free()
|
||||
# )
|
||||
# timer.start()
|
||||
setup_persistent_effect(game_state);
|
||||
# game_state.stateMachine.transitionToNextState(Constants.POST_MOVE)
|
||||
return true
|
||||
|
||||
func reset_tile_styles(board_flow, tiles_to_check):
|
||||
for tile_name in tiles_to_check:
|
||||
var tile = board_flow.get_node(tile_name)
|
||||
if !tile:
|
||||
print("continue")
|
||||
continue
|
||||
|
||||
# Reset to original chess board pattern
|
||||
var coords = tile_name.split("-")
|
||||
var isWhite = (int(coords[0]) + int(coords[1])) % 2 == 0
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.8, 0.8, 0.8, 1) if isWhite else Color(0.2, 0.2, 0.2, 1)
|
||||
tile.add_theme_stylebox_override("normal", style)
|
||||
|
||||
|
||||
func setup_persistent_effect(game_state):
|
||||
# Connect to the turn change signal if not already connected
|
||||
if !game_state.is_connected("turn_changed", on_turn_changed):
|
||||
game_state.connect("turn_changed", on_turn_changed)
|
||||
|
||||
func on_turn_changed():
|
||||
# print("TURN CHANGED ==================", attached_piece, " | ", remaining_turns, )
|
||||
|
||||
if attached_piece.get_parent().get_parent().owner.isPlayerTurn() and attached_piece and remaining_turns > 0:
|
||||
print(attached_piece.get_parent().get_parent(), attached_piece.get_parent().get_parent().owner)
|
||||
var piece = attached_piece
|
||||
var flow = attached_piece.get_parent().get_parent()
|
||||
var state = attached_piece.get_parent().get_parent().owner
|
||||
|
||||
# print("Debug values:")
|
||||
# print("- Piece: ", piece, " is null? ", piece == null)
|
||||
# print("- Board Flow: ", flow, " is null? ", flow == null)
|
||||
# print("- Game State: ", state, " is null? ", state == null)
|
||||
|
||||
# Now try apply_effect with these values
|
||||
apply_effect(piece, flow, state)
|
||||
remaining_turns -= 1
|
||||
if remaining_turns <= 0:
|
||||
remove_effect()
|
||||
else:
|
||||
burned = true
|
||||
|
||||
func remove_effect():
|
||||
if attached_piece:
|
||||
var game_state = attached_piece.get_parent().get_parent().owner
|
||||
if game_state.is_connected("turn_changed", on_turn_changed):
|
||||
game_state.disconnect("turn_changed", on_turn_changed)
|
||||
super.remove_effect()
|
||||
|
|
@ -4,6 +4,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")
|
||||
const SupernovaCard = preload("res://Systems/Cards/Supernova.gd")
|
||||
|
||||
var deck: Array = []
|
||||
var hand: Array = []
|
||||
|
|
@ -24,10 +25,11 @@ func _init():
|
|||
|
||||
func initializeStartingDeck():
|
||||
deck.clear();
|
||||
for i in range(3):
|
||||
for i in range(2):
|
||||
deck.append(DoubleTimeCard.new())
|
||||
deck.append(DrunkDrivingCard.new())
|
||||
deck.append(HopscotchCard.new())
|
||||
deck.append(SupernovaCard.new())
|
||||
shuffleDeck()
|
||||
drawStartingHand()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const WHITE = "white"
|
|||
const BLACK = "black"
|
||||
signal tile_pressed(location: String)
|
||||
signal send_location(location: String)
|
||||
signal turn_changed
|
||||
var currentPlayer: String = WHITE
|
||||
var board: Array
|
||||
var activeEffects: Array
|
||||
|
|
@ -371,6 +372,7 @@ func resolveMoveEffects() -> void:
|
|||
resetHighlights()
|
||||
hasMoved = false
|
||||
currentlyMovingPiece = null
|
||||
emit_signal("turn_changed")
|
||||
|
||||
func isPlayerTurn() -> bool:
|
||||
return currentPlayer == WHITE
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
extends "res://Systems/StateMachine/ChessGameState.gd"
|
||||
|
||||
const ATTACHMENT_PHASE_DURATION = 30 # Duration in seconds
|
||||
const ATTACHMENT_PHASE_DURATION = 15 # Duration in seconds
|
||||
var timer: Timer
|
||||
var tile_pressed_connection: Signal
|
||||
|
||||
|
|
@ -15,6 +15,7 @@ func enter(_previous: String, _data := {}) -> void:
|
|||
print("ENTERING STATE ", Constants.ATTACH_CARDS)
|
||||
if(game.currentPlayer == game.BLACK):
|
||||
_on_timer_timeout()
|
||||
return
|
||||
if !game.boardContainer.is_connected("tile_pressed", handleTilePressed):
|
||||
game.boardContainer.connect("tile_pressed", handleTilePressed)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue