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 | 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 450x 450x 450x 450x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 6x 6x 6x 6x 6x 6x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4670x 4638x 4638x 4638x 4638x 4638x 4638x 4638x 4670x 4670x 4670x 4670x 4670x 4670x 73x 73x 73x 73x 73x 73x 73x 73x 73x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 73x 73x 73x 16x 16x 13x 13x 13x 16x 73x 73x 73x 73x | // steal.js -- Port of steal.c
// Theft mechanics: nymph/monkey stealing, leprechaun gold theft,
// Wizard/nemesis artifact theft, mimic absorption, monster item drops.
//
// Ported functions:
// somegold() -- proportional subset of gold
// findgold() -- find gold in object chain
// stealgold() -- leprechaun gold theft
// thiefdead() -- cleanup when thief dies mid-steal
// unresponsive() -- check if hero can respond to seduction
// unstolenarm() -- callback: thief died while hero was removing armor
// await stealarm() -- callback: finish multi-turn armor theft
// remove_worn_item() -- unwear item (theft or transform)
// worn_item_removal() -- remove_worn_item with preface message
// steal() -- main steal attack
// mpickobj() -- monster picks up object (bottleneck, re-exported)
// stealamulet() -- Wizard/nemesis steal quest artifact or invocation item
// maybe_absorb_item() -- mimic absorbs poked item
// mdrop_obj() -- monster drops one object (bottleneck, re-exported)
// mdrop_special_objs()-- prevent monster from leaving with key items
// relobj() -- release all objects from dead/fleeing monster
import { game } from './gstate.js';
import { add_to_minv, rloco, unknow_object } from './mkobj.js';
import { formatMonsterEventRef, rn1, rn2, rnd, pushRngLogEntry } from './rng.js';
import { pline, pline_mon, impossible } from './pline.js';
import { Blind, Flying, Levitation, Punished, ULEFTY, is_fainted } from './macros.js';
import { Adjmonnam, DEADMONSTER, Monnam, Some_Monnam, mon_nam, monflee, noit_Monnam, stop_occupation, y_monnam } from './mon.js';
import { Tobjnam, distant_name, doname, makeplural, otense, simpleonames, xname, yname } from './objnam.js';
import { canseemon, canspotmon, newsym, setBotl } from './display.js';
import { cansee } from './vision.js';
import { bimanual, distu, Mgender, monnear, ROLL_FROM, s_suffix, strstri, upstart } from './hacklib.js';
import { nomul } from './cmd.js';
import { uwepgone, uswapwepgone, uqwepgone, welded } from './wield.js';
import { pmname } from './do_name.js';
import { encumber_msg } from './pickup.js';
import { touch_petrifies, throws_rocks, can_teleport, slithy, is_animal,
dmgtype, attacktype, monsndx } from './mondata.js';
import { carried, carry_obj_effects, count_unpaid, freeinv, mergable, stackobj } from './invent.js';
import { mons, AD_SITM, AT_ENGL, S_NYMPH, M1_ANIMAL } from './monsters.js';
import { AMULET_CLASS, AMULET_OF_YENDOR, ARMOR_CLASS, BELL, BELL_OF_OPENING, BOULDER, CANDELABRUM_OF_INVOCATION, COIN_CLASS, CORPSE, FAKE_AMULET_OF_YENDOR, FOOD_CLASS, GOLD_PIECE, LEASH, RING_CLASS, ROCK_CLASS, SPE_BOOK_OF_THE_DEAD, TOOL_CLASS } from './objects.js';
import { W_ARMOR, W_ACCESSORY, W_WEAPONS, W_AMUL, W_RING, W_TOOL, W_BALL, W_CHAIN, W_SADDLE, W_WEP, W_SWAPWEP, W_QUIVER, W_ARMG, LARGEST_INT, OBJ_FREE, OBJ_FLOOR, OBJ_INVENT, OBJ_DELETED, OBJ_MINVENT, RLOC_MSG, PLNMSG_MON_TAKES_OFF_ITEM, LOST_STOLEN, LOST_THROWN, LOST_DROPPED, LOST_NONE, TT_BURIEDBALL, SHOPBASE, FOOT, HAND, LEFT_HANDED } from './const.js';
import { obfree, obj_extract_self, place_object, splitobj, weight } from './mkobj.js';
// add_to_minv: imported from mkobj.js (via first import line)
import { costly_spot, find_objowner, in_rooms, shop_keeper, subfrombill } from './shk.js';
import { obj_sheds_light, snuff_light_source } from './light.js';
import { any_quest_artifact, is_quest_artifact, touch_artifact } from './artifact.js';
import { flooreffects } from './do.js';
import { setworn, setnotworn, extract_from_minvent,
update_mon_extrinsics } from './worn.js';
import { Armor_off, Cloak_off, Boots_off, Gloves_off, Helmet_off,
Shield_off, Shirt_off, Amulet_off, Ring_gone, Blindf_off,
donning, cancel_don, doffing, stop_donning } from './do_wear.js';
import { body_part, mbodypart, skinback } from './polyself.js';
import { minstapetrify, unconscious } from './trap.js';
import { inv_cnt, money_cnt } from './hack.js';
import { can_carry, droppables } from './dogmove.js';
import { Has_contents, engulfing_u } from './const.js';
import { unpunish } from './read.js';
import { rloc, tele_restrict } from './teleport.js';
import { o_unleash } from './apply.js';
import { obj_resists } from './zap.js';
import { maybe_finished_meal } from './eat.js';
// ── Local stubs for unported objnam functions ──
// ── Non-RNG stubs for functions not yet ported ──
// Some_Monnam: imported from mon.js
function armor_simple_name(obj) {
if (!obj) return 'armor';
return game.objects[obj.otyp]?.oc_name || 'armor';
}
// NOTE: differs from canonical hacklib.js — local takes (x, y) and reads game.u directly;
// canonical takes (player, x, y)
// can_carry imported from dogmove.js
// add_to_minv: imported from mkobj.js
// maybe_finished_meal: imported from eat.js (circular dep resolves at runtime)
// is_fainted: imported from macros.js
function openholdingtrap(_mon, _dummy) { return false; } // TODO: port from trap.c
// unknow_object: imported from mkobj.js
// NOTE: differs from canonical dogmove.js — local returns first inventory item
// unconditionally; canonical has full animal/mindless/weapon-keeping logic
// rloco: imported from mkobj.js
// ULEFTY: imported from macros.js
function RING_ON_PRIMARY() { return ULEFTY() ? game.u.uleft : game.u.uright; }
function RING_ON_SECONDARY() { return ULEFTY() ? game.u.uright : game.u.uleft; }
// ── Ported functions ──
// C ref: steal.c:14 -- somegold(lmoney)
// Proportional subset of gold; RNG: rn1()
export function somegold(lmoney) {
let igold = (lmoney >= LARGEST_INT) ? LARGEST_INT : lmoney;
if (igold < 50) {
/* all gold */
} else if (igold < 100) {
igold = rn1(igold - 25 + 1, 25);
} else if (igold < 500) {
igold = rn1(igold - 50 + 1, 50);
} else if (igold < 1000) {
igold = rn1(igold - 100 + 1, 100);
} else if (igold < 5000) {
igold = rn1(igold - 500 + 1, 500);
} else if (igold < 10000) {
igold = rn1(igold - 1000 + 1, 1000);
} else {
igold = rn1(igold - 5000 + 1, 5000);
}
return igold;
}
// C ref: steal.c:44 -- findgold(chain)
// Find first gold object in an object chain.
export function findgold(chain) {
while (chain && chain.otyp !== GOLD_PIECE)
chain = chain.nobj;
return chain;
}
// C ref: steal.c:57 -- stealgold(mtmp)
// Leprechaun steals gold. RNG: rn2(), somegold()
export async function stealgold(mtmp) {
const g = game;
const u = g.u;
// g_at: find gold on floor at hero's position
let fgold = null;
if (g.level) {
for (const obj of g.level.objects) {
if (obj.ox === u.ux && obj.oy === u.uy) {
if (!fgold && obj.otyp !== GOLD_PIECE) continue;
if (obj.otyp === GOLD_PIECE) { fgold = obj; break; }
}
}
}
// Actually: walk nexthere chain. Simplified: scan floor objects.
// Skip lesser coins: find first GOLD_PIECE on floor at u.ux,u.uy
fgold = null;
if (g.level) {
for (const obj of g.level.objects) {
if (obj.ox === u.ux && obj.oy === u.uy && obj.otyp === GOLD_PIECE) {
fgold = obj;
break;
}
}
}
// Do you have real gold?
const ygold = findgold(g.invent);
if (fgold && (!ygold || fgold.quan > ygold.quan || !rn2(5))) {
obj_extract_self(fgold);
await add_to_minv(mtmp, fgold);
newsym(u.ux, u.uy);
let who, whose, what;
if (u.usteed) {
who = u.usteed;
whose = s_suffix(y_monnam(who));
what = makeplural(mbodypart(who, FOOT));
} else {
who = game.player;
whose = 'your';
what = makeplural(body_part(FOOT));
}
/* avoid "between your rear regions" */
if (slithy(who?.data))
what = 'coils';
/* reduce "rear hooves/claws" to "hooves/claws" */
if (what.startsWith('rear '))
what = what.slice(5);
await pline(`${Monnam(mtmp)} quickly snatches some gold from ${(Levitation() || Flying()) ? 'beneath' : 'between'} ${whose} ${what}!`);
if (!ygold || !rn2(5)) {
if (!tele_restrict(mtmp))
await rloc(mtmp, RLOC_MSG);
await monflee(mtmp, 0, false, false);
}
} else if (ygold) {
const gold_price = game.objects[GOLD_PIECE].oc_cost;
let tmp = Math.trunc((somegold(money_cnt(g.invent)) + gold_price - 1) / gold_price);
tmp = Math.min(tmp, ygold.quan);
let stolen_gold;
if (tmp < ygold.quan) {
stolen_gold = splitobj(ygold, tmp);
} else {
setnotworn(ygold);
stolen_gold = ygold;
}
freeinv(stolen_gold);
await add_to_minv(mtmp, stolen_gold);
await pline('Your purse feels lighter.');
if (!tele_restrict(mtmp))
await rloc(mtmp, RLOC_MSG);
await monflee(mtmp, 0, false, false);
g.disp = g.disp || {};
setBotl('steal');
}
}
// C ref: steal.c:119 -- thiefdead()
// Monster who was stealing from hero has just died.
export function thiefdead() {
const g = game;
g.stealmid = 0;
if (g.afternmv === stealarm) {
g.afternmv = unstolenarm;
g.nomovemsg = null;
}
}
// C ref: steal.c:131 -- unresponsive()
// Checks whether hero can respond to seduction attempts.
export function unresponsive() {
const g = game;
if (g.multi >= 0)
return false;
return (unconscious() || is_fainted()
|| (g.multi_reason
&& (g.multi_reason.startsWith('frozen')
|| g.multi_reason.startsWith('paralyzed'))));
}
// C ref: steal.c:146 -- unstolenarm()
// Called via afternmv when hero finishes removing armor but thief died.
async function unstolenarm() {
const g = game;
let obj;
for (obj = g.invent; obj; obj = obj.nobj)
if (obj.o_id === g.stealoid)
break;
g.stealoid = 0;
if (obj) {
await pline(`You finish taking off your ${armor_simple_name(obj)}.`);
}
return 0;
}
// C ref: steal.c:164 -- await stealarm()
// Finish stealing armor that takes multiple turns to remove.
async function stealarm() {
const g = game;
let mtmp, otmp, nextobj;
if (!g.stealoid || !g.stealmid)
goto_botm();
function goto_botm() {
g.stealoid = g.stealmid = 0;
}
for (otmp = g.invent; otmp; otmp = nextobj) {
nextobj = otmp.nobj;
if (otmp.o_id === g.stealoid) {
for (mtmp = g.fmon; mtmp; mtmp = mtmp.nmon) {
if (mtmp.m_id === g.stealmid) {
if (DEADMONSTER(mtmp)) {
impossible('await stealarm(): dead monster stealing');
goto_botm();
return 0;
}
if (!dmgtype(mtmp.data, AD_SITM)
|| distu(mtmp.mx, mtmp.my) > 2) {
goto_botm();
return 0;
}
if (otmp.unpaid)
subfrombill(otmp, shop_keeper(g.u.ushops?.[0] || ''));
freeinv(otmp);
await pline(`${Monnam(mtmp)} steals ${doname(otmp)}!`);
await mpickobj(mtmp, otmp); /* may free otmp */
/* Implies seduction, "you gladly hand over ..."
so we don't set mavenge bit here. */
await monflee(mtmp, 0, false, false);
if (!tele_restrict(mtmp))
await rloc(mtmp, RLOC_MSG);
break;
}
}
break;
}
}
g.stealoid = g.stealmid = 0;
return 0;
}
// C ref: steal.c:210 -- remove_worn_item(obj, unchain_ball)
// Remove a worn item from hero. Used for theft, seduction, stone-to-flesh.
export async function remove_worn_item(obj, unchain_ball) {
const g = game;
if (donning(obj))
cancel_don();
if (!obj.owornmask)
return;
const oldinuse = obj.in_use;
obj.in_use = 1;
if (obj.owornmask & W_ARMOR) {
if (obj === g.u.uskin) {
impossible('Removing embedded scales?');
skinback(true);
}
if (obj === g.u.uarm)
await Armor_off();
else if (obj === g.u.uarmc)
await Cloak_off();
else if (obj === g.u.uarmf)
await Boots_off();
else if (obj === g.u.uarmg)
await Gloves_off();
else if (obj === g.u.uarmh)
Helmet_off();
else if (obj === g.u.uarms)
Shield_off();
else if (obj === g.u.uarmu)
Shirt_off();
else
setworn(null, obj.owornmask & W_ARMOR);
} else if (obj.owornmask & W_AMUL) {
await Amulet_off();
} else if (obj.owornmask & W_RING) {
await Ring_gone(obj);
} else if (obj.owornmask & W_TOOL) {
await Blindf_off(obj);
} else if (obj.owornmask & W_WEAPONS) {
if (obj === g.u.uwep)
await uwepgone();
if (obj === g.u.uswapwep)
uswapwepgone();
if (obj === g.u.uquiver)
uqwepgone();
}
if (obj.owornmask & (W_BALL | W_CHAIN)) {
if (unchain_ball)
unpunish();
} else if (obj.owornmask) {
/* catchall */
setnotworn(obj);
}
if (obj.where === OBJ_DELETED)
impossible(`remove_worn_item() "${simpleonames(obj)}" deleted!`);
obj.in_use = oldinuse;
}
// C ref: steal.c:293 -- worn_item_removal(mon, obj)
// Remove worn item with a preface message.
async function worn_item_removal(mon, obj) {
let objbuf = doname(obj);
/* massage the object description */
let strip_art = 0;
if (objbuf.startsWith('the ')) strip_art = 4;
else if (objbuf.startsWith('an ')) strip_art = 3;
else if (objbuf.startsWith('a ')) strip_art = 2;
if (strip_art) {
const article = objbuf.slice(0, strip_art);
const replacement = (obj === game.u.uchain) ? 'the ' : 'your ';
objbuf = objbuf.replace(article, replacement);
}
/* remove annotations */
objbuf = objbuf.replace(' (being worn)', '');
objbuf = objbuf.replace(' (alternate weapon; not wielded)', '');
/* convert "ring (on left hand)" to "ring (from left hand)" */
const onMatch = strstri(objbuf, ' (on ');
if (onMatch >= 0) {
const after = objbuf.slice(onMatch + 5);
if (after.startsWith('left ') || after.startsWith('right ')) {
objbuf = objbuf.slice(0, onMatch + 2)
+ objbuf.slice(onMatch + 2).replace('on', 'from');
}
}
let verb;
if ((obj.owornmask & W_WEAPONS) !== 0) verb = 'disarms';
else if ((obj.owornmask & W_ACCESSORY) !== 0) verb = 'removes';
else verb = 'takes off';
await pline(`${Some_Monnam(mon)} ${verb} ${objbuf}.`);
game.iflags = game.iflags || {};
game.iflags.last_msg = PLNMSG_MON_TAKES_OFF_ITEM;
/* removal might trigger more messages */
await remove_worn_item(obj, true);
}
// C ref: steal.c:342 -- steal(mtmp, objnambuf)
// Main steal attack for nymphs and monkeys.
// Returns 1 when something was stolen, -1 if monster died, 0 otherwise.
export async function steal(mtmp, objnambuf) {
const g = game;
const u = g.u;
let otmp;
let tmp, could_petrify, armordelay, olddelay, icnt;
let named = 0, retrycnt = 0;
const monkey_business = is_animal(mtmp.data);
let seen = canspotmon(mtmp);
const was_punished = Punished();
if (objnambuf)
objnambuf.value = '';
/* the following is true if successful on first of two attacks. */
if (!monnear(mtmp, u.ux, u.uy))
return 0;
let Monnambuf = Some_Monnam(mtmp);
/* food being eaten might already be used up */
if (g.occupation)
await maybe_finished_meal(false);
icnt = inv_cnt(false); /* don't include gold */
if (!icnt || (icnt === 1 && g.u.uskin)) {
/* Not even a thousand men in armor can strip a naked man. */
return await nothing_to_steal();
}
// Adornment ring check (skip for animals or if wearing gloves)
if (!monkey_business && !g.u.uarmg) {
// Adornment not ported; skip ring special cases
}
// retry label equivalent
let retry_count = 0;
while (true) {
tmp = 0;
for (otmp = g.invent; otmp; otmp = otmp.nobj)
if ((!g.u.uarm || otmp !== g.u.uarmc) && otmp !== g.u.uskin
&& otmp.oclass !== COIN_CLASS)
tmp += (otmp.owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
if (!tmp)
return await nothing_to_steal();
tmp = rn2(tmp);
for (otmp = g.invent; otmp; otmp = otmp.nobj)
if ((!g.u.uarm || otmp !== g.u.uarmc) && otmp !== g.u.uskin
&& otmp.oclass !== COIN_CLASS) {
tmp -= (otmp.owornmask & (W_ARMOR | W_ACCESSORY)) ? 5 : 1;
if (tmp < 0)
break;
}
if (!otmp) {
impossible('Steal fails!');
return 0;
}
/* can't steal ring(s) while wearing gloves */
if ((otmp === g.u.uleft || otmp === g.u.uright) && g.u.uarmg)
otmp = g.u.uarmg;
/* can't steal gloves while wielding - so steal the wielded item. */
if (otmp === g.u.uarmg && g.u.uwep)
otmp = g.u.uwep;
/* can't steal armor while wearing cloak - so steal the cloak. */
else if (otmp === g.u.uarm && g.u.uarmc)
otmp = g.u.uarmc;
/* can't steal shirt while wearing cloak or suit */
else if (otmp === g.u.uarmu && g.u.uarmc)
otmp = g.u.uarmc;
else if (otmp === g.u.uarmu && g.u.uarm)
otmp = g.u.uarm;
// gotobj:
if (otmp.o_id === g.stealoid)
return 0;
if (otmp.otyp === BOULDER && !throws_rocks(mtmp.data)) {
if (!retry_count++) continue; // goto retry
// fall through to cant_take
return await cant_take(Monnambuf, otmp, monkey_business);
}
break; // exit retry loop
}
/* animals can't overcome curse stickiness nor unlock chains */
if (monkey_business) {
let ostuck;
if (otmp === g.u.uball)
ostuck = true;
else if (otmp === g.u.uquiver || (otmp === g.u.uswapwep && !u.twoweap))
ostuck = false;
else
ostuck = ((otmp.cursed && otmp.owornmask)
|| (otmp === RING_ON_PRIMARY() && welded(g.u.uwep))
|| (otmp === RING_ON_SECONDARY() && welded(g.u.uwep)
&& bimanual(g.u.uwep)));
if (ostuck || can_carry(mtmp, otmp) === 0) {
return await cant_take(Monnambuf, otmp, monkey_business);
}
}
if (otmp.otyp === LEASH && otmp.leashmon) {
if (monkey_business && otmp.cursed)
return await cant_take(Monnambuf, otmp, monkey_business);
o_unleash(otmp);
}
const was_doffing = doffing(otmp);
olddelay = await stop_donning(otmp);
await stop_occupation();
if (otmp.owornmask & (W_ARMOR | W_ACCESSORY)) {
switch (otmp.oclass) {
case TOOL_CLASS:
case AMULET_CLASS:
case RING_CLASS:
case FOOD_CLASS: /* meat ring */
await worn_item_removal(mtmp, otmp);
break;
case ARMOR_CLASS:
armordelay = game.objects[otmp.otyp].oc_delay || 0;
if (olddelay > 0 && olddelay < armordelay)
armordelay = olddelay;
if (monkey_business || unresponsive()) {
if (armordelay >= 1 && !olddelay && rn2(10))
return await cant_take(Monnambuf, otmp, monkey_business);
await worn_item_removal(mtmp, otmp);
break;
} else {
const curssv = otmp.cursed;
const slowly = (armordelay >= 1 || g.multi < 0);
otmp.cursed = 0;
if (g.flags?.female)
await pline(`${!seen ? 'She' : Monnambuf} charms you. You gladly ${curssv ? 'let her take' : !slowly ? 'hand over' : was_doffing ? 'continue removing' : 'start removing'} your ${armor_simple_name(otmp)}.`);
else
await pline(`${!seen ? 'She' : Adjmonnam(mtmp, 'beautiful')} seduces you and ${curssv ? 'helps you to take' : !slowly ? 'you take' : was_doffing ? 'you continue taking' : 'you start taking'} off your ${armor_simple_name(otmp)}.`);
named++;
nomul(-armordelay);
g.multi_reason = 'taking off clothes';
g.nomovemsg = null;
await remove_worn_item(otmp, true);
otmp.cursed = curssv;
if (g.multi < 0) {
g.stealoid = otmp.o_id;
g.stealmid = mtmp.m_id;
g.afternmv = stealarm;
return 0;
}
}
break;
default:
impossible(`Tried to steal a strange worn thing. [${otmp.oclass}]`);
}
/* hero's blindfold might have just been stolen */
if (!seen && canspotmon(mtmp))
Monnambuf = Monnam(mtmp);
} else if (otmp.owornmask) { /* weapon or ball&chain */
let item = otmp;
if (otmp === g.u.uball)
item = g.u.uchain;
await worn_item_removal(mtmp, item);
if ((otmp.owornmask & W_WEAPONS) !== 0)
await remove_worn_item(otmp, false);
}
/* do this before removing it from inventory */
if (objnambuf)
objnambuf.value = yname(otmp);
/* usually set mavenge bit so knights won't suffer an alignment penalty
during retaliation; not applicable for removing attached iron ball */
if (!game.Conflict && !(was_punished && !Punished()))
mtmp.mavenge = 1;
if (otmp.unpaid)
subfrombill(otmp, shop_keeper(u.ushops?.[0] || ''));
freeinv(otmp);
if ((game.iflags?.last_msg === PLNMSG_MON_TAKES_OFF_ITEM)
&& mtmp.data?.mlet === S_NYMPH)
++named;
await pline(`${named ? 'She' : Monnambuf} stole ${doname(otmp)}.`);
await encumber_msg();
could_petrify = (otmp.otyp === CORPSE
&& touch_petrifies(mons[otmp.corpsenm]));
otmp.how_lost = LOST_STOLEN;
await mpickobj(mtmp, otmp); /* may free otmp */
if (could_petrify && !(mtmp.misc_worn_check & W_ARMG)) {
minstapetrify(mtmp, true);
return -1;
}
return (g.multi < 0) ? 0 : 1;
// ── inner helper: nothing_to_steal ──
async function nothing_to_steal() {
if (Punished() && !monkey_business && rn2(4)) {
/* uball is not carried (uchain never is) */
if (g.u.uball && g.u.uball.where === OBJ_FLOOR)
await worn_item_removal(mtmp, g.u.uchain);
} else if (u.utrap && u.utraptype === TT_BURIEDBALL
&& !monkey_business && !rn2(4)) {
let dummy = { value: false };
await pline(`${Monnambuf} takes off your unseen chain.`);
openholdingtrap(game.player, dummy);
} else if (Blind()) {
await pline('Somebody tries to rob you, but finds nothing to steal.');
} else if (inv_cnt(true) > inv_cnt(false)) {
await pline(`${Monnambuf} tries to rob you, but isn't interested in gold.`);
} else {
await pline(`${Monnambuf} tries to rob you, but there is nothing to steal!`);
}
return 1; /* let her flee */
}
// ── inner helper: cant_take ──
async function cant_take(monnambuf, obj, is_monkey) {
const how = ['steal', 'snatch', 'grab', 'take'];
await pline(`${monnambuf} tries to ${ROLL_FROM(how)} ${(obj.owornmask & W_ARMOR) ? 'your ' : ''}${(obj.owornmask & W_ARMOR) ? armor_simple_name(obj) : yname(obj)} but gives up.`);
return !rn2(Math.trunc(inv_cnt(false) / 5) + 2) ? 1 : 0;
}
}
// C ref: steal.c:618 -- mpickobj(mtmp, otmp)
// Monster picks up object. Bottleneck function with event logging.
// Re-exports from bottleneck.js but adds the full C logic.
export async function mpickobj(mtmp, otmp) {
if (!otmp) {
impossible(`monster (${pmname(mtmp?.data, Mgender(mtmp))}) taking or picking up nothing?`);
return 1;
} else if (otmp === game.u.uball || otmp === game.u.uchain) {
impossible(`monster (${pmname(mtmp?.data, Mgender(mtmp))}) taking or picking up attached ${otmp === game.u.uchain ? 'chain' : 'ball'} (${simpleonames(otmp)})?`);
return 0;
}
pushRngLogEntry(`^pickup[${formatMonsterEventRef(mtmp, monsndx(mtmp.data), mtmp.mx, mtmp.my)},${otmp.otyp}]`);
/* clear throwing/kicking trackers */
if (otmp === game.thrownobj)
game.thrownobj = null;
else if (otmp === game.kickedobj)
game.kickedobj = null;
/* unpaid item handling */
if (otmp.unpaid || (Has_contents(otmp) && count_unpaid(otmp.cobj))) {
subfrombill(otmp, find_objowner(otmp, otmp.ox, otmp.oy));
}
let snuff_otmp = false;
if (obj_sheds_light(otmp) && attacktype(mtmp.data, AT_ENGL)) {
if (engulfing_u(mtmp) && !Blind())
await pline(`${Tobjnam(otmp, 'go')} out.`);
snuff_otmp = true;
}
otmp.no_charge = 0;
if (!mtmp.mtame) {
if (!canseemon(mtmp) && mtmp !== game.u.ustuck)
unknow_object(otmp);
if (otmp.how_lost === LOST_THROWN)
otmp.how_lost = LOST_STOLEN;
else if (otmp.how_lost === LOST_DROPPED)
otmp.how_lost = LOST_NONE;
}
carry_obj_effects(otmp);
const freed_otmp = await add_to_minv(mtmp, otmp);
if (snuff_otmp)
snuff_light_source(mtmp.mx, mtmp.my);
return freed_otmp;
}
// C ref: steal.c:688 -- stealamulet(mtmp)
// Called for AD_SAMU (the Wizard and quest nemeses).
export async function stealamulet(mtmp) {
const g = game;
let otmp = null, obj = null;
let real = 0, fake = 0, n;
/* target every quest artifact */
n = 0;
for (obj = g.invent; obj; obj = obj.nobj)
if (any_quest_artifact(obj)) {
++n;
otmp = obj;
}
if (n > 1) {
n = rnd(n);
for (otmp = g.invent; otmp; otmp = otmp.nobj)
if (any_quest_artifact(otmp) && !--n)
break;
}
if (!otmp) {
/* find another valuable item */
if (g.u.uhave?.amulet) {
real = AMULET_OF_YENDOR;
fake = FAKE_AMULET_OF_YENDOR;
} else if (g.u.uhave?.bell) {
real = BELL_OF_OPENING;
fake = BELL;
} else if (g.u.uhave?.book) {
real = SPE_BOOK_OF_THE_DEAD;
} else if (g.u.uhave?.menorah) {
real = CANDELABRUM_OF_INVOCATION;
} else {
return; /* you have nothing of special interest */
}
n = 0;
for (obj = g.invent; obj; obj = obj.nobj)
if (obj.otyp === real || (obj.otyp === fake && !mtmp.iswiz)) {
++n;
otmp = obj;
}
if (n > 1) {
n = rnd(n);
for (otmp = g.invent; otmp; otmp = otmp.nobj)
if ((otmp.otyp === real
|| (otmp.otyp === fake && !mtmp.iswiz)) && !--n)
break;
}
}
if (otmp) {
/* take off outer gear if targeting inner items */
if ((otmp === g.u.uarm || otmp === g.u.uarmu) && g.u.uarmc)
await worn_item_removal(mtmp, g.u.uarmc);
if (otmp === g.u.uarmu && g.u.uarm)
await worn_item_removal(mtmp, g.u.uarm);
if ((otmp === g.u.uarmg || ((otmp === g.u.uright || otmp === g.u.uleft) && g.u.uarmg))
&& g.u.uwep) {
if (g.u.twoweap)
await worn_item_removal(mtmp, g.u.uswapwep);
await worn_item_removal(mtmp, g.u.uwep);
}
if ((otmp === g.u.uright || otmp === g.u.uleft) && g.u.uarmg)
await worn_item_removal(mtmp, g.u.uarmg);
/* finally, steal the target item */
if (otmp.owornmask)
await worn_item_removal(mtmp, otmp);
if (otmp.unpaid)
subfrombill(otmp, shop_keeper(g.u.ushops?.[0] || ''));
freeinv(otmp);
const buf = doname(otmp);
await mpickobj(mtmp, otmp); /* could merge and free otmp but won't */
await pline(`${Some_Monnam(mtmp)} steals ${buf}!`);
if (can_teleport(mtmp.data) && !tele_restrict(mtmp))
await rloc(mtmp, RLOC_MSG);
await encumber_msg();
}
}
// C ref: steal.c:771 -- maybe_absorb_item(mon, obj, ochance, achance)
// When a mimic gets poked, it might absorb the item.
export async function maybe_absorb_item(mon, obj, ochance, achance) {
if (obj === game.u.uball || obj === game.u.uchain || obj.oclass === ROCK_CLASS
|| obj_resists(obj, 100 - ochance, 100 - achance)
|| !(await touch_artifact(obj, mon)))
return;
if (carried(obj)) {
if (obj.owornmask)
await remove_worn_item(obj, true);
if (obj.unpaid)
subfrombill(obj, shop_keeper(game.u.ushops?.[0] || ''));
if (cansee(mon.mx, mon.my)) {
await pline(`${Some_Monnam(mon)} pulls ${yname(obj)} away from you and absorbs ${obj.quan > 1 ? 'them' : 'it'}!`);
} else {
let hand_s = body_part(HAND);
if (bimanual(obj))
hand_s = makeplural(hand_s);
await pline(`${upstart(yname(obj))} ${otense(obj, 'are')} pulled from your ${hand_s}!`);
}
freeinv(obj);
await encumber_msg();
} else {
/* not carried; presumably thrown or kicked */
if (canspotmon(mon))
await pline(`${Monnam(mon)} absorbs ${yname(obj)}!`);
}
/* add to mon's inventory */
await mpickobj(mon, obj);
}
// C ref: steal.c:812 -- mdrop_obj(mon, obj, verbosely)
// Drop one object from (possibly dead) monster's inventory.
export async function mdrop_obj(mon, obj, verbosely) {
const omx = mon.mx, omy = mon.my;
const unwornmask = obj.owornmask;
const obj_name = distant_name(obj, doname);
await extract_from_minvent(mon, obj, false, true);
/* don't charge for owned saddle on dead steed (provided
that the hero is within the same shop at the time) */
if (unwornmask && mon.mtame && (unwornmask & W_SADDLE) !== 0
&& !obj.unpaid && costly_spot(omx, omy)) {
const lev = game.level;
const roomno = lev?.locations?.[omx]?.[omy]?.roomno;
if (roomno && in_rooms(game.u.ux, game.u.uy, SHOPBASE).includes(String.fromCharCode(roomno)))
obj.no_charge = 1;
}
if (verbosely && cansee(omx, omy))
await pline_mon(mon, `${Monnam(mon)} drops ${obj_name}.`);
if (!(await flooreffects(obj, omx, omy, 'fall'))) {
place_object(obj, omx, omy);
stackobj(obj);
pushRngLogEntry(`^drop[${formatMonsterEventRef(mon, monsndx(mon.data), omx, omy)},${obj.otyp}]`);
}
if (!DEADMONSTER(mon) && unwornmask)
await update_mon_extrinsics(mon, obj, false, true);
}
// C ref: steal.c:851 -- mdrop_special_objs(mon)
// Prevent monster from taking Amulet, invocation items, or quest artifact.
export async function mdrop_special_objs(mon) {
let obj, otmp;
for (obj = mon.minvent; obj; obj = otmp) {
otmp = obj.nobj;
if (obj_resists(obj, 0, 0) || is_quest_artifact(obj)) {
if (mon.mx) {
await mdrop_obj(mon, obj, false);
} else {
await extract_from_minvent(mon, obj, true, true);
await rloco(obj);
}
}
}
}
// C ref: steal.c:874 -- relobj(mtmp, show, is_pet)
// Release all objects the creature is carrying.
export async function relobj(mtmp, show, is_pet) {
let otmp;
const omx = mtmp.mx, omy = mtmp.my;
/* vault guard's gold goes away */
if (mtmp.isgd && (otmp = findgold(mtmp.minvent)) !== null) {
if (canspotmon(mtmp))
await pline(`${s_suffix(Monnam(mtmp))} gold ${canseemon(mtmp) ? 'vanishes' : 'seems to vanish'}.`);
obj_extract_self(otmp);
obfree(otmp, null);
}
while ((otmp = (is_pet ? droppables(mtmp) : mtmp.minvent)) !== null) {
await mdrop_obj(mtmp, otmp, is_pet && game.flags?.verbose);
}
if (show && cansee(omx, omy))
newsym(omx, omy);
}
/*steal.js*/ |