All files / js artifact.js

71.78% Statements 374/521
64.18% Branches 95/148
88% Functions 22/25
71.78% Lines 374/521

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 52273x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 71x 71x 71x 73x 73x 73x 71x 71x 71x 71x 73x 73x 73x 69x 69x 69x 73x 73x 73x 27x 820x 820x 820x 18x 27x 73x 73x 73x 575x 575x 19550x 19550x 575x 575x 73x 73x 73x 73x 27x 27x 802x 9x 9x 9x 9x 9x 9x 9x 9x       9x 9x 802x 27x 27x 73x 73x 73x 12x 12x 12x 12x 12x 12x 73x 73x 73x 73x 73x 22x 22x 22x 22x 22x 22x 22x 22x 22x 726x 726x 726x 726x 726x 726x 726x 407x 407x 407x 407x 407x 407x 407x       726x 726x                                                   726x 22x 22x 22x 22x 22x       22x 22x 3x 3x 3x 3x 3x                   3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 22x 19x 19x     19x 22x 22x 22x 22x 22x 22x 22x 73x 73x 73x 93x 93x 73x 73x           73x 73x 73x 73x 496x 18x 496x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 137x           18x 18x 496x 496x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 18x 18x 496x                 18x 496x 73x 73x 73x 121x 116x 116x 5x 7x     5x 5x 5x 5x 5x 121x 121x 5x 5x   121x 73x 73x 73x 5x     5x 5x     5x 5x 5x 5x 5x     5x 5x 5x 5x 5x 73x 73x 73x 73x 5x 5x 5x 5x 5x 5x 5x 5x 73x 73x 73x 7x 7x 73x 73x 73x 24591x 24591x 24591x 73x 73x 73x 269x 13x 3x 3x 3x   269x 73x 73x 73x 276x 276x 73x 73x 73x           73x 73x 73x 73x 85x 85x 85x 85x 85x 85x 85x 85x 85x             85x 73x 73x 73x 73x 73x 116x 116x 116x 116x 3564x 3564x 3564x 3564x 11x 11x 11x 3564x 105x 116x 73x 73x 73x 73x 14x 14x 14x 14x 14x 73x 73x 73x 73x                                                                                     73x 73x 73x 73x 14x 14x 14x 14x 14x 14x 14x 14x 14x 4x   14x 14x 14x         14x 14x 10x 10x             10x 14x 14x 73x 73x 73x 73x 73x 23x 23x 23x 23x 23x 23x 23x 23x       23x 3x 3x 3x 23x 23x               23x 23x 23x 297x 11x 11x 297x 23x 23x 23x  
// artifact.js — Artifact system (port of artifact.c)
// Core artifact lookup, existence tracking, and property checks.
 
import { game } from './gstate.js';
import { artilist, NROFARTIFACTS, SPFX_ATTK, SPFX_DBONUS, SPFX_INTEL, SPFX_NOGEN, SPFX_RESTR, ART_GRIMTOOTH } from './artifacts.js';
import { rn2, rnd, c_d } from './rng.js';
import { Role_if, Race_if, Antimagic } from './macros.js';
import { is_covetous } from './mondata.js';
import { AD_PHYS, mons } from './monsters.js';
import { A_NONE, A_WIS, Has_contents, KILLED_BY, NON_PM, ONAME_RANDOM, W_ARTI, W_BALL, W_QUIVER, W_SADDLE, W_SWAPWEP } from './const.js';
import { Is_container, LEASH, OBJ_DESCR, TOOL_CLASS, WEAPON_CLASS } from './objects.js';
import { exercise } from './attrib.js';
import { losehp } from './hack.js';
import { pline, You } from './pline.js';
import { the, Tobjnam, xname } from './objnam.js';
import { fuzzymatch, s_suffix } from './hacklib.js';
import { carried } from './invent.js';
import { obj_shuffle_range } from './o_init.js';
import { bypass_obj, clear_bypasses, which_armor } from './worn.js';
 
// C ref: artifact.c:87 hack_artifacts()
function hack_artifacts() {
    // TODO: fix alignment of gift artifacts based on urole/initalign
}
 
// C ref: artifact.c:110 init_artifacts()
export async function init_artifacts() {
    game.artiexist = new Array(NROFARTIFACTS + 1).fill(false);
    game.artidisco = [];
    hack_artifacts();
}
 
// C ref: artifact.c:160 artiname(artinum) — get artifact name by index
export function artiname(artinum) {
    if (artinum <= 0 || artinum > NROFARTIFACTS) return '';
    return artilist[artinum]?.name || '';
}
 
