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

28 lines
828 B
GDScript

class_name DamageHandler
extends RefCounted
const BattleEventTypeScript = preload("res://Game/Runtime/Queue/BattleEventType.gd")
const BattleEventTaskScript = preload("res://Game/Runtime/Queue/BattleEventTask.gd")
func handle(task, state) -> Array:
var source = task.payload.get("source", null)
var target = task.payload.get("target", null)
var amount: int = int(task.payload.get("amount", 0))
if source == null or target == null:
return []
var dealt: int = target.take_damage(amount)
state.event_bus.publish(BattleEventTypeScript.DAMAGE_APPLIED, {
"source": source.display_name,
"target": target.display_name,
"amount": dealt
})
return [
BattleEventTaskScript.new(BattleEventTypeScript.DAMAGE_APPLIED, {
"source": source,
"target": target,
"amount": dealt
}, task.chain_id, "DamageHandler")
]