var status;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && type > 0) {
            cm.dispose();
            return;
        }
        if (mode == 1) {
            status++;
        } else {
            status--;
        }

        if (status == 0) {
            if (cm.getEventInstance().isEventCleared()) {
                cm.sendOk("Wow! You defeated the balrog.");
            } else if (cm.getPlayer().getMap().getCharacters().size() > 1) {
                cm.sendYesNo("Are you really going to leave this battle and leave your fellow travelers to die?");
            } else {
                cm.sendYesNo("If you're a coward, you will leave.");
            }
        } else if (status == 1) {
            if (cm.getEventInstance().isEventCleared()) {
                cm.warp(cm.getMapId() == 105100300 ? 105100301 : 105100401, 0);
            } else {
                cm.warp(105100100);
            }

            cm.dispose();
        }
    }
}