// C ref: artifact.c:173 exist_artifact(otyp, name) — check if artifact exists
export function exist_artifact(otyp, name) {
    for (let i = 1; i <= NROFARTIFACTS; i++) {
        if (artilist[i].otyp === otyp && artilist[i].name === name)
            return !!(game.artiexist?.[i]);
    }
    return false;
}
 
// C ref: artifact.c:205 nartifact_exist() — count existing artifacts
export function nartifact_exist() {
    let ct = 0;
    for (let i = 1; i <= NROFARTIFACTS; i++) {
        if (game.artiexist?.[i]) ct++;
    }
    return ct;
}
 
// C ref: artifact.c:371 artifact_exists — mark/unmark artifact existence
// Called from oname() and mk_artifact(). Sets oartifact and artiexist[].
export function artifact_exists(otmp, name, mod, flgs) {
    if (otmp && name) {
        for (let m = 1; m <= NROFARTIFACTS && artilist[m].otyp; m++) {
            if (artilist[m].otyp === otmp.otyp && artilist[m].name === name) {
                otmp.oartifact = mod ? m : 0;
                otmp.age = 0;
                if (mod) {
                    // C ref: artifact.c:392 — default origin is ONAME_RANDOM
                    if (!(flgs & 0x007F)) // no origin bits set
                        flgs |= ONAME_RANDOM;
                    artifact_origin(otmp, flgs);
                } else {
                    // uncreate
                    if (game.artiexist) game.artiexist[m] = false;
                }
                break;
            }
        }
    }
}
 
// C ref: artifact.c:478 artifact_origin — set artifact tracking flags
// JS uses boolean artiexist[], so we just set exists = true.
function artifact_origin(otmp, aflags) {
    const a = otmp.oartifact;
    if (a) {
        if (game.artiexist) game.artiexist[a] = true;
    }
}
 
// C ref: artifact.c:172 mk_artifact — create a random artifact
// When alignment is A_NONE, converts otmp into a matching artifact.
// When alignment is specified, creates a new artifact of that alignment.
export function mk_artifact(otmp, alignment, max_giftvalue, adjust_spe) {
    const by_align = (alignment !== A_NONE);
    const o_typ = (by_align || !otmp) ? 0 : otmp.otyp;
    const unique = !by_align && otmp && !!(game.objects[o_typ]?.oc_unique);
    const eligible = [];
    let n = 0, altn = 0;
    const alteligible = [];
 
    // C ref: artifact.c:190 — gather eligible artifacts
    for (let m = 1; m <= NROFARTIFACTS && artilist[m].otyp; m++) {
        const a = artilist[m];
        if (game.artiexist?.[m])
            continue;
        if ((a.spfx & SPFX_NOGEN) || unique)
            continue;
        if (a.gift_value > max_giftvalue && !Role_if(a.role))
            continue;
 
        if (!by_align) {
            // looking for a particular type of item
            if (a.otyp === o_typ)
                eligible[n++] = m;
            continue;
        }

        // by_align path: looking for alignment-specific item for hero's role+race
        // C ref: artifact.c:208 — check alignment and race compatibility
        if ((a.alignment === alignment || a.alignment === A_NONE)
            && (a.race === NON_PM || !race_hostile(a.race))) {
            if (Role_if(a.role)) {
                // role-specific first choice — make it the only candidate
                eligible[0] = m;
                n = 1;
                break;
            }

            // C ref: artifact.c:220 — skill compatibility check
            let skill_compatibility = 3; // P_SKILLED
            if (game.objects[a.otyp]?.oc_class === WEAPON_CLASS) {
                let skill = game.objects[a.otyp]?.oc_skill ?? 0;
                if (skill < 0) skill = -skill;
                skill_compatibility = game.u?.weapon_skills?.[skill]?.max_skill ?? 0;
            }

            // C ref: artifact.c:230 — randomized eligibility check
            if ((a.alignment !== A_NONE || (game.u?.ugifts ?? 0) > 0 || !rn2(3)) &&
                (!rn2(4) || skill_compatibility >= 3 /*P_SKILLED*/ ||
                 (skill_compatibility >= 2 /*P_BASIC*/ && rn2(2)))) {
                eligible[n++] = m;
            } else {
                if (!n)
                    alteligible[altn++] = m;
            }
        }
    }
 
    // C ref: artifact.c:254 — resort to fallback list if main list was empty
    let candidates = eligible;
    let count = n;
    if (!n && altn) {
        candidates = alteligible;
        count = altn;
    }
 
    if (count) {
        // C ref: artifact.c:259 — pick one at random
        const m = candidates[rn2(count)];
        const a = artilist[m];
 
        if (by_align) {
            // C ref: artifact.c:263 — create appropriate object from scratch
            // This path requires mksobj which would be circular; for now
            // the by_align path (divine gifts) is not called from mksobj_init.
            // TODO: implement when pray.js gift path is ported
            if (otmp) {
                // dispose of original — not implemented yet
            }
            return null; // by_align not yet supported
        }
 
        // C ref: artifact.c:280-284 — christen the object
        otmp.oeroded = 0;
        otmp.oeroded2 = 0;
        // Set name directly (can't call async oname from sync context)
        if (!otmp.oextra) otmp.oextra = {};
        otmp.oextra.oname = a.name;
        otmp.oartifact = m;
        artifact_origin(otmp, ONAME_RANDOM);
 
        // C ref: artifact.c:285-295 — adjust spe for situational artifacts
        if (adjust_spe) {
            const new_spe = (otmp.spe || 0) + a.gen_spe;
            if (new_spe >= -10 && new_spe < 10)
                otmp.spe = new_spe;
        }
    } else {
        // nothing appropriate found; return original object
        if (by_align && otmp) {
            return null;
        }
    }
 
    // C ref: artifact.c:306 — permapoisoned check
    if (otmp && permapoisoned(otmp))
        otmp.opoisoned = true;
 
    return otmp;
}
 
