[
  {
    "id": "ACT_afs_hack",
    "type": "activity_type",
    "activity_level": "NO_EXERCISE",
    "verb": "hacking",
    "based_on": "time",
    "can_resume": false,
    "completion_eoc": "EOC_finish_afs_hack"
  },
  {
    "id": "EOC_finish_afs_hack",
    "type": "effect_on_condition",
    "effect": [ { "u_add_effect": "afs_hack_done", "duration": "3 seconds" }, { "turn_cost": "1 s" } ]
  },
  {
    "type": "jmath_function",
    "id": "afs_hack_skill",
    "num_args": 1,
    "return": "(u_skill('computer') + u_val('intelligence')/3 + u_hack_bonus) * (_0)"
  },
  {
    "type": "jmath_function",
    "id": "afs_hack_time_adjust",
    "num_args": 3,
    "return": "_0 - _1 * afs_hack_skill(1) < _2 ? _2 : _0 - _1* afs_hack_skill(1)"
  },
  {
    "type": "jmath_function",
    "id": "afs_hack_bonus",
    "//": "Intended as: Tool Quality + ( Base Focus Mod * (Focus - Focus Threshold) / Focus Threshold ):rounded to nearest int",
    "//1": "Below 100 Focus your focus mod will be negative and you are punished. At 100 focus your mod will be 0. Above 100 focus your mod will be positive and you will be rewarded.",
    "//2": "ARGS: (Hack Tool Quality, Current Focus)",
    "num_args": 2,
    "return": "_0 + trunc( 4 * ( ( _1 - 100 ) / 100 ) )"
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_start_lock_hack",
    "condition": { "and": [ { "expects_vars": [ "furn_pos", "t_delay", "difficulty", "t_radius" ] }, "u_can_see" ] },
    "effect": [
      { "math": [ "_t_delay = afs_hack_time_adjust(_t_delay, time('20s'), time('2m'))" ] },
      { "math": [ "_hack_cost = (5 * (_t_delay / time('10m') )) * max(1, _power_cost_mult)" ] },
      { "math": [ "_hack_cost_bionic = (energy('2 kJ') * (_t_delay / time('10m') )) * max(1, _power_cost_mult)" ] },
      {
        "u_run_inv_eocs": "manual",
        "title": "Select a Hacking tool",
        "search_data": [
          { "condition": { "math": [ "n_quality('HACK') > 0" ] }, "flags": "HACK_NO_CHARGE" },
          {
            "condition": { "and": [ { "math": [ "n_quality('HACK') > 0" ] }, { "math": [ "_hack_cost_bionic < u_val('power')" ] } ] },
            "flags": "USES_BIONIC_POWER"
          },
          {
            "condition": { "and": [ { "math": [ "n_quality('HACK') > 0" ] }, { "math": [ "_hack_cost < n_val('power')" ] } ] },
            "excluded_flags": "USES_BIONIC_POWER",
            "uses_energy": true
          }
        ],
        "true_eocs": [ "EOC_hack_with_tool" ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_hack_with_tool",
    "effect": [
      { "npc_set_flag": "ACTIVE_HACK_TOOL" },
      { "u_message": "You connect to the lock controller." },
      { "u_assign_activity": "ACT_afs_hack", "duration": { "context_val": "t_delay" } },
      { "math": [ "u_hack_bonus = afs_hack_bonus( n_quality('HACK'), u_val('focus') )" ] },
      { "run_eocs": [ "EOC_hack_item_power_consume", "EOC_hack_bionic_power_consume" ] },
      {
        "run_eocs": "EOC_afs_hack_unlock",
        "time_in_future": { "context_val": "t_delay" },
        "variables": {
          "furn_pos": { "context_val": "furn_pos" },
          "difficulty": { "context_val": "difficulty" },
          "t_radius": { "context_val": "t_radius" }
        }
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_hack_item_power_consume",
    "effect": [
      {
        "u_run_inv_eocs": "all",
        "search_data": [ { "flags": "ACTIVE_HACK_TOOL", "excluded_flags": "USES_BIONIC_POWER", "uses_energy": true } ],
        "true_eocs": [
          {
            "id": "EOC_hack_item_power_consume_found_item",
            "effect": [ { "math": [ "n_val('power') -= _hack_cost" ] }, { "npc_unset_flag": "ACTIVE_HACK_TOOL" } ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_hack_bionic_power_consume",
    "effect": [
      {
        "u_run_inv_eocs": "all",
        "search_data": [ { "flags": [ "ACTIVE_HACK_TOOL", "USES_BIONIC_POWER" ] } ],
        "true_eocs": [
          {
            "id": "EOC_hack_bionic_power_consume_found_item",
            "effect": [ { "math": [ "u_val('power') -= _hack_cost_bionic" ] }, { "npc_unset_flag": "ACTIVE_HACK_TOOL" } ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_hack_unlock",
    "condition": { "and": [ { "expects_vars": [ "furn_pos", "difficulty", "t_radius" ] }, { "u_has_effect": "afs_hack_done" } ] },
    "effect": [
      {
        "run_eocs": [
          {
            "id": "EOC_afs_hack_success",
            "condition": { "roll_contested": { "math": [ "afs_hack_skill(1)" ] }, "die_size": 4, "difficulty": { "context_val": "difficulty" } },
            "effect": [
              {
                "if": { "compare_string": [ { "u_val": "hack_success_eoc" }, "" ] },
                "then": [ { "u_add_var": "hack_success_eoc", "value": "EOC_afs_hack_generic_success" } ]
              },
              { "run_eocs": [ { "u_val": "hack_success_eoc" } ] },
              { "u_add_var": "hack_minor_failure_eoc", "value": "" },
              { "u_add_var": "hack_critical_fail_eoc", "value": "" },
              { "u_add_var": "hack_success_eoc", "value": "" }
            ],
            "false_effect": [ { "run_eocs": [ "EOC_afs_hack_failure" ] } ]
          }
        ]
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_hack_generic_success",
    "effect": [
      {
        "u_transform_radius": { "context_val": "t_radius" },
        "ter_furn_transform": "afs_multi_unlock",
        "target_var": { "context_val": "furn_pos" }
      }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_hack_failure",
    "effect": [
      { "u_message": "You fail to override the device.", "type": "bad" },
      { "math": [ "_failure_roll = rand(9)" ] },
      {
        "if": { "compare_string": [ { "u_val": "hack_minor_failure_eoc" }, "" ] },
        "then": [ { "u_add_var": "hack_minor_failure_eoc", "value": "EOC_afs_generic_hack_minor_failures" } ]
      },
      {
        "if": { "compare_string": [ { "u_val": "hack_critical_fail_eoc" }, "" ] },
        "then": [ { "u_add_var": "hack_critical_fail_eoc", "value": "EOC_afs_generic_hack_critical_fail" } ]
      },
      {
        "if": { "math": [ "_failure_roll <= clamp(_difficulty - afs_hack_skill(1), 1, 10)" ] },
        "then": [ { "run_eocs": [ { "u_val": "hack_critical_fail_eoc" } ] }, { "math": [ "_failure_roll = 10" ] } ]
      },
      {
        "if": { "math": [ "_failure_roll <= clamp(_difficulty - afs_hack_skill(1) + 3, 1, 10)" ] },
        "then": [ { "run_eocs": [ { "u_val": "hack_minor_failure_eoc" } ] } ]
      },
      { "u_add_var": "hack_minor_failure_eoc", "value": "" },
      { "u_add_var": "hack_critical_fail_eoc", "value": "" },
      { "u_add_var": "hack_success_eoc", "value": "" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_generic_hack_minor_failures",
    "effect": [
      {
        "set_string_var": [ "EOC_afs_generic_hack_minor_failure_alarm", "EOC_afs_generic_hack_minor_failure_hurt" ],
        "target_var": { "context_val": "failure_eoc" }
      },
      { "run_eocs": [ { "context_val": "failure_eoc" } ] }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_generic_hack_critical_fail",
    "effect": [ { "u_transform_radius": 0, "ter_furn_transform": "afs_multi_lockdown", "target_var": { "context_val": "furn_pos" } } ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_generic_hack_minor_failure_alarm",
    "effect": [
      { "u_message": "You set off the devices alarm!", "type": "bad" },
      { "custom_light_level": 80, "length": [ "1 seconds", "10 seconds" ] },
      { "u_make_sound": "Alarm Bleeping", "volume": 15, "type": "alarm" }
    ]
  },
  {
    "type": "effect_on_condition",
    "id": "EOC_afs_generic_hack_minor_failure_hurt",
    "effect": [ { "u_message": "The device shocks you!", "type": "bad" }, { "u_deal_damage": "electric", "amount": 10 } ]
  }
]
