diff --git a/src/systems/VillagerSystem.ts b/src/systems/VillagerSystem.ts index f6eb302..68efa98 100644 --- a/src/systems/VillagerSystem.ts +++ b/src/systems/VillagerSystem.ts @@ -1,5 +1,6 @@ import Phaser from 'phaser' import { TILE_SIZE, VILLAGER_SPEED, VILLAGER_SPAWN_INTERVAL, VILLAGER_WORK_TIMES, VILLAGER_NAMES } from '../config' +import { TileType } from '../types' import type { VillagerState, VillagerJob, JobType, AIState, ItemId } from '../types' import { stateManager } from '../StateManager' import { findPath } from '../utils/pathfinding' @@ -200,13 +201,19 @@ export class VillagerSystem { const state = stateManager.getState() if (job.type === 'chop') { - if (state.world.resources[job.targetId]) { + const res = state.world.resources[job.targetId] + if (res) { this.adapter.send({ type: 'VILLAGER_HARVEST_RESOURCE', villagerId: v.id, resourceId: job.targetId }) + // Clear the FOREST tile so the area becomes passable for future pathfinding + this.adapter.send({ type: 'CHANGE_TILE', tileX: res.tileX, tileY: res.tileY, tile: TileType.DARK_GRASS }) this.resourceSystem.removeResource(job.targetId) } } else if (job.type === 'mine') { - if (state.world.resources[job.targetId]) { + const res = state.world.resources[job.targetId] + if (res) { this.adapter.send({ type: 'VILLAGER_HARVEST_RESOURCE', villagerId: v.id, resourceId: job.targetId }) + // Clear the ROCK tile so the area becomes passable for future pathfinding + this.adapter.send({ type: 'CHANGE_TILE', tileX: res.tileX, tileY: res.tileY, tile: TileType.GRASS }) this.resourceSystem.removeResource(job.targetId) } } else if (job.type === 'farm') {