[
  {
    "type": "effect_on_condition",
    "id": "EOC_CONDITION_CHECK_HOMULLUS_IN_CIVILIZATION_ON_OMT_ENTER",
    "eoc_type": "EVENT",
    "required_event": "avatar_enters_omt",
    "condition": { "u_has_trait": "HOMULLUS" },
    "effect": [
      { "u_location_variable": { "context_val": "check_loc" } },
      {
        "run_eocs": [
          {
            "id": "EOC_CONDITION_CHECK_HOMULLUS_IN_CIVILIZATION_ON_OMT_ENTER_2",
            "condition": {
              "or": [
                { "test_eoc": "EOC_CONDITION_HOMULLUS_NEAR_FACTION" },
                { "u_near_om_location": "FACTION_CAMP_ANY", "range": 2 },
                { "map_in_city": { "context_val": "check_loc" } }
              ]
            },
            "effect": [ { "math": [ "u_homullus_is_in_civilization = 1" ] } ],
            "false_effect": [ { "math": [ "u_homullus_is_in_civilization = 0" ] } ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_CONDITION_HOMULLUS_NEAR_FACTION",
    "condition": {
      "or": [
        { "u_near_om_location": "evac_center_13", "range": 3 },
        { "u_near_om_location": "evac_center_18", "range": 6 },
        { "u_near_om_location": "isolated_road_field_0", "range": 2 },
        { "u_near_om_location": "horse_farm_isherwood_9", "range": 3 },
        { "u_near_om_location": "farm_isherwood_2", "range": 3 },
        { "u_near_om_location": "dairy_farm_isherwood_SW", "range": 3 },
        { "u_near_om_location": "lumbermill_0_0_ocu", "range": 1 },
        { "u_near_om_location": "ranch_camp_41", "range": 6 },
        { "u_near_om_location": "godco_5", "range": 3 },
        { "u_near_om_location": "smallscrapyard_ocu", "range": 1 },
        { "u_near_om_location": "robofachq_surface_entrance", "range": 4 }
      ]
    },
    "effect": [  ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_IN_CIVILIZATION_CHECKER_CONDITION",
    "condition": { "math": [ "u_homullus_is_in_civilization == 1" ] },
    "effect": [  ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_SELF_DECEPTION",
    "effect": [
      { "u_lose_morale": "morale_homullus_self_deception" },
      {
        "u_add_morale": "morale_homullus_self_deception",
        "bonus": { "math": [ "( 5 + u_spell_level('homullus_self_deception_spell') ) * scaling_factor(u_val('perception') )" ] },
        "max_bonus": 40,
        "duration": {
          "math": [ "( 3600 + (u_spell_level('homullus_self_deception_spell') * 900) ) * scaling_factor(u_val('perception') )" ]
        },
        "decay_start": {
          "math": [ "( 3600 + (u_spell_level('homullus_self_deception_spell') * 900) ) * scaling_factor(u_val('perception') ) / 2" ]
        }
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_NO_TRACE_ON",
    "condition": { "not": { "u_has_trait": "NO_TRACE_YET_I_WISH_active" } },
    "effect": [ { "u_add_trait": "NO_TRACE_YET_I_WISH_active" }, { "u_message": "Your body stops producing scent.", "type": "good" } ],
    "false_effect": [
      { "u_lose_trait": "NO_TRACE_YET_I_WISH_active" },
      { "u_message": "Your body begins producing scent.", "type": "neutral" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_BACKSTAGE_ON",
    "condition": { "not": { "u_has_trait": "HOMULLUS_BACKSTAGE_active" } },
    "effect": [
      { "u_add_trait": "HOMULLUS_BACKSTAGE_active" },
      { "u_message": "You seem to fade into the background.", "type": "good" }
    ],
    "false_effect": [ { "u_lose_trait": "HOMULLUS_BACKSTAGE_active" }, { "u_message": "You become more noticeable.", "type": "neutral" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_RUNNING_GIVE_STAMINA",
    "eoc_type": "EVENT",
    "required_event": "avatar_moves",
    "condition": {
      "and": [ { "u_has_trait": "HOMULLUS_THE_HUNTER2" }, { "compare_string": [ "run", { "context_val": "movement_mode" } ] } ]
    },
    "effect": [ { "math": [ "u_val('stamina')", "+=", "rng(40,65)" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_INVISIBLE_TO_HUMANS",
    "condition": {
      "or": [
        "u_is_npc",
        {
          "or": [ { "u_has_species": "FERAL" }, { "and": [ { "not": { "u_has_species": "ZOMBIE" } }, { "u_has_species": "HUMAN" } ] } ]
        }
      ]
    },
    "effect": [
      {
        "u_add_effect": "telepathic_ignorance",
        "duration": {
          "math": [ "( 6000 + (u_spell_level('homullus_invisible_to_humans_spell') * 3000) ) * scaling_factor(u_val('intelligence') )" ]
        }
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DREAMWALKER_GAIN_DREAMDROSS",
    "eoc_type": "EVENT",
    "required_event": "character_wakes_up",
    "condition": {
      "and": [
        { "or": [ { "u_has_trait": "HOMULLUS_DREAMWALKER" }, { "u_has_trait": "CHANGELING_NOBLE_DREAMWALKER" } ] },
        {
          "x_in_y_chance": { "x": { "math": [ "1 + u_has_trait('THRESH_HOMULLUS') + u_has_trait('THRESH_FAIR_FOLK_NOBLE')" ] }, "y": 10 }
        },
        { "math": [ "u_characters_nearby('radius': 30, 'attitude': 'any') > 0" ] }
      ]
    },
    "effect": [
      {
        "u_message": "As you awaken from the remnants of another's dreams, you find scraps of dreamdross next to you.",
        "type": "neutral"
      },
      { "u_spawn_item": "scrap_dreamdross", "count": { "math": [ "rng(1,4)" ] } }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_GOBLIN_FRUIT",
    "condition": { "test_eoc": "EOC_HOMULLUS_IN_CIVILIZATION_CHECKER_CONDITION" },
    "effect": { "u_spawn_item": "spell_spawned_goblin_fruit_homullus", "use_item_group": true, "suppress_message": true },
    "false_effect": [ { "u_message": "You must be in the remnants of civilization to call forth a goblin fruit.", "type": "bad" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_GAIN_BIONIC_POWER_IN_CITIES",
    "recurrence": "30 seconds",
    "condition": { "or": [ { "u_has_any_trait": [ "HOMULLUS_GAIN_BIONIC_POWER", "HOMULLUS_GAIN_BIONIC_POWER_AND_MANA" ] } ] },
    "deactivate_condition": { "not": { "u_has_any_trait": [ "HOMULLUS_GAIN_BIONIC_POWER", "HOMULLUS_GAIN_BIONIC_POWER_AND_MANA" ] } },
    "effect": [ { "math": [ "u_val('power')", "+=", "energy('1 kJ') + (energy('1 kJ') * u_has_trait('THRESH_HOMULLUS'))" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "HOMULLUS_MIGRATE_TO_MIMIMIZED_MUTATIONS",
    "//": "For pre-existing homullus characters that don't have the mutation blocker mutation.",
    "eoc_type": "EVENT",
    "required_event": "game_begin",
    "condition": {
      "and": [
        { "u_has_trait": "HOMULLUS" },
        { "not": { "u_has_trait": "HOMULLUS_MINIMIZED_MUTATIONS" } },
        { "not": { "u_has_trait": "HOMULLUS_EXPANDED_MUTATIONS" } }
      ]
    },
    "effect": [ { "u_add_trait": "HOMULLUS_MINIMIZED_MUTATIONS" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_CUT_OFF_FURTHER_HOMULLUS_MUTATIONS",
    "eoc_type": "EVENT",
    "required_event": "character_consumes_item",
    "condition": {
      "and": [
        {
          "or": [
            { "compare_string": [ "iv_mutagen", { "context_val": "itype" } ] },
            { "compare_string": [ "mutagen", { "context_val": "itype" } ] }
          ]
        },
        { "u_has_trait": "HOMULLUS_EXPANDED_MUTATIONS" }
      ]
    },
    "effect": [ { "u_add_trait": "HOMULLUS_NO_DOLL_MUTATIONS" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_CUT_OFF_FURTHER_HOMULLUS_MUTATIONS_2",
    "recurrence": "10 m",
    "condition": { "u_has_trait": "HOMULLUS_NO_DOLL_MUTATIONS" },
    "deactivate_condition": { "not": { "u_has_trait": "HOMULLUS_NO_DOLL_MUTATIONS" } },
    "effect": [ { "math": [ "u_vitamin('mutagen_dollkin') = 0" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_ON",
    "condition": { "not": { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" } },
    "effect": [
      { "u_add_trait": "HOMULLUS_DOLL_FORM_TRAITS" },
      { "run_eocs": [ "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS", "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_RESETTER" ] },
      { "u_message": "Your limbs stiffen and your skin takes on an even more waxen appearance.", "type": "good" }
    ],
    "false_effect": [
      { "u_lose_trait": "HOMULLUS_DOLL_FORM_TRAITS" },
      { "u_lose_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" },
      { "u_message": "A small semblance of life returns to you.", "type": "neutral" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_COUNTER",
    "condition": { "math": [ "u_doll_form_movement > 0" ] },
    "effect": [ { "math": [ "u_doll_form_movement", "-=", "rand(3) + 1" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_COUNTER_ZERO_CHECKER",
    "recurrence": "1 s",
    "condition": { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" },
    "deactivate_condition": { "not": { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" } },
    "effect": [
      {
        "run_eocs": {
          "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_COUNTER_ZERO_CHECKER_2",
          "condition": {
            "and": [ { "math": [ "u_doll_form_movement == 0" ] }, { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS_ATTACKER" } ]
          },
          "effect": [ { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_REGAIN" } ]
        }
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_SET_TO_ZERO",
    "eoc_type": "EVENT",
    "required_event": "avatar_moves",
    "condition": { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" },
    "effect": [ { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_RESETTER" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_RESETTER",
    "condition": { "math": [ "u_monsters_nearby('radius': 45, 'attitude': 'both') == 0" ] },
    "effect": [ { "math": [ "u_doll_form_movement = 0" ] }, { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_REGAIN" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_INCREASING",
    "eoc_type": "EVENT",
    "required_event": "avatar_moves",
    "condition": { "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" }, { "math": [ "u_doll_form_movement <= 1000" ] } ] },
    "effect": [ { "math": [ "u_doll_form_movement", "+=", "rand(10) + 2" ] } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_MOVEMENT_BREAK_CHECKER",
    "eoc_type": "EVENT",
    "required_event": "avatar_moves",
    "condition": {
      "and": [
        { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" },
        { "math": [ "u_doll_form_movement > 0" ] },
        { "x_in_y_chance": { "x": { "math": [ "u_doll_form_movement" ] }, "y": 1000 } }
      ]
    },
    "effect": [
      {
        "u_message": "As you take another step, you notice hostile eyes turn toward you.  They don't see you as just a doll now.",
        "type": "bad"
      },
      { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_LOSE" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS",
    "condition": { "not": { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS_ATTACKER" } },
    "effect": [ { "u_add_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_MELEE_MONSTER_CANCEL_TOGGLES",
    "eoc_type": "EVENT",
    "required_event": "character_melee_attacks_monster",
    "condition": { "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" }, { "u_has_trait": "THRESH_HOMULLUS" } ] },
    "effect": [ { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_LOSE" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_MELEE_CHARACTER_CANCEL_TOGGLES",
    "eoc_type": "EVENT",
    "required_event": "character_melee_attacks_character",
    "condition": { "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" }, { "u_has_trait": "THRESH_HOMULLUS" } ] },
    "effect": [ { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_LOSE" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_RANGED_MONSTER_CANCEL_TOGGLES",
    "eoc_type": "EVENT",
    "required_event": "character_ranged_attacks_monster",
    "condition": { "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" }, { "u_has_trait": "THRESH_HOMULLUS" } ] },
    "effect": [ { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_LOSE" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_RANGED_CHARACTER_CANCEL_MIEN",
    "eoc_type": "EVENT",
    "required_event": "character_ranged_attacks_character",
    "condition": { "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" }, { "u_has_trait": "THRESH_HOMULLUS" } ] },
    "effect": [ { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_LOSE" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_LOSE",
    "condition": { "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" }, { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" } ] },
    "effect": [
      { "u_lose_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" },
      { "u_add_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS_ATTACKER" },
      { "run_eocs": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_REGAIN", "time_in_future": [ 180, 360 ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DOLL_FORM_ANGER_RELATIONS_REGAIN",
    "condition": {
      "and": [ { "u_has_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS_ATTACKER" }, { "u_has_trait": "HOMULLUS_DOLL_FORM_TRAITS" } ]
    },
    "effect": [
      { "u_lose_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS_ATTACKER" },
      { "u_add_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS" }
    ],
    "false_effect": [ { "u_lose_trait": "HOMULLUS_DOLL_FORM_ANGER_RELATIONS_ATTACKER" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_ALL_ROADS_TRANSLOCATE_CHECK",
    "condition": { "and": [ "u_is_outside", { "u_at_om_location": "road" }, { "u_is_on_terrain_with_flag": "ROAD" } ] },
    "effect": [ { "u_cast_spell": { "id": "paraclesian_translocate" } } ],
    "false_effect": [ { "u_message": "You must be standing on a road to cast this spell.", "type": "mixed" } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_ALL_ROADS_ATTUNEMENT_CHECK",
    "condition": {
      "and": [
        {
          "or": [
            { "test_eoc": "EOC_CONDITION_HOMULLUS_NEAR_FACTION" },
            { "math": [ "u_characters_nearby('radius': 50, 'attitude': 'any') >= 15" ] }
          ]
        }
      ]
    },
    "effect": [ { "u_cast_spell": { "id": "homullus_civilization_translocate_attune_real" }, "targeted": true } ],
    "false_effect": [
      { "u_message": "You must be within one of the remaining bastions of civilization to cast this spell.", "type": "mixed" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_HOMULLUS_DEATH_DOOR_REBIRTH",
    "eoc_type": "PREVENT_DEATH",
    "condition": {
      "and": [ { "u_has_trait": "DEATH_IS_BUT_A_DOOR" }, { "not": { "u_has_effect": "effect_homullus_prevented_death" } } ]
    },
    "effect": [
      {
        "u_location_variable": { "context_val": "homullus_death_door_target" },
        "species": "FERAL",
        "target_min_radius": 0,
        "target_max_radius": 30
      },
      {
        "if": { "math": [ "!has_var(_homullus_death_door_target)" ] },
        "then": [
          {
            "u_location_variable": { "context_val": "homullus_death_door_target" },
            "npc": "",
            "target_min_radius": 0,
            "target_max_radius": 30
          }
        ]
      },
      {
        "if": { "math": [ "has_var(_homullus_death_door_target)" ] },
        "then": [
          {
            "run_eocs": { "id": "EOC_HOMULLUS_DEATH_DOOR_KILL_TARGET", "effect": [ { "npc_cast_spell": { "id": "xedra_self_banish" } } ] },
            "beta_loc": { "context_val": "homullus_death_door_target" }
          },
          { "math": [ "u_vitamin('blood') = 0" ] },
          "u_prevent_death",
          { "math": [ "u_hp('ALL') = 999" ] },
          { "math": [ "u_vitamin('redcells') = 0" ] },
          { "math": [ "u_pain() = 0" ] },
          { "math": [ "u_val('rad') = 0" ] },
          {
            "u_lose_effect": [
              "corroding",
              "onfire",
              "dazed",
              "stunned",
              "venom_blind",
              "formication",
              "blisters",
              "frostbite",
              "frostbite_recovery",
              "wet",
              "slimed",
              "migo_atmosphere",
              "fetid_goop",
              "sap",
              "nausea",
              "bleed"
            ]
          },
          {
            "u_add_effect": "effect_homullus_prevented_death",
            "duration": { "math": [ "max( 20160, 1209600 - 15120 * u_sum_traits_of_category_char_has('HOMULLUS') )" ] }
          },
          { "u_teleport": { "context_val": "homullus_death_door_target" }, "force_safe": true }
        ]
      }
    ]
  }
]