// C ref: artifact.c:2837 permapoisoned — is object permanently poisoned?
export function permapoisoned(obj) {
    return !!(obj && obj.oartifact === ART_GRIMTOOTH);
}
 
// C ref: mondata.h:118 race_hostile — is race hostile to hero?
function race_hostile(pm) {
    const hatemask = game.urace?.hatemask || 0;
    const mflags2 = mons[pm]?.mflags2 ?? 0;
    return (mflags2 & hatemask) !== 0;
}
 
// C ref: artifact.c:908 touch_artifact — can mon touch this artifact?
// Returns 1 if safe, 0 if evaded/blasted. Consumes RNG when blast check fires.
export async function touch_artifact(obj, mon) {
    if (!obj?.oartifact) return 1;
    const oart = artilist[obj.oartifact];
    if (!oart || !oart.otyp) return 1;
 
    const yours = (mon === game.youmonst);
    const self_willed = !!(oart.spfx & SPFX_INTEL);
    let badclass, badalign;
 
    if (yours) {
        badclass = self_willed
            && ((oart.role !== NON_PM && !Role_if(oart.role))
                || (oart.race !== NON_PM && !Race_if(oart.race)));
        badalign = !!(oart.spfx & SPFX_RESTR)
            && oart.alignment !== A_NONE
            && (oart.alignment !== (game.u?.ualign?.type ?? 0)
                || (game.u?.ualign?.record ?? 0) < 0);
    } else if (mon && !is_covetous(mon.data)) {
        badclass = self_willed && oart.role !== NON_PM;
        badalign = !!(oart.spfx & SPFX_RESTR) && oart.alignment !== A_NONE;
    } else {
        badclass = badalign = false;
    }
 
    // C ref: artifact.c:944-960 — blast check with RNG
    if (((badclass || badalign) && self_willed)
        || (badalign && (!yours || !rn2(4)))) {
        if (!yours) return 0;
        // C ref: artifact.c:951 — hero blasted by artifact power
        await You(`are blasted by ${s_suffix(the(xname(obj)))} power!`);
        let dmg = c_d(Antimagic() ? 2 : 4, self_willed ? 10 : 4);
        // C ref: artifact.c:955-956 — silver damage bonus for silver-hating hero
        // TODO: Hate_silver check (requires ulycn/hates_silver)
        const buf = `touching ${oart.name}`;
        await losehp(dmg, buf, KILLED_BY);
        exercise(A_WIS, false);
    }
 
    // C ref: artifact.c:963-970 — totally incompatible = evade
    if (badclass && badalign && self_willed) {
        if (yours) {
            if (!carried(obj))
                await pline(`${Tobjnam(obj, 'evade')} your grasp!`);
            else
                await pline(`${Tobjnam(obj, 'are')} beyond your control!`);
        }
        return 0;
    }
    return 1;
}
 
