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:44:54 -05:00
|
|
|
|
import { getDefaultLevel, findBestToolKey, parseGameArgs, resolveGuildAreaWithFallback } 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: 'pelear',
|
|
|
|
|
|
type: 'message',
|
|
|
|
|
|
aliases: ['fight','arena'],
|
|
|
|
|
|
cooldown: 8,
|
|
|
|
|
|
description: 'Entra a la arena y pelea (usa espada si está disponible).',
|
2025-10-05 19:34:45 -05:00
|
|
|
|
usage: 'pelear [nivel] [toolKey] [area:clave] (ej: pelear 1 weapon.sword.iron)',
|
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, 'fight.arena');
|
2025-10-05 01:54:12 -05:00
|
|
|
|
|
2025-10-05 19:44:54 -05:00
|
|
|
|
const { area, source } = await resolveGuildAreaWithFallback(guildId, areaKey);
|
2025-10-05 19:34:45 -05:00
|
|
|
|
if (!area) {
|
2025-10-05 19:44:54 -05:00
|
|
|
|
await message.reply(`⚠️ Área de arena no configurada. Crea \`gameArea\` con key \`${areaKey}\` en este servidor.`);
|
2025-10-05 19:34:45 -05:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-10-05 19:44:54 -05:00
|
|
|
|
const globalNotice = source === 'global'
|
|
|
|
|
|
? `ℹ️ Usando configuración global para \`${areaKey}\`. Puedes crear \`gameArea\` para personalizarla en este servidor.`
|
|
|
|
|
|
: null;
|
2025-10-05 01:54:12 -05:00
|
|
|
|
|
|
|
|
|
|
const level = levelArg ?? await getDefaultLevel(userId, guildId, area.id);
|
|
|
|
|
|
const toolKey = providedTool ?? await findBestToolKey(userId, guildId, 'sword');
|
|
|
|
|
|
|
|
|
|
|
|
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 y misiones
|
|
|
|
|
|
await updateStats(userId, guildId, { fightsCompleted: 1 });
|
|
|
|
|
|
await updateQuestProgress(userId, guildId, 'fight_count', 1);
|
|
|
|
|
|
|
|
|
|
|
|
// Contar mobs derrotados
|
|
|
|
|
|
const mobsCount = result.mobs.length;
|
|
|
|
|
|
if (mobsCount > 0) {
|
|
|
|
|
|
await updateStats(userId, guildId, { mobsDefeated: mobsCount });
|
|
|
|
|
|
await updateQuestProgress(userId, guildId, 'mob_defeat_count', mobsCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const newAchievements = await checkAchievements(userId, guildId, 'fight_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
|
|
|
|
|
2025-10-05 19:44:54 -05:00
|
|
|
|
let response = globalNotice ? `${globalNotice}\n\n` : '';
|
|
|
|
|
|
response += `⚔️ Arena (nivel ${level})\nRecompensas: ${rewards}\nEnemigos: ${mobs}\nArma: ${toolInfo}`;
|
2025-10-05 05:35:32 -05:00
|
|
|
|
|
|
|
|
|
|
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 pelear: ${e?.message ?? e}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|