All files / js/levels tut-1.js

98.3% Statements 349/355
68.42% Branches 13/19
100% Functions 4/4
98.3% Lines 349/355

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 3562x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 76x 76x 76x 2x 2x 2x 74x 74x 76x 2x 2x 2x 72x 72x 76x 2x 2x 4x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 8x 8x 8x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x         2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x  
/**
 * tut-1 - NetHack special level
 * Converted from: tut-1.lua
 */
 
import * as des from '../sp_lev.js';
import { selection, percent, shuffle, nh, u } from '../sp_lev.js';
import { rn2 } from '../rng.js';
 
export async function generate() {
 
    let tut_ctrl_key = null;
    let tut_alt_key = null;
 
    function tut_key(command) {
       let s = nh.eckey(command);
       let m = s.match(/^\^([A-Z])$/); // ^X is Ctrl-X
       if ((m !== null)) {
          tut_ctrl_key = m[1];
          return "Ctrl-" + m[1];
       }
 
       m = s.match(/^M-([A-Z])$/); // M-X is Alt-X
       if ((m !== null)) {
          tut_alt_key = m[1];
          return "Alt-" + m[1];
       }
 
       return s;
    }
 
    function tut_key_help(x, y) {
       if ((tut_ctrl_key !== null)) {
          des.engraving({ coord: [ x,y ], type: "engrave", text: "Note: Outside the tutorial, Ctrl-key combinations are shown prefixed with a caret, like '^" + tut_ctrl_key + "'", degrade: false });
          tut_ctrl_key = null;
       }
    }
 
    des.level_init({ style: "solidfill", fg: " " });
    des.level_flags("mazelevel", "noflip",
                    "nomongen", "nodeathdrops", "noautosearch");
 
    des.map(`\
---------------------------------------------------------------------------
|-.--|.......|......|..S....|.F.......|.............|.......|.............|
|.-..........|......|--|....|.F.....|.|S-------.....|.....................|
||.--|.......|..T......|....|.F.....|.|.......|.....|.......|.............|
||.|.|.......|......|-.|....|.F.....|.|.......|.....|--------.............|
||.|.|.......|......||.|-.-----------.-.......|-S----.....................|
|-+-S---------..---.||........................|...|.......................|
|......|          |.-------------------.......|...|....--S----............|
|......|  ######  |.........|      |..S.......|...|....|.....|............|
|----.-| -+-   #  |.....---.|######+..|.......S...|....|.....|............|
|----+----.----+---.|.--|.|.|#     ------------...|....|.....F............|
|........|.|......|.|...F...|#  ........|.....+...|....|.....|............|
|.P......-S|......|------.---# .........|.....|...|....-------........----|
|..........|......+.|...|.|.S# ..--S-----.....|LLL|..................|..| |
|.W......---......|.|.|.|.|.|# ..|......|.....|LLL|..................|..--|
|....Z.L.S.F......|.|.|.|.---#   |......+.....|...|..................|..|.|
|........|--......|...|.....|####+......|.....|...+..................||...|
---------------------------------------------------------------------------
`);
 
 
    await des.region(selection.area(1,1, 73, 16), "lit");
 
    des.non_diggable();
 
    des.teleport_region({ region: [ 9,3, 9,3 ] });
 
    // TODO:
    // - save (more of) hero state when entering
    // - quit-command should maybe exit the tutorial?
 
    // turn on some newbie-friendly options
    nh.parse_config("OPTIONS=mention_walls");
    nh.parse_config("OPTIONS=mention_decor");
    nh.parse_config("OPTIONS=lit_corridor");
 
    let movekeys = tut_key("movewest") + " " + tut_key("movesouth") + " " + tut_key("movenorth") + " " + tut_key("moveeast");
 
    let diagmovekeys = tut_key("movesouthwest") + " " + tut_key("movenortheast") + " " + tut_key("movesoutheast") + " " + tut_key("movenorthwest");
 
    des.engraving({ coord: [ 9,3 ], type: "engrave", text: "Move around with " + movekeys, degrade: false });
    des.engraving({ coord: [ 5,2 ], type: "engrave", text: "Move diagonally with " + diagmovekeys, degrade: false });
 
    if ((u.role == "Knight")) {
       des.engraving({ coord: [ 12,1 ], type: "engrave", text: "Knights can jump with '" + tut_key("jump") + "'", degrade: false });
    }
 
    // 
 
    des.engraving({ coord: [ 2,4 ], type: "engrave", text: "Some actions may require multiple tries before succeeding", degrade: false });
    des.engraving({ coord: [ 2,5 ], type: "engrave", text: "Open the door by moving into it", degrade: false });
    des.door({ coord: [ 2,6 ], state: "closed" });
 
    des.engraving({ coord: [ 2,7 ], type: "engrave", text: "Close the door with '" + tut_key("close") + "'", degrade: false });
 
 
    // 
 
    des.engraving({ coord: [ 4,5 ], type: "engrave", text: "You can leave the tutorial via the magic portal.", degrade: false });
    await des.trap({ type: "magic portal", coord: [ 4,4 ], seen: true });
 
    // 
 
    des.engraving({ coord: [ 5,9 ], type: "engrave", text: "This door is locked. Kick it with '" + tut_key("kick") + "'", degrade: false });
    des.door({ coord: [ 5,10 ], state: "locked" });
 
    // by default, kick is the first command that can be a ctrl-key combo
    tut_key_help(6, 8);
 
 
    des.engraving({ coord: [ 5,12 ], type: "engrave", text: "Look around the map with '" + tut_key("glance") + "', press ESC when you're done", degrade: false });
 
    // 
 
    des.engraving({ coord: [ 10,13 ], type: "engrave", text: "Use '" + tut_key("search") + "' to search for secret doors", degrade: false });
 
    des.engraving({ coord: [ 10,15 ], type: "engrave", text: "Wrong secret", degrade: false });
 
    // 
 
    des.engraving({ coord: [ 10,10 ], type: "engrave", text: "Behind this door is a dark corridor", degrade: false });
    des.door({ coord: [ 10,9 ], state: percent(50) ? "locked" : "closed" });
    await des.region(selection.match("#"), "unlit");
    await des.region(selection.match(" "), "unlit");
    des.door({ coord: [ 15,10 ], state: percent(50) ? "locked" : "closed" });
 
    // 
 
    des.engraving({ coord: [ 15,11 ], type: "engrave", text: "There are four traps next to you! Search for them.", degrade: false });
    let locs = [ [14,11], [14,12], [15,12], [16,12], [16,11] ];
    shuffle(locs);
    for (let i = 0, __end_i = 3; i <= __end_i; i++) {
       await des.trap({ type: percent(50) ? "sleep gas" : "board",
                  coord: locs[i], victim: false });
    }
 
    des.engraving({ coord: [ 15,15 ], type: "engrave", text: "Some traps can be disabled with '" + tut_key("untrap") + "'", degrade: false });
    await des.trap({ coord: [ 15,16 ], type: "web", spider_on_web: false });
 
    // 
 
    des.door({ coord: [ 18,13 ], state: "closed" });
 
    des.engraving({ coord: [ 19,13 ], type: "engrave", text: "Pick up items with '" + tut_key("pickup") + "'", degrade: false });
 
    let armor = (u.role === "Monk") ? "leather gloves" : "leather armor";
 
    await des.object({ id: armor, spe: 0, buc: "cursed", coord: [ 19,14] });
 
    des.engraving({ coord: [ 19,15 ], type: "engrave", text: "Wear armor with '" + tut_key("wear") + "'", degrade: false });
 
    await des.object({ id: "dagger", spe: 0, buc: "!-cursed", coord: [ 21,15] });
 
    des.engraving({ coord: [ 21,14 ], type: "engrave", text: "Wield weapons with '" + tut_key("wield") + "'", degrade: false });
 
 
    des.engraving({ coord: [ 22,13 ], type: "engrave", text: "Hit monsters by walking into them.", degrade: false });
 
    await des.monster({ id: "lichen", coord: [ 23,15 ], waiting: true, countbirth: false });
 
    // 
 
    des.engraving({ coord: [ 24,16 ], type: "engrave", text: "Now you know the very basics. You can leave the tutorial via the magic portal.", degrade: false });
 
    des.engraving({ coord: [ 26,16 ], type: "engrave", text: "Step into this portal to leave the tutorial", degrade: false });
    await des.trap({ type: "magic portal", coord: [ 27,16 ], seen: true });
 
    // 
 
    des.engraving({ coord: [ 25,13 ], type: "engrave", text: "Push boulders by moving into them", degrade: false });
    await des.object({ id: "boulder", coord: [25,12] });
 
    // 
 
    des.engraving({ coord: [ 27,9 ], type: "engrave", text: "Take off armor with '" + tut_key("takeoff") + "'", degrade: false });
 
    // 
 
    await des.object({ class: "?", id: "remove curse", buc: "blessed", coord: [23,11] });
    des.engraving({ coord: [ 22,11 ], type: "engrave", text: "Some items have shuffled descriptions, different each game", degrade: false });
    des.engraving({ coord: [ 23,11 ], type: "engrave", text: "Pick up this scroll, read it with '" + tut_key("read") + "', and try to remove the armor again", degrade: false });
 
    // 
 
    des.engraving({ coord: [ 19,10 ], type: "engrave", text: "Another magic portal, a way to leave this tutorial", degrade: false });
    await des.trap({ type: "magic portal", coord: [ 19,11 ], seen: true });
 
    // 
 
    // rock fall
    await des.object({ coord: [14, 5], id: "rock", quantity: (rn2((99) - (50) + 1) + (50)) });
    await des.object({ coord: [15, 5], id: "rock", quantity: (rn2((30) - (10) + 1) + (10)) });
    await des.object({ coord: [14, 4], id: "rock", quantity: (rn2((30) - (10) + 1) + (10)) });
    await des.object({ coord: [15, 6], id: "rock", quantity: (rn2((60) - (30) + 1) + (30)) });
    await des.object({ coord: [14, 6], id: "rock", quantity: (rn2((60) - (30) + 1) + (30)) });
    await des.object({ coord: [14, 6], id: "boulder" });
 
    des.door({ coord: [ 20,3 ], state: percent(50) ? "open" : "closed" });
 
    des.engraving({ coord: [ 21,3 ], type: "engrave", text: "Avoid being burdened, it slows you down", degrade: false });
    des.engraving({ coord: [ 22,3 ], type: "engrave", text: "Drop items with '" + tut_key("drop") + "'", degrade: false });
    des.engraving({ coord: [ 22,4 ], type: "engrave", text: "You can drop partial stacks by prefixing the item slot letter with a number", degrade: false });
 
    // 
 
    await des.monster({ id: "yellow mold", coord: [ 26,2 ], waiting: true, countbirth: false });
 
    des.engraving({ coord: [ 25,5 ], type: "engrave", text: "Throw items with '" + tut_key("throw") + "'", degrade: false });
 
    await des.trap({ type: "magic portal", coord: [ 21,1 ], seen: true });
 
    // 
 
    await des.monster({ id: "wolf", coord: [ 29,2 ], peaceful: 0, waiting: true, countbirth: false });
 
    des.engraving({ coord: [ 37,4 ], type: "engrave", text: "Missiles, such as rocks, work better when fired from appropriate launcher", degrade: false });
 
    await des.object({ coord: [ 37,3 ], id: "sling", buc: "!-cursed", spe: 9 });
    des.engraving({ coord: [ 37,3 ], type: "engrave", text: "Wield the sling", degrade: false });
    des.engraving({ coord: [ 36,1 ], type: "engrave", text: "Use '" + tut_key("fire") + "' to fire missiles with the wielded launcher", degrade: false });
 
    des.engraving({ coord: [ 35,4 ], type: "engrave", text: "Firing launches items from your quiver; Use '" + tut_key("quiver") + "' to put items in it", degrade: false });
 
    des.engraving({ coord: [ 33,4 ], type: "engrave", text: "You can wait a turn with '" + tut_key("wait") + "'", degrade: false });
 
 
    // 
 
    des.door({ coord: [ 38,6 ], state: "closed" });
 
    des.engraving({ coord: [ 39,6 ], type: "engrave", text: "You loot containers with '" + tut_key("loot") + "'", degrade: false });
 
    await des.object({ coord: [ 41,6 ], id: "large box", broken: true, trapped: false,
                 contents: async function(obj) {
                    await des.object({ id: "secret door detection", class: "/", spe: 30 }); }
    });
    des.engraving({ coord: [ 42,6 ], type: "engrave", text: "Containers can also be emptied with '" + tut_key("tip") + "'", degrade: false });
 
    des.engraving({ coord: [ 45,6 ], type: "engrave", text: "Magic wands are used with '" + tut_key("zap") + "'", degrade: false });
 
    // 
 
    des.door({ coord: [ 35,9 ], state: "nodoor" });
    des.engraving({ coord: [ 34,9 ], type: "engrave", text: "You can run by prefixing a movement key with '" + tut_key("run") + "'", degrade: false });
 
    // 
 
    des.door({ coord: [ 33,16 ], state: "nodoor" });
    des.engraving({ coord: [ 35,15 ], type: "engrave", text: "Travel across the level with '" + tut_key("travel") + "'", degrade: false });
 
    // 
 
    await des.trap({ type: "magic portal", coord: [ 27,14 ], seen: true });
 
    // 
 
    des.engraving({ coord: [ 48,1 ], type: "burn", text: "Use '" + tut_key("eat") + "' to eat edible things", degrade: false });
 
    await des.object({ coord: [ 50,3 ], id: "apple", buc: "!-cursed"  });
    await des.object({ coord: [ 50,3 ], id: "candy bar", buc: "!-cursed"  });
 
    await des.object({ coord: [ 50,3 ], id: "corpse", montype: "lichen", buc: "!-cursed" });
 
    // 
 
    des.door({ coord: [ 46,11 ], state: "closed" });
 
    des.engraving({ coord: [ 43,11 ], type: "burn", text: "Use '" + tut_key("twoweapon") + "' to use two weapons at once", degrade: false });
    await des.object({ coord: [ 43,13 ], id: "knife", buc: "uncursed" });
    await des.object({ coord: [ 43,14 ], id: "dagger", buc: "blessed" });
 
    des.engraving({ coord: [ 43,16 ], type: "burn", text: "Swap weapons quickly with '" + tut_key("swap") + "'", degrade: false });
 
    des.door({ coord: [ 40,15 ], state: "random" });
 
    // 
 
    await des.object({ coord: [ 48,7 ], id: "ring of levitation", buc: "!-cursed" });
 
    des.engraving({ coord: [ 48,10 ], type: "burn", text: "Put on accessories with '" + tut_key("puton") + "'", degrade: false });
 
    des.engraving({ coord: [ 48,16 ], type: "burn", text: "Remove accessories with '" + tut_key("remove") + "'", degrade: false });
 
    des.door({ coord: [ 50,16 ], state: "closed" });
 
 
    // 
 
    des.engraving({ coord: [ 58,9 ], type: "burn", text: "Use '" + tut_key("down") + "' to go down the stairs", degrade: false });
    des.stair({ dir: "down", coord: [ 58,10 ] });
 
    // 
 
    // one more ctrl-key help, if needed
    tut_key_help(64, 4);
 
    des.engraving({ coord: [ 65,3 ], type: "burn", text: "UNDER CONSTRUCTION", degrade: false });
 
    await des.trap({ type: "magic portal", coord: [ 66,2 ], seen: true });
 
    // 
 
    // squeezing through small gaps
 
    des.engraving({ coord: [ 69,12 ], type: "burn", text: "Can't get through?  You're carrying too much.", degrade: false });
 
    // try to squeeze over boulders, find a trap door
 
    await des.object({ id: "boulder", coord: [71,16] });
    await des.object({ id: "boulder", coord: [72,16] });
    await des.object({ id: "boulder", coord: [73,16] });
    await des.trap({ type: "trap door", coord: [ 73,15 ] });
 
    // 
 
    des.engraving({ coord: [ 60,2 ], type: "engrave", text: "Spellcasting", degrade: false });
    if ((u.uenmax < 5)) {
       // TODO: make sure hero has enough Pw to cast the spell (5 pw) instead?
       // TODO: ensure the first cast of this spell succeeds?
       des.engraving({ coord: [ 59,2 ], type: "engrave", text: "Unfortunately you don't have enough energy to cast spells.", degrade: false });
    }
    des.engraving({ coord: [ 57,2 ], type: "engrave", text: "Pick up the spellbook with '" + tut_key("pickup") + "'", degrade: false });
    await des.object({ coord: [ 57,2 ], id: "spellbook of light", buc: "blessed" });
    des.engraving({ coord: [ 55,2 ], type: "engrave", text: "Read the spellbook with '" + tut_key("read") + "'", degrade: false });
    des.engraving({ coord: [ 53,2 ], type: "engrave", text: "Use '" + tut_key("cast") + "' to cast a spell", degrade: false });
    await des.region(selection.area(53,1, 59, 3), "unlit");
 
    // 
 
    des.engraving({ coord: [ 72,2 ], type: "engrave", text: "You \"quaff\" potions with '" + tut_key("quaff") + "'", degrade: false });
    await des.object({ coord: [ 72,2 ], id: "potion of object detection", buc: "blessed" });
 
 
    // --------------
 
    // entering && leaving tutorial _branch_ now handled by core
    // // nh.callback("cmd_before", "tutorial_cmd_before");
    // // nh.callback("level_enter", "tutorial_enter");
    // // nh.callback("level_leave", "tutorial_leave");
    // // nh.callback("end_turn", "tutorial_turn");
 
    // --------------
 
    // temporary stuff here
    // await des.trap({ type: "magic portal", coord: [ 9,5 ], seen: true });
    // await des.trap({ type: "magic portal", coord: [ 9,1 ], seen: true });
    // await des.object({ id: "leather armor", spe: 0, coord: [ 9,2] });
 
 
 
    return des.finalize_level();
}