feat: implement DoT/debuff runtime system (spec §6, AC-12, AC-13)
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m18s

- Add ActiveEffect, EffectType types to game.ts; activeEffects + effectiveArmor on EnemyState
- Add SpellOnHitEffect + onHitEffect field to SpellDefinition
- Wire onHitEffect to fire (burn), death (curse), lightning (armor_corrode), frost (freeze), soul (bypassArmor burn)
- Add applyOnHitEffect() — applies on-hit effect on successful spell hit (spec §6.2)
- Add processDoTPhase() — ticks all active effects after weapon/golem attacks (spec §6.3)
- Add bypassArmor/bypassBarrier support in applyEnemyDefenses() (AC-13)
- Export standalone applyEnemyDefenses from combat-tick.ts for DoT pipeline
- Split DoT runtime into separate dot-runtime.ts (135 lines) to keep combat-actions.ts under 400 lines
- Update all enemy generation sites with activeEffects/effectiveArmor defaults
- Fix test helpers for new required fields

All 921 tests pass (45 test files)
This commit is contained in:
2026-06-03 18:38:01 +02:00
parent a2cdf6d21c
commit b506f0bcc3
30 changed files with 3272 additions and 71 deletions
@@ -0,0 +1,347 @@
# Item Fabrication System — Design Spec
> Describes the Fabricator attunement's crafting system: recipe categories, unlock
> gates, material costs, crafting flow, and how fabricated items differ from base loot.
---
## 1. Objective
Item Fabrication is the Fabricator attunement's non-combat crafting system. It allows
the player to craft materials and equipment using mana and component items. Recipes
are unlocked through Fabricator discipline perks, and the resulting equipment can
carry pre-applied enchantments, making fabrication a parallel path to the Enchanter's
enchanting system.
**Design goals:**
- Fabricated equipment provides an alternative to loot drops
- Material crafting creates a multi-tier resource pipeline
- Discipline-gated recipe unlocks reward Fabricator attunement investment
- Pre-applied enchantments on crafted gear offer unique combinations
- Crafting Efficiency discipline reduces material costs
---
## 2. Recipe Categories
### 2.1 Overview
| Category | File | Count | Unlock Gate |
|---|---|---|---|
| Material Recipes | `fabricator-material-recipes.ts` | 15 | None (base recipes) |
| Core Equipment (Elemental) | `fabricator-recipes.ts` | 12 | Study Fabricator Recipes discipline |
| Wizard Branch | `fabricator-wizard-recipes.ts` | 14 | Study Wizard Equipment discipline |
| Physical Branch | `fabricator-physical-recipes.ts` | 7 | Study Physical Equipment discipline |
| **Total** | | **48** | |
### 2.2 Recipe Type Structure
```typescript
interface FabricatorRecipe {
id: string;
name: string;
description: string;
manaType: string; // Mana type required (must be unlocked)
equipmentTypeId: string; // Equipment type ID produced
slot: EquipmentSlot; // Slot the equipment occupies
materials: Record<string, number>; // materialId -> count required
manaCost: number; // Mana cost in the recipe's mana type
craftTime: number; // Craft time in hours
rarity: 'common' | 'uncommon' | 'rare' | 'epic' | 'legendary';
gearTrait: string; // Flavor text for gear properties
bonusEnchantments?: AppliedEnchantment[]; // Pre-applied enchantments
recipeType?: 'equipment' | 'material';
resultMaterial?: string; // For material recipes: material ID produced
resultAmount?: number; // For material recipes: how many are produced
}
```
---
## 3. Material Recipes
### 3.1 Tier 1: Basic Materials
| ID | Name | Mana Type | Mana Cost | Input | Output | Time |
|---|---|---|---|---|---|---|
| `manaCrystal` | Mana Crystal | raw | 500 | — | 1× manaCrystal | 1h |
| `manaCrystalDustCraft` | Mana Crystal Dust | raw | 10 | 1× manaCrystal | 2× manaCrystalDust | 1h |
### 3.2 Tier 2: Elemental Crystals
All cost 100 of the respective element mana, take 1 hour, produce 1 crystal.
| ID | Mana Type | Element |
|---|---|---|
| `fireCrystal` | fire | Fire |
| `waterCrystal` | water | Water |
| `airCrystal` | air | Air |
| `earthCrystal` | earth | Earth |
| `lightCrystal` | light | Light |
| `darkCrystal` | dark | Dark |
| `metalCrystal` | metal | Metal |
| `crystalCrystal` | crystal | Crystal |
### 3.3 Tier 3: Shards and Cores
| ID | Mana Type | Mana Cost | Input | Output | Time |
|---|---|---|---|---|---|
| `earthShardCraft` | earth | 50 | 1× earthCrystal | 1× earthShard | 1h |
| `elementalCore` | raw | 100 | 10× manaCrystal | 1× elementalCore | 10h |
### 3.4 Tier 4: Advanced Materials
| ID | Mana Type | Mana Cost | Input | Output | Time |
|---|---|---|---|---|---|
| `aetherWeave` | air | 500 | 3× airCrystal, 3× lightCrystal, 2× elementalCore | 1× aetherWeave | 12h |
| `voidCloth` | dark | 500 | 3× airCrystal, 3× darkCrystal, 2× voidEssence | 1× voidCloth | 12h |
| `liquidCrystalLattice` | crystal | 800 | 5× crystalCrystal, 3× elementalCore, 2× voidEssence, 1× celestialFragment | 1× liquidCrystalLattice | 20h |
### 3.5 Material Dependency Chain
```
Raw Mana (500) → Mana Crystal (1)
Mana Crystal (1) + Raw Mana (10) → Mana Crystal Dust (2)
Mana Crystal (1) + Element Mana (100) → Element Crystal (1) [per element]
Element Crystal (1) + Element Mana (50) → Element Shard (1) [earth only]
Mana Crystal (10) + Raw Mana (100) → Elemental Core (1) [10hr]
Air Crystal (3) + Light Crystal (3) + Elemental Core (2) → Aether Weave (1) [12hr]
Air Crystal (3) + Dark Crystal (3) + Void Essence (2) → Void Cloth (1) [12hr]
Crystal Crystal (5) + Elemental Core (3) + Void Essence (2) + Celestial Fragment (1) → Liquid Crystal Lattice (1) [20hr]
```
---
## 4. Equipment Recipes
### 4.1 Earth Gear (Unlock: Study Fabricator Recipes @ 50 XP)
| ID | Name | Slot | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|
| `earthHelm` | Earthen Helm | head | 200 earth | 4× manaCrystalDust, 2× earthShard | uncommon | 3h |
| `earthChest` | Stoneguard Armor | body | 500 earth | 8× manaCrystalDust, 4× earthShard, 1× elementalCore | rare | 6h |
| `earthBoots` | Stonegreaves | feet | 150 earth | 3× manaCrystalDust, 1× earthShard | uncommon | 2h |
### 4.2 Metal Gear (Unlock: Study Fabricator Recipes @ 100 XP)
| ID | Name | Slot | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|
| `metalBlade` | Metal Blade | mainHand | 400 metal | 6× manaCrystalDust, 3× metalShard, 2× elementalCore | rare | 5h |
| `metalShield` | Metal Spell Focus | offHand | 450 metal | 7× manaCrystalDust, 4× metalShard, 1× elementalCore | rare | 5h |
| `metalGloves` | Metalweave Gauntlets | hands | 250 metal | 4× manaCrystalDust, 2× metalShard | uncommon | 3h |
### 4.3 Sand Gear (Unlock: Study Fabricator Recipes @ 150 XP)
| ID | Name | Slot | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|
| `sandBoots` | Sandstrider Boots | feet | 120 sand | 3× manaCrystalDust, 1× sandShard | uncommon | 2h |
| `sandGloves` | Sandweave Gloves | hands | 140 sand | 3× manaCrystalDust, 2× sandShard | uncommon | 2h |
| `sandVest` | Sandcloth Vest | body | 300 sand | 5× manaCrystalDust, 2× sandShard, 1× elementalCore | rare | 4h |
### 4.4 Crystal Gear (Unlock: Study Fabricator Recipes @ 200 XP)
| ID | Name | Slot | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|
| `crystalWand` | Crystal Focus Wand | mainHand | 600 crystal | 10× manaCrystalDust, 5× crystalShard, 3× elementalCore | epic | 6h |
| `crystalRing` | Crystal Ring | accessory1 | 350 crystal | 5× manaCrystalDust, 3× crystalShard, 1× elementalCore | rare | 3h |
| `crystalAmulet` | Crystal Pendant | accessory2 | 400 crystal | 6× manaCrystalDust, 3× crystalShard, 2× elementalCore | rare | 4h |
### 4.5 Wizard Branch (Unlock: Study Wizard Equipment discipline)
| ID | Name | Slot | Unlock (XP) | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|---|
| `oakStaff` | Oak Staff | mainHand | 50 | 200 earth | 5× manaCrystalDust, 2× earthShard | uncommon | 3h |
| `arcanistStaff` | Arcanist Staff | mainHand | 100 | 700 crystal | 12× manaCrystalDust, 6× crystalShard, 3× elementalCore | epic | 8h |
| `battlestaff` | Battlestaff | mainHand | 150 | 500 metal | 8× manaCrystalDust, 4× metalShard, 2× elementalCore | rare | 6h |
| `arcanistCirclet` | Arcanist Circlet | head | 150 | 300 crystal | 6× manaCrystalDust, 2× crystalShard, 1× lightCrystal | rare | 4h |
| `arcanistRobe` | Arcanist Robe | body | 150 | 800 crystal | 14× manaCrystalDust, 7× crystalShard, 3× elementalCore | epic | 8h |
| `voidCatalyst` | Void Catalyst | mainHand | 200 | 600 crystal | 10× manaCrystalDust, 3× darkCrystal, 2× voidEssence, 2× elementalCore | epic | 7h |
| `arcanistPendant` | Arcanist Pendant | accessory1 | 250 | 500 crystal | 8× manaCrystalDust, 4× crystalShard, 2× elementalCore | epic | 5h |
**Advanced Wizard Gear:**
| ID | Name | Slot | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|
| `aetherRobe` | Aetherweave Robe | body | 1200 crystal | 3× aetherWeave, 15× manaCrystalDust, 8× crystalShard, 4× elementalCore | legendary | 15h |
| `aetherCirclet` | Aetherweave Circlet | head | 900 crystal | 2× aetherWeave, 10× manaCrystalDust, 3× lightCrystal, 3× elementalCore | epic | 10h |
| `voidRobe` | Voidweave Robe | body | 1200 sand | 3× voidCloth, 15× manaCrystalDust, 8× crystalShard, 3× voidEssence | legendary | 15h |
| `voidCowl` | Voidweave Cowl | head | 900 sand | 2× voidCloth, 10× manaCrystalDust, 3× darkCrystal, 2× voidEssence | epic | 10h |
| `latticeStaff` | Crystal Lattice Staff | mainHand | 2000 crystal | 2× liquidCrystalLattice, 2× aetherWeave, 2× voidCloth, 5× elementalCore | legendary | 25h |
| `latticeAmulet` | Crystal Lattice Amulet | accessory1 | 1500 crystal | 1× liquidCrystalLattice, 5× crystalCrystal, 4× elementalCore, 2× voidEssence | legendary | 18h |
### 4.6 Physical Branch (Unlock: Study Physical Equipment discipline)
| ID | Name | Slot | Unlock (XP) | Mana Cost | Materials | Rarity | Time |
|---|---|---|---|---|---|---|---|
| `crystalBlade` | Crystal Blade | mainHand | 50 | 500 crystal | 8× manaCrystalDust, 4× crystalShard, 2× elementalCore | rare | 5h |
| `arcanistBlade` | Arcanist Blade | mainHand | 100 | 600 metal | 10× manaCrystalDust, 5× metalShard, 3× elementalCore | epic | 7h |
| `voidBlade` | Void-Touched Blade | mainHand | 150 | 550 crystal | 9× manaCrystalDust, 3× darkCrystal, 2× voidEssence, 2× elementalCore | epic | 6h |
| `battleHelm` | Battle Helm | head | 200 | 350 metal | 6× manaCrystalDust, 3× metalShard, 1× elementalCore | rare | 4h |
| `battleRobe` | Battle Robe | body | 200 | 400 sand | 8× manaCrystalDust, 3× sandShard, 2× elementalCore | rare | 5h |
| `battleBoots` | Battle Boots | feet | 250 | 180 sand | 4× manaCrystalDust, 2× sandShard | uncommon | 3h |
| `combatGauntlets` | Combat Gauntlets | hands | 300 | 300 metal | 5× manaCrystalDust, 2× metalShard, 1× elementalCore | uncommon | 3h |
---
## 5. Recipe Unlock Gates
### 5.1 Study Fabricator Recipes Discipline
| XP Threshold | Recipes Unlocked |
|---|---|
| 50 | Earth gear (helm, chest, boots) |
| 100 | Metal gear (blade, shield, gloves) |
| 150 | Sand gear (boots, gloves, vest) |
| 200 | Crystal gear (wand, ring, amulet) |
### 5.2 Study Wizard Equipment Discipline
| XP Threshold | Recipes Unlocked |
|---|---|
| 50 | Oak Staff |
| 100 | Arcanist Staff |
| 150 | Battlestaff, Arcanist Circlet, Arcanist Robe |
| 200 | Void Catalyst |
| 250 | Arcanist Pendant |
| 300 | (advanced recipes via material availability) |
### 5.3 Study Physical Equipment Discipline
| XP Threshold | Recipes Unlocked |
|---|---|
| 50 | Crystal Blade |
| 100 | Arcanist Blade |
| 150 | Void Blade |
| 200 | Battle Helm, Battle Robe |
| 250 | Battle Boots |
| 300 | Combat Gauntlets |
---
## 6. Crafting Flow
### 6.1 Pre-Craft Checks
```
checkFabricatorCosts(recipe, materials, rawMana, elements):
- Verify all material counts are sufficient
- Verify mana (raw or elemental) is sufficient
- Return { canCraft, missingMana, missingMaterials }
```
### 6.2 Crafting Execution
```
executeMaterialCraft(recipe, materials):
1. Deduct mana cost from raw or elemental pool
2. Deduct input materials from inventory
3. Add resultAmount of resultMaterial to inventory
makeFabricatorProgress(recipeId, equipmentTypeId, craftTime, manaCost):
1. Create EquipmentCraftingProgress object
2. blueprintId = "fabricator-{recipeId}"
3. Progress accumulates at HOURS_PER_TICK per tick
4. On completion: create equipment instance with bonusEnchantments
```
### 6.3 Cancellation Refund
```
remainingFraction = (required - progress) / required
refundRate = remainingFraction + (1 - remainingFraction) × 0.5
manaRefund = floor(manaSpent × refundRate)
materialRefund = floor(materialsSpent × 0.5)
```
---
## 7. Crafting Efficiency Discipline Interaction
The **Crafting Efficiency** discipline provides:
| Source | Effect |
|---|---|
| Base stat bonus | `craftingCostReduction` +15 |
| Perk `efficiency-1` (once @ 300 XP) | +10% Crafting Cost Reduction |
The `craftingCostReduction` stat reduces material costs for all fabrication recipes.
Applied as: `actualCost = baseCost × (1 - craftingCostReduction / 100)`.
At maximum: 15 (base) + 10 (perk) = **25% cost reduction**.
---
## 8. How Fabricated Items Differ from Base Loot
| Property | Loot Drops | Fabricated Items |
|---|---|---|
| **Source** | Enemy drops, treasure rooms | Crafting recipes |
| **Enchantments** | None (must be enchanted) | Pre-applied `bonusEnchantments` |
| **Rarity** | Random (commonlegendary) | Fixed per recipe |
| **Quality** | Random (0100) | Fixed per recipe |
| **Stats** | Base for type | Base for type + enchantment bonuses |
| **Control** | None (random) | Full (player chooses recipe) |
Fabricated items are created with `bonusEnchantments` — pre-applied enchantment
objects with `effectId`, `stacks`, and `actualCost`. These enchantments are
permanent and cannot be removed without the Enchanter's disenchant process.
---
## 9. Equipment Types Producible via Fabrication
| Slot | Equipment Types |
|---|---|
| mainHand | Metal Blade, Crystal Focus Wand, Oak Staff, Arcanist Staff, Battlestaff, Void Catalyst, Crystal Lattice Staff |
| offHand | Metal Spell Focus |
| head | Earthen Helm, Arcanist Circlet, Aetherweave Circlet, Voidweave Cowl, Battle Helm |
| body | Stoneguard Armor, Sandcloth Vest, Arcanist Robe, Aetherweave Robe, Voidweave Robe, Battle Robe |
| hands | Metalweave Gauntlets, Sandweave Gloves, Combat Gauntlets |
| feet | Stonegreaves, Sandstrider Boots, Battle Boots |
| accessory1 | Crystal Ring, Arcanist Pendant, Crystal Lattice Amulet |
| accessory2 | Crystal Pendant |
---
## 10. Rarity Distribution
| Rarity | Count | Examples |
|---|---|---|
| common | 2 | Mana Crystal Dust, Earth Shard |
| uncommon | 14 | Earth gear, Sand gear, Oak Staff, Battle Boots, Combat Gauntlets, Mana Crystal |
| rare | 14 | Earth Chest, Metal gear, Crystal Ring/Amulet, Sand Vest, Crystal Blade, Battle Helm/Robe |
| epic | 10 | Crystal Wand, Arcanist Staff/Robe, Void Blade/Catalyst, Arcanist Pendant, Aether Circlet, Void Cowl |
| legendary | 5 | Aether Robe, Void Robe, Lattice Staff, Lattice Amulet, Liquid Crystal Lattice |
---
## 11. Acceptance Criteria
| # | Criterion |
|---|---|
| AC-1 | All 48 recipes are accessible when the Fabricator attunement is active. |
| AC-2 | Recipe unlock gates fire at the correct discipline XP thresholds. |
| AC-3 | Material crafting correctly consumes mana and input materials, producing the correct output. |
| AC-4 | Equipment crafting produces items with the correct pre-applied enchantments. |
| AC-5 | Crafting Efficiency discipline reduces material costs by the correct percentage. |
| AC-6 | Cancellation refunds mana at the blended rate (100% unspent, 50% spent) and materials at 50%. |
| AC-7 | Fabricated items cannot be crafted without the required mana type unlocked. |
| AC-8 | Material dependency chain is correct: Mana Crystal → Element Crystal → Elemental Core → Advanced Materials. |
| AC-9 | Craft time ranges from 1h (basic materials) to 25h (Crystal Lattice Staff). |
| AC-10 | Mana cost ranges from 10 (Mana Crystal Dust) to 2000 (Crystal Lattice Staff). |
---
## 12. Files Reference
| File | Role |
|---|---|
| `src/lib/game/data/fabricator-material-recipes.ts` | Material recipes (15) |
| `src/lib/game/data/fabricator-recipes.ts` | Core equipment recipes (12) |
| `src/lib/game/data/fabricator-wizard-recipes.ts` | Wizard branch recipes (14) |
| `src/lib/game/data/fabricator-physical-recipes.ts` | Physical branch recipes (7) |
| `src/lib/game/data/fabricator-recipe-types.ts` | Recipe type definitions |
| `src/lib/game/crafting-fabricator.ts` | Fabrication crafting logic |
| `src/lib/game/data/disciplines/fabricator.ts` | Fabricator disciplines (5) |
| `src/components/game/tabs/CraftingTab.tsx` | Crafting tab wrapper |
| `src/components/game/tabs/CraftingTab/FabricatorSubTab.tsx` | Fabricator crafting UI |