[
  {
    "type": "jmath_function",
    "id": "limit_caster_level_boost",
    "num_args": 2,
    "return": "floor( min(_0, ( 1 + ( _1 / 5 ) ) ) )",
    "//": "Limits caster level boost to 1 + (highest level of spell in the relevant school) / 5"
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_magus_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "MAGUS" },
    "effect": [
      {
        "math": [
          "u_level_boost",
          "=",
          "u_val('item_count', 'item: magus_booster_1_active') + u_val('item_count', 'item: magus_booster_2_active') * 2"
        ]
      },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: MAGUS')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: MAGUS') )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_kelvinist_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "KELVINIST" },
    "effect": [
      {
        "math": [
          "u_level_boost",
          "=",
          "u_val('item_count', 'item: kelvinist_booster_1_active') + u_val('item_count', 'item: kelvinist_booster_2_active') * 2"
        ]
      },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: KELVINIST')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: KELVINIST') )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_technomancer_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "TECHNOMANCER" },
    "effect": [
      {
        "math": [
          "u_level_boost",
          "=",
          "max( 0, u_val('effect_intensity', 'effect: technomancer_cl_booster_effect') ) + u_val('charge_count', 'item: technomancer_booster_2_active') / 5"
        ]
      },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: TECHNOMANCER')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: TECHNOMANCER') )"
        ]
      },
      {
        "math": [
          "u_doodad_boost",
          "=",
          "max( 0, limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: TECHNOMANCER') ) - max( 0, u_val('effect_intensity', 'effect: technomancer_cl_booster_effect') ) )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_technomancer_caster_level_boost_finish_casting",
    "eoc_type": "EVENT",
    "required_event": "spellcasting_finish",
    "condition": { "and": [ { "u_has_trait": "TECHNOMANCER" }, { "compare_string": [ "TECHNOMANCER", { "context_val": "school" } ] } ] },
    "effect": [
      {
        "u_consume_item": "technomancer_booster_2_active",
        "charges": { "math": [ "floor( u_doodad_boost ) * 5" ] },
        "count": 0
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_biomancer_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "BIOMANCER" },
    "effect": [
      { "math": [ "u_level_boost", "=", "max( 0, u_val('effect_intensity', 'effect: biomancer_cl_booster_effect') )" ] },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: BIOMANCER')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: BIOMANCER') )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_animist_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "ANIMIST" },
    "effect": [
      { "math": [ "u_level_boost", "=", "u_val('field_strength', 'field: fd_blood')" ] },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: ANIMIST')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: ANIMIST') )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_stormshaper_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "and": [ { "u_has_trait": "STORMSHAPER" }, "u_is_outside" ] },
    "effect": [
      { "math": [ "u_level_boost", "=", "weather('precipitation') * 2" ] },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: STORMSHAPER')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: STORMSHAPER') )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_earthshaper_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "EARTHSHAPER" },
    "effect": [
      { "math": [ "u_level_boost", "=", "max(0, -u_val('pos_z') )" ] },
      {
        "run_eocs": [
          {
            "id": "EOC_earthshaper_caster_level_boost_1",
            "condition": {
              "or": [
                { "u_is_on_terrain": "t_dirt" },
                { "u_is_on_terrain": "t_sand" },
                { "u_is_on_terrain": "t_sandbox" },
                { "u_is_on_terrain": "t_mud" },
                { "u_is_on_terrain": "t_rock_floor_no_roof" },
                { "u_is_on_terrain": "t_dirtfloor_no_roof" }
              ]
            },
            "effect": { "math": [ "u_level_boost", "=", "1" ] }
          },
          {
            "id": "EOC_earthshaper_caster_level_boost_2",
            "condition": {
              "or": [
                { "u_is_on_terrain": "t_clay" },
                { "u_is_on_terrain": "t_claymound" },
                { "u_is_on_terrain": "t_sandmound" },
                { "u_is_on_terrain": "t_dirtmoundfloor" },
                { "u_is_on_terrain": "t_dirtmound" }
              ]
            },
            "effect": { "math": [ "u_level_boost", "=", "2" ] }
          },
          {
            "id": "EOC_earthshaper_caster_level_boost_3",
            "condition": { "or": [ { "u_is_on_terrain": "t_pit_shallow" } ] },
            "effect": { "math": [ "u_level_boost", "=", "3" ] }
          },
          {
            "id": "EOC_earthshaper_caster_level_boost_5",
            "condition": { "or": [ { "u_is_on_terrain": "t_pit" } ] },
            "effect": { "math": [ "u_level_boost", "=", "5" ] }
          }
        ]
      },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: EARTHSHAPER')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: EARTHSHAPER') )"
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_druid_caster_level_boost",
    "eoc_type": "EVENT",
    "required_event": "opens_spellbook",
    "condition": { "u_has_trait": "DRUID" },
    "effect": [
      { "math": [ "u_level_boost", "=", "0" ] },
      {
        "run_eocs": [
          {
            "id": "EOC_druid_caster_level_boost_1",
            "condition": {
              "or": [
                { "u_is_on_terrain": "t_grass" },
                { "u_is_on_terrain": "t_grass_white" },
                { "u_is_on_terrain": "t_moss" },
                { "u_is_on_terrain": "t_moss_underground" },
                { "u_is_on_terrain": "t_forestfloor" }
              ]
            },
            "effect": { "math": [ "u_level_boost", "=", "1" ] }
          },
          {
            "id": "EOC_druid_caster_level_boost_2",
            "condition": {
              "or": [
                { "u_is_on_terrain": "t_grass_tall" },
                { "u_is_on_terrain": "t_grass_long" },
                { "u_is_on_terrain": "t_bamboo" },
                { "u_is_on_terrain": "t_bamboo_harvested" },
                { "u_is_on_terrain": "t_underbrush_harvested_winter" }
              ]
            },
            "effect": { "math": [ "u_level_boost", "=", "2" ] }
          },
          {
            "id": "EOC_druid_caster_level_boost_3",
            "condition": {
              "or": [
                { "u_is_on_terrain_with_flag": "SHRUB" },
                { "u_is_on_terrain": "t_bamboo_long" },
                { "u_is_on_terrain": "t_bamboo_tall" }
              ]
            },
            "effect": { "math": [ "u_level_boost", "=", "3" ] }
          },
          {
            "id": "EOC_druid_caster_level_boost_5",
            "condition": {
              "or": [
                { "u_is_on_terrain": "t_tree_young" },
                { "u_is_on_terrain": "t_mega_fern" },
                { "u_is_on_terrain": "t_fungus_colony" }
              ]
            },
            "effect": { "math": [ "u_level_boost", "=", "5" ] }
          }
        ]
      },
      {
        "math": [
          "u_val('spell_level_adjustment', 'school: DRUID')",
          "=",
          "limit_caster_level_boost(u_level_boost, u_val('spell_level', 'school: DRUID') )"
        ]
      }
    ]
  }
]
