feat(game-commands): add generic argument parser and integrate for mina, pelear, pescar
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { CommandMessage } from '../../../core/types/commands';
|
||||
import type Amayo from '../../../core/client';
|
||||
import { runMinigame } from '../../../game/minigames/service';
|
||||
import { resolveArea, getDefaultLevel, findBestToolKey } from './_helpers';
|
||||
import { resolveArea, getDefaultLevel, findBestToolKey, parseGameArgs } from './_helpers';
|
||||
import { updateStats } from '../../../game/stats/service';
|
||||
import { updateQuestProgress } from '../../../game/quests/service';
|
||||
import { checkAchievements } from '../../../game/achievements/service';
|
||||
@@ -12,23 +12,23 @@ export const command: CommandMessage = {
|
||||
aliases: ['fight','arena'],
|
||||
cooldown: 8,
|
||||
description: 'Entra a la arena y pelea (usa espada si está disponible).',
|
||||
usage: 'pelear [nivel] [toolKey] (ej: pelear 1 weapon.sword.iron)',
|
||||
usage: 'pelear [nivel] [toolKey] [area:clave] (ej: pelear 1 weapon.sword.iron)',
|
||||
run: async (message, args, _client: Amayo) => {
|
||||
const userId = message.author.id;
|
||||
const guildId = message.guild!.id;
|
||||
const areaKey = args[0] === 'fight.arena' ? args[0] : 'fight.arena'; // Forzar key de área de arena
|
||||
const { areaKey, levelArg, providedTool } = parseGameArgs(args, 'fight.arena');
|
||||
|
||||
const area = await resolveArea(guildId, areaKey);
|
||||
if (!area) { await message.reply('⚠️ Área de arena no configurada. Crea `gameArea` con key `fight.arena`.'); return; }
|
||||
|
||||
const levelArg = args[0] && /^\d+$/.test(args[0]) ? parseInt(args[0], 10) : null;
|
||||
const providedTool = args.find((a) => a && !/^\d+$/.test(a));
|
||||
if (!area) {
|
||||
await message.reply(`⚠️ Área de arena no configurada. Crea \`gameArea\` con key \`${areaKey}\`.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const level = levelArg ?? await getDefaultLevel(userId, guildId, area.id);
|
||||
const toolKey = providedTool ?? await findBestToolKey(userId, guildId, 'sword');
|
||||
|
||||
try {
|
||||
const result = await runMinigame(userId, guildId, areaKey, level, { toolKey: toolKey ?? undefined });
|
||||
const result = await runMinigame(userId, guildId, area.key, level, { toolKey: toolKey ?? undefined });
|
||||
|
||||
// Actualizar stats y misiones
|
||||
await updateStats(userId, guildId, { fightsCompleted: 1 });
|
||||
|
||||
Reference in New Issue
Block a user