apply_effect
Apply SRD conditions or custom effects to characters in D&D 5e campaigns. Use standard templates for conditions like blinded or poisoned, or create custom effects with specific modifiers for gameplay management.
Instructions
Apply an ActiveEffect to a character (SRD condition or custom effect).
For SRD conditions (blinded, charmed, deafened, exhaustion, frightened, grappled, incapacitated, invisible, paralyzed, petrified, poisoned, prone, restrained, stunned), uses the standard condition template.
For custom effects, creates a new ActiveEffect with the provided modifiers.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| character_name_or_id | Yes | Character name, ID, or player name. | |
| effect_name | Yes | Effect name (SRD condition like 'blinded', 'poisoned', or custom name) | |
| source | No | Source of the effect (e.g., 'Poison trap', 'Hold Person spell') | |
| duration | No | Duration in rounds. None for permanent effects. | |
| custom_modifiers | No | JSON list of custom modifiers, e.g. '[{"stat":"attack_roll","operation":"add","value":2}]' |
Implementation Reference
- The implementation of `EffectsEngine.apply_effect` which adds an effect to a character's list of active effects, handling stackability and unique ID generation.
def apply_effect(character: "Character", effect: ActiveEffect) -> ActiveEffect: """Apply an active effect to a character. Creates a deep copy of the effect with a unique ID and adds it to the character's active_effects list. Non-stackable effects with the same name will not be duplicated; the existing one is kept. Args: character: The character to apply the effect to. effect: The effect template to apply. Returns: The applied ActiveEffect instance (with unique ID), or the existing one if a non-stackable duplicate was found. """ # Check for non-stackable duplicates if not effect.stackable: for existing in character.active_effects: if existing.name == effect.name: return existing # Deep copy to avoid shared state between characters applied = deepcopy(effect) applied.id = random(length=8) character.active_effects.append(applied) return applied