import {FS} from '../../lib/fs'; const DISHES_FILE = 'config/chat-plugins/thecafe-foodfight.json'; const FOODFIGHT_COOLDOWN = 5 * 60 * 1000; const thecafe = Rooms.get('thecafe') as ChatRoom; const dishes: {[k: string]: string[]} = JSON.parse(FS(DISHES_FILE).readIfExistsSync() || "{}"); function saveDishes() { void FS(DISHES_FILE).write(JSON.stringify(dishes)); } function generateTeam(generator = '') { let potentialPokemon = Object.keys(Dex.data.Pokedex).filter(mon => { const species = Dex.getSpecies(mon); return species.baseSpecies === species.name; }); let speciesClause = true; switch (generator) { case 'ou': potentialPokemon = potentialPokemon.filter(mon => { const species = Dex.getSpecies(mon); return species.tier === 'OU'; }).concat(potentialPokemon.filter(mon => { // There is probably a better way to get the ratios right, oh well. const species = Dex.getSpecies(mon); return species.tier === 'OU' || species.tier === 'UU'; })); break; case 'ag': potentialPokemon = potentialPokemon.filter(mon => { const species = Dex.getSpecies(mon); const unviable = species.tier === 'NFE' || species.tier === 'PU' || species.tier === '(PU)' || species.tier.startsWith("LC"); const illegal = species.tier === 'Unreleased' || species.tier === 'Illegal' || species.tier.startsWith("CAP"); return !(unviable || illegal); }); speciesClause = false; break; default: potentialPokemon = potentialPokemon.filter(mon => { const species = Dex.getSpecies(mon); const op = species.tier === 'AG' || species.tier === 'Uber' || species.tier.slice(1, -1) === 'Uber'; const unviable = species.tier === 'Illegal' || species.tier.includes("LC"); return !(op || unviable); }); potentialPokemon.push('miltank', 'miltank', 'miltank', 'miltank'); // 5x chance for miltank for flavor purposes. } const team: string[] = []; while (team.length < 6) { const randIndex = Math.floor(Math.random() * potentialPokemon.length); const potentialMon = potentialPokemon[randIndex]; if (team.includes(potentialMon)) continue; team.push(potentialMon); if (speciesClause) potentialPokemon.splice(randIndex, 1); } return team.map(mon => Dex.getSpecies(mon).name); } function generateDish(): [string, string[]] { const keys = Object.keys(dishes); const entry = dishes[keys[Math.floor(Math.random() * keys.length)]].slice(); const dish = entry.splice(0, 1)[0]; const ingredients = []; while (ingredients.length < 6) { ingredients.push(entry.splice(Math.floor(Math.random() * entry.length), 1)[0]); } return [dish, ingredients]; } export const commands: ChatCommands = { foodfight(target, room, user) { room = this.requireRoom(thecafe.roomid); if (!Object.keys(dishes).length) return this.errorReply("No dishes found. Add some dishes first."); if (user.foodfight && user.foodfight.timestamp + FOODFIGHT_COOLDOWN > Date.now()) { return this.errorReply("Please wait a few minutes before using this command again."); } target = toID(target); let team: string[] = []; let importable; const [newDish, newIngredients] = generateDish(); if (!target) { const bfTeam = Dex.generateTeam('gen7bssfactory'); importable = Dex.stringifyTeam(bfTeam, newIngredients); team = bfTeam.map(val => val.species); } else { team = generateTeam(target); } user.foodfight = {generatedTeam: team, dish: newDish, ingredients: newIngredients, timestamp: Date.now()}; const importStr = importable ? `
| Your dish is: ${newDish} | ||||||
|---|---|---|---|---|---|---|
| Team | ${team.map(mon => `||||||
| Ingredients | ${newIngredients.map(ingredient => `${ingredient} | `).join('')}|||||
| ${self ? `Your` : `${this.targetUsername}'s`} dish is: ${targetUser.foodfight.dish} | ||||||
|---|---|---|---|---|---|---|
| Team | ${targetUser.foodfight.generatedTeam.map(mon => `||||||
| Ingredients | ${targetUser.foodfight.ingredients.map(ingredient => `${ingredient} | `).join('')}|||||
Access denied
There are no dishes in the database.
`; } else { buf += `Dishes | Ingredients |
|---|