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 | 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 80x 80x 80x 73x 38x 38x 38x 38x 73x 8x 8x 8x 73x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 6x 6x 8x 8x 8x 8x 8x 8x 8x 2x 8x 73x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 2x 2x 2x 2x 8x 6x 6x 6x 6x 8x 8x 73x 73x 2x 2x 2x 2x 2x 2x 2x 8x 8x 2x 2x 2x 2x 2x 2x 2x 73x 73x 15x 15x 15x 14x 14x 14x 1x 1x 1x 15x 73x 73x 11x 11x 11x 11x 11x 7x 7x 7x 4x 4x 11x 73x 73x 12x 12x 12x 12x 8x 8x 8x 4x 4x 4x 12x 73x 73x 73x 38x 38x 38x 38x 38x 38x 38x 38x 15x 37x 11x 12x 12x 12x 38x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 22x 22x 22x 73x 73x 73x 4x 4x 4x 4x 4x 4x 73x 73x 73x 73x 73x 73x 4x 4x 4x 4x 4x 4x 4x 4x 73x 73x 73x 4x 4x 4x 4x 4x 4x 73x 73x 73x | // quest.js — Quest dungeon branch routines (port of quest.c)
// Most functions check quest_status flags and display text via qt_pager.
import { game } from './gstate.js';
import { rn2 } from './rng.js';
import { pline, You, verbalize } from './pline.js';
import { exercise } from './attrib.js';
import { A_CURRENT, A_ORIGINAL, A_WIS, MIN_QUEST_ALIGN, MIN_QUEST_LEVEL, STRAT_WAITMASK } from './const.js';
import { qt_pager, com_pager } from './questpgr.js';
import { align_str } from './insight.js';
import { ynFunction } from './input.js';
import { tty_clear_nhwindow } from './display.js';
import { on_level } from './hacklib.js';
import { setmangry } from './mon.js';
import { schedule_goto } from './do.js';
import { UTOTYPE_NONE, UTOTYPE_PORTAL } from './const.js';
import { nomul } from './cmd.js';
function Qstat() {
return game.quest_status || (game.quest_status = {});
}
function Not_firsttime() {
const u = game.u;
return u.uz0?.dnum === u.uz?.dnum && u.uz0?.dlevel === u.uz?.dlevel;
}
function not_capable() {
return (game.u?.ulevel ?? 0) < MIN_QUEST_LEVEL;
}
async function is_pure(talk) {
const u = game.u;
const originalAlignment = u?.ualignbase?.[A_ORIGINAL] ?? u?.ualign?.type ?? 0;
if (game.flags?.debug && talk) {
if (u.ualign?.type !== originalAlignment) {
await You(`are currently ${align_str(u.ualign?.type)} instead of ${align_str(originalAlignment)}.`);
} else if ((u.ualignbase?.[A_CURRENT] ?? originalAlignment) !== originalAlignment) {
await You('have converted.');
} else if ((u.ualign?.record ?? 0) < MIN_QUEST_ALIGN) {
await You(`are currently ${u.ualign?.record ?? 0} and require ${MIN_QUEST_ALIGN}.`);
const yn = await ynFunction('adjust?', null, 'y'.charCodeAt(0), game?.nhDisplay);
await tty_clear_nhwindow('message');
if (String.fromCharCode(yn).toLowerCase() === 'y') {
u.ualign.record = MIN_QUEST_ALIGN;
}
}
}
const aligned = (u.ualign?.record ?? 0) >= MIN_QUEST_ALIGN
&& (u.ualign?.type === originalAlignment)
&& ((u.ualignbase?.[A_CURRENT] ?? originalAlignment) === originalAlignment);
if (aligned) return 1;
if ((u.ualignbase?.[A_CURRENT] ?? originalAlignment) !== originalAlignment) return -1;
return 0;
}
async function chat_with_leader(mtmp) {
const qs = Qstat();
if (!mtmp?.mpeaceful || qs.pissed_off) return;
if (game.u?.uhave?.questart && !qs.met_nemesis) qs.cheater = true;
if (qs.got_thanks) {
if (game.u?.uhave?.amulet) {
await finish_quest(null);
} else {
await qt_pager('posthanks');
}
return;
}
if (game.u?.uhave?.questart) {
await finish_quest(null);
return;
}
if (qs.got_quest) {
await qt_pager('encourage');
return;
}
if (!qs.met_leader) {
await qt_pager('leader_first');
qs.met_leader = true;
qs.not_ready = 0;
} else {
await qt_pager('leader_next');
}
if (!on_level(game.u?.uz, game.qstart_level)) return;
if (not_capable()) {
await qt_pager('badlevel');
exercise(A_WIS, true);
expulsion(false);
} else {
const purity = await is_pure(true);
if (purity < 0) {
if (!qs.pissed_off) {
await com_pager('banished');
qs.pissed_off = true;
expulsion(false);
}
} else if (purity === 0) {
await qt_pager('badalign');
qs.not_ready = 1;
exercise(A_WIS, true);
expulsion(false);
} else {
await qt_pager('assignquest');
exercise(A_WIS, true);
qs.got_quest = true;
}
}
}
// C ref: quest.c:186 expulsion — expel hero from quest
function expulsion(seal) {
// C ref: dungeon.c dungeon_branch("The Quest") — find the branch connecting
// the quest dungeon to the main dungeon.
const branches = game.branches || [];
const questDnum = game.quest_dnum ?? -1;
let br = null;
for (const b of branches) {
if (b.end1?.dnum === questDnum || b.end2?.dnum === questDnum) { br = b; break; }
}
if (!br) return;
const dest = (br.end1?.dnum === game.u?.uz?.dnum) ? br.end2 : br.end1;
const portal_flag = game.u?.uevent?.qexpelled ? UTOTYPE_NONE : UTOTYPE_PORTAL;
nomul(0);
schedule_goto(dest, portal_flag | (seal ? 0x08 /* UTOTYPE_RMPORTAL */ : 0), null, null);
if (seal) {
game.u.uevent = game.u.uevent || {};
game.u.uevent.qexpelled = 1;
// TODO: remdun_mapseen, remove portal trap
}
}
// C ref: quest.c:24 on_start
async function on_start() {
const qs = Qstat();
if (!qs.first_start) {
await qt_pager('firsttime');
qs.first_start = true;
} else if (game.u.uz0?.dnum !== game.u.uz?.dnum
|| (game.u.uz0?.dlevel ?? 0) < (game.u.uz?.dlevel ?? 0)) {
if ((qs.not_ready ?? 0) <= 2) await qt_pager('nexttime');
else await qt_pager('othertime');
}
}
// C ref: quest.c:38 on_locate
async function on_locate() {
const qs = Qstat();
const fromAbove = (game.u.uz0?.dlevel ?? 0) < (game.u.uz?.dlevel ?? 0);
if (qs.killed_nemesis) return;
if (!qs.first_locate) {
if (fromAbove) await qt_pager('locate_first');
qs.first_locate = true;
} else {
if (fromAbove) await qt_pager('locate_next');
}
}
// C ref: quest.c:60 on_goal
async function on_goal() {
const qs = Qstat();
if (qs.killed_nemesis) return;
if (!qs.made_goal) {
await qt_pager('goal_first');
qs.made_goal = 1;
} else {
await qt_pager('goal_next');
if ((qs.made_goal ?? 0) < 7) qs.made_goal = (qs.made_goal ?? 0) + 1;
}
}
// C ref: quest.c:88 onquest
export async function onquest() {
if (game.u?.uevent?.qcompleted || Not_firsttime()) return;
// C ref: quest.c:88-103 — determine which quest level the hero is on
const uz = game.u?.uz;
if (!uz) return;
const qstart = game.qstart_level;
const qlocate = game.qlocate_level;
const nemesis = game.nemesis_level;
if (qstart && uz.dnum === qstart.dnum && uz.dlevel === qstart.dlevel) {
await on_start();
} else if (qlocate && uz.dnum === qlocate.dnum && uz.dlevel === qlocate.dlevel) {
await on_locate();
} else if (nemesis && uz.dnum === nemesis.dnum && uz.dlevel === nemesis.dlevel) {
await on_goal();
}
}
// C ref: quest.c:106 nemdead
export async function nemdead() {
const qs = Qstat();
if (!qs.killed_nemesis) {
qs.killed_nemesis = true;
await qt_pager('killed_nemesis');
}
}
// C ref: quest.c:114 leaddead
export function leaddead() {
const qs = Qstat();
if (!qs.killed_leader) qs.killed_leader = true;
}
// C ref: quest.c:124 artitouch
export async function artitouch(obj) {
const qs = Qstat();
if (!qs.touched_artifact) {
qs.touched_artifact = true;
await qt_pager('gotit');
exercise(A_WIS, true);
}
}
// C ref: quest.c:138 ok_to_quest
export function ok_to_quest() {
const qs = Qstat();
return !!((qs.got_quest || qs.got_thanks) || qs.killed_leader);
}
// C ref: quest.c:369 leader_speaks
export async function leader_speaks(mtmp) {
const qs = Qstat();
if (!mtmp?.mpeaceful) {
if (!qs.pissed_off) await qt_pager('leader_last');
qs.pissed_off = true;
mtmp.mstrategy &= ~STRAT_WAITMASK;
}
if (!on_level(game.u?.uz, game.qstart_level)) return;
if (!qs.pissed_off)
await chat_with_leader(mtmp);
}
// C ref: quest.c:401 nemesis_speaks
export async function nemesis_speaks() {
const qs = Qstat();
if (!qs.in_battle) {
if (game.u?.uhave?.questart) await qt_pager('nemesis_wantsit');
else if ((qs.made_goal ?? 0) === 1 || !qs.met_nemesis) await qt_pager('nemesis_first');
else if ((qs.made_goal ?? 0) < 4) await qt_pager('nemesis_next');
else if ((qs.made_goal ?? 0) < 7) await qt_pager('nemesis_other');
else if (!rn2(5)) await qt_pager('discourage');
if ((qs.made_goal ?? 0) < 7) qs.made_goal = (qs.made_goal ?? 0) + 1;
qs.met_nemesis = true;
} else if (!rn2(5)) {
await qt_pager('discourage');
}
}
// C ref: quest.c:471 quest_chat
export async function quest_chat(mtmp) {
const qs = Qstat();
if (mtmp?.m_id === qs.leader_m_id) {
await chat_with_leader(mtmp);
if (qs.pissed_off)
await setmangry(mtmp, false);
return;
}
}
// C ref: quest.c:493 quest_talk
export async function quest_talk(mtmp) {
const qs = Qstat();
if (mtmp?.m_id === qs.leader_m_id) {
await leader_speaks(mtmp);
return;
}
}
// C ref: quest.c:224 finish_quest
export async function finish_quest(obj) {
const qs = Qstat();
qs.got_thanks = true;
if (obj) game.u.uevent = game.u.uevent || {};
if (obj) game.u.uevent.qcompleted = 1;
}
|