pokemon-showdown/data/mods/letsgo/scripts.ts
urkerab b90f03b77e
Calculate natures with 16-bit truncation (#7540)
Also fixes Let's Go! which wanted to override these but couldn't.
2020-10-25 16:54:43 -07:00

56 lines
1.8 KiB
TypeScript

export const Scripts: ModdedBattleScriptsData = {
inherit: 'gen7',
init() {
this.modData('Abilities', 'noability').isNonstandard = null;
for (const i in this.data.Pokedex) {
this.modData('Pokedex', i).abilities = {0: 'No Ability'};
}
},
/**
* Given a table of base stats and a pokemon set, return the actual stats.
*/
spreadModify(baseStats, set) {
const modStats: StatsTable = {hp: 10, atk: 10, def: 10, spa: 10, spd: 10, spe: 10};
let statName: StatName;
for (statName in modStats) {
const stat = baseStats[statName];
modStats[statName] = Math.floor((Math.floor(2 * stat + set.ivs[statName]) * set.level / 100 + 5));
}
if ('hp' in baseStats) {
const stat = baseStats['hp'];
modStats['hp'] = Math.floor(Math.floor(2 * stat + set.ivs['hp'] + 100) * set.level / 100 + 10);
}
return this.natureModify(modStats, set);
},
/**
* @param {StatsTable} stats
* @param {PokemonSet} set
* @return {StatsTable}
*/
natureModify(stats, set) {
const nature = this.dex.getNature(set.nature);
if (nature.plus) stats[nature.plus] = Math.floor(stats[nature.plus] * 1.1);
if (nature.minus) stats[nature.minus] = Math.floor(stats[nature.minus] * 0.9);
set.happiness = 70;
const friendshipValue = Math.floor((set.happiness / 255 / 10 + 1) * 100);
let stat: StatName;
for (stat in stats) {
if (stat !== 'hp') {
stats[stat] = Math.floor(stats[stat] * friendshipValue / 100);
}
stats[stat] += set.evs[stat];
}
return stats;
},
pokemon: {
getWeight() {
let weighthg = this.battle.runEvent('ModifyWeight', this, null, null, this.weighthg);
if (weighthg < 1) weighthg = 1;
const weightModifierFinal = 20 * Math.random() * 0.01;
return weighthg + (weighthg * (this.battle.random(2) === 1 ? 1 : -1) * weightModifierFinal);
},
},
};