[
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_MESMERIZE",
    "condition": {
      "and": [
        { "not": { "u_has_flag": "TEEP_IMMUNE" } },
        {
          "not": {
            "and": [
              { "u_has_flag": "TEEPSHIELD" },
              {
                "math": [
                  "(u_spell_level('telepathic_shield') + u_spell_level('telepathic_shield_knack') ) >= ( n_spell_level('telepathic_mesmerize') + n_spell_level('telepathic_mesmerize_knack') )"
                ]
              }
            ]
          }
        },
        { "not": { "and": [ { "u_has_flag": "TEEPSHIELD" }, { "u_has_worn_with_flag": "PORTAL_PROOF" } ] } }
      ]
    },
    "effect": [
      { "math": [ "u_telepathy_intelligence = ( ( n_val('intelligence') + 10) / 20 )" ] },
      {
        "math": [
          "u_telepathy_mesmer_power_level = ( n_spell_level('telepathic_mesmerize') + n_spell_level('telepathic_mesmerize_knack') )"
        ]
      },
      { "math": [ "u_nether_attunement_telepathy_scaling = n_nether_attunement_power_scaling" ] },
      {
        "math": [
          "u_telepath_mesmerism_duration",
          "=",
          "rng( ( ( (u_telepathy_mesmer_power_level * 2) + 8) * u_telepathy_intelligence * u_nether_attunement_telepathy_scaling),( ( (u_telepathy_mesmer_power_level * 5) + 20) * u_telepathy_intelligence * u_nether_attunement_telepathy_scaling))"
        ]
      },
      {
        "run_eocs": [
          {
            "id": "EOC_TELEPATH_MESMERIZE_2",
            "condition": "u_is_character",
            "//": "If you're not totally immune, there's always a chance mesmerism will work",
            "effect": [
              {
                "if": {
                  "not": {
                    "x_in_y_chance": {
                      "x": { "math": [ "min((u_val('intelligence') + u_val('perception')), 30) + (rand(9) + 1) + (rand(9) + 1)" ] },
                      "y": 40
                    }
                  }
                },
                "then": [
                  { "u_add_effect": "psi_stunned", "duration": { "math": [ "u_telepath_mesmerism_duration" ] } },
                  {
                    "u_add_effect": "effect_telepath_mesmerize_tracker",
                    "duration": { "math": [ "u_telepath_mesmerism_duration" ] }
                  },
                  { "npc_message": "You mesmerize your target and they stand in a daze.", "type": "good" }
                ],
                "else": { "npc_message": "Your target resists the mesmerism!", "type": "bad" }
              }
            ],
            "false_effect": [
              {
                "if": {
                  "and": [
                    { "x_in_y_chance": { "x": 1, "y": 2 } },
                    {
                      "or": [ { "u_has_species": "MIGO" }, { "u_has_species": "NETHER" }, { "u_has_species": "PLANT" } ]
                    }
                  ]
                },
                "then": [
                  { "u_add_effect": "psi_stunned", "duration": { "math": [ "u_telepath_mesmerism_duration" ] } },
                  {
                    "u_add_effect": "effect_telepath_mesmerize_tracker",
                    "duration": { "math": [ "u_telepath_mesmerism_duration" ] }
                  },
                  { "npc_message": "You mesmerize the alien creature and it stands in a daze.", "type": "good" }
                ],
                "else": { "npc_message": "Your target resists the mesmerism!", "type": "bad" }
              },
              {
                "if": { "and": [ { "x_in_y_chance": { "x": 19, "y": 20 } }, { "u_has_species": "FERAL" } ] },
                "then": [
                  { "u_add_effect": "psi_stunned", "duration": { "math": [ "u_telepath_mesmerism_duration" ] } },
                  {
                    "u_add_effect": "effect_telepath_mesmerize_tracker",
                    "duration": { "math": [ "u_telepath_mesmerism_duration" ] }
                  },
                  { "npc_message": "You mesmerize the feral human and they stand in a daze.", "type": "good" }
                ],
                "else": { "npc_message": "Your target resists the mesmerism!", "type": "bad" }
              },
              {
                "if": {
                  "and": [
                    { "not": { "u_has_species": "FERAL" } },
                    { "not": { "u_has_species": "MIGO" } },
                    { "not": { "u_has_species": "PLANT" } },
                    { "not": { "u_has_species": "NETHER" } }
                  ]
                },
                "then": [
                  { "u_add_effect": "psi_stunned", "duration": { "math": [ "u_telepath_mesmerism_duration" ] } },
                  {
                    "u_add_effect": "effect_telepath_mesmerize_tracker",
                    "duration": { "math": [ "u_telepath_mesmerism_duration" ] }
                  },
                  { "npc_message": "You mesmerize your target and they stand in a daze.", "type": "good" }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_MESMERISM_REMOVAL_CHARACTER",
    "eoc_type": "EVENT",
    "required_event": "character_takes_damage",
    "condition": { "and": [ { "u_has_effect": "psi_stunned" }, { "u_has_effect": "effect_telepath_mesmerize_tracker" } ] },
    "effect": [ { "u_lose_effect": [ "effect_telepath_mesmerize_tracker", "psi_stunned" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_MESMERISM_REMOVAL_MONSTER",
    "eoc_type": "EVENT",
    "required_event": "monster_takes_damage",
    "condition": { "and": [ { "u_has_effect": "psi_stunned" }, { "u_has_effect": "effect_telepath_mesmerize_tracker" } ] },
    "effect": [ { "u_lose_effect": [ "effect_telepath_mesmerize_tracker", "psi_stunned" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_MORALE_INITIATE",
    "condition": "u_is_avatar",
    "effect": [ { "run_eocs": "EOC_TELEPATH_MORALE_INITIATE_SELF" } ],
    "false_effect": [
      {
        "run_eocs": [
          {
            "id": "EOC_TELEPATH_MORALE_INITIATE_NPC_CHECK",
            "condition": "u_is_npc",
            "effect": [
              { "math": [ "u_telepathy_intelligence = ( ( n_val('intelligence') + 10) / 20 )" ] },
              {
                "math": [ "u_telepathy_power_level = (n_spell_level('telepathic_morale') + n_spell_level('telepathic_morale_knack') )" ]
              },
              { "math": [ "u_nether_attunement_telepathy_scaling = n_nether_attunement_power_scaling" ] },
              {
                "math": [
                  "u_mood_stabilized_power_level",
                  "=",
                  "u_telepathy_power_level * u_telepathy_intelligence * u_nether_attunement_telepathy_scaling"
                ]
              },
              { "run_eocs": "EOC_TELEPATH_MORALE_MODIFY_NPC_VALUES" }
            ],
            "false_effect": [
              { "math": [ "u_telepathy_intelligence = ( ( n_val('intelligence') + 10) / 20 )" ] },
              {
                "math": [ "u_telepathy_power_level = (n_spell_level('telepathic_morale') + n_spell_level('telepathic_morale_knack') )" ]
              },
              { "math": [ "u_nether_attunement_telepathy_scaling = n_nether_attunement_power_scaling" ] },
              {
                "math": [
                  "u_mood_stabilized_power_level",
                  "=",
                  "u_telepathy_power_level * u_telepathy_intelligence * u_nether_attunement_telepathy_scaling"
                ]
              },
              { "run_eocs": "EOC_TELEPATH_MORALE_MODIFY_MONSTER_VALUES" }
            ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_MORALE_MODIFY_NPC_VALUES",
    "condition": { "not": { "u_has_effect": "effect_telepath_mood_stabilization_attitude_modified" } },
    "effect": [
      {
        "run_eocs": [
          {
            "id": "EOC_TELEPATH_MORALE_MODIFY_NPC_VALUES_2",
            "condition": { "not": { "u_has_effect": "effect_telepathic_psi_armor" } },
            "effect": [
              { "math": [ "u_npc_fear() = max(-10, (u_npc_fear() - (u_mood_stabilized_power_level / 2)))" ] },
              { "math": [ "u_npc_anger() = max(-10, (u_npc_anger() - (u_mood_stabilized_power_level / 2)))" ] },
              { "math": [ "u_npc_trust() = min(20, (u_npc_trust() + (u_mood_stabilized_power_level / 4)))" ] },
              {
                "npc_message": "You reach in and, with a deft touch, sooth your target's negative emotions.",
                "type": "good"
              },
              { "u_add_effect": "effect_telepath_mood_stabilization_attitude_modified", "duration": "12 hours" }
            ],
            "false_effect": [
              {
                "npc_message": "You attempt to edit the target's mood, but your powers slam into a smooth, unyielding barrier and slide off.",
                "type": "bad"
              }
            ]
          }
        ]
      }
    ],
    "false_effect": [
      { "npc_message": "You don't want to risk affecting the target's mind too quickly, and withdraw.", "type": "neutral" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_MORALE_MODIFY_MONSTER_VALUES",
    "condition": { "not": { "u_has_effect": "effect_telepath_mood_stabilization_attitude_modified" } },
    "effect": [
      {
        "run_eocs": [
          {
            "id": "EOC_TELEPATH_MORALE_MODIFY_MONSTER_VALUES_2",
            "condition": { "not": { "u_has_effect": "effect_telepathic_psi_armor" } },
            "effect": [
              { "math": [ "u_val('anger')", "-=", "u_mood_stabilized_power_level * 5" ] },
              {
                "npc_message": "You reach in and, with a deft touch, sooth your target's negative emotions.",
                "type": "good"
              },
              { "u_add_effect": "effect_telepath_mood_stabilization_attitude_modified", "duration": "5 minutes" }
            ],
            "false_effect": [
              {
                "npc_message": "You attempt to edit the target's mood, but your powers slam into a smooth, unyielding barrier and slide off.",
                "type": "bad"
              }
            ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_OBSCURITY_REMOVAL_CHARACTER",
    "eoc_type": "EVENT",
    "required_event": "character_takes_damage",
    "condition": { "and": [ { "u_has_effect": "telepathic_ignorance" }, { "npc_has_effect": "telepathic_ignorance_self" } ] },
    "effect": [ { "u_lose_effect": "telepathic_ignorance" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_OBSCURITY_REMOVAL_MONSTER",
    "eoc_type": "EVENT",
    "required_event": "monster_takes_damage",
    "condition": { "and": [ { "u_has_effect": "telepathic_ignorance" }, { "npc_has_effect": "telepathic_ignorance_self" } ] },
    "effect": [ { "u_lose_effect": "telepathic_ignorance" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_PRIMAL_TERROR",
    "condition": {
      "and": [
        { "not": { "u_has_flag": "TEEP_IMMUNE" } },
        {
          "not": {
            "and": [
              { "u_has_flag": "TEEPSHIELD" },
              {
                "math": [
                  "(u_spell_level('telepathic_shield') + u_spell_level('telepathic_shield_knack') ) >= n_spell_level('telepathic_fear')"
                ]
              }
            ]
          }
        },
        { "not": { "and": [ { "u_has_flag": "TEEPSHIELD" }, { "u_has_worn_with_flag": "PORTAL_PROOF" } ] } }
      ]
    },
    "effect": [
      { "math": [ "u_telepathy_intelligence = ( ( n_val('intelligence') + 10) / 20 )" ] },
      { "math": [ "u_telepathy_power_level = n_spell_level('telepathic_fear')" ] },
      { "math": [ "u_nether_attunement_telepathy_scaling = n_nether_attunement_power_scaling" ] },
      {
        "u_add_effect": "psi_stunned",
        "duration": {
          "math": [
            "rng( ( ( ( ( ( (u_telepathy_power_level * 0.25 ) * 6 ) /  ( (u_telepathy_power_level * 0.25 ) + 3) ) ) * (u_telepathy_intelligence ) ) * u_nether_attunement_telepathy_scaling),( ( ( ( ( (u_telepathy_power_level * 0.25 ) * 10 ) /  ( (u_telepathy_power_level * 0.25 ) + 3) ) ) * (u_telepathy_intelligence ) ) * u_nether_attunement_telepathy_scaling) )"
          ]
        }
      },
      {
        "u_add_effect": "effect_telepathic_primal_terror",
        "duration": {
          "math": [
            "rng( ( ( (u_telepathy_power_level * 0.75) + 2) * u_telepathy_intelligence * u_nether_attunement_telepathy_scaling),( ( (u_telepathy_power_level * 1.75) + 5) * u_telepathy_intelligence * u_nether_attunement_telepathy_scaling) )"
          ]
        }
      },
      { "run_eocs": "EOC_TELEPATH_PRIMAL_TERROR_ATTITUDE" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_PRIMAL_TERROR_ATTITUDE",
    "condition": { "not": { "u_has_effect": "effect_telepath_primal_terror_attitude_modified" } },
    "effect": [
      {
        "run_eocs": [
          {
            "id": "EOC_TELEPATH_PRIMAL_TERROR_ATTITUDE_2",
            "condition": "u_is_npc",
            "effect": [
              { "math": [ "u_npc_fear()", "+=", "u_telepathy_power_level / 2" ] },
              { "u_add_effect": "effect_telepath_primal_terror_attitude_modified", "duration": "1 hours" }
            ],
            "false_effect": [
              { "math": [ "u_val('morale')", "-=", "u_telepathy_power_level * 5" ] },
              { "u_add_effect": "effect_telepath_primal_terror_attitude_modified", "duration": "1 hours" }
            ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_TELEPATH_NETWORK_ALLY_CHECK",
    "condition": { "npc_allies": 1 },
    "//": "Ideally this would check for allies within a certain radius nearby, something like u_npcs_nearby, but that doesn't seem to be possible.",
    "effect": [
      {
        "u_cast_spell": {
          "id": "telepathic_network_real",
          "hit_self": true,
          "message": "You now have an instinctive awareness of your allies, and they of you."
        }
      }
    ],
    "false_effect": [ { "u_message": "With no nearby allies, there is no one to network with.", "type": "bad" } ]
  }
]