// C ref: artifact.c:691 spec_abon(weapon, mon) — artifact to-hit bonus
export function spec_abon(weapon, mon) {
    if (!weapon?.oartifact) {
        return 0;
    }
    const arti = artilist[weapon.oartifact];
    if (!arti) {
        return 0;
    }
    /* C ref: artifact.c:1010 spec_applies()
       For artifacts without SPFX_DBONUS/SPFX_ATTK, special attacks apply
       exactly when attk.adtyp is AD_PHYS. This covers Cleaver's rnd(3)
       to-hit bonus path used by seed0362. */
    const hasConditionalTargeting = !!(arti.spfx & (SPFX_DBONUS | SPFX_ATTK));
    const applies = !hasConditionalTargeting && arti.attk?.adtyp === AD_PHYS;
    if (applies && arti.attk?.damn) {
        return rnd(arti.attk.damn);
    }
    return 0;
}
 
// C ref: artifact.c:1091 spec_dbon(weapon, mon, tmp) — artifact damage bonus
export function spec_dbon(weapon, mon, tmp) {
    if (!weapon?.oartifact) {
        return 0;
    }
    const arti = artilist[weapon.oartifact];
    if (!arti) {
        return 0;
    }
    /* Minimal C-faithful subset used by Cleaver:
       artifacts without SPFX_DBONUS/SPFX_ATTK apply on AD_PHYS. */
    const hasConditionalTargeting = !!(arti.spfx & (SPFX_DBONUS | SPFX_ATTK));
    const applies = !hasConditionalTargeting && arti.attk?.adtyp === AD_PHYS;
    if (!applies) {
        return 0;
    }
    if (arti.attk?.damd) {
        return rnd(arti.attk.damd);
    }
    return Math.max(tmp || 0, 1);
}
 
// C ref: artifact.c:1041 artifact_hit(magr, mdef, otmp, dmgptr, dieroll)
// Returns true if artifact special attack triggered.
export function artifact_hit(magr, mdef, otmp, dmgptr, dieroll) {
    if (!otmp?.oartifact) return false;
    // C ref: artifact.c:1470 — always add spec_dbon first.
    if (dmgptr && typeof dmgptr.value === 'number') {
        dmgptr.value += spec_dbon(otmp, mdef, dmgptr.value);
    }
    // TODO: full artifact hit effects/messages (Vorpal Blade beheading, etc.)
    return false;
}
 
// C ref: artifact.c:1500 arti_speak(obj) — artifact speaks
export function arti_speak(obj) {
    // TODO: port artifact speech
}
 
// ── is_quest_artifact: is this the current role's quest artifact? ──
export function is_quest_artifact(obj) {
    if (!obj || !obj.oartifact) return false;
    return obj.oartifact === game.urole?.questarti;
}
 
// ── any_quest_artifact: is this ANY role's quest artifact? ──
export function any_quest_artifact(obj) {
    if (!obj?.oartifact) return false;
    for (let i = 1; i <= NROFARTIFACTS; i++) {
        const arti = artilist[i];
        if (arti && arti.role >= 0 && obj.oartifact === i) return true;
    }
    return false;
}
 
// C: u_wield_art(artid) — check if player is wielding specific artifact
export function u_wield_art(artid) {
    return game.u.uwep && game.u.uwep.oartifact === artid;
}
 
// C ref: artifact.c:516 spec_ability(otmp, abil) — does artifact have given spfx?
export function spec_ability(otmp, abil) {
    if (!otmp?.oartifact) return false;
    const arti = artilist[otmp.oartifact];
    if (!arti) return false;
    return !!(arti.spfx & abil);
}
 
// C ref: artifact.c:2508 retouch_object — artifact check when wielding/wearing
// Called from ready_weapon, setworn, etc. Calls touch_artifact internally.
export async function retouch_object(objRef, loseit) {
    // C passes struct obj **objp; JS uses object ref directly
    const obj = objRef?.obj || objRef;
    if (!obj) return true;
 
    // C ref: artifact.c:2520 — call touch_artifact
    if (await touch_artifact(obj, game.youmonst)) {
        // touch_artifact returned true — hero can handle it
        return true;
    }

    // Hero can't handle the artifact
    if (loseit) {
        // Drop the object
    }
    return false;
}
 
// C ref: artifact.c:329 artifact_name — check if string is an artifact name
// Returns the canonical artifact name if found, null otherwise.
// Also sets otyp_p (output param) to the artifact's base object type.
export function artifact_name(name, otyp_p, fuzzy) {
    if (!name) return null;
    let nm = name;
    if (nm.toLowerCase().startsWith('the ')) nm = nm.slice(4);
    for (let i = 1; i < artilist.length && artilist[i].otyp; i++) {
        let aname = artilist[i].name;
        let cmp = aname;
        if (cmp.toLowerCase().startsWith('the ')) cmp = cmp.slice(4);
        if (fuzzy ? fuzzymatch(nm, cmp, " -", true) : nm.toLowerCase() === cmp.toLowerCase()) {
            if (otyp_p) otyp_p.value = artilist[i].otyp;
            return aname;
        }
    }
    return null;
}
 
