{"size": 1697, "ext": "js", "max_stars_repo_path": "scripts/magic/amazement.js", "max_stars_repo_name": "laice/golem", "max_stars_repo_stars_event_min_datetime": "2021-08-30T02:14:00.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T11:57:26.000Z", "max_issues_repo_path": "scripts/magic/amazement.js", "max_issues_repo_name": "laice/golem", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "scripts/magic/amazement.js", "max_forks_repo_name": "laice/golem", "max_forks_repo_forks_event_min_datetime": "2021-09-03T07:08:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-13T10:33:18.000Z"}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 30.3035714286, "max_line_length": 120, "alphanum_fraction": 0.6063641721}
/*
 * Copyright (c) 2021 James Skarzinskas.
 * All rights reserved.
 * See LICENSE.txt in project root for license information.
 * Authors:
 *     James Skarzinskas <james@jskarzin.org>
 */

// It's like a basement, but a maze!
function spell_amazement(ch) {
    if(!ch.room) {
        ch.send("You can't do that here.\r\n");
        return;
    }

    if(ch.room.exit[Golem.Directions.DirectionDown]) {
        ch.send("You can't burrow a maze into a room above another.\r\n");
        return;
    }

    const maze = Golem.game.generateDungeon(2, 32, 32);
    if(ch.room.flags & Golem.RoomFlags.ROOM_PLANAR) {
        ch.room.plane.map.layers[ch.room.z].terrain[ch.room.y][ch.room.x] = Golem.TerrainTypes.TerrainTypeCaveDeepWall1;
    }

    ch.send("{YA crack of lightning sunders the earth before you, revealing a dungeon!{x\r\n");

    try {
        const mazeFirstFloor = maze.floors[0];
        const mazeEntrance =
            mazeFirstFloor.grid[mazeFirstFloor.entryX][
                mazeFirstFloor.entryY
            ].room;

        ch.room.exit[Golem.Directions.DirectionDown] = Golem.NewExit(
            ch.room,
            Golem.Directions.DirectionDown,
            mazeEntrance,
            Golem.ExitFlags.EXIT_IS_DOOR | Golem.ExitFlags.EXIT_CLOSED
        );

        mazeEntrance.exit[Golem.Directions.DirectionUp] =
            Golem.NewExit(
                mazeEntrance,
                Golem.Directions.DirectionUp,
                ch.room,
                Golem.ExitFlags.EXIT_IS_DOOR |
                    Golem.ExitFlags.EXIT_CLOSED
            );
    } catch(err) {
        ch.send(err.toString());
    }
}

Golem.registerSpellHandler('amazement', spell_amazement);
