Files
gd-playground/Game/Runtime/Handlers/EndTurnFlowHandler.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

71 lines
2.0 KiB
GDScript

class_name EndTurnFlowHandler
extends RefCounted
const BattlePhaseScript = preload("res://Game/Runtime/BattlePhase.gd")
const BattleEventTypeScript = preload("res://Game/Runtime/Queue/BattleEventType.gd")
const IntentStateScript = preload("res://Game/Runtime/IntentState.gd")
func handle(task, state) -> Array:
if not state.is_player_turn:
return []
state.set_phase(BattlePhaseScript.PLAYER_END)
if state.player.block > 0:
state.player.block = 0
state.event_bus.publish("block_cleared", {
"target": state.player.display_name,
"reason": "player_end_phase"
})
state.end_player_turn()
state.set_phase(BattlePhaseScript.ENEMY)
var intent = state.enemy_intent
match intent.intent_type:
IntentStateScript.ATTACK:
var dealt: int = state.player.take_damage(intent.value)
state.event_bus.publish(BattleEventTypeScript.DAMAGE_APPLIED, {
"source": state.enemy.display_name,
"target": state.player.display_name,
"amount": dealt
})
IntentStateScript.BUFF:
state.enemy.strength += intent.value
state.event_bus.publish("buff_applied", {
"target": state.enemy.display_name,
"type": "strength",
"amount": intent.value
})
IntentStateScript.DEBUFF:
state.player.apply_weak(intent.value)
state.event_bus.publish("debuff_applied", {
"target": state.player.display_name,
"type": "weak",
"turns": intent.value
})
state.event_bus.publish("enemy_action_resolved", {
"intent_code": intent.code(),
"value": intent.value
})
state.enemy.tick_end_of_turn()
if state.enemy.block > 0:
state.enemy.block = 0
state.event_bus.publish("block_cleared", {
"target": state.enemy.display_name,
"reason": "enemy_phase_end"
})
var planner = task.payload.get("intent_planner", null)
if planner != null:
state.enemy_intent = planner.advance(state.enemy)
state.event_bus.publish("intent_changed", {"intent": state.enemy_intent})
var prev_turn: int = state.turn_index
state.start_next_turn()
state.event_bus.publish(BattleEventTypeScript.TURN_ENDED, {
"turn": prev_turn
})
return []