// fuzzymatch: imported from hacklib.js
 
// C ref: artifact.c get_artifact(otmp) — lookup artifact struct for object.
function get_artifact(obj) {
    const idx = obj?.oartifact ?? 0;
    if (!idx || idx < 0 || idx >= artilist.length) return null;
    return artilist[idx] || null;
}
 
// C ref: artifact.c:575 restrict_name
// check whether hero can name an item with the given artifact name
export function restrict_name(otmp, name) {
    if (!name) return false;
    let aname = name;
    if (aname.toLowerCase().startsWith('the ')) aname = aname.slice(4);

    /* decide what types of objects are the same as otyp;
       if it's been discovered, then only itself matches;
       otherwise, include all other undiscovered objects
       of the same class which have the same description
       or share the same pool of shuffled descriptions */
    const otyp = otmp.otyp;
    const ocls = game.objects[otyp].oc_class;
    const sametype = new Array(game.objects.length).fill(false);
    sametype[otyp] = true;

    if (!game.objects[otyp].oc_name_known) {
        const odesc = OBJ_DESCR(game.objects[otyp]);
        if (odesc) {
            const { lo, hi } = obj_shuffle_range(otyp);
            for (let i = game.bases[ocls]; i < game.objects.length; i++) {
                if (game.objects[i].oc_class !== ocls) break;
                if (!game.objects[i].oc_name_known
                    && (i < lo || i > hi)
                    && OBJ_DESCR(game.objects[i]) === odesc) {
                    sametype[i] = true;
                }
            }
            for (let i = lo; i <= hi; i++) {
                sametype[i] = true;
            }
        }
    }

    for (let i = 1; i < artilist.length && artilist[i].otyp; i++) {
        const a = artilist[i];
        let artname = a.name;
        if (artname.toLowerCase().startsWith('the ')) artname = artname.slice(4);
        if (artname.toLowerCase() === aname.toLowerCase()) {
            return !sametype[a.otyp];
        }
    }
    return false;
}
 
// C ref: artifact.c:2598 untouchable
// check whether hero can handle an item; if not, unwield/unwear and
// optionally drop it
async function untouchable(obj, drop_untouchable) {
    if (!obj) return false;
    const art = get_artifact(obj);
    let beingworn = false, carryeffect = false, invoked = false;
    const wearmask = ~(W_QUIVER | (game.u.twoweap ? 0 : W_SWAPWEP) | W_BALL);
 
    beingworn = ((obj.owornmask & wearmask) !== 0
                 /* some items in use don't have any wornmask setting */
                 || (obj.oclass === TOOL_CLASS
                     && (obj.lamplit
                         || (obj.otyp === LEASH && obj.leashmon)
                         || (Is_container(obj) && Has_contents(obj)))));
 
    if (art && art.name !== 'non-artifact') {
        carryeffect = art.cary.adtyp || art.cspfx;
        invoked = (art.inv_prop > 0 && art.inv_prop <= 50 /* LAST_PROP */
                   && (game.u.uprops?.[art.inv_prop]?.extrinsic & W_ARTI) !== 0);
    }
 
    if (beingworn || carryeffect || invoked) {
        const objRef = { v: obj };
        if (!(await retouch_object(objRef, drop_untouchable))) {
            const newObj = objRef.v;
            if (invoked && newObj) {
                // reverse #invoke; stub for now
            }
            return true;
        }
    }
    return false;
}
 
// C ref: artifact.c:2640 retouch_equipment
// check all items currently in use (mostly worn) for touchability
let retouch_nesting = 0;
export async function retouch_equipment(dropflag) {
    const g = game;
    const u = g.u;
    if (!retouch_nesting++) {
        clear_bypasses();
    }
 
    const dropit = dropflag > 0;
    if (u.twoweap) {
        bypass_obj(u.uswapwep);
        await untouchable(u.uswapwep, dropit);
    }
    if (u.uwep) {
        bypass_obj(u.uwep);
        await untouchable(u.uwep, dropit);
    }
 
    if (u.usteed) {
        const saddle = which_armor(u.usteed, W_SADDLE);
        if (saddle) {
            if (await untouchable(saddle, false)) {
                // TODO: saddle came off steed
            }
        }
    }
 
    const all_items = (dropflag === 1);
    for (let obj = g.invent; obj; obj = obj.nobj) {
        if (obj.owornmask && !obj.bypass) {
            await untouchable(obj, all_items);
        }
    }
 
    retouch_nesting--;
}