# E3.M2 — RefinementAndRecipeExecution

## Summary

| Field | Value |
|--------|--------|
| **Module ID** | E3.M2 |
| **Epic** | [Epic 3 — Crafting Economy](../epics/epic_03_crafting_economy.md) |
| **Stage target** | Prototype |
| **Status** | Planned (see [dependency register](module_dependency_register.md)) |

## Implementation snapshot

**Prep (NEO-42):** Server ships **`RefineActivitySkillXpGrant.GrantOnSuccessfulCraftOrRefine`** + **`RefineSkillXpConstants`** under `server/NeonSprawl.Server/Game/Skills/` — delegates to **`SkillProgressionGrantOperations.TryApplyGrant`** with **`refine`** + **`activity`** (prototype **10** XP), same persistence and **`allowedXpSourceKinds`** rules as **`POST …/skill-progression`**. **No** `CraftRequest` / **`CraftResult`** route yet; when this module adds authoritative craft/refine success, call that helper once on success ([NEO-42 implementation plan](../../plans/NEO-42-implementation-plan.md); [server README — Craft / refine hook (NEO-42)](../../../server/README.md#craft--refine-hook--skill-xp-neo-42)).

## Purpose

Implements the processing and crafting pipeline: raw-to-refined flows and recipe execution with server-authoritative inventory mutations. Bridges gathered materials ([E3.M1](E3_M1_ResourceNodeAndGatherLoop.md)) and item definitions ([E3.M3](E3_M3_ItemizationAndInventorySchema.md)) into usable outputs for combat, quests, and economy loops.

## Responsibilities

- Validate `CraftRequest` against `RecipeDef`, costs, and player inventory state.
- Produce `CraftResult` (success/failure, outputs, failures with reason codes).
- Support prototype recipe set (e.g. 8–12 starter recipes per epic slice minimums).

## Key contracts

| Contract | Role |
|----------|------|
| `RecipeDef` | Inputs, outputs, skill gates, station requirements (as scoped for prototype). |
| `CraftRequest` | Actor, recipe, quantities, optional targeting for UI/server sync. |
| `CraftResult` | Deterministic outcome for inventory and telemetry. |

## Module dependencies

- **E3.M1** — [ResourceNodeAndGatherLoop](E3_M1_ResourceNodeAndGatherLoop.md): refined materials from gather outputs into crafting inputs.
- **E3.M3** — [ItemizationAndInventorySchema](E3_M3_ItemizationAndInventorySchema.md): `ItemDef`, `ItemInstance`, inventory slots for costs and outputs.

## Dependents (by design)

- **E7.M1** — [QuestStateMachine](E7_M1_QuestStateMachine.md): quest steps may require crafted items or craft completion.
- **E6.M4** — [RewardParityEnforcer](E6_M4_RewardParityEnforcer.md): PvP ↔ PvE/crafting equivalents involving craft outputs.
- **Epic 2 integration** — Callers award crafting XP via [E2.M2](E2_M2_XpAwardAndLevelEngine.md) at activity sites.

## Related implementation slices

See Epic 3 **Slice 3 — Recipes and crafting pipeline**: gather → refine → item used in combat or quest; telemetry `item_crafted`, `craft_failed`, time-to-first-craft.

## Risks and telemetry

- Duplication or negative stacks: server-authoritative craft and inventory; integrity signals via E9.M4 when live.
- Quest/economy parity: lint reward bundles against E6.M4 and E3.M5 policies in later phases.

## Source anchors

- Master plan: [`neon_sprawl_vision.plan.md`](../../../neon_sprawl_vision.plan.md) — Core Epic Map, Epic 3.
- [Module dependency register](module_dependency_register.md)
