- 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.
51 lines
1.8 KiB
GDScript
51 lines
1.8 KiB
GDScript
class_name EffectRegistry
|
|
extends RefCounted
|
|
|
|
const DebugLogger = preload("res://Game/Infrastructure/Diagnostics/DebugLogger.gd")
|
|
const BattleEventTypeScript = preload("res://Game/Runtime/Queue/BattleEventType.gd")
|
|
|
|
func initialize(state) -> void:
|
|
# Core handlers are now registered in BattleState._register_core_handlers().
|
|
# Keep this method for compatibility with existing callers.
|
|
pass
|
|
|
|
func apply_specs(specs: Array, state, source, target) -> void:
|
|
initialize(state)
|
|
var queue: Array = specs.duplicate()
|
|
queue.sort_custom(func(a, b) -> bool: return a.priority > b.priority)
|
|
for spec in queue:
|
|
apply_spec(spec, state, source, target)
|
|
state.event_queue.run(state, state.event_bus)
|
|
|
|
func apply_spec(spec, state, source, target) -> void:
|
|
initialize(state)
|
|
match spec.type_id:
|
|
"damage":
|
|
var amount := int(spec.params.get("amount", 0))
|
|
var final_amount := _compute_attack_amount(amount, source)
|
|
state.event_queue.enqueue_event(BattleEventTypeScript.DAMAGE_REQUESTED, {
|
|
"source": source,
|
|
"target": target,
|
|
"amount": final_amount
|
|
}, "EffectRegistry")
|
|
"block":
|
|
var amount := int(spec.params.get("amount", 0))
|
|
state.event_queue.enqueue_event(BattleEventTypeScript.BLOCK_REQUESTED, {
|
|
"target": target,
|
|
"amount": amount
|
|
}, "EffectRegistry")
|
|
"weak":
|
|
var turns := int(spec.params.get("turns", 1))
|
|
state.event_queue.enqueue_event(BattleEventTypeScript.WEAK_APPLIED, {
|
|
"target": target,
|
|
"turns": turns
|
|
}, "EffectRegistry")
|
|
_:
|
|
DebugLogger.warn("EffectRegistry", "未知效果类型 type_id=%s" % spec.type_id)
|
|
|
|
func _compute_attack_amount(base_amount: int, source) -> int:
|
|
var amount: int = max(0, base_amount + source.strength)
|
|
if source.weak_turns > 0:
|
|
amount = int(floor(float(amount) * 0.75))
|
|
return max(0, amount)
|