Tailor dye depletion, passive HP regen, and faster spell projectiles.
Dye picker shows the fullest bottle per colour but crafts spend the emptiest matching bottle first. Entities regen 1 HP every 10s after a minute without damage. Spell projectiles fly 50% faster.
@@ -17,6 +17,11 @@ import
17
17
} from "/shared/crafting/recipes.js";
18
18
import { resolveTailorCraft } from "/shared/crafting/tailor.js";
19
19
import
20
{
21
listDyePickerChoices,
22
resolveDyeDisplayStack
23
} from "/shared/crafting/dye.js";
24
import
20
25
{
21
26
CLOTH_TIER_ORDER,
22
27
CLOTH_DISPLAY_NAME,
@@ -75,6 +80,7 @@ export function initCrafting ({
75
80
let selectedMaterial = ClothTier.cotton;
76
81
77
82
let dyeSlotIndex = null;
83
let dyeColorKey = null;
78
84
let crafting = false;
79
85
let craftTimer = null;
80
86
let craftAnimFrame = null;
@@ -106,12 +112,28 @@ export function initCrafting ({
106
112
});
107
113
dyeClearBtn?.addEventListener("click", () =>
108
114
{
109
dyeSlotIndex = null;
115
clearDyeSelection();
110
116
renderDetail();
111
117
});
112
118
document.getElementById("dye-picker-close")?.addEventListener("click", () => closeDyePicker());
113
119
dyeBackdrop?.addEventListener("click", () => closeDyePicker());
114
120
121
function dyeCraftOptions ()
122
{
123
return { dyeColorKey, dyeSlotIndex };
124
}
125
126
function clearDyeSelection ()
127
{
128
dyeColorKey = null;
129
dyeSlotIndex = null;
130
}
131
132
function selectedDyeStack (slots = getInventorySlots?.() ?? [])
133
{
134
return resolveDyeDisplayStack(slots, dyeCraftOptions());
135
}
136
115
137
function isTailorStation ()
116
138
{
117
139
return stationId === CraftingStationId.tailorBench;
@@ -212,7 +234,7 @@ export function initCrafting ({
212
234
if (!base.tailorTemplate)
213
235
{ return base; }
214
236
const slots = getInventorySlots?.() ?? [];
215
const dyeStack = dyeSlotIndex != null ? slots[dyeSlotIndex] : null;
237
const dyeStack = selectedDyeStack(slots);
216
238
const resolved = resolveTailorCraft({
217
239
templateId: base.tailorTemplate,
218
240
clothTier: selectedMaterial,
@@ -377,7 +399,7 @@ export function initCrafting ({
377
399
const minLevel = recipe.minSkillLevel | 0 || 1;
378
400
if ((skill | 0) < minLevel)
379
401
{ cell.classList.add("level-locked"); }
380
else if (canStartCraft(getInventorySlots?.() ?? [], recipe, skill, { dyeSlotIndex }))
402
else if (canStartCraft(getInventorySlots?.() ?? [], recipe, skill, dyeCraftOptions()))
381
403
{ cell.classList.add("craftable"); }
382
404
383
405
const img = document.createElement("img");
@@ -414,7 +436,7 @@ export function initCrafting ({
414
436
if (materialControls)
415
437
{ materialControls.hidden = !usesMaterialDropdown(); }
416
438
if (!isTailorStation())
417
{ dyeSlotIndex = null; }
439
{ clearDyeSelection(); }
418
440
if (dyeControls)
419
441
{ dyeControls.hidden = !isTailorStation(); }
420
442
@@ -446,18 +468,18 @@ export function initCrafting ({
446
468
}
447
469
if (recipe.consumeDye)
448
470
{
449
const dye = dyeSlotIndex != null ? slots[dyeSlotIndex] : null;
471
const dye = selectedDyeStack(slots);
450
472
const row = document.createElement("li");
451
473
row.className = "craft-input-row";
452
474
row.textContent = dye
453
? `Dye — 1 use (${dye.instance?.fillLevel ?? "?"}/5)`
475
? `Dye — 1 use (${dye.instance?.fillLevel ?? "?"}/5, partial bottles first)`
454
476
: "Dye — none selected";
455
477
inputsList.append(row);
456
478
}
457
479
458
480
if (dyePreview && dyeClearBtn)
459
481
{
460
const dye = dyeSlotIndex != null ? slots[dyeSlotIndex] : null;
482
const dye = selectedDyeStack(slots);
461
483
if (dye?.itemId === ItemId.dye)
462
484
{
463
485
dyePreview.hidden = false;
@@ -524,7 +546,7 @@ export function initCrafting ({
524
546
return;
525
547
}
526
548
const slotsSnapshot = slots ?? getInventorySlots?.() ?? [];
527
const craftOpts = { dyeSlotIndex };
549
const craftOpts = dyeCraftOptions();
528
550
if (canStartCraft(slotsSnapshot, recipe, skill, craftOpts))
529
551
{
530
552
statusEl.textContent = "";
@@ -539,7 +561,7 @@ export function initCrafting ({
539
561
{
540
562
statusEl.textContent = "Missing materials.";
541
563
}
542
else if (recipe.consumeDye && dyeSlotIndex != null)
564
else if (recipe.consumeDye && dyeColorKey != null)
543
565
{
544
566
statusEl.textContent = "Not enough bag space (need room for the result or a partially used dye).";
545
567
}
@@ -560,35 +582,36 @@ export function initCrafting ({
560
582
{ return; }
561
583
const slots = getInventorySlots?.() ?? [];
562
584
dyeGrid.replaceChildren();
563
let found = false;
564
slots.forEach((stack, index) =>
565
{
566
if (!stack || stack.itemId !== ItemId.dye)
567
{ return; }
568
found = true;
569
const cell = document.createElement("button");
570
cell.type = "button";
571
cell.className = "craft-recipe-cell craft-dye-cell";
572
cell.title = "Dye";
573
const img = document.createElement("img");
574
applyItemIcon(img, stack, itemAssetPathForStack(stack));
575
img.alt = "Dye";
576
cell.append(img);
577
cell.addEventListener("click", () =>
578
{
579
dyeSlotIndex = index;
580
closeDyePicker();
581
renderDetail();
582
});
583
dyeGrid.append(cell);
584
});
585
if (!found)
585
const choices = listDyePickerChoices(slots);
586
if (!choices.length)
586
587
{
587
588
const empty = document.createElement("p");
588
589
empty.className = "hint";
589
590
empty.textContent = "No dyes in your inventory.";
590
591
dyeGrid.append(empty);
591
592
}
593
else
594
{
595
for (const entry of choices)
596
{
597
const cell = document.createElement("button");
598
cell.type = "button";
599
cell.className = "craft-recipe-cell craft-dye-cell";
600
cell.title = "Dye";
601
const img = document.createElement("img");
602
applyItemIcon(img, entry.displayStack, itemAssetPathForStack(entry.displayStack));
603
img.alt = "Dye";
604
cell.append(img);
605
cell.addEventListener("click", () =>
606
{
607
dyeColorKey = entry.colorKey;
608
dyeSlotIndex = entry.displayIndex;
609
closeDyePicker();
610
renderDetail();
611
});
612
dyeGrid.append(cell);
613
}
614
}
592
615
dyePanel.hidden = false;
593
616
dyeBackdrop.hidden = false;
594
617
}
@@ -616,7 +639,7 @@ export function initCrafting ({
616
639
if (!recipe || crafting)
617
640
{ return; }
618
641
const slots = getInventorySlots?.() ?? [];
619
if (!canStartCraft(slots, recipe, stationSkillLevel(), { dyeSlotIndex }))
642
if (!canStartCraft(slots, recipe, stationSkillLevel(), dyeCraftOptions()))
620
643
{
621
644
renderDetail();
622
645
return;
@@ -707,6 +730,7 @@ export function initCrafting ({
707
730
const { fallback } = materialOptionsForStation();
708
731
selectedMaterial = fallback;
709
732
dyeSlotIndex = null;
733
dyeColorKey = null;
710
734
fillMaterialTiers();
711
735
const first = groupedDisplayRecipes()[0];
712
736
selectedCraftGroup = first?.group ?? null;
@@ -739,6 +763,7 @@ export function initCrafting ({
739
763
selectedRecipeId = null;
740
764
selectedCraftGroup = null;
741
765
dyeSlotIndex = null;
766
dyeColorKey = null;
742
767
panel.hidden = true;
743
768
backdrop.hidden = true;
744
769
detailEmpty.hidden = false;
@@ -17,6 +17,11 @@ import17
} from "/shared/crafting/recipes.js";17
} from "/shared/crafting/recipes.js";18
import { resolveTailorCraft } from "/shared/crafting/tailor.js";18
import { resolveTailorCraft } from "/shared/crafting/tailor.js";19
import19
import20
{21
listDyePickerChoices,22
resolveDyeDisplayStack23
} from "/shared/crafting/dye.js";24
import20
{25
{21
CLOTH_TIER_ORDER,26
CLOTH_TIER_ORDER,22
CLOTH_DISPLAY_NAME,27
CLOTH_DISPLAY_NAME,@@ -75,6 +80,7 @@ export function initCrafting ({75
let selectedMaterial = ClothTier.cotton;80
let selectedMaterial = ClothTier.cotton;76
81
77
let dyeSlotIndex = null;82
let dyeSlotIndex = null;83
let dyeColorKey = null;78
let crafting = false;84
let crafting = false;79
let craftTimer = null;85
let craftTimer = null;80
let craftAnimFrame = null;86
let craftAnimFrame = null;@@ -106,12 +112,28 @@ export function initCrafting ({106
});112
});107
dyeClearBtn?.addEventListener("click", () =>113
dyeClearBtn?.addEventListener("click", () =>108
{114
{109
dyeSlotIndex = null;115
clearDyeSelection();110
renderDetail();116
renderDetail();111
});117
});112
document.getElementById("dye-picker-close")?.addEventListener("click", () => closeDyePicker());118
document.getElementById("dye-picker-close")?.addEventListener("click", () => closeDyePicker());113
dyeBackdrop?.addEventListener("click", () => closeDyePicker());119
dyeBackdrop?.addEventListener("click", () => closeDyePicker());114
120
121
function dyeCraftOptions ()122
{123
return { dyeColorKey, dyeSlotIndex };124
}125
126
function clearDyeSelection ()127
{128
dyeColorKey = null;129
dyeSlotIndex = null;130
}131
132
function selectedDyeStack (slots = getInventorySlots?.() ?? [])133
{134
return resolveDyeDisplayStack(slots, dyeCraftOptions());135
}136
115
function isTailorStation ()137
function isTailorStation ()116
{138
{117
return stationId === CraftingStationId.tailorBench;139
return stationId === CraftingStationId.tailorBench;@@ -212,7 +234,7 @@ export function initCrafting ({212
if (!base.tailorTemplate)234
if (!base.tailorTemplate)213
{ return base; }235
{ return base; }214
const slots = getInventorySlots?.() ?? [];236
const slots = getInventorySlots?.() ?? [];215
const dyeStack = dyeSlotIndex != null ? slots[dyeSlotIndex] : null;237
const dyeStack = selectedDyeStack(slots);216
const resolved = resolveTailorCraft({238
const resolved = resolveTailorCraft({217
templateId: base.tailorTemplate,239
templateId: base.tailorTemplate,218
clothTier: selectedMaterial,240
clothTier: selectedMaterial,@@ -377,7 +399,7 @@ export function initCrafting ({377
const minLevel = recipe.minSkillLevel | 0 || 1;399
const minLevel = recipe.minSkillLevel | 0 || 1;378
if ((skill | 0) < minLevel)400
if ((skill | 0) < minLevel)379
{ cell.classList.add("level-locked"); }401
{ cell.classList.add("level-locked"); }380
else if (canStartCraft(getInventorySlots?.() ?? [], recipe, skill, { dyeSlotIndex }))402
else if (canStartCraft(getInventorySlots?.() ?? [], recipe, skill, dyeCraftOptions()))381
{ cell.classList.add("craftable"); }403
{ cell.classList.add("craftable"); }382
404
383
const img = document.createElement("img");405
const img = document.createElement("img");@@ -414,7 +436,7 @@ export function initCrafting ({414
if (materialControls)436
if (materialControls)415
{ materialControls.hidden = !usesMaterialDropdown(); }437
{ materialControls.hidden = !usesMaterialDropdown(); }416
if (!isTailorStation())438
if (!isTailorStation())417
{ dyeSlotIndex = null; }439
{ clearDyeSelection(); }418
if (dyeControls)440
if (dyeControls)419
{ dyeControls.hidden = !isTailorStation(); }441
{ dyeControls.hidden = !isTailorStation(); }420
442
@@ -446,18 +468,18 @@ export function initCrafting ({446
}468
}447
if (recipe.consumeDye)469
if (recipe.consumeDye)448
{470
{449
const dye = dyeSlotIndex != null ? slots[dyeSlotIndex] : null;471
const dye = selectedDyeStack(slots);450
const row = document.createElement("li");472
const row = document.createElement("li");451
row.className = "craft-input-row";473
row.className = "craft-input-row";452
row.textContent = dye474
row.textContent = dye453
? `Dye — 1 use (${dye.instance?.fillLevel ?? "?"}/5)`475
? `Dye — 1 use (${dye.instance?.fillLevel ?? "?"}/5, partial bottles first)`454
: "Dye — none selected";476
: "Dye — none selected";455
inputsList.append(row);477
inputsList.append(row);456
}478
}457
479
458
if (dyePreview && dyeClearBtn)480
if (dyePreview && dyeClearBtn)459
{481
{460
const dye = dyeSlotIndex != null ? slots[dyeSlotIndex] : null;482
const dye = selectedDyeStack(slots);461
if (dye?.itemId === ItemId.dye)483
if (dye?.itemId === ItemId.dye)462
{484
{463
dyePreview.hidden = false;485
dyePreview.hidden = false;@@ -524,7 +546,7 @@ export function initCrafting ({524
return;546
return;525
}547
}526
const slotsSnapshot = slots ?? getInventorySlots?.() ?? [];548
const slotsSnapshot = slots ?? getInventorySlots?.() ?? [];527
const craftOpts = { dyeSlotIndex };549
const craftOpts = dyeCraftOptions();528
if (canStartCraft(slotsSnapshot, recipe, skill, craftOpts))550
if (canStartCraft(slotsSnapshot, recipe, skill, craftOpts))529
{551
{530
statusEl.textContent = "";552
statusEl.textContent = "";@@ -539,7 +561,7 @@ export function initCrafting ({539
{561
{540
statusEl.textContent = "Missing materials.";562
statusEl.textContent = "Missing materials.";541
}563
}542
else if (recipe.consumeDye && dyeSlotIndex != null)564
else if (recipe.consumeDye && dyeColorKey != null)543
{565
{544
statusEl.textContent = "Not enough bag space (need room for the result or a partially used dye).";566
statusEl.textContent = "Not enough bag space (need room for the result or a partially used dye).";545
}567
}@@ -560,35 +582,36 @@ export function initCrafting ({560
{ return; }582
{ return; }561
const slots = getInventorySlots?.() ?? [];583
const slots = getInventorySlots?.() ?? [];562
dyeGrid.replaceChildren();584
dyeGrid.replaceChildren();563
let found = false;585
const choices = listDyePickerChoices(slots);564
slots.forEach((stack, index) =>586
if (!choices.length)565
{566
if (!stack || stack.itemId !== ItemId.dye)567
{ return; }568
found = true;569
const cell = document.createElement("button");570
cell.type = "button";571
cell.className = "craft-recipe-cell craft-dye-cell";572
cell.title = "Dye";573
const img = document.createElement("img");574
applyItemIcon(img, stack, itemAssetPathForStack(stack));575
img.alt = "Dye";576
cell.append(img);577
cell.addEventListener("click", () =>578
{579
dyeSlotIndex = index;580
closeDyePicker();581
renderDetail();582
});583
dyeGrid.append(cell);584
});585
if (!found)586
{587
{587
const empty = document.createElement("p");588
const empty = document.createElement("p");588
empty.className = "hint";589
empty.className = "hint";589
empty.textContent = "No dyes in your inventory.";590
empty.textContent = "No dyes in your inventory.";590
dyeGrid.append(empty);591
dyeGrid.append(empty);591
}592
}593
else594
{595
for (const entry of choices)596
{597
const cell = document.createElement("button");598
cell.type = "button";599
cell.className = "craft-recipe-cell craft-dye-cell";600
cell.title = "Dye";601
const img = document.createElement("img");602
applyItemIcon(img, entry.displayStack, itemAssetPathForStack(entry.displayStack));603
img.alt = "Dye";604
cell.append(img);605
cell.addEventListener("click", () =>606
{607
dyeColorKey = entry.colorKey;608
dyeSlotIndex = entry.displayIndex;609
closeDyePicker();610
renderDetail();611
});612
dyeGrid.append(cell);613
}614
}592
dyePanel.hidden = false;615
dyePanel.hidden = false;593
dyeBackdrop.hidden = false;616
dyeBackdrop.hidden = false;594
}617
}@@ -616,7 +639,7 @@ export function initCrafting ({616
if (!recipe || crafting)639
if (!recipe || crafting)617
{ return; }640
{ return; }618
const slots = getInventorySlots?.() ?? [];641
const slots = getInventorySlots?.() ?? [];619
if (!canStartCraft(slots, recipe, stationSkillLevel(), { dyeSlotIndex }))642
if (!canStartCraft(slots, recipe, stationSkillLevel(), dyeCraftOptions()))620
{643
{621
renderDetail();644
renderDetail();622
return;645
return;@@ -707,6 +730,7 @@ export function initCrafting ({707
const { fallback } = materialOptionsForStation();730
const { fallback } = materialOptionsForStation();708
selectedMaterial = fallback;731
selectedMaterial = fallback;709
dyeSlotIndex = null;732
dyeSlotIndex = null;733
dyeColorKey = null;710
fillMaterialTiers();734
fillMaterialTiers();711
const first = groupedDisplayRecipes()[0];735
const first = groupedDisplayRecipes()[0];712
selectedCraftGroup = first?.group ?? null;736
selectedCraftGroup = first?.group ?? null;@@ -739,6 +763,7 @@ export function initCrafting ({739
selectedRecipeId = null;763
selectedRecipeId = null;740
selectedCraftGroup = null;764
selectedCraftGroup = null;741
dyeSlotIndex = null;765
dyeSlotIndex = null;766
dyeColorKey = null;742
panel.hidden = true;767
panel.hidden = true;743
backdrop.hidden = true;768
backdrop.hidden = true;744
detailEmpty.hidden = false;769
detailEmpty.hidden = false;@@ -47,6 +47,13 @@ import
47
47
} from "../../../shared/equipment/stats.js";
48
48
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
49
49
import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../../../shared/spells/constants.js";
50
import
51
{
52
markHealthDamaged,
53
PASSIVE_HP_REGEN_DELAY_MS,
54
PASSIVE_HP_REGEN_PER_SECOND
55
} from "../../../shared/combat/passiveRegen.js";
56
import { publicEntityView } from "../ecs/serialize.js";
50
57
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
51
58
import { chunkBoundsAround, findPath } from "../navigation/astar.js";
52
59
import { tileToChunk } from "../world/coordinates.js";
@@ -766,6 +773,46 @@ function attackerCombatLevels (ecs, attackerHandle, profile, settings = null)
766
773
};
767
774
}
768
775
776
export function stepPassiveHealthRegen (world, now = Date.now(), dt = 1 / 20)
777
{
778
const events = [];
779
for (const entity of world.ecs.query(Component.health, Component.position))
780
{
781
const { handle, entityId, health, position, character } = entity;
782
if (world.ecs.has(handle, Component.dead))
783
{ continue; }
784
if (!world.chunkIsSimulating?.(position.tileX, position.tileY))
785
{ continue; }
786
if ((health.current | 0) >= (health.max | 0))
787
{ continue; }
788
const lastDamageAt = health.lastDamageAt ?? 0;
789
if (now - lastDamageAt < PASSIVE_HP_REGEN_DELAY_MS)
790
{ continue; }
791
const beforeInt = health.current | 0;
792
health.current = Math.min(
793
health.max | 0,
794
(Number(health.current) || 0) + PASSIVE_HP_REGEN_PER_SECOND * dt
795
);
796
if ((health.current | 0) === beforeInt)
797
{ continue; }
798
if (character)
799
{ syncPlayerHealth(world.ecs, handle); }
800
const view = publicEntityView(world.ecs, entityId);
801
if (!view)
802
{ continue; }
803
events.push({
804
type: "entity-health",
805
entityId,
806
...(character ? { characterId: character.characterId } : {}),
807
health: view.health,
808
maxHealth: view.maxHealth,
809
tileX: view.tileX,
810
tileY: view.tileY
811
});
812
}
813
return events;
814
}
815
769
816
export function stepCombat (world, now = Date.now())
770
817
{
771
818
const events = [];
@@ -1925,6 +1972,7 @@ function applyLocalMeleeHit (
1925
1972
if (health)
1926
1973
{
1927
1974
health.current = Math.max(0, (health.current | 0) - damage);
1975
markHealthDamaged(health, now);
1928
1976
}
1929
1977
events.push({
1930
1978
type: "combat-hit",
@@ -2092,7 +2140,10 @@ export function applyDamageAndKill (world, attackerId, targetId, damage, now = D
2092
2140
{ return events; }
2093
2141
const health = world.ecs.get(targetHandle, Component.health);
2094
2142
if (health)
2095
{ health.current = Math.max(0, (health.current | 0) - damage); }
2143
{
2144
health.current = Math.max(0, (health.current | 0) - damage);
2145
markHealthDamaged(health, now);
2146
}
2096
2147
events.push({
2097
2148
type: "combat-hit",
2098
2149
attackerId,
@@ -47,6 +47,13 @@ import47
} from "../../../shared/equipment/stats.js";47
} from "../../../shared/equipment/stats.js";48
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";48
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";49
import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../../../shared/spells/constants.js";49
import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../../../shared/spells/constants.js";50
import51
{52
markHealthDamaged,53
PASSIVE_HP_REGEN_DELAY_MS,54
PASSIVE_HP_REGEN_PER_SECOND55
} from "../../../shared/combat/passiveRegen.js";56
import { publicEntityView } from "../ecs/serialize.js";50
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";57
import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";51
import { chunkBoundsAround, findPath } from "../navigation/astar.js";58
import { chunkBoundsAround, findPath } from "../navigation/astar.js";52
import { tileToChunk } from "../world/coordinates.js";59
import { tileToChunk } from "../world/coordinates.js";@@ -766,6 +773,46 @@ function attackerCombatLevels (ecs, attackerHandle, profile, settings = null)766
};773
};767
}774
}768
775
776
export function stepPassiveHealthRegen (world, now = Date.now(), dt = 1 / 20)777
{778
const events = [];779
for (const entity of world.ecs.query(Component.health, Component.position))780
{781
const { handle, entityId, health, position, character } = entity;782
if (world.ecs.has(handle, Component.dead))783
{ continue; }784
if (!world.chunkIsSimulating?.(position.tileX, position.tileY))785
{ continue; }786
if ((health.current | 0) >= (health.max | 0))787
{ continue; }788
const lastDamageAt = health.lastDamageAt ?? 0;789
if (now - lastDamageAt < PASSIVE_HP_REGEN_DELAY_MS)790
{ continue; }791
const beforeInt = health.current | 0;792
health.current = Math.min(793
health.max | 0,794
(Number(health.current) || 0) + PASSIVE_HP_REGEN_PER_SECOND * dt795
);796
if ((health.current | 0) === beforeInt)797
{ continue; }798
if (character)799
{ syncPlayerHealth(world.ecs, handle); }800
const view = publicEntityView(world.ecs, entityId);801
if (!view)802
{ continue; }803
events.push({804
type: "entity-health",805
entityId,806
...(character ? { characterId: character.characterId } : {}),807
health: view.health,808
maxHealth: view.maxHealth,809
tileX: view.tileX,810
tileY: view.tileY811
});812
}813
return events;814
}815
769
export function stepCombat (world, now = Date.now())816
export function stepCombat (world, now = Date.now())770
{817
{771
const events = [];818
const events = [];@@ -1925,6 +1972,7 @@ function applyLocalMeleeHit (1925
if (health)1972
if (health)1926
{1973
{1927
health.current = Math.max(0, (health.current | 0) - damage);1974
health.current = Math.max(0, (health.current | 0) - damage);1975
markHealthDamaged(health, now);1928
}1976
}1929
events.push({1977
events.push({1930
type: "combat-hit",1978
type: "combat-hit",@@ -2092,7 +2140,10 @@ export function applyDamageAndKill (world, attackerId, targetId, damage, now = D2092
{ return events; }2140
{ return events; }2093
const health = world.ecs.get(targetHandle, Component.health);2141
const health = world.ecs.get(targetHandle, Component.health);2094
if (health)2142
if (health)2095
{ health.current = Math.max(0, (health.current | 0) - damage); }2143
{2144
health.current = Math.max(0, (health.current | 0) - damage);2145
markHealthDamaged(health, now);2146
}2096
events.push({2147
events.push({2097
type: "combat-hit",2148
type: "combat-hit",2098
attackerId,2149
attackerId,@@ -64,6 +64,7 @@ import {
64
64
silenceDeadPlayer,
65
65
stepAggression,
66
66
stepCombat,
67
stepPassiveHealthRegen,
67
68
chebyshev
68
69
} from "../combat/service.js";
69
70
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";
@@ -1284,6 +1285,7 @@ export class WorkerWorld
1284
1285
const transferRequests = [];
1285
1286
this.#regenStamina(dt, events);
1286
1287
events.push(...stepStatusEffects(this, now, dt));
1288
events.push(...stepPassiveHealthRegen(this, now, dt));
1287
1289
const flight = stepFreeFlight(this, now);
1288
1290
for (const event of flight)
1289
1291
{
@@ -64,6 +64,7 @@ import {64
silenceDeadPlayer,64
silenceDeadPlayer,65
stepAggression,65
stepAggression,66
stepCombat,66
stepCombat,67
stepPassiveHealthRegen,67
chebyshev68
chebyshev68
} from "../combat/service.js";69
} from "../combat/service.js";69
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";70
import { awardCombatHitXp, syncPlayerStamina } from "../skills/service.js";@@ -1284,6 +1285,7 @@ export class WorkerWorld1284
const transferRequests = [];1285
const transferRequests = [];1285
this.#regenStamina(dt, events);1286
this.#regenStamina(dt, events);1286
events.push(...stepStatusEffects(this, now, dt));1287
events.push(...stepStatusEffects(this, now, dt));1288
events.push(...stepPassiveHealthRegen(this, now, dt));1287
const flight = stepFreeFlight(this, now);1289
const flight = stepFreeFlight(this, now);1288
for (const event of flight)1290
for (const event of flight)1289
{1291
{@@ -6,6 +6,7 @@ import {
6
6
publicStatusEffectsView,
7
7
hasStatusEffect
8
8
} from "../../../shared/statusEffects/rules.js";
9
import { markHealthDamaged } from "../../../shared/combat/passiveRegen.js";
9
10
import { publicEntityView } from "../ecs/serialize.js";
10
11
import { syncPlayerHealth } from "../skills/service.js";
11
12
@@ -55,7 +56,10 @@ export function stepStatusEffects (world, now = Date.now(), dt = 1 / 20)
55
56
const next = Math.max(0, (Number(health.current) || 0) - rate * dt);
56
57
health.current = next;
57
58
if ((next | 0) !== beforeInt)
58
{ healthChanged = true; }
59
{
60
markHealthDamaged(health, now);
61
healthChanged = true;
62
}
59
63
}
60
64
if (entry.type === StatusEffectType.staminaRegen && stamina)
61
65
{
@@ -6,6 +6,7 @@ import {6
publicStatusEffectsView,6
publicStatusEffectsView,7
hasStatusEffect7
hasStatusEffect8
} from "../../../shared/statusEffects/rules.js";8
} from "../../../shared/statusEffects/rules.js";9
import { markHealthDamaged } from "../../../shared/combat/passiveRegen.js";9
import { publicEntityView } from "../ecs/serialize.js";10
import { publicEntityView } from "../ecs/serialize.js";10
import { syncPlayerHealth } from "../skills/service.js";11
import { syncPlayerHealth } from "../skills/service.js";11
12
@@ -55,7 +56,10 @@ export function stepStatusEffects (world, now = Date.now(), dt = 1 / 20)55
const next = Math.max(0, (Number(health.current) || 0) - rate * dt);56
const next = Math.max(0, (Number(health.current) || 0) - rate * dt);56
health.current = next;57
health.current = next;57
if ((next | 0) !== beforeInt)58
if ((next | 0) !== beforeInt)58
{ healthChanged = true; }59
{60
markHealthDamaged(health, now);61
healthChanged = true;62
}59
}63
}60
if (entry.type === StatusEffectType.staminaRegen && stamina)64
if (entry.type === StatusEffectType.staminaRegen && stamina)61
{65
{@@ -0,0 +1,57 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { ItemId } from "../../shared/definitions/items.js";
4
import { dyeColorKey } from "../../shared/definitions/dyes.js";
5
import { emptySlots } from "../../shared/items/inventory.js";
6
import { canCraftFitInventory } from "../../shared/crafting/recipes.js";
7
import {
8
listDyePickerChoices,
9
pickEmptiestDyeSlot
10
} from "../../shared/crafting/dye.js";
11
import { sweaterItemId } from "../../shared/definitions/clothItems.js";
12
import { ClothTier } from "../../shared/definitions/materialTiers.js";
13
import { yarnItemId } from "../../shared/definitions/clothItems.js";
14
15
const red = { r: 0.9, g: 0.1, b: 0.1 };
16
17
function dyeStack (color, fillLevel, quantity = 1)
18
{
19
return {
20
itemId: ItemId.dye,
21
quantity,
22
instance: { kind: "dye", color, fillLevel }
23
};
24
}
25
26
test("dye picker shows one fullest bottle per colour", () =>
27
{
28
const slots = emptySlots();
29
slots[0] = dyeStack(red, 1);
30
slots[1] = dyeStack(red, 4);
31
slots[2] = dyeStack({ r: 0.1, g: 0.2, b: 0.9 }, 3);
32
const choices = listDyePickerChoices(slots);
33
assert.equal(choices.length, 2);
34
const redChoice = choices.find((entry) => entry.displayIndex === 1);
35
assert.ok(redChoice);
36
assert.equal(redChoice.fill, 4);
37
});
38
39
test("tailor crafts consume the emptiest bottle of the chosen colour", () =>
40
{
41
const slots = emptySlots();
42
const yarn = yarnItemId(ClothTier.cotton);
43
slots[0] = { itemId: yarn, quantity: 3 };
44
slots[1] = dyeStack(red, 4);
45
slots[2] = dyeStack(red, 1);
46
for (let i = 3; i < slots.length; i++)
47
{ slots[i] = { itemId: ItemId.apple, quantity: 1 }; }
48
const colorKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 });
49
assert.equal(pickEmptiestDyeSlot(slots, colorKey), 2);
50
const recipe = {
51
output: { itemId: sweaterItemId(ClothTier.cotton), quantity: 1 },
52
inputs: [{ itemId: yarn, quantity: 3 }],
53
consumeDye: true,
54
dyeColor: red
55
};
56
assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: colorKey }), true);
57
});
@@ -0,0 +1,57 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { ItemId } from "../../shared/definitions/items.js";4
import { dyeColorKey } from "../../shared/definitions/dyes.js";5
import { emptySlots } from "../../shared/items/inventory.js";6
import { canCraftFitInventory } from "../../shared/crafting/recipes.js";7
import {8
listDyePickerChoices,9
pickEmptiestDyeSlot10
} from "../../shared/crafting/dye.js";11
import { sweaterItemId } from "../../shared/definitions/clothItems.js";12
import { ClothTier } from "../../shared/definitions/materialTiers.js";13
import { yarnItemId } from "../../shared/definitions/clothItems.js";14
15
const red = { r: 0.9, g: 0.1, b: 0.1 };16
17
function dyeStack (color, fillLevel, quantity = 1)18
{19
return {20
itemId: ItemId.dye,21
quantity,22
instance: { kind: "dye", color, fillLevel }23
};24
}25
26
test("dye picker shows one fullest bottle per colour", () =>27
{28
const slots = emptySlots();29
slots[0] = dyeStack(red, 1);30
slots[1] = dyeStack(red, 4);31
slots[2] = dyeStack({ r: 0.1, g: 0.2, b: 0.9 }, 3);32
const choices = listDyePickerChoices(slots);33
assert.equal(choices.length, 2);34
const redChoice = choices.find((entry) => entry.displayIndex === 1);35
assert.ok(redChoice);36
assert.equal(redChoice.fill, 4);37
});38
39
test("tailor crafts consume the emptiest bottle of the chosen colour", () =>40
{41
const slots = emptySlots();42
const yarn = yarnItemId(ClothTier.cotton);43
slots[0] = { itemId: yarn, quantity: 3 };44
slots[1] = dyeStack(red, 4);45
slots[2] = dyeStack(red, 1);46
for (let i = 3; i < slots.length; i++)47
{ slots[i] = { itemId: ItemId.apple, quantity: 1 }; }48
const colorKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 });49
assert.equal(pickEmptiestDyeSlot(slots, colorKey), 2);50
const recipe = {51
output: { itemId: sweaterItemId(ClothTier.cotton), quantity: 1 },52
inputs: [{ itemId: yarn, quantity: 3 }],53
consumeDye: true,54
dyeColor: red55
};56
assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: colorKey }), true);57
});@@ -8,7 +8,7 @@ import {
8
8
stackQuantity
9
9
} from "../../shared/items/inventory.js";
10
10
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
11
import { dyeItemInstance } from "../../shared/definitions/dyes.js";
11
import { dyeItemInstance, dyeColorKey } from "../../shared/definitions/dyes.js";
12
12
import { potionItemInstance } from "../../shared/alchemy/recipes.js";
13
13
import { canCraftFitInventory } from "../../shared/crafting/recipes.js";
14
14
import { ClothTier } from "../../shared/definitions/materialTiers.js";
@@ -137,12 +137,13 @@ test("canCraftFitInventory accounts for dye charge split after inputs", () =>
137
137
consumeDye: true,
138
138
dyeColor: red
139
139
};
140
assert.equal(canCraftFitInventory(slots, recipe, { dyeSlotIndex: 1 }), true);
140
const dyeKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 });
141
assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: dyeKey }), true);
141
142
// Full bag with only the yarn slot freeing: dye peel consumes that free slot → no room for sweater.
142
143
const tight = emptySlots();
143
144
tight[0] = { itemId: yarn, quantity: 3 };
144
145
tight[1] = dyeStack(red, 4, 2);
145
146
for (let i = 2; i < tight.length; i++)
146
147
{ tight[i] = { itemId: ItemId.apple, quantity: 1 }; }
147
assert.equal(canCraftFitInventory(tight, recipe, { dyeSlotIndex: 1 }), false);
148
assert.equal(canCraftFitInventory(tight, recipe, { dyeColorKey: dyeKey }), false);
148
149
});
@@ -8,7 +8,7 @@ import {8
stackQuantity8
stackQuantity9
} from "../../shared/items/inventory.js";9
} from "../../shared/items/inventory.js";10
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";10
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";11
import { dyeItemInstance } from "../../shared/definitions/dyes.js";11
import { dyeItemInstance, dyeColorKey } from "../../shared/definitions/dyes.js";12
import { potionItemInstance } from "../../shared/alchemy/recipes.js";12
import { potionItemInstance } from "../../shared/alchemy/recipes.js";13
import { canCraftFitInventory } from "../../shared/crafting/recipes.js";13
import { canCraftFitInventory } from "../../shared/crafting/recipes.js";14
import { ClothTier } from "../../shared/definitions/materialTiers.js";14
import { ClothTier } from "../../shared/definitions/materialTiers.js";@@ -137,12 +137,13 @@ test("canCraftFitInventory accounts for dye charge split after inputs", () =>137
consumeDye: true,137
consumeDye: true,138
dyeColor: red138
dyeColor: red139
};139
};140
assert.equal(canCraftFitInventory(slots, recipe, { dyeSlotIndex: 1 }), true);140
const dyeKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 });141
assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: dyeKey }), true);141
// Full bag with only the yarn slot freeing: dye peel consumes that free slot → no room for sweater.142
// Full bag with only the yarn slot freeing: dye peel consumes that free slot → no room for sweater.142
const tight = emptySlots();143
const tight = emptySlots();143
tight[0] = { itemId: yarn, quantity: 3 };144
tight[0] = { itemId: yarn, quantity: 3 };144
tight[1] = dyeStack(red, 4, 2);145
tight[1] = dyeStack(red, 4, 2);145
for (let i = 2; i < tight.length; i++)146
for (let i = 2; i < tight.length; i++)146
{ tight[i] = { itemId: ItemId.apple, quantity: 1 }; }147
{ tight[i] = { itemId: ItemId.apple, quantity: 1 }; }147
assert.equal(canCraftFitInventory(tight, recipe, { dyeSlotIndex: 1 }), false);148
assert.equal(canCraftFitInventory(tight, recipe, { dyeColorKey: dyeKey }), false);148
});149
});@@ -0,0 +1,30 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { EcsWorld } from "../src/ecs/world.js";
4
import { Component } from "../src/ecs/components.js";
5
import { stepPassiveHealthRegen } from "../src/combat/service.js";
6
import
7
{
8
markHealthDamaged,
9
PASSIVE_HP_REGEN_DELAY_MS
10
} from "../../shared/combat/passiveRegen.js";
11
12
test("passive health regen waits one minute after damage", () =>
13
{
14
const ecs = new EcsWorld();
15
const entityId = 1;
16
const handle = ecs.spawn(entityId);
17
ecs.add(handle, Component.position, { tileX: 8, tileY: 8 });
18
ecs.add(handle, Component.health, { current: 10, max: 100 });
19
const world = {
20
ecs,
21
chunkIsSimulating: () => true
22
};
23
const now = 1_000_000;
24
markHealthDamaged(ecs.get(handle, Component.health), now);
25
stepPassiveHealthRegen(world, now + PASSIVE_HP_REGEN_DELAY_MS - 1, 1);
26
assert.equal(ecs.get(handle, Component.health).current, 10);
27
const events = stepPassiveHealthRegen(world, now + PASSIVE_HP_REGEN_DELAY_MS + 10_000, 10);
28
assert.ok(events.some((event) => event.type === "entity-health"));
29
assert.ok(ecs.get(handle, Component.health).current > 10);
30
});
@@ -0,0 +1,30 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { EcsWorld } from "../src/ecs/world.js";4
import { Component } from "../src/ecs/components.js";5
import { stepPassiveHealthRegen } from "../src/combat/service.js";6
import7
{8
markHealthDamaged,9
PASSIVE_HP_REGEN_DELAY_MS10
} from "../../shared/combat/passiveRegen.js";11
12
test("passive health regen waits one minute after damage", () =>13
{14
const ecs = new EcsWorld();15
const entityId = 1;16
const handle = ecs.spawn(entityId);17
ecs.add(handle, Component.position, { tileX: 8, tileY: 8 });18
ecs.add(handle, Component.health, { current: 10, max: 100 });19
const world = {20
ecs,21
chunkIsSimulating: () => true22
};23
const now = 1_000_000;24
markHealthDamaged(ecs.get(handle, Component.health), now);25
stepPassiveHealthRegen(world, now + PASSIVE_HP_REGEN_DELAY_MS - 1, 1);26
assert.equal(ecs.get(handle, Component.health).current, 10);27
const events = stepPassiveHealthRegen(world, now + PASSIVE_HP_REGEN_DELAY_MS + 10_000, 10);28
assert.ok(events.some((event) => event.type === "entity-health"));29
assert.ok(ecs.get(handle, Component.health).current > 10);30
});