All files / js sit.js

20.66% Statements 161/779
13.88% Branches 5/36
7.14% Functions 1/14
20.66% Lines 161/779

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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 77973x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x   73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x   73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x                 73x 73x 73x                                     73x                                                                                                                                                                                                                       73x                                                                                                                                                                                                                                                                                                                                                 73x                                                                       73x 73x 3x 3x 3x 3x 3x       3x 3x     3x                 3x             3x     3x 3x     3x 3x 1x 1x                                             3x                                                                 2x 2x           2x   2x     2x     2x   2x   2x   2x                   2x         2x   2x     2x   2x 2x 2x 3x 3x 73x                                   73x 73x                                                                                                             73x 73x                                                                                                                                                                                                             73x
// sit.js — Port of sit.c
// Sitting on thrones, cursing inventory, removing intrinsics.
import { game } from './gstate.js';
import { rn2, rnd, rn1, c_d } from './rng.js';
import { pline, You, Your, You_feel, You_cant, You_hear, pline_The, verbalize } from './pline.js';
import { Acid_resistance, Antimagic, Blind, Blind_telepat, Cold_resistance, Drain_resistance, Fire_resistance, Flying, Half_physical_damage, Half_spell_damage, Hallucination, In_V_tower, Levitation, See_invisible, Shock_resistance, Slimed, Underwater, Upolyd } from './macros.js';
import { levl, m_at, t_at } from './map_access.js';
import { adjattrib, exercise } from './attrib.js';
import { map_background, newsym, setBotl, set_mimic_blocking, shieldeff } from './display.js';
import { amorphous, humanoid, is_hider, is_prince, is_swimmer, lays_eggs, likes_lava, slithy, sticks, eyecount } from './mondata.js';
import { dotrap, uescaped_shaft, uteetering_at_seen_pit, water_damage } from './trap.js';
import { mons, PM_TRAPPER, PM_GREMLIN, PM_GIANT_EEL, PM_ELECTRIC_EEL, S_DRAGON, S_EEL } from './monsters.js';
import { A_CON, A_MAX, A_STR, A_WIS, AGGRAVATE_MONSTER, BLINDED, COLD_RES, CONFUSION, DRAWBRIDGE_DOWN, ECMD_OK, ECMD_TIME, EYE, FAST, FIRE_RES, FOOT, FOUNTAIN, FROMOUTSIDE, HEAD, INTRINSIC, INVIS, IS_ALTAR, IS_GRAVE, IS_SINK, IS_THRONE, KILLED_BY, KILLED_BY_AN, LADDER, OBJ_AT, POISON_RES, PROTECTION, ROOM, SEE_INVIS, SICK_ALL, SPIKED_PIT, STAIRS, STEALTH, TELEPAT, TELEPORT, TIMEOUT, TT_BEARTRAP, TT_BURIEDBALL, TT_INFLOOR, TT_LAVA, TT_PIT, TT_WEB, VIASITTING, W_SADDLE } from './const.js';
import { CLOTH, COIN_CLASS, CORPSE, CREAM_PIE, EGG, Is_box, SPBOOK_CLASS, SPE_REMOVE_CURSE, TOWEL, WATER_WALKING_BOOTS } from './objects.js';
import { ART_MAGICBANE, SPFX_INTEL } from './artifacts.js';
import { curse, mksobj, set_bknown, set_corpsenm, unbless, weight } from './mkobj.js';
import { makemon } from './makemon.js';
import { defsyms } from './symbols.js';
import { Tobjnam, Yobjnam2, makeplural, the, vtense, xname } from './objnam.js';
import { hliquid, hcolor } from './do_name.js';
import { cansee } from './vision.js';
import { delobj, identify_pack, stackobj } from './invent.js';
import { Monnam, aggravate, mhis, mon_nam, see_monsters, update_inventory } from './mon.js';
import { do_mapping } from './detect.js';
import { observe_object } from './invent.js';
import { make_blinded, make_sick, make_glib } from './mhitu.js';
import { is_pool, is_lava, is_ice } from './dbridge.js';
import { msummon } from './minion.js';
import { burn_away_slime, can_reach_floor, change_luck, losehp, money_cnt } from './hack.js';
import { which_armor } from './worn.js';
import { SetVoice, Soundeffect } from './sounds.js';
import { dropy, heal_legs, schedule_goto } from './do.js';
import { losexp } from './exper.js';
import { dryup } from './fountain.js';
import { courtmon } from './mkroom.js';
import { body_part, polyself } from './polyself.js';
import { make_confused, split_mon } from './potion.js';
import { altar_wrath } from './pray.js';
import { do_genocide, seffects } from './read.js';
import { remove_worn_item } from './steal.js';
import { tele } from './teleport.js';
import { makewish } from './zap.js';
import { morehungry, useupf } from './eat.js';
import { surface } from './hacklib.js';
import { u_wield_art, spec_ability } from './artifact.js';
import { y_n } from './input.js';
// ── Non-RNG stubs for functions not yet ported ──
// NOTE: differs from canonical steal.js — stub is no-op, canonical has full armor/weapon removal
// delobj imported from invent.js
// NOTE: differs from canonical zap.js — stub is no-op, canonical has full wish implementation
// NOTE: differs from canonical read.js — stub is no-op, canonical has full genocide implementation
// aggravate: imported from mon.js
// NOTE: differs from canonical potion.js — stub is no-op, canonical sets HConfusion and botl
// make_sick imported from mhitu.js
// NOTE: differs from canonical do.js — stub is no-op, canonical has full leg-healing with messages
// NOTE: differs from canonical mkroom.js — stub returns null, canonical uses RNG to pick monster
// map_background: imported from display.js
function newsym_force(x, y) { newsym(x, y); } // TODO: real newsym_force
// NOTE: differs from canonical mondata.js — stub returns false, canonical checks ptr.mflags2 & M2_PRINCE
// NOTE: differs from canonical mondata.js — stub returns false, canonical checks ptr.mflags1 & M1_HIDE
// NOTE: differs from canonical mondata.js — stub returns false, canonical checks ptr.mflags1 & M1_OVIPAROUS
// NOTE: differs from canonical mondata.js — stub returns false, canonical checks ptr.mflags1 & M1_SLITHY
// amorphous, humanoid, sticks imported from mondata.js
// likes_lava imported from mondata.js
// is_pool imported from dbridge.js
// is_lava imported from dbridge.js
// is_ice imported from dbridge.js
// C ref: mondata.h — eggs_in_water: oviparous eel swimmer
function eggs_in_water(ptr) { return lays_eggs(ptr) && ptr?.mlet === S_EEL && is_swimmer(ptr); }
// NOTE: differs from canonical polyself.js — stub uses lookup table, canonical calls mbodypart(game.player, part)
 // TODO
