[
  {
    "type": "effect_on_condition",
    "id": "EOC_BIOKIN_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "BIOKINETIC" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_BIOKINESIS" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'BIOKINETIC')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_CLAIR_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "CLAIRSENTIENT" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_CLAIRSENTIENCE" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'CLAIRSENTIENT')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_ELECTRO_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "ELECTROKINETIC" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_ELECTROKINESIS" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'ELECTROKINETIC')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PHOTO_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "PHOTOKINETIC" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_PHOTOKINESIS" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'PHOTOKINETIC')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PYRO_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "PYROKINETIC" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_PYROKINESIS" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'PYROKINETIC')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEKIN_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "TELEKINETIC" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_TELEKINESIS" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEKINETIC')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TEEP_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "TELEPATH" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_TELEPATHY" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEPATH')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPORT_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "TELEPORTER" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_TELEPORTATION" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEPORTER')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_VITAKIN_MATRIX_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "VITAKINETIC" }, { "u_has_wielded_with_flag": "MATRIX_CRYSTAL_VITAKINESIS" } ] },
    "effect": [ { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'VITAKINETIC')", "=", "4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_REDUCE_FOCUS_EFFECTS",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "not": { "u_has_trait": "PSI_EXTENDED_CHANNELING_ON" } },
    "effect": [ { "math": [ "u_spellcasting_adjustment('concentration', 'flag_whitelist': 'PSIONIC' )", "=", "-0.4" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_EXTENDED_CHANNELING",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "PSI_EXTENDED_CHANNELING_ON" },
    "effect": [
      { "math": [ "u_spellcasting_adjustment('casting_time', 'flag_whitelist': 'PSIONIC')", "=", "25" ] },
      { "math": [ "u_spellcasting_adjustment('concentration', 'flag_whitelist': 'PSIONIC' )", "=", "-1" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_EXTENDED_CHANNELING_ATTUNEMENT",
    "eoc_type": "EVENT",
    "required_event": "spellcasting_finish",
    "condition": {
      "and": [
        {
          "u_has_any_trait": [
            "BIOKINETIC",
            "CLAIRSENTIENT",
            "ELECTROKINETIC",
            "PHOTOKINETIC",
            "PYROKINETIC",
            "TELEKINETIC",
            "TELEPATH",
            "TELEPORTER",
            "VITAKINETIC"
          ]
        },
        {
          "or": [
            { "compare_string": [ "BIOKINETIC", { "context_val": "school" } ] },
            { "compare_string": [ "CLAIRSENTIENT", { "context_val": "school" } ] },
            { "compare_string": [ "ELECTROKINETIC", { "context_val": "school" } ] },
            { "compare_string": [ "PHOTOKINETIC", { "context_val": "school" } ] },
            { "compare_string": [ "PYROKINETIC", { "context_val": "school" } ] },
            { "compare_string": [ "TELEKINETIC", { "context_val": "school" } ] },
            { "compare_string": [ "TELEPATH", { "context_val": "school" } ] },
            { "compare_string": [ "TELEPORTER", { "context_val": "school" } ] },
            { "compare_string": [ "VITAKINETIC", { "context_val": "school" } ] }
          ]
        },
        { "u_has_trait": "PSI_EXTENDED_CHANNELING_ON" }
      ]
    },
    "effect": [ { "u_cast_spell": { "id": "psionic_drained_difficulty_five", "hit_self": true } } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_NETHER_ATTUNEMENT_BOOST",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_effect": "effect_nether_attunement_power_surge" },
    "effect": [
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'BIOKINETIC')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'CLAIRSENTIENT')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'ELECTROKINETIC')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'PHOTOKINETIC')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'PYROKINETIC')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEKINETIC')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEPATH')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEPORTER')", "=", "3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'VITAKINETIC')", "=", "3" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_DRAIN_RESIST_POTION_COMEDOWN_PENALTY",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_effect": "effect_noetic_resilience_comedown" },
    "effect": [
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'BIOKINETIC')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'CLAIRSENTIENT')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'ELECTROKINETIC')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'PHOTOKINETIC')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'PYROKINETIC')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEKINETIC')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEPATH')", "=", "-3" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'TELEPORTER')", "=", "-4" ] },
      { "math": [ "u_spellcasting_adjustment('caster_level', 'school': 'VITAKINETIC')", "=", "-4" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_END_PSI_POWERS",
    "//": "This should remove absolutely all powers.",
    "effect": [
      {
        "run_eocs": [
          "EOC_BIOKIN_REMOVE_OVERCOME_PAIN",
          "EOC_BIOKIN_REMOVE_PHYSICAL_ENHANCE",
          "EOC_BIOKIN_REMOVE_BREATHE_SKIN",
          "EOC_BIOKIN_REMOVE_CLIMATE_CONTROL",
          "EOC_BIOKIN_REMOVE_ENHANCE_MOBILITY",
          "EOC_BIOKIN_REMOVE_HAMMERHAND",
          "EOC_BIOKIN_REMOVE_REFLEX_ENHANCE",
          "EOC_BIOKIN_REMOVE_METABOLISM_ENHANCE",
          "EOC_CLAIR_REMOVE_NIGHT_EYES",
          "EOC_CLAIR_REMOVE_SPEED_READ",
          "EOC_CLAIR_REMOVE_DANGER_SENSE",
          "EOC_CLAIR_REMOVE_SEE_AURAS",
          "EOC_CLAIR_REMOVE_RANGED_ENHANCE",
          "EOC_CLAIR_REMOVE_DODGE_POWER",
          "EOC_CLAIR_REMOVE_CRAFT_BONUS",
          "EOC_CLAIR_REMOVE_CLEAR_SIGHT",
          "EOC_CLAIR_REMOVE_GROUP_TACTICS",
          "EOC_ELECTROKIN_REMOVE_SEE_ELECTRICITY",
          "EOC_ELECTROKIN_REMOVE_PERSONAL_BATTERY",
          "EOC_ELECTROKIN_REMOVE_REDUCE_PAIN",
          "EOC_PHOTOKIN_REMOVE_LIGHT_LOCAL",
          "EOC_PHOTOKIN_REMOVE_RAD_IMMUNITY",
          "EOC_PHOTOKIN_REMOVE_CAMOUFLAGE",
          "EOC_PHOTOKIN_REMOVE_HIDE_UGLY",
          "EOC_PHOTOKIN_REMOVE_RADIO",
          "EOC_PYRO_REMOVE_FIRE_TOOL",
          "EOC_PYRO_REMOVE_WARMTH_CLOAK",
          "EOC_PYRO_REMOVE_TORCH_WELD",
          "EOC_PYROKIN_REMOVE_FLAME_IMMUNITY",
          "EOC_TELEKIN_REMOVE_MOMENTUM",
          "EOC_TELEKIN_REMOVE_TELEKINETIC_STRENGTH",
          "EOC_TELEKIN_REMOVE_SHIELD",
          "EOC_TELEKIN_REMOVE_JACKING_TOOL",
          "EOC_TELEKIN_REMOVE_LEVITATION",
          "EOC_TELEPATH_REMOVE_TELEPATHIC_CONCENTRATION",
          "EOC_TELEPATH_REMOVE_TELEPATHIC_SHIELD",
          "EOC_TELEPATH_REMOVE_TELEPATHIC_MORALE",
          "EOC_TELEPATH_REMOVE_SENSE_MINDS",
          "EOC_TELEPORT_REMOVE_STRIDE",
          "EOC_VITAKIN_REMOVE_HEALTH_POWER",
          "EOC_VITAKIN_REMOVE_CURE_DISEASE",
          "EOC_VITAKIN_REMOVE_SUPER_HEAL",
          "EOC_VITAKIN_REMOVE_RETURN_FROM_DEATH"
        ]
      },
      { "u_lose_effect": "effect_biokin_armor_skin" },
      { "u_lose_effect": "effect_biokin_sealed" },
      { "u_lose_effect": "effect_biokin_combat_dance" },
      { "u_lose_effect": "effect_biokin_perfected_motion" },
      { "u_lose_effect": "effect_clair_sense_rads_self" },
      { "u_remove_item_with": "clair_sense_rad_item" },
      { "u_lose_effect": "effect_clair_perfect_shot" },
      { "u_lose_effect": "effect_clair_omniscence" },
      { "u_lose_effect": "effect_electrokin_zap_enemies" },
      { "u_lose_effect": "effect_electrokin_melee_attacks" },
      { "u_lose_effect": "effect_electrokinetic_speed_boost" },
      { "u_lose_effect": "effect_photokin_dodge" },
      { "u_lose_effect": "effect_photokin_invisibility" },
      { "u_lose_effect": "effect_photokin_arms" },
      { "u_lose_effect": "effect_pyrokinetic_aura" },
      { "u_lose_effect": "effect_pyrokinetic_flame_immunity" },
      { "u_lose_effect": "effect_telekinetic_slowfall" },
      { "u_lose_effect": "effect_telekinetic_aegis" },
      { "u_lose_effect": "effect_telepath_invisibility" },
      { "u_lose_effect": "effect_telepath_network_effect" },
      { "u_lose_effect": "effect_vitakin_purge_rads" },
      { "math": [ "u_vitamin('vitamin_maintained_powers')", "=", "0" ] },
      { "u_lose_effect": "effect_psi_intense_concentration" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_END_PSI_POWERS_MAINTAINED",
    "//": "This should remove only those powers which are toggleable.",
    "effect": [
      {
        "run_eocs": [
          "EOC_BIOKIN_REMOVE_OVERCOME_PAIN",
          "EOC_BIOKIN_REMOVE_PHYSICAL_ENHANCE",
          "EOC_BIOKIN_REMOVE_BREATHE_SKIN",
          "EOC_BIOKIN_REMOVE_CLIMATE_CONTROL",
          "EOC_BIOKIN_REMOVE_ENHANCE_MOBILITY",
          "EOC_BIOKIN_REMOVE_HAMMERHAND",
          "EOC_BIOKIN_REMOVE_REFLEX_ENHANCE",
          "EOC_BIOKIN_REMOVE_METABOLISM_ENHANCE",
          "EOC_CLAIR_REMOVE_NIGHT_EYES",
          "EOC_CLAIR_REMOVE_SPEED_READ",
          "EOC_CLAIR_REMOVE_DANGER_SENSE",
          "EOC_CLAIR_REMOVE_SEE_AURAS",
          "EOC_CLAIR_REMOVE_RANGED_ENHANCE",
          "EOC_CLAIR_REMOVE_DODGE_POWER",
          "EOC_CLAIR_REMOVE_CRAFT_BONUS",
          "EOC_CLAIR_REMOVE_CLEAR_SIGHT",
          "EOC_CLAIR_REMOVE_GROUP_TACTICS",
          "EOC_ELECTROKIN_REMOVE_SEE_ELECTRICITY",
          "EOC_ELECTROKIN_REMOVE_PERSONAL_BATTERY",
          "EOC_ELECTROKIN_REMOVE_REDUCE_PAIN",
          "EOC_PHOTOKIN_REMOVE_LIGHT_LOCAL",
          "EOC_PHOTOKIN_REMOVE_RAD_IMMUNITY",
          "EOC_PHOTOKIN_REMOVE_CAMOUFLAGE",
          "EOC_PHOTOKIN_REMOVE_HIDE_UGLY",
          "EOC_PHOTOKIN_REMOVE_RADIO",
          "EOC_PYRO_REMOVE_FIRE_TOOL",
          "EOC_PYRO_REMOVE_WARMTH_CLOAK",
          "EOC_PYRO_REMOVE_TORCH_WELD",
          "EOC_PYROKIN_REMOVE_FLAME_IMMUNITY",
          "EOC_TELEKIN_REMOVE_MOMENTUM",
          "EOC_TELEKIN_REMOVE_TELEKINETIC_STRENGTH",
          "EOC_TELEKIN_REMOVE_SHIELD",
          "EOC_TELEKIN_REMOVE_JACKING_TOOL",
          "EOC_TELEKIN_REMOVE_LEVITATION",
          "EOC_TELEPATH_REMOVE_TELEPATHIC_CONCENTRATION",
          "EOC_TELEPATH_REMOVE_TELEPATHIC_SHIELD",
          "EOC_TELEPATH_REMOVE_TELEPATHIC_MORALE",
          "EOC_TELEPATH_REMOVE_SENSE_MINDS",
          "EOC_TELEPORT_REMOVE_STRIDE",
          "EOC_VITAKIN_REMOVE_HEALTH_POWER",
          "EOC_VITAKIN_REMOVE_CURE_DISEASE",
          "EOC_VITAKIN_REMOVE_SUPER_HEAL",
          "EOC_VITAKIN_REMOVE_RETURN_FROM_DEATH"
        ]
      },
      { "math": [ "u_vitamin('vitamin_maintained_powers')", "=", "0" ] },
      { "u_lose_effect": "effect_psi_intense_concentration" }
    ]
  }
]
