BlueGit

timfa questward

Add swords, damage affinities, sprites, tipped arrows, and elemental spell trees.

Craftable swords with dual metal/leather tint, mob weakness/resistance by damage type, elemental sprite mobs with essence drops, alchemy arrow coatings with tip UI and triple-channel tint, and replace Spark with full damage ladders for all seven magic elements.

timfa Tim Falken · pushed by timfa

Authored 2026-08-29 · 2 months ago

Hash
6d82116b402529e6e7e16d4333067345a2b3c7d6
Parent
2b6e44d0
73 files changed +1918 −192
client/assets/fx/projectile/arrow-tipped.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/fx/projectile/arrow.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/arrow/tipped-arrow.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/sword/sword-blade.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/sword/sword-equip.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/items/sword/sword.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/mobs/sprite/sprite-bloom.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/mobs/sprite/sprite.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/spells/airbolt.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#90b8d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">AB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#90b8d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">AB</text>
4</svg>
client/assets/spells/blight.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#48a838"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">BL</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#48a838"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">BL</text>
4</svg>
client/assets/spells/boulder.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#8a6a38"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">BO</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#8a6a38"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">BO</text>
4</svg>
client/assets/spells/cataclysm.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#8a6a38"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">CA</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#8a6a38"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">CA</text>
4</svg>
client/assets/spells/cyclone.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#90b8d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">CY</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#90b8d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">CY</text>
4</svg>
client/assets/spells/darkbolt.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#5a3878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">DB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#5a3878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">DB</text>
4</svg>
client/assets/spells/deluge.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#4080d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">DE</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#4080d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">DE</text>
4</svg>
client/assets/spells/earthbolt.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#8a6a38"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">EB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#8a6a38"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">EB</text>
4</svg>
client/assets/spells/eclipse.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#5a3878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">EC</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#5a3878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">EC</text>
4</svg>
client/assets/spells/flare.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#e8d878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">FL</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#e8d878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">FL</text>
4</svg>
client/assets/spells/gale.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#90b8d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">GA</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#90b8d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">GA</text>
4</svg>
client/assets/spells/gloom.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#5a3878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">GL</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#5a3878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">GL</text>
4</svg>
client/assets/spells/hurricane.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#90b8d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">HU</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#90b8d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">HU</text>
4</svg>
client/assets/spells/judgment.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#e8d878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">JU</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#e8d878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">JU</text>
4</svg>
client/assets/spells/landslide.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#8a6a38"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">LS</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#8a6a38"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">LS</text>
4</svg>
client/assets/spells/lightbolt.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#e8d878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">LB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#e8d878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">LB</text>
4</svg>
client/assets/spells/maelstrom.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#4080d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">MA</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#4080d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">MA</text>
4</svg>
client/assets/spells/oblivion.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#5a3878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">OB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#5a3878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">OB</text>
4</svg>
client/assets/spells/plague.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#48a838"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">PL</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#48a838"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">PL</text>
4</svg>
client/assets/spells/poisonbolt.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#48a838"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">PB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#48a838"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">PB</text>
4</svg>
client/assets/spells/quake.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#8a6a38"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">QU</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#8a6a38"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">QU</text>
4</svg>
client/assets/spells/radiance.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#e8d878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">RA</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#e8d878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">RA</text>
4</svg>
client/assets/spells/sunbeam.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#e8d878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">SB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#e8d878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">SB</text>
4</svg>
client/assets/spells/tempest.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#90b8d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">TE</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#90b8d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">TE</text>
4</svg>
client/assets/spells/torrent.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#4080d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">TO</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#4080d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">TO</text>
4</svg>
client/assets/spells/toxinburst.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#48a838"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">TX</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#48a838"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">TX</text>
4</svg>
client/assets/spells/venomcloud.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#48a838"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">VC</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#48a838"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">VC</text>
4</svg>
client/assets/spells/voidlance.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#5a3878"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">VL</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#5a3878"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">VL</text>
4</svg>
client/assets/spells/waterbolt.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#4080d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">WB</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#4080d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">WB</text>
4</svg>
client/assets/spells/waterspout.svg added +4 −0
@@ -0,0 +1,4 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2 <rect width="32" height="32" rx="6" fill="#4080d0"/>
3 <text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">WS</text>
4 </svg>
@@ -0,0 +1,4 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2<rect width="32" height="32" rx="6" fill="#4080d0"/>
3<text x="16" y="21" text-anchor="middle" fill="#f0ece0" font-size="11" font-family="Segoe UI,sans-serif" font-weight="600">WS</text>
4</svg>
client/src/editor/tileConfigModal.js +4 −1
@@ -820,7 +820,8 @@ export function initTileConfigModal ({
820 820 addBtn.addEventListener("click", () =>
821 821 {
822 822 const available = Object.values(SPELL_DEFINITIONS).find((def) =>
823 !spellsDraft.some((line) => line.spellId === def.spellId));
823 !def.mobOnly
824 && !spellsDraft.some((line) => line.spellId === def.spellId));
824 825 if (!available)
825 826 { return; }
826 827 spellsDraft.push({ spellId: available.spellId });
@@ -875,6 +876,8 @@ export function initTileConfigModal ({
875 876 const select = document.createElement("select");
876 877 for (const spell of Object.values(SPELL_DEFINITIONS))
877 878 {
879 if (spell.mobOnly)
880 { continue; }
878 881 const opt = document.createElement("option");
879 882 opt.value = spell.spellId;
880 883 const minLv = spell.minMagicLevel | 0 || 1;
@@ -820,7 +820,8 @@ export function initTileConfigModal ({
820 addBtn.addEventListener("click", () =>
820 addBtn.addEventListener("click", () =>
821 {
821 {
822 const available = Object.values(SPELL_DEFINITIONS).find((def) =>
822 const available = Object.values(SPELL_DEFINITIONS).find((def) =>
823 !spellsDraft.some((line) => line.spellId === def.spellId));
823 !def.mobOnly
824 && !spellsDraft.some((line) => line.spellId === def.spellId));
824 if (!available)
825 if (!available)
825 { return; }
826 { return; }
826 spellsDraft.push({ spellId: available.spellId });
827 spellsDraft.push({ spellId: available.spellId });
@@ -875,6 +876,8 @@ export function initTileConfigModal ({
875 const select = document.createElement("select");
876 const select = document.createElement("select");
876 for (const spell of Object.values(SPELL_DEFINITIONS))
877 for (const spell of Object.values(SPELL_DEFINITIONS))
877 {
878 {
879 if (spell.mobOnly)
880 { continue; }
878 const opt = document.createElement("option");
881 const opt = document.createElement("option");
879 opt.value = spell.spellId;
882 opt.value = spell.spellId;
880 const minLv = spell.minMagicLevel | 0 || 1;
883 const minLv = spell.minMagicLevel | 0 || 1;
client/src/play/inventory.js +23 −5
@@ -28,7 +28,8 @@ export function initInventory ({
28 28 contextMenu,
29 29 resolveSpriteUrl,
30 30 getFriends,
31 getLocalName
31 getLocalName,
32 tipArrows = null
32 33 })
33 34 {
34 35 const bagPanel = document.getElementById("bag-panel");
@@ -379,10 +380,20 @@ export function initInventory ({
379 380 }
380 381 if (slot.itemId === ItemId.potion && slot.instance?.kind === "potion")
381 382 {
382 items.push({
383 label: "Drink",
384 onSelect: () => socket.send({ type: MessageType.drinkItem, slotIndex })
385 });
383 if (tipArrows?.isArrowCoatingPotion?.(slot))
384 {
385 items.push({
386 label: "Apply to arrows",
387 onSelect: () => tipArrows.open(slotIndex)
388 });
389 }
390 else
391 {
392 items.push({
393 label: "Drink",
394 onSelect: () => socket.send({ type: MessageType.drinkItem, slotIndex })
395 });
396 }
386 397 }
387 398 items.push({
388 399 label: "Drop",
@@ -971,6 +982,13 @@ export function initInventory ({
971 982 {
972 983 return bag.inventory ?? [];
973 984 },
985 getBag ()
986 {
987 return {
988 slots: bag.inventory ?? [],
989 equipment: bag.equipment ?? null
990 };
991 },
974 992 getEquipment ()
975 993 {
976 994 return bag.equipment?.slots ?? bag.equipment ?? {};
@@ -28,7 +28,8 @@ export function initInventory ({
28 contextMenu,
28 contextMenu,
29 resolveSpriteUrl,
29 resolveSpriteUrl,
30 getFriends,
30 getFriends,
31 getLocalName
31 getLocalName,
32 tipArrows = null
32})
33})
33{
34{
34 const bagPanel = document.getElementById("bag-panel");
35 const bagPanel = document.getElementById("bag-panel");
@@ -379,10 +380,20 @@ export function initInventory ({
379 }
380 }
380 if (slot.itemId === ItemId.potion && slot.instance?.kind === "potion")
381 if (slot.itemId === ItemId.potion && slot.instance?.kind === "potion")
381 {
382 {
382 items.push({
383 if (tipArrows?.isArrowCoatingPotion?.(slot))
383 label: "Drink",
384 {
384 onSelect: () => socket.send({ type: MessageType.drinkItem, slotIndex })
385 items.push({
385 });
386 label: "Apply to arrows",
387 onSelect: () => tipArrows.open(slotIndex)
388 });
389 }
390 else
391 {
392 items.push({
393 label: "Drink",
394 onSelect: () => socket.send({ type: MessageType.drinkItem, slotIndex })
395 });
396 }
386 }
397 }
387 items.push({
398 items.push({
388 label: "Drop",
399 label: "Drop",
@@ -971,6 +982,13 @@ export function initInventory ({
971 {
982 {
972 return bag.inventory ?? [];
983 return bag.inventory ?? [];
973 },
984 },
985 getBag ()
986 {
987 return {
988 slots: bag.inventory ?? [],
989 equipment: bag.equipment ?? null
990 };
991 },
974 getEquipment ()
992 getEquipment ()
975 {
993 {
976 return bag.equipment?.slots ?? bag.equipment ?? {};
994 return bag.equipment?.slots ?? bag.equipment ?? {};
client/src/play/main.js +10 −0
@@ -14,6 +14,7 @@ import { initSkills } from "./skills.js";
14 14 import { initSpells } from "./spells.js";
15 15 import { initCrafting } from "./crafting.js";
16 16 import { initAlchemy } from "./alchemy.js";
17 import { initTipArrows } from "./tipArrows.js";
17 18 import { initStamina } from "./stamina.js";
18 19 import { initHealth } from "./health.js";
19 20 import { initStatusEffects } from "./statusEffects.js";
@@ -1347,10 +1348,19 @@ async function main ()
1347 1348 }
1348 1349 });
1349 1350 contextMenu = initContextMenu({ onSuppressWorldClick: consumeWorldClick });
1351 const tipArrows = initTipArrows({
1352 socket: { send (payload) { socket.send(payload); } },
1353 MessageType,
1354 getInventoryBag ()
1355 {
1356 return inventory?.getBag?.() ?? null;
1357 }
1358 });
1350 1359 inventory = initInventory({
1351 1360 socket: { send (payload) { socket.send(payload); } },
1352 1361 MessageType,
1353 1362 contextMenu,
1363 tipArrows,
1354 1364 resolveSpriteUrl (name)
1355 1365 {
1356 1366 return catalog?.images?.find((entry) => entry.name === name)?.url ?? null;
@@ -14,6 +14,7 @@ import { initSkills } from "./skills.js";
14import { initSpells } from "./spells.js";
14import { initSpells } from "./spells.js";
15import { initCrafting } from "./crafting.js";
15import { initCrafting } from "./crafting.js";
16import { initAlchemy } from "./alchemy.js";
16import { initAlchemy } from "./alchemy.js";
17import { initTipArrows } from "./tipArrows.js";
17import { initStamina } from "./stamina.js";
18import { initStamina } from "./stamina.js";
18import { initHealth } from "./health.js";
19import { initHealth } from "./health.js";
19import { initStatusEffects } from "./statusEffects.js";
20import { initStatusEffects } from "./statusEffects.js";
@@ -1347,10 +1348,19 @@ async function main ()
1347 }
1348 }
1348 });
1349 });
1349 contextMenu = initContextMenu({ onSuppressWorldClick: consumeWorldClick });
1350 contextMenu = initContextMenu({ onSuppressWorldClick: consumeWorldClick });
1351 const tipArrows = initTipArrows({
1352 socket: { send (payload) { socket.send(payload); } },
1353 MessageType,
1354 getInventoryBag ()
1355 {
1356 return inventory?.getBag?.() ?? null;
1357 }
1358 });
1350 inventory = initInventory({
1359 inventory = initInventory({
1351 socket: { send (payload) { socket.send(payload); } },
1360 socket: { send (payload) { socket.send(payload); } },
1352 MessageType,
1361 MessageType,
1353 contextMenu,
1362 contextMenu,
1363 tipArrows,
1354 resolveSpriteUrl (name)
1364 resolveSpriteUrl (name)
1355 {
1365 {
1356 return catalog?.images?.find((entry) => entry.name === name)?.url ?? null;
1366 return catalog?.images?.find((entry) => entry.name === name)?.url ?? null;
client/src/play/tipArrows.js added +245 −0
@@ -0,0 +1,245 @@
1 import { ItemId, itemDefinition, itemDisplayName } from "/shared/definitions/items.js";
2 import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";
3 import { ARROW_COATING_ARROWS_PER_USE, alchemyPotionDefinition } from "/shared/definitions/alchemy.js";
4 import { stackQuantity } from "/shared/items/inventory.js";
5 import { applyItemIcon } from "../render/potionIcon.js";
6
7 function coatingEffect (stack)
8 {
9 if (!stack || stack.itemId !== ItemId.potion || stack.instance?.kind !== "potion")
10 { return null; }
11 if (stack.instance.effect?.type === "arrow-coating")
12 { return stack.instance.effect; }
13 const def = alchemyPotionDefinition(stack.instance.potionKey);
14 return def?.effect?.type === "arrow-coating" ? def.effect : null;
15 }
16
17 /**
18 * Modal: apply arrow coating potion to untipped arrows in the bag.
19 */
20 export function initTipArrows ({
21 socket,
22 MessageType,
23 getInventoryBag,
24 root = document.body
25 })
26 {
27 const backdrop = document.createElement("div");
28 backdrop.className = "modal-backdrop";
29 backdrop.hidden = true;
30 backdrop.id = "tip-arrows-backdrop";
31
32 const panel = document.createElement("div");
33 panel.id = "tip-arrows-panel";
34 panel.innerHTML = `
35 <h2>Apply to arrows</h2>
36 <p class="tip-arrows-hint"></p>
37 <div class="tip-arrows-row">
38 <div class="tip-arrows-slot" data-role="coating"></div>
39 <span class="tip-arrows-arrow">→</span>
40 <button type="button" class="tip-arrows-slot tip-arrows-pick" data-role="arrow" title="Choose arrows"></button>
41 </div>
42 <label class="tip-arrows-qty-label">Quantity
43 <input type="number" class="tip-arrows-qty" min="1" value="1" />
44 </label>
45 <p class="tip-arrows-capacity"></p>
46 <div class="tip-arrows-actions">
47 <button type="button" class="tip-arrows-apply">Apply</button>
48 <button type="button" class="tip-arrows-cancel">Cancel</button>
49 </div>
50 <div class="tip-arrows-picker" hidden></div>
51 `;
52 backdrop.append(panel);
53 root.append(backdrop);
54
55 const hintEl = panel.querySelector(".tip-arrows-hint");
56 const coatingEl = panel.querySelector('[data-role="coating"]');
57 const arrowEl = panel.querySelector('[data-role="arrow"]');
58 const qtyInput = panel.querySelector(".tip-arrows-qty");
59 const capacityEl = panel.querySelector(".tip-arrows-capacity");
60 const pickerEl = panel.querySelector(".tip-arrows-picker");
61 const applyBtn = panel.querySelector(".tip-arrows-apply");
62 const cancelBtn = panel.querySelector(".tip-arrows-cancel");
63
64 let coatingSlotIndex = -1;
65 let arrowSlotIndex = -1;
66
67 function bag ()
68 {
69 return getInventoryBag?.() ?? null;
70 }
71
72 function coatingStack ()
73 {
74 return bag()?.slots?.[coatingSlotIndex] ?? null;
75 }
76
77 function arrowStack ()
78 {
79 return bag()?.slots?.[arrowSlotIndex] ?? null;
80 }
81
82 function coatingCharges ()
83 {
84 const stack = coatingStack();
85 if (!stack)
86 { return 0; }
87 const fill = Math.max(1, Math.min(5, stack.instance?.fillLevel | 0 || 4));
88 return stackQuantity(stack.quantity) * fill;
89 }
90
91 function maxTipWithCoating ()
92 {
93 return coatingCharges() * ARROW_COATING_ARROWS_PER_USE;
94 }
95
96 function maxTipForSelection ()
97 {
98 const arrows = arrowStack();
99 const arrowQty = arrows ? stackQuantity(arrows.quantity) : 0;
100 return Math.min(arrowQty, ARROW_COATING_ARROWS_PER_USE, maxTipWithCoating());
101 }
102
103 function renderSlot (el, stack)
104 {
105 el.replaceChildren();
106 if (!stack)
107 {
108 el.textContent = "+";
109 return;
110 }
111 const img = document.createElement("img");
112 img.alt = "";
113 applyItemIcon(img, stack);
114 el.append(img);
115 const qty = stackQuantity(stack.quantity);
116 if (qty > 1)
117 {
118 const span = document.createElement("span");
119 span.className = "qty";
120 span.textContent = String(qty);
121 el.append(span);
122 }
123 }
124
125 function refresh ()
126 {
127 const coating = coatingStack();
128 const name = coating?.instance?.displayName ?? "Coating";
129 hintEl.textContent = `${name} tips up to ${ARROW_COATING_ARROWS_PER_USE} arrows per use.`;
130 renderSlot(coatingEl, coating);
131 renderSlot(arrowEl, arrowStack());
132 const max = maxTipForSelection();
133 qtyInput.max = String(Math.max(1, max));
134 if ((qtyInput.value | 0) > max || (qtyInput.value | 0) < 1)
135 { qtyInput.value = String(Math.max(1, max)); }
136 capacityEl.textContent = coating
137 ? `This coating can tip up to ${maxTipWithCoating()} arrows in total.`
138 : "";
139 applyBtn.disabled = !coating || !arrowStack() || max <= 0;
140 }
141
142 function listUntippedArrowSlots ()
143 {
144 const slots = bag()?.slots ?? [];
145 const out = [];
146 for (let i = 0; i < slots.length; i++)
147 {
148 const slot = slots[i];
149 if (!slot)
150 { continue; }
151 const def = itemDefinition(slot.itemId);
152 if (def?.equipment?.kind !== EquipmentKind.arrowAmmo)
153 { continue; }
154 if (slot.instance?.kind === "tipped-arrow")
155 { continue; }
156 out.push({ slotIndex: i, stack: slot });
157 }
158 return out;
159 }
160
161 function openPicker ()
162 {
163 pickerEl.hidden = false;
164 pickerEl.replaceChildren();
165 const options = listUntippedArrowSlots();
166 if (!options.length)
167 {
168 pickerEl.textContent = "No untipped arrows in your bag.";
169 return;
170 }
171 for (const opt of options)
172 {
173 const btn = document.createElement("button");
174 btn.type = "button";
175 btn.className = "tip-arrows-pick-option";
176 const img = document.createElement("img");
177 img.alt = "";
178 applyItemIcon(img, opt.stack);
179 btn.append(img);
180 const label = document.createElement("span");
181 label.textContent = `${itemDisplayName(opt.stack)} ×${stackQuantity(opt.stack.quantity)}`;
182 btn.append(label);
183 btn.addEventListener("click", () =>
184 {
185 arrowSlotIndex = opt.slotIndex;
186 pickerEl.hidden = true;
187 const max = maxTipForSelection();
188 qtyInput.value = String(Math.max(1, max));
189 refresh();
190 });
191 pickerEl.append(btn);
192 }
193 }
194
195 function close ()
196 {
197 backdrop.hidden = true;
198 pickerEl.hidden = true;
199 coatingSlotIndex = -1;
200 arrowSlotIndex = -1;
201 }
202
203 function open (slotIndex)
204 {
205 coatingSlotIndex = slotIndex | 0;
206 arrowSlotIndex = -1;
207 pickerEl.hidden = true;
208 backdrop.hidden = false;
209 qtyInput.value = "1";
210 refresh();
211 }
212
213 arrowEl.addEventListener("click", () => openPicker());
214 cancelBtn.addEventListener("click", () => close());
215 backdrop.addEventListener("click", (event) =>
216 {
217 if (event.target === backdrop)
218 { close(); }
219 });
220 panel.addEventListener("click", (event) => event.stopPropagation());
221 applyBtn.addEventListener("click", () =>
222 {
223 const qty = Math.max(1, qtyInput.value | 0 || 1);
224 if (coatingSlotIndex < 0 || arrowSlotIndex < 0)
225 { return; }
226 socket.send({
227 type: MessageType.tipArrows,
228 coatingSlotIndex,
229 arrowSlotIndex,
230 quantity: qty
231 });
232 close();
233 });
234 qtyInput.addEventListener("change", () => refresh());
235
236 return {
237 open,
238 close,
239 isOpen: () => !backdrop.hidden,
240 isArrowCoatingPotion (stack)
241 {
242 return !!coatingEffect(stack);
243 }
244 };
245 }
@@ -0,0 +1,245 @@
1import { ItemId, itemDefinition, itemDisplayName } from "/shared/definitions/items.js";
2import { EquipmentKind } from "/shared/definitions/equipmentKinds.js";
3import { ARROW_COATING_ARROWS_PER_USE, alchemyPotionDefinition } from "/shared/definitions/alchemy.js";
4import { stackQuantity } from "/shared/items/inventory.js";
5import { applyItemIcon } from "../render/potionIcon.js";
6
7function coatingEffect (stack)
8{
9 if (!stack || stack.itemId !== ItemId.potion || stack.instance?.kind !== "potion")
10 { return null; }
11 if (stack.instance.effect?.type === "arrow-coating")
12 { return stack.instance.effect; }
13 const def = alchemyPotionDefinition(stack.instance.potionKey);
14 return def?.effect?.type === "arrow-coating" ? def.effect : null;
15}
16
17/**
18 * Modal: apply arrow coating potion to untipped arrows in the bag.
19 */
20export function initTipArrows ({
21 socket,
22 MessageType,
23 getInventoryBag,
24 root = document.body
25})
26{
27 const backdrop = document.createElement("div");
28 backdrop.className = "modal-backdrop";
29 backdrop.hidden = true;
30 backdrop.id = "tip-arrows-backdrop";
31
32 const panel = document.createElement("div");
33 panel.id = "tip-arrows-panel";
34 panel.innerHTML = `
35 <h2>Apply to arrows</h2>
36 <p class="tip-arrows-hint"></p>
37 <div class="tip-arrows-row">
38 <div class="tip-arrows-slot" data-role="coating"></div>
39 <span class="tip-arrows-arrow">→</span>
40 <button type="button" class="tip-arrows-slot tip-arrows-pick" data-role="arrow" title="Choose arrows"></button>
41 </div>
42 <label class="tip-arrows-qty-label">Quantity
43 <input type="number" class="tip-arrows-qty" min="1" value="1" />
44 </label>
45 <p class="tip-arrows-capacity"></p>
46 <div class="tip-arrows-actions">
47 <button type="button" class="tip-arrows-apply">Apply</button>
48 <button type="button" class="tip-arrows-cancel">Cancel</button>
49 </div>
50 <div class="tip-arrows-picker" hidden></div>
51 `;
52 backdrop.append(panel);
53 root.append(backdrop);
54
55 const hintEl = panel.querySelector(".tip-arrows-hint");
56 const coatingEl = panel.querySelector('[data-role="coating"]');
57 const arrowEl = panel.querySelector('[data-role="arrow"]');
58 const qtyInput = panel.querySelector(".tip-arrows-qty");
59 const capacityEl = panel.querySelector(".tip-arrows-capacity");
60 const pickerEl = panel.querySelector(".tip-arrows-picker");
61 const applyBtn = panel.querySelector(".tip-arrows-apply");
62 const cancelBtn = panel.querySelector(".tip-arrows-cancel");
63
64 let coatingSlotIndex = -1;
65 let arrowSlotIndex = -1;
66
67 function bag ()
68 {
69 return getInventoryBag?.() ?? null;
70 }
71
72 function coatingStack ()
73 {
74 return bag()?.slots?.[coatingSlotIndex] ?? null;
75 }
76
77 function arrowStack ()
78 {
79 return bag()?.slots?.[arrowSlotIndex] ?? null;
80 }
81
82 function coatingCharges ()
83 {
84 const stack = coatingStack();
85 if (!stack)
86 { return 0; }
87 const fill = Math.max(1, Math.min(5, stack.instance?.fillLevel | 0 || 4));
88 return stackQuantity(stack.quantity) * fill;
89 }
90
91 function maxTipWithCoating ()
92 {
93 return coatingCharges() * ARROW_COATING_ARROWS_PER_USE;
94 }
95
96 function maxTipForSelection ()
97 {
98 const arrows = arrowStack();
99 const arrowQty = arrows ? stackQuantity(arrows.quantity) : 0;
100 return Math.min(arrowQty, ARROW_COATING_ARROWS_PER_USE, maxTipWithCoating());
101 }
102
103 function renderSlot (el, stack)
104 {
105 el.replaceChildren();
106 if (!stack)
107 {
108 el.textContent = "+";
109 return;
110 }
111 const img = document.createElement("img");
112 img.alt = "";
113 applyItemIcon(img, stack);
114 el.append(img);
115 const qty = stackQuantity(stack.quantity);
116 if (qty > 1)
117 {
118 const span = document.createElement("span");
119 span.className = "qty";
120 span.textContent = String(qty);
121 el.append(span);
122 }
123 }
124
125 function refresh ()
126 {
127 const coating = coatingStack();
128 const name = coating?.instance?.displayName ?? "Coating";
129 hintEl.textContent = `${name} tips up to ${ARROW_COATING_ARROWS_PER_USE} arrows per use.`;
130 renderSlot(coatingEl, coating);
131 renderSlot(arrowEl, arrowStack());
132 const max = maxTipForSelection();
133 qtyInput.max = String(Math.max(1, max));
134 if ((qtyInput.value | 0) > max || (qtyInput.value | 0) < 1)
135 { qtyInput.value = String(Math.max(1, max)); }
136 capacityEl.textContent = coating
137 ? `This coating can tip up to ${maxTipWithCoating()} arrows in total.`
138 : "";
139 applyBtn.disabled = !coating || !arrowStack() || max <= 0;
140 }
141
142 function listUntippedArrowSlots ()
143 {
144 const slots = bag()?.slots ?? [];
145 const out = [];
146 for (let i = 0; i < slots.length; i++)
147 {
148 const slot = slots[i];
149 if (!slot)
150 { continue; }
151 const def = itemDefinition(slot.itemId);
152 if (def?.equipment?.kind !== EquipmentKind.arrowAmmo)
153 { continue; }
154 if (slot.instance?.kind === "tipped-arrow")
155 { continue; }
156 out.push({ slotIndex: i, stack: slot });
157 }
158 return out;
159 }
160
161 function openPicker ()
162 {
163 pickerEl.hidden = false;
164 pickerEl.replaceChildren();
165 const options = listUntippedArrowSlots();
166 if (!options.length)
167 {
168 pickerEl.textContent = "No untipped arrows in your bag.";
169 return;
170 }
171 for (const opt of options)
172 {
173 const btn = document.createElement("button");
174 btn.type = "button";
175 btn.className = "tip-arrows-pick-option";
176 const img = document.createElement("img");
177 img.alt = "";
178 applyItemIcon(img, opt.stack);
179 btn.append(img);
180 const label = document.createElement("span");
181 label.textContent = `${itemDisplayName(opt.stack)} ×${stackQuantity(opt.stack.quantity)}`;
182 btn.append(label);
183 btn.addEventListener("click", () =>
184 {
185 arrowSlotIndex = opt.slotIndex;
186 pickerEl.hidden = true;
187 const max = maxTipForSelection();
188 qtyInput.value = String(Math.max(1, max));
189 refresh();
190 });
191 pickerEl.append(btn);
192 }
193 }
194
195 function close ()
196 {
197 backdrop.hidden = true;
198 pickerEl.hidden = true;
199 coatingSlotIndex = -1;
200 arrowSlotIndex = -1;
201 }
202
203 function open (slotIndex)
204 {
205 coatingSlotIndex = slotIndex | 0;
206 arrowSlotIndex = -1;
207 pickerEl.hidden = true;
208 backdrop.hidden = false;
209 qtyInput.value = "1";
210 refresh();
211 }
212
213 arrowEl.addEventListener("click", () => openPicker());
214 cancelBtn.addEventListener("click", () => close());
215 backdrop.addEventListener("click", (event) =>
216 {
217 if (event.target === backdrop)
218 { close(); }
219 });
220 panel.addEventListener("click", (event) => event.stopPropagation());
221 applyBtn.addEventListener("click", () =>
222 {
223 const qty = Math.max(1, qtyInput.value | 0 || 1);
224 if (coatingSlotIndex < 0 || arrowSlotIndex < 0)
225 { return; }
226 socket.send({
227 type: MessageType.tipArrows,
228 coatingSlotIndex,
229 arrowSlotIndex,
230 quantity: qty
231 });
232 close();
233 });
234 qtyInput.addEventListener("change", () => refresh());
235
236 return {
237 open,
238 close,
239 isOpen: () => !backdrop.hidden,
240 isArrowCoatingPotion (stack)
241 {
242 return !!coatingEffect(stack);
243 }
244 };
245}
client/src/render/potionIcon.js +3 −2
@@ -99,10 +99,11 @@ export async function tintedItemIconDataUrl (assetPath, tint)
99 99 return url;
100 100 }
101 101
102 /** Dual-channel arrow icon (red shaft + blue tip masks). */
102 /** Dual/triple-channel arrow icon (red shaft + blue tip + optional green coat). */
103 103 export async function dualTintedItemIconDataUrl (assetPath, dualTint)
104 104 {
105 const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}`;
105 const coatKey = dualTint.coat ? colorKey(dualTint.coat) : "-";
106 const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}|${coatKey}`;
106 107 if (urlCache.has(key))
107 108 { return urlCache.get(key); }
108 109 const img = await loadImage(assetPath);
@@ -99,10 +99,11 @@ export async function tintedItemIconDataUrl (assetPath, tint)
99 return url;
99 return url;
100}
100}
101
101
102/** Dual-channel arrow icon (red shaft + blue tip masks). */
102/** Dual/triple-channel arrow icon (red shaft + blue tip + optional green coat). */
103export async function dualTintedItemIconDataUrl (assetPath, dualTint)
103export async function dualTintedItemIconDataUrl (assetPath, dualTint)
104{
104{
105 const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}`;
105 const coatKey = dualTint.coat ? colorKey(dualTint.coat) : "-";
106 const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}|${coatKey}`;
106 if (urlCache.has(key))
107 if (urlCache.has(key))
107 { return urlCache.get(key); }
108 { return urlCache.get(key); }
108 const img = await loadImage(assetPath);
109 const img = await loadImage(assetPath);
client/src/render/worldView.js +63 −15
@@ -152,7 +152,8 @@ const TINT_LIT_SPRITE_FRAG = [
152 152 "}"
153 153 ].join("\n");
154 154
155 /** Dual-channel tint: red = shaft/wood, blue = tip/string, white unchanged; then darkness. */
155 /** Dual/triple-channel tint: red = shaft, blue = tip, green = coat; then darkness.
156 * Equal non-dominant channels lighten the assigned tint toward white. */
156 157 const DUAL_TINT_LIT_SPRITE_FRAG = [
157 158 "precision mediump float;",
158 159 "varying vec2 v_texCoord;",
@@ -163,26 +164,36 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
163 164 "uniform float u_spriteHeight;",
164 165 "uniform vec3 u_shaftTint;",
165 166 "uniform vec3 u_tipTint;",
167 "uniform vec3 u_coatTint;",
168 "uniform float u_hasCoat;",
169 "vec3 channelTint(float L, float o1, float o2, vec3 tint) {",
170 " float equal = step(abs(o1 - o2), 0.04);",
171 " float blend = L > 0.0 ? clamp(mix(min(o1, o2), o1, equal) / L, 0.0, 1.0) : 0.0;",
172 " float tintLuma = dot(tint, vec3(0.2126, 0.7152, 0.0722));",
173 " vec3 toward = mix(vec3(tintLuma), vec3(1.0), equal);",
174 " return mix(tint, toward, blend) * L;",
175 "}",
166 176 "void main() {",
167 177 " vec4 color = texture2D(u_texture, v_texCoord);",
168 178 " if (color.a <= 0.0) { discard; }",
169 179 " float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
170 180 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
171 181 " vec3 rgb = color.rgb;",
182 " if (u_hasCoat > 0.5) {",
183 " float coatMask = clamp((color.g - max(color.r, color.b)) * 1.75, 0.0, 1.0);",
184 " if (coatMask > 0.0) {",
185 " vec3 coatCol = channelTint(color.g, color.r, color.b, u_coatTint);",
186 " rgb = mix(rgb, coatCol, coatMask);",
187 " }",
188 " }",
172 189 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
173 190 " if (tipMask > 0.0) {",
174 " float L = color.b;",
175 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
176 " float tipLuma = dot(u_tipTint, vec3(0.2126, 0.7152, 0.0722));",
177 " vec3 tipCol = mix(u_tipTint, vec3(tipLuma), gBlend) * L;",
191 " vec3 tipCol = channelTint(color.b, color.r, color.g, u_tipTint);",
178 192 " rgb = mix(rgb, tipCol, tipMask);",
179 193 " }",
180 194 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
181 195 " if (shaftMask > 0.0) {",
182 " float L = color.r;",
183 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
184 " float shaftLuma = dot(u_shaftTint, vec3(0.2126, 0.7152, 0.0722));",
185 " vec3 shaftCol = mix(u_shaftTint, vec3(shaftLuma), gBlend) * L;",
196 " vec3 shaftCol = channelTint(color.r, color.g, color.b, u_shaftTint);",
186 197 " rgb = mix(rgb, shaftCol, shaftMask);",
187 198 " }",
188 199 " if (u_wade > 0.5 && fromBottom < 5.0) {",
@@ -983,6 +994,7 @@ export class WorldView
983 994 {
984 995 const shaft = normalizeRgb(dualTint.shaft);
985 996 const tip = normalizeRgb(dualTint.tip);
997 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
986 998 shader = getDualTintLitSpriteShader();
987 999 uniforms = {
988 1000 u_darkness: 0,
@@ -990,7 +1002,9 @@ export class WorldView
990 1002 u_wade: 0,
991 1003 u_spriteHeight: height,
992 1004 u_shaftTint: [shaft.r, shaft.g, shaft.b],
993 u_tipTint: [tip.r, tip.g, tip.b]
1005 u_tipTint: [tip.r, tip.g, tip.b],
1006 u_coatTint: coat ? [coat.r, coat.g, coat.b] : [0, 0, 0],
1007 u_hasCoat: coat ? 1 : 0
994 1008 };
995 1009 }
996 1010 else if (tightFit && bodyHtml && maskUniforms)
@@ -2079,6 +2093,8 @@ export class WorldView
2079 2093 entity.object.renderer.sprite = this.game.images[base];
2080 2094 this.#startIdleAnimation(entity.object);
2081 2095 }
2096 entity.bodyTint = layers[0]?.tint ? normalizeRgb(layers[0].tint) : null;
2097 entity.bloomBody = !!layers[0]?.bloomBody;
2082 2098 for (const overlay of entity.overlays ?? [])
2083 2099 { overlay.destroy(); }
2084 2100 for (const overlay of entity.bloomOverlays ?? [])
@@ -2088,6 +2104,21 @@ export class WorldView
2088 2104 entity.overlayDualTints = [];
2089 2105 entity.overlayTightFit = [];
2090 2106 entity.bloomOverlays = [];
2107 entity.bloomOverlayTints = [];
2108 if (entity.bloomBody && this.game.images[base])
2109 {
2110 const bloomName = bloomCompanionName(base);
2111 const bloomImage = this.game.images[bloomName] ?? this.game.images[base];
2112 if (bloomImage)
2113 {
2114 const bloom = new GameObject(0, 0, bloomImage, SORT_ENTITY);
2115 bloom.renderer.layer = RENDER_LAYER_BLOOM;
2116 this.#markUnlit(bloom);
2117 this.scene.addObject(bloom);
2118 entity.bloomOverlays.push(bloom);
2119 entity.bloomOverlayTints.push(entity.bodyTint);
2120 }
2121 }
2091 2122 for (const layer of layers.slice(1))
2092 2123 {
2093 2124 const image = this.game.images[layer.sprite];
@@ -2118,6 +2149,9 @@ export class WorldView
2118 2149 this.#markUnlit(bloom);
2119 2150 this.scene.addObject(bloom);
2120 2151 entity.bloomOverlays.push(bloom);
2152 entity.bloomOverlayTints.push(
2153 layer.tint ? normalizeRgb(layer.tint) : null
2154 );
2121 2155 }
2122 2156 }
2123 2157
@@ -2143,7 +2177,7 @@ export class WorldView
2143 2177 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2144 2178
2145 2179 entity.object.transform.rotation = walkTilt;
2146 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade);
2180 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null);
2147 2181 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2148 2182 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2149 2183 {
@@ -2172,13 +2206,20 @@ export class WorldView
2172 2206 }
2173 2207 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2174 2208 }
2175 for (const overlay of entity.bloomOverlays ?? [])
2209 for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)
2176 2210 {
2211 const overlay = entity.bloomOverlays[index];
2177 2212 this.#setRendererVisible(overlay, this.bloomEnabled);
2178 2213 if (!this.bloomEnabled)
2179 2214 { continue; }
2180 2215 overlay.transform.rotation = walkTilt;
2181 this.#syncLitSprite(overlay, tileShade, flashStrength, wade);
2216 this.#syncLitSprite(
2217 overlay,
2218 tileShade,
2219 flashStrength,
2220 wade,
2221 entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null
2222 );
2182 2223 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2183 2224 }
2184 2225 this.#placeHpBar(entity, pivotX, pivotY);
@@ -2305,6 +2346,7 @@ export class WorldView
2305 2346 object._lit = true;
2306 2347 const shaft = normalizeRgb(dualTint.shaft);
2307 2348 const tip = normalizeRgb(dualTint.tip);
2349 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
2308 2350 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2309 2351 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2310 2352 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
@@ -2315,7 +2357,9 @@ export class WorldView
2315 2357 u_wade: wade ? 1 : 0,
2316 2358 u_spriteHeight: height,
2317 2359 u_shaftTint: [shaft.r, shaft.g, shaft.b],
2318 u_tipTint: [tip.r, tip.g, tip.b]
2360 u_tipTint: [tip.r, tip.g, tip.b],
2361 u_coatTint: coat ? [coat.r, coat.g, coat.b] : [0, 0, 0],
2362 u_hasCoat: coat ? 1 : 0
2319 2363 };
2320 2364 object.renderer.secondaryMap = null;
2321 2365 }
@@ -2485,7 +2529,11 @@ export class WorldView
2485 2529 {
2486 2530 if (!payload?.shaftTint || !payload?.tipTint)
2487 2531 { return null; }
2488 return { shaft: payload.shaftTint, tip: payload.tipTint };
2532 return {
2533 shaft: payload.shaftTint,
2534 tip: payload.tipTint,
2535 ...(payload.coatTint ? { coat: payload.coatTint } : {})
2536 };
2489 2537 }
2490 2538
2491 2539 #syncHpBar (entity)
@@ -152,7 +152,8 @@ const TINT_LIT_SPRITE_FRAG = [
152 "}"
152 "}"
153].join("\n");
153].join("\n");
154
154
155/** Dual-channel tint: red = shaft/wood, blue = tip/string, white unchanged; then darkness. */
155/** Dual/triple-channel tint: red = shaft, blue = tip, green = coat; then darkness.
156 * Equal non-dominant channels lighten the assigned tint toward white. */
156const DUAL_TINT_LIT_SPRITE_FRAG = [
157const DUAL_TINT_LIT_SPRITE_FRAG = [
157 "precision mediump float;",
158 "precision mediump float;",
158 "varying vec2 v_texCoord;",
159 "varying vec2 v_texCoord;",
@@ -163,26 +164,36 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
163 "uniform float u_spriteHeight;",
164 "uniform float u_spriteHeight;",
164 "uniform vec3 u_shaftTint;",
165 "uniform vec3 u_shaftTint;",
165 "uniform vec3 u_tipTint;",
166 "uniform vec3 u_tipTint;",
167 "uniform vec3 u_coatTint;",
168 "uniform float u_hasCoat;",
169 "vec3 channelTint(float L, float o1, float o2, vec3 tint) {",
170 " float equal = step(abs(o1 - o2), 0.04);",
171 " float blend = L > 0.0 ? clamp(mix(min(o1, o2), o1, equal) / L, 0.0, 1.0) : 0.0;",
172 " float tintLuma = dot(tint, vec3(0.2126, 0.7152, 0.0722));",
173 " vec3 toward = mix(vec3(tintLuma), vec3(1.0), equal);",
174 " return mix(tint, toward, blend) * L;",
175 "}",
166 "void main() {",
176 "void main() {",
167 " vec4 color = texture2D(u_texture, v_texCoord);",
177 " vec4 color = texture2D(u_texture, v_texCoord);",
168 " if (color.a <= 0.0) { discard; }",
178 " if (color.a <= 0.0) { discard; }",
169 " float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
179 " float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
170 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
180 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
171 " vec3 rgb = color.rgb;",
181 " vec3 rgb = color.rgb;",
182 " if (u_hasCoat > 0.5) {",
183 " float coatMask = clamp((color.g - max(color.r, color.b)) * 1.75, 0.0, 1.0);",
184 " if (coatMask > 0.0) {",
185 " vec3 coatCol = channelTint(color.g, color.r, color.b, u_coatTint);",
186 " rgb = mix(rgb, coatCol, coatMask);",
187 " }",
188 " }",
172 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
189 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
173 " if (tipMask > 0.0) {",
190 " if (tipMask > 0.0) {",
174 " float L = color.b;",
191 " vec3 tipCol = channelTint(color.b, color.r, color.g, u_tipTint);",
175 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
176 " float tipLuma = dot(u_tipTint, vec3(0.2126, 0.7152, 0.0722));",
177 " vec3 tipCol = mix(u_tipTint, vec3(tipLuma), gBlend) * L;",
178 " rgb = mix(rgb, tipCol, tipMask);",
192 " rgb = mix(rgb, tipCol, tipMask);",
179 " }",
193 " }",
180 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
194 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
181 " if (shaftMask > 0.0) {",
195 " if (shaftMask > 0.0) {",
182 " float L = color.r;",
196 " vec3 shaftCol = channelTint(color.r, color.g, color.b, u_shaftTint);",
183 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
184 " float shaftLuma = dot(u_shaftTint, vec3(0.2126, 0.7152, 0.0722));",
185 " vec3 shaftCol = mix(u_shaftTint, vec3(shaftLuma), gBlend) * L;",
186 " rgb = mix(rgb, shaftCol, shaftMask);",
197 " rgb = mix(rgb, shaftCol, shaftMask);",
187 " }",
198 " }",
188 " if (u_wade > 0.5 && fromBottom < 5.0) {",
199 " if (u_wade > 0.5 && fromBottom < 5.0) {",
@@ -983,6 +994,7 @@ export class WorldView
983 {
994 {
984 const shaft = normalizeRgb(dualTint.shaft);
995 const shaft = normalizeRgb(dualTint.shaft);
985 const tip = normalizeRgb(dualTint.tip);
996 const tip = normalizeRgb(dualTint.tip);
997 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
986 shader = getDualTintLitSpriteShader();
998 shader = getDualTintLitSpriteShader();
987 uniforms = {
999 uniforms = {
988 u_darkness: 0,
1000 u_darkness: 0,
@@ -990,7 +1002,9 @@ export class WorldView
990 u_wade: 0,
1002 u_wade: 0,
991 u_spriteHeight: height,
1003 u_spriteHeight: height,
992 u_shaftTint: [shaft.r, shaft.g, shaft.b],
1004 u_shaftTint: [shaft.r, shaft.g, shaft.b],
993 u_tipTint: [tip.r, tip.g, tip.b]
1005 u_tipTint: [tip.r, tip.g, tip.b],
1006 u_coatTint: coat ? [coat.r, coat.g, coat.b] : [0, 0, 0],
1007 u_hasCoat: coat ? 1 : 0
994 };
1008 };
995 }
1009 }
996 else if (tightFit && bodyHtml && maskUniforms)
1010 else if (tightFit && bodyHtml && maskUniforms)
@@ -2079,6 +2093,8 @@ export class WorldView
2079 entity.object.renderer.sprite = this.game.images[base];
2093 entity.object.renderer.sprite = this.game.images[base];
2080 this.#startIdleAnimation(entity.object);
2094 this.#startIdleAnimation(entity.object);
2081 }
2095 }
2096 entity.bodyTint = layers[0]?.tint ? normalizeRgb(layers[0].tint) : null;
2097 entity.bloomBody = !!layers[0]?.bloomBody;
2082 for (const overlay of entity.overlays ?? [])
2098 for (const overlay of entity.overlays ?? [])
2083 { overlay.destroy(); }
2099 { overlay.destroy(); }
2084 for (const overlay of entity.bloomOverlays ?? [])
2100 for (const overlay of entity.bloomOverlays ?? [])
@@ -2088,6 +2104,21 @@ export class WorldView
2088 entity.overlayDualTints = [];
2104 entity.overlayDualTints = [];
2089 entity.overlayTightFit = [];
2105 entity.overlayTightFit = [];
2090 entity.bloomOverlays = [];
2106 entity.bloomOverlays = [];
2107 entity.bloomOverlayTints = [];
2108 if (entity.bloomBody && this.game.images[base])
2109 {
2110 const bloomName = bloomCompanionName(base);
2111 const bloomImage = this.game.images[bloomName] ?? this.game.images[base];
2112 if (bloomImage)
2113 {
2114 const bloom = new GameObject(0, 0, bloomImage, SORT_ENTITY);
2115 bloom.renderer.layer = RENDER_LAYER_BLOOM;
2116 this.#markUnlit(bloom);
2117 this.scene.addObject(bloom);
2118 entity.bloomOverlays.push(bloom);
2119 entity.bloomOverlayTints.push(entity.bodyTint);
2120 }
2121 }
2091 for (const layer of layers.slice(1))
2122 for (const layer of layers.slice(1))
2092 {
2123 {
2093 const image = this.game.images[layer.sprite];
2124 const image = this.game.images[layer.sprite];
@@ -2118,6 +2149,9 @@ export class WorldView
2118 this.#markUnlit(bloom);
2149 this.#markUnlit(bloom);
2119 this.scene.addObject(bloom);
2150 this.scene.addObject(bloom);
2120 entity.bloomOverlays.push(bloom);
2151 entity.bloomOverlays.push(bloom);
2152 entity.bloomOverlayTints.push(
2153 layer.tint ? normalizeRgb(layer.tint) : null
2154 );
2121 }
2155 }
2122 }
2156 }
2123
2157
@@ -2143,7 +2177,7 @@ export class WorldView
2143 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2177 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2144
2178
2145 entity.object.transform.rotation = walkTilt;
2179 entity.object.transform.rotation = walkTilt;
2146 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade);
2180 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null);
2147 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2181 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1);
2148 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2182 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2149 {
2183 {
@@ -2172,13 +2206,20 @@ export class WorldView
2172 }
2206 }
2173 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2207 this.#placePivoted(overlay, pivotX, pivotY, overlaySortY, SORT_ENTITY, entity.visualScale ?? 1);
2174 }
2208 }
2175 for (const overlay of entity.bloomOverlays ?? [])
2209 for (let index = 0; index < (entity.bloomOverlays ?? []).length; index++)
2176 {
2210 {
2211 const overlay = entity.bloomOverlays[index];
2177 this.#setRendererVisible(overlay, this.bloomEnabled);
2212 this.#setRendererVisible(overlay, this.bloomEnabled);
2178 if (!this.bloomEnabled)
2213 if (!this.bloomEnabled)
2179 { continue; }
2214 { continue; }
2180 overlay.transform.rotation = walkTilt;
2215 overlay.transform.rotation = walkTilt;
2181 this.#syncLitSprite(overlay, tileShade, flashStrength, wade);
2216 this.#syncLitSprite(
2217 overlay,
2218 tileShade,
2219 flashStrength,
2220 wade,
2221 entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null
2222 );
2182 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2223 this.#placePivoted(overlay, pivotX, pivotY, pivotY + 0.002, SORT_ENTITY, entity.visualScale ?? 1);
2183 }
2224 }
2184 this.#placeHpBar(entity, pivotX, pivotY);
2225 this.#placeHpBar(entity, pivotX, pivotY);
@@ -2305,6 +2346,7 @@ export class WorldView
2305 object._lit = true;
2346 object._lit = true;
2306 const shaft = normalizeRgb(dualTint.shaft);
2347 const shaft = normalizeRgb(dualTint.shaft);
2307 const tip = normalizeRgb(dualTint.tip);
2348 const tip = normalizeRgb(dualTint.tip);
2349 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
2308 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2350 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2309 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2351 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2310 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2352 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
@@ -2315,7 +2357,9 @@ export class WorldView
2315 u_wade: wade ? 1 : 0,
2357 u_wade: wade ? 1 : 0,
2316 u_spriteHeight: height,
2358 u_spriteHeight: height,
2317 u_shaftTint: [shaft.r, shaft.g, shaft.b],
2359 u_shaftTint: [shaft.r, shaft.g, shaft.b],
2318 u_tipTint: [tip.r, tip.g, tip.b]
2360 u_tipTint: [tip.r, tip.g, tip.b],
2361 u_coatTint: coat ? [coat.r, coat.g, coat.b] : [0, 0, 0],
2362 u_hasCoat: coat ? 1 : 0
2319 };
2363 };
2320 object.renderer.secondaryMap = null;
2364 object.renderer.secondaryMap = null;
2321 }
2365 }
@@ -2485,7 +2529,11 @@ export class WorldView
2485 {
2529 {
2486 if (!payload?.shaftTint || !payload?.tipTint)
2530 if (!payload?.shaftTint || !payload?.tipTint)
2487 { return null; }
2531 { return null; }
2488 return { shaft: payload.shaftTint, tip: payload.tipTint };
2532 return {
2533 shaft: payload.shaftTint,
2534 tip: payload.tipTint,
2535 ...(payload.coatTint ? { coat: payload.coatTint } : {})
2536 };
2489 }
2537 }
2490
2538
2491 #syncHpBar (entity)
2539 #syncHpBar (entity)
client/ui/play.css +119 −0
@@ -1345,6 +1345,125 @@ button.friend-account-name:hover {
1345 1345 display: none !important;
1346 1346 }
1347 1347
1348 #tip-arrows-panel {
1349 position: fixed;
1350 z-index: 6;
1351 top: 50%;
1352 left: 50%;
1353 transform: translate(-50%, -50%);
1354 width: min(360px, 92vw);
1355 padding: 1rem 1.1rem 1.1rem;
1356 background: #1a1e26;
1357 border: 1px solid #2c3340;
1358 border-radius: 6px;
1359 color: #d6dbe4;
1360 }
1361
1362 #tip-arrows-panel h2 {
1363 margin: 0 0 0.35rem;
1364 font-size: 1.05rem;
1365 }
1366
1367 .tip-arrows-hint,
1368 .tip-arrows-capacity {
1369 margin: 0.25rem 0 0.75rem;
1370 font-size: 0.85rem;
1371 opacity: 0.85;
1372 }
1373
1374 .tip-arrows-row {
1375 display: flex;
1376 align-items: center;
1377 justify-content: center;
1378 gap: 0.75rem;
1379 margin: 0.75rem 0;
1380 }
1381
1382 .tip-arrows-slot {
1383 position: relative;
1384 width: 48px;
1385 height: 48px;
1386 border: 1px solid #3a4454;
1387 background: #12161d;
1388 display: grid;
1389 place-items: center;
1390 padding: 0;
1391 color: #8a94a6;
1392 cursor: default;
1393 }
1394
1395 .tip-arrows-slot img {
1396 width: 40px;
1397 height: 40px;
1398 object-fit: contain;
1399 image-rendering: pixelated;
1400 }
1401
1402 .tip-arrows-slot .qty {
1403 position: absolute;
1404 right: 2px;
1405 bottom: 1px;
1406 font-size: 0.7rem;
1407 }
1408
1409 .tip-arrows-pick {
1410 cursor: pointer;
1411 }
1412
1413 .tip-arrows-arrow {
1414 opacity: 0.6;
1415 }
1416
1417 .tip-arrows-qty-label {
1418 display: flex;
1419 flex-direction: column;
1420 gap: 0.25rem;
1421 font-size: 0.85rem;
1422 margin-bottom: 0.5rem;
1423 }
1424
1425 .tip-arrows-qty {
1426 width: 6rem;
1427 padding: 0.25rem 0.4rem;
1428 background: #12161d;
1429 border: 1px solid #3a4454;
1430 color: inherit;
1431 }
1432
1433 .tip-arrows-actions {
1434 display: flex;
1435 gap: 0.5rem;
1436 margin-top: 0.75rem;
1437 }
1438
1439 .tip-arrows-picker {
1440 margin-top: 0.75rem;
1441 max-height: 180px;
1442 overflow: auto;
1443 display: flex;
1444 flex-direction: column;
1445 gap: 0.35rem;
1446 }
1447
1448 .tip-arrows-pick-option {
1449 display: flex;
1450 align-items: center;
1451 gap: 0.5rem;
1452 padding: 0.35rem 0.5rem;
1453 background: #12161d;
1454 border: 1px solid #2c3340;
1455 color: inherit;
1456 cursor: pointer;
1457 text-align: left;
1458 }
1459
1460 .tip-arrows-pick-option img {
1461 width: 28px;
1462 height: 28px;
1463 object-fit: contain;
1464 image-rendering: pixelated;
1465 }
1466
1348 1467 .send-item {
1349 1468 display: flex;
1350 1469 align-items: center;
@@ -1345,6 +1345,125 @@ button.friend-account-name:hover {
1345 display: none !important;
1345 display: none !important;
1346}
1346}
1347
1347
1348#tip-arrows-panel {
1349 position: fixed;
1350 z-index: 6;
1351 top: 50%;
1352 left: 50%;
1353 transform: translate(-50%, -50%);
1354 width: min(360px, 92vw);
1355 padding: 1rem 1.1rem 1.1rem;
1356 background: #1a1e26;
1357 border: 1px solid #2c3340;
1358 border-radius: 6px;
1359 color: #d6dbe4;
1360}
1361
1362#tip-arrows-panel h2 {
1363 margin: 0 0 0.35rem;
1364 font-size: 1.05rem;
1365}
1366
1367.tip-arrows-hint,
1368.tip-arrows-capacity {
1369 margin: 0.25rem 0 0.75rem;
1370 font-size: 0.85rem;
1371 opacity: 0.85;
1372}
1373
1374.tip-arrows-row {
1375 display: flex;
1376 align-items: center;
1377 justify-content: center;
1378 gap: 0.75rem;
1379 margin: 0.75rem 0;
1380}
1381
1382.tip-arrows-slot {
1383 position: relative;
1384 width: 48px;
1385 height: 48px;
1386 border: 1px solid #3a4454;
1387 background: #12161d;
1388 display: grid;
1389 place-items: center;
1390 padding: 0;
1391 color: #8a94a6;
1392 cursor: default;
1393}
1394
1395.tip-arrows-slot img {
1396 width: 40px;
1397 height: 40px;
1398 object-fit: contain;
1399 image-rendering: pixelated;
1400}
1401
1402.tip-arrows-slot .qty {
1403 position: absolute;
1404 right: 2px;
1405 bottom: 1px;
1406 font-size: 0.7rem;
1407}
1408
1409.tip-arrows-pick {
1410 cursor: pointer;
1411}
1412
1413.tip-arrows-arrow {
1414 opacity: 0.6;
1415}
1416
1417.tip-arrows-qty-label {
1418 display: flex;
1419 flex-direction: column;
1420 gap: 0.25rem;
1421 font-size: 0.85rem;
1422 margin-bottom: 0.5rem;
1423}
1424
1425.tip-arrows-qty {
1426 width: 6rem;
1427 padding: 0.25rem 0.4rem;
1428 background: #12161d;
1429 border: 1px solid #3a4454;
1430 color: inherit;
1431}
1432
1433.tip-arrows-actions {
1434 display: flex;
1435 gap: 0.5rem;
1436 margin-top: 0.75rem;
1437}
1438
1439.tip-arrows-picker {
1440 margin-top: 0.75rem;
1441 max-height: 180px;
1442 overflow: auto;
1443 display: flex;
1444 flex-direction: column;
1445 gap: 0.35rem;
1446}
1447
1448.tip-arrows-pick-option {
1449 display: flex;
1450 align-items: center;
1451 gap: 0.5rem;
1452 padding: 0.35rem 0.5rem;
1453 background: #12161d;
1454 border: 1px solid #2c3340;
1455 color: inherit;
1456 cursor: pointer;
1457 text-align: left;
1458}
1459
1460.tip-arrows-pick-option img {
1461 width: 28px;
1462 height: 28px;
1463 object-fit: contain;
1464 image-rendering: pixelated;
1465}
1466
1348.send-item {
1467.send-item {
1349 display: flex;
1468 display: flex;
1350 align-items: center;
1469 align-items: center;
server/src/combat/service.js +64 −9
@@ -13,6 +13,8 @@ import
13 13 } from "../../../shared/definitions/mobCombat.js";
14 14 import { spellDefinition } from "../../../shared/definitions/spells.js";
15 15 import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16 import { mobDamageAffinities } from "../../../shared/combat/magic.js";
17 import { AttackType } from "../../../shared/definitions/attackTypes.js";
16 18 import
17 19 {
18 20 effectiveHitSkillInDarkness,
@@ -42,6 +44,7 @@ import { tileToChunk } from "../world/coordinates.js";
42 44 import { stackQuantity } from "../../../shared/items/inventory.js";
43 45 import { addGroundItem, publicGroundItem } from "../items/bags.js";
44 46 import { resolveItemDualTint } from "../../../shared/render/tint.js";
47 import { essenceItemIdForElement } from "../../../shared/definitions/essenceItems.js";
45 48 import { castMobAttackSpell } from "../spells/mobCast.js";
46 49 import { attachOrigins, lootOrigin } from "../../../shared/items/origin.js";
47 50 import { scheduleSpawnerRespawn } from "../simulation/spawners.js";
@@ -219,6 +222,18 @@ function arrowStackInOffhand (equipment)
219 222 return stack;
220 223 }
221 224
225 /** Physical attack type, or tipped-arrow magic element when present. */
226 function resolveAttackDamageType (ecs, attackerHandle, profile)
227 {
228 if (attackerHandle != null && profile?.mode === "ranged")
229 {
230 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
231 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
232 { return stack.instance.element; }
233 }
234 return profile?.attackType ?? AttackType.blunt;
235 }
236
222 237 function consumeArrow (ecs, handle)
223 238 {
224 239 const equipment = ecs.get(handle, Component.equipment);
@@ -267,6 +282,12 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now, attackerId = nul
267 282 ...(def?.drops ?? []),
268 283 ...(Array.isArray(spawnOrigin?.drops) ? spawnOrigin.drops : [])
269 284 ];
285 if (creature.element && (def?.essenceDropChance ?? 0) > 0)
286 {
287 const essenceId = essenceItemIdForElement(creature.element);
288 if (essenceId)
289 { dropTable.push({ itemId: essenceId, chance: def.essenceDropChance }); }
290 }
270 291 for (const drop of dropTable)
271 292 {
272 293 if (Math.random() > (drop.chance ?? 1))
@@ -327,13 +348,23 @@ function projectileDualTintFromAttacker (ecs, handle)
327 348 return resolveItemDualTint(stack, itemDefinition(stack.itemId));
328 349 }
329 350
351 function projectileSpriteFromAttacker (ecs, handle)
352 {
353 const equipment = ecs.get(handle, Component.equipment);
354 const stack = arrowStackInOffhand(equipment);
355 if (stack?.instance?.kind === "tipped-arrow")
356 { return "fx:projectile:arrow-tipped"; }
357 return "fx:projectile:arrow";
358 }
359
330 360 function publicDualTint (dualTint)
331 361 {
332 362 if (!dualTint)
333 363 { return null; }
334 364 return {
335 365 shaftTint: dualTint.shaft,
336 tipTint: dualTint.tip
366 tipTint: dualTint.tip,
367 ...(dualTint.coat ? { coatTint: dualTint.coat } : {})
337 368 };
338 369 }
339 370
@@ -543,7 +574,9 @@ export function stepCombat (world, now = Date.now())
543 574 && dist === 1
544 575 && world.isClearStanding?.(entity.entityId, entity.position.tileX, entity.position.tileY);
545 576 const attackSpells = isCreature ? eligibleMobAttackSpells(world.ecs, entity.handle) : [];
546 const shouldCast = isCreature && attackSpells.length > 0 && (isStaff || !canSwing);
577 const preferSpell = isCreature
578 && !!mobDefinition(world.ecs.get(entity.handle, Component.creature)?.mobTypeId)?.preferSpellAttack;
579 const shouldCast = isCreature && attackSpells.length > 0 && (isStaff || !canSwing || preferSpell);
547 580
548 581 if (shouldCast)
549 582 {
@@ -871,9 +904,20 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
871 904 { return events; }
872 905 const isCreature = !!world.ecs.get(attackerHandle, Component.creature)
873 906 && !world.ecs.get(attackerHandle, Component.character);
907 const arrowTint = projectileDualTintFromAttacker(world.ecs, attackerHandle);
908 const arrowSprite = projectileSpriteFromAttacker(world.ecs, attackerHandle);
909 const tipElement = (() =>
910 {
911 const stack = arrowStackInOffhand(world.ecs.get(attackerHandle, Component.equipment));
912 return stack?.instance?.kind === "tipped-arrow" ? stack.instance.element : null;
913 })();
874 914 if (!isCreature && !consumeArrow(world.ecs, attackerHandle))
875 915 { return events; }
876 916
917 const shotProfile = tipElement
918 ? { ...profile, attackType: tipElement }
919 : profile;
920
877 921 const snapshot = { tileX: targetPos.tileX, tileY: targetPos.tileY };
878 922 const target = resolveCombatTarget(world, targetId);
879 923 if (!target)
@@ -885,15 +929,16 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
885 929 type: "remote-ranged-resolve",
886 930 attackerId,
887 931 targetId,
888 profile,
889 attackerLevels: attackerCombatLevels(world.ecs, attackerHandle, profile, world.settings),
932 profile: shotProfile,
933 attackerLevels: attackerCombatLevels(world.ecs, attackerHandle, shotProfile, world.settings),
890 934 attackerIsPlayer: !!world.ecs.get(attackerHandle, Component.character),
891 935 now,
892 936 tileX: snapshot.tileX,
893 937 tileY: snapshot.tileY,
894 938 fromTileX: from.tileX,
895 939 fromTileY: from.tileY,
896 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
940 sprite: arrowSprite,
941 ...(publicDualTint(arrowTint) ?? {})
897 942 });
898 943 return events;
899 944 }
@@ -904,7 +949,7 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
904 949 targetId,
905 950 attackerHandle,
906 951 target.handle,
907 profile,
952 shotProfile,
908 953 now,
909 954 snapshot
910 955 );
@@ -937,7 +982,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
937 982 tileY: endY,
938 983 durationMs: RANGED_PROJECTILE_MS,
939 984 trackTarget: outcome?.type !== "combat-miss",
940 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
985 sprite: arrowSprite,
986 ...(publicDualTint(arrowTint) ?? {})
941 987 });
942 988 return events.concat(hitEvents);
943 989 }
@@ -1132,8 +1178,10 @@ export function applyRemoteRangedShot (world, payload)
1132 1178 tileY: endY,
1133 1179 durationMs: RANGED_PROJECTILE_MS,
1134 1180 trackTarget: outcome?.type !== "combat-miss",
1181 sprite: payload.sprite ?? "fx:projectile:arrow",
1135 1182 shaftTint: payload.shaftTint ?? null,
1136 tipTint: payload.tipTint ?? null
1183 tipTint: payload.tipTint ?? null,
1184 coatTint: payload.coatTint ?? null
1137 1185 }, ...hitEvents];
1138 1186
1139 1187 const forwards = [];
@@ -1250,6 +1298,11 @@ function applyLocalMeleeHit (
1250 1298 world.settings
1251 1299 );
1252 1300
1301 const attackType = resolveAttackDamageType(world.ecs, attackerHandle, profile);
1302 const targetCreature = world.ecs.get(targetHandle, Component.creature);
1303 const targetAffinities = targetCreature
1304 ? mobDamageAffinities(mobDefinition(targetCreature.mobTypeId))
1305 : {};
1253 1306 const resolved = resolvePhysicalAttack({
1254 1307 hitSkillLevel: effectiveHitSkillInDarkness(
1255 1308 attackerLevels.hitLevel,
@@ -1257,7 +1310,9 @@ function applyLocalMeleeHit (
1257 1310 ),
1258 1311 agilitySkillLevel: agilityLevel,
1259 1312 damageSkillLevel: attackerLevels.damageLevel,
1260 defenceSkillLevel: defenceLevel
1313 defenceSkillLevel: defenceLevel,
1314 attackType,
1315 targetAffinities
1261 1316 });
1262 1317
1263 1318 if (resolved.outcome === "miss")
@@ -13,6 +13,8 @@ import
13 } from "../../../shared/definitions/mobCombat.js";
13 } from "../../../shared/definitions/mobCombat.js";
14import { spellDefinition } from "../../../shared/definitions/spells.js";
14import { spellDefinition } from "../../../shared/definitions/spells.js";
15import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
15import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16import { mobDamageAffinities } from "../../../shared/combat/magic.js";
17import { AttackType } from "../../../shared/definitions/attackTypes.js";
16import
18import
17 {
19 {
18 effectiveHitSkillInDarkness,
20 effectiveHitSkillInDarkness,
@@ -42,6 +44,7 @@ import { tileToChunk } from "../world/coordinates.js";
42import { stackQuantity } from "../../../shared/items/inventory.js";
44import { stackQuantity } from "../../../shared/items/inventory.js";
43import { addGroundItem, publicGroundItem } from "../items/bags.js";
45import { addGroundItem, publicGroundItem } from "../items/bags.js";
44import { resolveItemDualTint } from "../../../shared/render/tint.js";
46import { resolveItemDualTint } from "../../../shared/render/tint.js";
47import { essenceItemIdForElement } from "../../../shared/definitions/essenceItems.js";
45import { castMobAttackSpell } from "../spells/mobCast.js";
48import { castMobAttackSpell } from "../spells/mobCast.js";
46import { attachOrigins, lootOrigin } from "../../../shared/items/origin.js";
49import { attachOrigins, lootOrigin } from "../../../shared/items/origin.js";
47import { scheduleSpawnerRespawn } from "../simulation/spawners.js";
50import { scheduleSpawnerRespawn } from "../simulation/spawners.js";
@@ -219,6 +222,18 @@ function arrowStackInOffhand (equipment)
219 return stack;
222 return stack;
220}
223}
221
224
225/** Physical attack type, or tipped-arrow magic element when present. */
226function resolveAttackDamageType (ecs, attackerHandle, profile)
227{
228 if (attackerHandle != null && profile?.mode === "ranged")
229 {
230 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
231 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
232 { return stack.instance.element; }
233 }
234 return profile?.attackType ?? AttackType.blunt;
235}
236
222function consumeArrow (ecs, handle)
237function consumeArrow (ecs, handle)
223{
238{
224 const equipment = ecs.get(handle, Component.equipment);
239 const equipment = ecs.get(handle, Component.equipment);
@@ -267,6 +282,12 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now, attackerId = nul
267 ...(def?.drops ?? []),
282 ...(def?.drops ?? []),
268 ...(Array.isArray(spawnOrigin?.drops) ? spawnOrigin.drops : [])
283 ...(Array.isArray(spawnOrigin?.drops) ? spawnOrigin.drops : [])
269 ];
284 ];
285 if (creature.element && (def?.essenceDropChance ?? 0) > 0)
286 {
287 const essenceId = essenceItemIdForElement(creature.element);
288 if (essenceId)
289 { dropTable.push({ itemId: essenceId, chance: def.essenceDropChance }); }
290 }
270 for (const drop of dropTable)
291 for (const drop of dropTable)
271 {
292 {
272 if (Math.random() > (drop.chance ?? 1))
293 if (Math.random() > (drop.chance ?? 1))
@@ -327,13 +348,23 @@ function projectileDualTintFromAttacker (ecs, handle)
327 return resolveItemDualTint(stack, itemDefinition(stack.itemId));
348 return resolveItemDualTint(stack, itemDefinition(stack.itemId));
328}
349}
329
350
351function projectileSpriteFromAttacker (ecs, handle)
352{
353 const equipment = ecs.get(handle, Component.equipment);
354 const stack = arrowStackInOffhand(equipment);
355 if (stack?.instance?.kind === "tipped-arrow")
356 { return "fx:projectile:arrow-tipped"; }
357 return "fx:projectile:arrow";
358}
359
330function publicDualTint (dualTint)
360function publicDualTint (dualTint)
331{
361{
332 if (!dualTint)
362 if (!dualTint)
333 { return null; }
363 { return null; }
334 return {
364 return {
335 shaftTint: dualTint.shaft,
365 shaftTint: dualTint.shaft,
336 tipTint: dualTint.tip
366 tipTint: dualTint.tip,
367 ...(dualTint.coat ? { coatTint: dualTint.coat } : {})
337 };
368 };
338}
369}
339
370
@@ -543,7 +574,9 @@ export function stepCombat (world, now = Date.now())
543 && dist === 1
574 && dist === 1
544 && world.isClearStanding?.(entity.entityId, entity.position.tileX, entity.position.tileY);
575 && world.isClearStanding?.(entity.entityId, entity.position.tileX, entity.position.tileY);
545 const attackSpells = isCreature ? eligibleMobAttackSpells(world.ecs, entity.handle) : [];
576 const attackSpells = isCreature ? eligibleMobAttackSpells(world.ecs, entity.handle) : [];
546 const shouldCast = isCreature && attackSpells.length > 0 && (isStaff || !canSwing);
577 const preferSpell = isCreature
578 && !!mobDefinition(world.ecs.get(entity.handle, Component.creature)?.mobTypeId)?.preferSpellAttack;
579 const shouldCast = isCreature && attackSpells.length > 0 && (isStaff || !canSwing || preferSpell);
547
580
548 if (shouldCast)
581 if (shouldCast)
549 {
582 {
@@ -871,9 +904,20 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
871 { return events; }
904 { return events; }
872 const isCreature = !!world.ecs.get(attackerHandle, Component.creature)
905 const isCreature = !!world.ecs.get(attackerHandle, Component.creature)
873 && !world.ecs.get(attackerHandle, Component.character);
906 && !world.ecs.get(attackerHandle, Component.character);
907 const arrowTint = projectileDualTintFromAttacker(world.ecs, attackerHandle);
908 const arrowSprite = projectileSpriteFromAttacker(world.ecs, attackerHandle);
909 const tipElement = (() =>
910 {
911 const stack = arrowStackInOffhand(world.ecs.get(attackerHandle, Component.equipment));
912 return stack?.instance?.kind === "tipped-arrow" ? stack.instance.element : null;
913 })();
874 if (!isCreature && !consumeArrow(world.ecs, attackerHandle))
914 if (!isCreature && !consumeArrow(world.ecs, attackerHandle))
875 { return events; }
915 { return events; }
876
916
917 const shotProfile = tipElement
918 ? { ...profile, attackType: tipElement }
919 : profile;
920
877 const snapshot = { tileX: targetPos.tileX, tileY: targetPos.tileY };
921 const snapshot = { tileX: targetPos.tileX, tileY: targetPos.tileY };
878 const target = resolveCombatTarget(world, targetId);
922 const target = resolveCombatTarget(world, targetId);
879 if (!target)
923 if (!target)
@@ -885,15 +929,16 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
885 type: "remote-ranged-resolve",
929 type: "remote-ranged-resolve",
886 attackerId,
930 attackerId,
887 targetId,
931 targetId,
888 profile,
932 profile: shotProfile,
889 attackerLevels: attackerCombatLevels(world.ecs, attackerHandle, profile, world.settings),
933 attackerLevels: attackerCombatLevels(world.ecs, attackerHandle, shotProfile, world.settings),
890 attackerIsPlayer: !!world.ecs.get(attackerHandle, Component.character),
934 attackerIsPlayer: !!world.ecs.get(attackerHandle, Component.character),
891 now,
935 now,
892 tileX: snapshot.tileX,
936 tileX: snapshot.tileX,
893 tileY: snapshot.tileY,
937 tileY: snapshot.tileY,
894 fromTileX: from.tileX,
938 fromTileX: from.tileX,
895 fromTileY: from.tileY,
939 fromTileY: from.tileY,
896 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
940 sprite: arrowSprite,
941 ...(publicDualTint(arrowTint) ?? {})
897 });
942 });
898 return events;
943 return events;
899 }
944 }
@@ -904,7 +949,7 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
904 targetId,
949 targetId,
905 attackerHandle,
950 attackerHandle,
906 target.handle,
951 target.handle,
907 profile,
952 shotProfile,
908 now,
953 now,
909 snapshot
954 snapshot
910 );
955 );
@@ -937,7 +982,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
937 tileY: endY,
982 tileY: endY,
938 durationMs: RANGED_PROJECTILE_MS,
983 durationMs: RANGED_PROJECTILE_MS,
939 trackTarget: outcome?.type !== "combat-miss",
984 trackTarget: outcome?.type !== "combat-miss",
940 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
985 sprite: arrowSprite,
986 ...(publicDualTint(arrowTint) ?? {})
941 });
987 });
942 return events.concat(hitEvents);
988 return events.concat(hitEvents);
943}
989}
@@ -1132,8 +1178,10 @@ export function applyRemoteRangedShot (world, payload)
1132 tileY: endY,
1178 tileY: endY,
1133 durationMs: RANGED_PROJECTILE_MS,
1179 durationMs: RANGED_PROJECTILE_MS,
1134 trackTarget: outcome?.type !== "combat-miss",
1180 trackTarget: outcome?.type !== "combat-miss",
1181 sprite: payload.sprite ?? "fx:projectile:arrow",
1135 shaftTint: payload.shaftTint ?? null,
1182 shaftTint: payload.shaftTint ?? null,
1136 tipTint: payload.tipTint ?? null
1183 tipTint: payload.tipTint ?? null,
1184 coatTint: payload.coatTint ?? null
1137 }, ...hitEvents];
1185 }, ...hitEvents];
1138
1186
1139 const forwards = [];
1187 const forwards = [];
@@ -1250,6 +1298,11 @@ function applyLocalMeleeHit (
1250 world.settings
1298 world.settings
1251 );
1299 );
1252
1300
1301 const attackType = resolveAttackDamageType(world.ecs, attackerHandle, profile);
1302 const targetCreature = world.ecs.get(targetHandle, Component.creature);
1303 const targetAffinities = targetCreature
1304 ? mobDamageAffinities(mobDefinition(targetCreature.mobTypeId))
1305 : {};
1253 const resolved = resolvePhysicalAttack({
1306 const resolved = resolvePhysicalAttack({
1254 hitSkillLevel: effectiveHitSkillInDarkness(
1307 hitSkillLevel: effectiveHitSkillInDarkness(
1255 attackerLevels.hitLevel,
1308 attackerLevels.hitLevel,
@@ -1257,7 +1310,9 @@ function applyLocalMeleeHit (
1257 ),
1310 ),
1258 agilitySkillLevel: agilityLevel,
1311 agilitySkillLevel: agilityLevel,
1259 damageSkillLevel: attackerLevels.damageLevel,
1312 damageSkillLevel: attackerLevels.damageLevel,
1260 defenceSkillLevel: defenceLevel
1313 defenceSkillLevel: defenceLevel,
1314 attackType,
1315 targetAffinities
1261 });
1316 });
1262
1317
1263 if (resolved.outcome === "miss")
1318 if (resolved.outcome === "miss")
server/src/ecs/serialize.js +4 −1
@@ -81,6 +81,8 @@ export function publicEntityView (ecs, entityId)
81 81 const isMob = !!creature && !character;
82 82 const gearLight = equippedLightRadiusTiles(equipment);
83 83 const effectLight = statusExtraLightRadius(statusEffects, now);
84 const creatureLight = creature?.lightRadiusTiles
85 ?? (mob?.lightRadiusTiles ?? 0);
84 86 return {
85 87 entityId,
86 88 tileX: position.tileX,
@@ -95,6 +97,7 @@ export function publicEntityView (ecs, entityId)
95 97 characterId: character?.characterId ?? null,
96 98 accountId: character?.accountId ?? null,
97 99 mobTypeId: creature?.mobTypeId ?? null,
100 element: creature?.element ?? null,
98 101 canFight: mob ? mobCanFight(mob) : !!character,
99 102 hostile: !!mob?.hostile,
100 103 talkable: !!mob?.talkable || shopHasInterface(ecs.get(handle, Component.shop)),
@@ -107,7 +110,7 @@ export function publicEntityView (ecs, entityId)
107 110 maxHealth: health ? health.max : undefined,
108 111 sprite: layers[0]?.sprite ?? null,
109 112 layers,
110 lightRadiusTiles: Math.max(gearLight, effectLight),
113 lightRadiusTiles: Math.max(gearLight, effectLight, creatureLight),
111 114 visualScale: statusVisualScale(statusEffects, now),
112 115 statusEffects: publicStatusEffectsView(statusEffects, now)
113 116 };
@@ -81,6 +81,8 @@ export function publicEntityView (ecs, entityId)
81 const isMob = !!creature && !character;
81 const isMob = !!creature && !character;
82 const gearLight = equippedLightRadiusTiles(equipment);
82 const gearLight = equippedLightRadiusTiles(equipment);
83 const effectLight = statusExtraLightRadius(statusEffects, now);
83 const effectLight = statusExtraLightRadius(statusEffects, now);
84 const creatureLight = creature?.lightRadiusTiles
85 ?? (mob?.lightRadiusTiles ?? 0);
84 return {
86 return {
85 entityId,
87 entityId,
86 tileX: position.tileX,
88 tileX: position.tileX,
@@ -95,6 +97,7 @@ export function publicEntityView (ecs, entityId)
95 characterId: character?.characterId ?? null,
97 characterId: character?.characterId ?? null,
96 accountId: character?.accountId ?? null,
98 accountId: character?.accountId ?? null,
97 mobTypeId: creature?.mobTypeId ?? null,
99 mobTypeId: creature?.mobTypeId ?? null,
100 element: creature?.element ?? null,
98 canFight: mob ? mobCanFight(mob) : !!character,
101 canFight: mob ? mobCanFight(mob) : !!character,
99 hostile: !!mob?.hostile,
102 hostile: !!mob?.hostile,
100 talkable: !!mob?.talkable || shopHasInterface(ecs.get(handle, Component.shop)),
103 talkable: !!mob?.talkable || shopHasInterface(ecs.get(handle, Component.shop)),
@@ -107,7 +110,7 @@ export function publicEntityView (ecs, entityId)
107 maxHealth: health ? health.max : undefined,
110 maxHealth: health ? health.max : undefined,
108 sprite: layers[0]?.sprite ?? null,
111 sprite: layers[0]?.sprite ?? null,
109 layers,
112 layers,
110 lightRadiusTiles: Math.max(gearLight, effectLight),
113 lightRadiusTiles: Math.max(gearLight, effectLight, creatureLight),
111 visualScale: statusVisualScale(statusEffects, now),
114 visualScale: statusVisualScale(statusEffects, now),
112 statusEffects: publicStatusEffectsView(statusEffects, now)
115 statusEffects: publicStatusEffectsView(statusEffects, now)
113 };
116 };
server/src/gateway/websocket.js +10 −0
@@ -286,6 +286,16 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
286 286 slotIndex: message.slotIndex | 0
287 287 });
288 288 break;
289 case MessageType.tipArrows:
290 requirePlaying(session);
291 simulation.enqueue(session.id, {
292 type: "tip-arrows",
293 characterId: session.characterId,
294 coatingSlotIndex: message.coatingSlotIndex | 0,
295 arrowSlotIndex: message.arrowSlotIndex | 0,
296 quantity: message.quantity | 0
297 });
298 break;
289 299 case MessageType.openBank:
290 300 requirePlaying(session);
291 301 simulation.enqueue(session.id, {
@@ -286,6 +286,16 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
286 slotIndex: message.slotIndex | 0
286 slotIndex: message.slotIndex | 0
287 });
287 });
288 break;
288 break;
289 case MessageType.tipArrows:
290 requirePlaying(session);
291 simulation.enqueue(session.id, {
292 type: "tip-arrows",
293 characterId: session.characterId,
294 coatingSlotIndex: message.coatingSlotIndex | 0,
295 arrowSlotIndex: message.arrowSlotIndex | 0,
296 quantity: message.quantity | 0
297 });
298 break;
289 case MessageType.openBank:
299 case MessageType.openBank:
290 requirePlaying(session);
300 requirePlaying(session);
291 simulation.enqueue(session.id, {
301 simulation.enqueue(session.id, {
server/src/items/bags.js +91 −0
@@ -29,6 +29,7 @@ import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
29 29 import { randomUUID } from "node:crypto";
30 30 import { tileShoveTowardBlock } from "../simulation/tileInteract.js";
31 31 import { resolvePotionEffect } from "../../../shared/alchemy/recipes.js";
32 import { ARROW_COATING_ARROWS_PER_USE } from "../../../shared/definitions/alchemy.js";
32 33 import
33 34 {
34 35 applyStatusEffect,
@@ -175,6 +176,8 @@ export function handleItemCommand (world, sessionId, command, now)
175 176 return eatItem(world, sessionId, command);
176 177 case "drink-item":
177 178 return drinkItem(world, sessionId, command);
179 case "tip-arrows":
180 return tipArrows(world, sessionId, command);
178 181 default:
179 182 return null;
180 183 }
@@ -533,6 +536,91 @@ function drinkItem (world, sessionId, command)
533 536 };
534 537 }
535 538
539 /**
540 * Apply an arrow-coating potion to untipped arrows in the bag.
541 * Consumes one coating fill charge; tips up to ARROW_COATING_ARROWS_PER_USE arrows.
542 */
543 function tipArrows (world, sessionId, command)
544 {
545 const { handle } = world.requireOwnedEntity(sessionId, command.characterId);
546 const inventory = ensureInventory(world.ecs, handle);
547 const coatingSlotIndex = command.coatingSlotIndex | 0;
548 const arrowSlotIndex = command.arrowSlotIndex | 0;
549 const wantQty = Math.max(1, command.quantity | 0 || 1);
550
551 const coating = inventory.slots[coatingSlotIndex];
552 if (!coating || coating.itemId !== ItemId.potion || coating.instance?.kind !== "potion")
553 { throw userError("That is not a coating."); }
554 const effect = coating.instance.effect
555 ?? resolvePotionEffect(coating.instance);
556 if (effect?.type !== "arrow-coating" || !effect.element)
557 { throw userError("That brew cannot tip arrows."); }
558 const element = effect.element;
559
560 const arrowSlot = inventory.slots[arrowSlotIndex];
561 if (!arrowSlot)
562 { throw userError("Select arrows to tip."); }
563 const arrowDef = itemDefinition(arrowSlot.itemId);
564 if (arrowDef?.equipment?.kind !== EquipmentKind.arrowAmmo)
565 { throw userError("That is not an arrow."); }
566 if (arrowSlot.instance?.kind === "tipped-arrow")
567 { throw userError("Those arrows are already tipped."); }
568
569 const available = stackQuantity(arrowSlot.quantity);
570 const tipQty = Math.min(wantQty, available, ARROW_COATING_ARROWS_PER_USE);
571 if (tipQty <= 0)
572 { throw userError("No arrows to tip."); }
573
574 const taken = takeFromSlot(inventory.slots, arrowSlotIndex, tipQty);
575 if (!taken.ok || !taken.taken)
576 { throw userError("Could not take those arrows."); }
577 inventory.slots = taken.slots;
578
579 const tipped = attachOrigins({
580 itemId: arrowSlot.itemId,
581 quantity: tipQty,
582 instance: { kind: "tipped-arrow", element },
583 origins: taken.taken.origins ?? []
584 });
585 const inserted = insertStack(inventory.slots, tipped, itemDefinition(arrowSlot.itemId));
586 if (!inserted.ok || inserted.remainder > 0)
587 {
588 const refund = insertStack(
589 inventory.slots,
590 attachOrigins({
591 itemId: arrowSlot.itemId,
592 quantity: tipQty,
593 instance: null,
594 origins: taken.taken.origins ?? []
595 }),
596 arrowDef
597 );
598 inventory.slots = refund.slots;
599 throw userError("Need bag space for the tipped arrows.");
600 }
601 inventory.slots = inserted.slots;
602
603 const consumed = consumeFillCharge(inventory.slots, coatingSlotIndex, {
604 kind: "potion",
605 itemId: ItemId.potion,
606 returnEmptyItemId: ItemId.glassBottle
607 });
608 if (!consumed.ok)
609 {
610 throw userError(
611 consumed.reason === "space"
612 ? "Need bag space to keep the partially used coating (or empty bottle)."
613 : "That coating is gone."
614 );
615 }
616 inventory.slots = consumed.slots;
617
618 return {
619 events: [],
620 private: bagView(world.ecs, handle)
621 };
622 }
623
536 624 function ensureStatusEffects (ecs, handle)
537 625 {
538 626 let component = ecs.get(handle, Component.statusEffects);
@@ -557,6 +645,9 @@ function applyPotionEffect (ecs, handle, effect)
557 645 const health = ecs.get(handle, Component.health);
558 646 const type = effect.type;
559 647
648 if (type === "arrow-coating")
649 { return result; }
650
560 651 if (type === "heal" && health)
561 652 {
562 653 const amount = Math.max(0, effect.amount | 0 || 0);
@@ -29,6 +29,7 @@ import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
29import { randomUUID } from "node:crypto";
29import { randomUUID } from "node:crypto";
30import { tileShoveTowardBlock } from "../simulation/tileInteract.js";
30import { tileShoveTowardBlock } from "../simulation/tileInteract.js";
31import { resolvePotionEffect } from "../../../shared/alchemy/recipes.js";
31import { resolvePotionEffect } from "../../../shared/alchemy/recipes.js";
32import { ARROW_COATING_ARROWS_PER_USE } from "../../../shared/definitions/alchemy.js";
32import
33import
33 {
34 {
34 applyStatusEffect,
35 applyStatusEffect,
@@ -175,6 +176,8 @@ export function handleItemCommand (world, sessionId, command, now)
175 return eatItem(world, sessionId, command);
176 return eatItem(world, sessionId, command);
176 case "drink-item":
177 case "drink-item":
177 return drinkItem(world, sessionId, command);
178 return drinkItem(world, sessionId, command);
179 case "tip-arrows":
180 return tipArrows(world, sessionId, command);
178 default:
181 default:
179 return null;
182 return null;
180 }
183 }
@@ -533,6 +536,91 @@ function drinkItem (world, sessionId, command)
533 };
536 };
534}
537}
535
538
539/**
540 * Apply an arrow-coating potion to untipped arrows in the bag.
541 * Consumes one coating fill charge; tips up to ARROW_COATING_ARROWS_PER_USE arrows.
542 */
543function tipArrows (world, sessionId, command)
544{
545 const { handle } = world.requireOwnedEntity(sessionId, command.characterId);
546 const inventory = ensureInventory(world.ecs, handle);
547 const coatingSlotIndex = command.coatingSlotIndex | 0;
548 const arrowSlotIndex = command.arrowSlotIndex | 0;
549 const wantQty = Math.max(1, command.quantity | 0 || 1);
550
551 const coating = inventory.slots[coatingSlotIndex];
552 if (!coating || coating.itemId !== ItemId.potion || coating.instance?.kind !== "potion")
553 { throw userError("That is not a coating."); }
554 const effect = coating.instance.effect
555 ?? resolvePotionEffect(coating.instance);
556 if (effect?.type !== "arrow-coating" || !effect.element)
557 { throw userError("That brew cannot tip arrows."); }
558 const element = effect.element;
559
560 const arrowSlot = inventory.slots[arrowSlotIndex];
561 if (!arrowSlot)
562 { throw userError("Select arrows to tip."); }
563 const arrowDef = itemDefinition(arrowSlot.itemId);
564 if (arrowDef?.equipment?.kind !== EquipmentKind.arrowAmmo)
565 { throw userError("That is not an arrow."); }
566 if (arrowSlot.instance?.kind === "tipped-arrow")
567 { throw userError("Those arrows are already tipped."); }
568
569 const available = stackQuantity(arrowSlot.quantity);
570 const tipQty = Math.min(wantQty, available, ARROW_COATING_ARROWS_PER_USE);
571 if (tipQty <= 0)
572 { throw userError("No arrows to tip."); }
573
574 const taken = takeFromSlot(inventory.slots, arrowSlotIndex, tipQty);
575 if (!taken.ok || !taken.taken)
576 { throw userError("Could not take those arrows."); }
577 inventory.slots = taken.slots;
578
579 const tipped = attachOrigins({
580 itemId: arrowSlot.itemId,
581 quantity: tipQty,
582 instance: { kind: "tipped-arrow", element },
583 origins: taken.taken.origins ?? []
584 });
585 const inserted = insertStack(inventory.slots, tipped, itemDefinition(arrowSlot.itemId));
586 if (!inserted.ok || inserted.remainder > 0)
587 {
588 const refund = insertStack(
589 inventory.slots,
590 attachOrigins({
591 itemId: arrowSlot.itemId,
592 quantity: tipQty,
593 instance: null,
594 origins: taken.taken.origins ?? []
595 }),
596 arrowDef
597 );
598 inventory.slots = refund.slots;
599 throw userError("Need bag space for the tipped arrows.");
600 }
601 inventory.slots = inserted.slots;
602
603 const consumed = consumeFillCharge(inventory.slots, coatingSlotIndex, {
604 kind: "potion",
605 itemId: ItemId.potion,
606 returnEmptyItemId: ItemId.glassBottle
607 });
608 if (!consumed.ok)
609 {
610 throw userError(
611 consumed.reason === "space"
612 ? "Need bag space to keep the partially used coating (or empty bottle)."
613 : "That coating is gone."
614 );
615 }
616 inventory.slots = consumed.slots;
617
618 return {
619 events: [],
620 private: bagView(world.ecs, handle)
621 };
622}
623
536function ensureStatusEffects (ecs, handle)
624function ensureStatusEffects (ecs, handle)
537{
625{
538 let component = ecs.get(handle, Component.statusEffects);
626 let component = ecs.get(handle, Component.statusEffects);
@@ -557,6 +645,9 @@ function applyPotionEffect (ecs, handle, effect)
557 const health = ecs.get(handle, Component.health);
645 const health = ecs.get(handle, Component.health);
558 const type = effect.type;
646 const type = effect.type;
559
647
648 if (type === "arrow-coating")
649 { return result; }
650
560 if (type === "heal" && health)
651 if (type === "heal" && health)
561 {
652 {
562 const amount = Math.max(0, effect.amount | 0 || 0);
653 const amount = Math.max(0, effect.amount | 0 || 0);
server/src/simulation/spawners.js +26 −3
@@ -15,7 +15,8 @@ import {
15 15 isTownGuardMob,
16 16 isHumanoidMob
17 17 } from "../../../shared/definitions/mobs.js";
18 import { spellDefinition } from "../../../shared/definitions/spells.js";
18 import { spellDefinition, SPRITE_BOLT_SPELL_BY_ELEMENT } from "../../../shared/definitions/spells.js";
19 import { MAGIC_ELEMENT_ORDER, magicElementTint } from "../../../shared/definitions/attackTypes.js";
19 20 import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";
20 21 import { CENTRAL_EXCHANGE_STAFF } from "../../../shared/market/exchange.js";
21 22 import { emptyEquipment } from "../../../shared/items/inventory.js";
@@ -236,6 +237,17 @@ export function mobComponents (request)
236 237 { appearance.sprite = sprite; }
237 238 }
238 239
240 let element = request.element ?? null;
241 if (def.randomElementOnSpawn && !element)
242 {
243 element = MAGIC_ELEMENT_ORDER[Math.floor(Math.random() * MAGIC_ELEMENT_ORDER.length)];
244 }
245 if (element)
246 {
247 appearance.tint = magicElementTint(element);
248 appearance.bloomBody = !!def.bloomBody;
249 }
250
239 251 const maxHp = mobHealthForLevel(def, level);
240 252 const components = {
241 253 position: {
@@ -246,7 +258,12 @@ export function mobComponents (request)
246 258 movement: { gait: def.gait ?? GAIT.walk, walkCarry: 0 },
247 259 path: { tiles: [] },
248 260 appearance,
249 creature: { mobTypeId: def.mobTypeId, level },
261 creature: {
262 mobTypeId: def.mobTypeId,
263 level,
264 ...(element ? { element } : {}),
265 ...(def.lightRadiusTiles ? { lightRadiusTiles: def.lightRadiusTiles } : {})
266 },
250 267 health: { current: maxHp, max: maxHp }
251 268 };
252 269 if (request.spawnerId)
@@ -296,9 +313,15 @@ export function mobComponents (request)
296 313 }
297 314
298 315 const knownSpells = normalizeMobSpells(request.spells, level);
316 if (element && SPRITE_BOLT_SPELL_BY_ELEMENT[element])
317 {
318 const boltId = SPRITE_BOLT_SPELL_BY_ELEMENT[element];
319 if (!knownSpells.some((entry) => entry.spellId === boltId))
320 { knownSpells.push({ spellId: boltId }); }
321 }
299 322 if (knownSpells.length)
300 323 {
301 const castChance = mobSpellCastChancePercent(level);
324 const castChance = element ? 100 : mobSpellCastChancePercent(level);
302 325 components.spells = {
303 326 known: knownSpells.map((entry) => entry.spellId),
304 327 favorites: [],
@@ -15,7 +15,8 @@ import {
15 isTownGuardMob,
15 isTownGuardMob,
16 isHumanoidMob
16 isHumanoidMob
17} from "../../../shared/definitions/mobs.js";
17} from "../../../shared/definitions/mobs.js";
18import { spellDefinition } from "../../../shared/definitions/spells.js";
18import { spellDefinition, SPRITE_BOLT_SPELL_BY_ELEMENT } from "../../../shared/definitions/spells.js";
19import { MAGIC_ELEMENT_ORDER, magicElementTint } from "../../../shared/definitions/attackTypes.js";
19import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";
20import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";
20import { CENTRAL_EXCHANGE_STAFF } from "../../../shared/market/exchange.js";
21import { CENTRAL_EXCHANGE_STAFF } from "../../../shared/market/exchange.js";
21import { emptyEquipment } from "../../../shared/items/inventory.js";
22import { emptyEquipment } from "../../../shared/items/inventory.js";
@@ -236,6 +237,17 @@ export function mobComponents (request)
236 { appearance.sprite = sprite; }
237 { appearance.sprite = sprite; }
237 }
238 }
238
239
240 let element = request.element ?? null;
241 if (def.randomElementOnSpawn && !element)
242 {
243 element = MAGIC_ELEMENT_ORDER[Math.floor(Math.random() * MAGIC_ELEMENT_ORDER.length)];
244 }
245 if (element)
246 {
247 appearance.tint = magicElementTint(element);
248 appearance.bloomBody = !!def.bloomBody;
249 }
250
239 const maxHp = mobHealthForLevel(def, level);
251 const maxHp = mobHealthForLevel(def, level);
240 const components = {
252 const components = {
241 position: {
253 position: {
@@ -246,7 +258,12 @@ export function mobComponents (request)
246 movement: { gait: def.gait ?? GAIT.walk, walkCarry: 0 },
258 movement: { gait: def.gait ?? GAIT.walk, walkCarry: 0 },
247 path: { tiles: [] },
259 path: { tiles: [] },
248 appearance,
260 appearance,
249 creature: { mobTypeId: def.mobTypeId, level },
261 creature: {
262 mobTypeId: def.mobTypeId,
263 level,
264 ...(element ? { element } : {}),
265 ...(def.lightRadiusTiles ? { lightRadiusTiles: def.lightRadiusTiles } : {})
266 },
250 health: { current: maxHp, max: maxHp }
267 health: { current: maxHp, max: maxHp }
251 };
268 };
252 if (request.spawnerId)
269 if (request.spawnerId)
@@ -296,9 +313,15 @@ export function mobComponents (request)
296 }
313 }
297
314
298 const knownSpells = normalizeMobSpells(request.spells, level);
315 const knownSpells = normalizeMobSpells(request.spells, level);
316 if (element && SPRITE_BOLT_SPELL_BY_ELEMENT[element])
317 {
318 const boltId = SPRITE_BOLT_SPELL_BY_ELEMENT[element];
319 if (!knownSpells.some((entry) => entry.spellId === boltId))
320 { knownSpells.push({ spellId: boltId }); }
321 }
299 if (knownSpells.length)
322 if (knownSpells.length)
300 {
323 {
301 const castChance = mobSpellCastChancePercent(level);
324 const castChance = element ? 100 : mobSpellCastChancePercent(level);
302 components.spells = {
325 components.spells = {
303 known: knownSpells.map((entry) => entry.spellId),
326 known: knownSpells.map((entry) => entry.spellId),
304 favorites: [],
327 favorites: [],
server/src/spells/service.js +2 −1
@@ -23,6 +23,7 @@ import
23 23 } from "../../../shared/spells/constants.js";
24 24 import
25 25 {
26 mobDamageAffinities,
26 27 mobElementAffinities,
27 28 ElementMultiplier,
28 29 resolveMagicAttack,
@@ -469,7 +470,7 @@ function targetAffinitiesForEntity (world, entityId)
469 470 const creature = world.ecs.get(handle, Component.creature);
470 471 if (!creature)
471 472 { return {}; }
472 return mobElementAffinities(mobDefinition(creature.mobTypeId));
473 return mobDamageAffinities(mobDefinition(creature.mobTypeId));
473 474 }
474 475
475 476 function applySpellImpact (world, impact, now)
@@ -23,6 +23,7 @@ import
23} from "../../../shared/spells/constants.js";
23} from "../../../shared/spells/constants.js";
24import
24import
25{
25{
26 mobDamageAffinities,
26 mobElementAffinities,
27 mobElementAffinities,
27 ElementMultiplier,
28 ElementMultiplier,
28 resolveMagicAttack,
29 resolveMagicAttack,
@@ -469,7 +470,7 @@ function targetAffinitiesForEntity (world, entityId)
469 const creature = world.ecs.get(handle, Component.creature);
470 const creature = world.ecs.get(handle, Component.creature);
470 if (!creature)
471 if (!creature)
471 { return {}; }
472 { return {}; }
472 return mobElementAffinities(mobDefinition(creature.mobTypeId));
473 return mobDamageAffinities(mobDefinition(creature.mobTypeId));
473}
474}
474
475
475function applySpellImpact (world, impact, now)
476function applySpellImpact (world, impact, now)
server/tests/combatRolls.test.js +33 −0
@@ -91,6 +91,39 @@ test("physical attack hit applies rolled damage when not blocked", () =>
91 91 assert.equal(result.damage, 3);
92 92 });
93 93
94 test("physical attack applies weakness and resistance multipliers", () =>
95 {
96 let i = 0;
97 const rolls = [0.9, 0, 0.5, 0];
98 const rng = () => rolls[i++];
99 const weak = resolvePhysicalAttack({
100 hitSkillLevel: 10,
101 agilitySkillLevel: 1,
102 damageSkillLevel: 5,
103 defenceSkillLevel: 1,
104 attackType: "slashing",
105 targetAffinities: { slashing: "weak" },
106 rng
107 });
108 assert.equal(weak.outcome, "hit");
109 assert.equal(weak.damage, 6);
110 assert.equal(weak.multiplier, 2);
111
112 i = 0;
113 const resist = resolvePhysicalAttack({
114 hitSkillLevel: 10,
115 agilitySkillLevel: 1,
116 damageSkillLevel: 5,
117 defenceSkillLevel: 1,
118 attackType: "blunt",
119 targetAffinities: { blunt: "resistant" },
120 rng
121 });
122 assert.equal(resist.outcome, "hit");
123 assert.equal(resist.damage, 1);
124 assert.equal(resist.multiplier, 0.5);
125 });
126
94 127 test("physical damage is the damage skill roll only", () =>
95 128 {
96 129 let i = 0;
@@ -91,6 +91,39 @@ test("physical attack hit applies rolled damage when not blocked", () =>
91 assert.equal(result.damage, 3);
91 assert.equal(result.damage, 3);
92});
92});
93
93
94test("physical attack applies weakness and resistance multipliers", () =>
95{
96 let i = 0;
97 const rolls = [0.9, 0, 0.5, 0];
98 const rng = () => rolls[i++];
99 const weak = resolvePhysicalAttack({
100 hitSkillLevel: 10,
101 agilitySkillLevel: 1,
102 damageSkillLevel: 5,
103 defenceSkillLevel: 1,
104 attackType: "slashing",
105 targetAffinities: { slashing: "weak" },
106 rng
107 });
108 assert.equal(weak.outcome, "hit");
109 assert.equal(weak.damage, 6);
110 assert.equal(weak.multiplier, 2);
111
112 i = 0;
113 const resist = resolvePhysicalAttack({
114 hitSkillLevel: 10,
115 agilitySkillLevel: 1,
116 damageSkillLevel: 5,
117 defenceSkillLevel: 1,
118 attackType: "blunt",
119 targetAffinities: { blunt: "resistant" },
120 rng
121 });
122 assert.equal(resist.outcome, "hit");
123 assert.equal(resist.damage, 1);
124 assert.equal(resist.multiplier, 0.5);
125});
126
94test("physical damage is the damage skill roll only", () =>
127test("physical damage is the damage skill roll only", () =>
95{
128{
96 let i = 0;
129 let i = 0;
server/tests/magic.test.js +12 −3
@@ -2,6 +2,7 @@ import test from "node:test";
2 2 import assert from "node:assert/strict";
3 3 import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast } from "../../shared/combat/magic.js";
4 4 import { spellDefinition, spellDifficulty, SpellId } from "../../shared/definitions/spells.js";
5 import { spellDifficultyFromTier } from "../../shared/spells/constants.js";
5 6
6 7 test("spell cast fails when difficulty roll beats magic roll", () =>
7 8 {
@@ -83,8 +84,16 @@ test("non-damage spell applies effect only after a successful cast roll", () =>
83 84
84 85 test("spell definitions expose tier-based difficulty", () =>
85 86 {
86 const spark = spellDefinition(SpellId.spark);
87 assert.equal(spellDifficulty(spark), 4);
88 assert.equal(spark.element, "fire");
87 const firebolt = spellDefinition(SpellId.firebolt);
88 assert.equal(spellDifficulty(firebolt), spellDifficultyFromTier(3));
89 assert.equal(firebolt.element, "fire");
90 assert.equal(spellDefinition("spark"), null);
89 91 assert.ok(spellDefinition(SpellId.light));
92 assert.ok(spellDefinition(SpellId.waterbolt));
93 assert.ok(spellDefinition(SpellId.maelstrom));
94 assert.ok(spellDefinition(SpellId.hurricane));
95 assert.ok(spellDefinition(SpellId.cataclysm));
96 assert.ok(spellDefinition(SpellId.judgment));
97 assert.ok(spellDefinition(SpellId.oblivion));
98 assert.ok(spellDefinition(SpellId.blight));
90 99 });
@@ -2,6 +2,7 @@ import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast } from "../../shared/combat/magic.js";
3import { resolveMagicAttack, resolveMagicEffect, resolveSpellCast } from "../../shared/combat/magic.js";
4import { spellDefinition, spellDifficulty, SpellId } from "../../shared/definitions/spells.js";
4import { spellDefinition, spellDifficulty, SpellId } from "../../shared/definitions/spells.js";
5import { spellDifficultyFromTier } from "../../shared/spells/constants.js";
5
6
6test("spell cast fails when difficulty roll beats magic roll", () =>
7test("spell cast fails when difficulty roll beats magic roll", () =>
7{
8{
@@ -83,8 +84,16 @@ test("non-damage spell applies effect only after a successful cast roll", () =>
83
84
84test("spell definitions expose tier-based difficulty", () =>
85test("spell definitions expose tier-based difficulty", () =>
85{
86{
86 const spark = spellDefinition(SpellId.spark);
87 const firebolt = spellDefinition(SpellId.firebolt);
87 assert.equal(spellDifficulty(spark), 4);
88 assert.equal(spellDifficulty(firebolt), spellDifficultyFromTier(3));
88 assert.equal(spark.element, "fire");
89 assert.equal(firebolt.element, "fire");
90 assert.equal(spellDefinition("spark"), null);
89 assert.ok(spellDefinition(SpellId.light));
91 assert.ok(spellDefinition(SpellId.light));
92 assert.ok(spellDefinition(SpellId.waterbolt));
93 assert.ok(spellDefinition(SpellId.maelstrom));
94 assert.ok(spellDefinition(SpellId.hurricane));
95 assert.ok(spellDefinition(SpellId.cataclysm));
96 assert.ok(spellDefinition(SpellId.judgment));
97 assert.ok(spellDefinition(SpellId.oblivion));
98 assert.ok(spellDefinition(SpellId.blight));
90});
99});
server/tests/spawner-bounty.test.js +31 −14
@@ -1,12 +1,13 @@
1 1 import test from "node:test";
2 2 import assert from "node:assert/strict";
3 import {
4 MobId,
5 normalizeSpawnerConfig,
6 mobMaxHealthForLevel,
7 mobLevelDisplayName,
8 mobDefinition
9 } from "../../shared/definitions/mobs.js";
3 import
4 {
5 MobId,
6 normalizeSpawnerConfig,
7 mobMaxHealthForLevel,
8 mobLevelDisplayName,
9 mobDefinition
10 } from "../../shared/definitions/mobs.js";
10 11 import { mobCanFight, mobSpellCastChancePercent } from "../../shared/definitions/mobCombat.js";
11 12 import { SpellId } from "../../shared/definitions/spells.js";
12 13 import { SkillId } from "../../shared/definitions/skills.js";
@@ -50,19 +51,35 @@ test("spawner config keeps bounty, level, and spells", () =>
50 51 level: 5,
51 52 bounty: 25,
52 53 spells: [
53 { spellId: SpellId.spark, chance: 75 },
54 { spellId: SpellId.firebolt, chance: 75 },
54 55 { spellId: SpellId.light, chance: 0 },
55 { spellId: SpellId.spark, chance: 10 }
56 { spellId: SpellId.firebolt, chance: 10 }
56 57 ]
57 58 }, "s1");
58 59 assert.equal(config.level, 5);
59 60 assert.equal(config.bounty, 25);
60 61 assert.equal(config.spells.length, 2);
61 assert.equal(config.spells[0].spellId, SpellId.spark);
62 assert.equal(config.spells[0].spellId, SpellId.firebolt);
62 63 assert.equal(config.spells[0].chance, undefined);
63 64 assert.equal(config.spells[1].spellId, SpellId.light);
64 65 });
65 66
67 test("spawner config drops retired spark spell without failing", () =>
68 {
69 const config = normalizeSpawnerConfig({
70 mobTypeId: MobId.humanoid,
71 spells: [
72 { spellId: "spark" },
73 { spellId: SpellId.light },
74 { spellId: SpellId.firebolt }
75 ]
76 }, "legacy-spark");
77 assert.deepEqual(
78 config.spells.map((row) => row.spellId),
79 [SpellId.light, SpellId.firebolt]
80 );
81 });
82
66 83 test("humanoid aggressive forces bounty to 0", () =>
67 84 {
68 85 const config = normalizeSpawnerConfig({
@@ -101,7 +118,7 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells
101 118 displayName: "Captain",
102 119 sex: "male",
103 120 spells: [
104 { spellId: SpellId.spark },
121 { spellId: SpellId.firebolt },
105 122 { spellId: SpellId.light }
106 123 ]
107 124 });
@@ -112,9 +129,9 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells
112 129 assert.equal(components.skills.levels[SkillId.unarmed], 4);
113 130 assert.equal(components.spawnOrigin.bounty, 12);
114 131 assert.equal(components.spawnOrigin.townGuard, true);
115 assert.ok(components.spells.known.includes(SpellId.spark));
132 assert.ok(components.spells.known.includes(SpellId.firebolt));
116 133 assert.ok(components.spells.known.includes(SpellId.light));
117 assert.equal(components.spells.castChances[SpellId.spark], mobSpellCastChancePercent(4));
134 assert.equal(components.spells.castChances[SpellId.firebolt], mobSpellCastChancePercent(4));
118 135 assert.equal(components.spells.castChances[SpellId.light], mobSpellCastChancePercent(4));
119 136 });
120 137
@@ -126,7 +143,7 @@ test("mobs below spell minMagicLevel do not learn the spell", () =>
126 143 mobTypeId: MobId.rat,
127 144 spawnerId: "0:0:4",
128 145 level: 1,
129 spells: [{ spellId: SpellId.spark }]
146 spells: [{ spellId: SpellId.firebolt }]
130 147 });
131 148 assert.equal(components.spells, undefined);
132 149 });
@@ -1,12 +1,13 @@
1import test from "node:test";
1import test from "node:test";
2import assert from "node:assert/strict";
2import assert from "node:assert/strict";
3import {
3import
4 MobId,
4 {
5 normalizeSpawnerConfig,
5 MobId,
6 mobMaxHealthForLevel,
6 normalizeSpawnerConfig,
7 mobLevelDisplayName,
7 mobMaxHealthForLevel,
8 mobDefinition
8 mobLevelDisplayName,
9} from "../../shared/definitions/mobs.js";
9 mobDefinition
10 } from "../../shared/definitions/mobs.js";
10import { mobCanFight, mobSpellCastChancePercent } from "../../shared/definitions/mobCombat.js";
11import { mobCanFight, mobSpellCastChancePercent } from "../../shared/definitions/mobCombat.js";
11import { SpellId } from "../../shared/definitions/spells.js";
12import { SpellId } from "../../shared/definitions/spells.js";
12import { SkillId } from "../../shared/definitions/skills.js";
13import { SkillId } from "../../shared/definitions/skills.js";
@@ -50,19 +51,35 @@ test("spawner config keeps bounty, level, and spells", () =>
50 level: 5,
51 level: 5,
51 bounty: 25,
52 bounty: 25,
52 spells: [
53 spells: [
53 { spellId: SpellId.spark, chance: 75 },
54 { spellId: SpellId.firebolt, chance: 75 },
54 { spellId: SpellId.light, chance: 0 },
55 { spellId: SpellId.light, chance: 0 },
55 { spellId: SpellId.spark, chance: 10 }
56 { spellId: SpellId.firebolt, chance: 10 }
56 ]
57 ]
57 }, "s1");
58 }, "s1");
58 assert.equal(config.level, 5);
59 assert.equal(config.level, 5);
59 assert.equal(config.bounty, 25);
60 assert.equal(config.bounty, 25);
60 assert.equal(config.spells.length, 2);
61 assert.equal(config.spells.length, 2);
61 assert.equal(config.spells[0].spellId, SpellId.spark);
62 assert.equal(config.spells[0].spellId, SpellId.firebolt);
62 assert.equal(config.spells[0].chance, undefined);
63 assert.equal(config.spells[0].chance, undefined);
63 assert.equal(config.spells[1].spellId, SpellId.light);
64 assert.equal(config.spells[1].spellId, SpellId.light);
64});
65});
65
66
67test("spawner config drops retired spark spell without failing", () =>
68{
69 const config = normalizeSpawnerConfig({
70 mobTypeId: MobId.humanoid,
71 spells: [
72 { spellId: "spark" },
73 { spellId: SpellId.light },
74 { spellId: SpellId.firebolt }
75 ]
76 }, "legacy-spark");
77 assert.deepEqual(
78 config.spells.map((row) => row.spellId),
79 [SpellId.light, SpellId.firebolt]
80 );
81});
82
66test("humanoid aggressive forces bounty to 0", () =>
83test("humanoid aggressive forces bounty to 0", () =>
67{
84{
68 const config = normalizeSpawnerConfig({
85 const config = normalizeSpawnerConfig({
@@ -101,7 +118,7 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells
101 displayName: "Captain",
118 displayName: "Captain",
102 sex: "male",
119 sex: "male",
103 spells: [
120 spells: [
104 { spellId: SpellId.spark },
121 { spellId: SpellId.firebolt },
105 { spellId: SpellId.light }
122 { spellId: SpellId.light }
106 ]
123 ]
107 });
124 });
@@ -112,9 +129,9 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells
112 assert.equal(components.skills.levels[SkillId.unarmed], 4);
129 assert.equal(components.skills.levels[SkillId.unarmed], 4);
113 assert.equal(components.spawnOrigin.bounty, 12);
130 assert.equal(components.spawnOrigin.bounty, 12);
114 assert.equal(components.spawnOrigin.townGuard, true);
131 assert.equal(components.spawnOrigin.townGuard, true);
115 assert.ok(components.spells.known.includes(SpellId.spark));
132 assert.ok(components.spells.known.includes(SpellId.firebolt));
116 assert.ok(components.spells.known.includes(SpellId.light));
133 assert.ok(components.spells.known.includes(SpellId.light));
117 assert.equal(components.spells.castChances[SpellId.spark], mobSpellCastChancePercent(4));
134 assert.equal(components.spells.castChances[SpellId.firebolt], mobSpellCastChancePercent(4));
118 assert.equal(components.spells.castChances[SpellId.light], mobSpellCastChancePercent(4));
135 assert.equal(components.spells.castChances[SpellId.light], mobSpellCastChancePercent(4));
119});
136});
120
137
@@ -126,7 +143,7 @@ test("mobs below spell minMagicLevel do not learn the spell", () =>
126 mobTypeId: MobId.rat,
143 mobTypeId: MobId.rat,
127 spawnerId: "0:0:4",
144 spawnerId: "0:0:4",
128 level: 1,
145 level: 1,
129 spells: [{ spellId: SpellId.spark }]
146 spells: [{ spellId: SpellId.firebolt }]
130 });
147 });
131 assert.equal(components.spells, undefined);
148 assert.equal(components.spells, undefined);
132});
149});
shared/appearance/hair.js +5 −1
@@ -217,7 +217,11 @@ export function hairLayerFromAppearance (appearance)
217 217 export function composeAppearanceLayers (appearance, equipmentSlots)
218 218 {
219 219 const sex = appearance?.sex === "female" ? "female" : "male";
220 const layers = [{ sprite: appearance?.sprite ?? bodySpriteName(sex) }];
220 const layers = [{
221 sprite: appearance?.sprite ?? bodySpriteName(sex),
222 ...(appearance?.tint ? { tint: appearance.tint } : {}),
223 ...(appearance?.bloomBody ? { bloomBody: true } : {})
224 }];
221 225 const slots = equipmentSlots ?? {};
222 226 for (const slot of EQUIPMENT_DRAW_ORDER)
223 227 {
@@ -217,7 +217,11 @@ export function hairLayerFromAppearance (appearance)
217export function composeAppearanceLayers (appearance, equipmentSlots)
217export function composeAppearanceLayers (appearance, equipmentSlots)
218{
218{
219 const sex = appearance?.sex === "female" ? "female" : "male";
219 const sex = appearance?.sex === "female" ? "female" : "male";
220 const layers = [{ sprite: appearance?.sprite ?? bodySpriteName(sex) }];
220 const layers = [{
221 sprite: appearance?.sprite ?? bodySpriteName(sex),
222 ...(appearance?.tint ? { tint: appearance.tint } : {}),
223 ...(appearance?.bloomBody ? { bloomBody: true } : {})
224 }];
221 const slots = equipmentSlots ?? {};
225 const slots = equipmentSlots ?? {};
222 for (const slot of EQUIPMENT_DRAW_ORDER)
226 for (const slot of EQUIPMENT_DRAW_ORDER)
223 {
227 {
shared/combat/magic.js +22 −7
@@ -1,4 +1,5 @@
1 1 import { rollSkill } from "./rolls.js";
2 import { damageTypeMultiplier, MagicElement } from "../definitions/attackTypes.js";
2 3
3 4 /**
4 5 * Magic attack resolution — cast step is implemented; full combat wiring is later.
@@ -16,7 +17,7 @@ export const ElementMultiplier = Object.freeze({
16 17 resistant: 0.5
17 18 });
18 19
19 /** @typedef {"fire"|"water"|"earth"|"air"|"holy"|"dark"|"none"} SpellElement */
20 /** @typedef {import("../definitions/attackTypes.js").MagicElement[keyof import("../definitions/attackTypes.js").MagicElement]|"holy"|"none"} SpellElement */
20 21
21 22 /**
22 23 * Whether the caster successfully channels the spell.
@@ -39,14 +40,19 @@ export function resolveSpellCast ({
39 40 };
40 41 }
41 42
43 function normalizeSpellElement (element)
44 {
45 if (element === "holy")
46 { return MagicElement.light; }
47 return element ?? "none";
48 }
49
42 50 function elementalMultiplier (element, targetAffinities = {})
43 51 {
44 const affinity = targetAffinities[element];
45 if (affinity === "weak")
46 { return ElementMultiplier.weak; }
47 if (affinity === "resistant")
48 { return ElementMultiplier.resistant; }
49 return ElementMultiplier.neutral;
52 const key = normalizeSpellElement(element);
53 if (key === "none")
54 { return ElementMultiplier.neutral; }
55 return damageTypeMultiplier(key, targetAffinities);
50 56 }
51 57
52 58 /**
@@ -126,3 +132,12 @@ export function mobElementAffinities (mobDef)
126 132 {
127 133 return mobDef?.elementAffinities ?? {};
128 134 }
135
136 /** Physical + elemental affinities for damage multipliers. */
137 export function mobDamageAffinities (mobDef)
138 {
139 return {
140 ...(mobDef?.attackAffinities ?? {}),
141 ...(mobDef?.elementAffinities ?? {})
142 };
143 }
@@ -1,4 +1,5 @@
1import { rollSkill } from "./rolls.js";
1import { rollSkill } from "./rolls.js";
2import { damageTypeMultiplier, MagicElement } from "../definitions/attackTypes.js";
2
3
3/**
4/**
4 * Magic attack resolution — cast step is implemented; full combat wiring is later.
5 * Magic attack resolution — cast step is implemented; full combat wiring is later.
@@ -16,7 +17,7 @@ export const ElementMultiplier = Object.freeze({
16 resistant: 0.5
17 resistant: 0.5
17});
18});
18
19
19/** @typedef {"fire"|"water"|"earth"|"air"|"holy"|"dark"|"none"} SpellElement */
20/** @typedef {import("../definitions/attackTypes.js").MagicElement[keyof import("../definitions/attackTypes.js").MagicElement]|"holy"|"none"} SpellElement */
20
21
21/**
22/**
22 * Whether the caster successfully channels the spell.
23 * Whether the caster successfully channels the spell.
@@ -39,14 +40,19 @@ export function resolveSpellCast ({
39 };
40 };
40}
41}
41
42
43function normalizeSpellElement (element)
44{
45 if (element === "holy")
46 { return MagicElement.light; }
47 return element ?? "none";
48}
49
42function elementalMultiplier (element, targetAffinities = {})
50function elementalMultiplier (element, targetAffinities = {})
43{
51{
44 const affinity = targetAffinities[element];
52 const key = normalizeSpellElement(element);
45 if (affinity === "weak")
53 if (key === "none")
46 { return ElementMultiplier.weak; }
54 { return ElementMultiplier.neutral; }
47 if (affinity === "resistant")
55 return damageTypeMultiplier(key, targetAffinities);
48 { return ElementMultiplier.resistant; }
49 return ElementMultiplier.neutral;
50}
56}
51
57
52/**
58/**
@@ -126,3 +132,12 @@ export function mobElementAffinities (mobDef)
126{
132{
127 return mobDef?.elementAffinities ?? {};
133 return mobDef?.elementAffinities ?? {};
128}
134}
135
136/** Physical + elemental affinities for damage multipliers. */
137export function mobDamageAffinities (mobDef)
138{
139 return {
140 ...(mobDef?.attackAffinities ?? {}),
141 ...(mobDef?.elementAffinities ?? {})
142 };
143}
shared/combat/rolls.js +14 −5
@@ -1,3 +1,5 @@
1 import { damageTypeMultiplier } from "../definitions/attackTypes.js";
2
1 3 /** Uniform integer roll in [0, skillLevel]. */
2 4 export function rollSkill (skillLevel, rng = Math.random)
3 5 {
@@ -10,13 +12,15 @@ export function rollSkill (skillLevel, rng = Math.random)
10 12 * 1. Roll hit skill vs defender Agility — miss if toHitRoll < agilityRoll
11 13 * 2. Always roll attacker damage skill (for dodge XP even on miss)
12 14 * 3. On hit: defender rolls Defence — block if defenceRoll > toHitRoll
13 * 4. On hit and not blocked: apply rolled damage
15 * 4. On hit and not blocked: apply rolled damage × attack-type affinities
14 16 */
15 17 export function resolvePhysicalAttack ({
16 18 hitSkillLevel,
17 19 agilitySkillLevel,
18 20 damageSkillLevel,
19 21 defenceSkillLevel,
22 attackType = null,
23 targetAffinities = {},
20 24 rng = Math.random
21 25 })
22 26 {
@@ -31,11 +35,11 @@ export function resolvePhysicalAttack ({
31 35 agilityRoll,
32 36 damageRoll,
33 37 damage: 0,
34 blocked: false
38 blocked: false,
39 multiplier: 1
35 40 };
36 41 }
37 42
38 const damage = damageRoll;
39 43 const defenceRoll = rollSkill(defenceSkillLevel, rng);
40 44 if (defenceRoll > toHitRoll)
41 45 {
@@ -46,10 +50,14 @@ export function resolvePhysicalAttack ({
46 50 damageRoll,
47 51 defenceRoll,
48 52 damage: 0,
49 blocked: true
53 blocked: true,
54 multiplier: 1
50 55 };
51 56 }
52 57
58 const multiplier = damageTypeMultiplier(attackType, targetAffinities);
59 const damage = Math.max(0, Math.floor(damageRoll * multiplier));
60
53 61 return {
54 62 outcome: "hit",
55 63 toHitRoll,
@@ -57,6 +65,7 @@ export function resolvePhysicalAttack ({
57 65 damageRoll,
58 66 defenceRoll,
59 67 damage,
60 blocked: false
68 blocked: false,
69 multiplier
61 70 };
62 71 }
@@ -1,3 +1,5 @@
1import { damageTypeMultiplier } from "../definitions/attackTypes.js";
2
1/** Uniform integer roll in [0, skillLevel]. */
3/** Uniform integer roll in [0, skillLevel]. */
2export function rollSkill (skillLevel, rng = Math.random)
4export function rollSkill (skillLevel, rng = Math.random)
3{
5{
@@ -10,13 +12,15 @@ export function rollSkill (skillLevel, rng = Math.random)
10 * 1. Roll hit skill vs defender Agility — miss if toHitRoll < agilityRoll
12 * 1. Roll hit skill vs defender Agility — miss if toHitRoll < agilityRoll
11 * 2. Always roll attacker damage skill (for dodge XP even on miss)
13 * 2. Always roll attacker damage skill (for dodge XP even on miss)
12 * 3. On hit: defender rolls Defence — block if defenceRoll > toHitRoll
14 * 3. On hit: defender rolls Defence — block if defenceRoll > toHitRoll
13 * 4. On hit and not blocked: apply rolled damage
15 * 4. On hit and not blocked: apply rolled damage × attack-type affinities
14 */
16 */
15export function resolvePhysicalAttack ({
17export function resolvePhysicalAttack ({
16 hitSkillLevel,
18 hitSkillLevel,
17 agilitySkillLevel,
19 agilitySkillLevel,
18 damageSkillLevel,
20 damageSkillLevel,
19 defenceSkillLevel,
21 defenceSkillLevel,
22 attackType = null,
23 targetAffinities = {},
20 rng = Math.random
24 rng = Math.random
21})
25})
22{
26{
@@ -31,11 +35,11 @@ export function resolvePhysicalAttack ({
31 agilityRoll,
35 agilityRoll,
32 damageRoll,
36 damageRoll,
33 damage: 0,
37 damage: 0,
34 blocked: false
38 blocked: false,
39 multiplier: 1
35 };
40 };
36 }
41 }
37
42
38 const damage = damageRoll;
39 const defenceRoll = rollSkill(defenceSkillLevel, rng);
43 const defenceRoll = rollSkill(defenceSkillLevel, rng);
40 if (defenceRoll > toHitRoll)
44 if (defenceRoll > toHitRoll)
41 {
45 {
@@ -46,10 +50,14 @@ export function resolvePhysicalAttack ({
46 damageRoll,
50 damageRoll,
47 defenceRoll,
51 defenceRoll,
48 damage: 0,
52 damage: 0,
49 blocked: true
53 blocked: true,
54 multiplier: 1
50 };
55 };
51 }
56 }
52
57
58 const multiplier = damageTypeMultiplier(attackType, targetAffinities);
59 const damage = Math.max(0, Math.floor(damageRoll * multiplier));
60
53 return {
61 return {
54 outcome: "hit",
62 outcome: "hit",
55 toHitRoll,
63 toHitRoll,
@@ -57,6 +65,7 @@ export function resolvePhysicalAttack ({
57 damageRoll,
65 damageRoll,
58 defenceRoll,
66 defenceRoll,
59 damage,
67 damage,
60 blocked: false
68 blocked: false,
69 multiplier
61 };
70 };
62}
71}
shared/crafting/tierRecipes.js +46 −0
@@ -10,6 +10,7 @@ import {
10 10 MATERIAL_DISPLAY_NAME,
11 11 WoodTier,
12 12 woodTierForMetal,
13 leatherTierForMetal,
13 14 clothTierForWood,
14 15 tierSmeltSkillLevel,
15 16 tierCraftSkillLevel,
@@ -21,6 +22,7 @@ import {
21 22 } from "../definitions/armourItems.js";
22 23 import { RangedItemId } from "../definitions/rangedItems.js";
23 24 import { yarnItemId } from "../definitions/clothItems.js";
25 import { leatherMaterialItemId } from "../definitions/leatherItems.js";
24 26
25 27 /**
26 28 * Tier-scaled craft recipes generated from {@link ItemFamilyId} templates.
@@ -201,6 +203,48 @@ function plantClippersRecipes ()
201 203 }));
202 204 }
203 205
206 function swordBladeRecipes ()
207 {
208 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
209 recipeId: `sword-blade-${metalTier}`,
210 craftGroup: "sword-blade",
211 craftGroupLabel: "Sword blade",
212 stationId: CraftingStationId.anvil,
213 outputFamily: ItemFamilyId.swordBlade,
214 outputTier: metalTier,
215 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 2 }],
216 minSkillLevel: tierSmeltSkillLevel(metalTier),
217 skillId: "smithing",
218 xpMaterial: metalTier
219 }));
220 }
221
222 function swordAssembleRecipes ()
223 {
224 return MATERIAL_TIER_ORDER.map((metalTier) =>
225 {
226 const woodTier = woodTierForMetal(metalTier);
227 const leatherTier = leatherTierForMetal(metalTier);
228 const leatherId = leatherMaterialItemId(leatherTier);
229 return tierRecipe({
230 recipeId: `sword-${metalTier}`,
231 craftGroup: "sword",
232 craftGroupLabel: "Sword",
233 stationId: CraftingStationId.craftingBench,
234 outputFamily: ItemFamilyId.sword,
235 outputTier: metalTier,
236 inputs: [
237 { itemId: familyItemId(ItemFamilyId.swordBlade, metalTier), quantity: 1 },
238 { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 },
239 { itemId: leatherId, quantity: 1 }
240 ],
241 minSkillLevel: tierCraftSkillLevel(metalTier),
242 skillId: "crafting",
243 xpMaterial: metalTier
244 });
245 });
246 }
247
204 248 function arrowShaftRecipes ()
205 249 {
206 250 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
@@ -346,6 +390,8 @@ export const TIER_FAMILY_RECIPES = Object.freeze([
346 390 ...axeHeadRecipes(),
347 391 ...axeAssembleRecipes(),
348 392 ...plantClippersRecipes(),
393 ...swordBladeRecipes(),
394 ...swordAssembleRecipes(),
349 395 ...arrowShaftRecipes(),
350 396 ...arrowTipRecipes(),
351 397 ...arrowAssembleRecipes(),
@@ -10,6 +10,7 @@ import {
10 MATERIAL_DISPLAY_NAME,
10 MATERIAL_DISPLAY_NAME,
11 WoodTier,
11 WoodTier,
12 woodTierForMetal,
12 woodTierForMetal,
13 leatherTierForMetal,
13 clothTierForWood,
14 clothTierForWood,
14 tierSmeltSkillLevel,
15 tierSmeltSkillLevel,
15 tierCraftSkillLevel,
16 tierCraftSkillLevel,
@@ -21,6 +22,7 @@ import {
21} from "../definitions/armourItems.js";
22} from "../definitions/armourItems.js";
22import { RangedItemId } from "../definitions/rangedItems.js";
23import { RangedItemId } from "../definitions/rangedItems.js";
23import { yarnItemId } from "../definitions/clothItems.js";
24import { yarnItemId } from "../definitions/clothItems.js";
25import { leatherMaterialItemId } from "../definitions/leatherItems.js";
24
26
25/**
27/**
26 * Tier-scaled craft recipes generated from {@link ItemFamilyId} templates.
28 * Tier-scaled craft recipes generated from {@link ItemFamilyId} templates.
@@ -201,6 +203,48 @@ function plantClippersRecipes ()
201 }));
203 }));
202}
204}
203
205
206function swordBladeRecipes ()
207{
208 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
209 recipeId: `sword-blade-${metalTier}`,
210 craftGroup: "sword-blade",
211 craftGroupLabel: "Sword blade",
212 stationId: CraftingStationId.anvil,
213 outputFamily: ItemFamilyId.swordBlade,
214 outputTier: metalTier,
215 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 2 }],
216 minSkillLevel: tierSmeltSkillLevel(metalTier),
217 skillId: "smithing",
218 xpMaterial: metalTier
219 }));
220}
221
222function swordAssembleRecipes ()
223{
224 return MATERIAL_TIER_ORDER.map((metalTier) =>
225 {
226 const woodTier = woodTierForMetal(metalTier);
227 const leatherTier = leatherTierForMetal(metalTier);
228 const leatherId = leatherMaterialItemId(leatherTier);
229 return tierRecipe({
230 recipeId: `sword-${metalTier}`,
231 craftGroup: "sword",
232 craftGroupLabel: "Sword",
233 stationId: CraftingStationId.craftingBench,
234 outputFamily: ItemFamilyId.sword,
235 outputTier: metalTier,
236 inputs: [
237 { itemId: familyItemId(ItemFamilyId.swordBlade, metalTier), quantity: 1 },
238 { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 },
239 { itemId: leatherId, quantity: 1 }
240 ],
241 minSkillLevel: tierCraftSkillLevel(metalTier),
242 skillId: "crafting",
243 xpMaterial: metalTier
244 });
245 });
246}
247
204function arrowShaftRecipes ()
248function arrowShaftRecipes ()
205{
249{
206 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
250 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
@@ -346,6 +390,8 @@ export const TIER_FAMILY_RECIPES = Object.freeze([
346 ...axeHeadRecipes(),
390 ...axeHeadRecipes(),
347 ...axeAssembleRecipes(),
391 ...axeAssembleRecipes(),
348 ...plantClippersRecipes(),
392 ...plantClippersRecipes(),
393 ...swordBladeRecipes(),
394 ...swordAssembleRecipes(),
349 ...arrowShaftRecipes(),
395 ...arrowShaftRecipes(),
350 ...arrowTipRecipes(),
396 ...arrowTipRecipes(),
351 ...arrowAssembleRecipes(),
397 ...arrowAssembleRecipes(),
shared/definitions/alchemy.js +106 −1
@@ -1,4 +1,11 @@
1 1 /** Cauldron action / step kinds (authoritative recipe language). */
2 import {
3 MagicElement,
4 MAGIC_ELEMENT_ORDER,
5 MAGIC_ELEMENT_TINT,
6 ASH_WOOD_FOR_ELEMENT
7 } from "./attackTypes.js";
8
2 9 export const AlchemyStepKind = Object.freeze({
3 10 heat: "heat",
4 11 cool: "cool",
@@ -10,6 +17,8 @@ export const POTION_MAX_STACK = 16;
10 17 export const POTION_FILL_LEVELS = Object.freeze([1, 2, 3, 4, 5]);
11 18 export const CAULDRON_SLOT_COUNT = 4;
12 19 export const DYE_CAULDRON_SLOT_COUNT = 6;
20 /** How many untipped arrows one coating charge can tip. */
21 export const ARROW_COATING_ARROWS_PER_USE = 10;
13 22
14 23 /** Deterministic cauldron look lines (hashed from the step transcript). */
15 24 export const CAULDRON_FLAVOR_LINES = Object.freeze([
@@ -120,9 +129,105 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
120 129 amount: 5,
121 130 durationMs: 60_000
122 131 })
123 })
132 }),
133 ...buildArrowCoatingPotions()
124 134 });
125 135
136 /**
137 * Arrow coatings — one per magic element. Each uses a different wood ash + matching essence,
138 * with a distinct brew sequence so they do not collide with each other.
139 */
140 function buildArrowCoatingPotions ()
141 {
142 const coats = {};
143 const sequences = [
144 // fire — heat the ash, then fold in essence
145 (ash, essence) => [
146 { kind: AlchemyStepKind.insert, itemKey: ash },
147 { kind: AlchemyStepKind.heat },
148 { kind: AlchemyStepKind.insert, itemKey: essence },
149 { kind: AlchemyStepKind.stir }
150 ],
151 // water — cool ash slurry, essence last
152 (ash, essence) => [
153 { kind: AlchemyStepKind.insert, itemKey: ash },
154 { kind: AlchemyStepKind.cool },
155 { kind: AlchemyStepKind.stir },
156 { kind: AlchemyStepKind.insert, itemKey: essence }
157 ],
158 // air — stir ash, heat essence gently
159 (ash, essence) => [
160 { kind: AlchemyStepKind.insert, itemKey: ash },
161 { kind: AlchemyStepKind.stir },
162 { kind: AlchemyStepKind.insert, itemKey: essence },
163 { kind: AlchemyStepKind.heat }
164 ],
165 // earth — essence first, then ash, heavy heat
166 (ash, essence) => [
167 { kind: AlchemyStepKind.insert, itemKey: essence },
168 { kind: AlchemyStepKind.heat },
169 { kind: AlchemyStepKind.insert, itemKey: ash },
170 { kind: AlchemyStepKind.stir }
171 ],
172 // light — cool essence, warm ash
173 (ash, essence) => [
174 { kind: AlchemyStepKind.insert, itemKey: essence },
175 { kind: AlchemyStepKind.cool },
176 { kind: AlchemyStepKind.insert, itemKey: ash },
177 { kind: AlchemyStepKind.heat }
178 ],
179 // dark — ash and essence together under cool stillness
180 (ash, essence) => [
181 { kind: AlchemyStepKind.insert, itemKey: ash },
182 { kind: AlchemyStepKind.insert, itemKey: essence },
183 { kind: AlchemyStepKind.cool },
184 { kind: AlchemyStepKind.stir }
185 ],
186 // poison — heat essence alone, then ash, cool to set
187 (ash, essence) => [
188 { kind: AlchemyStepKind.insert, itemKey: essence },
189 { kind: AlchemyStepKind.heat },
190 { kind: AlchemyStepKind.stir },
191 { kind: AlchemyStepKind.insert, itemKey: ash },
192 { kind: AlchemyStepKind.cool }
193 ]
194 ];
195 const names = {
196 [MagicElement.fire]: "Fire arrow coating",
197 [MagicElement.water]: "Water arrow coating",
198 [MagicElement.air]: "Air arrow coating",
199 [MagicElement.earth]: "Earth arrow coating",
200 [MagicElement.light]: "Light arrow coating",
201 [MagicElement.dark]: "Dark arrow coating",
202 [MagicElement.poison]: "Poison arrow coating"
203 };
204 MAGIC_ELEMENT_ORDER.forEach((element, index) =>
205 {
206 const wood = ASH_WOOD_FOR_ELEMENT[element];
207 const ashKey = `${wood}-ash`;
208 const essenceKey = `${element}-essence`;
209 const tint = MAGIC_ELEMENT_TINT[element];
210 const potionKey = `${element}ArrowCoating`;
211 coats[potionKey] = Object.freeze({
212 potionKey,
213 displayName: names[element] ?? `${element} arrow coating`,
214 minAlchemyLevel: 5,
215 color: Object.freeze({ r: tint.r, g: tint.g, b: tint.b }),
216 fillLevel: 4,
217 ingredients: Object.freeze([
218 Object.freeze({ key: ashKey, quantity: 1 }),
219 Object.freeze({ key: essenceKey, quantity: 1 })
220 ]),
221 steps: Object.freeze(sequences[index](ashKey, essenceKey).map((s) => Object.freeze(s))),
222 effect: Object.freeze({
223 type: "arrow-coating",
224 element
225 })
226 });
227 });
228 return coats;
229 }
230
126 231 /**
127 232 * Failure (unstable) potions chosen by hashing the step transcript.
128 233 */
@@ -1,4 +1,11 @@
1/** Cauldron action / step kinds (authoritative recipe language). */
1/** Cauldron action / step kinds (authoritative recipe language). */
2import {
3 MagicElement,
4 MAGIC_ELEMENT_ORDER,
5 MAGIC_ELEMENT_TINT,
6 ASH_WOOD_FOR_ELEMENT
7} from "./attackTypes.js";
8
2export const AlchemyStepKind = Object.freeze({
9export const AlchemyStepKind = Object.freeze({
3 heat: "heat",
10 heat: "heat",
4 cool: "cool",
11 cool: "cool",
@@ -10,6 +17,8 @@ export const POTION_MAX_STACK = 16;
10export const POTION_FILL_LEVELS = Object.freeze([1, 2, 3, 4, 5]);
17export const POTION_FILL_LEVELS = Object.freeze([1, 2, 3, 4, 5]);
11export const CAULDRON_SLOT_COUNT = 4;
18export const CAULDRON_SLOT_COUNT = 4;
12export const DYE_CAULDRON_SLOT_COUNT = 6;
19export const DYE_CAULDRON_SLOT_COUNT = 6;
20/** How many untipped arrows one coating charge can tip. */
21export const ARROW_COATING_ARROWS_PER_USE = 10;
13
22
14/** Deterministic cauldron look lines (hashed from the step transcript). */
23/** Deterministic cauldron look lines (hashed from the step transcript). */
15export const CAULDRON_FLAVOR_LINES = Object.freeze([
24export const CAULDRON_FLAVOR_LINES = Object.freeze([
@@ -120,9 +129,105 @@ export const ALCHEMY_POTION_DEFINITIONS = Object.freeze({
120 amount: 5,
129 amount: 5,
121 durationMs: 60_000
130 durationMs: 60_000
122 })
131 })
123 })
132 }),
133 ...buildArrowCoatingPotions()
124});
134});
125
135
136/**
137 * Arrow coatings — one per magic element. Each uses a different wood ash + matching essence,
138 * with a distinct brew sequence so they do not collide with each other.
139 */
140function buildArrowCoatingPotions ()
141{
142 const coats = {};
143 const sequences = [
144 // fire — heat the ash, then fold in essence
145 (ash, essence) => [
146 { kind: AlchemyStepKind.insert, itemKey: ash },
147 { kind: AlchemyStepKind.heat },
148 { kind: AlchemyStepKind.insert, itemKey: essence },
149 { kind: AlchemyStepKind.stir }
150 ],
151 // water — cool ash slurry, essence last
152 (ash, essence) => [
153 { kind: AlchemyStepKind.insert, itemKey: ash },
154 { kind: AlchemyStepKind.cool },
155 { kind: AlchemyStepKind.stir },
156 { kind: AlchemyStepKind.insert, itemKey: essence }
157 ],
158 // air — stir ash, heat essence gently
159 (ash, essence) => [
160 { kind: AlchemyStepKind.insert, itemKey: ash },
161 { kind: AlchemyStepKind.stir },
162 { kind: AlchemyStepKind.insert, itemKey: essence },
163 { kind: AlchemyStepKind.heat }
164 ],
165 // earth — essence first, then ash, heavy heat
166 (ash, essence) => [
167 { kind: AlchemyStepKind.insert, itemKey: essence },
168 { kind: AlchemyStepKind.heat },
169 { kind: AlchemyStepKind.insert, itemKey: ash },
170 { kind: AlchemyStepKind.stir }
171 ],
172 // light — cool essence, warm ash
173 (ash, essence) => [
174 { kind: AlchemyStepKind.insert, itemKey: essence },
175 { kind: AlchemyStepKind.cool },
176 { kind: AlchemyStepKind.insert, itemKey: ash },
177 { kind: AlchemyStepKind.heat }
178 ],
179 // dark — ash and essence together under cool stillness
180 (ash, essence) => [
181 { kind: AlchemyStepKind.insert, itemKey: ash },
182 { kind: AlchemyStepKind.insert, itemKey: essence },
183 { kind: AlchemyStepKind.cool },
184 { kind: AlchemyStepKind.stir }
185 ],
186 // poison — heat essence alone, then ash, cool to set
187 (ash, essence) => [
188 { kind: AlchemyStepKind.insert, itemKey: essence },
189 { kind: AlchemyStepKind.heat },
190 { kind: AlchemyStepKind.stir },
191 { kind: AlchemyStepKind.insert, itemKey: ash },
192 { kind: AlchemyStepKind.cool }
193 ]
194 ];
195 const names = {
196 [MagicElement.fire]: "Fire arrow coating",
197 [MagicElement.water]: "Water arrow coating",
198 [MagicElement.air]: "Air arrow coating",
199 [MagicElement.earth]: "Earth arrow coating",
200 [MagicElement.light]: "Light arrow coating",
201 [MagicElement.dark]: "Dark arrow coating",
202 [MagicElement.poison]: "Poison arrow coating"
203 };
204 MAGIC_ELEMENT_ORDER.forEach((element, index) =>
205 {
206 const wood = ASH_WOOD_FOR_ELEMENT[element];
207 const ashKey = `${wood}-ash`;
208 const essenceKey = `${element}-essence`;
209 const tint = MAGIC_ELEMENT_TINT[element];
210 const potionKey = `${element}ArrowCoating`;
211 coats[potionKey] = Object.freeze({
212 potionKey,
213 displayName: names[element] ?? `${element} arrow coating`,
214 minAlchemyLevel: 5,
215 color: Object.freeze({ r: tint.r, g: tint.g, b: tint.b }),
216 fillLevel: 4,
217 ingredients: Object.freeze([
218 Object.freeze({ key: ashKey, quantity: 1 }),
219 Object.freeze({ key: essenceKey, quantity: 1 })
220 ]),
221 steps: Object.freeze(sequences[index](ashKey, essenceKey).map((s) => Object.freeze(s))),
222 effect: Object.freeze({
223 type: "arrow-coating",
224 element
225 })
226 });
227 });
228 return coats;
229}
230
126/**
231/**
127 * Failure (unstable) potions chosen by hashing the step transcript.
232 * Failure (unstable) potions chosen by hashing the step transcript.
128 */
233 */
shared/definitions/attackTypes.js +90 −3
@@ -1,6 +1,93 @@
1 /** Physical weapon damage style; mobs may be weak or resistant (later). */
1 /**
2 * Physical weapon damage styles and magic elements.
3 * Mobs may set `attackAffinities` / `elementAffinities` to `"weak"` or `"resistant"`.
4 */
5
2 6 export const AttackType = Object.freeze({
7 /** Unarmed / sticks — often resisted, rarely weak. */
8 blunt: "blunt",
9 /** Swords. */
3 10 slashing: "slashing",
4 piercing: "piercing",
5 blunt: "blunt"
11 /** Clubs / quarterstaves. */
12 crushing: "crushing",
13 /** Combat axes. */
14 chopping: "chopping",
15 /** Untipped arrows / bows. */
16 piercing: "piercing"
17 });
18
19 /** Magic / tipped-arrow elements. */
20 export const MagicElement = Object.freeze({
21 fire: "fire",
22 water: "water",
23 air: "air",
24 earth: "earth",
25 light: "light",
26 dark: "dark",
27 poison: "poison"
28 });
29
30 export const MAGIC_ELEMENT_ORDER = Object.freeze([
31 MagicElement.fire,
32 MagicElement.water,
33 MagicElement.air,
34 MagicElement.earth,
35 MagicElement.light,
36 MagicElement.dark,
37 MagicElement.poison
38 ]);
39
40 /** All damage channels that can appear on affinities. */
41 export const DamageType = Object.freeze({
42 ...AttackType,
43 ...MagicElement
44 });
45
46 export const DamageMultiplier = Object.freeze({
47 weak: 2,
48 neutral: 1,
49 resistant: 0.5
50 });
51
52 /**
53 * @param {string|null|undefined} damageType
54 * @param {Record<string, string>|null|undefined} affinities
55 */
56 export function damageTypeMultiplier (damageType, affinities = {})
57 {
58 if (!damageType || !affinities)
59 { return DamageMultiplier.neutral; }
60 const affinity = affinities[damageType];
61 if (affinity === "weak")
62 { return DamageMultiplier.weak; }
63 if (affinity === "resistant")
64 { return DamageMultiplier.resistant; }
65 return DamageMultiplier.neutral;
66 }
67
68 /** Display colours for elemental sprites / essences / coatings (0–1 RGB). */
69 export const MAGIC_ELEMENT_TINT = Object.freeze({
70 [MagicElement.fire]: Object.freeze({ r: 1, g: 0.35, b: 0.12 }),
71 [MagicElement.water]: Object.freeze({ r: 0.25, g: 0.55, b: 1 }),
72 [MagicElement.air]: Object.freeze({ r: 0.75, g: 0.9, b: 1 }),
73 [MagicElement.earth]: Object.freeze({ r: 0.55, g: 0.4, b: 0.22 }),
74 [MagicElement.light]: Object.freeze({ r: 1, g: 0.95, b: 0.55 }),
75 [MagicElement.dark]: Object.freeze({ r: 0.35, g: 0.2, b: 0.55 }),
76 [MagicElement.poison]: Object.freeze({ r: 0.35, g: 0.85, b: 0.25 })
77 });
78
79 export function magicElementTint (element)
80 {
81 return MAGIC_ELEMENT_TINT[element] ?? MAGIC_ELEMENT_TINT[MagicElement.fire];
82 }
83
84 /** Wood ash tier paired with each coating element (each coating uses a different ash). */
85 export const ASH_WOOD_FOR_ELEMENT = Object.freeze({
86 [MagicElement.fire]: "pine",
87 [MagicElement.water]: "birch",
88 [MagicElement.air]: "oak",
89 [MagicElement.earth]: "ebony",
90 [MagicElement.light]: "lignum",
91 [MagicElement.dark]: "heartwood",
92 [MagicElement.poison]: "elder"
6 93 });
@@ -1,6 +1,93 @@
1/** Physical weapon damage style; mobs may be weak or resistant (later). */
1/**
2 * Physical weapon damage styles and magic elements.
3 * Mobs may set `attackAffinities` / `elementAffinities` to `"weak"` or `"resistant"`.
4 */
5
2export const AttackType = Object.freeze({
6export const AttackType = Object.freeze({
7 /** Unarmed / sticks — often resisted, rarely weak. */
8 blunt: "blunt",
9 /** Swords. */
3 slashing: "slashing",
10 slashing: "slashing",
4 piercing: "piercing",
11 /** Clubs / quarterstaves. */
5 blunt: "blunt"
12 crushing: "crushing",
13 /** Combat axes. */
14 chopping: "chopping",
15 /** Untipped arrows / bows. */
16 piercing: "piercing"
17});
18
19/** Magic / tipped-arrow elements. */
20export const MagicElement = Object.freeze({
21 fire: "fire",
22 water: "water",
23 air: "air",
24 earth: "earth",
25 light: "light",
26 dark: "dark",
27 poison: "poison"
28});
29
30export const MAGIC_ELEMENT_ORDER = Object.freeze([
31 MagicElement.fire,
32 MagicElement.water,
33 MagicElement.air,
34 MagicElement.earth,
35 MagicElement.light,
36 MagicElement.dark,
37 MagicElement.poison
38]);
39
40/** All damage channels that can appear on affinities. */
41export const DamageType = Object.freeze({
42 ...AttackType,
43 ...MagicElement
44});
45
46export const DamageMultiplier = Object.freeze({
47 weak: 2,
48 neutral: 1,
49 resistant: 0.5
50});
51
52/**
53 * @param {string|null|undefined} damageType
54 * @param {Record<string, string>|null|undefined} affinities
55 */
56export function damageTypeMultiplier (damageType, affinities = {})
57{
58 if (!damageType || !affinities)
59 { return DamageMultiplier.neutral; }
60 const affinity = affinities[damageType];
61 if (affinity === "weak")
62 { return DamageMultiplier.weak; }
63 if (affinity === "resistant")
64 { return DamageMultiplier.resistant; }
65 return DamageMultiplier.neutral;
66}
67
68/** Display colours for elemental sprites / essences / coatings (0–1 RGB). */
69export const MAGIC_ELEMENT_TINT = Object.freeze({
70 [MagicElement.fire]: Object.freeze({ r: 1, g: 0.35, b: 0.12 }),
71 [MagicElement.water]: Object.freeze({ r: 0.25, g: 0.55, b: 1 }),
72 [MagicElement.air]: Object.freeze({ r: 0.75, g: 0.9, b: 1 }),
73 [MagicElement.earth]: Object.freeze({ r: 0.55, g: 0.4, b: 0.22 }),
74 [MagicElement.light]: Object.freeze({ r: 1, g: 0.95, b: 0.55 }),
75 [MagicElement.dark]: Object.freeze({ r: 0.35, g: 0.2, b: 0.55 }),
76 [MagicElement.poison]: Object.freeze({ r: 0.35, g: 0.85, b: 0.25 })
77});
78
79export function magicElementTint (element)
80{
81 return MAGIC_ELEMENT_TINT[element] ?? MAGIC_ELEMENT_TINT[MagicElement.fire];
82}
83
84/** Wood ash tier paired with each coating element (each coating uses a different ash). */
85export const ASH_WOOD_FOR_ELEMENT = Object.freeze({
86 [MagicElement.fire]: "pine",
87 [MagicElement.water]: "birch",
88 [MagicElement.air]: "oak",
89 [MagicElement.earth]: "ebony",
90 [MagicElement.light]: "lignum",
91 [MagicElement.dark]: "heartwood",
92 [MagicElement.poison]: "elder"
6});
93});
shared/definitions/essenceItems.js added +88 −0
@@ -0,0 +1,88 @@
1 import { ItemCategory } from "./itemCategories.js";
2 import {
3 MagicElement,
4 MAGIC_ELEMENT_ORDER,
5 MAGIC_ELEMENT_TINT,
6 ASH_WOOD_FOR_ELEMENT
7 } from "./attackTypes.js";
8 import { MATERIAL_DISPLAY_NAME } from "./materialTiers.js";
9
10 /**
11 * Elemental essences dropped by sprites (100%). Share the ash sprite, tinted per element.
12 */
13 export const EssenceItemId = Object.freeze({
14 [MagicElement.fire]: 424,
15 [MagicElement.water]: 425,
16 [MagicElement.air]: 426,
17 [MagicElement.earth]: 427,
18 [MagicElement.light]: 428,
19 [MagicElement.dark]: 429,
20 [MagicElement.poison]: 430
21 });
22
23 const ELEMENT_DISPLAY = Object.freeze({
24 [MagicElement.fire]: "Fire",
25 [MagicElement.water]: "Water",
26 [MagicElement.air]: "Air",
27 [MagicElement.earth]: "Earth",
28 [MagicElement.light]: "Light",
29 [MagicElement.dark]: "Dark",
30 [MagicElement.poison]: "Poison"
31 });
32
33 function buildEssenceDefinitions ()
34 {
35 const defs = {};
36 for (const element of MAGIC_ELEMENT_ORDER)
37 {
38 const itemId = EssenceItemId[element];
39 const name = ELEMENT_DISPLAY[element] ?? element;
40 const tint = MAGIC_ELEMENT_TINT[element];
41 defs[itemId] = Object.freeze({
42 itemId,
43 key: `${element}-essence`,
44 displayName: `${name} essence`,
45 description: `A condensed mote of ${name.toLowerCase()}, shed by a sprite.`,
46 seedValue: 8,
47 stackable: true,
48 maxStackSize: 99,
49 uniqueInstance: false,
50 category: ItemCategory.ingredient,
51 iconKey: "ash",
52 defaultState: "ash",
53 essenceElement: element,
54 tint: Object.freeze({ r: tint.r, g: tint.g, b: tint.b })
55 });
56 }
57 return defs;
58 }
59
60 export const ESSENCE_ITEM_DEFINITIONS = Object.freeze(buildEssenceDefinitions());
61
62 export function essenceItemIdForElement (element)
63 {
64 return EssenceItemId[element] ?? null;
65 }
66
67 export function essenceElementDisplayName (element)
68 {
69 return ELEMENT_DISPLAY[element] ?? element;
70 }
71
72 /** Ash wood tier used when brewing the coating for this element. */
73 export function ashWoodForCoatingElement (element)
74 {
75 return ASH_WOOD_FOR_ELEMENT[element] ?? null;
76 }
77
78 export function coatingDisplayName (element)
79 {
80 const name = ELEMENT_DISPLAY[element] ?? element;
81 return `${name} arrow coating`;
82 }
83
84 export function coatingAshDisplayName (element)
85 {
86 const wood = ashWoodForCoatingElement(element);
87 return wood ? (MATERIAL_DISPLAY_NAME[wood] ?? wood) : "wood";
88 }
@@ -0,0 +1,88 @@
1import { ItemCategory } from "./itemCategories.js";
2import {
3 MagicElement,
4 MAGIC_ELEMENT_ORDER,
5 MAGIC_ELEMENT_TINT,
6 ASH_WOOD_FOR_ELEMENT
7} from "./attackTypes.js";
8import { MATERIAL_DISPLAY_NAME } from "./materialTiers.js";
9
10/**
11 * Elemental essences dropped by sprites (100%). Share the ash sprite, tinted per element.
12 */
13export const EssenceItemId = Object.freeze({
14 [MagicElement.fire]: 424,
15 [MagicElement.water]: 425,
16 [MagicElement.air]: 426,
17 [MagicElement.earth]: 427,
18 [MagicElement.light]: 428,
19 [MagicElement.dark]: 429,
20 [MagicElement.poison]: 430
21});
22
23const ELEMENT_DISPLAY = Object.freeze({
24 [MagicElement.fire]: "Fire",
25 [MagicElement.water]: "Water",
26 [MagicElement.air]: "Air",
27 [MagicElement.earth]: "Earth",
28 [MagicElement.light]: "Light",
29 [MagicElement.dark]: "Dark",
30 [MagicElement.poison]: "Poison"
31});
32
33function buildEssenceDefinitions ()
34{
35 const defs = {};
36 for (const element of MAGIC_ELEMENT_ORDER)
37 {
38 const itemId = EssenceItemId[element];
39 const name = ELEMENT_DISPLAY[element] ?? element;
40 const tint = MAGIC_ELEMENT_TINT[element];
41 defs[itemId] = Object.freeze({
42 itemId,
43 key: `${element}-essence`,
44 displayName: `${name} essence`,
45 description: `A condensed mote of ${name.toLowerCase()}, shed by a sprite.`,
46 seedValue: 8,
47 stackable: true,
48 maxStackSize: 99,
49 uniqueInstance: false,
50 category: ItemCategory.ingredient,
51 iconKey: "ash",
52 defaultState: "ash",
53 essenceElement: element,
54 tint: Object.freeze({ r: tint.r, g: tint.g, b: tint.b })
55 });
56 }
57 return defs;
58}
59
60export const ESSENCE_ITEM_DEFINITIONS = Object.freeze(buildEssenceDefinitions());
61
62export function essenceItemIdForElement (element)
63{
64 return EssenceItemId[element] ?? null;
65}
66
67export function essenceElementDisplayName (element)
68{
69 return ELEMENT_DISPLAY[element] ?? element;
70}
71
72/** Ash wood tier used when brewing the coating for this element. */
73export function ashWoodForCoatingElement (element)
74{
75 return ASH_WOOD_FOR_ELEMENT[element] ?? null;
76}
77
78export function coatingDisplayName (element)
79{
80 const name = ELEMENT_DISPLAY[element] ?? element;
81 return `${name} arrow coating`;
82}
83
84export function coatingAshDisplayName (element)
85{
86 const wood = ashWoodForCoatingElement(element);
87 return wood ? (MATERIAL_DISPLAY_NAME[wood] ?? wood) : "wood";
88}
shared/definitions/familyItemIds.js +6 −0
@@ -8,6 +8,10 @@ import {
8 8 AXE_ITEM_BY_METAL,
9 9 PLANT_CLIPPERS_ITEM_BY_METAL
10 10 } from "./metalItems.js";
11 import {
12 SWORD_BLADE_ITEM_BY_METAL,
13 SWORD_ITEM_BY_METAL
14 } from "./swordItems.js";
11 15 import {
12 16 ARROW_SHAFT_BY_WOOD,
13 17 ARROW_TIP_BY_METAL,
@@ -27,6 +31,8 @@ export const FAMILY_ITEM_IDS = Object.freeze({
27 31 [ItemFamilyId.pickaxe]: PICKAXE_ITEM_BY_METAL,
28 32 [ItemFamilyId.axe]: AXE_ITEM_BY_METAL,
29 33 [ItemFamilyId.plantClippers]: PLANT_CLIPPERS_ITEM_BY_METAL,
34 [ItemFamilyId.swordBlade]: SWORD_BLADE_ITEM_BY_METAL,
35 [ItemFamilyId.sword]: SWORD_ITEM_BY_METAL,
30 36 [ItemFamilyId.arrowShaft]: ARROW_SHAFT_BY_WOOD,
31 37 [ItemFamilyId.arrowTip]: ARROW_TIP_BY_METAL,
32 38 [ItemFamilyId.arrow]: ARROW_BY_METAL,
@@ -8,6 +8,10 @@ import {
8 AXE_ITEM_BY_METAL,
8 AXE_ITEM_BY_METAL,
9 PLANT_CLIPPERS_ITEM_BY_METAL
9 PLANT_CLIPPERS_ITEM_BY_METAL
10} from "./metalItems.js";
10} from "./metalItems.js";
11import {
12 SWORD_BLADE_ITEM_BY_METAL,
13 SWORD_ITEM_BY_METAL
14} from "./swordItems.js";
11import {
15import {
12 ARROW_SHAFT_BY_WOOD,
16 ARROW_SHAFT_BY_WOOD,
13 ARROW_TIP_BY_METAL,
17 ARROW_TIP_BY_METAL,
@@ -27,6 +31,8 @@ export const FAMILY_ITEM_IDS = Object.freeze({
27 [ItemFamilyId.pickaxe]: PICKAXE_ITEM_BY_METAL,
31 [ItemFamilyId.pickaxe]: PICKAXE_ITEM_BY_METAL,
28 [ItemFamilyId.axe]: AXE_ITEM_BY_METAL,
32 [ItemFamilyId.axe]: AXE_ITEM_BY_METAL,
29 [ItemFamilyId.plantClippers]: PLANT_CLIPPERS_ITEM_BY_METAL,
33 [ItemFamilyId.plantClippers]: PLANT_CLIPPERS_ITEM_BY_METAL,
34 [ItemFamilyId.swordBlade]: SWORD_BLADE_ITEM_BY_METAL,
35 [ItemFamilyId.sword]: SWORD_ITEM_BY_METAL,
30 [ItemFamilyId.arrowShaft]: ARROW_SHAFT_BY_WOOD,
36 [ItemFamilyId.arrowShaft]: ARROW_SHAFT_BY_WOOD,
31 [ItemFamilyId.arrowTip]: ARROW_TIP_BY_METAL,
37 [ItemFamilyId.arrowTip]: ARROW_TIP_BY_METAL,
32 [ItemFamilyId.arrow]: ARROW_BY_METAL,
38 [ItemFamilyId.arrow]: ARROW_BY_METAL,
shared/definitions/items.js +14 −0
@@ -18,6 +18,8 @@ import { POTION_MAX_STACK } from "./alchemy.js";
18 18 import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
19 19 import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
20 20 import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
21 import { SwordItemId, SWORD_ITEM_DEFINITIONS } from "./swordItems.js";
22 import { EssenceItemId, ESSENCE_ITEM_DEFINITIONS } from "./essenceItems.js";
21 23
22 24 export const ItemId = Object.freeze({
23 25 paper: 1,
@@ -282,6 +284,8 @@ export const ITEM_DEFINITIONS = Object.freeze({
282 284 ...SPELLBOOK_ITEM_DEFINITIONS,
283 285 ...FISH_ITEM_DEFINITIONS,
284 286 ...GEM_ITEM_DEFINITIONS,
287 ...SWORD_ITEM_DEFINITIONS,
288 ...ESSENCE_ITEM_DEFINITIONS,
285 289 [DyeItemId.flower]: FLOWER_ITEM_DEFINITION,
286 290 [DyeItemId.dye]: DYE_ITEM_DEFINITION
287 291 });
@@ -341,6 +345,12 @@ export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
341 345 const charges = Math.max(0, stack.instance.charges | 0);
342 346 return `${def.displayName} (${charges})`;
343 347 }
348 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
349 {
350 const el = String(stack.instance.element);
351 const label = el.charAt(0).toUpperCase() + el.slice(1);
352 return `${label} ${def.displayName ?? "arrow"}`;
353 }
344 354 return def.displayName ?? "Item";
345 355 }
346 356
@@ -426,6 +436,8 @@ export function itemSpriteName (itemId, instance = null)
426 436 { return spriteImageName("item", "paper", "paper"); }
427 437 if (itemId === ItemId.letter)
428 438 { return spriteImageName("item", "letter", letterVisualState(instance)); }
439 if (instance?.kind === "tipped-arrow")
440 { return spriteImageName("item", "arrow", "tipped-arrow"); }
429 441 const folderKey = def.iconKey ?? def.key;
430 442 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def));
431 443 }
@@ -501,6 +513,8 @@ export function itemAssetPathForStack (stack)
501 513 { return `/assets/items/potion/potion-0.png`; }
502 514 if (stack.itemId === ItemId.flower)
503 515 { return `/assets/items/flower/flower.png`; }
516 if (stack.instance?.kind === "tipped-arrow")
517 { return `/assets/items/arrow/tipped-arrow.png`; }
504 518 return itemAssetPath(stack.itemId, null, stack.instance);
505 519 }
506 520
@@ -18,6 +18,8 @@ import { POTION_MAX_STACK } from "./alchemy.js";
18import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
18import { SpellbookItemId, SPELLBOOK_ITEM_DEFINITIONS } from "./spellItems.js";
19import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
19import { FISH_ITEM_DEFINITIONS, FishingToolItemId } from "./fishItems.js";
20import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
20import { GemItemId, GEM_ITEM_DEFINITIONS } from "./gemItems.js";
21import { SwordItemId, SWORD_ITEM_DEFINITIONS } from "./swordItems.js";
22import { EssenceItemId, ESSENCE_ITEM_DEFINITIONS } from "./essenceItems.js";
21
23
22export const ItemId = Object.freeze({
24export const ItemId = Object.freeze({
23 paper: 1,
25 paper: 1,
@@ -282,6 +284,8 @@ export const ITEM_DEFINITIONS = Object.freeze({
282 ...SPELLBOOK_ITEM_DEFINITIONS,
284 ...SPELLBOOK_ITEM_DEFINITIONS,
283 ...FISH_ITEM_DEFINITIONS,
285 ...FISH_ITEM_DEFINITIONS,
284 ...GEM_ITEM_DEFINITIONS,
286 ...GEM_ITEM_DEFINITIONS,
287 ...SWORD_ITEM_DEFINITIONS,
288 ...ESSENCE_ITEM_DEFINITIONS,
285 [DyeItemId.flower]: FLOWER_ITEM_DEFINITION,
289 [DyeItemId.flower]: FLOWER_ITEM_DEFINITION,
286 [DyeItemId.dye]: DYE_ITEM_DEFINITION
290 [DyeItemId.dye]: DYE_ITEM_DEFINITION
287});
291});
@@ -341,6 +345,12 @@ export function itemDisplayName (stack, def = itemDefinition(stack?.itemId))
341 const charges = Math.max(0, stack.instance.charges | 0);
345 const charges = Math.max(0, stack.instance.charges | 0);
342 return `${def.displayName} (${charges})`;
346 return `${def.displayName} (${charges})`;
343 }
347 }
348 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
349 {
350 const el = String(stack.instance.element);
351 const label = el.charAt(0).toUpperCase() + el.slice(1);
352 return `${label} ${def.displayName ?? "arrow"}`;
353 }
344 return def.displayName ?? "Item";
354 return def.displayName ?? "Item";
345}
355}
346
356
@@ -426,6 +436,8 @@ export function itemSpriteName (itemId, instance = null)
426 { return spriteImageName("item", "paper", "paper"); }
436 { return spriteImageName("item", "paper", "paper"); }
427 if (itemId === ItemId.letter)
437 if (itemId === ItemId.letter)
428 { return spriteImageName("item", "letter", letterVisualState(instance)); }
438 { return spriteImageName("item", "letter", letterVisualState(instance)); }
439 if (instance?.kind === "tipped-arrow")
440 { return spriteImageName("item", "arrow", "tipped-arrow"); }
429 const folderKey = def.iconKey ?? def.key;
441 const folderKey = def.iconKey ?? def.key;
430 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def));
442 return def.sprite ?? spriteImageName("item", folderKey, itemDefaultState(def));
431}
443}
@@ -501,6 +513,8 @@ export function itemAssetPathForStack (stack)
501 { return `/assets/items/potion/potion-0.png`; }
513 { return `/assets/items/potion/potion-0.png`; }
502 if (stack.itemId === ItemId.flower)
514 if (stack.itemId === ItemId.flower)
503 { return `/assets/items/flower/flower.png`; }
515 { return `/assets/items/flower/flower.png`; }
516 if (stack.instance?.kind === "tipped-arrow")
517 { return `/assets/items/arrow/tipped-arrow.png`; }
504 return itemAssetPath(stack.itemId, null, stack.instance);
518 return itemAssetPath(stack.itemId, null, stack.instance);
505}
519}
506
520
shared/definitions/materialTiers.js +13 −0
@@ -540,6 +540,19 @@ export function woodTierForMetal (metalTier)
540 540 return WOOD_TIER_FOR_METAL[metalTier] ?? WoodTier.pine;
541 541 }
542 542
543 /** Matching leather material for a metal tier (bronze↔soft … dragon↔dragonhide). */
544 export function leatherTierForMetal (metalTier)
545 {
546 const idx = MATERIAL_TIER_ORDER.indexOf(metalTier);
547 return LEATHER_TIER_ORDER[idx >= 0 ? idx : 0] ?? LeatherTier.softLeather;
548 }
549
550 export function metalTierForLeather (leatherTier)
551 {
552 const idx = LEATHER_TIER_ORDER.indexOf(leatherTier);
553 return MATERIAL_TIER_ORDER[idx >= 0 ? idx : 0] ?? MaterialTier.bronze;
554 }
555
543 556 /** Matching wood tier for a gemstone (tourmaline↔pine … jadeite↔elder). */
544 557 export function woodTierForGem (gemTier)
545 558 {
@@ -540,6 +540,19 @@ export function woodTierForMetal (metalTier)
540 return WOOD_TIER_FOR_METAL[metalTier] ?? WoodTier.pine;
540 return WOOD_TIER_FOR_METAL[metalTier] ?? WoodTier.pine;
541}
541}
542
542
543/** Matching leather material for a metal tier (bronze↔soft … dragon↔dragonhide). */
544export function leatherTierForMetal (metalTier)
545{
546 const idx = MATERIAL_TIER_ORDER.indexOf(metalTier);
547 return LEATHER_TIER_ORDER[idx >= 0 ? idx : 0] ?? LeatherTier.softLeather;
548}
549
550export function metalTierForLeather (leatherTier)
551{
552 const idx = LEATHER_TIER_ORDER.indexOf(leatherTier);
553 return MATERIAL_TIER_ORDER[idx >= 0 ? idx : 0] ?? MaterialTier.bronze;
554}
555
543/** Matching wood tier for a gemstone (tourmaline↔pine … jadeite↔elder). */
556/** Matching wood tier for a gemstone (tourmaline↔pine … jadeite↔elder). */
544export function woodTierForGem (gemTier)
557export function woodTierForGem (gemTier)
545{
558{
shared/definitions/mobs.js +43 −4
@@ -6,6 +6,7 @@ import { RangedItemId } from "./rangedItems.js";
6 6 import { ArmourItemId } from "./armourItems.js";
7 7 import { WoodItemId } from "./woodItems.js";
8 8 import { ItemId } from "./items.js";
9 import { spellDefinition } from "./spells.js";
9 10
10 11 export const MobId = Object.freeze({
11 12 deer: "deer",
@@ -18,7 +19,9 @@ export const MobId = Object.freeze({
18 19 /** Editor/spawner identity for Central Exchange staff (always humanoid bodies). */
19 20 centralExchange: "central-exchange",
20 21 /** Temporary Shade summon (spell). */
21 shade: "shade"
22 shade: "shade",
23 /** Elemental sprite — random element on spawn, drops essence, emits light. */
24 sprite: "sprite"
22 25 });
23 26
24 27 /** @typedef {{ itemId: number, chance: number, quantity?: number, quantityMin?: number, quantityMax?: number }} MobDrop */
@@ -174,6 +177,39 @@ export const MOB_DEFINITIONS = Object.freeze({
174 177 framesPerRow: 1,
175 178 animationSpeed: 0
176 179 }),
180 [MobId.sprite]: Object.freeze({
181 mobTypeId: MobId.sprite,
182 key: "sprite",
183 assetFolder: "mobs",
184 displayName: "Sprite",
185 health: 35,
186 maxHealth: 35,
187 maxHealthFromLevel: "levelPlus10",
188 attackSkill: 25,
189 attackCooldownMs: 1100,
190 drops: Object.freeze([]),
191 /** Essence drop is resolved from the creature's chosen element on death. */
192 essenceDropChance: 1,
193 sells: Object.freeze([]),
194 dialogue: Object.freeze([]),
195 persistent: false,
196 flying: false,
197 freeFlight: false,
198 ambient: false,
199 talkable: false,
200 untargetable: false,
201 aggressive: true,
202 aggroRangeTiles: 6,
203 preferSpellAttack: true,
204 lightRadiusTiles: 2,
205 randomElementOnSpawn: true,
206 bloomBody: true,
207 gait: "walk",
208 sex: "male",
209 frames: 2,
210 framesPerRow: 2,
211 animationSpeed: 0.5
212 }),
177 213 [MobId.humanoid]: Object.freeze({
178 214 mobTypeId: MobId.humanoid,
179 215 key: "humanoid",
@@ -280,6 +316,8 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
280 316 const townGuard = mobTypeId === MobId.townGuard;
281 317 const centralExchange = mobTypeId === MobId.centralExchange;
282 318 const bodyNpc = humanoid || townGuard || centralExchange;
319 const level = townGuard ? 30 : (mobTypeId === MobId.sprite ? 25 : 1);
320 const bounty = townGuard ? 500 : 0;
283 321 return {
284 322 spawnerId,
285 323 mobTypeId,
@@ -290,8 +328,8 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
290 328 respawnDelaySeconds: 25,
291 329 spawnRangeTiles: bodyNpc ? 1 : 4,
292 330 maxWanderRangeTiles: bodyNpc ? 1 : 8,
293 level: townGuard ? 30 : 1,
294 bounty: townGuard ? 500 : 0,
331 level,
332 bounty,
295 333 /** Humanoid spawners only: auto-engage players in aggro range. Forces bounty 0. */
296 334 aggressive: false,
297 335 sex: "male",
@@ -474,7 +512,8 @@ function normalizeSpells (raw)
474 512 if (!entry || typeof entry !== "object")
475 513 { continue; }
476 514 const spellId = String(entry.spellId ?? "").trim();
477 if (!spellId || seen.has(spellId))
515 // Drop unknown / retired ids (e.g. legacy spark) so spawners stay loadable.
516 if (!spellId || seen.has(spellId) || !spellDefinition(spellId))
478 517 { continue; }
479 518 seen.add(spellId);
480 519 // Cast chance is derived from mob level at spawn time — not stored.
@@ -6,6 +6,7 @@ import { RangedItemId } from "./rangedItems.js";
6import { ArmourItemId } from "./armourItems.js";
6import { ArmourItemId } from "./armourItems.js";
7import { WoodItemId } from "./woodItems.js";
7import { WoodItemId } from "./woodItems.js";
8import { ItemId } from "./items.js";
8import { ItemId } from "./items.js";
9import { spellDefinition } from "./spells.js";
9
10
10export const MobId = Object.freeze({
11export const MobId = Object.freeze({
11 deer: "deer",
12 deer: "deer",
@@ -18,7 +19,9 @@ export const MobId = Object.freeze({
18 /** Editor/spawner identity for Central Exchange staff (always humanoid bodies). */
19 /** Editor/spawner identity for Central Exchange staff (always humanoid bodies). */
19 centralExchange: "central-exchange",
20 centralExchange: "central-exchange",
20 /** Temporary Shade summon (spell). */
21 /** Temporary Shade summon (spell). */
21 shade: "shade"
22 shade: "shade",
23 /** Elemental sprite — random element on spawn, drops essence, emits light. */
24 sprite: "sprite"
22});
25});
23
26
24/** @typedef {{ itemId: number, chance: number, quantity?: number, quantityMin?: number, quantityMax?: number }} MobDrop */
27/** @typedef {{ itemId: number, chance: number, quantity?: number, quantityMin?: number, quantityMax?: number }} MobDrop */
@@ -174,6 +177,39 @@ export const MOB_DEFINITIONS = Object.freeze({
174 framesPerRow: 1,
177 framesPerRow: 1,
175 animationSpeed: 0
178 animationSpeed: 0
176 }),
179 }),
180 [MobId.sprite]: Object.freeze({
181 mobTypeId: MobId.sprite,
182 key: "sprite",
183 assetFolder: "mobs",
184 displayName: "Sprite",
185 health: 35,
186 maxHealth: 35,
187 maxHealthFromLevel: "levelPlus10",
188 attackSkill: 25,
189 attackCooldownMs: 1100,
190 drops: Object.freeze([]),
191 /** Essence drop is resolved from the creature's chosen element on death. */
192 essenceDropChance: 1,
193 sells: Object.freeze([]),
194 dialogue: Object.freeze([]),
195 persistent: false,
196 flying: false,
197 freeFlight: false,
198 ambient: false,
199 talkable: false,
200 untargetable: false,
201 aggressive: true,
202 aggroRangeTiles: 6,
203 preferSpellAttack: true,
204 lightRadiusTiles: 2,
205 randomElementOnSpawn: true,
206 bloomBody: true,
207 gait: "walk",
208 sex: "male",
209 frames: 2,
210 framesPerRow: 2,
211 animationSpeed: 0.5
212 }),
177 [MobId.humanoid]: Object.freeze({
213 [MobId.humanoid]: Object.freeze({
178 mobTypeId: MobId.humanoid,
214 mobTypeId: MobId.humanoid,
179 key: "humanoid",
215 key: "humanoid",
@@ -280,6 +316,8 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
280 const townGuard = mobTypeId === MobId.townGuard;
316 const townGuard = mobTypeId === MobId.townGuard;
281 const centralExchange = mobTypeId === MobId.centralExchange;
317 const centralExchange = mobTypeId === MobId.centralExchange;
282 const bodyNpc = humanoid || townGuard || centralExchange;
318 const bodyNpc = humanoid || townGuard || centralExchange;
319 const level = townGuard ? 30 : (mobTypeId === MobId.sprite ? 25 : 1);
320 const bounty = townGuard ? 500 : 0;
283 return {
321 return {
284 spawnerId,
322 spawnerId,
285 mobTypeId,
323 mobTypeId,
@@ -290,8 +328,8 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
290 respawnDelaySeconds: 25,
328 respawnDelaySeconds: 25,
291 spawnRangeTiles: bodyNpc ? 1 : 4,
329 spawnRangeTiles: bodyNpc ? 1 : 4,
292 maxWanderRangeTiles: bodyNpc ? 1 : 8,
330 maxWanderRangeTiles: bodyNpc ? 1 : 8,
293 level: townGuard ? 30 : 1,
331 level,
294 bounty: townGuard ? 500 : 0,
332 bounty,
295 /** Humanoid spawners only: auto-engage players in aggro range. Forces bounty 0. */
333 /** Humanoid spawners only: auto-engage players in aggro range. Forces bounty 0. */
296 aggressive: false,
334 aggressive: false,
297 sex: "male",
335 sex: "male",
@@ -474,7 +512,8 @@ function normalizeSpells (raw)
474 if (!entry || typeof entry !== "object")
512 if (!entry || typeof entry !== "object")
475 { continue; }
513 { continue; }
476 const spellId = String(entry.spellId ?? "").trim();
514 const spellId = String(entry.spellId ?? "").trim();
477 if (!spellId || seen.has(spellId))
515 // Drop unknown / retired ids (e.g. legacy spark) so spawners stay loadable.
516 if (!spellId || seen.has(spellId) || !spellDefinition(spellId))
478 { continue; }
517 { continue; }
479 seen.add(spellId);
518 seen.add(spellId);
480 // Cast chance is derived from mob level at spawn time — not stored.
519 // Cast chance is derived from mob level at spawn time — not stored.
shared/definitions/skills.js +1 −0
@@ -99,6 +99,7 @@ export const UNARMED_ATTACK = Object.freeze({
99 99 rangeTiles: 1,
100 100 hitSkillId: SkillId.unarmed,
101 101 damageSkillId: SkillId.strength,
102 attackType: "blunt",
102 103 cooldownMs: 800
103 104 });
104 105
@@ -99,6 +99,7 @@ export const UNARMED_ATTACK = Object.freeze({
99 rangeTiles: 1,
99 rangeTiles: 1,
100 hitSkillId: SkillId.unarmed,
100 hitSkillId: SkillId.unarmed,
101 damageSkillId: SkillId.strength,
101 damageSkillId: SkillId.strength,
102 attackType: "blunt",
102 cooldownMs: 800
103 cooldownMs: 800
103});
104});
104
105
shared/definitions/spellItems.js +42 −4
@@ -1,9 +1,11 @@
1 1 import { ItemCategory } from "./itemCategories.js";
2 2 import { SpellId, spellDefinition, learnableSpellIds } from "./spells.js";
3 3
4 /** Stable ids for spellbooks (spark keeps legacy 134). */
4 /**
5 * Stable spellbook item ids.
6 * Legacy spark spellbook (134) is retired — id kept unused so saves do not collide.
7 */
5 8 const SPELLBOOK_ID_BY_SPELL = Object.freeze({
6 [SpellId.spark]: 134,
7 9 [SpellId.dark]: 391,
8 10 [SpellId.firebolt]: 392,
9 11 [SpellId.fireball]: 393,
@@ -14,7 +16,43 @@ const SPELLBOOK_ID_BY_SPELL = Object.freeze({
14 16 [SpellId.drain]: 398,
15 17 [SpellId.tinders]: 399,
16 18 [SpellId.shade]: 400,
17 [SpellId.revitalize]: 401
19 [SpellId.revitalize]: 401,
20 // Water tree
21 [SpellId.waterbolt]: 431,
22 [SpellId.waterspout]: 432,
23 [SpellId.torrent]: 433,
24 [SpellId.deluge]: 434,
25 [SpellId.maelstrom]: 435,
26 // Air tree
27 [SpellId.airbolt]: 436,
28 [SpellId.gale]: 437,
29 [SpellId.cyclone]: 438,
30 [SpellId.tempest]: 439,
31 [SpellId.hurricane]: 440,
32 // Earth tree
33 [SpellId.earthbolt]: 441,
34 [SpellId.boulder]: 442,
35 [SpellId.quake]: 443,
36 [SpellId.landslide]: 444,
37 [SpellId.cataclysm]: 445,
38 // Light tree
39 [SpellId.lightbolt]: 446,
40 [SpellId.radiance]: 447,
41 [SpellId.flare]: 448,
42 [SpellId.sunbeam]: 449,
43 [SpellId.judgment]: 450,
44 // Dark tree
45 [SpellId.darkbolt]: 451,
46 [SpellId.gloom]: 452,
47 [SpellId.voidlance]: 453,
48 [SpellId.eclipse]: 454,
49 [SpellId.oblivion]: 455,
50 // Poison tree
51 [SpellId.poisonbolt]: 456,
52 [SpellId.toxinburst]: 457,
53 [SpellId.venomcloud]: 458,
54 [SpellId.plague]: 459,
55 [SpellId.blight]: 460
18 56 });
19 57
20 58 export const SpellbookItemId = Object.freeze(
@@ -59,7 +97,7 @@ function buildSpellbookDefinitions ()
59 97 uniqueInstance: true,
60 98 category: ItemCategory.finished,
61 99 iconKey: "spellbook",
62 defaultState: spellId === SpellId.spark ? "spark" : "spark",
100 defaultState: "spark",
63 101 consumableSpellId: spellId
64 102 });
65 103 }
@@ -1,9 +1,11 @@
1import { ItemCategory } from "./itemCategories.js";
1import { ItemCategory } from "./itemCategories.js";
2import { SpellId, spellDefinition, learnableSpellIds } from "./spells.js";
2import { SpellId, spellDefinition, learnableSpellIds } from "./spells.js";
3
3
4/** Stable ids for spellbooks (spark keeps legacy 134). */
4/**
5 * Stable spellbook item ids.
6 * Legacy spark spellbook (134) is retired — id kept unused so saves do not collide.
7 */
5const SPELLBOOK_ID_BY_SPELL = Object.freeze({
8const SPELLBOOK_ID_BY_SPELL = Object.freeze({
6 [SpellId.spark]: 134,
7 [SpellId.dark]: 391,
9 [SpellId.dark]: 391,
8 [SpellId.firebolt]: 392,
10 [SpellId.firebolt]: 392,
9 [SpellId.fireball]: 393,
11 [SpellId.fireball]: 393,
@@ -14,7 +16,43 @@ const SPELLBOOK_ID_BY_SPELL = Object.freeze({
14 [SpellId.drain]: 398,
16 [SpellId.drain]: 398,
15 [SpellId.tinders]: 399,
17 [SpellId.tinders]: 399,
16 [SpellId.shade]: 400,
18 [SpellId.shade]: 400,
17 [SpellId.revitalize]: 401
19 [SpellId.revitalize]: 401,
20 // Water tree
21 [SpellId.waterbolt]: 431,
22 [SpellId.waterspout]: 432,
23 [SpellId.torrent]: 433,
24 [SpellId.deluge]: 434,
25 [SpellId.maelstrom]: 435,
26 // Air tree
27 [SpellId.airbolt]: 436,
28 [SpellId.gale]: 437,
29 [SpellId.cyclone]: 438,
30 [SpellId.tempest]: 439,
31 [SpellId.hurricane]: 440,
32 // Earth tree
33 [SpellId.earthbolt]: 441,
34 [SpellId.boulder]: 442,
35 [SpellId.quake]: 443,
36 [SpellId.landslide]: 444,
37 [SpellId.cataclysm]: 445,
38 // Light tree
39 [SpellId.lightbolt]: 446,
40 [SpellId.radiance]: 447,
41 [SpellId.flare]: 448,
42 [SpellId.sunbeam]: 449,
43 [SpellId.judgment]: 450,
44 // Dark tree
45 [SpellId.darkbolt]: 451,
46 [SpellId.gloom]: 452,
47 [SpellId.voidlance]: 453,
48 [SpellId.eclipse]: 454,
49 [SpellId.oblivion]: 455,
50 // Poison tree
51 [SpellId.poisonbolt]: 456,
52 [SpellId.toxinburst]: 457,
53 [SpellId.venomcloud]: 458,
54 [SpellId.plague]: 459,
55 [SpellId.blight]: 460
18});
56});
19
57
20export const SpellbookItemId = Object.freeze(
58export const SpellbookItemId = Object.freeze(
@@ -59,7 +97,7 @@ function buildSpellbookDefinitions ()
59 uniqueInstance: true,
97 uniqueInstance: true,
60 category: ItemCategory.finished,
98 category: ItemCategory.finished,
61 iconKey: "spellbook",
99 iconKey: "spellbook",
62 defaultState: spellId === SpellId.spark ? "spark" : "spark",
100 defaultState: "spark",
63 consumableSpellId: spellId
101 consumableSpellId: spellId
64 });
102 });
65 }
103 }
shared/definitions/spells.js +364 −88
@@ -1,4 +1,5 @@
1 1 import { spellDifficultyFromTier } from "../spells/constants.js";
2 import { MagicElement } from "./attackTypes.js";
2 3
3 4 /**
4 5 * @typedef {object} SpellDefinition
@@ -13,24 +14,322 @@ import { spellDifficultyFromTier } from "../spells/constants.js";
13 14 * @property {string} [projectileSprite] fx:projectile:spell-* base name
14 15 * @property {string} [effect] Server impact kind (defaults to spellId)
15 16 * @property {boolean} [starter] Known by default; no spellbook required
17 * @property {boolean} [mobOnly] Not offered on player spellbooks
18 * @property {boolean} [damageTree] Part of an elemental damage progression
16 19 */
17 20
21 /**
22 * Elemental damage trees (tiers 3–7), plus utility / special spells.
23 * Legacy `spark` was removed — unknown ids are dropped on load/normalize.
24 */
18 25 export const SpellId = Object.freeze({
19 26 light: "light",
20 27 dark: "dark",
21 spark: "spark",
28 // Fire damage tree
22 29 firebolt: "firebolt",
23 30 fireball: "fireball",
24 31 blaze: "blaze",
25 32 inferno: "inferno",
26 33 hellfire: "hellfire",
34 // Water damage tree
35 waterbolt: "waterbolt",
36 waterspout: "waterspout",
37 torrent: "torrent",
38 deluge: "deluge",
39 maelstrom: "maelstrom",
40 // Air damage tree
41 airbolt: "airbolt",
42 gale: "gale",
43 cyclone: "cyclone",
44 tempest: "tempest",
45 hurricane: "hurricane",
46 // Earth damage tree
47 earthbolt: "earthbolt",
48 boulder: "boulder",
49 quake: "quake",
50 landslide: "landslide",
51 cataclysm: "cataclysm",
52 // Light damage tree
53 lightbolt: "lightbolt",
54 radiance: "radiance",
55 flare: "flare",
56 sunbeam: "sunbeam",
57 judgment: "judgment",
58 // Dark damage tree
59 darkbolt: "darkbolt",
60 gloom: "gloom",
61 voidlance: "voidlance",
62 eclipse: "eclipse",
63 oblivion: "oblivion",
64 // Poison damage tree
65 poisonbolt: "poisonbolt",
66 toxinburst: "toxinburst",
67 venomcloud: "venomcloud",
68 plague: "plague",
69 blight: "blight",
70 // Utility / special
27 71 poison: "poison",
28 72 drain: "drain",
29 73 tinders: "tinders",
30 74 shade: "shade",
31 revitalize: "revitalize"
75 revitalize: "revitalize",
76 /** Sprite elemental bolts (mob-only; not player spellbooks). */
77 spriteBoltFire: "sprite-bolt-fire",
78 spriteBoltWater: "sprite-bolt-water",
79 spriteBoltAir: "sprite-bolt-air",
80 spriteBoltEarth: "sprite-bolt-earth",
81 spriteBoltLight: "sprite-bolt-light",
82 spriteBoltDark: "sprite-bolt-dark",
83 spriteBoltPoison: "sprite-bolt-poison"
32 84 });
33 85
86 /** Shared projectile art for damage bolts (tinted by element on cast later if needed). */
87 const BOLT_PROJECTILE = "fx:projectile:spell-spark";
88 const LIGHT_PROJECTILE = "fx:projectile:spell-light";
89
90 /**
91 * Damage progression per element — mirrors the fire ladder (tiers 3–7).
92 * @type {ReadonlyArray<{ element: string, spells: ReadonlyArray<{ id: string, name: string, description: string }> }>}
93 */
94 const ELEMENT_DAMAGE_TREES = Object.freeze([
95 Object.freeze({
96 element: MagicElement.fire,
97 spells: Object.freeze([
98 Object.freeze({
99 id: SpellId.firebolt,
100 name: "Firebolt",
101 description: "A fierce bolt of fire that streaks toward a foe and scorches on impact."
102 }),
103 Object.freeze({
104 id: SpellId.fireball,
105 name: "Fireball",
106 description: "A roaring sphere of flame that bursts against whatever it strikes."
107 }),
108 Object.freeze({
109 id: SpellId.blaze,
110 name: "Blaze",
111 description: "A searing tongue of fire that clings to flesh and armour alike."
112 }),
113 Object.freeze({
114 id: SpellId.inferno,
115 name: "Inferno",
116 description: "A storm of fire that overwhelms a foe in a rush of heat and ash."
117 }),
118 Object.freeze({
119 id: SpellId.hellfire,
120 name: "Hellfire",
121 description: "The deepest flame, white-hot and merciless, called down upon a single mark."
122 })
123 ])
124 }),
125 Object.freeze({
126 element: MagicElement.water,
127 spells: Object.freeze([
128 Object.freeze({
129 id: SpellId.waterbolt,
130 name: "Waterbolt",
131 description: "A hard lance of water that strikes like a thrown spear."
132 }),
133 Object.freeze({
134 id: SpellId.waterspout,
135 name: "Waterspout",
136 description: "A rising column of water that hammers a foe from below."
137 }),
138 Object.freeze({
139 id: SpellId.torrent,
140 name: "Torrent",
141 description: "A rushing flood aimed at one mark, crushing and cold."
142 }),
143 Object.freeze({
144 id: SpellId.deluge,
145 name: "Deluge",
146 description: "A cascade of heavy water that batters a foe without mercy."
147 }),
148 Object.freeze({
149 id: SpellId.maelstrom,
150 name: "Maelstrom",
151 description: "A whirling abyss of water that pulls and pounds a single enemy."
152 })
153 ])
154 }),
155 Object.freeze({
156 element: MagicElement.air,
157 spells: Object.freeze([
158 Object.freeze({
159 id: SpellId.airbolt,
160 name: "Airbolt",
161 description: "A compressed dart of wind that cuts the air toward a foe."
162 }),
163 Object.freeze({
164 id: SpellId.gale,
165 name: "Gale",
166 description: "A violent gust that slams into a mark with sudden force."
167 }),
168 Object.freeze({
169 id: SpellId.cyclone,
170 name: "Cyclone",
171 description: "A spinning funnel of air that tears at whatever it catches."
172 }),
173 Object.freeze({
174 id: SpellId.tempest,
175 name: "Tempest",
176 description: "A howling blast that batters a foe with storm-born fury."
177 }),
178 Object.freeze({
179 id: SpellId.hurricane,
180 name: "Hurricane",
181 description: "The full wrath of the sky, focused into one devastating strike."
182 })
183 ])
184 }),
185 Object.freeze({
186 element: MagicElement.earth,
187 spells: Object.freeze([
188 Object.freeze({
189 id: SpellId.earthbolt,
190 name: "Earthbolt",
191 description: "A shard of stone flung hard enough to crack bone."
192 }),
193 Object.freeze({
194 id: SpellId.boulder,
195 name: "Boulder",
196 description: "A mass of rock that crashes into a foe with crushing weight."
197 }),
198 Object.freeze({
199 id: SpellId.quake,
200 name: "Quake",
201 description: "The ground itself heaves beneath a mark, shaking them to pieces."
202 }),
203 Object.freeze({
204 id: SpellId.landslide,
205 name: "Landslide",
206 description: "A surge of earth and rubble that buries a single enemy."
207 }),
208 Object.freeze({
209 id: SpellId.cataclysm,
210 name: "Cataclysm",
211 description: "The deepest earth answers, shattering stone and foe alike."
212 })
213 ])
214 }),
215 Object.freeze({
216 element: MagicElement.light,
217 spells: Object.freeze([
218 Object.freeze({
219 id: SpellId.lightbolt,
220 name: "Lightbolt",
221 description: "A bright lance of radiance that burns where it lands."
222 }),
223 Object.freeze({
224 id: SpellId.radiance,
225 name: "Radiance",
226 description: "A flare of pure light that sears a foe in a white flash."
227 }),
228 Object.freeze({
229 id: SpellId.flare,
230 name: "Flare",
231 description: "A brilliant burst that blinds and burns in the same breath."
232 }),
233 Object.freeze({
234 id: SpellId.sunbeam,
235 name: "Sunbeam",
236 description: "A column of daylight called down upon a single mark."
237 }),
238 Object.freeze({
239 id: SpellId.judgment,
240 name: "Judgment",
241 description: "The fiercest light, pitiless and absolute, cast upon one enemy."
242 })
243 ])
244 }),
245 Object.freeze({
246 element: MagicElement.dark,
247 spells: Object.freeze([
248 Object.freeze({
249 id: SpellId.darkbolt,
250 name: "Darkbolt",
251 description: "A bolt of shadow that bites colder than steel."
252 }),
253 Object.freeze({
254 id: SpellId.gloom,
255 name: "Gloom",
256 description: "A smothering cloud of dark that clings to a foe and drains them."
257 }),
258 Object.freeze({
259 id: SpellId.voidlance,
260 name: "Voidlance",
261 description: "A spear of emptiness that pierces flesh and spirit alike."
262 }),
263 Object.freeze({
264 id: SpellId.eclipse,
265 name: "Eclipse",
266 description: "A sudden night falls on one mark, crushing them in shadow."
267 }),
268 Object.freeze({
269 id: SpellId.oblivion,
270 name: "Oblivion",
271 description: "The deepest dark, called to unmake a single enemy."
272 })
273 ])
274 }),
275 Object.freeze({
276 element: MagicElement.poison,
277 spells: Object.freeze([
278 Object.freeze({
279 id: SpellId.poisonbolt,
280 name: "Poisonbolt",
281 description: "A green-tinged dart that strikes with toxic force."
282 }),
283 Object.freeze({
284 id: SpellId.toxinburst,
285 name: "Toxinburst",
286 description: "A burst of virulent fluid that spatters a foe on impact."
287 }),
288 Object.freeze({
289 id: SpellId.venomcloud,
290 name: "Venomcloud",
291 description: "A choking haze of venom that settles on a single mark."
292 }),
293 Object.freeze({
294 id: SpellId.plague,
295 name: "Plague",
296 description: "A virulent curse that hammers a foe with sickening power."
297 }),
298 Object.freeze({
299 id: SpellId.blight,
300 name: "Blight",
301 description: "The foulest poison, concentrated into one merciless strike."
302 })
303 ])
304 })
305 ]);
306
307 function buildDamageTreeDefinitions ()
308 {
309 const out = {};
310 for (const tree of ELEMENT_DAMAGE_TREES)
311 {
312 tree.spells.forEach((entry, index) =>
313 {
314 const tier = 3 + index;
315 out[entry.id] = Object.freeze({
316 spellId: entry.id,
317 displayName: entry.name,
318 tier,
319 element: tree.element,
320 target: "entity",
321 autoRepeat: true,
322 minMagicLevel: tier,
323 projectileSprite: BOLT_PROJECTILE,
324 effect: "damage",
325 damageTree: true,
326 description: entry.description
327 });
328 });
329 }
330 return out;
331 }
332
34 333 /** @type {Record<string, SpellDefinition>} */
35 334 export const SPELL_DEFINITIONS = Object.freeze({
36 335 [SpellId.light]: Object.freeze({
@@ -42,7 +341,7 @@ export const SPELL_DEFINITIONS = Object.freeze({
42 341 autoRepeat: false,
43 342 minMagicLevel: 1,
44 343 starter: true,
45 projectileSprite: "fx:projectile:spell-light",
344 projectileSprite: LIGHT_PROJECTILE,
46 345 effect: "light",
47 346 description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while."
48 347 }),
@@ -50,95 +349,24 @@ export const SPELL_DEFINITIONS = Object.freeze({
50 349 spellId: SpellId.dark,
51 350 displayName: "Dark",
52 351 tier: 2,
53 element: "dark",
352 element: MagicElement.dark,
54 353 target: "tile",
55 354 autoRepeat: false,
56 355 minMagicLevel: 2,
57 projectileSprite: "fx:projectile:spell-light",
356 projectileSprite: LIGHT_PROJECTILE,
58 357 effect: "dark",
59 358 description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim."
60 359 }),
61 [SpellId.spark]: Object.freeze({
62 spellId: SpellId.spark,
63 displayName: "Spark",
64 tier: 2,
65 element: "fire",
66 target: "entity",
67 autoRepeat: true,
68 minMagicLevel: 2,
69 projectileSprite: "fx:projectile:spell-spark",
70 effect: "damage",
71 description: "A snapping mote of flame that leaps at a foe and bites on arrival."
72 }),
73 [SpellId.firebolt]: Object.freeze({
74 spellId: SpellId.firebolt,
75 displayName: "Firebolt",
76 tier: 3,
77 element: "fire",
78 target: "entity",
79 autoRepeat: true,
80 minMagicLevel: 3,
81 projectileSprite: "fx:projectile:spell-spark",
82 effect: "damage",
83 description: "A fierce bolt of fire that streaks toward a foe and scorches on impact."
84 }),
85 [SpellId.fireball]: Object.freeze({
86 spellId: SpellId.fireball,
87 displayName: "Fireball",
88 tier: 4,
89 element: "fire",
90 target: "entity",
91 autoRepeat: true,
92 minMagicLevel: 4,
93 projectileSprite: "fx:projectile:spell-spark",
94 effect: "damage",
95 description: "A roaring sphere of flame that bursts against whatever it strikes."
96 }),
97 [SpellId.blaze]: Object.freeze({
98 spellId: SpellId.blaze,
99 displayName: "Blaze",
100 tier: 5,
101 element: "fire",
102 target: "entity",
103 autoRepeat: true,
104 minMagicLevel: 5,
105 projectileSprite: "fx:projectile:spell-spark",
106 effect: "damage",
107 description: "A searing tongue of fire that clings to flesh and armour alike."
108 }),
109 [SpellId.inferno]: Object.freeze({
110 spellId: SpellId.inferno,
111 displayName: "Inferno",
112 tier: 6,
113 element: "fire",
114 target: "entity",
115 autoRepeat: true,
116 minMagicLevel: 6,
117 projectileSprite: "fx:projectile:spell-spark",
118 effect: "damage",
119 description: "A storm of fire that overwhelms a foe in a rush of heat and ash."
120 }),
121 [SpellId.hellfire]: Object.freeze({
122 spellId: SpellId.hellfire,
123 displayName: "Hellfire",
124 tier: 7,
125 element: "fire",
126 target: "entity",
127 autoRepeat: true,
128 minMagicLevel: 7,
129 projectileSprite: "fx:projectile:spell-spark",
130 effect: "damage",
131 description: "The deepest flame, white-hot and merciless, called down upon a single mark."
132 }),
360 ...buildDamageTreeDefinitions(),
133 361 [SpellId.poison]: Object.freeze({
134 362 spellId: SpellId.poison,
135 363 displayName: "Poison",
136 364 tier: 3,
137 element: "earth",
365 element: MagicElement.earth,
138 366 target: "entity",
139 367 autoRepeat: true,
140 368 minMagicLevel: 3,
141 projectileSprite: "fx:projectile:spell-spark",
369 projectileSprite: BOLT_PROJECTILE,
142 370 effect: "poison",
143 371 description: "A venomous curse that sinks in without a wound, then eats at the body over time."
144 372 }),
@@ -146,11 +374,11 @@ export const SPELL_DEFINITIONS = Object.freeze({
146 374 spellId: SpellId.drain,
147 375 displayName: "Drain",
148 376 tier: 4,
149 element: "dark",
377 element: MagicElement.dark,
150 378 target: "entity",
151 379 autoRepeat: true,
152 380 minMagicLevel: 4,
153 projectileSprite: "fx:projectile:spell-light",
381 projectileSprite: LIGHT_PROJECTILE,
154 382 effect: "drain",
155 383 description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover."
156 384 }),
@@ -158,11 +386,11 @@ export const SPELL_DEFINITIONS = Object.freeze({
158 386 spellId: SpellId.tinders,
159 387 displayName: "Tinders",
160 388 tier: 3,
161 element: "fire",
389 element: MagicElement.fire,
162 390 target: "tile",
163 391 autoRepeat: false,
164 392 minMagicLevel: 3,
165 projectileSprite: "fx:projectile:spell-spark",
393 projectileSprite: BOLT_PROJECTILE,
166 394 effect: "tinders",
167 395 description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would."
168 396 }),
@@ -170,11 +398,11 @@ export const SPELL_DEFINITIONS = Object.freeze({
170 398 spellId: SpellId.shade,
171 399 displayName: "Shade",
172 400 tier: 6,
173 element: "dark",
401 element: MagicElement.dark,
174 402 target: "tile",
175 403 autoRepeat: false,
176 404 minMagicLevel: 6,
177 projectileSprite: "fx:projectile:spell-light",
405 projectileSprite: LIGHT_PROJECTILE,
178 406 effect: "shade",
179 407 description: "A summoned shadow that fights beside you until the magic frays."
180 408 }),
@@ -186,12 +414,60 @@ export const SPELL_DEFINITIONS = Object.freeze({
186 414 target: "entity",
187 415 autoRepeat: false,
188 416 minMagicLevel: 5,
189 projectileSprite: "fx:projectile:spell-light",
417 projectileSprite: LIGHT_PROJECTILE,
190 418 effect: "revitalize",
191 419 description: "A gentle current of life that mends wounds one breath at a time."
192 })
420 }),
421 [SpellId.spriteBoltFire]: spriteBoltDef(SpellId.spriteBoltFire, "Fire spark", MagicElement.fire),
422 [SpellId.spriteBoltWater]: spriteBoltDef(SpellId.spriteBoltWater, "Water spark", MagicElement.water),
423 [SpellId.spriteBoltAir]: spriteBoltDef(SpellId.spriteBoltAir, "Air spark", MagicElement.air),
424 [SpellId.spriteBoltEarth]: spriteBoltDef(SpellId.spriteBoltEarth, "Earth spark", MagicElement.earth),
425 [SpellId.spriteBoltLight]: spriteBoltDef(SpellId.spriteBoltLight, "Light spark", MagicElement.light),
426 [SpellId.spriteBoltDark]: spriteBoltDef(SpellId.spriteBoltDark, "Dark spark", MagicElement.dark),
427 [SpellId.spriteBoltPoison]: spriteBoltDef(SpellId.spriteBoltPoison, "Poison spark", MagicElement.poison)
428 });
429
430 function spriteBoltDef (spellId, displayName, element)
431 {
432 return Object.freeze({
433 spellId,
434 displayName,
435 tier: 2,
436 element,
437 target: "entity",
438 autoRepeat: true,
439 minMagicLevel: 1,
440 projectileSprite: BOLT_PROJECTILE,
441 effect: "damage",
442 mobOnly: true,
443 description: `A flickering ${element} mote cast by a sprite.`
444 });
445 }
446
447 export const SPRITE_BOLT_SPELL_BY_ELEMENT = Object.freeze({
448 [MagicElement.fire]: SpellId.spriteBoltFire,
449 [MagicElement.water]: SpellId.spriteBoltWater,
450 [MagicElement.air]: SpellId.spriteBoltAir,
451 [MagicElement.earth]: SpellId.spriteBoltEarth,
452 [MagicElement.light]: SpellId.spriteBoltLight,
453 [MagicElement.dark]: SpellId.spriteBoltDark,
454 [MagicElement.poison]: SpellId.spriteBoltPoison
193 455 });
194 456
457 /** Damage-tree spell ids grouped by element (for UI / editors). */
458 export function damageTreeSpellIds (element = null)
459 {
460 const ids = [];
461 for (const tree of ELEMENT_DAMAGE_TREES)
462 {
463 if (element && tree.element !== element)
464 { continue; }
465 for (const spell of tree.spells)
466 { ids.push(spell.id); }
467 }
468 return ids;
469 }
470
195 471 export function spellDefinition (spellId)
196 472 {
197 473 return SPELL_DEFINITIONS[spellId] ?? null;
@@ -206,6 +482,6 @@ export function spellDifficulty (spellDef)
206 482 export function learnableSpellIds ()
207 483 {
208 484 return Object.values(SPELL_DEFINITIONS)
209 .filter((def) => !def.starter)
485 .filter((def) => !def.starter && !def.mobOnly)
210 486 .map((def) => def.spellId);
211 487 }
@@ -1,4 +1,5 @@
1import { spellDifficultyFromTier } from "../spells/constants.js";
1import { spellDifficultyFromTier } from "../spells/constants.js";
2import { MagicElement } from "./attackTypes.js";
2
3
3/**
4/**
4 * @typedef {object} SpellDefinition
5 * @typedef {object} SpellDefinition
@@ -13,24 +14,322 @@ import { spellDifficultyFromTier } from "../spells/constants.js";
13 * @property {string} [projectileSprite] fx:projectile:spell-* base name
14 * @property {string} [projectileSprite] fx:projectile:spell-* base name
14 * @property {string} [effect] Server impact kind (defaults to spellId)
15 * @property {string} [effect] Server impact kind (defaults to spellId)
15 * @property {boolean} [starter] Known by default; no spellbook required
16 * @property {boolean} [starter] Known by default; no spellbook required
17 * @property {boolean} [mobOnly] Not offered on player spellbooks
18 * @property {boolean} [damageTree] Part of an elemental damage progression
16 */
19 */
17
20
21/**
22 * Elemental damage trees (tiers 3–7), plus utility / special spells.
23 * Legacy `spark` was removed — unknown ids are dropped on load/normalize.
24 */
18export const SpellId = Object.freeze({
25export const SpellId = Object.freeze({
19 light: "light",
26 light: "light",
20 dark: "dark",
27 dark: "dark",
21 spark: "spark",
28 // Fire damage tree
22 firebolt: "firebolt",
29 firebolt: "firebolt",
23 fireball: "fireball",
30 fireball: "fireball",
24 blaze: "blaze",
31 blaze: "blaze",
25 inferno: "inferno",
32 inferno: "inferno",
26 hellfire: "hellfire",
33 hellfire: "hellfire",
34 // Water damage tree
35 waterbolt: "waterbolt",
36 waterspout: "waterspout",
37 torrent: "torrent",
38 deluge: "deluge",
39 maelstrom: "maelstrom",
40 // Air damage tree
41 airbolt: "airbolt",
42 gale: "gale",
43 cyclone: "cyclone",
44 tempest: "tempest",
45 hurricane: "hurricane",
46 // Earth damage tree
47 earthbolt: "earthbolt",
48 boulder: "boulder",
49 quake: "quake",
50 landslide: "landslide",
51 cataclysm: "cataclysm",
52 // Light damage tree
53 lightbolt: "lightbolt",
54 radiance: "radiance",
55 flare: "flare",
56 sunbeam: "sunbeam",
57 judgment: "judgment",
58 // Dark damage tree
59 darkbolt: "darkbolt",
60 gloom: "gloom",
61 voidlance: "voidlance",
62 eclipse: "eclipse",
63 oblivion: "oblivion",
64 // Poison damage tree
65 poisonbolt: "poisonbolt",
66 toxinburst: "toxinburst",
67 venomcloud: "venomcloud",
68 plague: "plague",
69 blight: "blight",
70 // Utility / special
27 poison: "poison",
71 poison: "poison",
28 drain: "drain",
72 drain: "drain",
29 tinders: "tinders",
73 tinders: "tinders",
30 shade: "shade",
74 shade: "shade",
31 revitalize: "revitalize"
75 revitalize: "revitalize",
76 /** Sprite elemental bolts (mob-only; not player spellbooks). */
77 spriteBoltFire: "sprite-bolt-fire",
78 spriteBoltWater: "sprite-bolt-water",
79 spriteBoltAir: "sprite-bolt-air",
80 spriteBoltEarth: "sprite-bolt-earth",
81 spriteBoltLight: "sprite-bolt-light",
82 spriteBoltDark: "sprite-bolt-dark",
83 spriteBoltPoison: "sprite-bolt-poison"
32});
84});
33
85
86/** Shared projectile art for damage bolts (tinted by element on cast later if needed). */
87const BOLT_PROJECTILE = "fx:projectile:spell-spark";
88const LIGHT_PROJECTILE = "fx:projectile:spell-light";
89
90/**
91 * Damage progression per element — mirrors the fire ladder (tiers 3–7).
92 * @type {ReadonlyArray<{ element: string, spells: ReadonlyArray<{ id: string, name: string, description: string }> }>}
93 */
94const ELEMENT_DAMAGE_TREES = Object.freeze([
95 Object.freeze({
96 element: MagicElement.fire,
97 spells: Object.freeze([
98 Object.freeze({
99 id: SpellId.firebolt,
100 name: "Firebolt",
101 description: "A fierce bolt of fire that streaks toward a foe and scorches on impact."
102 }),
103 Object.freeze({
104 id: SpellId.fireball,
105 name: "Fireball",
106 description: "A roaring sphere of flame that bursts against whatever it strikes."
107 }),
108 Object.freeze({
109 id: SpellId.blaze,
110 name: "Blaze",
111 description: "A searing tongue of fire that clings to flesh and armour alike."
112 }),
113 Object.freeze({
114 id: SpellId.inferno,
115 name: "Inferno",
116 description: "A storm of fire that overwhelms a foe in a rush of heat and ash."
117 }),
118 Object.freeze({
119 id: SpellId.hellfire,
120 name: "Hellfire",
121 description: "The deepest flame, white-hot and merciless, called down upon a single mark."
122 })
123 ])
124 }),
125 Object.freeze({
126 element: MagicElement.water,
127 spells: Object.freeze([
128 Object.freeze({
129 id: SpellId.waterbolt,
130 name: "Waterbolt",
131 description: "A hard lance of water that strikes like a thrown spear."
132 }),
133 Object.freeze({
134 id: SpellId.waterspout,
135 name: "Waterspout",
136 description: "A rising column of water that hammers a foe from below."
137 }),
138 Object.freeze({
139 id: SpellId.torrent,
140 name: "Torrent",
141 description: "A rushing flood aimed at one mark, crushing and cold."
142 }),
143 Object.freeze({
144 id: SpellId.deluge,
145 name: "Deluge",
146 description: "A cascade of heavy water that batters a foe without mercy."
147 }),
148 Object.freeze({
149 id: SpellId.maelstrom,
150 name: "Maelstrom",
151 description: "A whirling abyss of water that pulls and pounds a single enemy."
152 })
153 ])
154 }),
155 Object.freeze({
156 element: MagicElement.air,
157 spells: Object.freeze([
158 Object.freeze({
159 id: SpellId.airbolt,
160 name: "Airbolt",
161 description: "A compressed dart of wind that cuts the air toward a foe."
162 }),
163 Object.freeze({
164 id: SpellId.gale,
165 name: "Gale",
166 description: "A violent gust that slams into a mark with sudden force."
167 }),
168 Object.freeze({
169 id: SpellId.cyclone,
170 name: "Cyclone",
171 description: "A spinning funnel of air that tears at whatever it catches."
172 }),
173 Object.freeze({
174 id: SpellId.tempest,
175 name: "Tempest",
176 description: "A howling blast that batters a foe with storm-born fury."
177 }),
178 Object.freeze({
179 id: SpellId.hurricane,
180 name: "Hurricane",
181 description: "The full wrath of the sky, focused into one devastating strike."
182 })
183 ])
184 }),
185 Object.freeze({
186 element: MagicElement.earth,
187 spells: Object.freeze([
188 Object.freeze({
189 id: SpellId.earthbolt,
190 name: "Earthbolt",
191 description: "A shard of stone flung hard enough to crack bone."
192 }),
193 Object.freeze({
194 id: SpellId.boulder,
195 name: "Boulder",
196 description: "A mass of rock that crashes into a foe with crushing weight."
197 }),
198 Object.freeze({
199 id: SpellId.quake,
200 name: "Quake",
201 description: "The ground itself heaves beneath a mark, shaking them to pieces."
202 }),
203 Object.freeze({
204 id: SpellId.landslide,
205 name: "Landslide",
206 description: "A surge of earth and rubble that buries a single enemy."
207 }),
208 Object.freeze({
209 id: SpellId.cataclysm,
210 name: "Cataclysm",
211 description: "The deepest earth answers, shattering stone and foe alike."
212 })
213 ])
214 }),
215 Object.freeze({
216 element: MagicElement.light,
217 spells: Object.freeze([
218 Object.freeze({
219 id: SpellId.lightbolt,
220 name: "Lightbolt",
221 description: "A bright lance of radiance that burns where it lands."
222 }),
223 Object.freeze({
224 id: SpellId.radiance,
225 name: "Radiance",
226 description: "A flare of pure light that sears a foe in a white flash."
227 }),
228 Object.freeze({
229 id: SpellId.flare,
230 name: "Flare",
231 description: "A brilliant burst that blinds and burns in the same breath."
232 }),
233 Object.freeze({
234 id: SpellId.sunbeam,
235 name: "Sunbeam",
236 description: "A column of daylight called down upon a single mark."
237 }),
238 Object.freeze({
239 id: SpellId.judgment,
240 name: "Judgment",
241 description: "The fiercest light, pitiless and absolute, cast upon one enemy."
242 })
243 ])
244 }),
245 Object.freeze({
246 element: MagicElement.dark,
247 spells: Object.freeze([
248 Object.freeze({
249 id: SpellId.darkbolt,
250 name: "Darkbolt",
251 description: "A bolt of shadow that bites colder than steel."
252 }),
253 Object.freeze({
254 id: SpellId.gloom,
255 name: "Gloom",
256 description: "A smothering cloud of dark that clings to a foe and drains them."
257 }),
258 Object.freeze({
259 id: SpellId.voidlance,
260 name: "Voidlance",
261 description: "A spear of emptiness that pierces flesh and spirit alike."
262 }),
263 Object.freeze({
264 id: SpellId.eclipse,
265 name: "Eclipse",
266 description: "A sudden night falls on one mark, crushing them in shadow."
267 }),
268 Object.freeze({
269 id: SpellId.oblivion,
270 name: "Oblivion",
271 description: "The deepest dark, called to unmake a single enemy."
272 })
273 ])
274 }),
275 Object.freeze({
276 element: MagicElement.poison,
277 spells: Object.freeze([
278 Object.freeze({
279 id: SpellId.poisonbolt,
280 name: "Poisonbolt",
281 description: "A green-tinged dart that strikes with toxic force."
282 }),
283 Object.freeze({
284 id: SpellId.toxinburst,
285 name: "Toxinburst",
286 description: "A burst of virulent fluid that spatters a foe on impact."
287 }),
288 Object.freeze({
289 id: SpellId.venomcloud,
290 name: "Venomcloud",
291 description: "A choking haze of venom that settles on a single mark."
292 }),
293 Object.freeze({
294 id: SpellId.plague,
295 name: "Plague",
296 description: "A virulent curse that hammers a foe with sickening power."
297 }),
298 Object.freeze({
299 id: SpellId.blight,
300 name: "Blight",
301 description: "The foulest poison, concentrated into one merciless strike."
302 })
303 ])
304 })
305]);
306
307function buildDamageTreeDefinitions ()
308{
309 const out = {};
310 for (const tree of ELEMENT_DAMAGE_TREES)
311 {
312 tree.spells.forEach((entry, index) =>
313 {
314 const tier = 3 + index;
315 out[entry.id] = Object.freeze({
316 spellId: entry.id,
317 displayName: entry.name,
318 tier,
319 element: tree.element,
320 target: "entity",
321 autoRepeat: true,
322 minMagicLevel: tier,
323 projectileSprite: BOLT_PROJECTILE,
324 effect: "damage",
325 damageTree: true,
326 description: entry.description
327 });
328 });
329 }
330 return out;
331}
332
34/** @type {Record<string, SpellDefinition>} */
333/** @type {Record<string, SpellDefinition>} */
35export const SPELL_DEFINITIONS = Object.freeze({
334export const SPELL_DEFINITIONS = Object.freeze({
36 [SpellId.light]: Object.freeze({
335 [SpellId.light]: Object.freeze({
@@ -42,7 +341,7 @@ export const SPELL_DEFINITIONS = Object.freeze({
42 autoRepeat: false,
341 autoRepeat: false,
43 minMagicLevel: 1,
342 minMagicLevel: 1,
44 starter: true,
343 starter: true,
45 projectileSprite: "fx:projectile:spell-light",
344 projectileSprite: LIGHT_PROJECTILE,
46 effect: "light",
345 effect: "light",
47 description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while."
346 description: "A whisper of radiance that settles on stone or grass, holding back the dark for a while."
48 }),
347 }),
@@ -50,95 +349,24 @@ export const SPELL_DEFINITIONS = Object.freeze({
50 spellId: SpellId.dark,
349 spellId: SpellId.dark,
51 displayName: "Dark",
350 displayName: "Dark",
52 tier: 2,
351 tier: 2,
53 element: "dark",
352 element: MagicElement.dark,
54 target: "tile",
353 target: "tile",
55 autoRepeat: false,
354 autoRepeat: false,
56 minMagicLevel: 2,
355 minMagicLevel: 2,
57 projectileSprite: "fx:projectile:spell-light",
356 projectileSprite: LIGHT_PROJECTILE,
58 effect: "dark",
357 effect: "dark",
59 description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim."
358 description: "A pool of shadow that drinks the light from a place, leaving the air thick and dim."
60 }),
359 }),
61 [SpellId.spark]: Object.freeze({
360 ...buildDamageTreeDefinitions(),
62 spellId: SpellId.spark,
63 displayName: "Spark",
64 tier: 2,
65 element: "fire",
66 target: "entity",
67 autoRepeat: true,
68 minMagicLevel: 2,
69 projectileSprite: "fx:projectile:spell-spark",
70 effect: "damage",
71 description: "A snapping mote of flame that leaps at a foe and bites on arrival."
72 }),
73 [SpellId.firebolt]: Object.freeze({
74 spellId: SpellId.firebolt,
75 displayName: "Firebolt",
76 tier: 3,
77 element: "fire",
78 target: "entity",
79 autoRepeat: true,
80 minMagicLevel: 3,
81 projectileSprite: "fx:projectile:spell-spark",
82 effect: "damage",
83 description: "A fierce bolt of fire that streaks toward a foe and scorches on impact."
84 }),
85 [SpellId.fireball]: Object.freeze({
86 spellId: SpellId.fireball,
87 displayName: "Fireball",
88 tier: 4,
89 element: "fire",
90 target: "entity",
91 autoRepeat: true,
92 minMagicLevel: 4,
93 projectileSprite: "fx:projectile:spell-spark",
94 effect: "damage",
95 description: "A roaring sphere of flame that bursts against whatever it strikes."
96 }),
97 [SpellId.blaze]: Object.freeze({
98 spellId: SpellId.blaze,
99 displayName: "Blaze",
100 tier: 5,
101 element: "fire",
102 target: "entity",
103 autoRepeat: true,
104 minMagicLevel: 5,
105 projectileSprite: "fx:projectile:spell-spark",
106 effect: "damage",
107 description: "A searing tongue of fire that clings to flesh and armour alike."
108 }),
109 [SpellId.inferno]: Object.freeze({
110 spellId: SpellId.inferno,
111 displayName: "Inferno",
112 tier: 6,
113 element: "fire",
114 target: "entity",
115 autoRepeat: true,
116 minMagicLevel: 6,
117 projectileSprite: "fx:projectile:spell-spark",
118 effect: "damage",
119 description: "A storm of fire that overwhelms a foe in a rush of heat and ash."
120 }),
121 [SpellId.hellfire]: Object.freeze({
122 spellId: SpellId.hellfire,
123 displayName: "Hellfire",
124 tier: 7,
125 element: "fire",
126 target: "entity",
127 autoRepeat: true,
128 minMagicLevel: 7,
129 projectileSprite: "fx:projectile:spell-spark",
130 effect: "damage",
131 description: "The deepest flame, white-hot and merciless, called down upon a single mark."
132 }),
133 [SpellId.poison]: Object.freeze({
361 [SpellId.poison]: Object.freeze({
134 spellId: SpellId.poison,
362 spellId: SpellId.poison,
135 displayName: "Poison",
363 displayName: "Poison",
136 tier: 3,
364 tier: 3,
137 element: "earth",
365 element: MagicElement.earth,
138 target: "entity",
366 target: "entity",
139 autoRepeat: true,
367 autoRepeat: true,
140 minMagicLevel: 3,
368 minMagicLevel: 3,
141 projectileSprite: "fx:projectile:spell-spark",
369 projectileSprite: BOLT_PROJECTILE,
142 effect: "poison",
370 effect: "poison",
143 description: "A venomous curse that sinks in without a wound, then eats at the body over time."
371 description: "A venomous curse that sinks in without a wound, then eats at the body over time."
144 }),
372 }),
@@ -146,11 +374,11 @@ export const SPELL_DEFINITIONS = Object.freeze({
146 spellId: SpellId.drain,
374 spellId: SpellId.drain,
147 displayName: "Drain",
375 displayName: "Drain",
148 tier: 4,
376 tier: 4,
149 element: "dark",
377 element: MagicElement.dark,
150 target: "entity",
378 target: "entity",
151 autoRepeat: true,
379 autoRepeat: true,
152 minMagicLevel: 4,
380 minMagicLevel: 4,
153 projectileSprite: "fx:projectile:spell-light",
381 projectileSprite: LIGHT_PROJECTILE,
154 effect: "drain",
382 effect: "drain",
155 description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover."
383 description: "A hunger that saps a foe's wind, leaving them gasping and slow to recover."
156 }),
384 }),
@@ -158,11 +386,11 @@ export const SPELL_DEFINITIONS = Object.freeze({
158 spellId: SpellId.tinders,
386 spellId: SpellId.tinders,
159 displayName: "Tinders",
387 displayName: "Tinders",
160 tier: 3,
388 tier: 3,
161 element: "fire",
389 element: MagicElement.fire,
162 target: "tile",
390 target: "tile",
163 autoRepeat: false,
391 autoRepeat: false,
164 minMagicLevel: 3,
392 minMagicLevel: 3,
165 projectileSprite: "fx:projectile:spell-spark",
393 projectileSprite: BOLT_PROJECTILE,
166 effect: "tinders",
394 effect: "tinders",
167 description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would."
395 description: "Sparks of will that can coax logs into flame or sear raw meat as a cookfire would."
168 }),
396 }),
@@ -170,11 +398,11 @@ export const SPELL_DEFINITIONS = Object.freeze({
170 spellId: SpellId.shade,
398 spellId: SpellId.shade,
171 displayName: "Shade",
399 displayName: "Shade",
172 tier: 6,
400 tier: 6,
173 element: "dark",
401 element: MagicElement.dark,
174 target: "tile",
402 target: "tile",
175 autoRepeat: false,
403 autoRepeat: false,
176 minMagicLevel: 6,
404 minMagicLevel: 6,
177 projectileSprite: "fx:projectile:spell-light",
405 projectileSprite: LIGHT_PROJECTILE,
178 effect: "shade",
406 effect: "shade",
179 description: "A summoned shadow that fights beside you until the magic frays."
407 description: "A summoned shadow that fights beside you until the magic frays."
180 }),
408 }),
@@ -186,12 +414,60 @@ export const SPELL_DEFINITIONS = Object.freeze({
186 target: "entity",
414 target: "entity",
187 autoRepeat: false,
415 autoRepeat: false,
188 minMagicLevel: 5,
416 minMagicLevel: 5,
189 projectileSprite: "fx:projectile:spell-light",
417 projectileSprite: LIGHT_PROJECTILE,
190 effect: "revitalize",
418 effect: "revitalize",
191 description: "A gentle current of life that mends wounds one breath at a time."
419 description: "A gentle current of life that mends wounds one breath at a time."
192 })
420 }),
421 [SpellId.spriteBoltFire]: spriteBoltDef(SpellId.spriteBoltFire, "Fire spark", MagicElement.fire),
422 [SpellId.spriteBoltWater]: spriteBoltDef(SpellId.spriteBoltWater, "Water spark", MagicElement.water),
423 [SpellId.spriteBoltAir]: spriteBoltDef(SpellId.spriteBoltAir, "Air spark", MagicElement.air),
424 [SpellId.spriteBoltEarth]: spriteBoltDef(SpellId.spriteBoltEarth, "Earth spark", MagicElement.earth),
425 [SpellId.spriteBoltLight]: spriteBoltDef(SpellId.spriteBoltLight, "Light spark", MagicElement.light),
426 [SpellId.spriteBoltDark]: spriteBoltDef(SpellId.spriteBoltDark, "Dark spark", MagicElement.dark),
427 [SpellId.spriteBoltPoison]: spriteBoltDef(SpellId.spriteBoltPoison, "Poison spark", MagicElement.poison)
428});
429
430function spriteBoltDef (spellId, displayName, element)
431{
432 return Object.freeze({
433 spellId,
434 displayName,
435 tier: 2,
436 element,
437 target: "entity",
438 autoRepeat: true,
439 minMagicLevel: 1,
440 projectileSprite: BOLT_PROJECTILE,
441 effect: "damage",
442 mobOnly: true,
443 description: `A flickering ${element} mote cast by a sprite.`
444 });
445}
446
447export const SPRITE_BOLT_SPELL_BY_ELEMENT = Object.freeze({
448 [MagicElement.fire]: SpellId.spriteBoltFire,
449 [MagicElement.water]: SpellId.spriteBoltWater,
450 [MagicElement.air]: SpellId.spriteBoltAir,
451 [MagicElement.earth]: SpellId.spriteBoltEarth,
452 [MagicElement.light]: SpellId.spriteBoltLight,
453 [MagicElement.dark]: SpellId.spriteBoltDark,
454 [MagicElement.poison]: SpellId.spriteBoltPoison
193});
455});
194
456
457/** Damage-tree spell ids grouped by element (for UI / editors). */
458export function damageTreeSpellIds (element = null)
459{
460 const ids = [];
461 for (const tree of ELEMENT_DAMAGE_TREES)
462 {
463 if (element && tree.element !== element)
464 { continue; }
465 for (const spell of tree.spells)
466 { ids.push(spell.id); }
467 }
468 return ids;
469}
470
195export function spellDefinition (spellId)
471export function spellDefinition (spellId)
196{
472{
197 return SPELL_DEFINITIONS[spellId] ?? null;
473 return SPELL_DEFINITIONS[spellId] ?? null;
@@ -206,6 +482,6 @@ export function spellDifficulty (spellDef)
206export function learnableSpellIds ()
482export function learnableSpellIds ()
207{
483{
208 return Object.values(SPELL_DEFINITIONS)
484 return Object.values(SPELL_DEFINITIONS)
209 .filter((def) => !def.starter)
485 .filter((def) => !def.starter && !def.mobOnly)
210 .map((def) => def.spellId);
486 .map((def) => def.spellId);
211}
487}
shared/definitions/swordItems.js added +51 −0
@@ -0,0 +1,51 @@
1 import {
2 ItemFamilyId,
3 buildFamilyDefinitionMap
4 } from "./tierFamilies.js";
5 import { MaterialTier } from "./materialTiers.js";
6
7 /**
8 * Sword blades (anvil) and complete swords (crafting bench).
9 * Red = metal, blue = leather wrap. Equip sprite uses native width (22×24).
10 */
11 export const SwordItemId = Object.freeze({
12 bronzeSwordBlade: 410,
13 ironSwordBlade: 411,
14 steelSwordBlade: 412,
15 mithrilSwordBlade: 413,
16 adamantiumSwordBlade: 414,
17 orichalcumSwordBlade: 415,
18 dragonSwordBlade: 416,
19 bronzeSword: 417,
20 ironSword: 418,
21 steelSword: 419,
22 mithrilSword: 420,
23 adamantiumSword: 421,
24 orichalcumSword: 422,
25 dragonSword: 423
26 });
27
28 export const SWORD_BLADE_ITEM_BY_METAL = Object.freeze({
29 [MaterialTier.bronze]: SwordItemId.bronzeSwordBlade,
30 [MaterialTier.iron]: SwordItemId.ironSwordBlade,
31 [MaterialTier.steel]: SwordItemId.steelSwordBlade,
32 [MaterialTier.mithril]: SwordItemId.mithrilSwordBlade,
33 [MaterialTier.adamantium]: SwordItemId.adamantiumSwordBlade,
34 [MaterialTier.orichalcum]: SwordItemId.orichalcumSwordBlade,
35 [MaterialTier.dragon]: SwordItemId.dragonSwordBlade
36 });
37
38 export const SWORD_ITEM_BY_METAL = Object.freeze({
39 [MaterialTier.bronze]: SwordItemId.bronzeSword,
40 [MaterialTier.iron]: SwordItemId.ironSword,
41 [MaterialTier.steel]: SwordItemId.steelSword,
42 [MaterialTier.mithril]: SwordItemId.mithrilSword,
43 [MaterialTier.adamantium]: SwordItemId.adamantiumSword,
44 [MaterialTier.orichalcum]: SwordItemId.orichalcumSword,
45 [MaterialTier.dragon]: SwordItemId.dragonSword
46 });
47
48 export const SWORD_ITEM_DEFINITIONS = Object.freeze({
49 ...buildFamilyDefinitionMap(ItemFamilyId.swordBlade, SWORD_BLADE_ITEM_BY_METAL),
50 ...buildFamilyDefinitionMap(ItemFamilyId.sword, SWORD_ITEM_BY_METAL)
51 });
@@ -0,0 +1,51 @@
1import {
2 ItemFamilyId,
3 buildFamilyDefinitionMap
4} from "./tierFamilies.js";
5import { MaterialTier } from "./materialTiers.js";
6
7/**
8 * Sword blades (anvil) and complete swords (crafting bench).
9 * Red = metal, blue = leather wrap. Equip sprite uses native width (22×24).
10 */
11export const SwordItemId = Object.freeze({
12 bronzeSwordBlade: 410,
13 ironSwordBlade: 411,
14 steelSwordBlade: 412,
15 mithrilSwordBlade: 413,
16 adamantiumSwordBlade: 414,
17 orichalcumSwordBlade: 415,
18 dragonSwordBlade: 416,
19 bronzeSword: 417,
20 ironSword: 418,
21 steelSword: 419,
22 mithrilSword: 420,
23 adamantiumSword: 421,
24 orichalcumSword: 422,
25 dragonSword: 423
26});
27
28export const SWORD_BLADE_ITEM_BY_METAL = Object.freeze({
29 [MaterialTier.bronze]: SwordItemId.bronzeSwordBlade,
30 [MaterialTier.iron]: SwordItemId.ironSwordBlade,
31 [MaterialTier.steel]: SwordItemId.steelSwordBlade,
32 [MaterialTier.mithril]: SwordItemId.mithrilSwordBlade,
33 [MaterialTier.adamantium]: SwordItemId.adamantiumSwordBlade,
34 [MaterialTier.orichalcum]: SwordItemId.orichalcumSwordBlade,
35 [MaterialTier.dragon]: SwordItemId.dragonSwordBlade
36});
37
38export const SWORD_ITEM_BY_METAL = Object.freeze({
39 [MaterialTier.bronze]: SwordItemId.bronzeSword,
40 [MaterialTier.iron]: SwordItemId.ironSword,
41 [MaterialTier.steel]: SwordItemId.steelSword,
42 [MaterialTier.mithril]: SwordItemId.mithrilSword,
43 [MaterialTier.adamantium]: SwordItemId.adamantiumSword,
44 [MaterialTier.orichalcum]: SwordItemId.orichalcumSword,
45 [MaterialTier.dragon]: SwordItemId.dragonSword
46});
47
48export const SWORD_ITEM_DEFINITIONS = Object.freeze({
49 ...buildFamilyDefinitionMap(ItemFamilyId.swordBlade, SWORD_BLADE_ITEM_BY_METAL),
50 ...buildFamilyDefinitionMap(ItemFamilyId.sword, SWORD_ITEM_BY_METAL)
51});
shared/definitions/tierFamilies.js +57 −4
@@ -7,7 +7,8 @@ import {
7 7 CLOTH_TIER_ORDER,
8 8 CLOTH_DISPLAY_NAME,
9 9 woodTierForMetal,
10 clothTierForWood
10 clothTierForWood,
11 leatherTierForMetal
11 12 } from "./materialTiers.js";
12 13 import { EquipmentKind } from "./equipmentKinds.js";
13 14 import { AttackType } from "./attackTypes.js";
@@ -31,6 +32,8 @@ export const ItemFamilyId = Object.freeze({
31 32 axeHead: "axeHead",
32 33 pickaxe: "pickaxe",
33 34 axe: "axe",
35 swordBlade: "swordBlade",
36 sword: "sword",
34 37 plantClippers: "plantClippers",
35 38 arrowShaft: "arrowShaft",
36 39 arrowTip: "arrowTip",
@@ -181,7 +184,15 @@ export const ITEM_FAMILIES = Object.freeze({
181 184 seedValue: 8,
182 185 dualTintFromTier: true,
183 186 woodTierFromMetal: true,
184 equipmentKind: EquipmentKind.axeTool
187 equipmentKind: EquipmentKind.axeTool,
188 equipmentAttack: Object.freeze({
189 mode: "melee",
190 rangeTiles: 1,
191 hitSkillId: SkillId.axefighting,
192 damageSkillId: SkillId.strength,
193 attackType: AttackType.chopping,
194 cooldownMs: 800
195 })
185 196 }),
186 197 [ItemFamilyId.plantClippers]: Object.freeze({
187 198 familyId: ItemFamilyId.plantClippers,
@@ -287,7 +298,44 @@ export const ITEM_FAMILIES = Object.freeze({
287 298 rangeTiles: 1,
288 299 hitSkillId: SkillId.clubfighting,
289 300 damageSkillId: SkillId.strength,
290 attackType: AttackType.blunt,
301 attackType: AttackType.crushing,
302 cooldownMs: 700
303 })
304 }),
305 [ItemFamilyId.swordBlade]: Object.freeze({
306 familyId: ItemFamilyId.swordBlade,
307 axis: TierAxis.metal,
308 label: "sword blade",
309 description: (name) => `A smithed ${name.toLowerCase()} blade. Haft it with leather at a crafting bench.`,
310 category: ItemCategory.intermediate,
311 iconKey: "sword",
312 defaultState: "sword-blade",
313 stackable: true,
314 maxStackSize: DEFAULT_STACK,
315 seedValue: 6,
316 tintFromTier: true
317 }),
318 [ItemFamilyId.sword]: Object.freeze({
319 familyId: ItemFamilyId.sword,
320 axis: TierAxis.metal,
321 label: "sword",
322 description: (name) => `A ${name.toLowerCase()} sword, leather-wrapped for a sure grip.`,
323 category: ItemCategory.tool,
324 iconKey: "sword",
325 defaultState: "sword",
326 stackable: false,
327 maxStackSize: 1,
328 seedValue: 10,
329 /** Red = metal, blue = leather wrap (wood haft hidden under the wrap). */
330 dualTintFromTier: true,
331 leatherTierFromMetal: true,
332 equipmentKind: EquipmentKind.metalWeapon,
333 equipmentAttack: Object.freeze({
334 mode: "melee",
335 rangeTiles: 1,
336 hitSkillId: SkillId.swordfighting,
337 damageSkillId: SkillId.strength,
338 attackType: AttackType.slashing,
291 339 cooldownMs: 700
292 340 })
293 341 })
@@ -365,7 +413,12 @@ export function buildTierItemDef (familyId, tier, itemId, extra = {})
365 413 ...(family.tintFromTier ? { tintFromTier: true } : {}),
366 414 ...(family.npcShopAllowed ? { npcShopAllowed: true } : {}),
367 415 ...(family.woodTierFromMetal ? { woodTier: woodTierForMetal(tier), dualTintFromTier: true } : {}),
368 ...(family.dualTintFromTier && !family.woodTierFromMetal ? { dualTintFromTier: true } : {}),
416 ...(family.leatherTierFromMetal
417 ? { leatherTier: leatherTierForMetal(tier), dualTintFromTier: true }
418 : {}),
419 ...(family.dualTintFromTier && !family.woodTierFromMetal && !family.leatherTierFromMetal
420 ? { dualTintFromTier: true }
421 : {}),
369 422 ...(family.clothTierFromWood ? { clothTier: clothTierForWood(tier) } : {}),
370 423 ...(equipment ? { equipment } : {})
371 424 });
@@ -7,7 +7,8 @@ import {
7 CLOTH_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 CLOTH_DISPLAY_NAME,
8 CLOTH_DISPLAY_NAME,
9 woodTierForMetal,
9 woodTierForMetal,
10 clothTierForWood
10 clothTierForWood,
11 leatherTierForMetal
11} from "./materialTiers.js";
12} from "./materialTiers.js";
12import { EquipmentKind } from "./equipmentKinds.js";
13import { EquipmentKind } from "./equipmentKinds.js";
13import { AttackType } from "./attackTypes.js";
14import { AttackType } from "./attackTypes.js";
@@ -31,6 +32,8 @@ export const ItemFamilyId = Object.freeze({
31 axeHead: "axeHead",
32 axeHead: "axeHead",
32 pickaxe: "pickaxe",
33 pickaxe: "pickaxe",
33 axe: "axe",
34 axe: "axe",
35 swordBlade: "swordBlade",
36 sword: "sword",
34 plantClippers: "plantClippers",
37 plantClippers: "plantClippers",
35 arrowShaft: "arrowShaft",
38 arrowShaft: "arrowShaft",
36 arrowTip: "arrowTip",
39 arrowTip: "arrowTip",
@@ -181,7 +184,15 @@ export const ITEM_FAMILIES = Object.freeze({
181 seedValue: 8,
184 seedValue: 8,
182 dualTintFromTier: true,
185 dualTintFromTier: true,
183 woodTierFromMetal: true,
186 woodTierFromMetal: true,
184 equipmentKind: EquipmentKind.axeTool
187 equipmentKind: EquipmentKind.axeTool,
188 equipmentAttack: Object.freeze({
189 mode: "melee",
190 rangeTiles: 1,
191 hitSkillId: SkillId.axefighting,
192 damageSkillId: SkillId.strength,
193 attackType: AttackType.chopping,
194 cooldownMs: 800
195 })
185 }),
196 }),
186 [ItemFamilyId.plantClippers]: Object.freeze({
197 [ItemFamilyId.plantClippers]: Object.freeze({
187 familyId: ItemFamilyId.plantClippers,
198 familyId: ItemFamilyId.plantClippers,
@@ -287,7 +298,44 @@ export const ITEM_FAMILIES = Object.freeze({
287 rangeTiles: 1,
298 rangeTiles: 1,
288 hitSkillId: SkillId.clubfighting,
299 hitSkillId: SkillId.clubfighting,
289 damageSkillId: SkillId.strength,
300 damageSkillId: SkillId.strength,
290 attackType: AttackType.blunt,
301 attackType: AttackType.crushing,
302 cooldownMs: 700
303 })
304 }),
305 [ItemFamilyId.swordBlade]: Object.freeze({
306 familyId: ItemFamilyId.swordBlade,
307 axis: TierAxis.metal,
308 label: "sword blade",
309 description: (name) => `A smithed ${name.toLowerCase()} blade. Haft it with leather at a crafting bench.`,
310 category: ItemCategory.intermediate,
311 iconKey: "sword",
312 defaultState: "sword-blade",
313 stackable: true,
314 maxStackSize: DEFAULT_STACK,
315 seedValue: 6,
316 tintFromTier: true
317 }),
318 [ItemFamilyId.sword]: Object.freeze({
319 familyId: ItemFamilyId.sword,
320 axis: TierAxis.metal,
321 label: "sword",
322 description: (name) => `A ${name.toLowerCase()} sword, leather-wrapped for a sure grip.`,
323 category: ItemCategory.tool,
324 iconKey: "sword",
325 defaultState: "sword",
326 stackable: false,
327 maxStackSize: 1,
328 seedValue: 10,
329 /** Red = metal, blue = leather wrap (wood haft hidden under the wrap). */
330 dualTintFromTier: true,
331 leatherTierFromMetal: true,
332 equipmentKind: EquipmentKind.metalWeapon,
333 equipmentAttack: Object.freeze({
334 mode: "melee",
335 rangeTiles: 1,
336 hitSkillId: SkillId.swordfighting,
337 damageSkillId: SkillId.strength,
338 attackType: AttackType.slashing,
291 cooldownMs: 700
339 cooldownMs: 700
292 })
340 })
293 })
341 })
@@ -365,7 +413,12 @@ export function buildTierItemDef (familyId, tier, itemId, extra = {})
365 ...(family.tintFromTier ? { tintFromTier: true } : {}),
413 ...(family.tintFromTier ? { tintFromTier: true } : {}),
366 ...(family.npcShopAllowed ? { npcShopAllowed: true } : {}),
414 ...(family.npcShopAllowed ? { npcShopAllowed: true } : {}),
367 ...(family.woodTierFromMetal ? { woodTier: woodTierForMetal(tier), dualTintFromTier: true } : {}),
415 ...(family.woodTierFromMetal ? { woodTier: woodTierForMetal(tier), dualTintFromTier: true } : {}),
368 ...(family.dualTintFromTier && !family.woodTierFromMetal ? { dualTintFromTier: true } : {}),
416 ...(family.leatherTierFromMetal
417 ? { leatherTier: leatherTierForMetal(tier), dualTintFromTier: true }
418 : {}),
419 ...(family.dualTintFromTier && !family.woodTierFromMetal && !family.leatherTierFromMetal
420 ? { dualTintFromTier: true }
421 : {}),
369 ...(family.clothTierFromWood ? { clothTier: clothTierForWood(tier) } : {}),
422 ...(family.clothTierFromWood ? { clothTier: clothTierForWood(tier) } : {}),
370 ...(equipment ? { equipment } : {})
423 ...(equipment ? { equipment } : {})
371 });
424 });
shared/lighting/combatLight.js +5 −1
@@ -2,6 +2,7 @@ import { CHUNK_SIZE } from "../protocol/constants.js";
2 2 import { lightIntensity, falloffAtDistance } from "./raycast.js";
3 3 import { equippedLightRadiusTiles } from "../definitions/items.js";
4 4 import { statusExtraLightRadius } from "../statusEffects/rules.js";
5 import { mobDefinition } from "../definitions/mobs.js";
5 6
6 7 /** Night ambient darkness 0–1 (matches client `nightFactor`). */
7 8 export function nightFactor (hour, nightDarkness = 0.72)
@@ -69,7 +70,10 @@ function entityLightRadiusTiles (ecs, handle, Component, now)
69 70 const equipment = ecs.get(handle, Component.equipment);
70 71 const gear = equippedLightRadiusTiles(equipment);
71 72 const status = statusExtraLightRadius(ecs.get(handle, Component.statusEffects), now);
72 return Math.max(gear, status);
73 const creature = ecs.get(handle, Component.creature);
74 const creatureLight = creature?.lightRadiusTiles
75 ?? (creature ? (mobDefinition(creature.mobTypeId)?.lightRadiusTiles ?? 0) : 0);
76 return Math.max(gear, status, creatureLight);
73 77 }
74 78
75 79 export function tileIndexLocal (tileX, tileY, chunkSize = CHUNK_SIZE)
@@ -2,6 +2,7 @@ import { CHUNK_SIZE } from "../protocol/constants.js";
2import { lightIntensity, falloffAtDistance } from "./raycast.js";
2import { lightIntensity, falloffAtDistance } from "./raycast.js";
3import { equippedLightRadiusTiles } from "../definitions/items.js";
3import { equippedLightRadiusTiles } from "../definitions/items.js";
4import { statusExtraLightRadius } from "../statusEffects/rules.js";
4import { statusExtraLightRadius } from "../statusEffects/rules.js";
5import { mobDefinition } from "../definitions/mobs.js";
5
6
6/** Night ambient darkness 0–1 (matches client `nightFactor`). */
7/** Night ambient darkness 0–1 (matches client `nightFactor`). */
7export function nightFactor (hour, nightDarkness = 0.72)
8export function nightFactor (hour, nightDarkness = 0.72)
@@ -69,7 +70,10 @@ function entityLightRadiusTiles (ecs, handle, Component, now)
69 const equipment = ecs.get(handle, Component.equipment);
70 const equipment = ecs.get(handle, Component.equipment);
70 const gear = equippedLightRadiusTiles(equipment);
71 const gear = equippedLightRadiusTiles(equipment);
71 const status = statusExtraLightRadius(ecs.get(handle, Component.statusEffects), now);
72 const status = statusExtraLightRadius(ecs.get(handle, Component.statusEffects), now);
72 return Math.max(gear, status);
73 const creature = ecs.get(handle, Component.creature);
74 const creatureLight = creature?.lightRadiusTiles
75 ?? (creature ? (mobDefinition(creature.mobTypeId)?.lightRadiusTiles ?? 0) : 0);
76 return Math.max(gear, status, creatureLight);
73}
77}
74
78
75export function tileIndexLocal (tileX, tileY, chunkSize = CHUNK_SIZE)
79export function tileIndexLocal (tileX, tileY, chunkSize = CHUNK_SIZE)
shared/protocol/constants.js +1 −0
@@ -179,6 +179,7 @@ export const MessageType = Object.freeze({
179 179 setGraphicsSettings: "SET_GRAPHICS_SETTINGS",
180 180 eatItem: "EAT_ITEM",
181 181 drinkItem: "DRINK_ITEM",
182 tipArrows: "TIP_ARROWS",
182 183 startCraft: "START_CRAFT",
183 184 startFire: "START_FIRE",
184 185 startFish: "START_FISH",
@@ -179,6 +179,7 @@ export const MessageType = Object.freeze({
179 setGraphicsSettings: "SET_GRAPHICS_SETTINGS",
179 setGraphicsSettings: "SET_GRAPHICS_SETTINGS",
180 eatItem: "EAT_ITEM",
180 eatItem: "EAT_ITEM",
181 drinkItem: "DRINK_ITEM",
181 drinkItem: "DRINK_ITEM",
182 tipArrows: "TIP_ARROWS",
182 startCraft: "START_CRAFT",
183 startCraft: "START_CRAFT",
183 startFire: "START_FIRE",
184 startFire: "START_FIRE",
184 startFish: "START_FISH",
185 startFish: "START_FISH",
shared/render/tint.js +90 −20
@@ -1,5 +1,6 @@
1 1 import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId } from "../definitions/materialTiers.js";
2 2 import { itemDefinition } from "../definitions/items.js";
3 import { magicElementTint } from "../definitions/attackTypes.js";
3 4
4 5 /**
5 6 * Artist convention for tintable pixels (source sprites):
@@ -10,49 +11,101 @@ import { itemDefinition } from "../definitions/items.js";
10 11 * so dark target colours stay dark: mix(tint, vec3(luma(tint)), G/R) * L.
11 12 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
12 13 *
13 * Dual-channel arrows / tools / bows ({@link applyDualChannelTintToImageData}):
14 * - Dominant red (R > G,B): shaft / wood / handle mask; lightness = R; tint with shaft colour.
15 * - Dominant blue (B > R,G): tip / metal / string mask; lightness = B; tint with tip colour.
14 * Dual / triple channel ({@link applyDualChannelTintToImageData}):
15 * - Dominant red (R > G,B): shaft / wood / metal blade; lightness = R.
16 * - Dominant blue (B > R,G): tip / leather / string; lightness = B.
17 * - Dominant green (G > R,B): coating (tipped arrows); lightness = G.
18 * - When one channel is highest and the other two are equal and non-zero,
19 * that is a lighter tint of the assigned colour (blend toward white) —
20 * not a mix of multiple assigned colours.
16 21 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
17 22 */
18 23
24 const SECONDARY_EQUAL_TOL = 0.04;
25
19 26 /** Mask strength when a paint channel dominates (matches world dual-tint shader). */
20 27 export function channelDominanceMask (r, g, b, channel)
21 28 {
22 29 if (channel === "shaft")
23 30 { return clamp01((r - Math.max(g, b)) * 1.75); }
31 if (channel === "coat")
32 { return clamp01((g - Math.max(r, b)) * 1.75); }
24 33 return clamp01((b - Math.max(r, g)) * 1.75);
25 34 }
26 35
27 /** Tint pixels where `channel` dominates, preserving channel lightness. */
36 function channelLightness (r, g, b, channel)
37 {
38 if (channel === "shaft")
39 { return r; }
40 if (channel === "coat")
41 { return g; }
42 return b;
43 }
44
45 function channelSecondaries (r, g, b, channel)
46 {
47 if (channel === "shaft")
48 { return [g, b]; }
49 if (channel === "coat")
50 { return [r, b]; }
51 return [r, g];
52 }
53
54 /**
55 * Tint pixels where `channel` dominates, preserving channel lightness.
56 * Equal non-dominant channels → blend assigned tint toward white.
57 * Unequal → keep legacy soft desat via the lesser secondary (compat with dual art).
58 */
28 59 export function channelTintedRgb (r, g, b, channel, tintRgb)
29 60 {
30 61 const mask = channelDominanceMask(r, g, b, channel);
31 62 if (mask <= 0)
32 63 { return null; }
33 const L = channel === "shaft" ? r : b;
34 const gBlend = L > 0 ? Math.min(1, Math.max(0, g / L)) : 0;
64 const L = channelLightness(r, g, b, channel);
65 const [o1, o2] = channelSecondaries(r, g, b, channel);
66 const equalSeconds = Math.abs(o1 - o2) <= SECONDARY_EQUAL_TOL;
67 const whiteBlend = L > 0 && equalSeconds
68 ? Math.min(1, Math.max(0, o1 / L))
69 : (L > 0 ? Math.min(1, Math.max(0, Math.min(o1, o2) / L)) : 0);
35 70 const tint = normalizeRgb(tintRgb);
36 const tintLuma = luminance(tint.r, tint.g, tint.b);
71 const toward = equalSeconds
72 ? { r: 1, g: 1, b: 1 }
73 : (() =>
74 {
75 const tintLuma = luminance(tint.r, tint.g, tint.b);
76 return { r: tintLuma, g: tintLuma, b: tintLuma };
77 })();
37 78 return {
38 r: clamp01(mix(tint.r, tintLuma, gBlend) * L),
39 g: clamp01(mix(tint.g, tintLuma, gBlend) * L),
40 b: clamp01(mix(tint.b, tintLuma, gBlend) * L),
79 r: clamp01(mix(tint.r, toward.r, whiteBlend) * L),
80 g: clamp01(mix(tint.g, toward.g, whiteBlend) * L),
81 b: clamp01(mix(tint.b, toward.b, whiteBlend) * L),
41 82 mask
42 83 };
43 84 }
44 85
45 /** Shaft + tip channel tints for full-arrow sprites. */
46 export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint)
86 /** Shaft + tip (+ optional coat) channel tints. */
87 export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint, coatTint = null)
47 88 {
48 89 let rgb = { r, g, b };
90 if (coatTint)
91 {
92 const coat = channelTintedRgb(r, g, b, "coat", coatTint);
93 if (coat)
94 {
95 rgb = {
96 r: mix(r, coat.r, coat.mask),
97 g: mix(g, coat.g, coat.mask),
98 b: mix(b, coat.b, coat.mask)
99 };
100 }
101 }
49 102 const tip = channelTintedRgb(r, g, b, "tip", tipTint);
50 103 if (tip)
51 104 {
52 105 rgb = {
53 r: mix(r, tip.r, tip.mask),
54 g: mix(g, tip.g, tip.mask),
55 b: mix(b, tip.b, tip.mask)
106 r: mix(rgb.r, tip.r, tip.mask),
107 g: mix(rgb.g, tip.g, tip.mask),
108 b: mix(rgb.b, tip.b, tip.mask)
56 109 };
57 110 }
58 111 const shaft = channelTintedRgb(r, g, b, "shaft", shaftTint);
@@ -67,12 +120,13 @@ export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint)
67 120 return rgb;
68 121 }
69 122
70 /** Mutate ImageData: red channel = shaft, blue = tip, white unchanged. */
71 export function applyDualChannelTintToImageData (imageData, { shaft, tip })
123 /** Mutate ImageData: red = shaft, blue = tip, optional green = coat. */
124 export function applyDualChannelTintToImageData (imageData, { shaft, tip, coat = null })
72 125 {
73 126 const data = imageData.data;
74 127 const shaftTint = normalizeRgb(shaft);
75 128 const tipTint = normalizeRgb(tip);
129 const coatTint = coat ? normalizeRgb(coat) : null;
76 130 for (let i = 0; i < data.length; i += 4)
77 131 {
78 132 if (data[i + 3] < 8)
@@ -80,7 +134,7 @@ export function applyDualChannelTintToImageData (imageData, { shaft, tip })
80 134 const r = data[i] / 255;
81 135 const g = data[i + 1] / 255;
82 136 const b = data[i + 2] / 255;
83 const next = dualChannelTintedRgb(r, g, b, shaftTint, tipTint);
137 const next = dualChannelTintedRgb(r, g, b, shaftTint, tipTint, coatTint);
84 138 data[i] = Math.round(next.r * 255);
85 139 data[i + 1] = Math.round(next.g * 255);
86 140 data[i + 2] = Math.round(next.b * 255);
@@ -99,17 +153,33 @@ export function resolveItemDualTint (stackOrDef, def = null)
99 153 if (!definition?.dualTintFromTier)
100 154 { return null; }
101 155
102 // Tools / arrows: metal primary tier + matching wood shaft.
156 // Tools / arrows: metal primary tier + matching wood shaft (red = wood, blue = metal).
103 157 if (definition.woodTier)
104 158 {
105 159 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
106 160 const woodTier = definition.woodTier;
107 161 if (!metalTier || !woodTier)
108 162 { return null; }
109 return {
163 const dual = {
110 164 shaft: tierTintColor(woodTier),
111 165 tip: tierTintColor(metalTier)
112 166 };
167 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
168 { dual.coat = magicElementTint(stack.instance.element); }
169 return dual;
170 }
171
172 // Swords: red = metal, blue = leather wrap.
173 if (definition.leatherTier)
174 {
175 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
176 const leatherTier = definition.leatherTier;
177 if (!metalTier || !leatherTier)
178 { return null; }
179 return {
180 shaft: tierTintColor(metalTier),
181 tip: tierTintColor(leatherTier)
182 };
113 183 }
114 184
115 185 // Magic staff: wood shaft (red) + gem tip (blue).
@@ -1,5 +1,6 @@
1import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId } from "../definitions/materialTiers.js";
1import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId } from "../definitions/materialTiers.js";
2import { itemDefinition } from "../definitions/items.js";
2import { itemDefinition } from "../definitions/items.js";
3import { magicElementTint } from "../definitions/attackTypes.js";
3
4
4/**
5/**
5 * Artist convention for tintable pixels (source sprites):
6 * Artist convention for tintable pixels (source sprites):
@@ -10,49 +11,101 @@ import { itemDefinition } from "../definitions/items.js";
10 * so dark target colours stay dark: mix(tint, vec3(luma(tint)), G/R) * L.
11 * so dark target colours stay dark: mix(tint, vec3(luma(tint)), G/R) * L.
11 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
12 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
12 *
13 *
13 * Dual-channel arrows / tools / bows ({@link applyDualChannelTintToImageData}):
14 * Dual / triple channel ({@link applyDualChannelTintToImageData}):
14 * - Dominant red (R > G,B): shaft / wood / handle mask; lightness = R; tint with shaft colour.
15 * - Dominant red (R > G,B): shaft / wood / metal blade; lightness = R.
15 * - Dominant blue (B > R,G): tip / metal / string mask; lightness = B; tint with tip colour.
16 * - Dominant blue (B > R,G): tip / leather / string; lightness = B.
17 * - Dominant green (G > R,B): coating (tipped arrows); lightness = G.
18 * - When one channel is highest and the other two are equal and non-zero,
19 * that is a lighter tint of the assigned colour (blend toward white) —
20 * not a mix of multiple assigned colours.
16 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
21 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
17 */
22 */
18
23
24const SECONDARY_EQUAL_TOL = 0.04;
25
19/** Mask strength when a paint channel dominates (matches world dual-tint shader). */
26/** Mask strength when a paint channel dominates (matches world dual-tint shader). */
20export function channelDominanceMask (r, g, b, channel)
27export function channelDominanceMask (r, g, b, channel)
21{
28{
22 if (channel === "shaft")
29 if (channel === "shaft")
23 { return clamp01((r - Math.max(g, b)) * 1.75); }
30 { return clamp01((r - Math.max(g, b)) * 1.75); }
31 if (channel === "coat")
32 { return clamp01((g - Math.max(r, b)) * 1.75); }
24 return clamp01((b - Math.max(r, g)) * 1.75);
33 return clamp01((b - Math.max(r, g)) * 1.75);
25}
34}
26
35
27/** Tint pixels where `channel` dominates, preserving channel lightness. */
36function channelLightness (r, g, b, channel)
37{
38 if (channel === "shaft")
39 { return r; }
40 if (channel === "coat")
41 { return g; }
42 return b;
43}
44
45function channelSecondaries (r, g, b, channel)
46{
47 if (channel === "shaft")
48 { return [g, b]; }
49 if (channel === "coat")
50 { return [r, b]; }
51 return [r, g];
52}
53
54/**
55 * Tint pixels where `channel` dominates, preserving channel lightness.
56 * Equal non-dominant channels → blend assigned tint toward white.
57 * Unequal → keep legacy soft desat via the lesser secondary (compat with dual art).
58 */
28export function channelTintedRgb (r, g, b, channel, tintRgb)
59export function channelTintedRgb (r, g, b, channel, tintRgb)
29{
60{
30 const mask = channelDominanceMask(r, g, b, channel);
61 const mask = channelDominanceMask(r, g, b, channel);
31 if (mask <= 0)
62 if (mask <= 0)
32 { return null; }
63 { return null; }
33 const L = channel === "shaft" ? r : b;
64 const L = channelLightness(r, g, b, channel);
34 const gBlend = L > 0 ? Math.min(1, Math.max(0, g / L)) : 0;
65 const [o1, o2] = channelSecondaries(r, g, b, channel);
66 const equalSeconds = Math.abs(o1 - o2) <= SECONDARY_EQUAL_TOL;
67 const whiteBlend = L > 0 && equalSeconds
68 ? Math.min(1, Math.max(0, o1 / L))
69 : (L > 0 ? Math.min(1, Math.max(0, Math.min(o1, o2) / L)) : 0);
35 const tint = normalizeRgb(tintRgb);
70 const tint = normalizeRgb(tintRgb);
36 const tintLuma = luminance(tint.r, tint.g, tint.b);
71 const toward = equalSeconds
72 ? { r: 1, g: 1, b: 1 }
73 : (() =>
74 {
75 const tintLuma = luminance(tint.r, tint.g, tint.b);
76 return { r: tintLuma, g: tintLuma, b: tintLuma };
77 })();
37 return {
78 return {
38 r: clamp01(mix(tint.r, tintLuma, gBlend) * L),
79 r: clamp01(mix(tint.r, toward.r, whiteBlend) * L),
39 g: clamp01(mix(tint.g, tintLuma, gBlend) * L),
80 g: clamp01(mix(tint.g, toward.g, whiteBlend) * L),
40 b: clamp01(mix(tint.b, tintLuma, gBlend) * L),
81 b: clamp01(mix(tint.b, toward.b, whiteBlend) * L),
41 mask
82 mask
42 };
83 };
43}
84}
44
85
45/** Shaft + tip channel tints for full-arrow sprites. */
86/** Shaft + tip (+ optional coat) channel tints. */
46export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint)
87export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint, coatTint = null)
47{
88{
48 let rgb = { r, g, b };
89 let rgb = { r, g, b };
90 if (coatTint)
91 {
92 const coat = channelTintedRgb(r, g, b, "coat", coatTint);
93 if (coat)
94 {
95 rgb = {
96 r: mix(r, coat.r, coat.mask),
97 g: mix(g, coat.g, coat.mask),
98 b: mix(b, coat.b, coat.mask)
99 };
100 }
101 }
49 const tip = channelTintedRgb(r, g, b, "tip", tipTint);
102 const tip = channelTintedRgb(r, g, b, "tip", tipTint);
50 if (tip)
103 if (tip)
51 {
104 {
52 rgb = {
105 rgb = {
53 r: mix(r, tip.r, tip.mask),
106 r: mix(rgb.r, tip.r, tip.mask),
54 g: mix(g, tip.g, tip.mask),
107 g: mix(rgb.g, tip.g, tip.mask),
55 b: mix(b, tip.b, tip.mask)
108 b: mix(rgb.b, tip.b, tip.mask)
56 };
109 };
57 }
110 }
58 const shaft = channelTintedRgb(r, g, b, "shaft", shaftTint);
111 const shaft = channelTintedRgb(r, g, b, "shaft", shaftTint);
@@ -67,12 +120,13 @@ export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint)
67 return rgb;
120 return rgb;
68}
121}
69
122
70/** Mutate ImageData: red channel = shaft, blue = tip, white unchanged. */
123/** Mutate ImageData: red = shaft, blue = tip, optional green = coat. */
71export function applyDualChannelTintToImageData (imageData, { shaft, tip })
124export function applyDualChannelTintToImageData (imageData, { shaft, tip, coat = null })
72{
125{
73 const data = imageData.data;
126 const data = imageData.data;
74 const shaftTint = normalizeRgb(shaft);
127 const shaftTint = normalizeRgb(shaft);
75 const tipTint = normalizeRgb(tip);
128 const tipTint = normalizeRgb(tip);
129 const coatTint = coat ? normalizeRgb(coat) : null;
76 for (let i = 0; i < data.length; i += 4)
130 for (let i = 0; i < data.length; i += 4)
77 {
131 {
78 if (data[i + 3] < 8)
132 if (data[i + 3] < 8)
@@ -80,7 +134,7 @@ export function applyDualChannelTintToImageData (imageData, { shaft, tip })
80 const r = data[i] / 255;
134 const r = data[i] / 255;
81 const g = data[i + 1] / 255;
135 const g = data[i + 1] / 255;
82 const b = data[i + 2] / 255;
136 const b = data[i + 2] / 255;
83 const next = dualChannelTintedRgb(r, g, b, shaftTint, tipTint);
137 const next = dualChannelTintedRgb(r, g, b, shaftTint, tipTint, coatTint);
84 data[i] = Math.round(next.r * 255);
138 data[i] = Math.round(next.r * 255);
85 data[i + 1] = Math.round(next.g * 255);
139 data[i + 1] = Math.round(next.g * 255);
86 data[i + 2] = Math.round(next.b * 255);
140 data[i + 2] = Math.round(next.b * 255);
@@ -99,17 +153,33 @@ export function resolveItemDualTint (stackOrDef, def = null)
99 if (!definition?.dualTintFromTier)
153 if (!definition?.dualTintFromTier)
100 { return null; }
154 { return null; }
101
155
102 // Tools / arrows: metal primary tier + matching wood shaft.
156 // Tools / arrows: metal primary tier + matching wood shaft (red = wood, blue = metal).
103 if (definition.woodTier)
157 if (definition.woodTier)
104 {
158 {
105 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
159 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
106 const woodTier = definition.woodTier;
160 const woodTier = definition.woodTier;
107 if (!metalTier || !woodTier)
161 if (!metalTier || !woodTier)
108 { return null; }
162 { return null; }
109 return {
163 const dual = {
110 shaft: tierTintColor(woodTier),
164 shaft: tierTintColor(woodTier),
111 tip: tierTintColor(metalTier)
165 tip: tierTintColor(metalTier)
112 };
166 };
167 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
168 { dual.coat = magicElementTint(stack.instance.element); }
169 return dual;
170 }
171
172 // Swords: red = metal, blue = leather wrap.
173 if (definition.leatherTier)
174 {
175 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
176 const leatherTier = definition.leatherTier;
177 if (!metalTier || !leatherTier)
178 { return null; }
179 return {
180 shaft: tierTintColor(metalTier),
181 tip: tierTintColor(leatherTier)
182 };
113 }
183 }
114
184
115 // Magic staff: wood shaft (red) + gem tip (blue).
185 // Magic staff: wood shaft (red) + gem tip (blue).