// NOTE: differs from canonical objnam.js — stub returns 'object', canonical has full object naming
// NOTE: differs from canonical hack.js — stub uses quan||0, canonical uses quan||1
// exercise imported from attrib.js
// losehp imported from hack.js
// dotrap imported from trap.js
// burn_away_slime imported from hack.js
// NOTE: differs from canonical fountain.js — stub is no-op, canonical has full fountain drying
// NOTE: differs from canonical potion.js — stub returns false, canonical has full clone logic
// water_damage imported from hack.js
// NOTE: differs from canonical pray.js — stub is no-op, canonical has full altar wrath with messages
// useupf: imported from eat.js
// Is_box: imported from objects.js
// update_inventory imported from mon.js
// u_wield_art: imported from artifact.js
// spec_ability: imported from artifact.js
// shieldeff imported from display.js
// which_armor imported from worn.js
// NOTE: differs from canonical mkobj.js — stub uses oc_weight||1, canonical uses oc_wt*quan with full corpse/container logic
// NOTE: differs from canonical mkobj.js — stub just sets corpsenm, canonical handles timers and weight
function egg_type_from_parent(mndx, goose) { return mndx; } // TODO
// NOTE: differs from canonical do.js — stub is no-op, canonical calls dropz with full equip/floor logic
// stackobj imported from invent.js
// Half_physical_damage imported from macros.js
// Half_spell_damage imported from macros.js
// Slimed imported from macros.js
// NOTE: differs from canonical exper.js — stub is no-op, canonical has full level drain with HP adjustment
function find_hell(lev) { /* TODO */ }
// NOTE: differs from canonical do.js — stub is no-op, canonical sets utotype/utolev/messages
// msummon imported from minion.js
// NOTE: differs from canonical read.js — stub returns 0, canonical has full scroll effects dispatch
// NOTE: differs from canonical polyself.js — stub is no-op, canonical has full polymorph implementation
// make_glib imported from mhitu.js
// set_mimic_blocking imported from display.js
// see_monsters imported from mon.js
// NOTE: differs from canonical input.js — stub returns ESC, canonical has full line input with display
// y_n: imported from input.js
// NOTE: differs from canonical mkobj.js — stub skips COIN_CLASS check and uses 1/0 instead of true/false
const NH_BLACK = 'black';
const NO_MM_FLAGS = 0;
const POLY_NOFLAGS = 0;
const Never_mind = 'Never mind.';
const voice_throne = 0;
// ── Helper: read/write uprops intrinsic ──
function getHProp(prop) {
    return game.u?.uprops?.[prop]?.intrinsic || 0;
}
function setHProp(prop, val) {
    if (!game.u.uprops) game.u.uprops = {};
    if (!game.u.uprops[prop]) game.u.uprops[prop] = {};
    game.u.uprops[prop].intrinsic = val;
}
// ── Ported functions ──
// C ref: sit.c:13 take_gold() — take away the hero's money
export async function take_gold() {
    let lost_money = 0;
    let otmp = game.invent;
    while (otmp) {
        const nobj = otmp.nobj;
        if (otmp.oclass === COIN_CLASS) {
            lost_money = 1;
            await remove_worn_item(otmp, false);
            delobj(otmp);
        }
        otmp = nobj;
    }
    if (!lost_money) {
        await You_feel('a strange sensation.');
    } else {
        await You('notice you have no gold!');
        setBotl('take_gold');
    }
}
// C ref: sit.c:237 special_throne_effect() — special throne in Vlad's tower
async function special_throne_effect(effect) {
    const u = game.u;
    const tx = u.ux, ty = u.uy;
    switch (effect) {
    case 1:
    case 2:
    case 3:
    case 4:
        // 4 chances of a wish, then throne disappears
        await makewish();
        levl(tx, ty).typ = ROOM;
        levl(tx, ty).flags = 0;
        map_background(tx, ty, false);
        newsym_force(tx, ty);
        await pline_The('throne disintegrates, having spent its power.');
        break;
    case 5:
        // permanent level drain
        await pline('Sitting on the throne was a terrible experience.');
        if (!Drain_resistance()) {
            await losexp('a bad experience sitting on a throne');
            if (u.ulevelmax > u.ulevel)
                u.ulevelmax -= 1;
        }
        break;
    case 6:
    {
        // grease hands and inventory
        await pline('A greasy liquid sprays all over you!');
        for (let otmp = game.invent; otmp; otmp = otmp.nobj) {
            if (otmp.oclass !== COIN_CLASS)
                otmp.greased = 1;
        }
        make_glib(rn1(101, 100));
        update_inventory();
        break;
    }
    case 7:
        // lose an intrinsic
        await attrcurse();
        await pline_The('throne somehow seems to be amused.');
        break;
    case 8:
    {
        // level teleport to Vibrating Square level
        const vs_level = {};
        find_hell(vs_level);
        vs_level.dlevel = (game.dungeons?.[vs_level.dnum]?.num_dunlevs || 1) - 1;
        if (u.uhave?.amulet) {
            await You_feel('extremely disoriented for a moment.');
        } else {
            schedule_goto(
                vs_level, 0, null,
                'You feel extremely out of place.');
        }
        break;
    }
    case 9:
    {
        // summon demons
        await pline_The('throne seeems to be calling for help!');
        await msummon(null);
        await msummon(null);
        await msummon(null);
        break;
    }
    case 10:
    {
        // confused blessed remove curse effect
        const fake_spellbook = {
            otyp: SPE_REMOVE_CURSE,
            oclass: SPBOOK_CLASS,
            blessed: 1,
        };
        const save_confusion = getHProp(CONFUSION); // CONFUSION index — use const
        setHProp(CONFUSION, 1); // HConfusion = 1
        await seffects(fake_spellbook);
        setHProp(CONFUSION, save_confusion);
        break;
    }
    case 11:
        // polymorph
        await pline('This throne was not meant for those such as you!');
        await You_feel('a change coming over you.');
        await polyself(POLY_NOFLAGS);
        break;
    case 12:
    {
        // acid damage
        await pline('The throne is covered in acid!');
        const dmg = Acid_resistance() ? rnd(16) : rnd(80);
        await losehp(dmg, 'acidic chair', KILLED_BY_AN);
        exercise(A_CON, false);
        break;
    }
    case 13:
    {
        // ability shuffle
        await pline('As you sit on the throne, your body and mind start to warp.');
        for (let ability = 0; ability < A_MAX; ++ability) {
            const adj = rn2(5) - 2;
            await adjattrib(ability, adj, -1);
        }
        break;
    }
    }
}
// C ref: sit.c:38 throne_sit_effect() — maybe do something when hero sits on a throne
async function throne_sit_effect() {
    const u = game.u;
    const tx = u.ux, ty = u.uy;
    const special_throne = !!In_V_tower(u.uz);
    if (rnd(6) > 4) {
        const effect = rnd(13);
        // wizard mode prompt omitted (debug only)
        if (special_throne) {
            await special_throne_effect(effect);
            return;
        }
        switch (effect) {
        case 1:
        {
            const attr = rn2(A_MAX);
            const loss = -rn1(4, 3);
            await adjattrib(attr, loss, false);
            await losehp(rnd(10), 'cursed throne', KILLED_BY_AN);
            break;
        }
        case 2:
            await adjattrib(rn2(A_MAX), 1, false);
            break;
        case 3:
        {
            await pline(`A${Shock_resistance() ? 'n' : ' massive'} electric shock shoots through your body!`);
            const dmg = Shock_resistance() ? rnd(6) : rnd(30);
            await losehp(dmg, 'electric chair', KILLED_BY_AN);
            exercise(A_CON, false);
            break;
        }
        case 4:
            await You_feel('much, much better!');
            if (Upolyd()) {
                if (u.mh >= (u.mhmax - 5))
                    u.mhmax += 4;
                u.mh = u.mhmax;
            }
            if (u.uhp >= (u.uhpmax - 5)) {
                u.uhpmax += 4;
                if (u.uhpmax > (u.uhppeak || 0))
                    u.uhppeak = u.uhpmax;
            }
            u.uhp = u.uhpmax;
            u.ucreamed = 0;
            await make_blinded(0, true);
            await make_sick(0, null, false, SICK_ALL);
            await heal_legs(0);
            setBotl('sit');
            break;
        case 5:
            await take_gold();
            break;
        case 6:
            if (u.uluck + rn2(5) < 0) {
                await You_feel('your luck is changing.');
                change_luck(1);
            } else {
                await makewish();
            }
            break;
        case 7:
        {
            const cnt = rnd(10);
            await pline('A voice echoes:');
            SetVoice(null, 0, 80, voice_throne);
            await verbalize(`Thine audience hath been summoned, ${game.flags.female ? 'Dame' : 'Sire'}!`);
            for (let i = 0; i < cnt; i++) {
                await makemon(courtmon(), tx, ty, NO_MM_FLAGS);
            }
            break;
        }
        case 8:
            await pline('A voice echoes:');
            SetVoice(null, 0, 80, voice_throne);
            await verbalize(`By thine Imperious order, ${game.flags.female ? 'Dame' : 'Sire'}...`);
            await do_genocide(5); // REALLY|ONTHRONE
            break;
        case 9:
            await pline('A voice echoes:');
            SetVoice(null, 0, 80, voice_throne);
            await verbalize('A curse upon thee for sitting upon this most holy throne!');
            if ((game.u.uluck || 0) > 0) {
                const blindTimeout = getHProp(BLINDED) || 0;
                await make_blinded(blindTimeout + rn1(100, 250), true);
                const luckVal = game.u.uluck || 0;
                change_luck((luckVal > 1) ? -rnd(2) : -1);
            } else {
                await rndcurse();
            }
            break;
        case 10:
        {
            const luck = game.u.uluck || 0;
            const hSeeInvis = getHProp(SEE_INVIS);
            if (luck < 0 || (hSeeInvis & INTRINSIC)) {
                if (game.level?.flags?.nommap) {
                    await pline('A terrible drone fills your head!');
                    const confTimeout = getHProp(CONFUSION) & TIMEOUT;                    await make_confused(confTimeout + rnd(30), false);
                } else {
                    await pline('An image forms in your mind.');
                    await do_mapping();
                }
            } else {
                if (!Blind()) {
                    await Your('vision becomes clear.');
                } else {
                    const num_of_eyes = eyecount(game.player?.data);
                    let eye = body_part(EYE);
                    switch (num_of_eyes) {
                    default:
                    case 2:
                        eye = makeplural(eye);
                        // FALLTHROUGH
                    case 1:
                        await Your(`${eye} ${vtense(eye, 'tingle')}...`);
                        break;
                    case 0:
                        await You(`have a very strange feeling in your ${body_part(HEAD)}.`);
                        break;
                    }
                }
                setHProp(SEE_INVIS, getHProp(SEE_INVIS) | FROMOUTSIDE);
                newsym(u.ux, u.uy);
            }
            break;
        }
        case 11:
            if ((game.u.uluck || 0) < 0) {
                await You_feel('threatened.');
                aggravate();
            } else {
                await You_feel('a wrenching sensation.');
                await tele();
            }
            break;
        case 12:
            await You('are granted an insight!');
            if (game.invent) {
                await identify_pack(rn2(5), false);
            }
            break;
        case 13:
        {
            await Your('mind turns into a pretzel!');
            const confTimeout = getHProp(CONFUSION) & TIMEOUT;            await make_confused(confTimeout + rn1(7, 16), false);
            break;
        }
        default:
            break;
        }
    } else {
        if (is_prince(game.player?.data) || u.uevent?.uhand_of_elbereth) {
            await You_feel('very comfortable here.');
        } else {
            await You_feel('somehow out of place...');
        }
    }
    // 3.7: remove throne with 1/3 chance
    if (!special_throne && !rn2(3)) {
        // wizard mode y_n omitted for now
        levl(tx, ty).typ = ROOM;
        levl(tx, ty).flags = 0;
        map_background(tx, ty, false);
        newsym_force(tx, ty);
        await pline_The(`throne ${cansee(tx, ty) ? 'vanishes' : 'has vanished'} in a puff of logic.`);
    }
}
// C ref: sit.c:352 lay_an_egg() — hero lays an egg
async function lay_an_egg() {
    const u = game.u;
    if (!game.flags.female) {
        await pline(`${Hallucination()
            ? 'You may think you are a platypus, but a male still'
            : 'Males'} can't lay eggs!`);
        return ECMD_OK;
    } else if (u.uhunger < (game.objects[EGG]?.oc_nutrition || 0)) {
        await You("don't have enough energy to lay an egg.");
        return ECMD_OK;
    } else if (eggs_in_water(game.player?.data)) {
        if (!(Underwater() || false /* Is_waterlevel */)) {
            await pline('A splash tetra you are not.');
            return ECMD_OK;
        }
        if (Upolyd()
            && (game.player?.data === mons[PM_GIANT_EEL]
                || game.player?.data === mons[PM_ELECTRIC_EEL])) {
            await You('yearn for the Sargasso Sea.');
            return ECMD_OK;
        }
    }
    const uegg = mksobj(EGG, false, false);
    uegg.spe = 1;
    uegg.quan = 1;
    uegg.owt = weight(uegg);
    set_corpsenm(uegg, egg_type_from_parent(u.umonnum, false));
    uegg.known = 1;
    observe_object(uegg);
    await You(`${eggs_in_water(game.player?.data) ? 'spawn' : 'lay'} an egg.`);
    await dropy(uegg);
    stackobj(uegg);
    await morehungry(game.objects[EGG]?.oc_nutrition || 0);
    return ECMD_TIME;
}
// C ref: sit.c:394 dosit() — #sit command
export async function dosit() {
    const sit_message_prefix = 'sit on the ';
    const u = game.u;
    const trap = t_at(u.ux, u.uy);
    const typ = levl(u.ux, u.uy)?.typ || 0;
    if (u.usteed) {
        await You(`are already sitting on ${mon_nam(u.usteed)}.`);
        return ECMD_OK;
    }
    if (u.uundetected && is_hider(game.player?.data)
        && u.umonnum !== PM_TRAPPER) {
        u.uundetected = 0;
    }
    if (!can_reach_floor(false)) {
        if (u.uswallow) {
            await pline('There are no seats in here!');
        } else if (Levitation()) {
            await You('tumble in place.');
        } else {
            await You('are sitting on air.');
        }
        return ECMD_OK;
    } else if (u.ustuck && !sticks(game.player?.data)) {
        if (humanoid(u.ustuck?.data)) {
            await pline(`${Monnam(u.ustuck)} won't offer ${mhis(u.ustuck)} lap.`);
        } else {
            await pline(`${Monnam(u.ustuck)} has no lap.`);
        }
        return ECMD_OK;
    } else if (is_pool(u.ux, u.uy) && !Underwater()) {
        // water walking — goto in_water
        return await dosit_in_water(u);
    } else if (Upolyd() && u.umonnum === PM_GREMLIN
               && (levl(u.ux, u.uy)?.typ === FOUNTAIN || is_pool(u.ux, u.uy))) {
        return await dosit_in_water(u);
    }
    if (OBJ_AT(u.ux, u.uy)
        && !(uteetering_at_seen_pit(trap) || uescaped_shaft(trap))) {
        const obj = game.level?.objects?.[u.ux]?.[u.uy];
        if (obj) {
            if (game.player?.data?.mlet === S_DRAGON && obj.oclass === COIN_CLASS) {
                await You(`coil up around your ${(obj.quan + money_cnt(game.invent) < u.ulevel * 1000) ? 'meager ' : ''}hoard.`);
            } else if (obj.otyp === TOWEL) {
                await pline("It's probably not a good time for a picnic...");
            } else {
                if (slithy(game.player?.data)) {
                    await You(`coil up around ${the(xname(obj))}.`);
                } else {
                    await You(`sit on ${the(xname(obj))}.`);
                }
                if (obj.otyp === CORPSE && amorphous(mons[obj.corpsenm])) {
                    await pline("It's squishy...");
                } else if (obj.otyp === CREAM_PIE) {
                    Soundeffect(0, 30);
                    await pline('Squelch!');
                    useupf(obj, obj.quan);
                } else if (!(Is_box(obj)
                             || (game.objects[obj.otyp]?.oc_material || 0) === CLOTH)) {
                    await pline("It's not very comfortable...");
                }
            }
        }
    } else if (trap !== null || (u.utrap && (u.utraptype >= TT_LAVA))) {
        if (u.utrap) {
            exercise(A_WIS, false);
            if (u.utraptype === TT_BEARTRAP) {
                await You_cant(`sit down with your ${body_part(FOOT)} in the bear trap.`);
                u.utrap++;
            } else if (u.utraptype === TT_PIT) {
                if (trap && trap.ttyp === SPIKED_PIT) {
                    await You('sit down on a spike.  Ouch!');
                    await losehp(Half_physical_damage() ? rn2(2) : 1,
                           'sitting on an iron spike', KILLED_BY);
                    exercise(A_STR, false);
                } else {
                    await You('sit down in the pit.');
                }
                u.utrap += rn2(5);
            } else if (u.utraptype === TT_WEB) {
                await You('sit in the spider web and get entangled further!');
                u.utrap += rn1(10, 5);
            } else if (u.utraptype === TT_LAVA) {
                await You(`sit in the ${hliquid('lava')}!`);
                if (Slimed()) await burn_away_slime();
                u.utrap += rnd(4);
                await losehp(c_d(2, 10), 'sitting in lava', KILLED_BY);
            } else if (u.utraptype === TT_INFLOOR
                       || u.utraptype === TT_BURIEDBALL) {
                await You_cant('maneuver to sit!');
                u.utrap++;
            }
        } else {
            await You(`${Flying() ? 'land' : 'sit down'}.`);
            await dotrap(trap, VIASITTING);
        }
    } else if ((Underwater() || false /* Is_waterlevel */)
                && !eggs_in_water(game.player?.data)) {
        if (false /* Is_waterlevel */) {
            await pline('There are no cushions floating nearby.');
        } else {
            await You('sit down on the muddy bottom.');
        }
    } else if (is_pool(u.ux, u.uy) && !eggs_in_water(game.player?.data)) {
        return await dosit_in_water(u);
    } else if (IS_SINK(typ)) {
        await You(`${sit_message_prefix}${defsyms[36]?.explanation || 'sink'}.`);
        await Your(`${humanoid(game.player?.data) ? 'rump' : 'underside'} gets wet.`);
    } else if (IS_ALTAR(typ)) {
        await You(`${sit_message_prefix}${defsyms[33]?.explanation || 'altar'}.`);
        await altar_wrath(u.ux, u.uy);
    } else if (IS_GRAVE(typ)) {
        await You(`${sit_message_prefix}${defsyms[34]?.explanation || 'grave'}.`);
    } else if (typ === STAIRS) {
        await You(`${sit_message_prefix}stairs.`);
    } else if (typ === LADDER) {
        await You(`${sit_message_prefix}ladder.`);
    } else if (is_lava(u.ux, u.uy)) {
        await You(`${sit_message_prefix}${hliquid('lava')}.`);
        await burn_away_slime();
        if (likes_lava(game.player?.data)) {
            await pline_The(`${hliquid('lava')} feels warm.`);
            return ECMD_TIME;
        }
        await pline_The(`${hliquid('lava')} burns you!`);
        const lavaDmg = c_d(Fire_resistance() ? 2 : 10, 10);
        await losehp(lavaDmg, 'sitting on lava', KILLED_BY);
    } else if (is_ice(u.ux, u.uy)) {
        await You(`${sit_message_prefix}${defsyms[39]?.explanation || 'ice'}.`);
        if (!Cold_resistance()) {
            await pline_The('ice feels cold.');
        }
    } else if (typ === DRAWBRIDGE_DOWN) {
        await You(`${sit_message_prefix}drawbridge.`);
    } else if (IS_THRONE(typ)) {
        await You(`${sit_message_prefix}${defsyms[35]?.explanation || 'throne'}.`);
        await throne_sit_effect();
    } else if (lays_eggs(game.player?.data)) {
        return await lay_an_egg();
    } else {
        await pline(`Having fun sitting on the ${surface(u.ux, u.uy)}?`);
    }
    return ECMD_TIME;
}
// Helper for the in_water goto label in dosit
async function dosit_in_water(u) {
    await You(`sit in the ${hliquid('water')}.`);
    if (Upolyd() && u.umonnum === PM_GREMLIN) {
        if (await split_mon(game.player, null)) {
            if (levl(u.ux, u.uy)?.typ === FOUNTAIN)
                await dryup(u.ux, u.uy, true);
        }
    } else {
        if (!rn2(10) && u.uarm) {
            await water_damage(u.uarm, 'armor', true);
        }
        if (!rn2(10) && u.uarmf && u.uarmf?.otyp !== WATER_WALKING_BOOTS) {
            await water_damage(u.uarm, 'armor', true); // C bug: uses uarm not uarmf
        }
    }
    return ECMD_TIME;
}
// C ref: sit.c:563 rndcurse() — curse a few inventory items at random
export async function rndcurse() {
    const mal_aura = 'feel a malignant aura surround %s.';
    if (u_wield_art(ART_MAGICBANE) && rn2(20)) {
        await You(mal_aura.replace('%s', 'the magic-absorbing blade'));
        return;
    }
    if (Antimagic()) {
        shieldeff(game.u.ux, game.u.uy);
    }
    await You(mal_aura.replace('%s', 'you'));
    let nobj = 0;
    for (let otmp = game.invent; otmp; otmp = otmp.nobj) {
        if (otmp.oclass === COIN_CLASS) continue;
        nobj++;
    }
    const cnt = rnd(Math.trunc(6 / ((Antimagic() ? 1 : 0) + (Half_spell_damage() ? 1 : 0) + 1)));
    if (nobj) {
        for (let i = cnt; i > 0; i--) {
            let onum = rnd(nobj);
            let otmp = null;
            for (otmp = game.invent; otmp; otmp = otmp.nobj) {
                if (otmp.oclass === COIN_CLASS) continue;
                if (--onum === 0) break;
            }
            if (!otmp || otmp.cursed) continue;
            if (otmp.oartifact && spec_ability(otmp, SPFX_INTEL)
                && rn2(10) < 8) {
                await pline(`${Tobjnam(otmp, 'resist')}!`);
                continue;
            }
            if (otmp.blessed)
                unbless(otmp);
            else
                curse(otmp);
        }
        update_inventory();
    }
    // steed's saddle
    const u = game.u;
    if (u.usteed && !rn2(4)) {
        const otmp = which_armor(u.usteed, W_SADDLE);
        if (otmp && !otmp.cursed) {
            if (otmp.blessed)
                unbless(otmp);
            else
                curse(otmp);
            if (!Blind()) {
                await pline(`${Yobjnam2(otmp, 'glow')} ${hcolor(otmp.cursed ? NH_BLACK : 'brown')}.`);
                otmp.bknown = Hallucination() ? 0 : 1;
            } else {
                otmp.bknown = 0;
            }
        }
    }
}
// C ref: sit.c:639 attrcurse() — remove a random intrinsic
export async function attrcurse() {
    let ret = 0;
    switch (rnd(11)) {
    case 1:
        if (getHProp(FIRE_RES) & INTRINSIC) {
            setHProp(FIRE_RES, getHProp(FIRE_RES) & ~INTRINSIC);
            await You_feel('warmer.');
            ret = FIRE_RES;
            break;
        }
        // FALLTHROUGH
    case 2:
        if (getHProp(TELEPORT) & INTRINSIC) {
            setHProp(TELEPORT, getHProp(TELEPORT) & ~INTRINSIC);
            await You_feel('less jumpy.');
            ret = TELEPORT;
            break;
        }
        // FALLTHROUGH
    case 3:
        if (getHProp(POISON_RES) & INTRINSIC) {
            setHProp(POISON_RES, getHProp(POISON_RES) & ~INTRINSIC);
            await You_feel('a little sick!');
            ret = POISON_RES;
            break;
        }
        // FALLTHROUGH
    case 4:
        if (getHProp(TELEPAT) & INTRINSIC) {
            setHProp(TELEPAT, getHProp(TELEPAT) & ~INTRINSIC);
            if (Blind() && !Blind_telepat())
                see_monsters();
            await Your('senses fail!');
            ret = TELEPAT;
            break;
        }
        // FALLTHROUGH
    case 5:
        if (getHProp(COLD_RES) & INTRINSIC) {
            setHProp(COLD_RES, getHProp(COLD_RES) & ~INTRINSIC);
            await You_feel('cooler.');
            ret = COLD_RES;
            break;
        }
        // FALLTHROUGH
    case 6:
        if (getHProp(INVIS) & INTRINSIC) {
            setHProp(INVIS, getHProp(INVIS) & ~INTRINSIC);
            await You_feel('paranoid.');
            ret = INVIS;
            break;
        }
        // FALLTHROUGH
    case 7:
        if (getHProp(SEE_INVIS) & INTRINSIC) {
            setHProp(SEE_INVIS, getHProp(SEE_INVIS) & ~INTRINSIC);
            if (!See_invisible()) {
                set_mimic_blocking();
                see_monsters();
                newsym(game.u.ux, game.u.uy);
            }
            await You(`${Hallucination() ? 'tawt you taw a puttie tat' : 'thought you saw something'}!`);
            ret = SEE_INVIS;
            break;
        }
        // FALLTHROUGH
    case 8:
        if (getHProp(FAST) & INTRINSIC) {
            setHProp(FAST, getHProp(FAST) & ~INTRINSIC);
            await You_feel('slower.');
            ret = FAST;
            break;
        }
        // FALLTHROUGH
    case 9:
        if (getHProp(STEALTH) & INTRINSIC) {
            setHProp(STEALTH, getHProp(STEALTH) & ~INTRINSIC);
            await You_feel('clumsy.');
            ret = STEALTH;
            break;
        }
        // FALLTHROUGH
    case 10:
        if (getHProp(PROTECTION) & INTRINSIC) {
            setHProp(PROTECTION, getHProp(PROTECTION) & ~INTRINSIC);
            await You_feel('vulnerable.');
            ret = PROTECTION;
            break;
        }
        // FALLTHROUGH
    case 11:
        if (getHProp(AGGRAVATE_MONSTER) & INTRINSIC) {
            setHProp(AGGRAVATE_MONSTER, getHProp(AGGRAVATE_MONSTER) & ~INTRINSIC);
            await You_feel('less attractive.');
            ret = AGGRAVATE_MONSTER;
            break;
        }
        // FALLTHROUGH
    default:
        break;
    }
    return ret;
}
/*sit.js*/