UNPKG

showdown-calc-cli

Version:

Quick and easy pokemon damage calulations in your terminal

53 lines (52 loc) 2.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.interactiveCalc = void 0; const inquirer_1 = __importDefault(require("inquirer")); const utils_1 = require("../utils"); const filterAbility = (input) => { if (input === 'Non-damage impacting ability') return 'Run Away'; return (0, utils_1.capitalize)(input); }; const filterItem = (input) => { if (input === 'Non-damage impacting item') return undefined; return (0, utils_1.capitalize)(input); }; const interactiveCalc = async (gen) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; try { const ans = await inquirer_1.default.prompt((0, utils_1.getDamageCalcPrompts)(gen)); const attacker = Object.assign(Object.assign({ name: ans.attackerSpecies, ability: filterAbility(ans.attackerAbility), item: filterItem(ans.attackerItem) }, gen >= 3 && { evs: { atk: (_a = ans.atkEv) !== null && _a !== void 0 ? _a : 0, spa: (_b = ans.spaEv) !== null && _b !== void 0 ? _b : 0 } }), { boosts: Object.assign({ atk: (_c = ans.atkBoost) !== null && _c !== void 0 ? _c : 0, spa: (_d = ans.spaBoost) !== null && _d !== void 0 ? _d : 0 }, gen === 1 && { spd: (_e = ans.spaBoost) !== null && _e !== void 0 ? _e : 0 }), nature: ans.attackerNature, move: ans.move }); const defender = Object.assign(Object.assign({ name: ans.defenderSpecies, ability: filterAbility(ans.defenderAbility), item: filterItem(ans.defenderItem) }, gen >= 3 && { evs: { hp: ans.hpEv, def: (_f = ans.defEv) !== null && _f !== void 0 ? _f : 0, spd: (_g = ans.spdEv) !== null && _g !== void 0 ? _g : 0 } }), { boosts: Object.assign(Object.assign({ def: (_h = ans.defBoost) !== null && _h !== void 0 ? _h : 0 }, gen === 1 && { spa: (_j = ans.spdBoost) !== null && _j !== void 0 ? _j : 0 }), { spd: (_k = ans.spdBoost) !== null && _k !== void 0 ? _k : 0 }), nature: ans.defenderNature }); const battleCondition = { weather: ans.weather, terrain: ans.terrain, isGravity: ans.otherBattleConditions.includes('Gravity'), defenderSide: { isReflect: ans.otherBattleConditions.includes('Reflect'), isLightScreen: ans.otherBattleConditions.includes('Light Screen') } }; const result = (0, utils_1.calcDamage)(attacker, defender, gen, battleCondition); (0, utils_1.displayResult)(result); } catch (err) { console.log('\nSomething went wrong, check your inputs\n'); } }; exports.interactiveCalc = interactiveCalc;