added supprot for effects and they stack with cards
This commit is contained in:
parent
16b099b6b4
commit
6ed2dd5f75
5 changed files with 154 additions and 98 deletions
|
|
@ -5,6 +5,7 @@ var deck: Array = []
|
||||||
var hand: Array = []
|
var hand: Array = []
|
||||||
var discard: Array = []
|
var discard: Array = []
|
||||||
var attached_cards: Dictionary = {} # piece_id: card
|
var attached_cards: Dictionary = {} # piece_id: card
|
||||||
|
var attached_effects: Dictionary = {} # piece_id: [card]
|
||||||
var hand_size: int = 5
|
var hand_size: int = 5
|
||||||
|
|
||||||
# Card costs for shop
|
# Card costs for shop
|
||||||
|
|
@ -72,6 +73,57 @@ func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = nu
|
||||||
# print("Failed Play Card 2")
|
# print("Failed Play Card 2")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
func playEffect(card: Card, target_piece: Pawn, board_flow = null, game_state = null):
|
||||||
|
|
||||||
|
var key = target_piece.get_instance_id();
|
||||||
|
if !attached_effects.has(key):
|
||||||
|
attached_effects[key] = []
|
||||||
|
else:
|
||||||
|
for existing_card in attached_effects[key]:
|
||||||
|
if existing_card.cardName == card.cardName:
|
||||||
|
# Card already exists, don't add it again
|
||||||
|
return false
|
||||||
|
|
||||||
|
if card.apply_effect(target_piece, board_flow, game_state):
|
||||||
|
if card.duration > 0:
|
||||||
|
attached_effects[key].append(card)
|
||||||
|
|
||||||
|
|
||||||
|
return true
|
||||||
|
# print("Failed Play Card 2")
|
||||||
|
return false
|
||||||
|
|
||||||
|
func updateEffectDurations():
|
||||||
|
var expired_entries = [] # Store [piece_id, card_id] pairs to remove
|
||||||
|
|
||||||
|
for piece_id in attached_effects:
|
||||||
|
var cards_to_remove = [] # Track which cards to remove from this piece's array
|
||||||
|
|
||||||
|
for card in attached_effects[piece_id]:
|
||||||
|
card.update_duration()
|
||||||
|
if card.remaining_turns <= 0:
|
||||||
|
cards_to_remove.append(card)
|
||||||
|
else:
|
||||||
|
var piece_node = instance_from_id(piece_id)
|
||||||
|
if is_instance_valid(piece_node):
|
||||||
|
piece_node.update_appearance()
|
||||||
|
|
||||||
|
# Remove expired cards from this piece's array
|
||||||
|
for card in cards_to_remove:
|
||||||
|
attached_effects[piece_id].erase(card)
|
||||||
|
|
||||||
|
# If no cards left for this piece, mark the piece_id for removal
|
||||||
|
if attached_effects[piece_id].is_empty():
|
||||||
|
expired_entries.append(piece_id)
|
||||||
|
var piece_node = instance_from_id(piece_id)
|
||||||
|
if is_instance_valid(piece_node):
|
||||||
|
piece_node.update_appearance()
|
||||||
|
|
||||||
|
# Remove empty entries
|
||||||
|
for piece_id in expired_entries:
|
||||||
|
attached_effects.erase(piece_id)
|
||||||
|
|
||||||
func updateCardDurations():
|
func updateCardDurations():
|
||||||
var expired_cards = []
|
var expired_cards = []
|
||||||
for piece_id in attached_cards:
|
for piece_id in attached_cards:
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,15 @@ func enter(_previous: String, _data := {}) -> void:
|
||||||
if card.effectType == Card.EffectType.MOVEMENT_MODIFIER:
|
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
|
||||||
|
for piece_id in game.deckManager.attached_effects:
|
||||||
|
for effect in game.deckManager.attached_effects[piece_id]:
|
||||||
|
if effect.effectType == Card.EffectType.MOVEMENT_MODIFIER:
|
||||||
|
var effects = effect.modify_moves()
|
||||||
|
# Add to existing moves if already present, otherwise set new value
|
||||||
|
if piece_id in moves_remaining:
|
||||||
|
moves_remaining[piece_id] += effects.get("extra_moves", 0)
|
||||||
|
else:
|
||||||
|
moves_remaining[piece_id] = effects.get("extra_moves", 0) + 1
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
if game.boardContainer.is_connected("tile_pressed", handleMovement):
|
if game.boardContainer.is_connected("tile_pressed", handleMovement):
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,9 @@ func _init(button: Button, is_white: bool, d: int) -> void:
|
||||||
func apply_effect(piece: Pawn = null) -> void:
|
func apply_effect(piece: Pawn = null) -> void:
|
||||||
if piece && is_effect_active():
|
if piece && is_effect_active():
|
||||||
var deck_manager = game.deckManager
|
var deck_manager = game.deckManager
|
||||||
|
|
||||||
# Check for and remove any existing card
|
|
||||||
var piece_id = piece.get_instance_id()
|
|
||||||
if deck_manager.attached_cards.has(piece_id):
|
|
||||||
var existing_card = deck_manager.attached_cards[piece_id]
|
|
||||||
existing_card.remove_effect()
|
|
||||||
deck_manager.attached_cards.erase(piece_id)
|
|
||||||
|
|
||||||
# Add double movement effect to the piece
|
|
||||||
var double_time = DoubleTimeCard.new()
|
var double_time = DoubleTimeCard.new()
|
||||||
double_time.duration = 2
|
double_time.duration = 2
|
||||||
deck_manager.playCard(double_time, piece, null, null, true)
|
deck_manager.playEffect(double_time, piece, null, null)
|
||||||
piece.on_card_effect_changed()
|
piece.on_card_effect_changed()
|
||||||
|
|
||||||
func update_appearance() -> void:
|
func update_appearance() -> void:
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func apply_effect(piece: Pawn = null) -> void:
|
||||||
# Add double movement effect
|
# Add double movement effect
|
||||||
var double_time = DoubleTimeCard.new()
|
var double_time = DoubleTimeCard.new()
|
||||||
double_time.duration = 1 # Just for this turn
|
double_time.duration = 1 # Just for this turn
|
||||||
game.deckManager.playCard(double_time, pawn, null, game, true)
|
game.deckManager.playEffect(double_time, pawn, null, game)
|
||||||
pawn.on_card_effect_changed()
|
pawn.on_card_effect_changed()
|
||||||
boosted_pawns.append(pawn_id)
|
boosted_pawns.append(pawn_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ class_name Pawn
|
||||||
|
|
||||||
@export var Points = 1
|
@export var Points = 1
|
||||||
|
|
||||||
var attached_card_label: Label
|
|
||||||
var duration_label: Label
|
var duration_label: Label
|
||||||
var Temp_Color = 0
|
var Temp_Color = 0
|
||||||
var Double_Start = true
|
var Double_Start = true
|
||||||
var En_Passant = false
|
var En_Passant = false
|
||||||
const BASE_SIZE = Vector2(40, 40)
|
const BASE_SIZE = Vector2(40, 40)
|
||||||
const EFFECT_TINT_COLOR = Color(0.3, 0.8, 0.3, 0.5) # Green tint for card effects
|
const CARD_TINT_COLOR = Color(0.3, 0.8, 0.3, 0.5) # Green tint for card effects
|
||||||
|
const EFFECT_TINT_COLOR = Color(0.8, 0.2, 0.2, 0.5)
|
||||||
var id: String = Utils.generate_guid()
|
var id: String = Utils.generate_guid()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
|
@ -53,11 +53,15 @@ func update_appearance() -> void:
|
||||||
|
|
||||||
var deck_manager = chess_game.deckManager
|
var deck_manager = chess_game.deckManager
|
||||||
var has_card = deck_manager.attached_cards.has(get_instance_id())
|
var has_card = deck_manager.attached_cards.has(get_instance_id())
|
||||||
|
var has_effect = deck_manager.attached_effects.has(get_instance_id())
|
||||||
|
|
||||||
if has_card:
|
if has_card:
|
||||||
# Apply tint while keeping the piece color
|
# Apply tint while keeping the piece color
|
||||||
var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK
|
var base_color = Color.WHITE if Item_Color == 0 else Color.BLACK
|
||||||
modulate = base_color * EFFECT_TINT_COLOR
|
modulate = base_color * CARD_TINT_COLOR
|
||||||
|
|
||||||
|
if has_effect:
|
||||||
|
modulate = base_color * CARD_TINT_COLOR * EFFECT_TINT_COLOR
|
||||||
|
|
||||||
# Update duration display
|
# Update duration display
|
||||||
var card = deck_manager.attached_cards[get_instance_id()]
|
var card = deck_manager.attached_cards[get_instance_id()]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue