Drop coins on death, rearrange bags, and close station UIs on walk-away.
Players lose carried coins to the ground when they die, can drag bag slots to reorganize, and bank/craft/NPC panels close when leaving adjacency. Empty bank Reserved/Inheritance tabs stay hidden; reserved tooltips note the cheque hold.
@@ -1,10 +1,12 @@
1
1
<!DOCTYPE html>
2
2
<html lang="en">
3
3
4
<head>
4
5
<meta charset="utf-8">
5
6
<title>Questward</title>
6
7
<link rel="stylesheet" href="/ui/play.css">
7
8
</head>
9
8
10
<body>
9
11
<div id="hud" hidden>
10
12
<span id="you"></span>
@@ -99,7 +101,8 @@
99
101
<p id="bag-coins" hidden>0 coins</p>
100
102
<div id="equip-grid" class="item-grid equip"></div>
101
103
<div id="bag-grid" class="item-grid"></div>
102
<p id="bag-hint" class="hint">Left-click to select. Right-click for other options.</p>
104
<p id="bag-hint" class="hint">Left-click to select. Drag between slots to rearrange. Right-click for other
105
options.</p>
103
106
</aside>
104
107
<aside id="bank-panel" hidden>
105
108
<header>
@@ -289,7 +292,8 @@
289
292
<p id="shop-coins" class="shop-coins">Coins: 0</p>
290
293
<div class="shop-tabs" role="tablist">
291
294
<button id="shop-tab-buy" type="button" class="shop-tab active" role="tab" aria-selected="true">Buy</button>
292
<button id="shop-tab-sell" type="button" class="shop-tab" role="tab" aria-selected="false" hidden>Sell</button>
295
<button id="shop-tab-sell" type="button" class="shop-tab" role="tab" aria-selected="false"
296
hidden>Sell</button>
293
297
</div>
294
298
<section id="shop-pane-buy" class="shop-pane">
295
299
<div class="shop-body">
@@ -305,7 +309,8 @@
305
309
<button id="shop-buy-10" type="button">Buy 10</button>
306
310
<button id="shop-buy-x" type="button">Buy x</button>
307
311
</div>
308
<p id="shop-bag-warn" class="shop-bag-warn" hidden>Inventory full; purchases will be sent to your bank.</p>
312
<p id="shop-bag-warn" class="shop-bag-warn" hidden>Inventory full; purchases will be sent to your
313
bank.</p>
309
314
</div>
310
315
</div>
311
316
</section>
@@ -346,7 +351,8 @@
346
351
<p id="market-hint" class="hint"></p>
347
352
<p id="market-coins" class="shop-coins">Funds: 0</p>
348
353
<div class="market-tabs" role="tablist">
349
<button id="market-tab-orders" type="button" class="market-tab active" data-tab="orders">Your Orders</button>
354
<button id="market-tab-orders" type="button" class="market-tab active" data-tab="orders">Your
355
Orders</button>
350
356
<button id="market-tab-sell" type="button" class="market-tab" data-tab="sell">Sell</button>
351
357
<button id="market-tab-buy" type="button" class="market-tab" data-tab="buy">Buy</button>
352
358
</div>
@@ -370,7 +376,8 @@
370
376
</section>
371
377
<section id="market-pane-buy" class="market-pane" data-pane="buy" hidden>
372
378
<label class="send-row">Search items
373
<input id="market-buy-search" type="search" placeholder="Type a name and press Enter" autocomplete="off">
379
<input id="market-buy-search" type="search" placeholder="Type a name and press Enter"
380
autocomplete="off">
374
381
</label>
375
382
<div id="market-catalog" class="market-catalog"></div>
376
383
<p id="market-buy-item" class="hint">Search and select an item</p>
@@ -392,8 +399,10 @@
392
399
<button id="cauldron-close" type="button">Close</button>
393
400
</header>
394
401
<div class="cauldron-tabs" role="tablist">
395
<button id="cauldron-tab-alchemy" type="button" class="cauldron-tab active" role="tab" aria-selected="true">Alchemy</button>
396
<button id="cauldron-tab-dyes" type="button" class="cauldron-tab" role="tab" aria-selected="false">Dyes</button>
402
<button id="cauldron-tab-alchemy" type="button" class="cauldron-tab active" role="tab"
403
aria-selected="true">Alchemy</button>
404
<button id="cauldron-tab-dyes" type="button" class="cauldron-tab" role="tab"
405
aria-selected="false">Dyes</button>
397
406
</div>
398
407
<section id="cauldron-alchemy-pane" class="cauldron-pane">
399
408
<div id="cauldron-slots" class="cauldron-slots"></div>
@@ -505,7 +514,8 @@
505
514
<div id="skill-level-floats"></div>
506
515
<div id="chat-bubbles"></div>
507
516
<div id="chat-bar" hidden>
508
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">
517
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false"
518
placeholder="Say something…">
509
519
</div>
510
520
<div id="inspect-backdrop" hidden></div>
511
521
<div id="inspect-modal" hidden>
@@ -521,6 +531,7 @@
521
531
<div id="death-modal" role="dialog" aria-modal="true" aria-labelledby="death-title" hidden>
522
532
<h2 id="death-title">You have died</h2>
523
533
<p>Your remains mark where you fell. Respawn at the nearest church altar.</p>
534
<p>Your carried coins are dropped on the ground.</p>
524
535
<button id="death-respawn" type="button">Respawn</button>
525
536
</div>
526
537
<div id="overlay">
@@ -539,7 +550,8 @@
539
550
<p id="error" class="error"></p>
540
551
<div id="character-list"></div>
541
552
<button id="create-character-open" type="button">Create Character</button>
542
<p class="hint">Open chunk 0,0 in the <a href="/editor">world editor</a>, save, then Apply now before walking.</p>
553
<p class="hint">Open chunk 0,0 in the <a href="/editor">world editor</a>, save, then Apply now before
554
walking.</p>
543
555
</section>
544
556
</div>
545
557
<div id="create-backdrop" class="modal-backdrop" hidden></div>
@@ -551,8 +563,10 @@
551
563
<p id="create-error" class="error"></p>
552
564
<form id="create-form">
553
565
<div class="create-tabs" role="tablist">
554
<button type="button" class="create-tab active" data-create-tab="appearance" role="tab" aria-selected="true">Appearance</button>
555
<button type="button" class="create-tab" data-create-tab="clothing" role="tab" aria-selected="false">Clothing</button>
566
<button type="button" class="create-tab active" data-create-tab="appearance" role="tab"
567
aria-selected="true">Appearance</button>
568
<button type="button" class="create-tab" data-create-tab="clothing" role="tab"
569
aria-selected="false">Clothing</button>
556
570
</div>
557
571
<section class="create-pane" data-create-pane="appearance">
558
572
<label>First name <input id="first-name" required></label>
@@ -564,19 +578,24 @@
564
578
</select>
565
579
</label>
566
580
<div id="create-hair" class="hair-controls">
567
<canvas id="create-hair-preview" data-hair-preview width="64" height="96" aria-label="Character preview"></canvas>
581
<canvas id="create-hair-preview" data-hair-preview width="64" height="96"
582
aria-label="Character preview"></canvas>
568
583
<label>Hair
569
584
<select id="create-hair-style" data-hair-style></select>
570
585
</label>
571
<label>Hue <input id="create-hair-hue" data-hair-hue type="range" min="0" max="360" value="30"></label>
572
<label>Saturation <input id="create-hair-saturation" data-hair-saturation type="range" min="0" max="100" value="55"></label>
573
<label>Darkness <input id="create-hair-darkness" data-hair-darkness type="range" min="0" max="100" value="45"></label>
586
<label>Hue <input id="create-hair-hue" data-hair-hue type="range" min="0" max="360"
587
value="30"></label>
588
<label>Saturation <input id="create-hair-saturation" data-hair-saturation type="range" min="0"
589
max="100" value="55"></label>
590
<label>Darkness <input id="create-hair-darkness" data-hair-darkness type="range" min="0" max="100"
591
value="45"></label>
574
592
<span id="create-hair-swatch" data-hair-swatch class="hair-swatch" aria-hidden="true"></span>
575
593
</div>
576
594
</section>
577
595
<section class="create-pane" data-create-pane="clothing" hidden>
578
596
<div id="create-clothing" class="create-clothing">
579
<canvas id="create-clothing-preview" data-clothing-preview width="80" height="96" aria-label="Clothing preview"></canvas>
597
<canvas id="create-clothing-preview" data-clothing-preview width="80" height="96"
598
aria-label="Clothing preview"></canvas>
580
599
<div class="create-clothing-fields">
581
600
<label>Legs
582
601
<select data-create-legs></select>
@@ -585,14 +604,17 @@
585
604
<fieldset class="create-dye-fieldset">
586
605
<legend>Shirt colour</legend>
587
606
<label>Hue <input data-shirt-hue type="range" min="0" max="360" value="30"></label>
588
<label>Saturation <input data-shirt-saturation type="range" min="0" max="100" value="55"></label>
589
<label>Darkness <input data-shirt-darkness type="range" min="0" max="100" value="45"></label>
607
<label>Saturation <input data-shirt-saturation type="range" min="0" max="100"
608
value="55"></label>
609
<label>Darkness <input data-shirt-darkness type="range" min="0" max="100"
610
value="45"></label>
590
611
<span data-shirt-swatch class="hair-swatch" aria-hidden="true"></span>
591
612
</fieldset>
592
613
<fieldset class="create-dye-fieldset">
593
614
<legend>Legs colour</legend>
594
615
<label>Hue <input data-legs-hue type="range" min="0" max="360" value="210"></label>
595
<label>Saturation <input data-legs-saturation type="range" min="0" max="100" value="55"></label>
616
<label>Saturation <input data-legs-saturation type="range" min="0" max="100"
617
value="55"></label>
596
618
<label>Darkness <input data-legs-darkness type="range" min="0" max="100" value="45"></label>
597
619
<span data-legs-swatch class="hair-swatch" aria-hidden="true"></span>
598
620
</fieldset>
@@ -605,4 +627,5 @@
605
627
<script src="/framework/framework.js"></script>
606
628
<script type="module" src="/src/play/main.js"></script>
607
629
</body>
608
</html>
630
631
</html>
@@ -1,10 +1,12 @@1
<!DOCTYPE html>1
<!DOCTYPE html>2
<html lang="en">2
<html lang="en">3
3
<head>4
<head>4
<meta charset="utf-8">5
<meta charset="utf-8">5
<title>Questward</title>6
<title>Questward</title>6
<link rel="stylesheet" href="/ui/play.css">7
<link rel="stylesheet" href="/ui/play.css">7
</head>8
</head>9
8
<body>10
<body>9
<div id="hud" hidden>11
<div id="hud" hidden>10
<span id="you"></span>12
<span id="you"></span>@@ -99,7 +101,8 @@99
<p id="bag-coins" hidden>0 coins</p>101
<p id="bag-coins" hidden>0 coins</p>100
<div id="equip-grid" class="item-grid equip"></div>102
<div id="equip-grid" class="item-grid equip"></div>101
<div id="bag-grid" class="item-grid"></div>103
<div id="bag-grid" class="item-grid"></div>102
<p id="bag-hint" class="hint">Left-click to select. Right-click for other options.</p>104
<p id="bag-hint" class="hint">Left-click to select. Drag between slots to rearrange. Right-click for other105
options.</p>103
</aside>106
</aside>104
<aside id="bank-panel" hidden>107
<aside id="bank-panel" hidden>105
<header>108
<header>@@ -289,7 +292,8 @@289
<p id="shop-coins" class="shop-coins">Coins: 0</p>292
<p id="shop-coins" class="shop-coins">Coins: 0</p>290
<div class="shop-tabs" role="tablist">293
<div class="shop-tabs" role="tablist">291
<button id="shop-tab-buy" type="button" class="shop-tab active" role="tab" aria-selected="true">Buy</button>294
<button id="shop-tab-buy" type="button" class="shop-tab active" role="tab" aria-selected="true">Buy</button>292
<button id="shop-tab-sell" type="button" class="shop-tab" role="tab" aria-selected="false" hidden>Sell</button>295
<button id="shop-tab-sell" type="button" class="shop-tab" role="tab" aria-selected="false"296
hidden>Sell</button>293
</div>297
</div>294
<section id="shop-pane-buy" class="shop-pane">298
<section id="shop-pane-buy" class="shop-pane">295
<div class="shop-body">299
<div class="shop-body">@@ -305,7 +309,8 @@305
<button id="shop-buy-10" type="button">Buy 10</button>309
<button id="shop-buy-10" type="button">Buy 10</button>306
<button id="shop-buy-x" type="button">Buy x</button>310
<button id="shop-buy-x" type="button">Buy x</button>307
</div>311
</div>308
<p id="shop-bag-warn" class="shop-bag-warn" hidden>Inventory full; purchases will be sent to your bank.</p>312
<p id="shop-bag-warn" class="shop-bag-warn" hidden>Inventory full; purchases will be sent to your313
bank.</p>309
</div>314
</div>310
</div>315
</div>311
</section>316
</section>@@ -346,7 +351,8 @@346
<p id="market-hint" class="hint"></p>351
<p id="market-hint" class="hint"></p>347
<p id="market-coins" class="shop-coins">Funds: 0</p>352
<p id="market-coins" class="shop-coins">Funds: 0</p>348
<div class="market-tabs" role="tablist">353
<div class="market-tabs" role="tablist">349
<button id="market-tab-orders" type="button" class="market-tab active" data-tab="orders">Your Orders</button>354
<button id="market-tab-orders" type="button" class="market-tab active" data-tab="orders">Your355
Orders</button>350
<button id="market-tab-sell" type="button" class="market-tab" data-tab="sell">Sell</button>356
<button id="market-tab-sell" type="button" class="market-tab" data-tab="sell">Sell</button>351
<button id="market-tab-buy" type="button" class="market-tab" data-tab="buy">Buy</button>357
<button id="market-tab-buy" type="button" class="market-tab" data-tab="buy">Buy</button>352
</div>358
</div>@@ -370,7 +376,8 @@370
</section>376
</section>371
<section id="market-pane-buy" class="market-pane" data-pane="buy" hidden>377
<section id="market-pane-buy" class="market-pane" data-pane="buy" hidden>372
<label class="send-row">Search items378
<label class="send-row">Search items373
<input id="market-buy-search" type="search" placeholder="Type a name and press Enter" autocomplete="off">379
<input id="market-buy-search" type="search" placeholder="Type a name and press Enter"380
autocomplete="off">374
</label>381
</label>375
<div id="market-catalog" class="market-catalog"></div>382
<div id="market-catalog" class="market-catalog"></div>376
<p id="market-buy-item" class="hint">Search and select an item</p>383
<p id="market-buy-item" class="hint">Search and select an item</p>@@ -392,8 +399,10 @@392
<button id="cauldron-close" type="button">Close</button>399
<button id="cauldron-close" type="button">Close</button>393
</header>400
</header>394
<div class="cauldron-tabs" role="tablist">401
<div class="cauldron-tabs" role="tablist">395
<button id="cauldron-tab-alchemy" type="button" class="cauldron-tab active" role="tab" aria-selected="true">Alchemy</button>402
<button id="cauldron-tab-alchemy" type="button" class="cauldron-tab active" role="tab"396
<button id="cauldron-tab-dyes" type="button" class="cauldron-tab" role="tab" aria-selected="false">Dyes</button>403
aria-selected="true">Alchemy</button>404
<button id="cauldron-tab-dyes" type="button" class="cauldron-tab" role="tab"405
aria-selected="false">Dyes</button>397
</div>406
</div>398
<section id="cauldron-alchemy-pane" class="cauldron-pane">407
<section id="cauldron-alchemy-pane" class="cauldron-pane">399
<div id="cauldron-slots" class="cauldron-slots"></div>408
<div id="cauldron-slots" class="cauldron-slots"></div>@@ -505,7 +514,8 @@505
<div id="skill-level-floats"></div>514
<div id="skill-level-floats"></div>506
<div id="chat-bubbles"></div>515
<div id="chat-bubbles"></div>507
<div id="chat-bar" hidden>516
<div id="chat-bar" hidden>508
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false" placeholder="Say something…">517
<input id="chat-input" type="text" maxlength="100" autocomplete="off" spellcheck="false"518
placeholder="Say something…">509
</div>519
</div>510
<div id="inspect-backdrop" hidden></div>520
<div id="inspect-backdrop" hidden></div>511
<div id="inspect-modal" hidden>521
<div id="inspect-modal" hidden>@@ -521,6 +531,7 @@521
<div id="death-modal" role="dialog" aria-modal="true" aria-labelledby="death-title" hidden>531
<div id="death-modal" role="dialog" aria-modal="true" aria-labelledby="death-title" hidden>522
<h2 id="death-title">You have died</h2>532
<h2 id="death-title">You have died</h2>523
<p>Your remains mark where you fell. Respawn at the nearest church altar.</p>533
<p>Your remains mark where you fell. Respawn at the nearest church altar.</p>534
<p>Your carried coins are dropped on the ground.</p>524
<button id="death-respawn" type="button">Respawn</button>535
<button id="death-respawn" type="button">Respawn</button>525
</div>536
</div>526
<div id="overlay">537
<div id="overlay">@@ -539,7 +550,8 @@539
<p id="error" class="error"></p>550
<p id="error" class="error"></p>540
<div id="character-list"></div>551
<div id="character-list"></div>541
<button id="create-character-open" type="button">Create Character</button>552
<button id="create-character-open" type="button">Create Character</button>542
<p class="hint">Open chunk 0,0 in the <a href="/editor">world editor</a>, save, then Apply now before walking.</p>553
<p class="hint">Open chunk 0,0 in the <a href="/editor">world editor</a>, save, then Apply now before554
walking.</p>543
</section>555
</section>544
</div>556
</div>545
<div id="create-backdrop" class="modal-backdrop" hidden></div>557
<div id="create-backdrop" class="modal-backdrop" hidden></div>@@ -551,8 +563,10 @@551
<p id="create-error" class="error"></p>563
<p id="create-error" class="error"></p>552
<form id="create-form">564
<form id="create-form">553
<div class="create-tabs" role="tablist">565
<div class="create-tabs" role="tablist">554
<button type="button" class="create-tab active" data-create-tab="appearance" role="tab" aria-selected="true">Appearance</button>566
<button type="button" class="create-tab active" data-create-tab="appearance" role="tab"555
<button type="button" class="create-tab" data-create-tab="clothing" role="tab" aria-selected="false">Clothing</button>567
aria-selected="true">Appearance</button>568
<button type="button" class="create-tab" data-create-tab="clothing" role="tab"569
aria-selected="false">Clothing</button>556
</div>570
</div>557
<section class="create-pane" data-create-pane="appearance">571
<section class="create-pane" data-create-pane="appearance">558
<label>First name <input id="first-name" required></label>572
<label>First name <input id="first-name" required></label>@@ -564,19 +578,24 @@564
</select>578
</select>565
</label>579
</label>566
<div id="create-hair" class="hair-controls">580
<div id="create-hair" class="hair-controls">567
<canvas id="create-hair-preview" data-hair-preview width="64" height="96" aria-label="Character preview"></canvas>581
<canvas id="create-hair-preview" data-hair-preview width="64" height="96"582
aria-label="Character preview"></canvas>568
<label>Hair583
<label>Hair569
<select id="create-hair-style" data-hair-style></select>584
<select id="create-hair-style" data-hair-style></select>570
</label>585
</label>571
<label>Hue <input id="create-hair-hue" data-hair-hue type="range" min="0" max="360" value="30"></label>586
<label>Hue <input id="create-hair-hue" data-hair-hue type="range" min="0" max="360"572
<label>Saturation <input id="create-hair-saturation" data-hair-saturation type="range" min="0" max="100" value="55"></label>587
value="30"></label>573
<label>Darkness <input id="create-hair-darkness" data-hair-darkness type="range" min="0" max="100" value="45"></label>588
<label>Saturation <input id="create-hair-saturation" data-hair-saturation type="range" min="0"589
max="100" value="55"></label>590
<label>Darkness <input id="create-hair-darkness" data-hair-darkness type="range" min="0" max="100"591
value="45"></label>574
<span id="create-hair-swatch" data-hair-swatch class="hair-swatch" aria-hidden="true"></span>592
<span id="create-hair-swatch" data-hair-swatch class="hair-swatch" aria-hidden="true"></span>575
</div>593
</div>576
</section>594
</section>577
<section class="create-pane" data-create-pane="clothing" hidden>595
<section class="create-pane" data-create-pane="clothing" hidden>578
<div id="create-clothing" class="create-clothing">596
<div id="create-clothing" class="create-clothing">579
<canvas id="create-clothing-preview" data-clothing-preview width="80" height="96" aria-label="Clothing preview"></canvas>597
<canvas id="create-clothing-preview" data-clothing-preview width="80" height="96"598
aria-label="Clothing preview"></canvas>580
<div class="create-clothing-fields">599
<div class="create-clothing-fields">581
<label>Legs600
<label>Legs582
<select data-create-legs></select>601
<select data-create-legs></select>@@ -585,14 +604,17 @@585
<fieldset class="create-dye-fieldset">604
<fieldset class="create-dye-fieldset">586
<legend>Shirt colour</legend>605
<legend>Shirt colour</legend>587
<label>Hue <input data-shirt-hue type="range" min="0" max="360" value="30"></label>606
<label>Hue <input data-shirt-hue type="range" min="0" max="360" value="30"></label>588
<label>Saturation <input data-shirt-saturation type="range" min="0" max="100" value="55"></label>607
<label>Saturation <input data-shirt-saturation type="range" min="0" max="100"589
<label>Darkness <input data-shirt-darkness type="range" min="0" max="100" value="45"></label>608
value="55"></label>609
<label>Darkness <input data-shirt-darkness type="range" min="0" max="100"610
value="45"></label>590
<span data-shirt-swatch class="hair-swatch" aria-hidden="true"></span>611
<span data-shirt-swatch class="hair-swatch" aria-hidden="true"></span>591
</fieldset>612
</fieldset>592
<fieldset class="create-dye-fieldset">613
<fieldset class="create-dye-fieldset">593
<legend>Legs colour</legend>614
<legend>Legs colour</legend>594
<label>Hue <input data-legs-hue type="range" min="0" max="360" value="210"></label>615
<label>Hue <input data-legs-hue type="range" min="0" max="360" value="210"></label>595
<label>Saturation <input data-legs-saturation type="range" min="0" max="100" value="55"></label>616
<label>Saturation <input data-legs-saturation type="range" min="0" max="100"617
value="55"></label>596
<label>Darkness <input data-legs-darkness type="range" min="0" max="100" value="45"></label>618
<label>Darkness <input data-legs-darkness type="range" min="0" max="100" value="45"></label>597
<span data-legs-swatch class="hair-swatch" aria-hidden="true"></span>619
<span data-legs-swatch class="hair-swatch" aria-hidden="true"></span>598
</fieldset>620
</fieldset>@@ -605,4 +627,5 @@605
<script src="/framework/framework.js"></script>627
<script src="/framework/framework.js"></script>606
<script type="module" src="/src/play/main.js"></script>628
<script type="module" src="/src/play/main.js"></script>607
</body>629
</body>608
</html>630
631
</html>@@ -444,6 +444,11 @@ export function initAlchemy ({
444
444
|| !pickPanel?.hidden
445
445
|| !confirmPanel?.hidden;
446
446
},
447
isOpen ()
448
{
449
return open;
450
},
451
close,
447
452
reset ()
448
453
{
449
454
open = false;
@@ -444,6 +444,11 @@ export function initAlchemy ({444
|| !pickPanel?.hidden444
|| !pickPanel?.hidden445
|| !confirmPanel?.hidden;445
|| !confirmPanel?.hidden;446
},446
},447
isOpen ()448
{449
return open;450
},451
close,447
reset ()452
reset ()448
{453
{449
open = false;454
open = false;@@ -162,6 +162,21 @@ export function initDialogue ({ socket, MessageType, getEntity, captureSpeakerIc
162
162
{
163
163
return open;
164
164
},
165
isOpen ()
166
{
167
return open;
168
},
169
close ()
170
{
171
if (!open)
172
{ return; }
173
socket.send({ type: MessageType.closeDialogue });
174
show(false);
175
},
176
npcEntityId ()
177
{
178
return current?.npcEntityId ?? null;
179
},
165
180
handleStep (message)
166
181
{
167
182
current = {
@@ -162,6 +162,21 @@ export function initDialogue ({ socket, MessageType, getEntity, captureSpeakerIc162
{162
{163
return open;163
return open;164
},164
},165
isOpen ()166
{167
return open;168
},169
close ()170
{171
if (!open)172
{ return; }173
socket.send({ type: MessageType.closeDialogue });174
show(false);175
},176
npcEntityId ()177
{178
return current?.npcEntityId ?? null;179
},165
handleStep (message)180
handleStep (message)166
{181
{167
current = {182
current = {@@ -1,14 +1,15 @@
1
import {
2
itemDefinition,
3
itemDescription,
4
itemOriginSummary,
5
itemAssetPathForStack,
6
itemDisplayName,
7
formatQuantity,
8
ItemId,
9
EQUIPMENT_SLOT,
10
LETTER_MAX_BODY_CHARS
11
} from "/shared/definitions/items.js";
1
import
2
{
3
itemDefinition,
4
itemDescription,
5
itemOriginSummary,
6
itemAssetPathForStack,
7
itemDisplayName,
8
formatQuantity,
9
ItemId,
10
EQUIPMENT_SLOT,
11
LETTER_MAX_BODY_CHARS
12
} from "/shared/definitions/items.js";
12
13
import { formatLetterSignature } from "/shared/courier/systemLetters.js";
13
14
import { applyItemIcon } from "../render/potionIcon.js";
14
15
@@ -41,6 +42,10 @@ export function initInventory ({
41
42
const bankAvailablePane = document.getElementById("bank-available-pane");
42
43
const bankReservedPane = document.getElementById("bank-reserved-pane");
43
44
const bankInheritPane = document.getElementById("bank-inherit-pane");
45
const bankTabAvailable = document.getElementById("bank-tab-available");
46
const bankTabReserved = document.getElementById("bank-tab-reserved");
47
const bankTabInherit = document.getElementById("bank-tab-inherit");
48
const bankTabsRow = document.querySelector("#bank-panel .bank-tabs");
44
49
45
50
const sendPanel = document.getElementById("send-panel");
46
51
const sendBackdrop = document.getElementById("send-backdrop");
@@ -61,6 +66,7 @@ export function initInventory ({
61
66
const writeChequeVault = document.getElementById("write-cheque-vault");
62
67
63
68
let bag = { inventory: [], equipment: { slots: {} }, vault: [], vaultReserved: [] };
69
let inheritance = { slots: [], currency: 0 };
64
70
let selected = null;
65
71
let bankOpen = false;
66
72
let bankTab = "available";
@@ -70,6 +76,8 @@ export function initInventory ({
70
76
let writeChequeState = null;
71
77
let pendingSearch = false;
72
78
let localCharacterId = null;
79
let dragFromIndex = null;
80
let suppressSlotClick = false;
73
81
74
82
document.getElementById("bag-toggle").addEventListener("click", () =>
75
83
{
@@ -140,14 +148,17 @@ export function initInventory ({
140
148
(bag.inventory ?? []).forEach((slot, index) =>
141
149
{
142
150
const button = document.createElement("button");
151
button.type = "button";
143
152
button.className = `item-slot${selected === index ? " selected" : ""}`;
153
button.dataset.slotIndex = String(index);
144
154
button.title = tooltip(slot);
155
button.draggable = !!slot;
145
156
if (slot)
146
157
{
147
const def = itemDefinition(slot.itemId);
148
158
const img = document.createElement("img");
149
159
applyItemIcon(img, slot, itemAssetPathForStack(slot));
150
160
img.alt = itemDisplayName(slot);
161
img.draggable = false;
151
162
button.append(img);
152
163
if (slot.quantity > 1)
153
164
{
@@ -157,8 +168,62 @@ export function initInventory ({
157
168
button.append(count);
158
169
}
159
170
}
171
button.addEventListener("dragstart", (event) =>
172
{
173
if (!slot)
174
{
175
event.preventDefault();
176
return;
177
}
178
dragFromIndex = index;
179
suppressSlotClick = false;
180
event.dataTransfer.effectAllowed = "move";
181
event.dataTransfer.setData("text/plain", String(index));
182
button.classList.add("dragging");
183
});
184
button.addEventListener("dragend", () =>
185
{
186
button.classList.remove("dragging");
187
dragFromIndex = null;
188
for (const el of bagGrid.querySelectorAll(".item-slot.drag-over"))
189
{ el.classList.remove("drag-over"); }
190
// Click fires after a completed drag in some browsers; ignore it.
191
suppressSlotClick = true;
192
queueMicrotask(() =>
193
{ suppressSlotClick = false; });
194
});
195
button.addEventListener("dragover", (event) =>
196
{
197
if (dragFromIndex == null || dragFromIndex === index)
198
{ return; }
199
event.preventDefault();
200
event.dataTransfer.dropEffect = "move";
201
button.classList.add("drag-over");
202
});
203
button.addEventListener("dragleave", () =>
204
{ button.classList.remove("drag-over"); });
205
button.addEventListener("drop", (event) =>
206
{
207
event.preventDefault();
208
button.classList.remove("drag-over");
209
const raw = event.dataTransfer.getData("text/plain");
210
const from = raw === "" ? dragFromIndex : (raw | 0);
211
if (from == null || from === index)
212
{ return; }
213
selected = index;
214
socket.send({
215
type: MessageType.moveInventorySlot,
216
fromSlotIndex: from,
217
toSlotIndex: index
218
});
219
});
160
220
button.addEventListener("click", () =>
161
221
{
222
if (suppressSlotClick)
223
{
224
suppressSlotClick = false;
225
return;
226
}
162
227
if (!slot)
163
228
{ return; }
164
229
if (bankOpen)
@@ -190,11 +255,11 @@ export function initInventory ({
190
255
{
191
256
const worn = bag.equipment?.slots?.[slot];
192
257
const button = document.createElement("button");
258
button.type = "button";
193
259
button.className = "item-slot";
194
260
button.title = worn ? tooltip(worn) : label;
195
261
if (worn)
196
262
{
197
const def = itemDefinition(worn.itemId);
198
263
const img = document.createElement("img");
199
264
applyItemIcon(img, worn, itemAssetPathForStack(worn));
200
265
img.alt = itemDisplayName(worn);
@@ -530,15 +595,50 @@ export function initInventory ({
530
595
closeTransfer();
531
596
}
532
597
598
function bankHasReserved ()
599
{
600
return (bag.vaultReserved ?? []).some((slot) => slot);
601
}
602
603
function bankHasInheritance ()
604
{
605
const slots = inheritance?.slots ?? [];
606
const hasSlots = slots.some((slot) => slot);
607
const hasCoins = (inheritance?.currency | 0) > 0;
608
return hasSlots || hasCoins;
609
}
610
611
function syncBankTabs ()
612
{
613
const showReserved = bankHasReserved();
614
const showInherit = bankHasInheritance();
615
if (bankTabReserved)
616
{ bankTabReserved.hidden = !showReserved; }
617
if (bankTabInherit)
618
{ bankTabInherit.hidden = !showInherit; }
619
if (bankTabsRow)
620
{ bankTabsRow.hidden = !showReserved && !showInherit; }
621
if ((bankTab === "reserved" && !showReserved) || (bankTab === "inherit" && !showInherit))
622
{ bankTab = "available"; }
623
}
624
533
625
function setBankTab (tab)
534
626
{
627
syncBankTabs();
628
if (tab === "reserved" && !bankHasReserved())
629
{ tab = "available"; }
630
if (tab === "inherit" && !bankHasInheritance())
631
{ tab = "available"; }
535
632
bankTab = tab;
536
document.getElementById("bank-tab-available").classList.toggle("active", tab === "available");
537
document.getElementById("bank-tab-reserved").classList.toggle("active", tab === "reserved");
538
document.getElementById("bank-tab-inherit").classList.toggle("active", tab === "inherit");
539
bankAvailablePane.hidden = tab !== "available";
540
bankReservedPane.hidden = tab !== "reserved";
541
bankInheritPane.hidden = tab !== "inherit";
633
bankTabAvailable?.classList.toggle("active", tab === "available");
634
bankTabReserved?.classList.toggle("active", tab === "reserved");
635
bankTabInherit?.classList.toggle("active", tab === "inherit");
636
if (bankAvailablePane)
637
{ bankAvailablePane.hidden = tab !== "available"; }
638
if (bankReservedPane)
639
{ bankReservedPane.hidden = tab !== "reserved"; }
640
if (bankInheritPane)
641
{ bankInheritPane.hidden = tab !== "inherit"; }
542
642
}
543
643
544
644
function openSend (slotIndex, slot)
@@ -736,7 +836,7 @@ export function initInventory ({
736
836
button.className = "item-slot";
737
837
if (writeChequeState && side === "vault" && writeChequeState.vaultSlotIndex === index)
738
838
{ button.classList.add("selected"); }
739
button.title = tooltip(slot);
839
button.title = tooltip(slot, { reserved: side === "reserved" });
740
840
const def = itemDefinition(slot.itemId);
741
841
const img = document.createElement("img");
742
842
applyItemIcon(img, slot, itemAssetPathForStack(slot));
@@ -802,15 +902,20 @@ export function initInventory ({
802
902
setBankTab(bankTab);
803
903
}
804
904
805
function tooltip (slot)
905
function tooltip (slot, { reserved = false } = {})
806
906
{
807
907
if (!slot)
808
908
{ return ""; }
809
const def = itemDefinition(slot.itemId);
810
909
const base = `${itemDisplayName(slot)}${slot.quantity > 1 ? ` ×${formatQuantity(slot.quantity)}` : ""}`;
811
910
const origin = itemOriginSummary(slot);
812
911
const desc = itemDescription(slot, { localCharacterId });
813
912
const lines = [base];
913
if (reserved)
914
{
915
lines.push(slot.chequeId
916
? "Reserved against a written cheque."
917
: "Reserved in the vault.");
918
}
814
919
if (origin)
815
920
{ lines.push(origin); }
816
921
if (desc)
@@ -824,6 +929,11 @@ export function initInventory ({
824
929
return !bagPanel.hidden || bankOpen || !sendPanel.hidden || !letterPanel.hidden
825
930
|| !sendTargetPanel.hidden || !transferPanel.hidden || !writeChequePanel.hidden;
826
931
},
932
isBankOpen ()
933
{
934
return bankOpen;
935
},
936
closeBank,
827
937
isBlocking ()
828
938
{
829
939
if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden
@@ -870,7 +980,10 @@ export function initInventory ({
870
980
bag = { ...bag, ...message };
871
981
render();
872
982
if (bankOpen)
873
{ renderBank(); }
983
{
984
renderBank();
985
syncBankTabs();
986
}
874
987
if (writeChequeState)
875
988
{ renderWriteChequeVault(); }
876
989
if (letterState && letterStatus.textContent === "Saving…")
@@ -898,11 +1011,22 @@ export function initInventory ({
898
1011
bagPanel.hidden = false;
899
1012
bag.vault = message.vault ?? [];
900
1013
bag.vaultReserved = message.vaultReserved ?? [];
901
renderVault(inheritGrid, message.inheritance?.slots ?? [], { interactive: false });
1014
inheritance = {
1015
slots: message.inheritance?.slots ?? [],
1016
currency: message.inheritance?.currency | 0 || 0
1017
};
1018
renderVault(inheritGrid, inheritance.slots, { interactive: false });
902
1019
inheritGrid.querySelectorAll("button").forEach((button) =>
903
1020
{
904
1021
button.onclick = null;
905
1022
});
1023
const inheritCoins = document.getElementById("inherit-coins");
1024
if (inheritCoins)
1025
{
1026
const coins = inheritance.currency | 0;
1027
inheritCoins.hidden = coins <= 0;
1028
inheritCoins.textContent = coins > 0 ? `${formatQuantity(coins)} coins` : "";
1029
}
906
1030
setBankTab("available");
907
1031
renderBank();
908
1032
render();
@@ -1,14 +1,15 @@1
import {1
import2
itemDefinition,2
{3
itemDescription,3
itemDefinition,4
itemOriginSummary,4
itemDescription,5
itemAssetPathForStack,5
itemOriginSummary,6
itemDisplayName,6
itemAssetPathForStack,7
formatQuantity,7
itemDisplayName,8
ItemId,8
formatQuantity,9
EQUIPMENT_SLOT,9
ItemId,10
LETTER_MAX_BODY_CHARS10
EQUIPMENT_SLOT,11
} from "/shared/definitions/items.js";11
LETTER_MAX_BODY_CHARS12
} from "/shared/definitions/items.js";12
import { formatLetterSignature } from "/shared/courier/systemLetters.js";13
import { formatLetterSignature } from "/shared/courier/systemLetters.js";13
import { applyItemIcon } from "../render/potionIcon.js";14
import { applyItemIcon } from "../render/potionIcon.js";14
15
@@ -41,6 +42,10 @@ export function initInventory ({41
const bankAvailablePane = document.getElementById("bank-available-pane");42
const bankAvailablePane = document.getElementById("bank-available-pane");42
const bankReservedPane = document.getElementById("bank-reserved-pane");43
const bankReservedPane = document.getElementById("bank-reserved-pane");43
const bankInheritPane = document.getElementById("bank-inherit-pane");44
const bankInheritPane = document.getElementById("bank-inherit-pane");45
const bankTabAvailable = document.getElementById("bank-tab-available");46
const bankTabReserved = document.getElementById("bank-tab-reserved");47
const bankTabInherit = document.getElementById("bank-tab-inherit");48
const bankTabsRow = document.querySelector("#bank-panel .bank-tabs");44
49
45
const sendPanel = document.getElementById("send-panel");50
const sendPanel = document.getElementById("send-panel");46
const sendBackdrop = document.getElementById("send-backdrop");51
const sendBackdrop = document.getElementById("send-backdrop");@@ -61,6 +66,7 @@ export function initInventory ({61
const writeChequeVault = document.getElementById("write-cheque-vault");66
const writeChequeVault = document.getElementById("write-cheque-vault");62
67
63
let bag = { inventory: [], equipment: { slots: {} }, vault: [], vaultReserved: [] };68
let bag = { inventory: [], equipment: { slots: {} }, vault: [], vaultReserved: [] };69
let inheritance = { slots: [], currency: 0 };64
let selected = null;70
let selected = null;65
let bankOpen = false;71
let bankOpen = false;66
let bankTab = "available";72
let bankTab = "available";@@ -70,6 +76,8 @@ export function initInventory ({70
let writeChequeState = null;76
let writeChequeState = null;71
let pendingSearch = false;77
let pendingSearch = false;72
let localCharacterId = null;78
let localCharacterId = null;79
let dragFromIndex = null;80
let suppressSlotClick = false;73
81
74
document.getElementById("bag-toggle").addEventListener("click", () =>82
document.getElementById("bag-toggle").addEventListener("click", () =>75
{83
{@@ -140,14 +148,17 @@ export function initInventory ({140
(bag.inventory ?? []).forEach((slot, index) =>148
(bag.inventory ?? []).forEach((slot, index) =>141
{149
{142
const button = document.createElement("button");150
const button = document.createElement("button");151
button.type = "button";143
button.className = `item-slot${selected === index ? " selected" : ""}`;152
button.className = `item-slot${selected === index ? " selected" : ""}`;153
button.dataset.slotIndex = String(index);144
button.title = tooltip(slot);154
button.title = tooltip(slot);155
button.draggable = !!slot;145
if (slot)156
if (slot)146
{157
{147
const def = itemDefinition(slot.itemId);148
const img = document.createElement("img");158
const img = document.createElement("img");149
applyItemIcon(img, slot, itemAssetPathForStack(slot));159
applyItemIcon(img, slot, itemAssetPathForStack(slot));150
img.alt = itemDisplayName(slot);160
img.alt = itemDisplayName(slot);161
img.draggable = false;151
button.append(img);162
button.append(img);152
if (slot.quantity > 1)163
if (slot.quantity > 1)153
{164
{@@ -157,8 +168,62 @@ export function initInventory ({157
button.append(count);168
button.append(count);158
}169
}159
}170
}171
button.addEventListener("dragstart", (event) =>172
{173
if (!slot)174
{175
event.preventDefault();176
return;177
}178
dragFromIndex = index;179
suppressSlotClick = false;180
event.dataTransfer.effectAllowed = "move";181
event.dataTransfer.setData("text/plain", String(index));182
button.classList.add("dragging");183
});184
button.addEventListener("dragend", () =>185
{186
button.classList.remove("dragging");187
dragFromIndex = null;188
for (const el of bagGrid.querySelectorAll(".item-slot.drag-over"))189
{ el.classList.remove("drag-over"); }190
// Click fires after a completed drag in some browsers; ignore it.191
suppressSlotClick = true;192
queueMicrotask(() =>193
{ suppressSlotClick = false; });194
});195
button.addEventListener("dragover", (event) =>196
{197
if (dragFromIndex == null || dragFromIndex === index)198
{ return; }199
event.preventDefault();200
event.dataTransfer.dropEffect = "move";201
button.classList.add("drag-over");202
});203
button.addEventListener("dragleave", () =>204
{ button.classList.remove("drag-over"); });205
button.addEventListener("drop", (event) =>206
{207
event.preventDefault();208
button.classList.remove("drag-over");209
const raw = event.dataTransfer.getData("text/plain");210
const from = raw === "" ? dragFromIndex : (raw | 0);211
if (from == null || from === index)212
{ return; }213
selected = index;214
socket.send({215
type: MessageType.moveInventorySlot,216
fromSlotIndex: from,217
toSlotIndex: index218
});219
});160
button.addEventListener("click", () =>220
button.addEventListener("click", () =>161
{221
{222
if (suppressSlotClick)223
{224
suppressSlotClick = false;225
return;226
}162
if (!slot)227
if (!slot)163
{ return; }228
{ return; }164
if (bankOpen)229
if (bankOpen)@@ -190,11 +255,11 @@ export function initInventory ({190
{255
{191
const worn = bag.equipment?.slots?.[slot];256
const worn = bag.equipment?.slots?.[slot];192
const button = document.createElement("button");257
const button = document.createElement("button");258
button.type = "button";193
button.className = "item-slot";259
button.className = "item-slot";194
button.title = worn ? tooltip(worn) : label;260
button.title = worn ? tooltip(worn) : label;195
if (worn)261
if (worn)196
{262
{197
const def = itemDefinition(worn.itemId);198
const img = document.createElement("img");263
const img = document.createElement("img");199
applyItemIcon(img, worn, itemAssetPathForStack(worn));264
applyItemIcon(img, worn, itemAssetPathForStack(worn));200
img.alt = itemDisplayName(worn);265
img.alt = itemDisplayName(worn);@@ -530,15 +595,50 @@ export function initInventory ({530
closeTransfer();595
closeTransfer();531
}596
}532
597
598
function bankHasReserved ()599
{600
return (bag.vaultReserved ?? []).some((slot) => slot);601
}602
603
function bankHasInheritance ()604
{605
const slots = inheritance?.slots ?? [];606
const hasSlots = slots.some((slot) => slot);607
const hasCoins = (inheritance?.currency | 0) > 0;608
return hasSlots || hasCoins;609
}610
611
function syncBankTabs ()612
{613
const showReserved = bankHasReserved();614
const showInherit = bankHasInheritance();615
if (bankTabReserved)616
{ bankTabReserved.hidden = !showReserved; }617
if (bankTabInherit)618
{ bankTabInherit.hidden = !showInherit; }619
if (bankTabsRow)620
{ bankTabsRow.hidden = !showReserved && !showInherit; }621
if ((bankTab === "reserved" && !showReserved) || (bankTab === "inherit" && !showInherit))622
{ bankTab = "available"; }623
}624
533
function setBankTab (tab)625
function setBankTab (tab)534
{626
{627
syncBankTabs();628
if (tab === "reserved" && !bankHasReserved())629
{ tab = "available"; }630
if (tab === "inherit" && !bankHasInheritance())631
{ tab = "available"; }535
bankTab = tab;632
bankTab = tab;536
document.getElementById("bank-tab-available").classList.toggle("active", tab === "available");633
bankTabAvailable?.classList.toggle("active", tab === "available");537
document.getElementById("bank-tab-reserved").classList.toggle("active", tab === "reserved");634
bankTabReserved?.classList.toggle("active", tab === "reserved");538
document.getElementById("bank-tab-inherit").classList.toggle("active", tab === "inherit");635
bankTabInherit?.classList.toggle("active", tab === "inherit");539
bankAvailablePane.hidden = tab !== "available";636
if (bankAvailablePane)540
bankReservedPane.hidden = tab !== "reserved";637
{ bankAvailablePane.hidden = tab !== "available"; }541
bankInheritPane.hidden = tab !== "inherit";638
if (bankReservedPane)639
{ bankReservedPane.hidden = tab !== "reserved"; }640
if (bankInheritPane)641
{ bankInheritPane.hidden = tab !== "inherit"; }542
}642
}543
643
544
function openSend (slotIndex, slot)644
function openSend (slotIndex, slot)@@ -736,7 +836,7 @@ export function initInventory ({736
button.className = "item-slot";836
button.className = "item-slot";737
if (writeChequeState && side === "vault" && writeChequeState.vaultSlotIndex === index)837
if (writeChequeState && side === "vault" && writeChequeState.vaultSlotIndex === index)738
{ button.classList.add("selected"); }838
{ button.classList.add("selected"); }739
button.title = tooltip(slot);839
button.title = tooltip(slot, { reserved: side === "reserved" });740
const def = itemDefinition(slot.itemId);840
const def = itemDefinition(slot.itemId);741
const img = document.createElement("img");841
const img = document.createElement("img");742
applyItemIcon(img, slot, itemAssetPathForStack(slot));842
applyItemIcon(img, slot, itemAssetPathForStack(slot));@@ -802,15 +902,20 @@ export function initInventory ({802
setBankTab(bankTab);902
setBankTab(bankTab);803
}903
}804
904
805
function tooltip (slot)905
function tooltip (slot, { reserved = false } = {})806
{906
{807
if (!slot)907
if (!slot)808
{ return ""; }908
{ return ""; }809
const def = itemDefinition(slot.itemId);810
const base = `${itemDisplayName(slot)}${slot.quantity > 1 ? ` ×${formatQuantity(slot.quantity)}` : ""}`;909
const base = `${itemDisplayName(slot)}${slot.quantity > 1 ? ` ×${formatQuantity(slot.quantity)}` : ""}`;811
const origin = itemOriginSummary(slot);910
const origin = itemOriginSummary(slot);812
const desc = itemDescription(slot, { localCharacterId });911
const desc = itemDescription(slot, { localCharacterId });813
const lines = [base];912
const lines = [base];913
if (reserved)914
{915
lines.push(slot.chequeId916
? "Reserved against a written cheque."917
: "Reserved in the vault.");918
}814
if (origin)919
if (origin)815
{ lines.push(origin); }920
{ lines.push(origin); }816
if (desc)921
if (desc)@@ -824,6 +929,11 @@ export function initInventory ({824
return !bagPanel.hidden || bankOpen || !sendPanel.hidden || !letterPanel.hidden929
return !bagPanel.hidden || bankOpen || !sendPanel.hidden || !letterPanel.hidden825
|| !sendTargetPanel.hidden || !transferPanel.hidden || !writeChequePanel.hidden;930
|| !sendTargetPanel.hidden || !transferPanel.hidden || !writeChequePanel.hidden;826
},931
},932
isBankOpen ()933
{934
return bankOpen;935
},936
closeBank,827
isBlocking ()937
isBlocking ()828
{938
{829
if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden939
if (!sendPanel.hidden || !letterPanel.hidden || !sendTargetPanel.hidden@@ -870,7 +980,10 @@ export function initInventory ({870
bag = { ...bag, ...message };980
bag = { ...bag, ...message };871
render();981
render();872
if (bankOpen)982
if (bankOpen)873
{ renderBank(); }983
{984
renderBank();985
syncBankTabs();986
}874
if (writeChequeState)987
if (writeChequeState)875
{ renderWriteChequeVault(); }988
{ renderWriteChequeVault(); }876
if (letterState && letterStatus.textContent === "Saving…")989
if (letterState && letterStatus.textContent === "Saving…")@@ -898,11 +1011,22 @@ export function initInventory ({898
bagPanel.hidden = false;1011
bagPanel.hidden = false;899
bag.vault = message.vault ?? [];1012
bag.vault = message.vault ?? [];900
bag.vaultReserved = message.vaultReserved ?? [];1013
bag.vaultReserved = message.vaultReserved ?? [];901
renderVault(inheritGrid, message.inheritance?.slots ?? [], { interactive: false });1014
inheritance = {1015
slots: message.inheritance?.slots ?? [],1016
currency: message.inheritance?.currency | 0 || 01017
};1018
renderVault(inheritGrid, inheritance.slots, { interactive: false });902
inheritGrid.querySelectorAll("button").forEach((button) =>1019
inheritGrid.querySelectorAll("button").forEach((button) =>903
{1020
{904
button.onclick = null;1021
button.onclick = null;905
});1022
});1023
const inheritCoins = document.getElementById("inherit-coins");1024
if (inheritCoins)1025
{1026
const coins = inheritance.currency | 0;1027
inheritCoins.hidden = coins <= 0;1028
inheritCoins.textContent = coins > 0 ? `${formatQuantity(coins)} coins` : "";1029
}906
setBankTab("available");1030
setBankTab("available");907
renderBank();1031
renderBank();908
render();1032
render();@@ -81,8 +81,14 @@ let createHairControls;
81
81
let createClothingControls;
82
82
let createActiveTab = "appearance";
83
83
let pendingPickup = null;
84
/** @type {{ kind: "bank" | "doorway" | "cauldron" | "station" | "mine" | "chop", tileX: number, tileY: number, stationId?: string, getCheques?: boolean } | { kind: "talk", targetEntityId: number } | null } */
84
/** @type {{ kind: "bank" | "doorway" | "cauldron" | "station" | "mine" | "chop", tileX: number, tileY: number, stationId?: string, getCheques?: boolean } | { kind: "talk", targetEntityId: number } | { kind: "market" | "bounty" | "barber", tileX: number, tileY: number } | null } */
85
85
let pendingInteract = null;
86
/**
87
* Block/NPC the player currently has a station UI open for.
88
* Closed automatically when Chebyshev distance exceeds 1.
89
* @type {null | { kind: "bank" | "station" | "cauldron" | "market" | "bounty" | "barber", tileX: number, tileY: number } | { kind: "shop" | "dialogue", entityId: number }}
90
*/
91
let uiFocus = null;
86
92
/** Last approach moveTo so we do not re-path every frame (resets server walkCarry). */
87
93
let approachMove = null;
88
94
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */
@@ -391,6 +397,80 @@ function requestTalk (targetEntityId, purpose = null)
391
397
{ flushPendingInteract(); }
392
398
}
393
399
400
function setUiFocus (focus)
401
{
402
uiFocus = focus;
403
}
404
405
function clearUiFocus ()
406
{
407
uiFocus = null;
408
}
409
410
/** Close bank / station / NPC UIs when the player walks out of adjacency. */
411
function closeOpenUiIfTooFar ()
412
{
413
if (!uiFocus || !view)
414
{ return; }
415
const local = view.entities.get(view.localEntityId);
416
if (!local)
417
{ return; }
418
419
let tooFar = false;
420
if (uiFocus.entityId != null)
421
{
422
const target = view.entities.get(uiFocus.entityId);
423
tooFar = !target
424
|| chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1;
425
}
426
else if (uiFocus.tileX != null && uiFocus.tileY != null)
427
{
428
tooFar = chebyshev(local.tileX, local.tileY, uiFocus.tileX, uiFocus.tileY) > 1;
429
}
430
if (!tooFar)
431
{ return; }
432
433
const kind = uiFocus.kind;
434
clearUiFocus();
435
switch (kind)
436
{
437
case "bank":
438
if (inventory?.isBankOpen?.())
439
{ inventory.closeBank(); }
440
break;
441
case "station":
442
if (crafting?.isOpen?.())
443
{ crafting.close(); }
444
break;
445
case "cauldron":
446
if (alchemy?.isOpen?.())
447
{ alchemy.close(); }
448
break;
449
case "market":
450
if (market?.isOpen?.())
451
{ market.close(); }
452
break;
453
case "bounty":
454
if (bounty?.isOpen?.())
455
{ bounty.close(); }
456
break;
457
case "barber":
458
if (barber?.isOpen?.())
459
{ barber.close(); }
460
break;
461
case "shop":
462
if (shop?.isOpen?.())
463
{ shop.close(); }
464
break;
465
case "dialogue":
466
if (dialogueUi?.isOpen?.())
467
{ dialogueUi.close(); }
468
break;
469
default:
470
break;
471
}
472
}
473
394
474
function flushPendingInteract ()
395
475
{
396
476
if (!pendingInteract || !view)
@@ -403,6 +483,11 @@ function flushPendingInteract ()
403
483
{
404
484
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
405
485
{ return; }
486
setUiFocus({
487
kind: "bank",
488
tileX: pendingInteract.tileX,
489
tileY: pendingInteract.tileY
490
});
406
491
const getCheques = !!pendingInteract.getCheques;
407
492
socket.send({ type: MessageType.openBank });
408
493
if (getCheques)
@@ -428,6 +513,11 @@ function flushPendingInteract ()
428
513
{
429
514
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
430
515
{ return; }
516
setUiFocus({
517
kind: "market",
518
tileX: pendingInteract.tileX,
519
tileY: pendingInteract.tileY
520
});
431
521
socket.send({ type: MessageType.openMarket });
432
522
clearPendingInteract();
433
523
return;
@@ -437,6 +527,11 @@ function flushPendingInteract ()
437
527
{
438
528
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
439
529
{ return; }
530
setUiFocus({
531
kind: "bounty",
532
tileX: pendingInteract.tileX,
533
tileY: pendingInteract.tileY
534
});
440
535
socket.send({ type: MessageType.openBounty });
441
536
clearPendingInteract();
442
537
return;
@@ -446,6 +541,11 @@ function flushPendingInteract ()
446
541
{
447
542
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
448
543
{ return; }
544
setUiFocus({
545
kind: "barber",
546
tileX: pendingInteract.tileX,
547
tileY: pendingInteract.tileY
548
});
449
549
socket.send({ type: MessageType.openBarber });
450
550
clearPendingInteract();
451
551
return;
@@ -455,6 +555,11 @@ function flushPendingInteract ()
455
555
{
456
556
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
457
557
{ return; }
558
setUiFocus({
559
kind: "cauldron",
560
tileX: pendingInteract.tileX,
561
tileY: pendingInteract.tileY
562
});
458
563
socket.send({ type: MessageType.openCauldron });
459
564
clearPendingInteract();
460
565
return;
@@ -464,6 +569,11 @@ function flushPendingInteract ()
464
569
{
465
570
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)
466
571
{ return; }
572
setUiFocus({
573
kind: "station",
574
tileX: pendingInteract.tileX,
575
tileY: pendingInteract.tileY
576
});
467
577
socket.send({
468
578
type: MessageType.openStation,
469
579
stationId: pendingInteract.stationId
@@ -530,6 +640,11 @@ function flushPendingInteract ()
530
640
targetEntityId: pendingInteract.targetEntityId,
531
641
purpose: pendingInteract.purpose || undefined
532
642
});
643
// Shop vs dialogue is decided server-side; both use NPC adjacency.
644
setUiFocus({
645
kind: pendingInteract.purpose === "shop" ? "shop" : "dialogue",
646
entityId: pendingInteract.targetEntityId
647
});
533
648
clearPendingInteract();
534
649
}
535
650
}
@@ -1292,6 +1407,7 @@ async function main ()
1292
1407
});
1293
1408
}
1294
1409
}
1410
closeOpenUiIfTooFar();
1295
1411
break;
1296
1412
case MessageType.chunkDelta:
1297
1413
for (const tile of message.tiles ?? [])
@@ -1313,11 +1429,20 @@ async function main ()
1313
1429
break;
1314
1430
case MessageType.entityMove:
1315
1431
view?.moveEntity(message);
1316
if (message.entityId === view?.localEntityId && message.gait)
1432
if (message.entityId === view?.localEntityId)
1317
1433
{
1318
gait = message.gait;
1319
document.getElementById("gait").textContent = gait;
1434
if (message.gait)
1435
{
1436
gait = message.gait;
1437
document.getElementById("gait").textContent = gait;
1438
}
1439
closeOpenUiIfTooFar();
1320
1440
}
1441
else if (
1442
uiFocus?.entityId != null
1443
&& message.entityId === uiFocus.entityId
1444
)
1445
{ closeOpenUiIfTooFar(); }
1321
1446
break;
1322
1447
case MessageType.entityDespawn:
1323
1448
view?.despawnEntity(message.entityId);
@@ -1382,6 +1507,8 @@ async function main ()
1382
1507
inventory?.handleBank(message);
1383
1508
break;
1384
1509
case MessageType.cauldronSnapshot:
1510
if (message.open === false && uiFocus?.kind === "cauldron")
1511
{ clearUiFocus(); }
1385
1512
alchemy?.handleSnapshot(message);
1386
1513
break;
1387
1514
case MessageType.pigeonDispatched:
@@ -1436,15 +1563,21 @@ async function main ()
1436
1563
{ crafting?.openStation(message.stationId); }
1437
1564
break;
1438
1565
case MessageType.shopOpen:
1566
if (message.npcEntityId != null)
1567
{ setUiFocus({ kind: "shop", entityId: message.npcEntityId | 0 }); }
1439
1568
shop?.handleShopOpen(message);
1440
1569
break;
1441
1570
case MessageType.shopClosed:
1571
if (uiFocus?.kind === "shop")
1572
{ clearUiFocus(); }
1442
1573
shop?.handleShopClosed(message);
1443
1574
break;
1444
1575
case MessageType.marketOpen:
1445
1576
market?.handleOpen(message);
1446
1577
break;
1447
1578
case MessageType.marketClosed:
1579
if (uiFocus?.kind === "market")
1580
{ clearUiFocus(); }
1448
1581
market?.handleClosed(message);
1449
1582
break;
1450
1583
case MessageType.marketTrade:
@@ -1455,6 +1588,8 @@ async function main ()
1455
1588
bounty?.handleSnapshot(message);
1456
1589
break;
1457
1590
case MessageType.closeBounty:
1591
if (uiFocus?.kind === "bounty")
1592
{ clearUiFocus(); }
1458
1593
bounty?.handleClosed(message);
1459
1594
break;
1460
1595
case MessageType.characterBounty:
@@ -1465,6 +1600,8 @@ async function main ()
1465
1600
barber?.handleSnapshot(message);
1466
1601
break;
1467
1602
case MessageType.closeBarber:
1603
if (uiFocus?.kind === "barber")
1604
{ clearUiFocus(); }
1468
1605
barber?.handleClosed(message);
1469
1606
break;
1470
1607
case MessageType.itemBubble:
@@ -1578,12 +1715,18 @@ async function main ()
1578
1715
questsUi?.handleStepComplete(message);
1579
1716
break;
1580
1717
case MessageType.dialogueStep:
1718
if (message.npcEntityId != null)
1719
{ setUiFocus({ kind: "dialogue", entityId: message.npcEntityId | 0 }); }
1581
1720
dialogueUi?.handleStep(message);
1582
1721
break;
1583
1722
case MessageType.dialogueChoices:
1723
if (message.npcEntityId != null)
1724
{ setUiFocus({ kind: "dialogue", entityId: message.npcEntityId | 0 }); }
1584
1725
dialogueUi?.handleChoices(message);
1585
1726
break;
1586
1727
case MessageType.dialogueClose:
1728
if (uiFocus?.kind === "dialogue")
1729
{ clearUiFocus(); }
1587
1730
dialogueUi?.handleClose(message);
1588
1731
break;
1589
1732
case MessageType.forceLogout:
@@ -1611,6 +1754,7 @@ function returnToMenu (reason = "")
1611
1754
{
1612
1755
playing = false;
1613
1756
clearAllPendingActions();
1757
clearUiFocus();
1614
1758
social?.reset();
1615
1759
chat?.reset();
1616
1760
inventory?.reset();
@@ -81,8 +81,14 @@ let createHairControls;81
let createClothingControls;81
let createClothingControls;82
let createActiveTab = "appearance";82
let createActiveTab = "appearance";83
let pendingPickup = null;83
let pendingPickup = null;84
/** @type {{ kind: "bank" | "doorway" | "cauldron" | "station" | "mine" | "chop", tileX: number, tileY: number, stationId?: string, getCheques?: boolean } | { kind: "talk", targetEntityId: number } | null } */84
/** @type {{ kind: "bank" | "doorway" | "cauldron" | "station" | "mine" | "chop", tileX: number, tileY: number, stationId?: string, getCheques?: boolean } | { kind: "talk", targetEntityId: number } | { kind: "market" | "bounty" | "barber", tileX: number, tileY: number } | null } */85
let pendingInteract = null;85
let pendingInteract = null;86
/**87
* Block/NPC the player currently has a station UI open for.88
* Closed automatically when Chebyshev distance exceeds 1.89
* @type {null | { kind: "bank" | "station" | "cauldron" | "market" | "bounty" | "barber", tileX: number, tileY: number } | { kind: "shop" | "dialogue", entityId: number }}90
*/91
let uiFocus = null;86
/** Last approach moveTo so we do not re-path every frame (resets server walkCarry). */92
/** Last approach moveTo so we do not re-path every frame (resets server walkCarry). */87
let approachMove = null;93
let approachMove = null;88
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */94
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */@@ -391,6 +397,80 @@ function requestTalk (targetEntityId, purpose = null)391
{ flushPendingInteract(); }397
{ flushPendingInteract(); }392
}398
}393
399
400
function setUiFocus (focus)401
{402
uiFocus = focus;403
}404
405
function clearUiFocus ()406
{407
uiFocus = null;408
}409
410
/** Close bank / station / NPC UIs when the player walks out of adjacency. */411
function closeOpenUiIfTooFar ()412
{413
if (!uiFocus || !view)414
{ return; }415
const local = view.entities.get(view.localEntityId);416
if (!local)417
{ return; }418
419
let tooFar = false;420
if (uiFocus.entityId != null)421
{422
const target = view.entities.get(uiFocus.entityId);423
tooFar = !target424
|| chebyshev(local.tileX, local.tileY, target.tileX, target.tileY) > 1;425
}426
else if (uiFocus.tileX != null && uiFocus.tileY != null)427
{428
tooFar = chebyshev(local.tileX, local.tileY, uiFocus.tileX, uiFocus.tileY) > 1;429
}430
if (!tooFar)431
{ return; }432
433
const kind = uiFocus.kind;434
clearUiFocus();435
switch (kind)436
{437
case "bank":438
if (inventory?.isBankOpen?.())439
{ inventory.closeBank(); }440
break;441
case "station":442
if (crafting?.isOpen?.())443
{ crafting.close(); }444
break;445
case "cauldron":446
if (alchemy?.isOpen?.())447
{ alchemy.close(); }448
break;449
case "market":450
if (market?.isOpen?.())451
{ market.close(); }452
break;453
case "bounty":454
if (bounty?.isOpen?.())455
{ bounty.close(); }456
break;457
case "barber":458
if (barber?.isOpen?.())459
{ barber.close(); }460
break;461
case "shop":462
if (shop?.isOpen?.())463
{ shop.close(); }464
break;465
case "dialogue":466
if (dialogueUi?.isOpen?.())467
{ dialogueUi.close(); }468
break;469
default:470
break;471
}472
}473
394
function flushPendingInteract ()474
function flushPendingInteract ()395
{475
{396
if (!pendingInteract || !view)476
if (!pendingInteract || !view)@@ -403,6 +483,11 @@ function flushPendingInteract ()403
{483
{404
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)484
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)405
{ return; }485
{ return; }486
setUiFocus({487
kind: "bank",488
tileX: pendingInteract.tileX,489
tileY: pendingInteract.tileY490
});406
const getCheques = !!pendingInteract.getCheques;491
const getCheques = !!pendingInteract.getCheques;407
socket.send({ type: MessageType.openBank });492
socket.send({ type: MessageType.openBank });408
if (getCheques)493
if (getCheques)@@ -428,6 +513,11 @@ function flushPendingInteract ()428
{513
{429
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)514
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)430
{ return; }515
{ return; }516
setUiFocus({517
kind: "market",518
tileX: pendingInteract.tileX,519
tileY: pendingInteract.tileY520
});431
socket.send({ type: MessageType.openMarket });521
socket.send({ type: MessageType.openMarket });432
clearPendingInteract();522
clearPendingInteract();433
return;523
return;@@ -437,6 +527,11 @@ function flushPendingInteract ()437
{527
{438
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)528
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)439
{ return; }529
{ return; }530
setUiFocus({531
kind: "bounty",532
tileX: pendingInteract.tileX,533
tileY: pendingInteract.tileY534
});440
socket.send({ type: MessageType.openBounty });535
socket.send({ type: MessageType.openBounty });441
clearPendingInteract();536
clearPendingInteract();442
return;537
return;@@ -446,6 +541,11 @@ function flushPendingInteract ()446
{541
{447
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)542
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)448
{ return; }543
{ return; }544
setUiFocus({545
kind: "barber",546
tileX: pendingInteract.tileX,547
tileY: pendingInteract.tileY548
});449
socket.send({ type: MessageType.openBarber });549
socket.send({ type: MessageType.openBarber });450
clearPendingInteract();550
clearPendingInteract();451
return;551
return;@@ -455,6 +555,11 @@ function flushPendingInteract ()455
{555
{456
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)556
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)457
{ return; }557
{ return; }558
setUiFocus({559
kind: "cauldron",560
tileX: pendingInteract.tileX,561
tileY: pendingInteract.tileY562
});458
socket.send({ type: MessageType.openCauldron });563
socket.send({ type: MessageType.openCauldron });459
clearPendingInteract();564
clearPendingInteract();460
return;565
return;@@ -464,6 +569,11 @@ function flushPendingInteract ()464
{569
{465
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)570
if (chebyshev(local.tileX, local.tileY, pendingInteract.tileX, pendingInteract.tileY) > 1)466
{ return; }571
{ return; }572
setUiFocus({573
kind: "station",574
tileX: pendingInteract.tileX,575
tileY: pendingInteract.tileY576
});467
socket.send({577
socket.send({468
type: MessageType.openStation,578
type: MessageType.openStation,469
stationId: pendingInteract.stationId579
stationId: pendingInteract.stationId@@ -530,6 +640,11 @@ function flushPendingInteract ()530
targetEntityId: pendingInteract.targetEntityId,640
targetEntityId: pendingInteract.targetEntityId,531
purpose: pendingInteract.purpose || undefined641
purpose: pendingInteract.purpose || undefined532
});642
});643
// Shop vs dialogue is decided server-side; both use NPC adjacency.644
setUiFocus({645
kind: pendingInteract.purpose === "shop" ? "shop" : "dialogue",646
entityId: pendingInteract.targetEntityId647
});533
clearPendingInteract();648
clearPendingInteract();534
}649
}535
}650
}@@ -1292,6 +1407,7 @@ async function main ()1292
});1407
});1293
}1408
}1294
}1409
}1410
closeOpenUiIfTooFar();1295
break;1411
break;1296
case MessageType.chunkDelta:1412
case MessageType.chunkDelta:1297
for (const tile of message.tiles ?? [])1413
for (const tile of message.tiles ?? [])@@ -1313,11 +1429,20 @@ async function main ()1313
break;1429
break;1314
case MessageType.entityMove:1430
case MessageType.entityMove:1315
view?.moveEntity(message);1431
view?.moveEntity(message);1316
if (message.entityId === view?.localEntityId && message.gait)1432
if (message.entityId === view?.localEntityId)1317
{1433
{1318
gait = message.gait;1434
if (message.gait)1319
document.getElementById("gait").textContent = gait;1435
{1436
gait = message.gait;1437
document.getElementById("gait").textContent = gait;1438
}1439
closeOpenUiIfTooFar();1320
}1440
}1441
else if (1442
uiFocus?.entityId != null1443
&& message.entityId === uiFocus.entityId1444
)1445
{ closeOpenUiIfTooFar(); }1321
break;1446
break;1322
case MessageType.entityDespawn:1447
case MessageType.entityDespawn:1323
view?.despawnEntity(message.entityId);1448
view?.despawnEntity(message.entityId);@@ -1382,6 +1507,8 @@ async function main ()1382
inventory?.handleBank(message);1507
inventory?.handleBank(message);1383
break;1508
break;1384
case MessageType.cauldronSnapshot:1509
case MessageType.cauldronSnapshot:1510
if (message.open === false && uiFocus?.kind === "cauldron")1511
{ clearUiFocus(); }1385
alchemy?.handleSnapshot(message);1512
alchemy?.handleSnapshot(message);1386
break;1513
break;1387
case MessageType.pigeonDispatched:1514
case MessageType.pigeonDispatched:@@ -1436,15 +1563,21 @@ async function main ()1436
{ crafting?.openStation(message.stationId); }1563
{ crafting?.openStation(message.stationId); }1437
break;1564
break;1438
case MessageType.shopOpen:1565
case MessageType.shopOpen:1566
if (message.npcEntityId != null)1567
{ setUiFocus({ kind: "shop", entityId: message.npcEntityId | 0 }); }1439
shop?.handleShopOpen(message);1568
shop?.handleShopOpen(message);1440
break;1569
break;1441
case MessageType.shopClosed:1570
case MessageType.shopClosed:1571
if (uiFocus?.kind === "shop")1572
{ clearUiFocus(); }1442
shop?.handleShopClosed(message);1573
shop?.handleShopClosed(message);1443
break;1574
break;1444
case MessageType.marketOpen:1575
case MessageType.marketOpen:1445
market?.handleOpen(message);1576
market?.handleOpen(message);1446
break;1577
break;1447
case MessageType.marketClosed:1578
case MessageType.marketClosed:1579
if (uiFocus?.kind === "market")1580
{ clearUiFocus(); }1448
market?.handleClosed(message);1581
market?.handleClosed(message);1449
break;1582
break;1450
case MessageType.marketTrade:1583
case MessageType.marketTrade:@@ -1455,6 +1588,8 @@ async function main ()1455
bounty?.handleSnapshot(message);1588
bounty?.handleSnapshot(message);1456
break;1589
break;1457
case MessageType.closeBounty:1590
case MessageType.closeBounty:1591
if (uiFocus?.kind === "bounty")1592
{ clearUiFocus(); }1458
bounty?.handleClosed(message);1593
bounty?.handleClosed(message);1459
break;1594
break;1460
case MessageType.characterBounty:1595
case MessageType.characterBounty:@@ -1465,6 +1600,8 @@ async function main ()1465
barber?.handleSnapshot(message);1600
barber?.handleSnapshot(message);1466
break;1601
break;1467
case MessageType.closeBarber:1602
case MessageType.closeBarber:1603
if (uiFocus?.kind === "barber")1604
{ clearUiFocus(); }1468
barber?.handleClosed(message);1605
barber?.handleClosed(message);1469
break;1606
break;1470
case MessageType.itemBubble:1607
case MessageType.itemBubble:@@ -1578,12 +1715,18 @@ async function main ()1578
questsUi?.handleStepComplete(message);1715
questsUi?.handleStepComplete(message);1579
break;1716
break;1580
case MessageType.dialogueStep:1717
case MessageType.dialogueStep:1718
if (message.npcEntityId != null)1719
{ setUiFocus({ kind: "dialogue", entityId: message.npcEntityId | 0 }); }1581
dialogueUi?.handleStep(message);1720
dialogueUi?.handleStep(message);1582
break;1721
break;1583
case MessageType.dialogueChoices:1722
case MessageType.dialogueChoices:1723
if (message.npcEntityId != null)1724
{ setUiFocus({ kind: "dialogue", entityId: message.npcEntityId | 0 }); }1584
dialogueUi?.handleChoices(message);1725
dialogueUi?.handleChoices(message);1585
break;1726
break;1586
case MessageType.dialogueClose:1727
case MessageType.dialogueClose:1728
if (uiFocus?.kind === "dialogue")1729
{ clearUiFocus(); }1587
dialogueUi?.handleClose(message);1730
dialogueUi?.handleClose(message);1588
break;1731
break;1589
case MessageType.forceLogout:1732
case MessageType.forceLogout:@@ -1611,6 +1754,7 @@ function returnToMenu (reason = "")1611
{1754
{1612
playing = false;1755
playing = false;1613
clearAllPendingActions();1756
clearAllPendingActions();1757
clearUiFocus();1614
social?.reset();1758
social?.reset();1615
chat?.reset();1759
chat?.reset();1616
inventory?.reset();1760
inventory?.reset();@@ -843,6 +843,14 @@ a {
843
843
outline: 2px solid #d4c48a;
844
844
}
845
845
846
.item-slot.dragging {
847
opacity: 0.45;
848
}
849
850
.item-slot.drag-over {
851
outline: 2px solid #6a8caf;
852
}
853
846
854
.item-slot .qty {
847
855
position: absolute;
848
856
right: 2px;
@@ -843,6 +843,14 @@ a {843
outline: 2px solid #d4c48a;843
outline: 2px solid #d4c48a;844
}844
}845
845
846
.item-slot.dragging {847
opacity: 0.45;848
}849
850
.item-slot.drag-over {851
outline: 2px solid #6a8caf;852
}853
846
.item-slot .qty {854
.item-slot .qty {847
position: absolute;855
position: absolute;848
right: 2px;856
right: 2px;@@ -252,6 +252,15 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
252
252
equipSlot: message.equipSlot
253
253
});
254
254
break;
255
case MessageType.moveInventorySlot:
256
requirePlaying(session);
257
simulation.enqueue(session.id, {
258
type: "move-inventory-slot",
259
characterId: session.characterId,
260
fromSlotIndex: message.fromSlotIndex | 0,
261
toSlotIndex: message.toSlotIndex | 0
262
});
263
break;
255
264
case MessageType.eatItem:
256
265
requirePlaying(session);
257
266
simulation.enqueue(session.id, {
@@ -252,6 +252,15 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,252
equipSlot: message.equipSlot252
equipSlot: message.equipSlot253
});253
});254
break;254
break;255
case MessageType.moveInventorySlot:256
requirePlaying(session);257
simulation.enqueue(session.id, {258
type: "move-inventory-slot",259
characterId: session.characterId,260
fromSlotIndex: message.fromSlotIndex | 0,261
toSlotIndex: message.toSlotIndex | 0262
});263
break;255
case MessageType.eatItem:264
case MessageType.eatItem:256
requirePlaying(session);265
requirePlaying(session);257
simulation.enqueue(session.id, {266
simulation.enqueue(session.id, {@@ -5,39 +5,44 @@ import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";
5
5
import { stackRulesFor } from "../../../shared/items/stackRules.js";
6
6
import { BlockType } from "../../../shared/definitions/tiles.js";
7
7
import { ItemId, itemDefinition, itemSpriteName, stackDisplayLabel, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";
8
import {
9
emptyEquipment,
10
emptySlots,
11
insertStack,
12
insertStackGrowable,
13
normalizeVault,
14
normalizeInventorySlots,
15
publicEquipment,
16
publicSlots,
17
takeFromSlot,
18
takeMatchingFromSlots,
19
countItemInSlots,
20
cloneStack,
21
singleItemFromStack,
22
stackQuantity,
23
consumeFillCharge
24
} from "../../../shared/items/inventory.js";
8
import
9
{
10
emptyEquipment,
11
emptySlots,
12
insertStack,
13
insertStackGrowable,
14
normalizeVault,
15
normalizeInventorySlots,
16
publicEquipment,
17
publicSlots,
18
takeFromSlot,
19
takeMatchingFromSlots,
20
countItemInSlots,
21
cloneStack,
22
singleItemFromStack,
23
stackQuantity,
24
consumeFillCharge,
25
moveInventorySlot
26
} from "../../../shared/items/inventory.js";
25
27
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";
26
28
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
27
29
import { randomUUID } from "node:crypto";
28
30
import { tileShoveTowardBlock } from "../simulation/tileInteract.js";
29
31
import { resolvePotionEffect } from "../../../shared/alchemy/recipes.js";
30
import {
31
applyStatusEffect,
32
emptyStatusEffects,
33
StatusEffectType
34
} from "../../../shared/statusEffects/rules.js";
35
import {
36
attachOrigins,
37
writtenOrigin,
38
bankIssuedOrigin,
39
normalizeOrigins
40
} from "../../../shared/items/origin.js";
32
import
33
{
34
applyStatusEffect,
35
emptyStatusEffects,
36
StatusEffectType
37
} from "../../../shared/statusEffects/rules.js";
38
import
39
{
40
attachOrigins,
41
writtenOrigin,
42
bankIssuedOrigin,
43
normalizeOrigins,
44
mergeOriginLists
45
} from "../../../shared/items/origin.js";
41
46
import { BANK_LETTER_AUTHOR } from "../../../shared/courier/systemLetters.js";
42
47
import { canCharacterPickupGroundItem } from "../../../shared/items/letters.js";
43
48
@@ -71,6 +76,47 @@ export function bagView (ecs, handle)
71
76
};
72
77
}
73
78
79
/** Remove all coin stacks from the bag for death drops. Anyone may pick them up. */
80
export function stripCarriedCoinsForDeath (world, characterId)
81
{
82
const entityId = world.characterEntities.get(characterId);
83
if (entityId == null)
84
{ return { stack: null, private: null }; }
85
const handle = world.ecs.handleOf(entityId);
86
if (handle == null)
87
{ return { stack: null, private: null }; }
88
const inventory = ensureInventory(world.ecs, handle);
89
let total = 0;
90
let origins = [];
91
const next = inventory.slots.map(cloneStack);
92
for (let i = 0; i < next.length; i++)
93
{
94
const slot = next[i];
95
if (!slot || (slot.itemId | 0) !== ItemId.coins)
96
{ continue; }
97
const qty = stackQuantity(slot.quantity);
98
if (qty <= 0)
99
{
100
next[i] = null;
101
continue;
102
}
103
total += qty;
104
origins = mergeOriginLists(origins, normalizeOrigins(slot));
105
next[i] = null;
106
}
107
if (total <= 0)
108
{ return { stack: null, private: null }; }
109
inventory.slots = next;
110
return {
111
stack: attachOrigins({
112
itemId: ItemId.coins,
113
quantity: total,
114
origins
115
}),
116
private: bagView(world.ecs, handle)
117
};
118
}
119
74
120
export function applyBagView (ecs, handle, bag)
75
121
{
76
122
const inventory = ensureInventory(ecs, handle);
@@ -101,6 +147,8 @@ export function handleItemCommand (world, sessionId, command, now)
101
147
return equipItem(world, sessionId, command);
102
148
case "unequip-item":
103
149
return unequipItem(world, sessionId, command);
150
case "move-inventory-slot":
151
return moveInventorySlotCommand(world, sessionId, command);
104
152
case "open-bank":
105
153
return openBank(world, sessionId, command);
106
154
case "bank-deposit":
@@ -392,6 +440,24 @@ function unequipItem (world, sessionId, command)
392
440
return { events: [], private: bagView(world.ecs, handle), appearanceChanged };
393
441
}
394
442
443
function moveInventorySlotCommand (world, sessionId, command)
444
{
445
const { handle } = world.requireOwnedEntity(sessionId, command.characterId);
446
if (world.ecs.has(handle, Component.dead))
447
{ throw userError("You are dead."); }
448
const inventory = ensureInventory(world.ecs, handle);
449
const moved = moveInventorySlot(
450
inventory.slots,
451
command.fromSlotIndex,
452
command.toSlotIndex
453
);
454
if (!moved.ok)
455
{ throw userError(moved.reason ?? "Could not move that item."); }
456
if (moved.changed)
457
{ inventory.slots = moved.slots; }
458
return { events: [], private: bagView(world.ecs, handle) };
459
}
460
395
461
function eatItem (world, sessionId, command)
396
462
{
397
463
const { handle } = world.requireOwnedEntity(sessionId, command.characterId);
@@ -5,39 +5,44 @@ import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";5
import { stackRulesFor } from "../../../shared/items/stackRules.js";5
import { stackRulesFor } from "../../../shared/items/stackRules.js";6
import { BlockType } from "../../../shared/definitions/tiles.js";6
import { BlockType } from "../../../shared/definitions/tiles.js";7
import { ItemId, itemDefinition, itemSpriteName, stackDisplayLabel, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";7
import { ItemId, itemDefinition, itemSpriteName, stackDisplayLabel, LETTER_MAX_BODY_CHARS, BLANK_CHEQUE_CARRY_CAP } from "../../../shared/definitions/items.js";8
import {8
import9
emptyEquipment,9
{10
emptySlots,10
emptyEquipment,11
insertStack,11
emptySlots,12
insertStackGrowable,12
insertStack,13
normalizeVault,13
insertStackGrowable,14
normalizeInventorySlots,14
normalizeVault,15
publicEquipment,15
normalizeInventorySlots,16
publicSlots,16
publicEquipment,17
takeFromSlot,17
publicSlots,18
takeMatchingFromSlots,18
takeFromSlot,19
countItemInSlots,19
takeMatchingFromSlots,20
cloneStack,20
countItemInSlots,21
singleItemFromStack,21
cloneStack,22
stackQuantity,22
singleItemFromStack,23
consumeFillCharge23
stackQuantity,24
} from "../../../shared/items/inventory.js";24
consumeFillCharge,25
moveInventorySlot26
} from "../../../shared/items/inventory.js";25
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";27
import { tileKey, tileToChunk, tileToLocal } from "../world/coordinates.js";26
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";28
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";27
import { randomUUID } from "node:crypto";29
import { randomUUID } from "node:crypto";28
import { tileShoveTowardBlock } from "../simulation/tileInteract.js";30
import { tileShoveTowardBlock } from "../simulation/tileInteract.js";29
import { resolvePotionEffect } from "../../../shared/alchemy/recipes.js";31
import { resolvePotionEffect } from "../../../shared/alchemy/recipes.js";30
import {32
import31
applyStatusEffect,33
{32
emptyStatusEffects,34
applyStatusEffect,33
StatusEffectType35
emptyStatusEffects,34
} from "../../../shared/statusEffects/rules.js";36
StatusEffectType35
import {37
} from "../../../shared/statusEffects/rules.js";36
attachOrigins,38
import37
writtenOrigin,39
{38
bankIssuedOrigin,40
attachOrigins,39
normalizeOrigins41
writtenOrigin,40
} from "../../../shared/items/origin.js";42
bankIssuedOrigin,43
normalizeOrigins,44
mergeOriginLists45
} from "../../../shared/items/origin.js";41
import { BANK_LETTER_AUTHOR } from "../../../shared/courier/systemLetters.js";46
import { BANK_LETTER_AUTHOR } from "../../../shared/courier/systemLetters.js";42
import { canCharacterPickupGroundItem } from "../../../shared/items/letters.js";47
import { canCharacterPickupGroundItem } from "../../../shared/items/letters.js";43
48
@@ -71,6 +76,47 @@ export function bagView (ecs, handle)71
};76
};72
}77
}73
78
79
/** Remove all coin stacks from the bag for death drops. Anyone may pick them up. */80
export function stripCarriedCoinsForDeath (world, characterId)81
{82
const entityId = world.characterEntities.get(characterId);83
if (entityId == null)84
{ return { stack: null, private: null }; }85
const handle = world.ecs.handleOf(entityId);86
if (handle == null)87
{ return { stack: null, private: null }; }88
const inventory = ensureInventory(world.ecs, handle);89
let total = 0;90
let origins = [];91
const next = inventory.slots.map(cloneStack);92
for (let i = 0; i < next.length; i++)93
{94
const slot = next[i];95
if (!slot || (slot.itemId | 0) !== ItemId.coins)96
{ continue; }97
const qty = stackQuantity(slot.quantity);98
if (qty <= 0)99
{100
next[i] = null;101
continue;102
}103
total += qty;104
origins = mergeOriginLists(origins, normalizeOrigins(slot));105
next[i] = null;106
}107
if (total <= 0)108
{ return { stack: null, private: null }; }109
inventory.slots = next;110
return {111
stack: attachOrigins({112
itemId: ItemId.coins,113
quantity: total,114
origins115
}),116
private: bagView(world.ecs, handle)117
};118
}119
74
export function applyBagView (ecs, handle, bag)120
export function applyBagView (ecs, handle, bag)75
{121
{76
const inventory = ensureInventory(ecs, handle);122
const inventory = ensureInventory(ecs, handle);@@ -101,6 +147,8 @@ export function handleItemCommand (world, sessionId, command, now)101
return equipItem(world, sessionId, command);147
return equipItem(world, sessionId, command);102
case "unequip-item":148
case "unequip-item":103
return unequipItem(world, sessionId, command);149
return unequipItem(world, sessionId, command);150
case "move-inventory-slot":151
return moveInventorySlotCommand(world, sessionId, command);104
case "open-bank":152
case "open-bank":105
return openBank(world, sessionId, command);153
return openBank(world, sessionId, command);106
case "bank-deposit":154
case "bank-deposit":@@ -392,6 +440,24 @@ function unequipItem (world, sessionId, command)392
return { events: [], private: bagView(world.ecs, handle), appearanceChanged };440
return { events: [], private: bagView(world.ecs, handle), appearanceChanged };393
}441
}394
442
443
function moveInventorySlotCommand (world, sessionId, command)444
{445
const { handle } = world.requireOwnedEntity(sessionId, command.characterId);446
if (world.ecs.has(handle, Component.dead))447
{ throw userError("You are dead."); }448
const inventory = ensureInventory(world.ecs, handle);449
const moved = moveInventorySlot(450
inventory.slots,451
command.fromSlotIndex,452
command.toSlotIndex453
);454
if (!moved.ok)455
{ throw userError(moved.reason ?? "Could not move that item."); }456
if (moved.changed)457
{ inventory.slots = moved.slots; }458
return { events: [], private: bagView(world.ecs, handle) };459
}460
395
function eatItem (world, sessionId, command)461
function eatItem (world, sessionId, command)396
{462
{397
const { handle } = world.requireOwnedEntity(sessionId, command.characterId);463
const { handle } = world.requireOwnedEntity(sessionId, command.characterId);@@ -1680,6 +1680,8 @@ export class Simulation
1680
1680
tileX: event.tileX,
1681
1681
tileY: event.tileY,
1682
1682
now: this.now,
1683
dropCarriedCoins: true,
1684
coinGroundItemId: this.nextGroundItemId++,
1683
1685
drops: [
1684
1686
{
1685
1687
groundItemId: this.nextGroundItemId++,
@@ -1705,6 +1707,18 @@ export class Simulation
1705
1707
this.#persistGroundEvent(dropEvent);
1706
1708
events.push(dropEvent);
1707
1709
}
1710
if (result?.private)
1711
{
1712
this.#saveBagFromView(event.characterId, result.private);
1713
if (event.sessionId != null)
1714
{
1715
events.push({
1716
type: "inventory",
1717
sessionId: event.sessionId,
1718
...result.private
1719
});
1720
}
1721
}
1708
1722
return events;
1709
1723
}
1710
1724
@@ -1680,6 +1680,8 @@ export class Simulation1680
tileX: event.tileX,1680
tileX: event.tileX,1681
tileY: event.tileY,1681
tileY: event.tileY,1682
now: this.now,1682
now: this.now,1683
dropCarriedCoins: true,1684
coinGroundItemId: this.nextGroundItemId++,1683
drops: [1685
drops: [1684
{1686
{1685
groundItemId: this.nextGroundItemId++,1687
groundItemId: this.nextGroundItemId++,@@ -1705,6 +1707,18 @@ export class Simulation1705
this.#persistGroundEvent(dropEvent);1707
this.#persistGroundEvent(dropEvent);1706
events.push(dropEvent);1708
events.push(dropEvent);1707
}1709
}1710
if (result?.private)1711
{1712
this.#saveBagFromView(event.characterId, result.private);1713
if (event.sessionId != null)1714
{1715
events.push({1716
type: "inventory",1717
sessionId: event.sessionId,1718
...result.private1719
});1720
}1721
}1708
return events;1722
return events;1709
}1723
}1710
1724
@@ -29,7 +29,8 @@ import {
29
29
handleItemCommand,
30
30
removeGroundItem,
31
31
publicGroundItem,
32
setGroundItemsForRegion
32
setGroundItemsForRegion,
33
stripCarriedCoinsForDeath
33
34
} from "../items/bags.js";
34
35
import { handleSpellCommand, processSpellImpacts, stepPendingSpellCast, stepSpellAutoCast, tickSpellLights } from "../spells/service.js";
35
36
import { publicSpellsView } from "../../../shared/spells/state.js";
@@ -495,7 +496,21 @@ export class WorkerWorld
495
496
#spawnCorpseDrops (message)
496
497
{
497
498
const events = [];
498
for (const drop of message.drops ?? [])
499
const drops = [...(message.drops ?? [])];
500
let privateBag = null;
501
if (message.dropCarriedCoins)
502
{
503
const stripped = stripCarriedCoinsForDeath(this, message.characterId);
504
privateBag = stripped.private;
505
if (stripped.stack && message.coinGroundItemId != null)
506
{
507
drops.push({
508
groundItemId: message.coinGroundItemId,
509
stack: stripped.stack
510
});
511
}
512
}
513
for (const drop of drops)
499
514
{
500
515
const stack = drop.stack ?? { itemId: drop.itemId, quantity: 1 };
501
516
const item = {
@@ -519,7 +534,7 @@ export class WorkerWorld
519
534
expiresAt: item.expiresAt
520
535
});
521
536
}
522
return { events };
537
return { events, private: privateBag };
523
538
}
524
539
525
540
#applyRespawn (message)
@@ -29,7 +29,8 @@ import {29
handleItemCommand,29
handleItemCommand,30
removeGroundItem,30
removeGroundItem,31
publicGroundItem,31
publicGroundItem,32
setGroundItemsForRegion32
setGroundItemsForRegion,33
stripCarriedCoinsForDeath33
} from "../items/bags.js";34
} from "../items/bags.js";34
import { handleSpellCommand, processSpellImpacts, stepPendingSpellCast, stepSpellAutoCast, tickSpellLights } from "../spells/service.js";35
import { handleSpellCommand, processSpellImpacts, stepPendingSpellCast, stepSpellAutoCast, tickSpellLights } from "../spells/service.js";35
import { publicSpellsView } from "../../../shared/spells/state.js";36
import { publicSpellsView } from "../../../shared/spells/state.js";@@ -495,7 +496,21 @@ export class WorkerWorld495
#spawnCorpseDrops (message)496
#spawnCorpseDrops (message)496
{497
{497
const events = [];498
const events = [];498
for (const drop of message.drops ?? [])499
const drops = [...(message.drops ?? [])];500
let privateBag = null;501
if (message.dropCarriedCoins)502
{503
const stripped = stripCarriedCoinsForDeath(this, message.characterId);504
privateBag = stripped.private;505
if (stripped.stack && message.coinGroundItemId != null)506
{507
drops.push({508
groundItemId: message.coinGroundItemId,509
stack: stripped.stack510
});511
}512
}513
for (const drop of drops)499
{514
{500
const stack = drop.stack ?? { itemId: drop.itemId, quantity: 1 };515
const stack = drop.stack ?? { itemId: drop.itemId, quantity: 1 };501
const item = {516
const item = {@@ -519,7 +534,7 @@ export class WorkerWorld519
expiresAt: item.expiresAt534
expiresAt: item.expiresAt520
});535
});521
}536
}522
return { events };537
return { events, private: privateBag };523
}538
}524
539
525
#applyRespawn (message)540
#applyRespawn (message)@@ -7,6 +7,7 @@ import { MobId } from "../../shared/definitions/mobs.js";
7
7
import { mobComponents } from "../src/simulation/spawners.js";
8
8
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";
9
9
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
10
import { emptyEquipment, emptySlots, addCoinsToSlots, countCoinsInSlots } from "../../shared/items/inventory.js";
10
11
11
12
function componentsOf (simulation, entityId)
12
13
{
@@ -92,9 +93,46 @@ test("player death marks dead and drops bones and skull", () =>
92
93
assert.ok(componentsOf(harness.simulation, playerId)[Component.dead]);
93
94
assert.equal(harness.stateDb.getCharacter(character.character_id).is_dead, 1);
94
95
const drops = harness.stateDb.listGroundItemsInRegion(0, 0, 63, 63);
96
const itemIds = drops.map((item) => item.stack.itemId);
97
assert.ok(itemIds.includes(ItemId.bones));
98
assert.ok(itemIds.includes(ItemId.skull));
99
const bag = harness.simulation.bagOf(playerId);
100
assert.equal(countCoinsInSlots(bag.inventory), 0);
101
}
102
finally
103
{ harness.close(); }
104
});
105
});
106
107
test("player death drops all carried coins for anyone to pick up", () =>
108
{
109
withDeterministicCombat(() =>
110
{
111
const harness = makeSimulation({ workerCount: 1 });
112
try
113
{
114
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
115
const funded = addCoinsToSlots(emptySlots(), 250);
116
assert.equal(funded.ok, true);
117
harness.stateDb.saveBag(character.character_id, {
118
inventory: funded.slots,
119
equipment: emptyEquipment(),
120
vault: [],
121
vaultReserved: []
122
});
123
const playerId = harness.simulation.spawnCharacter(1, character);
124
assert.equal(countCoinsInSlots(harness.simulation.bagOf(playerId).inventory), 250);
125
killPlayer(harness, character, playerId);
126
const bag = harness.simulation.bagOf(playerId);
127
assert.equal(countCoinsInSlots(bag.inventory), 0);
128
const drops = harness.stateDb.listGroundItemsInRegion(0, 0, 63, 63);
129
const coinDrop = drops.find((item) => item.stack.itemId === ItemId.coins);
130
assert.ok(coinDrop);
131
assert.equal(coinDrop.stack.quantity, 250);
132
assert.equal(coinDrop.source, "player-death");
95
133
assert.deepEqual(
96
134
drops.map((item) => item.stack.itemId).sort((a, b) => a - b),
97
[ItemId.bones, ItemId.skull]
135
[ItemId.coins, ItemId.bones, ItemId.skull].sort((a, b) => a - b)
98
136
);
99
137
}
100
138
finally
@@ -7,6 +7,7 @@ import { MobId } from "../../shared/definitions/mobs.js";7
import { mobComponents } from "../src/simulation/spawners.js";7
import { mobComponents } from "../src/simulation/spawners.js";8
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";8
import { createEmptyChunkData, encodeChunkBlob } from "../src/world/chunkData.js";9
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";9
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";10
import { emptyEquipment, emptySlots, addCoinsToSlots, countCoinsInSlots } from "../../shared/items/inventory.js";10
11
11
function componentsOf (simulation, entityId)12
function componentsOf (simulation, entityId)12
{13
{@@ -92,9 +93,46 @@ test("player death marks dead and drops bones and skull", () =>92
assert.ok(componentsOf(harness.simulation, playerId)[Component.dead]);93
assert.ok(componentsOf(harness.simulation, playerId)[Component.dead]);93
assert.equal(harness.stateDb.getCharacter(character.character_id).is_dead, 1);94
assert.equal(harness.stateDb.getCharacter(character.character_id).is_dead, 1);94
const drops = harness.stateDb.listGroundItemsInRegion(0, 0, 63, 63);95
const drops = harness.stateDb.listGroundItemsInRegion(0, 0, 63, 63);96
const itemIds = drops.map((item) => item.stack.itemId);97
assert.ok(itemIds.includes(ItemId.bones));98
assert.ok(itemIds.includes(ItemId.skull));99
const bag = harness.simulation.bagOf(playerId);100
assert.equal(countCoinsInSlots(bag.inventory), 0);101
}102
finally103
{ harness.close(); }104
});105
});106
107
test("player death drops all carried coins for anyone to pick up", () =>108
{109
withDeterministicCombat(() =>110
{111
const harness = makeSimulation({ workerCount: 1 });112
try113
{114
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });115
const funded = addCoinsToSlots(emptySlots(), 250);116
assert.equal(funded.ok, true);117
harness.stateDb.saveBag(character.character_id, {118
inventory: funded.slots,119
equipment: emptyEquipment(),120
vault: [],121
vaultReserved: []122
});123
const playerId = harness.simulation.spawnCharacter(1, character);124
assert.equal(countCoinsInSlots(harness.simulation.bagOf(playerId).inventory), 250);125
killPlayer(harness, character, playerId);126
const bag = harness.simulation.bagOf(playerId);127
assert.equal(countCoinsInSlots(bag.inventory), 0);128
const drops = harness.stateDb.listGroundItemsInRegion(0, 0, 63, 63);129
const coinDrop = drops.find((item) => item.stack.itemId === ItemId.coins);130
assert.ok(coinDrop);131
assert.equal(coinDrop.stack.quantity, 250);132
assert.equal(coinDrop.source, "player-death");95
assert.deepEqual(133
assert.deepEqual(96
drops.map((item) => item.stack.itemId).sort((a, b) => a - b),134
drops.map((item) => item.stack.itemId).sort((a, b) => a - b),97
[ItemId.bones, ItemId.skull]135
[ItemId.coins, ItemId.bones, ItemId.skull].sort((a, b) => a - b)98
);136
);99
}137
}100
finally138
finally@@ -1,15 +1,23 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import { emptyEquipment, emptySlots, insertStack, takeFromSlot } from "../../shared/items/inventory.js";
3
import
4
{
5
emptyEquipment,
6
emptySlots,
7
insertStack,
8
moveInventorySlot,
9
takeFromSlot
10
} from "../../shared/items/inventory.js";
4
11
import { ItemOriginKind } from "../../shared/items/origin.js";
5
12
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
6
13
import { Component } from "../src/ecs/components.js";
7
14
import { encodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";
8
import {
9
makeCharacter,
10
makeSimulation,
11
stepTimes
12
} from "./helpers/simulationHarness.js";
15
import
16
{
17
makeCharacter,
18
makeSimulation,
19
stepTimes
20
} from "./helpers/simulationHarness.js";
13
21
14
22
function workerOf (simulation, entityId)
15
23
{
@@ -33,6 +41,59 @@ test("stackable items merge until max stack then need a new slot", () =>
33
41
assert.equal(taken.slots[0].quantity, 70);
34
42
});
35
43
44
test("moveInventorySlot moves, swaps, and merges stacks", () =>
45
{
46
const def = itemDefinition(ItemId.apple);
47
let slots = emptySlots();
48
slots = insertStack(slots, { itemId: ItemId.apple, quantity: 5 }, def).slots;
49
slots[3] = { itemId: ItemId.paper, quantity: 1 };
50
const moved = moveInventorySlot(slots, 0, 2);
51
assert.equal(moved.ok, true);
52
assert.equal(moved.slots[0], null);
53
assert.equal(moved.slots[2]?.itemId, ItemId.apple);
54
assert.equal(moved.slots[2]?.quantity, 5);
55
56
const swapped = moveInventorySlot(moved.slots, 2, 3);
57
assert.equal(swapped.slots[2]?.itemId, ItemId.paper);
58
assert.equal(swapped.slots[3]?.itemId, ItemId.apple);
59
60
slots = emptySlots();
61
slots[0] = { itemId: ItemId.apple, quantity: 10 };
62
slots[1] = { itemId: ItemId.apple, quantity: 5 };
63
const merged = moveInventorySlot(slots, 0, 1);
64
assert.equal(merged.ok, true);
65
assert.equal(merged.slots[0], null);
66
assert.equal(merged.slots[1]?.quantity, 15);
67
});
68
69
test("player can rearrange bag slots via move-inventory-slot", () =>
70
{
71
const harness = makeSimulation({ workerCount: 1 });
72
try
73
{
74
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
75
const entityId = harness.simulation.spawnCharacter(1, character);
76
const bag = harness.simulation.bagOf(entityId);
77
const appleSlot = bag.inventory.findIndex((slot) => slot?.itemId === ItemId.apple);
78
assert.ok(appleSlot >= 0);
79
const emptySlot = bag.inventory.findIndex((slot) => !slot);
80
assert.ok(emptySlot >= 0);
81
harness.simulation.enqueue(1, {
82
type: "move-inventory-slot",
83
characterId: character.character_id,
84
fromSlotIndex: appleSlot,
85
toSlotIndex: emptySlot
86
});
87
const stepped = harness.simulation.step();
88
assert.equal(stepped.events.some((event) => event.type === "command-error"), false);
89
const after = harness.simulation.bagOf(entityId);
90
assert.equal(after.inventory[appleSlot], null);
91
assert.equal(after.inventory[emptySlot]?.itemId, ItemId.apple);
92
}
93
finally
94
{ harness.close(); }
95
});
96
36
97
test("a player can drop and pick up an item on their tile", () =>
37
98
{
38
99
const harness = makeSimulation({ workerCount: 1 });
@@ -1,15 +1,23 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { emptyEquipment, emptySlots, insertStack, takeFromSlot } from "../../shared/items/inventory.js";3
import4
{5
emptyEquipment,6
emptySlots,7
insertStack,8
moveInventorySlot,9
takeFromSlot10
} from "../../shared/items/inventory.js";4
import { ItemOriginKind } from "../../shared/items/origin.js";11
import { ItemOriginKind } from "../../shared/items/origin.js";5
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";12
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";6
import { Component } from "../src/ecs/components.js";13
import { Component } from "../src/ecs/components.js";7
import { encodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";14
import { encodeChunkBlob, createEmptyChunkData } from "../src/world/chunkData.js";8
import {15
import9
makeCharacter,16
{10
makeSimulation,17
makeCharacter,11
stepTimes18
makeSimulation,12
} from "./helpers/simulationHarness.js";19
stepTimes20
} from "./helpers/simulationHarness.js";13
21
14
function workerOf (simulation, entityId)22
function workerOf (simulation, entityId)15
{23
{@@ -33,6 +41,59 @@ test("stackable items merge until max stack then need a new slot", () =>33
assert.equal(taken.slots[0].quantity, 70);41
assert.equal(taken.slots[0].quantity, 70);34
});42
});35
43
44
test("moveInventorySlot moves, swaps, and merges stacks", () =>45
{46
const def = itemDefinition(ItemId.apple);47
let slots = emptySlots();48
slots = insertStack(slots, { itemId: ItemId.apple, quantity: 5 }, def).slots;49
slots[3] = { itemId: ItemId.paper, quantity: 1 };50
const moved = moveInventorySlot(slots, 0, 2);51
assert.equal(moved.ok, true);52
assert.equal(moved.slots[0], null);53
assert.equal(moved.slots[2]?.itemId, ItemId.apple);54
assert.equal(moved.slots[2]?.quantity, 5);55
56
const swapped = moveInventorySlot(moved.slots, 2, 3);57
assert.equal(swapped.slots[2]?.itemId, ItemId.paper);58
assert.equal(swapped.slots[3]?.itemId, ItemId.apple);59
60
slots = emptySlots();61
slots[0] = { itemId: ItemId.apple, quantity: 10 };62
slots[1] = { itemId: ItemId.apple, quantity: 5 };63
const merged = moveInventorySlot(slots, 0, 1);64
assert.equal(merged.ok, true);65
assert.equal(merged.slots[0], null);66
assert.equal(merged.slots[1]?.quantity, 15);67
});68
69
test("player can rearrange bag slots via move-inventory-slot", () =>70
{71
const harness = makeSimulation({ workerCount: 1 });72
try73
{74
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });75
const entityId = harness.simulation.spawnCharacter(1, character);76
const bag = harness.simulation.bagOf(entityId);77
const appleSlot = bag.inventory.findIndex((slot) => slot?.itemId === ItemId.apple);78
assert.ok(appleSlot >= 0);79
const emptySlot = bag.inventory.findIndex((slot) => !slot);80
assert.ok(emptySlot >= 0);81
harness.simulation.enqueue(1, {82
type: "move-inventory-slot",83
characterId: character.character_id,84
fromSlotIndex: appleSlot,85
toSlotIndex: emptySlot86
});87
const stepped = harness.simulation.step();88
assert.equal(stepped.events.some((event) => event.type === "command-error"), false);89
const after = harness.simulation.bagOf(entityId);90
assert.equal(after.inventory[appleSlot], null);91
assert.equal(after.inventory[emptySlot]?.itemId, ItemId.apple);92
}93
finally94
{ harness.close(); }95
});96
36
test("a player can drop and pick up an item on their tile", () =>97
test("a player can drop and pick up an item on their tile", () =>37
{98
{38
const harness = makeSimulation({ workerCount: 1 });99
const harness = makeSimulation({ workerCount: 1 });