working updates
This commit is contained in:
@@ -6,6 +6,7 @@ extends RefCounted
|
||||
signal game_started
|
||||
signal game_ended(winner_index: int)
|
||||
signal card_played(card: CardInstance, player_index: int)
|
||||
signal summon_cast(card: CardInstance, player_index: int)
|
||||
signal card_moved(card: CardInstance, from_zone: Enums.ZoneType, to_zone: Enums.ZoneType)
|
||||
signal damage_dealt(player_index: int, amount: int, cards: Array[CardInstance])
|
||||
signal forward_broken(card: CardInstance)
|
||||
@@ -106,7 +107,31 @@ func end_main_phase() -> void:
|
||||
turn_manager.advance_phase()
|
||||
|
||||
## Play a card from hand
|
||||
func play_card(player_index: int, card: CardInstance) -> bool:
|
||||
## Returns dictionary of CP spent, or empty dict on failure
|
||||
func play_card(player_index: int, card: CardInstance) -> Dictionary:
|
||||
if not game_active:
|
||||
return {}
|
||||
|
||||
if player_index != turn_manager.current_player_index:
|
||||
return {}
|
||||
|
||||
if not turn_manager.is_main_phase():
|
||||
return {}
|
||||
|
||||
var player = players[player_index]
|
||||
|
||||
# Validate and play (returns CP spent dict)
|
||||
var cp_spent = player.play_card(card)
|
||||
if not cp_spent.is_empty():
|
||||
card_played.emit(card, player_index)
|
||||
card_moved.emit(card, Enums.ZoneType.HAND,
|
||||
Enums.ZoneType.FIELD_FORWARDS if card.is_forward() else Enums.ZoneType.FIELD_BACKUPS)
|
||||
return cp_spent
|
||||
|
||||
return {}
|
||||
|
||||
## Cast a summon from hand
|
||||
func cast_summon(player_index: int, card: CardInstance) -> bool:
|
||||
if not game_active:
|
||||
return false
|
||||
|
||||
@@ -118,11 +143,15 @@ func play_card(player_index: int, card: CardInstance) -> bool:
|
||||
|
||||
var player = players[player_index]
|
||||
|
||||
# Validate and play
|
||||
if player.play_card(card):
|
||||
card_played.emit(card, player_index)
|
||||
card_moved.emit(card, Enums.ZoneType.HAND,
|
||||
Enums.ZoneType.FIELD_FORWARDS if card.is_forward() else Enums.ZoneType.FIELD_BACKUPS)
|
||||
# Cast the summon (pays cost, removes from hand)
|
||||
var cast_card = player.cast_summon(card)
|
||||
if cast_card:
|
||||
# Emit signal for effect resolution (TODO: implement effect system)
|
||||
summon_cast.emit(cast_card, player_index)
|
||||
|
||||
# Move to break zone after casting
|
||||
player.break_zone.add_card(cast_card)
|
||||
card_moved.emit(cast_card, Enums.ZoneType.HAND, Enums.ZoneType.BREAK)
|
||||
return true
|
||||
|
||||
return false
|
||||
@@ -168,6 +197,10 @@ func declare_attack(attacker: CardInstance) -> bool:
|
||||
if not turn_manager.is_attack_phase():
|
||||
return false
|
||||
|
||||
# Must be in DECLARATION step to declare attack
|
||||
if turn_manager.attack_step != Enums.AttackStep.DECLARATION:
|
||||
return false
|
||||
|
||||
var player = get_current_player()
|
||||
|
||||
if not player.field_forwards.has_card(attacker):
|
||||
@@ -181,7 +214,14 @@ func declare_attack(attacker: CardInstance) -> bool:
|
||||
attacker.dull()
|
||||
|
||||
attacker.attacked_this_turn = true
|
||||
turn_manager.set_attacker(attacker)
|
||||
|
||||
# Update attack step (now returns bool for validation)
|
||||
if not turn_manager.set_attacker(attacker):
|
||||
# Rollback dull if state transition failed
|
||||
if not attacker.has_brave():
|
||||
attacker.activate()
|
||||
attacker.attacked_this_turn = false
|
||||
return false
|
||||
|
||||
attack_declared.emit(attacker)
|
||||
return true
|
||||
@@ -203,7 +243,10 @@ func declare_block(blocker: CardInstance) -> bool:
|
||||
if not blocker.can_block():
|
||||
return false
|
||||
|
||||
turn_manager.set_blocker(blocker)
|
||||
# Update attack step (now returns bool for validation)
|
||||
if not turn_manager.set_blocker(blocker):
|
||||
return false
|
||||
|
||||
if blocker:
|
||||
block_declared.emit(blocker)
|
||||
|
||||
@@ -220,25 +263,37 @@ func resolve_combat() -> void:
|
||||
|
||||
var attacker = turn_manager.current_attacker
|
||||
var blocker = turn_manager.current_blocker
|
||||
var player = get_current_player()
|
||||
|
||||
# Validate attacker is still on field (could have been broken by ability)
|
||||
if not attacker or not player.field_forwards.has_card(attacker):
|
||||
turn_manager.complete_attack()
|
||||
return
|
||||
|
||||
if blocker == null:
|
||||
# Unblocked - deal 1 damage to opponent
|
||||
_deal_damage_to_player(1 - turn_manager.current_player_index, 1)
|
||||
else:
|
||||
# Blocked - exchange damage
|
||||
var attacker_power = attacker.get_power()
|
||||
var blocker_power = blocker.get_power()
|
||||
# Validate blocker is still on field
|
||||
var opponent = get_opponent()
|
||||
if not opponent.field_forwards.has_card(blocker):
|
||||
# Blocker was removed - attack goes through as unblocked
|
||||
_deal_damage_to_player(1 - turn_manager.current_player_index, 1)
|
||||
else:
|
||||
# Blocked - exchange damage
|
||||
var attacker_power = attacker.get_power()
|
||||
var blocker_power = blocker.get_power()
|
||||
|
||||
# Apply damage
|
||||
var attacker_broken = attacker.apply_damage(blocker_power)
|
||||
var blocker_broken = blocker.apply_damage(attacker_power)
|
||||
# Apply damage
|
||||
var attacker_broken = attacker.apply_damage(blocker_power)
|
||||
var blocker_broken = blocker.apply_damage(attacker_power)
|
||||
|
||||
# Break destroyed forwards
|
||||
if attacker_broken:
|
||||
_break_forward(attacker, turn_manager.current_player_index)
|
||||
# Break destroyed forwards
|
||||
if attacker_broken:
|
||||
_break_forward(attacker, turn_manager.current_player_index)
|
||||
|
||||
if blocker_broken:
|
||||
_break_forward(blocker, 1 - turn_manager.current_player_index)
|
||||
if blocker_broken:
|
||||
_break_forward(blocker, 1 - turn_manager.current_player_index)
|
||||
|
||||
combat_resolved.emit(attacker, blocker)
|
||||
turn_manager.complete_attack()
|
||||
|
||||
Reference in New Issue
Block a user