78 lines
No EOL
3 KiB
GDScript
78 lines
No EOL
3 KiB
GDScript
class_name FireyCapeCard extends Card
|
|
|
|
var previous_position: String = ""
|
|
var fire_tiles: Array[String] = []
|
|
|
|
func _init():
|
|
super._init()
|
|
cardName = "Firey Cape"
|
|
rank = Rank.RANK_2
|
|
effectType = EffectType.PIECE_EFFECT
|
|
description = "Leaves a trail of fire that lasts 4 turns. Owner's pieces can pass safely."
|
|
duration = 3 # Card effect lasts 3 turns
|
|
unitWhitelist = [] # Any piece can wear the cape
|
|
|
|
func apply_effect(target_piece = null, board_flow = null, game_state = null):
|
|
if !super.apply_effect(target_piece, board_flow, game_state):
|
|
return false
|
|
|
|
# Store the current position as previous position
|
|
previous_position = target_piece.get_parent().name
|
|
setup_persistent_effect(game_state)
|
|
return true
|
|
|
|
func setup_persistent_effect(game_state):
|
|
if !game_state.is_connected("turn_changed", on_turn_changed):
|
|
game_state.connect("turn_changed", on_turn_changed)
|
|
|
|
func on_turn_changed():
|
|
if !attached_piece || remaining_turns <= 0:
|
|
return
|
|
|
|
var piece = attached_piece
|
|
var board_flow = piece.get_parent().get_parent()
|
|
var current_pos = piece.get_parent().name
|
|
|
|
# If the piece has moved, place fire tiles
|
|
if current_pos != previous_position:
|
|
var current_coords = current_pos.split("-")
|
|
var prev_coords = previous_position.split("-")
|
|
var current_x = int(current_coords[0])
|
|
var current_y = int(current_coords[1])
|
|
var prev_x = int(prev_coords[0])
|
|
var prev_y = int(prev_coords[1])
|
|
|
|
# Calculate all positions between previous and current (excluding current)
|
|
var positions_to_mark = []
|
|
var dx = sign(current_x - prev_x)
|
|
var dy = sign(current_y - prev_y)
|
|
var x = prev_x
|
|
var y = prev_y
|
|
|
|
# Start with the previous position
|
|
positions_to_mark.append(previous_position)
|
|
|
|
# Add intermediate positions (but not the final position)
|
|
while (x + dx != current_x || y + dy != current_y):
|
|
x += dx
|
|
y += dy
|
|
positions_to_mark.append(str(x) + "-" + str(y))
|
|
|
|
# Place fire tiles
|
|
var tile_owner = Tile.TileOwner.PLAYER if piece.Item_Color == 0 else Tile.TileOwner.ENEMY
|
|
for pos in positions_to_mark:
|
|
var container = board_flow.get_node(pos) as PieceContainer
|
|
if container:
|
|
var is_white = (int(pos.split("-")[0]) + int(pos.split("-")[1])) % 2 == 0
|
|
var fire_tile = FireWallTile.new(container, is_white, 4, tile_owner)
|
|
board_flow.get_parent().tileManager.add_tile(pos, fire_tile)
|
|
fire_tiles.append(pos)
|
|
|
|
previous_position = current_pos
|
|
|
|
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() |