[
  {
    "//": "EoCs related to learning new powers and practicing existing powers are stored below",
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER",
    "condition": { "u_has_effect": "effect_psi_studying_power" },
    "effect": [
      { "math": [ "u_psi_studying_tick_experience_counter", "+=", "contemplation_factor(1)" ] },
      {
        "run_eocs": [
          {
            "id": "EOC_PSI_STUDYING_POWER_INTEGER_TICK_OVER",
            "condition": { "math": [ "u_psi_studying_tick_experience_counter >= 1" ] },
            "effect": [
              { "math": [ "u_spell_exp(u_latest_studied_power_name)", "+=", "1" ] },
              { "math": [ "u_psi_studying_tick_experience_counter", "-=", "1" ] }
            ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_INITIAL_SETUP",
    "effect": [
      { "u_message": "You attempt to unlock new capabilities within your mind." },
      { "run_eocs": "EOC_PSI_STUDYING_DUST_CONVERSION" },
      { "u_assign_activity": "ACT_PSI_LEARNING_NEW_POWER", "duration": "16 hours" },
      { "u_add_effect": "effect_psi_learning_new_power", "duration": "16 hours" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_BEGIN",
    "condition": { "not": { "u_has_any_effect": [ "weary_7", "weary_8" ] } },
    "effect": [
      { "u_message": "You spend some time meditating and contemplating your powers.", "type": "good" },
      { "math": [ "u_psi_studying_tick_experience_counter = 0" ] },
      { "u_add_effect": "effect_psi_studying_power", "duration": "24 hours" },
      { "u_assign_activity": "ACT_PSI_STUDYING_POWER", "duration": "24 hours" },
      { "run_eocs": "EOC_PSI_STUDYING_DUST_CONVERSION" },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_METAPHYSICS_GAIN", "time_in_future": [ "30 seconds", "5 minutes" ] }
    ],
    "false_effect": [ { "u_message": "You are too exhausted to contemplate anything.", "type": "bad" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_METAPHYSICS_GAIN",
    "condition": {
      "and": [
        { "u_has_effect": "effect_psi_studying_power" },
        { "math": [ "u_latest_studied_power_difficulty > u_skill('metaphysics')" ] }
      ]
    },
    "effect": [
      { "math": [ "u_skill_exp('metaphysics', 'format': 'raw')", "+=", "(35 * u_latest_studied_power_difficulty)" ] },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_METAPHYSICS_GAIN", "time_in_future": [ "30 seconds", "5 minutes" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_SIDE_EFFECTS",
    "effect": [
      { "run_eocs": "EOC_PSI_STUDYING_POWER_FOCUS_REDUCTION", "time_in_future": [ "1 minutes", "1 minutes" ] },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_ADD_PROFICIENCY", "time_in_future": [ "1 minutes", "1 minutes" ] },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_NETHER_ATTUNEMENT", "time_in_future": [ "3 minutes", "3 minutes" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_FOCUS_REDUCTION",
    "condition": { "u_has_effect": "effect_psi_studying_power" },
    "effect": [
      {
        "run_eocs": [
          {
            "id": "EOC_PSI_STUDYING_POWER_FOCUS_REDUCTION_2",
            "condition": { "math": [ "u_val('focus') >= 25" ] },
            "effect": [ { "math": [ "u_val('focus')", "-=", "rand(1)" ] } ]
          }
        ]
      },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_FOCUS_REDUCTION", "time_in_future": [ "1 minutes", "1 minutes" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_ADD_PROFICIENCY",
    "condition": { "u_has_effect": "effect_psi_studying_power" },
    "effect": [
      { "math": [ "u_proficiency(u_latest_studied_power_proficiency, 'format': 'percent')", "+=", "(rand(4) / 66)" ] },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_ADD_PROFICIENCY", "time_in_future": [ "1 minutes", "1 minutes" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_POWER_NETHER_ATTUNEMENT",
    "condition": { "u_has_effect": "effect_psi_studying_power" },
    "effect": [
      { "math": [ "u_vitamin('vitamin_psionic_drain')", "+=", "rand(2)" ] },
      { "math": [ "u_calories()", "-=", "psionics_contemplation_kcal_cost(u_latest_studied_power_difficulty)" ] },
      { "run_eocs": "EOC_PSI_STUDYING_POWER_NETHER_ATTUNEMENT", "time_in_future": [ "3 minutes", "3 minutes" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_DUST_CONVERSION",
    "condition": { "math": [ "u_latest_studied_power_difficulty > 3" ] },
    "effect": [ { "u_spawn_item": "matrix_crystal_drained_dust", "suppress_message": true } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_MOVING_CANCELS_RESEARCH",
    "eoc_type": "EVENT",
    "required_event": "avatar_moves",
    "condition": { "or": [ { "u_has_effect": "effect_psi_learning_new_power" }, { "u_has_effect": "effect_psi_studying_power" } ] },
    "effect": [ { "u_lose_effect": [ "effect_psi_learning_new_power", "effect_psi_studying_power" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_CHANNELING_CANCELS_RESEARCH",
    "eoc_type": "EVENT",
    "required_event": "spellcasting_finish",
    "condition": { "or": [ { "u_has_effect": "effect_psi_learning_new_power" }, { "u_has_effect": "effect_psi_studying_power" } ] },
    "effect": [ { "u_lose_effect": [ "effect_psi_learning_new_power", "effect_psi_studying_power" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_CANCELLING_ACTIVITY_CANCELS_RESEARCH",
    "eoc_type": "EVENT",
    "required_event": "character_finished_activity",
    "condition": {
      "and": [
        {
          "or": [
            { "compare_string": [ "ACT_PSI_LEARNING_NEW_POWER", { "context_val": "activity" } ] },
            { "compare_string": [ "ACT_PSI_STUDYING_POWER", { "context_val": "activity" } ] }
          ]
        },
        {
          "or": [ { "u_has_effect": "effect_psi_learning_new_power" }, { "u_has_effect": "effect_psi_studying_power" } ]
        }
      ]
    },
    "effect": [ { "u_lose_effect": [ "effect_psi_learning_new_power", "effect_psi_studying_power" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_TOO_TIRED_TO_STUDY",
    "eoc_type": "EVENT",
    "required_event": "character_gains_effect",
    "condition": {
      "and": [
        {
          "or": [
            { "compare_string": [ "weary_7", { "context_val": "effect" } ] },
            { "compare_string": [ "weary_8", { "context_val": "effect" } ] }
          ]
        },
        {
          "or": [ { "u_has_effect": "effect_psi_learning_new_power" }, { "u_has_effect": "effect_psi_studying_power" } ]
        }
      ]
    },
    "effect": [
      { "u_lose_effect": [ "effect_psi_learning_new_power", "effect_psi_studying_power" ] },
      {
        "u_message": "You're so exhausted you can barely think straight, and certainly can't concentrate on studying your powers.",
        "popup": true
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_LEARNING_BANNED_EFFECTS",
    "condition": {
      "not": {
        "u_has_any_effect": [
          "sleep",
          "effect_psi_learning_new_power",
          "effect_vitakin_wakeful_resting",
          "infected",
          "spores",
          "taint",
          "visuals",
          "hallu",
          "motor_seizure",
          "frostbite",
          "blisters",
          "formication",
          "pre_common_cold",
          "common_cold",
          "pre_flu",
          "flu",
          "pre_conjunctivitis_viral",
          "conjunctivitis_viral",
          "pre_conjunctivitis_bacterial",
          "conjunctivitis_bacterial",
          "asthma",
          "brainworms",
          "bloodworms",
          "grabbed",
          "lack_sleep",
          "sleep_deprived",
          "under_operation",
          "zapped",
          "electrocuted",
          "anemia",
          "redcells_anemia",
          "scurvy",
          "toxin_buildup",
          "bad_food_ennui",
          "hypovolemia",
          "disabled",
          "foodpoison",
          "venom_pain",
          "venom_dmg",
          "badpoison",
          "onfire",
          "dazed",
          "stunned"
        ]
      }
    },
    "effect": [  ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_CONDITION_PSI_REQUIRED_FOR_LEARNING_NEW_POWER",
    "condition": {
      "and": [
        { "u_has_effect": "effect_psi_learning_new_power" },
        {
          "not": { "u_has_any_effect": [ "sleep", "effect_vitakin_wakeful_resting", "lack_sleep", "sleep_deprived", "under_operation" ] }
        },
        { "not": { "u_has_trait": "CANNOT_GAIN_PSIONICS" } }
      ]
    },
    "effect": [  ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_BIOKIN_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_biokinesis", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_CLAIR_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_clairsentience", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_ELECTROKIN_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_electrokinesis", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_PHOTOKIN_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_photokinesis", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_PYROKIN_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_pyrokinesis", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_TELEKIN_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_telekinesis", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_TELEPATH_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_telepathy", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_TELEPORT_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_teleportation", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PSI_STUDYING_VITAKIN_POWER_SETUP",
    "effect": [
      { "set_string_var": "prof_contemplation_vitakinesis", "target_var": { "u_val": "latest_studied_power_proficiency" } },
      { "math": [ "u_latest_studied_power_difficulty = u_spell_difficulty(u_latest_studied_power_name)" ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PRACTICE_PSIONICS_FINAL_LEARNING_CHECK",
    "condition": {
      "roll_contested": { "math": [ "u_skill('metaphysics') + u_has_proficiency(u_latest_studied_power_proficiency)" ] },
      "difficulty": { "math": [ "learn_new_power_difficulty_setting()" ] }
    },
    "effect": [
      {
        "u_message": "You are studying <spell_name:<u_val:latest_studied_power_name>> whose ID is <u_val:latest_studied_power_name> with Difficulty <u_val:latest_studied_power_difficulty> and requires the <u_val:latest_studied_power_proficiency> proficiency",
        "type": "debug"
      },
      {
        "u_message": "As you meditate, all the pieces suddenly come together.  You've unlocked: <spell_name:<u_val:latest_studied_power_name>>.",
        "popup": true
      },
      { "math": [ "u_spell_level(u_latest_studied_power_name) = 1" ] },
      { "run_eocs": "EOC_PRACTICE_PSIONICS_FINAL_LEARNING_CHECK_SPECIAL_EXCEPTIONS" },
      {
        "math": [
          "u_vitamin('vitamin_psionic_drain')",
          "+=",
          "rng( learn_new_power_lower_nether_attunement_level(),learn_new_power_upper_nether_attunement_level() )"
        ]
      },
      { "u_lose_effect": "effect_psi_learning_new_power" },
      "u_cancel_activity"
    ],
    "false_effect": [
      { "u_message": "You just couldn't manage to grasp the technique.  You'll have to try again.", "popup": true },
      {
        "math": [
          "u_vitamin('vitamin_psionic_drain')",
          "+=",
          "rng( learn_new_power_lower_nether_attunement_level(),learn_new_power_upper_nether_attunement_level() )"
        ]
      },
      { "u_lose_effect": "effect_psi_learning_new_power" },
      "u_cancel_activity"
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_PRACTICE_PSIONICS_FINAL_LEARNING_CHECK_SPECIAL_EXCEPTIONS",
    "effect": [
      {
        "if": { "compare_string": [ "teleport_loci_establishment", { "u_val": "latest_studied_power_name" } ] },
        "then": [
          { "math": [ "u_spell_level('teleport_loci_technique') = 1" ] },
          { "u_learn_recipe": "practice_teleport_loci_technique" }
        ]
      }
    ]
  }
]
