fix: emit desire_fulfilled events, populate LLM context, fix category scoring
- desireFulfillmentSystem records memory events when desires are fulfilled - desireGeneratorSystem populates recentEvents and recentInventions template vars - industrySystem own_item_category scoring now checks recipe output category Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,10 +9,11 @@ import type { CraftingState } from './craftingSystem.js';
|
||||
import type { BuildingState, StructureData } from './buildingSystem.js';
|
||||
import type { PickupState } from './pickupSystem.js';
|
||||
import { RecipeRegistry, type Recipe } from '../industry/recipeRegistry.js';
|
||||
import { ItemRegistry } from '../industry/itemRegistry.js';
|
||||
import { getEffectiveStat } from './statHelpers.js';
|
||||
import { industryConfig } from '../config/industryConfig.js';
|
||||
|
||||
function scoreCraftableRecipes(recipes: Recipe[], desires: Desire[]): Recipe {
|
||||
function scoreCraftableRecipes(recipes: Recipe[], desires: Desire[], itemRegistry?: ItemRegistry): Recipe {
|
||||
if (recipes.length === 1 || desires.length === 0) return recipes[0];
|
||||
|
||||
let bestRecipe = recipes[0];
|
||||
@@ -24,8 +25,11 @@ function scoreCraftableRecipes(recipes: Recipe[], desires: Desire[]): Recipe {
|
||||
const f = desire.fulfillment;
|
||||
if (f.type === 'own_item' && f.itemId === recipe.outputItemId) {
|
||||
score += desire.priority * 10;
|
||||
} else if (f.type === 'own_item_category') {
|
||||
score += desire.priority * 5;
|
||||
} else if (f.type === 'own_item_category' && itemRegistry) {
|
||||
const outputDef = itemRegistry.get(recipe.outputItemId);
|
||||
if (outputDef && outputDef.category === f.category) {
|
||||
score += desire.priority * 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (score > bestScore) {
|
||||
@@ -91,7 +95,8 @@ export function industrySystem(world: World, map: GameMap): void {
|
||||
const craftRecipes = registry.findCraftable(inv).filter(r => !r.id.startsWith('build_'));
|
||||
if (craftRecipes.length > 0) {
|
||||
const desires = world.getComponent<Desire[]>(entity, 'desires') ?? [];
|
||||
const recipe = scoreCraftableRecipes(craftRecipes, desires);
|
||||
const itemRegistry = world.getSingleton<ItemRegistry>('itemRegistry');
|
||||
const recipe = scoreCraftableRecipes(craftRecipes, desires, itemRegistry);
|
||||
const dex = getEffectiveStat(world, entity, 'dexterity');
|
||||
const baseTicks = industryConfig.craftBaseTicks;
|
||||
const ticks = Math.max(1, Math.round(baseTicks * (1 - (dex - 10) * industryConfig.craftDexterityModifier)));
|
||||
|
||||
Reference in New Issue
Block a user