added Halitoses

This commit is contained in:
2ManyProjects 2025-03-17 18:01:05 -05:00
parent 0cbbd15a60
commit 7a964d18d9
3 changed files with 146 additions and 2 deletions

143
Systems/Cards/Halitosis.gd Normal file
View file

@ -0,0 +1,143 @@
class_name HalitosisCard extends Card
const EFFECT_RADIUS = 1
var valid = false;
func _init():
duration = 3
super._init()
cardName = "Halitosis"
rank = Rank.RANK_2
effectType = EffectType.PIECE_EFFECT
description = "All enemy units within 1 radius of the moving piece at the end of the turn are pushed back"
unitWhitelist = ["Pawn", "Knight", "King"]
remaining_turns = duration
is_default = false
func reset():
remaining_turns = duration
valid = false
func apply_effect(target_piece = null, board_flow = null, game_state = null):
print("HALITOSIS apply_effect", target_piece)
attached_piece = target_piece
stored_board_flow = board_flow
stored_game_state = game_state
if !target_piece or !board_flow or !game_state:
print(cardName, " missing input param ")
return false
setup_persistent_effect(game_state)
# dont apply on card attachment
if !valid:
print("HALITOSIS apply_effect INVALID", )
return true
var piece_pos = target_piece.get_parent().name.split("-")
var piece_x = int(piece_pos[0])
var piece_y = int(piece_pos[1])
var tiles_to_check = []
for dx in range(-EFFECT_RADIUS, EFFECT_RADIUS + 1):
for dy in range(-EFFECT_RADIUS, EFFECT_RADIUS + 1):
if max(abs(dx), abs(dy)) > EFFECT_RADIUS:
continue
var target_x = piece_x + dx
var target_y = piece_y + dy
if target_x < 0 or target_x >= game_state.boardXSize or target_y < 0 or target_y >= game_state.boardYSize:
continue
if dx == 0 and dy == 0:
continue
tiles_to_check.append(str(target_x) + "-" + str(target_y))
# Process tiles and add overlay
for tile_name in tiles_to_check:
var container = board_flow.get_node(tile_name) as PieceContainer
# Handle overlay through container's overlay management
container.remove_overlay("HalitosisOverlay")
var overlay = ColorRect.new()
overlay.name = "HalitosisOverlay"
overlay.color = Color(0.5, 0.7, 1, 0.3) # Blue-ish
overlay.size = container.size
overlay.mouse_filter = Control.MOUSE_FILTER_IGNORE
container.add_overlay(overlay)
overlay.show()
# Check for pieces to affect
var piece = container.get_piece()
if piece != null and piece.Item_Color != target_piece.Item_Color:
# Calculate the direction to push
var push_dir_x = piece_x - int(tile_name.split("-")[0])
var push_dir_y = piece_y - int(tile_name.split("-")[1])
# Normalize the direction vector
var length = sqrt(push_dir_x * push_dir_x + push_dir_y * push_dir_y)
if length > 0:
push_dir_x = round(push_dir_x / length)
push_dir_y = round(push_dir_y / length)
# Calculate target cell to push to
var push_target_x = int(int(tile_name.split("-")[0]) - push_dir_x)
var push_target_y = int(int(tile_name.split("-")[1]) - push_dir_y)
var push_target = str(push_target_x) + "-" + str(push_target_y)
print("HALITSOSES ", tile_name, " ", push_target)
# Check if target is valid and empty
if push_target_x >= 0 and push_target_x < game_state.boardXSize and push_target_y >= 0 and push_target_y < game_state.boardYSize:
var target_container = board_flow.get_node(push_target) as PieceContainer
if target_container and !target_container.has_piece():
# Animate the push
target_container.animate_movement(container, piece)
else:
# If we can't push (blocked), capture the piece instead
# game_state.updatePointsAndCapture(piece)
print("Blocked should we capture?")
else:
print("Off Board should we capture?")
# If push would be off the board, capture the piece
# game_state.updatePointsAndCapture(piece)
# Setup timer to remove overlays
var timer = Timer.new()
board_flow.add_child(timer)
timer.wait_time = 1
timer.one_shot = true
timer.timeout.connect(func():
for tile_name in tiles_to_check:
var tile = board_flow.get_node(tile_name)
var overlay = tile.get_node_or_null("HalitosisOverlay")
if overlay:
overlay.queue_free()
timer.queue_free()
)
timer.start()
return true
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 ==================", stored_game_state.isPlayerTurn())
if stored_game_state.stateMachine.disabled:
return
if stored_game_state.isPlayerTurn() and attached_piece and remaining_turns > 0:
var piece = attached_piece
var flow = stored_board_flow
var state = stored_game_state
# Now try apply_effect with these values
valid = true
apply_effect(piece, flow, state)
func remove_effect():
if attached_piece:
var game_state = stored_game_state
if game_state.is_connected("turn_changed", on_turn_changed):
game_state.disconnect("turn_changed", on_turn_changed)
super.remove_effect()

View file

@ -0,0 +1 @@
uid://b8f17yg2854vs

View file

@ -552,8 +552,8 @@ func generate_chess_data(node, player):
var unit_string = level_unit_distribution[index]
var pawn_string = ""
var height = 6;
# unit_string = level_unit_distribution[level_unit_distribution.size() - 1]
# height = 8
unit_string = level_unit_distribution[level_unit_distribution.size() - 1]
height = 8
for x in unit_string.length():
pawn_string += "p"