fix ?
This commit is contained in:
@@ -17,13 +17,13 @@ let lastKnownBotSettings = {};
|
||||
// ----------------------------------------------------------------
|
||||
// botLog — sends a log entry to the server
|
||||
// ----------------------------------------------------------------
|
||||
async function botLog(player_id, feature, message) {
|
||||
async function botLog(player_id, world_id, feature, message) {
|
||||
log(`[${feature}] ${message}`);
|
||||
try {
|
||||
await apiFetch(`${BASE_URL}/api/bot-logs`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ player_id, feature, message })
|
||||
body: JSON.stringify({ player_id, world_id, feature, message })
|
||||
});
|
||||
} catch (e) { /* non-critical */ }
|
||||
}
|
||||
@@ -38,7 +38,8 @@ async function autoBootcampLoop() {
|
||||
if (!settings.bootcamp_enabled) return;
|
||||
|
||||
const player_id = uw.Game?.player_id;
|
||||
if (!player_id) return;
|
||||
const world_id = uw.Game?.world_id;
|
||||
if (!player_id || !world_id) return;
|
||||
|
||||
let model;
|
||||
try {
|
||||
@@ -67,7 +68,7 @@ async function autoBootcampLoop() {
|
||||
action_name: 'useReward',
|
||||
arguments: {}
|
||||
});
|
||||
await botLog(player_id, 'bootcamp', `Reward used: ${reward.power_id}`);
|
||||
await botLog(player_id, world_id, 'bootcamp', 'Διεκδίκηση αμοιβής ληστών...');
|
||||
} else if (stashable) {
|
||||
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||
model_url: `PlayerAttackSpot/${player_id}`,
|
||||
@@ -75,7 +76,7 @@ async function autoBootcampLoop() {
|
||||
arguments: {}
|
||||
}, 0, {
|
||||
success: () => {
|
||||
botLog(player_id, 'bootcamp', `Reward stashed: ${reward.power_id}`);
|
||||
botLog(player_id, world_id, 'bootcamp', `Reward stashed: ${reward.power_id}`);
|
||||
},
|
||||
error: () => {
|
||||
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', {
|
||||
@@ -83,7 +84,7 @@ async function autoBootcampLoop() {
|
||||
action_name: 'useReward',
|
||||
arguments: {}
|
||||
});
|
||||
botLog(player_id, 'bootcamp', `Reward used (inventory full fallback): ${reward.power_id}`);
|
||||
botLog(player_id, world_id, 'bootcamp', 'Αποτυχία διεκδίκησης αμοιβής.');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -92,7 +93,7 @@ async function autoBootcampLoop() {
|
||||
action_name: 'useReward',
|
||||
arguments: {}
|
||||
});
|
||||
await botLog(player_id, 'bootcamp', `Reward used (fallback): ${reward.power_id}`);
|
||||
await botLog(player_id, world_id, 'bootcamp', `Reward used (fallback): ${reward.power_id}`);
|
||||
}
|
||||
await sleep(randInt(3000, 7000));
|
||||
return; // Wait for next cycle to attack
|
||||
@@ -110,7 +111,7 @@ async function autoBootcampLoop() {
|
||||
const cooldown = model.getCooldownDuration();
|
||||
if (cooldown > 0) {
|
||||
const minRemaining = Math.round(cooldown / 60);
|
||||
await botLog(player_id, 'bootcamp', `Camp on cooldown — ${minRemaining} min remaining`);
|
||||
await botLog(player_id, world_id, 'bootcamp', `Camp on cooldown — ${minRemaining} min remaining`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@ async function autoBootcampLoop() {
|
||||
if (movements) {
|
||||
for (const mv of Object.values(movements)) {
|
||||
if (mv.attributes.destination_is_attack_spot || mv.attributes.origin_is_attack_spot) {
|
||||
await botLog(player_id, 'bootcamp', 'Attack already in flight — skipping');
|
||||
await botLog(player_id, world_id, 'bootcamp', 'Attack already in flight — skipping');
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -152,7 +153,7 @@ async function autoBootcampLoop() {
|
||||
}
|
||||
|
||||
if (Object.keys(units).length === 0) {
|
||||
await botLog(player_id, 'bootcamp', 'No available units — skipping attack');
|
||||
await botLog(player_id, world_id, 'bootcamp', 'No available units — skipping attack. (Χωρίς αμυντικά)');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -163,10 +164,10 @@ async function autoBootcampLoop() {
|
||||
});
|
||||
|
||||
const unitSummary = Object.entries(units).map(([u, n]) => `${n}x${u}`).join(', ');
|
||||
await botLog(player_id, 'bootcamp', `Attack sent — ${unitSummary}`);
|
||||
await botLog(player_id, world_id, 'bootcamp', `Στέλνω ${JSON.stringify(units)} στο camp...`);
|
||||
|
||||
} catch (e) {
|
||||
await botLog(player_id, 'bootcamp', `Error during attack: ${e}`);
|
||||
await botLog(player_id, world_id, 'bootcamp', `Error during attack: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +188,8 @@ async function autoRuralTradeLoop() {
|
||||
if (!settings.rural_trade_enabled) return;
|
||||
|
||||
const player_id = uw.Game?.player_id;
|
||||
if (!player_id) return;
|
||||
const world_id = uw.Game?.world_id;
|
||||
if (!player_id || !world_id) return;
|
||||
|
||||
const minRatio = RATIO_MAP[settings.rural_trade_ratio] ?? 0.75;
|
||||
|
||||
@@ -285,12 +287,12 @@ async function autoRuralTradeLoop() {
|
||||
arguments: { farm_town_id: farm.attributes.id, amount },
|
||||
town_id: parseInt(town_id_str)
|
||||
});
|
||||
await botLog(player_id, 'rural_trade',
|
||||
await botLog(player_id, world_id, 'rural_trade',
|
||||
`Traded ${amount} ${missingResource} ← ${farm.attributes.name} via ${town_obj.getName?.() ?? town_id_str}`);
|
||||
tradesTotal++;
|
||||
tradeMade = true;
|
||||
} catch (e) {
|
||||
await botLog(player_id, 'rural_trade', `Trade error: ${e}`);
|
||||
await botLog(player_id, world_id, 'rural_trade', `Trade error: ${e}`);
|
||||
}
|
||||
|
||||
await sleep(randInt(800, 1800));
|
||||
@@ -300,7 +302,7 @@ async function autoRuralTradeLoop() {
|
||||
}
|
||||
|
||||
if (!tradeMade && missingResource) {
|
||||
await botLog(player_id, 'rural_trade',
|
||||
await botLog(player_id, world_id, 'rural_trade',
|
||||
`${town_obj.getName?.() ?? town_id_str} needs ${missingResource} but no suitable village found`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user