<commit_before>import Game from "../../core/models/game";
import {Artifact} from "../../core/models/artifact";
import {Monster} from "../../core/models/monster";
import {RoomExit} from "../../core/models/room";
import {Room} from "../../core/models/room";

export var event_handlers = {

  "start": function(arg: string) {
    let game = Game.getInstance();

    game.data['oak door shut'] = false;

    game.data['wandering monsters'] = [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26];

    // sir charles
    game.monsters.get(32).spells = ['heal'];
    game.monsters.get(32).spell_points = 2;

    // magician
    game.monsters.get(32).spells = ['blast', 'heal'];
    game.monsters.get(32).spell_points = 2;

    // high priest
    game.monsters.get(56).spells = ['blast'];
    game.monsters.get(56).spell_points = 3;

    // alkanda
    game.monsters.get(29).spells = ['blast'];
    game.monsters.get(32).spell_points = 4;

    game.data['regeneration counter'] = 0;
    game.data['alkanda summoned'] = false;
    game.data["original ag"] = game.player.agility;
    game.data["sober counter"] = 0;
    // wand charges
    game.artifacts.get(33).quantity = game.diceRoll(1, 4) + 2;

    // place the mage's body
    game.artifacts.get(32).moveToRoom(
      game.rooms.getRandom([1,2,3,4,5,6,7,8,9,10,11,12,13,14,28,29,30,31,32,41,50,51,52,53]).id
    );

  },

  "attackMonster": function(arg: string, target: Monster) {
    let game = Game.getInstance();
    if (game.player.weapon_id === 33) {
      fireball();
      return false;
    }
    return true;
  },

  "afterGet": function(arg, artifact) {
    let game = Game.getInstance();

    if (artifact && artifact.id === 41) {
      // scimitar
      game.history.write("Alignment conflict! The evil runes on the scimitar burn with a cold fire against your hand!", "special2");
      game.player.injure(game.diceRoll(1, 8) + 1, true);
    }
  },

  "beforeMove": function(arg: string, room: Room, exit: RoomExit): boolean {
    let game = Game.getInstance();

    // traps! (artifact type 14)
    for (let a of game.artifacts.inRoom.filter(x => x.embedded && x.type === 14)) {
      game.effects.print(a.effect_id);
      // weapon_odds field is used to store the chance of hitting, as an integer (not a percentage).
      // to make the saving throw, the player rolls 1 d (agility) and has to be above that number.

      // choose targets and deal damage
      let monster_ids = game.monsters.visible.map(x => x.id);
      monster_ids.push(0);
      for (let i = 0; i < a.quantity; i++) {
        let monster_index = game.diceRoll(1, monster_ids.length) - 1;
        let victim = game.monsters.get(monster_ids[monster_index]);
        if (victim.rollSavingThrow('agility', a.weapon_odds)) {
          game.history.write(victim.name + " narrowly avoids the trap!");
        } else {
        // damage is stored in dice and sides, just like weapons.
        // the "armor_penalty" field should be either 1 (ignore armor) or 0 (armor absorbs hits)
          victim.injure(game.diceRoll(a.dice, a.sides), a.armor_penalty === 1);
        }
        monster_ids.splice(monster_index, 1);
      }
      a.embedded = false;
    }

    return true;
  },

  "afterMove": function(arg: string, room_from: Room, room_to: Room) {
    let game = Game.getInstance();
    // oak door
    if (room_from.id === 33 && room_to.id === 18 && !game.data['oak door shut']) {
      game.history.write("After you pass through the oak door, you find that it shuts and locks behind you!");<commit_msg>Temple of Ngurct: fix bug in event handler<commit_after>import Game from "../../core/models/game";
import {Artifact} from "../../core/models/artifact";
import {Monster} from "../../core/models/monster";
import {RoomExit} from "../../core/models/room";
import {Room} from "../../core/models/room";

export var event_handlers = {

  "start": function(arg: string) {
    let game = Game.getInstance();

    game.data['oak door shut'] = false;

    game.data['wandering monsters'] = [7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26];

    // sir charles
    game.monsters.get(32).spells = ['heal'];
    game.monsters.get(32).spell_points = 2;

    // magician
    game.monsters.get(32).spells = ['blast', 'heal'];
    game.monsters.get(32).spell_points = 2;

    // high priest
    game.monsters.get(56).spells = ['blast'];
    game.monsters.get(56).spell_points = 3;

    // alkanda
    game.monsters.get(29).spells = ['blast'];
    game.monsters.get(32).spell_points = 4;

    game.data['regeneration counter'] = 0;
    game.data['alkanda summoned'] = false;
    game.data["original ag"] = game.player.agility;
    game.data["sober counter"] = 0;
    // wand charges
    game.artifacts.get(33).quantity = game.diceRoll(1, 4) + 2;

    // place the mage's body
    game.artifacts.get(32).moveToRoom(
      game.rooms.getRandom([1,2,3,4,5,6,7,8,9,10,11,12,13,14,28,29,30,31,32,41,50,51,52,53]).id
    );

  },

  "attackMonster": function(arg: string, target: Monster) {
    let game = Game.getInstance();
    if (game.player.weapon_id === 33) {
      fireball();
      return false;
    }
    return true;
  },

  "afterGet": function(arg, artifact) {
    let game = Game.getInstance();

    if (artifact && artifact.id === 41) {
      // scimitar
      game.history.write("Alignment conflict! The evil runes on the scimitar burn with a cold fire against your hand!", "special2");
      game.player.injure(game.diceRoll(1, 8) + 1, true);
    }
  },

  "beforeMove": function(arg: string, room: Room, exit: RoomExit): boolean {
    let game = Game.getInstance();

    // traps! (artifact type 14)
    for (let a of game.artifacts.inRoom.filter(x => x.embedded && x.type === 14)) {
      game.effects.print(a.effect_id);
      // weapon_odds field is used to store the chance of hitting, as an integer (not a percentage).
      // to make the saving throw, the player rolls 1 d (agility) and has to be above that number.

      // choose targets and deal damage
      let monster_ids = game.monsters.visible.map(x => x.id);
      monster_ids.push(0);
      for (let i = 0; i < a.quantity; i++) {
        let monster_index = game.diceRoll(1, monster_ids.length) - 1;
        let victim = game.monsters.get(monster_ids[monster_index]);
        if (victim.rollSavingThrow('agility', a.weapon_odds)) {
          game.history.write(victim.name + " narrowly avoids the trap!");
        } else {
          // damage is stored in dice and sides, just like weapons.
          // the "armor_penalty" field should be either 1 (ignore armor) or 0 (armor absorbs hits)
          victim.injure(game.diceRoll(a.dice, a.sides), a.armor_penalty === 1);
        }
        monster_ids.splice(monster_index, 1);
        if (!monster_ids.length) break;  // no more targets left
      }
      a.embedded = false;
    }

    return true;
  },

  "afterMove": function(arg: string, room_from: Room, room_to: Room) {
    let game = Game.getInstance();
    // oak door
    if (room_from.id === 33 && room_to.id === 18 && !game.data['oak door shut']) {
      game.history.write("After you pass through the oak door, you find that it shuts and locks behind you!");
{'fraction_non_alphanumeric': 0.16095795043163463, 'fraction_numerical': 0.03620161514898357, 'mean_word_length': 2.882702702702703, 'pattern_counts': {'":': 10, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2975447', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2412, 'n_words': 599}