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 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 | 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 7x 61x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 2425x 73x 73x 73x 73x 73x 73x 4514x 4514x 4514x 4396x 4396x 4396x 73x 73x 4520x 4520x 4520x 73x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 10x 10x 10x 10x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 12x 12x 12x 73x 73x 73x 2003x 2003x 2003x 2003x 2003x 2003x 1915x 2003x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1725x 1725x 1725x 1725x 1725x 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 404x 404x 404x 404x 6464x 6464x 6464x 6464x 404x 404x 404x 404x 404x 403x 403x 404x 73x 73x 73x 340x 340x 340x 340x 340x 340x 5440x 340x 340x 340x 340x 68x 68x 68x 68x 54x 54x 54x 54x 54x 54x 54x 54x 54x 54x 68x 68x 340x 340x 296x 296x 224x 224x 217x 217x 217x 217x 217x 217x 217x 224x 224x 224x 296x 340x 5440x 340x 340x 340x 340x 340x 340x 340x 340x 340x 73x 73x 73x 64x 64x 64x 64x 64x 64x 1024x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1024x 64x 49x 49x 49x 64x 64x 64x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 31x 31x 31x 10x 10x 10x 10x 10x 10x 10x 3x 3x 3x 3x 3x 3x 3x 3x 3x 10x 73x 73x 73x 1725x 1725x 1725x 1725x 1725x 1725x 1665x 1665x 1665x 1665x 60x 60x 60x 60x 1725x 62x 62x 62x 62x 62x 62x 62x 62x 62x 62x 29x 62x 62x 62x 16x 62x 62x 62x 1x 62x 62x 62x 4x 62x 12x 12x 62x 62x 62x 60x 60x 1725x 73x 1725x 1725x 1725x 1725x 1725x 88x 88x 88x 1725x 1637x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 1725x 73x 73x 73x 284x 284x 284x 284x 46x 10x 10x 10x 10x 10x 46x 284x 284x 284x 284x 73x 73x 73x 17940x 17940x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 17940x 17927x 17927x 35103x 17886x 17886x 17940x 73x 73x 73x 73x 270x 270x 391x 391x 391x 391x 270x 73x 73x 73x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 113x 113x 113x 113x 113x 26x 26x 26x 26x 26x 26x 26x 73x 73x 73x 3x 3x 3x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 3x 3x 3x 3x 2x 3x 73x 73x 73x 5087x 5087x 5087x 5087x 3170x 5086x 5087x 5087x 2425x 2425x 2425x 5087x 5087x 5087x 5087x 2425x 5087x 5087x 2425x 5087x 5087x 2425x 4976x 1191x 1191x 5087x 73x 73x 17608x 17608x 17608x 17608x 17608x 17608x 17608x 17608x 17608x 17608x 17608x 17608x 17606x 17606x 17606x 17608x 34739x 34739x 4508x 4508x 11x 4508x 4508x 4508x 5x 5x 5x 5x 5x 34739x 3520x 1x 34739x 4241x 4241x 4241x 4194x 4241x 4241x 317x 34739x 4514x 282x 4514x 4514x 4514x 4514x 282x 34739x 4520x 365x 34739x 4520x 132x 34739x 4396x 293x 34739x 4520x 4520x 4520x 339x 34739x 34571x 34571x 34739x 34739x 1712x 1712x 17606x 17608x 1717x 1717x 17608x 17608x 17608x 17608x 1717x 1717x 17443x 1717x 17423x 1x 1x 1x 1x 1x 1x 1717x 17443x 1717x 17608x 17608x 17608x 17608x 17608x 1717x 1717x 17608x 17608x 73x 73x 73x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 6x 6x 6x 6x 23x 13x 13x 13x 13x 13x 13x 13x 23x 23x 16x 16x 16x 23x 23x 16x 16x 16x 23x 23x 16x 16x 23x 23x 23x 23x 23x 23x 23x 23x 23x 73x 73x 73x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 3x 3x 3x 3x 3x 3x 3x 3x 3x 44x 44x 44x 73x 73x 73x 73x 73x | // worn.js — Port of worn.c
// Equipment worn/wielded tracking, monster armor, bypass system.
//
// Ported functions:
// setworn() — set/clear worn equipment slot with intrinsics
// setnotworn() — remove worn item (e.g. when destroyed)
// allunworn() — clear all worn pointers (save with FREEING)
// wearmask_to_obj() — return item worn in slot indicated by mask
// wornmask_to_armcat() — convert armor wornmask to armor category
// armcat_to_wornmask() — convert armor category to wornmask
// wearslot() — bitmask of equipment slot(s) an item fits
// recalc_telepat_range() — recalculate hero's telepathy range
// mon_set_minvis() — set monster permanent invisibility
// mon_adjust_speed() — adjust monster speed
// update_mon_extrinsics()— update monster extrinsics for armor on/off
// find_mac() — calculate monster AC
// which_armor() — find armor worn by monster in slot
// m_dowear() — monster puts on best available armor
// m_lose_armor() — monster drops a piece of armor
// extra_pref() — bias monster armor preference
// bypass_obj() — set bypass bit on object
// bypass_objlist() — set/clear bypass on object chain
// clear_bypasses() — clear all bypass bits
// nxt_unbypassed_obj() — return first unbypassed object
// mon_break_armor() — break/drop armor on polymorph
// racial_exception() — race-based armor exceptions
// extract_from_minvent() — remove object from monster inventory
import { game } from './gstate.js';
import { pline, pline_mon, You, Your, You_hear, impossible } from './pline.js';
import { Role_if, See_invisible, Stone_resistance } from './macros.js';
import { set_twoweap } from './wield.js';
import { newsym, canseemon } from './display.js';
import { cansee, vision_recalc } from './vision.js';
import { obj_no_longer_held } from './do.js';
import { ALCHEMY_SMOCK, AMULET_CLASS, AMULET_OF_GUARDING, AMULET_OF_LIFE_SAVING, AMULET_OF_REFLECTION, ARMOR_CLASS, ARM_BOOTS, ARM_CLOAK, ARM_GLOVES, ARM_HELM, ARM_SHIELD, ARM_SHIRT, ARM_SUIT, BALL_CLASS, BLINDFOLD, CHAIN_CLASS, CORNUTHAUM, DUNCE_CAP, ELVEN_BOOTS, ELVEN_CLOAK, ELVEN_LEATHER_HELM, ELVEN_MITHRIL_COAT, ELVEN_SHIELD, FOOD_CLASS, GEM_CLASS, GRAY_DRAGON_SCALES, GRAY_DRAGON_SCALE_MAIL, HELM_OF_OPPOSITE_ALIGNMENT, Is_dragon_mail, Is_dragon_scales, LEATHER, LENSES, MEAT_RING, MUMMY_WRAPPING, RING_CLASS, RUBBER_HOSE, SADDLE, SPEED_BOOTS, TIN_OPENER, TOOL_CLASS, TOWEL, WEAPON_CLASS, YELLOW_DRAGON_SCALES, YELLOW_DRAGON_SCALE_MAIL, greatest_erosion, is_cloak, is_flimsy, is_gloves, is_shield, is_shirt } from './objects.js';
import {
W_ARM, W_ARMC, W_ARMH, W_ARMS, W_ARMG, W_ARMF, W_ARMU,
W_ARMOR, W_WEP, W_SWAPWEP, W_QUIVER,
W_AMUL, W_RINGL, W_RINGR, W_TOOL, W_SADDLE, W_BALL, W_CHAIN,
W_ART, W_ARTI, I_SPECIAL,
BOLT_LIM, AC_MAX, DISMOUNT_FELL, NON_PM, OBJ_MINVENT,
INVIS, FAST, CLAIRVOYANT, BLINDED, TELEPAT,
POISON_RES, ACID_RES, FIRE_RES, COLD_RES, SLEEP_RES,
DISINT_RES, SHOCK_RES, STONE_RES,
ANTIMAGIC, REFLECTING, PROTECTION, STEALTH,
LEVITATION, FLYING, WWALKING, DISPLACED, FUMBLING, JUMPING,
MSLOW, MFAST,
} from './const.js';
import {
mons,
PM_WIZARD, PM_MONK, PM_HOBBIT, PM_SKELETON, PM_LONG_WORM,
PM_GRAY_DRAGON, PM_WINGED_GARGOYLE, PM_MARILITH, PM_AIR_ELEMENTAL,
S_MUMMY, S_CENTAUR, S_GHOST, S_VORTEX,
M1_NOHANDS, M1_MINDLESS, M1_ANIMAL, M1_SLITHY, M1_HUMANOID,
MZ_SMALL, MZ_HUMAN, MZ_HUGE,
} from './monsters.js';
import { bimanual, is_art, Mgender, s_suffix, sgn, Something, strsubst, surface } from './hacklib.js';
import { breakarm, has_horns, humanoid, is_animal, is_mindless as mindless, is_weptool, is_whirly, nohands, noncorporeal, sliparm, slithy, touch_petrifies, verysmall, WrappingAllowed } from './mondata.js';
import { m_useup } from './mthrowu.js';
import { see_wsegs } from './worm.js';
// ── Non-RNG stubs for functions not yet ported ──
// update_inventory imported from mon.js
function set_artifact_intrinsic(_obj, _on, _mask) { /* TODO: port from artifact.c */ }
function monstunseesu_prop(_prop) { /* TODO: port from mon.c */ }
// NOTE: differs from canonical do_wear.js — stub is no-op, canonical has real takeoff mask logic
// artifact_light imported from light.js
// end_burn imported from light.js
// NOTE: differs from canonical light.js — stub is no-op, canonical sets obj.lamplit = true
// arti_light_description imported from light.js
// see_wsegs imported from worm.js
// NOTE: differs from canonical zap.js — stub is no-op, canonical checks oclass and calls update_inventory
// NOTE: differs from canonical steed.js — stub is no-op, canonical clears usteed and places monster
// m_useup imported from mthrowu.js
function mwepgone(_mon) { /* TODO: port from wield.c */ }
// cloak_simple_name: imported from objnam.js
// simpleonames: imported from objnam.js
// Something imported from hacklib.js
// NOTE: differs from canonical objnam.js — stub uses regex, canonical uses just_an() helper
// NOTE: differs from canonical do_name.js — stub uses mname||'monster', canonical checks name??mname??"creature"
// NOTE: differs from canonical do_name.js — stub returns input, canonical uses Hallucination RNG
// NOTE: differs from canonical hacklib.js — stub uses String.replace (handles $ patterns), canonical uses indexOf/slice
// ── Mondata macros ──
// nohands, slithy, humanoid, is_whirly, noncorporeal, has_horns, is_animal imported from mondata.js
// NOTE: differs from canonical mondata.js — stub uses < MZ_SMALL, canonical uses <= 1 (MZ_TINY)
// mindless: imported from mondata.js as is_mindless
function cantweararm(ptr) { return breakarm(ptr) || sliparm(ptr); }
// NOTE: differs from canonical mondata.js — stub returns false, canonical checks msize >= MZ_HUGE or non-humanoid
// NOTE: differs from canonical mondata.js — stub returns false, canonical checks is_unsolid || nolimbs
// ── Object macros ──
// is_shield: imported from objects.js
function is_helmet(obj) {
return obj.oclass === ARMOR_CLASS && game.objects[obj.otyp].oc_armcat === ARM_HELM;
}
function is_boots(obj) {
return obj.oclass === ARMOR_CLASS && game.objects[obj.otyp].oc_armcat === ARM_BOOTS;
}
// is_gloves: imported from objects.js
// is_shirt: imported from objects.js
function is_suit(obj) {
return obj.oclass === ARMOR_CLASS && game.objects[obj.otyp].oc_armcat === ARM_SUIT;
}
// is_flimsy: imported from objects.js
function is_elven_armor(obj) {
return obj.otyp === ELVEN_LEATHER_HELM
|| obj.otyp === ELVEN_MITHRIL_COAT
|| obj.otyp === ELVEN_CLOAK
|| obj.otyp === ELVEN_SHIELD
|| obj.otyp === ELVEN_BOOTS;
}
// Is_dragon_scales: imported from objects.js
// Is_dragon_mail: imported from objects.js
export function Dragon_scales_to_pm(obj) {
return mons[PM_GRAY_DRAGON + obj.otyp - GRAY_DRAGON_SCALES];
}
export function Dragon_mail_to_pm(obj) {
return mons[PM_GRAY_DRAGON + obj.otyp - GRAY_DRAGON_SCALE_MAIL];
}
// greatest_erosion: imported from objects.js
function ARM_BONUS(obj) {
const a_ac = game.objects[obj.otyp].oc_oc1 || 0; // a_ac == oc_oc1
return a_ac + (obj.spe || 0) - Math.min(greatest_erosion(obj), a_ac);
}
// WrappingAllowed imported from mondata.js
// NOTE: differs from canonical steed.js — stub returns false, canonical checks monster properties
// NOTE: differs from canonical steed.js — stub returns false, canonical checks mtmp.mtame
// touch_petrifies imported from mondata.js
// Stone_resistance imported from macros.js
// NOTE: differs from canonical rng.js — stub returns 0, canonical has full RNG with luck adjustment
// instapetrify imported from trap.js
function has_mcorpsenm(mtmp) { return mtmp?.mextra?.mcorpsenm !== undefined; }
function MCORPSENM_set(mtmp, val) { if (mtmp?.mextra) mtmp.mextra.mcorpsenm = val; }
// ── res_to_mr: convert property index to MR_ bitmask ──
// C: (FIRE_RES <= r && r <= STONE_RES) ? (1 << (r - 1)) : 0
function res_to_mr(r) {
return (FIRE_RES <= r && r <= STONE_RES) ? (1 << (r - 1)) : 0;
}
// ── w_blocks macro ──
// C: This only allows for one blocking item per property
function w_blocks(obj, mask) {
if (obj.otyp === MUMMY_WRAPPING && (mask & W_ARMC) !== 0) return INVIS;
if (obj.otyp === CORNUTHAUM && (mask & W_ARMH) !== 0 && !Role_if(PM_WIZARD))
return CLAIRVOYANT;
if (is_art(obj, ART_EYES_OF_THE_OVERWORLD) && (mask & W_TOOL) !== 0)
return BLINDED;
return 0;
}
import { ART_EYES_OF_THE_OVERWORLD } from './artifacts.js';
import { makeknown } from './invent.js';
import { DEADMONSTER, Monnam, check_gear_next_turn, mhim, mhis, mon_nam, update_inventory } from './mon.js';
import { arti_light_description, artifact_light, begin_burn, end_burn } from './light.js';
import { instapetrify } from './trap.js';
import { Soundeffect } from './sounds.js';
import { Has_contents } from './const.js';
import { Yname2, an, cloak_simple_name, distant_name, doname, otense, simpleonames } from './objnam.js';
import { curse, obj_extract_self, place_object } from './mkobj.js';
import { hcolor, pmname } from './do_name.js';
import { cancel_doff } from './do_wear.js';
import { rnl } from './rng.js';
import { can_ride, can_saddle, dismount_steed } from './steed.js';
import { learnwand } from './zap.js';
// ── altprop macro ──
function altprop(obj) {
return obj.otyp === ALCHEMY_SMOCK
? (POISON_RES + ACID_RES - (game.objects[obj.otyp].oc_oprop || 0))
: 0;
}
// ── The worn[] table ──
// In C this is a static array of {w_mask, *w_obj, w_what}.
// In JS we use property names on the game object.
const WORN_TABLE = [
{ mask: W_ARM, slot: 'uarm', what: 'suit' },
{ mask: W_ARMC, slot: 'uarmc', what: 'cloak' },
{ mask: W_ARMH, slot: 'uarmh', what: 'helmet' },
{ mask: W_ARMS, slot: 'uarms', what: 'shield' },
{ mask: W_ARMG, slot: 'uarmg', what: 'gloves' },
{ mask: W_ARMF, slot: 'uarmf', what: 'boots' },
{ mask: W_ARMU, slot: 'uarmu', what: 'shirt' },
{ mask: W_RINGL, slot: 'uleft', what: 'left ring' },
{ mask: W_RINGR, slot: 'uright', what: 'right ring' },
{ mask: W_WEP, slot: 'uwep', what: 'weapon' },
{ mask: W_SWAPWEP, slot: 'uswapwep', what: 'alternate weapon' },
{ mask: W_QUIVER, slot: 'uquiver', what: 'quiver' },
{ mask: W_AMUL, slot: 'uamul', what: 'amulet' },
{ mask: W_TOOL, slot: 'ublindf', what: 'facewear' },
{ mask: W_BALL, slot: 'uball', what: 'chained ball' },
{ mask: W_CHAIN, slot: 'uchain', what: 'attached chain' },
];
// ── recalc_telepat_range ──
export function recalc_telepat_range() {
const g = game;
const u = g.u;
let nobjs = 0;
for (const wp of WORN_TABLE) {
const oobj = u[wp.slot];
if (oobj && (game.objects[oobj.otyp].oc_oprop || 0) === TELEPAT)
nobjs++;
}
// count all artifacts with SPFX_ESP as one
if ((u.uprops[TELEPAT].extrinsic || 0) & W_ART)
nobjs++;
if (nobjs)
u.unblind_telepat_range = (BOLT_LIM * BOLT_LIM) * nobjs;
else
u.unblind_telepat_range = -1;
}
// ── setworn ──
export function setworn(obj, mask) {
const g = game;
const u = g.u;
if ((mask & (W_ARM | I_SPECIAL)) === (W_ARM | I_SPECIAL)) {
// restoring saved game; no properties are conferred via skin
g.uskin = obj;
} else {
for (const wp of WORN_TABLE) {
if (wp.mask & mask) {
const oobj = u[wp.slot];
if (oobj && !(oobj.owornmask & wp.mask))
impossible(`Setworn: mask=0x${wp.mask.toString(16).padStart(8, '0')}.`);
if (oobj) {
if (u.twoweap && (oobj.owornmask & (W_WEP | W_SWAPWEP)))
set_twoweap(false); // u.twoweap = FALSE
oobj.owornmask &= ~wp.mask;
if (wp.mask & ~(W_SWAPWEP | W_QUIVER)) {
let p = game.objects[oobj.otyp].oc_oprop || 0;
u.uprops[p].extrinsic =
u.uprops[p].extrinsic & ~wp.mask;
monstunseesu_prop(p);
p = w_blocks(oobj, mask);
if (p !== 0)
u.uprops[p].blocked &= ~wp.mask;
if (oobj.oartifact)
set_artifact_intrinsic(oobj, 0, mask);
}
cancel_doff(oobj, wp.mask);
}
u[wp.slot] = obj;
if (obj) {
obj.owornmask |= wp.mask;
if (wp.mask & ~(W_SWAPWEP | W_QUIVER)) {
if (obj.oclass === WEAPON_CLASS || is_weptool(obj)
|| mask !== W_WEP) {
let p = game.objects[obj.otyp].oc_oprop || 0;
u.uprops[p].extrinsic =
u.uprops[p].extrinsic | wp.mask;
p = w_blocks(obj, mask);
if (p !== 0)
u.uprops[p].blocked |= wp.mask;
}
if (obj.oartifact)
set_artifact_intrinsic(obj, 1, mask);
}
}
}
}
if (obj && (obj.owornmask & W_ARMOR) !== 0)
u.uroleplay.nudist = false;
// tux -> tuxedo -> "monkey suit" -> monk's suit
if (!g.iflags) g.iflags = {};
g.iflags.tux_penalty = !!(u.uarm && Role_if(PM_MONK) && g.urole?.spelarmr);
}
update_inventory();
recalc_telepat_range();
}
// ── setnotworn ──
export function setnotworn(obj) {
const g = game;
const u = g.u;
if (!obj) return;
if (u.twoweap && (obj === u.uwep || obj === u.uswapwep))
set_twoweap(false);
for (const wp of WORN_TABLE) {
if (obj === u[wp.slot]) {
cancel_doff(obj, wp.mask);
u[wp.slot] = null;
let p = game.objects[obj.otyp].oc_oprop || 0;
u.uprops[p].extrinsic = u.uprops[p].extrinsic & ~wp.mask;
monstunseesu_prop(p);
obj.owornmask &= ~wp.mask;
if (obj.oartifact)
set_artifact_intrinsic(obj, 0, wp.mask);
p = w_blocks(obj, wp.mask);
if (p !== 0)
u.uprops[p].blocked &= ~wp.mask;
}
}
if (!u.uarm) {
if (!g.iflags) g.iflags = {};
g.iflags.tux_penalty = false;
}
update_inventory();
recalc_telepat_range();
}
// ── allunworn ──
export function allunworn() {
const g = game;
g.u.twoweap = 0;
for (const wp of WORN_TABLE) {
g[wp.slot] = null;
}
}
// ── wearmask_to_obj ──
export function wearmask_to_obj(wornmask) {
const g = game;
for (const wp of WORN_TABLE) {
if (wp.mask & wornmask)
return g[wp.slot];
}
return null;
}
// ── wornmask_to_armcat ──
export function wornmask_to_armcat(mask) {
switch (mask & W_ARMOR) {
case W_ARM: return ARM_SUIT;
case W_ARMC: return ARM_CLOAK;
case W_ARMH: return ARM_HELM;
case W_ARMS: return ARM_SHIELD;
case W_ARMG: return ARM_GLOVES;
case W_ARMF: return ARM_BOOTS;
case W_ARMU: return ARM_SHIRT;
}
return 0;
}
// ── armcat_to_wornmask ──
export function armcat_to_wornmask(cat) {
switch (cat) {
case ARM_SUIT: return W_ARM;
case ARM_CLOAK: return W_ARMC;
case ARM_HELM: return W_ARMH;
case ARM_SHIELD: return W_ARMS;
case ARM_GLOVES: return W_ARMG;
case ARM_BOOTS: return W_ARMF;
case ARM_SHIRT: return W_ARMU;
}
return 0;
}
// ── wearslot ──
export function wearslot(obj) {
const otyp = obj.otyp;
let res = 0;
switch (obj.oclass) {
case AMULET_CLASS:
res = W_AMUL;
break;
case RING_CLASS:
res = W_RINGL | W_RINGR;
break;
case ARMOR_CLASS:
switch (game.objects[otyp].oc_armcat) {
case ARM_SUIT: res = W_ARM; break;
case ARM_SHIELD: res = W_ARMS; break;
case ARM_HELM: res = W_ARMH; break;
case ARM_GLOVES: res = W_ARMG; break;
case ARM_BOOTS: res = W_ARMF; break;
case ARM_CLOAK: res = W_ARMC; break;
case ARM_SHIRT: res = W_ARMU; break;
}
break;
case WEAPON_CLASS:
res = W_WEP | W_SWAPWEP;
if (game.objects[otyp].oc_merge)
res |= W_QUIVER;
break;
case TOOL_CLASS:
if (otyp === BLINDFOLD || otyp === TOWEL || otyp === LENSES)
res = W_TOOL;
else if (is_weptool(obj) || otyp === TIN_OPENER)
res = W_WEP | W_SWAPWEP;
else if (otyp === SADDLE)
res = W_SADDLE;
break;
case FOOD_CLASS:
if (obj.otyp === MEAT_RING)
res = W_RINGL | W_RINGR;
break;
case GEM_CLASS:
res = W_QUIVER;
break;
case BALL_CLASS:
res = W_BALL;
break;
case CHAIN_CLASS:
res = W_CHAIN;
break;
default:
break;
}
return res;
}
// ── mon_set_minvis ──
export function mon_set_minvis(mon, cursed_potion) {
mon.perminvis = !cursed_potion ? 1 : 0;
if (!mon.invis_blkd) {
mon.minvis = mon.perminvis;
newsym(mon.mx, mon.my);
if (mon.wormno)
see_wsegs(mon);
}
}
// ── mon_adjust_speed ──
export async function mon_adjust_speed(mon, adjust, obj) {
const g = game;
const give_msg_init = !g.in_mklev;
let give_msg = give_msg_init;
let petrify = false;
const oldspeed = mon.mspeed;
switch (adjust) {
case 2:
mon.permspeed = MFAST;
give_msg = false;
break;
case 1:
if (mon.permspeed === MSLOW)
mon.permspeed = 0;
else
mon.permspeed = MFAST;
break;
case 0:
break;
case -1:
if (mon.permspeed === MFAST)
mon.permspeed = 0;
else
mon.permspeed = MSLOW;
break;
case -2:
mon.permspeed = MSLOW;
give_msg = false;
break;
case -3:
if (mon.permspeed === MFAST)
mon.permspeed = 0;
petrify = true;
break;
case -4:
if (mon.permspeed === MFAST)
mon.permspeed = 0;
give_msg = false;
break;
}
// check for worn speed boots
let otmp;
for (otmp = mon.minvent; otmp; otmp = otmp.nobj) {
if (otmp.owornmask && (game.objects[otmp.otyp].oc_oprop || 0) === FAST)
break;
}
if (otmp)
mon.mspeed = MFAST;
else
mon.mspeed = mon.permspeed;
if (give_msg && (mon.mspeed !== oldspeed || petrify) && mon.data.mmove
&& !(mon.mfrozen || mon.msleeping) && canseemon(mon)) {
const howmuch = (mon.mspeed + oldspeed === MFAST + MSLOW) ? 'much ' : '';
if (petrify) {
if (g.flags.verbose)
await pline_mon(mon, '%s is slowing down.', Monnam(mon));
} else if (adjust > 0 || mon.mspeed === MFAST) {
await pline_mon(mon, '%s is suddenly moving %sfaster.',
Monnam(mon), howmuch);
} else {
await pline_mon(mon, '%s seems to be moving %sslower.',
Monnam(mon), howmuch);
}
if (obj)
learnwand(obj);
}
}
// ── update_mon_extrinsics ──
export async function update_mon_extrinsics(mon, obj, on, silently) {
const g = game;
let unseen = !canseemon(mon);
let which = game.objects[obj.otyp].oc_oprop || 0;
const altwhich = altprop(obj);
if (!which && !altwhich) {
// goto maybe_blocks
await _maybe_blocks(mon, obj, on, silently, unseen);
return;
}
// The C code uses 'goto again' for alchemy smock dual-property.
// We use a loop.
let first = true;
while (first || (altwhich && which !== altwhich)) {
if (!first) which = altwhich;
first = false;
if (on) {
switch (which) {
case INVIS:
mon.minvis = !mon.invis_blkd ? 1 : 0;
break;
case FAST: {
const save_in_mklev = g.in_mklev;
if (silently) g.in_mklev = true;
await mon_adjust_speed(mon, 0, obj);
g.in_mklev = save_in_mklev;
break;
}
case ANTIMAGIC:
case REFLECTING:
case PROTECTION:
break;
case CLAIRVOYANT:
case STEALTH:
case TELEPAT:
break;
case LEVITATION:
case FLYING:
case WWALKING:
break;
case DISPLACED:
case FUMBLING:
case JUMPING:
break;
default:
mon.mextrinsics = (mon.mextrinsics || 0) | res_to_mr(which);
break;
}
} else {
// off
switch (which) {
case INVIS:
mon.minvis = mon.perminvis;
break;
case FAST: {
const save_in_mklev = g.in_mklev;
if (silently) g.in_mklev = true;
await mon_adjust_speed(mon, 0, obj);
g.in_mklev = save_in_mklev;
break;
}
case FIRE_RES:
case COLD_RES:
case SLEEP_RES:
case DISINT_RES:
case SHOCK_RES:
case POISON_RES:
case ACID_RES:
case STONE_RES: {
const mask = res_to_mr(which);
let found = null;
for (let otmp = mon.minvent; otmp; otmp = otmp.nobj) {
if (otmp === obj || !otmp.owornmask)
continue;
if ((game.objects[otmp.otyp].oc_oprop || 0) === which) {
found = otmp;
break;
}
if (altprop(otmp) === which) {
found = otmp;
break;
}
}
if (!found)
mon.mextrinsics = (mon.mextrinsics || 0) & ~mask;
break;
}
default:
break;
}
}
}
await _maybe_blocks(mon, obj, on, silently, unseen);
}
async function _maybe_blocks(mon, obj, on, silently, unseen) {
const g = game;
switch (w_blocks(obj, ~0)) {
case INVIS:
mon.invis_blkd = on ? 1 : 0;
mon.minvis = on ? 0 : mon.perminvis;
break;
default:
break;
}
if (!on && mon === g.u.usteed && obj.otyp === SADDLE)
await dismount_steed(DISMOUNT_FELL);
if (!silently && (unseen ^ !canseemon(mon)))
newsym(mon.mx, mon.my);
}
// ── find_mac ──
export function find_mac(mon) {
let base = mon.data.ac;
const mwflags = mon.misc_worn_check || 0;
for (let obj = mon.minvent; obj; obj = obj.nobj) {
if (obj.owornmask & mwflags) {
if (obj.otyp === AMULET_OF_GUARDING)
base -= 2;
else
base -= ARM_BONUS(obj);
}
}
if (Math.abs(base) > AC_MAX)
base = sgn(base) * AC_MAX;
return base;
}
// ── which_armor ──
export function which_armor(mon, flag) {
const g = game;
if (mon === g.youmonst) {
switch (flag) {
case W_ARM: return g.u.uarm;
case W_ARMC: return g.u.uarmc;
case W_ARMH: return g.u.uarmh;
case W_ARMS: return g.u.uarms;
case W_ARMG: return g.u.uarmg;
case W_ARMF: return g.u.uarmf;
case W_ARMU: return g.u.uarmu;
default:
impossible('bad flag in which_armor');
return null;
}
} else {
for (let obj = mon.minvent; obj; obj = obj.nobj)
if (obj.owornmask & flag)
return obj;
return null;
}
}
// ── m_lose_armor (static) ──
async function m_lose_armor_fn(mon, obj, polyspot) {
await extract_from_minvent(mon, obj, true, false);
place_object(obj, mon.mx, mon.my);
if (polyspot)
bypass_obj(obj);
newsym(mon.mx, mon.my);
}
// ── clear_bypass (static) ──
function clear_bypass(objchn) {
for (let o = objchn; o; o = o.nobj) {
o.bypass = 0;
if (Has_contents(o))
clear_bypass(o.cobj);
}
}
// ── clear_bypasses ──
export function clear_bypasses() {
const g = game;
clear_bypass(g.fobj || null);
clear_bypass(g.invent || null);
clear_bypass(g.migrating_objs || null);
clear_bypass(g.level?.buriedobjlist || null);
clear_bypass(g.billobjs || null);
clear_bypass(g.objs_deleted || null);
for (let mtmp = g.fmon; mtmp; mtmp = mtmp.nmon) {
if (DEADMONSTER(mtmp)) continue;
clear_bypass(mtmp.minvent);
if (mtmp.data === mons[PM_LONG_WORM] && has_mcorpsenm(mtmp))
MCORPSENM_set(mtmp, NON_PM);
}
for (let mtmp = g.migrating_mons; mtmp; mtmp = mtmp.nmon) {
clear_bypass(mtmp.minvent);
}
for (let mtmp = g.mydogs; mtmp; mtmp = mtmp.nmon) {
clear_bypass(mtmp.minvent);
}
if (g.u.uball) g.u.uball.bypass = 0;
if (g.uchain) g.uchain.bypass = 0;
g.context.bypasses = false;
}
// ── bypass_obj ──
export function bypass_obj(obj) {
obj.bypass = 1;
game.context.bypasses = true;
}
// ── bypass_objlist ──
export function bypass_objlist(objchain, on) {
if (on && objchain)
game.context.bypasses = true;
let o = objchain;
while (o) {
o.bypass = on ? 1 : 0;
o = o.nobj;
}
}
// ── nxt_unbypassed_obj ──
export function nxt_unbypassed_obj(objchain) {
let o = objchain;
while (o) {
if (!o.bypass) {
bypass_obj(o);
break;
}
o = o.nobj;
}
return o;
}
// ── extra_pref ──
export function extra_pref(mon, obj) {
if (obj) {
if (obj.otyp === SPEED_BOOTS && mon.permspeed !== MFAST)
return 20;
}
return 0;
}
// ── racial_exception ──
export function racial_exception(mon, obj) {
// raceptr(mon) — simplified: use mon.data for now
const ptr = mon.data; // TODO: use real raceptr()
if (ptr === mons[PM_HOBBIT] && is_elven_armor(obj))
return 1;
return 0;
}
// ── m_dowear ──
export async function m_dowear(mon, creation) {
const RACE_EXCEPTION = true;
if (verysmall(mon.data) || nohands(mon.data) || is_animal(mon.data))
return;
if (mindless(mon.data)
&& (!creation || (mon.data.mlet !== S_MUMMY
&& mon.data !== mons[PM_SKELETON])))
return;
await m_dowear_type(mon, W_AMUL, creation, false);
const can_wear_armor = !cantweararm(mon.data);
if (can_wear_armor && !((mon.misc_worn_check || 0) & W_ARM))
await m_dowear_type(mon, W_ARMU, creation, false);
if (can_wear_armor || WrappingAllowed(mon.data))
await m_dowear_type(mon, W_ARMC, creation, false);
await m_dowear_type(mon, W_ARMH, creation, false);
if (!mon.mw || !bimanual(mon.mw))
await m_dowear_type(mon, W_ARMS, creation, false);
await m_dowear_type(mon, W_ARMG, creation, false);
if (!slithy(mon.data) && mon.data.mlet !== S_CENTAUR)
await m_dowear_type(mon, W_ARMF, creation, false);
if (can_wear_armor)
await m_dowear_type(mon, W_ARM, creation, false);
else
await m_dowear_type(mon, W_ARM, creation, RACE_EXCEPTION);
}
// ── m_dowear_type (static) ──
async function m_dowear_type(mon, flag, creation, racialexception) {
let m_delay = 0;
const sawmon = canseemon(mon);
const sawloc = cansee(mon.mx, mon.my);
let autocurse;
const nambuf = See_invisible() ? Monnam(mon) : mon_nam(mon);
if (mon.mfrozen) return;
const old = which_armor(mon, flag);
if (old && old.cursed) return;
if (old && flag === W_AMUL && old.otyp !== AMULET_OF_GUARDING) return;
let best = old;
let outer_break = false;
for (let obj = mon.minvent; obj && !outer_break; obj = obj.nobj) {
switch (flag) {
case W_AMUL:
if (obj.oclass !== AMULET_CLASS
|| (obj.otyp !== AMULET_OF_LIFE_SAVING
&& obj.otyp !== AMULET_OF_REFLECTION
&& obj.otyp !== AMULET_OF_GUARDING))
continue;
if (!best || obj.otyp !== AMULET_OF_GUARDING) {
best = obj;
if (best.otyp !== AMULET_OF_GUARDING)
outer_break = true;
}
continue;
case W_ARMU:
if (!is_shirt(obj)) continue;
break;
case W_ARMC:
if (!is_cloak(obj)) continue;
if (mon.data.msize > MZ_HUMAN && obj.otyp !== MUMMY_WRAPPING)
continue;
if (mon.minvis && w_blocks(obj, W_ARMC) === INVIS
&& !See_invisible() && !creation)
continue;
break;
case W_ARMH:
if (!is_helmet(obj)) continue;
if (obj.otyp === HELM_OF_OPPOSITE_ALIGNMENT
&& (mon.ispriest || mon.isminion))
continue;
if (has_horns(mon.data) && !is_flimsy(obj))
continue;
break;
case W_ARMS:
if (!is_shield(obj)) continue;
break;
case W_ARMG:
if (!is_gloves(obj)) continue;
break;
case W_ARMF:
if (!is_boots(obj)) continue;
break;
case W_ARM:
if (!is_suit(obj)) continue;
if (racialexception && racial_exception(mon, obj) < 1)
continue;
break;
}
if (obj.owornmask) continue;
if (best && (ARM_BONUS(best) + extra_pref(mon, best)
>= ARM_BONUS(obj) + extra_pref(mon, obj)))
continue;
best = obj;
}
if (!best || best === old) return;
autocurse = ((best.otyp === HELM_OF_OPPOSITE_ALIGNMENT
|| best.otyp === DUNCE_CAP) && !best.cursed);
if ((flag === W_ARM || flag === W_ARMU) && ((mon.misc_worn_check || 0) & W_ARMC))
m_delay += 2;
let oldmask = 0;
if (old) {
m_delay += game.objects[old.otyp].oc_delay || 0;
oldmask = old.owornmask;
old.owornmask = 0;
}
if (!creation) {
if (sawmon) {
let buf = '';
let oldarm = '';
let newarm = '';
if (old) {
oldarm = distant_name(old, doname);
buf = ` removes ${oldarm} and`;
}
newarm = distant_name(best, doname);
if (oldarm && newarm.toLowerCase() === oldarm.toLowerCase()) {
if (newarm.toLowerCase().startsWith('a '))
newarm = strsubst(newarm, newarm.slice(0, 2), 'another ');
else if (newarm.toLowerCase().startsWith('an '))
newarm = strsubst(newarm, newarm.slice(0, 3), 'another ');
}
await pline_mon(mon, '%s%s puts on %s.', Monnam(mon), buf, newarm);
if (autocurse)
await pline('%s %s %s %s for a moment.',
s_suffix(Monnam(mon)), simpleonames(best),
otense(best, 'glow'), hcolor('black'));
}
m_delay += game.objects[best.otyp].oc_delay || 0;
mon.mfrozen = m_delay;
if (mon.mfrozen)
mon.mcanmove = 0;
}
if (old) {
await update_mon_extrinsics(mon, old, false, creation);
old.owornmask = oldmask;
if (old.lamplit && artifact_light(old))
end_burn(old, false);
old.owornmask = 0;
}
mon.misc_worn_check = (mon.misc_worn_check || 0) | flag;
best.owornmask |= flag;
if (autocurse)
curse(best);
if (artifact_light(best) && !best.lamplit) {
begin_burn(best, false);
vision_recalc(1);
if (!creation && best.lamplit && cansee(mon.mx, mon.my)) {
const adesc = arti_light_description(best);
if (sawmon)
await pline('%s %s to shine %s.', Yname2(best),
otense(best, 'begin'), adesc);
else if (canseemon(mon))
await pline('%s %s shining %s.', Yname2(best),
otense(best, 'are'), adesc);
else if (sawloc)
await pline('%s begins to shine %s.', 'Something', adesc);
else
await pline('%s is shining %s.', 'Something', adesc);
}
}
await update_mon_extrinsics(mon, best, true, creation);
if (!creation && (sawmon ^ canseemon(mon))) {
if (mon.minvis && !See_invisible()) {
await pline('Suddenly you cannot see %s.', nambuf);
makeknown(best.otyp);
}
}
}
// ── mon_break_armor ──
export async function mon_break_armor(mon, polyspot) {
let otmp;
const mdat = mon.data;
const vis = cansee(mon.mx, mon.my);
const handless_or_tiny = (nohands(mdat) || verysmall(mdat));
let noride = false;
const pronoun = mhim(mon);
const ppronoun = mhis(mon);
const g = game;
if (breakarm(mdat)) {
if ((otmp = which_armor(mon, W_ARM)) !== null) {
if ((Is_dragon_scales(otmp) && mdat === Dragon_scales_to_pm(otmp))
|| (Is_dragon_mail(otmp) && mdat === Dragon_mail_to_pm(otmp))) {
; // no message
} else {
Soundeffect('se_cracking_sound', 100);
if (vis)
await pline_mon(mon, '%s breaks out of %s armor!',
Monnam(mon), ppronoun);
else
await You_hear('a cracking sound.');
}
await m_useup(mon, otmp);
}
if ((otmp = which_armor(mon, W_ARMC)) !== null
&& (otmp.otyp !== MUMMY_WRAPPING || !WrappingAllowed(mdat))) {
if (otmp.oartifact) {
if (vis)
await pline_mon(mon, "%s %s falls off!",
s_suffix(Monnam(mon)), cloak_simple_name(otmp));
await m_lose_armor_fn(mon, otmp, polyspot);
} else {
Soundeffect('se_ripping_sound', 100);
if (vis)
await pline_mon(mon, "%s %s tears apart!",
s_suffix(Monnam(mon)), cloak_simple_name(otmp));
else
await You_hear('a ripping sound.');
await m_useup(mon, otmp);
}
}
if ((otmp = which_armor(mon, W_ARMU)) !== null) {
if (vis)
await pline_mon(mon, "%s shirt rips to shreds!",
s_suffix(Monnam(mon)));
else
await You_hear('a ripping sound.');
await m_useup(mon, otmp);
}
} else if (sliparm(mdat)) {
const passes_thru_clothes = !(mdat.msize <= MZ_SMALL);
if ((otmp = which_armor(mon, W_ARM)) !== null) {
Soundeffect('se_thud', 50);
if (vis)
await pline_mon(mon, "%s armor falls around %s!",
s_suffix(Monnam(mon)), pronoun);
else
await You_hear('a thud.');
await m_lose_armor_fn(mon, otmp, polyspot);
}
if ((otmp = which_armor(mon, W_ARMC)) !== null
&& (otmp.otyp !== MUMMY_WRAPPING || !WrappingAllowed(mdat))) {
if (vis) {
if (is_whirly(mon.data))
await pline_mon(mon, "%s %s falls, unsupported!",
s_suffix(Monnam(mon)), cloak_simple_name(otmp));
else
await pline_mon(mon, "%s shrinks out of %s %s!",
Monnam(mon), ppronoun, cloak_simple_name(otmp));
}
await m_lose_armor_fn(mon, otmp, polyspot);
}
if ((otmp = which_armor(mon, W_ARMU)) !== null) {
if (vis) {
if (passes_thru_clothes)
await pline_mon(mon, "%s seeps right through %s shirt!",
Monnam(mon), ppronoun);
else
await pline_mon(mon, "%s becomes much too small for %s shirt!",
Monnam(mon), ppronoun);
}
await m_lose_armor_fn(mon, otmp, polyspot);
}
}
if (handless_or_tiny) {
if ((otmp = which_armor(mon, W_ARMG)) !== null) {
if (vis)
await pline_mon(mon, "%s drops %s gloves%s!",
Monnam(mon), ppronoun,
mon.mw ? ' and weapon' : '');
await m_lose_armor_fn(mon, otmp, polyspot);
}
if ((otmp = which_armor(mon, W_ARMS)) !== null) {
Soundeffect('se_clank', 50);
if (vis)
await pline_mon(mon, "%s can no longer hold %s shield!",
Monnam(mon), ppronoun);
else
await You_hear('a clank.');
await m_lose_armor_fn(mon, otmp, polyspot);
}
}
if (handless_or_tiny || has_horns(mdat)) {
if ((otmp = which_armor(mon, W_ARMH)) !== null
&& (handless_or_tiny || !is_flimsy(otmp))) {
if (vis)
await pline_mon(mon, "%s helmet falls to the %s!",
s_suffix(Monnam(mon)), surface(mon.mx, mon.my));
else
await You_hear('a clank.');
await m_lose_armor_fn(mon, otmp, polyspot);
}
}
if (handless_or_tiny || slithy(mdat) || mdat.mlet === S_CENTAUR) {
if ((otmp = which_armor(mon, W_ARMF)) !== null) {
if (vis) {
if (is_whirly(mon.data))
await pline_mon(mon, "%s boots fall away!",
s_suffix(Monnam(mon)));
else
await pline_mon(mon, "%s boots %s off %s feet!",
s_suffix(Monnam(mon)),
verysmall(mdat) ? 'slide' : 'are pushed', ppronoun);
}
await m_lose_armor_fn(mon, otmp, polyspot);
}
}
if (!can_saddle(mon)) {
if ((otmp = which_armor(mon, W_SADDLE)) !== null) {
await m_lose_armor_fn(mon, otmp, polyspot);
if (vis)
await pline_mon(mon, "%s saddle falls off.",
s_suffix(Monnam(mon)));
}
if (mon === g.u.usteed)
noride = true;
}
if (noride || (mon === g.u.usteed && !can_ride(mon))) {
await You('can no longer ride %s.', mon_nam(mon));
if (touch_petrifies(g.u.usteed?.data) && !Stone_resistance() && rnl(3)) {
await You('touch %s.', mon_nam(g.u.usteed));
const buf = `falling off ${an(pmname(g.u.usteed.data, Mgender(g.u.usteed)))}`;
await instapetrify(buf);
}
await dismount_steed(DISMOUNT_FELL);
}
}
// ── extract_from_minvent ──
export async function extract_from_minvent(mon, obj, do_extrinsics, silently) {
const unwornmask = obj.owornmask || 0;
if (obj.where !== OBJ_MINVENT) {
impossible('extract_from_minvent called on object not in minvent');
return;
}
if ((unwornmask & W_ARM) !== 0 && obj.lamplit && artifact_light(obj))
end_burn(obj, false);
obj_extract_self(obj);
obj.owornmask = 0;
if (unwornmask) {
if (!DEADMONSTER(mon) && do_extrinsics) {
// update_mon_extrinsics is async but extract_from_minvent is sync in C
// This is safe because during mklev/creation silently=true suppresses messages
// For runtime calls, the caller should handle the async context
await update_mon_extrinsics(mon, obj, false, silently);
}
mon.misc_worn_check = (mon.misc_worn_check || 0) & ~unwornmask;
check_gear_next_turn(mon);
}
obj_no_longer_held(obj);
if (unwornmask & W_WEP) {
mwepgone(mon);
}
}
// ── check_wornmask_slots — sanity check, simplified ──
export function check_wornmask_slots() {
// Sanity checks are debug-only; omitted for now.
}
/*worn.js*/
|