Skip to content

Chapter 41 — Crafting, Salvage & Item Transformation

Chapter 41 — Crafting, Salvage & Item Transformation

Section titled “Chapter 41 — Crafting, Salvage & Item Transformation”

Objects in AI RPG Engine can be found, tracked, and remembered — but until now, not changed. The crafting system adds salvage (items → materials), crafting (materials → items), repair, and modification — all responding to local scarcity, district mood, faction access, and item provenance.

This is not a crafting minigame. Lookup-table recipes, deterministic yield tables, and context-driven quality modifiers produce emergent item-economy feedback with zero LLM calls and negligible token overhead.


Materials use the existing 8 supply categories — no new categories. A player’s material inventory is stored in profile.custom as materials.{category}: number, following the same key-value pattern as leverage currencies (leverage.{currency}), capped at 0–50 per category.

materials.medicine: 3
materials.components: 7
materials.weapons: 2
FunctionSignatureDescription
getMaterialInventory(custom) → MaterialInventoryRead all materials.* keys into structured form
adjustMaterial(custom, category, delta) → customModify single material, clamp 0–50
applyMaterialDeltas(custom, deltas) → customApply multiple material changes atomically
hasMaterials(custom) → booleanTrue if any material > 0
FunctionDescription
formatMaterialsForDirector(inventory)Detailed multi-line view of all categories
formatMaterialsCompact(inventory)One-line status: Materials: 3 medicine, 5 components

Salvaging destroys an item and yields materials based on its slot and rarity.

SlotCommonUncommonRareLegendary
weaponcomponents×1components×2, weapons×1components×3, weapons×2components×4, weapons×3
armorcomponents×1components×2, luxuries×1components×3, luxuries×2components×4, luxuries×3
toolcomponents×2components×3components×4, fuel×1components×5, fuel×2
accessoryluxuries×1luxuries×2luxuries×2, components×1luxuries×3, components×2
trinketcomponents×1components×1, luxuries×1luxuries×2, contraband×1luxuries×3, contraband×2

Quality is derived from rarity: common → poor, uncommon → standard, rare/legendary → fine.

Provenance flags generate byproducts on salvage:

FlagByproductSide Effect
cursedoccult-residue
blessedsanctified-essence
contrabandcontraband-partsGenerates heat
stolenSuspicion if faction present in district

Salvaging a relic (tier > 0) generates a rumor claim string.

Salvaging increases the district’s supply for yielded categories by 1 per unit — the player is adding materials to the local economy.

FunctionSignatureDescription
computeSalvageYield(item) → MaterialYield[]Pure yield lookup
salvageItem(item, context?) → SalvageResultFull salvage: yields + byproducts + economy shifts
formatSalvagePreview(item, result) → stringPreview for director /salvage command

Recipes are static lookup tables — genre-aware, tag-filtered, deterministic. Three categories: craft (materials → new item), repair (materials → restore item), modify (materials → enhance/transform item).

Recipe IDCategoryInputsOutput
repair-weaponrepaircomponents×2Repair equipped weapon
repair-armorrepaircomponents×2, luxuries×1Repair equipped armor
craft-bandagecraftmedicine×2Tool (medical), common
craft-torchcraftfuel×1, components×1Tool, common
modify-sharpenmodifycomponents×1Weapon +1 attack
modify-reinforcemodifycomponents×2Armor +1 defense
GenreRecipe IDInputsNotes
fantasycraft-potionmedicine×3Healing tool
fantasymodify-blessmedicine×1Requires sacred tag
zombiecraft-improvised-weaponweapons×1, components×2Makeshift weapon
cyberpunkcraft-stimmedicine×2, components×1Combat stimulant
cyberpunkmodify-black-market-tunecontraband×2Requires black market
piratemodify-faction-markluxuries×1Requires faction access
weird-westmodify-cursecontraband×1Adds cursed flag

getAvailableRecipes(genre, playerTags?, districtTags?) returns recipes matching:

  1. Genre filter (genre-specific or universal)
  2. Required tags (e.g., sacred for bless, black market access for contraband mods)

canCraft(recipe, materials, context?) checks:

  1. Material quantities meet recipe inputs
  2. Context requirements met (black market access, faction access, district tags)

resolveCraft(recipe, context) produces a new item:

  1. Consumes materials from recipe inputs
  2. Generates output ItemDefinition fragment (slot, rarity, stat modifiers)
  3. Applies quality bonus from context
  4. Produces side effects (economy shifts, rumors, heat)
