2025-10-05 01:54:12 -05:00
|
|
|
import type { CommandMessage } from '../../../core/types/commands';
|
|
|
|
|
import type Amayo from '../../../core/client';
|
|
|
|
|
import { runMinigame } from '../../../game/minigames/service';
|
2025-10-05 19:34:45 -05:00
|
|
|
import { resolveArea, getDefaultLevel, findBestToolKey, parseGameArgs } from './_helpers';
|
2025-10-05 05:35:32 -05:00
|
|
|
import { updateStats } from '../../../game/stats/service';
|
|
|
|
|
import { updateQuestProgress } from '../../../game/quests/service';
|
|
|
|
|
import { checkAchievements } from '../../../game/achievements/service';
|
2025-10-05 01:54:12 -05:00
|
|
|
|
|
|
|
|
export const command: CommandMessage = {
|
|
|
|
|
name: 'mina',
|
|
|
|
|
type: 'message',
|
|
|
|
|
aliases: ['minar'],
|
|
|
|
|
cooldown: 5,
|
|
|
|
|
description: 'Ir a la mina (usa pico si está disponible) y obtener recompensas según el nivel.',
|
2025-10-05 19:34:45 -05:00
|
|
|
usage: 'mina [nivel] [toolKey] [area:clave] (ej: mina 2 tool.pickaxe.basic)',
|
2025-10-05 01:54:12 -05:00
|
|
|
run: async (message, args, _client: Amayo) => {
|
|
|
|
|
const userId = message.author.id;
|
|
|
|
|
const guildId = message.guild!.id;
|
2025-10-05 19:34:45 -05:00
|
|
|
const { areaKey, levelArg, providedTool } = parseGameArgs(args, 'mine.cavern');
|
2025-10-05 01:54:12 -05:00
|
|
|
|
|
|
|
|
const area = await resolveArea(guildId, areaKey);
|
2025-10-05 19:34:45 -05:00
|
|
|
if (!area) {
|
|
|
|
|
await message.reply(`⚠️ Área de mina no configurada. Pide a un admin crear \`gameArea\` con key \`${areaKey}\`.`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-10-05 01:54:12 -05:00
|
|
|
|
|
|
|
|
const level = levelArg ?? await getDefaultLevel(userId, guildId, area.id);
|
|
|
|
|
const toolKey = providedTool ?? await findBestToolKey(userId, guildId, 'pickaxe');
|
|
|
|
|
|
|
|
|
|
try {
|
2025-10-05 19:34:45 -05:00
|
|
|
const result = await runMinigame(userId, guildId, area.key, level, { toolKey: toolKey ?? undefined });
|
2025-10-05 05:35:32 -05:00
|
|
|
|
|
|
|
|
// Actualizar stats
|
|
|
|
|
await updateStats(userId, guildId, { minesCompleted: 1 });
|
|
|
|
|
|
2025-10-05 19:34:45 -05:00
|
|
|
// Actualizar progreso de misiones
|
|
|
|
|
await updateQuestProgress(userId, guildId, 'mine_count', 1);
|
2025-10-05 05:35:32 -05:00
|
|
|
|
|
|
|
|
// Verificar logros
|
|
|
|
|
const newAchievements = await checkAchievements(userId, guildId, 'mine_count');
|
|
|
|
|
|
2025-10-05 01:54:12 -05:00
|
|
|
const rewards = result.rewards.map(r => r.type === 'coins' ? `🪙 +${r.amount}` : `📦 ${r.itemKey} x${r.qty}`).join(' · ') || '—';
|
|
|
|
|
const mobs = result.mobs.length ? result.mobs.join(', ') : '—';
|
|
|
|
|
const toolInfo = result.tool?.key ? `🔧 ${result.tool.key}${result.tool.broken ? ' (rota)' : ` (-${result.tool.durabilityDelta} dur.)`}` : '—';
|
2025-10-05 05:35:32 -05:00
|
|
|
|
|
|
|
|
let response = `⛏️ Mina (nivel ${level})
|
2025-10-05 01:54:12 -05:00
|
|
|
Recompensas: ${rewards}
|
|
|
|
|
Mobs: ${mobs}
|
2025-10-05 05:35:32 -05:00
|
|
|
Herramienta: ${toolInfo}`;
|
|
|
|
|
|
|
|
|
|
// Notificar logros desbloqueados
|
|
|
|
|
if (newAchievements.length > 0) {
|
|
|
|
|
response += `\n\n🏆 ¡Logro desbloqueado!`;
|
|
|
|
|
for (const ach of newAchievements) {
|
|
|
|
|
response += `\n✨ **${ach.name}** - ${ach.description}`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await message.reply(response);
|
2025-10-05 01:54:12 -05:00
|
|
|
} catch (e: any) {
|
|
|
|
|
await message.reply(`❌ No se pudo minar: ${e?.message ?? e}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|