49 lines
No EOL
1.4 KiB
JavaScript
49 lines
No EOL
1.4 KiB
JavaScript
// states/Observe.js
|
|
const { getBot, getActiveTask, isCombatLocked, getStateMachine } = require('../core/context');
|
|
const logSurroundings = require('../lib/log-surroundings');
|
|
const { chatWithAI } = require('../lib/ai-helper');
|
|
const config = require('../config.json');
|
|
|
|
module.exports = async function Observe() {
|
|
const bot = getBot();
|
|
|
|
if (getActiveTask() || isCombatLocked()) {
|
|
console.log('[OBSERVE] Skipping — locked by task or combat.');
|
|
return;
|
|
}
|
|
|
|
console.log('[STATE] Observe');
|
|
|
|
// Example: count nearby entities. I will need to add way more to this observe file later.
|
|
const entities = Object.values(bot.entities).filter(e => e.type === 'mob');
|
|
if (entities.length > 0) {
|
|
context.setCombatLock(true);
|
|
bot.chat(`Noticed ${entities.length} mob(s), engaging...`);
|
|
|
|
const mob = entities[0];
|
|
bot.attack(mob);
|
|
|
|
bot.once('death', () => {
|
|
context.setCombatLock(false);
|
|
bot.chat("I died. Lock released.");
|
|
});
|
|
|
|
const checkClear = setInterval(() => {
|
|
const remaining = Object.values(bot.entities).filter(e => e.type === 'mob');
|
|
if (remaining.length === 0) {
|
|
context.setCombatLock(false);
|
|
clearInterval(checkClear);
|
|
bot.chat("Area is clear.");
|
|
}
|
|
}, 3000);
|
|
|
|
return; // skip rest of Observe state
|
|
}
|
|
|
|
await logSurroundings();
|
|
|
|
setTimeout(() => {
|
|
getStateMachine().transition('Idle');
|
|
}, 10000);
|
|
|
|
}; |