class_name EffectCtx extends RefCounted ## Context passed to effect callbacks. ## Provides access to the battle context, effect definition, target combatant, source, and potency. var ctx: BattleContext var def: EffectDef var potency: int var target: Combatant var source: NBattleObject func _init(context: BattleContext, def_val: EffectDef, potency_val: int, target_val: Combatant, source_val: NBattleObject) -> void: ctx = context def = def_val potency = potency_val target = target_val source = source_val ## Emits a trigger event for the given trigger definition. func emit_trigger(trigger_def: Variant) -> void: var resolved: NBattleObject = _resolve_trigger(trigger_def) if resolved == null: return var trigger: TriggerDef = resolved as TriggerDef if trigger == null: push_error("NBattle: Expected TriggerDef in emit_trigger") return var source_id: int = 0 if source: source_id = source.get_id() ctx._emit_event(TriggerEvent.new( trigger.get_id(), def.get_id(), target.get_id(), source_id, potency )) func _resolve_trigger(trigger_def: Variant) -> NBattleObject: if trigger_def is TriggerDef: return trigger_def if trigger_def is String: return ctx.get_trigger_def_by_name(trigger_def) if trigger_def is int: return ctx.get_trigger_def_by_id(trigger_def) push_error("NBattle: Invalid trigger_def type in emit_trigger") return null