Files
gd-playground/Game/Application/Commands/PlayCardCommand.gd
54shitaimzf e465f1cbb0 feat: 基础卡牌场景与卡牌逻辑可扩展框架,以及todo文档
- Added BattleState class to manage battle flow, including turn management and event handling.
- Introduced BuffInstance class to represent buffs applied to combatants.
- Created CardInstance class to handle card definitions and cost calculations.
- Developed CombatantState class to manage combatant attributes and actions.
- Implemented EffectRegistry to apply effects based on event specifications.
- Added various handlers (BlockHandler, DamageHandler, DrawHandler, etc.) to process specific events.
- Created IntentPlanner and IntentState classes to manage enemy actions and intents.
- Established a queue system for handling battle events with BattleEventQueue and BattleEventTask.
- Introduced triggers for applying effects based on game events (e.g., OnCardDrawnGainBlockTrigger).
- Added necessary UID files for new scripts to ensure proper resource management.
2026-04-22 21:58:15 +08:00

43 lines
1.3 KiB
GDScript

class_name PlayCardCommand
extends RefCounted
const BattlePhaseScript = preload("res://Game/Runtime/BattlePhase.gd")
const BattleEventTypeScript = preload("res://Game/Runtime/Queue/BattleEventType.gd")
func execute(state, effect_registry, hand_index: int, target_side: String) -> bool:
if not state.is_player_turn:
return false
if state.phase != BattlePhaseScript.PLAYER_PLAY:
return false
if hand_index < 0 or hand_index >= state.hand.size():
return false
var card_instance = state.hand[hand_index]
var cost: int = card_instance.get_cost()
if cost > state.energy:
return false
if not _is_target_valid(card_instance.card_def.targeting, target_side):
return false
state.event_queue.enqueue_event(BattleEventTypeScript.CARD_PLAY_REQUESTED, {
"hand_index": hand_index,
"target_side": target_side,
"effect_registry": effect_registry
}, "PlayCardCommand")
state.event_queue.run(state, state.event_bus)
return true
func _is_target_valid(targeting: int, target_side: String) -> bool:
match targeting:
ECardTargeting.NONE:
return true
ECardTargeting.SELF:
return target_side == "self"
ECardTargeting.SINGLE_ENEMY:
return target_side == "enemy"
ECardTargeting.ANY_UNIT:
return target_side == "self" or target_side == "enemy"
_:
return target_side == "enemy"