[
  {
    "id": "EOC_PERK_insight",
    "type": "effect_on_condition",
    "recurrence": "1 seconds",
    "condition": {
      "and": [
        { "u_has_flag": "MELEE_PERK_INSIGHT" },
        { "u_using_martial_art": "style_none" },
        { "x_in_y_chance": { "x": { "math": [ "u_val('perception')" ] }, "y": 20 } }
      ]
    },
    "effect": [
      {
        "if": { "and": [ { "u_has_flag": "MELEE_PERK_SIXTH_SENSE" }, { "math": [ "u_effect_intensity('perk_insight') < 20" ] } ] },
        "then": [
          {
            "if": { "math": [ "u_monsters_nearby('radius': 15) > 0" ] },
            "then": [ { "run_eocs": "EOC_GAIN_INSIGHT", "beta_talker": "avatar" } ]
          }
        ],
        "else": [ { "u_cast_spell": { "id": "perk_insight_spell" }, "targeted": true } ]
      }
    ],
    "false_effect": [ { "if": { "not": { "u_using_martial_art": "style_none" } }, "then": [ { "u_lose_effect": "perk_insight" } ] } ]
  },
  {
    "id": "EOC_PERK_SPEND_INSIGHT",
    "type": "effect_on_condition",
    "condition": { "u_has_flag": "MELEE_PERK_INSIGHT" },
    "effect": [ { "math": [ "u_perk_last_insight = u_effect_intensity('perk_insight')" ] }, { "u_lose_effect": "perk_insight" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PERK_MYSTIC_SHOT_CHAR",
    "eoc_type": "EVENT",
    "required_event": "character_ranged_attacks_character",
    "condition": { "u_has_flag": "MELEE_PERK_MYSTIC_SHOT" },
    "effect": [ { "run_eocs": "EOC_PERK_SPEND_INSIGHT" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PERK_MYSTIC_SHOT_MON",
    "eoc_type": "EVENT",
    "required_event": "character_ranged_attacks_monster",
    "condition": { "u_has_flag": "MELEE_PERK_MYSTIC_SHOT" },
    "effect": [ { "run_eocs": "EOC_PERK_SPEND_INSIGHT" } ]
  },
  {
    "id": "EOC_PERK_CLEAR_INSIGHT",
    "type": "effect_on_condition",
    "condition": { "math": [ "u_monsters_nearby('radius': 20) == 0" ] },
    "deactivate_condition": { "not": { "u_has_flag": "MELEE_PERK_INSIGHT" } },
    "recurrence": "20 seconds",
    "effect": [ { "u_lose_effect": "perk_insight" } ]
  },
  {
    "id": "EOC_PERK_TWILIGHT_FORM",
    "type": "effect_on_condition",
    "condition": { "u_has_flag": "MELEE_PERK_TWILIGHT_FORM" },
    "effect": [ { "u_add_effect": "perk_insight", "intensity": { "math": [ "u_perk_last_insight * 0.5" ] }, "duration": "4 days" } ]
  },
  {
    "id": "perk_insight_spell",
    "type": "SPELL",
    "name": "Insight",
    "description": "",
    "shape": "blast",
    "valid_targets": [ "hostile" ],
    "flags": [ "RANDOM_CRITTER", "RANDOM_TARGET", "NO_EXPLOSION_SFX", "SILENT" ],
    "min_range": 15,
    "max_range": 15,
    "effect": "effect_on_condition",
    "effect_str": "EOC_GAIN_INSIGHT"
  },
  {
    "id": "EOC_GAIN_INSIGHT",
    "type": "effect_on_condition",
    "effect": [
      {
        "if": {
          "or": [ { "npc_has_flag": "MELEE_PERK_INSIGHT_INFINITE" }, { "math": [ "n_effect_intensity('perk_insight') < 20" ] } ]
        },
        "then": [
          {
            "npc_add_effect": "perk_insight",
            "intensity": { "math": [ "n_effect_intensity('perk_insight') + perk_insight_scaling_factor()" ] },
            "duration": "4 days"
          }
        ]
      }
    ]
  }
]
