{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "troika-spell",
    "title": "Troika! Spell",
    "description": "A spell in the Troika! RPG system",
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "Spell name"
        },
        "cost": {
            "oneOf": [
                {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Fixed stamina cost"
                },
                {
                    "type": "string",
                    "description": "Variable cost formula or special cost (e.g., 'double cost of original Spell', '?', '2 per viewer')"
                }
            ],
            "description": "Stamina cost to cast the spell"
        },
        "plasmicCoreSubstitution": {
            "type": "boolean",
            "default": true,
            "description": "Whether plasmic cores can be used instead of stamina (triggers death if Oops! occurs)"
        },
        "description": {
            "type": "string",
            "description": "Full spell description and effects"
        },
        "duration": {
            "type": "string",
            "description": "How long the spell lasts"
        },
        "range": {
            "type": "string",
            "description": "Spell range or targeting"
        },
        "testType": {
            "type": "string",
            "enum": [
                "rollUnder",
                "rollVersus",
                "automatic",
                "special"
            ],
            "description": "Type of test required to cast"
        },
        "requirements": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "description": "Special requirements (free hand, speech, components, etc.)"
        },
        "components": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "description": "Required components (e.g., 'corpse', 'skull', 'mirrors')"
        },
        "tags": {
            "type": "array",
            "items": {
                "type": "string",
                "enum": [
                    "offensive",
                    "defensive",
                    "utility",
                    "social",
                    "movement",
                    "illusion",
                    "divination",
                    "necromancy",
                    "elemental",
                    "transmutation",
                    "enchantment",
                    "conjuration"
                ]
            },
            "description": "Spell categories for organization"
        },
        "damageTable": {
            "$ref": "#/definitions/damageTable",
            "description": "Damage table for offensive spells"
        },
        "successTable": {
            "$ref": "#/definitions/successTable",
            "description": "Complex success table for spells like Posthumous Vitality"
        },
        "specialMechanics": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "description": "Special mechanical effects and rules"
        },
        "areaOfEffect": {
            "type": "string",
            "description": "Area of effect description (e.g., '24 metres', '30 metres around caster')"
        },
        "saves": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "type": {
                        "type": "string",
                        "enum": [
                            "luck",
                            "skill",
                            "none"
                        ]
                    },
                    "description": {
                        "type": "string"
                    },
                    "onSuccess": {
                        "type": "string"
                    },
                    "onFailure": {
                        "type": "string"
                    }
                },
                "required": [
                    "type"
                ]
            },
            "description": "Saving throws required by the spell"
        },
        "oopsEntry": {
            "type": "boolean",
            "default": true,
            "description": "Whether this spell triggers Oops! table on fumble"
        },
        "isUnknown": {
            "type": "boolean",
            "default": false,
            "description": "Whether this spell's effects are unknown (like Zed)"
        },
        "castingModifiers": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "condition": {
                        "type": "string"
                    },
                    "modifier": {
                        "type": "integer"
                    },
                    "description": {
                        "type": "string"
                    }
                },
                "required": [
                    "condition",
                    "modifier"
                ]
            },
            "description": "Modifiers to casting rolls under specific conditions"
        },
        "@context": {
            "type": [
                "string",
                "object",
                "array"
            ],
            "description": "JSON-LD context reference or inline context object"
        },
        "@id": {
            "type": "string",
            "description": "JSON-LD unique resource identifier URI"
        },
        "@type": {
            "type": [
                "string",
                "array"
            ],
            "description": "JSON-LD semantic resource type"
        }
    },
    "required": [
        "name",
        "cost",
        "description",
        "testType"
    ],
    "definitions": {
        "damageTable": {
            "type": "object",
            "properties": {
                "1": {
                    "type": "integer"
                },
                "2": {
                    "type": "integer"
                },
                "3": {
                    "type": "integer"
                },
                "4": {
                    "type": "integer"
                },
                "5": {
                    "type": "integer"
                },
                "6": {
                    "type": "integer"
                },
                "7+": {
                    "type": "integer"
                }
            },
            "required": [
                "1",
                "2",
                "3",
                "4",
                "5",
                "6",
                "7+"
            ]
        },
        "successTable": {
            "type": "object",
            "properties": {
                "diceExpression": {
                    "type": "string",
                    "description": "Dice expression for the table (e.g., '2d6+skill')"
                },
                "entries": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "range": {
                                "type": "string",
                                "description": "Result range (e.g., '4-12', '13-14', '17+')"
                            },
                            "effect": {
                                "type": "string",
                                "description": "Effect description"
                            }
                        },
                        "required": [
                            "range",
                            "effect"
                        ]
                    }
                }
            },
            "required": [
                "diceExpression",
                "entries"
            ]
        }
    }
}