ConditionEffect
District prosperity > 60+1 to highest stat modifier
District stability > 5020% chance rarity upgrade
Black market contextAdds contraband provenance flag
Faction accessAdds factionId to provenance, origin = “Commissioned by {faction}“

resolveRepair(item, recipe, context) restores item stats toward original values. Cost scales with rarity.

resolveModify(item, recipe, context) applies a modification kind:

KindEffectProvenance
enhancement+1 stat (attack/defense)Lore append
makeshiftBasic stat boostmakeshift flag
blessedblessed flag + rumor
cursedcursed flag + rumor
black-market+2 statcontraband flag + 10 heat
faction-markfactionId + reputation

Modifications create derived ItemDefinitions — new ID = {original}-mod-{tick}. The original stays in the catalog; immutability is preserved.


Crafting actions produce CraftEffect side effects — a discriminated union:

TypeFieldsTrigger
economy-shiftdistrictId, category, delta, causeMaterial consumption shifts district supply
rumorclaim, valenceCrafting rare+ items, blessed/cursed mods
heatdeltaBlack-market modifications (+10)
reputationfactionId, deltaFaction-mark modifications (+5)
suspiciondistrictId, deltaSalvaging stolen items near faction

The crafting system adds one pressure kind:

  • Trigger: Components < 15 in any district
  • Urgency: 0.5, 8 turns
  • Resolved-by-player: Components +15, +5 reputation with local faction, rumor “restored the workshop”
  • Expired: Components −5, commerce −3

Merchant NPCs in a crafting-shortage district boost their bargain priority by +0.2 (“desperate for materials”).


craftingEfficiency (0.7–1.3) is added to DistrictModifiers:

ConditionValue
Prosperity > 60 + safety > 501.2
Safety < 300.7
Otherwise1.0

Two new actions in the strategic move recommendation engine:

ActionCategoryImpactHeat
diplomacy.negotiate-materialsdiplomacy0.50
social.commission-craftsocial0.40

Both receive +0.3 urgency boost when crafting-shortage pressure is active.


When a crafting action occurs, the narrator receives craftingContext describing the player’s modified/crafted gear. System prompt rules instruct:

  • Describe crafting through sensory detail — hammering, mixing, stitching
  • Modified items feel different — sharpened blades catch light, reinforced armor sits heavier
  • Makeshift items look improvised — rough welds, mismatched parts
  • Blessed items emanate subtle warmth; cursed items feel cold and wrong
  • Black-market modifications look dangerous — exposed wiring, volatile compounds

NPCs react to the player’s crafted/modified gear:

Gear TypeNPC Reaction
MakeshiftComment on resourcefulness, offer to improve
Faction-markedRecognition from same faction, wariness from rivals
Black-market modifiedSuspicion, threats to report, offers to buy
BlessedAwe, reverence, superstitious fear
CursedRecoil, warding gestures, warnings

CommandAction
craft <recipe-id>Craft an item from a recipe
salvage <item-name>Destroy item for materials
repair <slot>Repair equipped item in slot
modify <item> <recipe-id>Apply modification to item
CommandDescription
/craftList available recipes with can-craft status
/materialsShow current material inventory
/salvage <item-id>Preview salvage yields without executing

The CRAFTING ACTIVITY section appears in the session summary when crafting occurred:

──────────────────────────────────────────────────────────────
CRAFTING ACTIVITY
──────────────────────────────────────────────────────────────
crafted: Iron Bandage — Crafted Iron Bandage at market-square
modified: Iron Sword — Enhanced Iron Sword with modify-sharpen
Materials: medicine -2, components +3

  1. Materials = existing 8 supply categories — no new categories; salvaging a sword yields weapons + components, not “iron ingots”
  2. Materials in profile.custom — same storage pattern as leverage currencies, capped at 50
  3. Recipes are lookup tables — genre-aware + tag-filtered, ~6 universal + ~3–5 per genre, no per-pack recipe configuration
  4. Modifications create derived ItemDefinitions — preserves catalog immutability; new ID = {original}-mod-{tick}
  5. Salvage affects district economy — adding materials to local supply (+1 per unit), creating micro-economic feedback
  6. One pressure kindcrafting-shortage only; keeps pressure budget lean
  7. Quality scales with context — prosperity, stability, faction access, black market all modulate output quality
  8. Pure functions throughout — all crafting logic is deterministic, no side effects, no LLM calls
  9. ~15 token narration budget — crafting context costs negligible tokens