Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate natures with 16-bit truncation #7540

Merged
merged 2 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/mods/letsgo/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Scripts: ModdedBattleScriptsData = {
const stat = baseStats['hp'];
modStats['hp'] = Math.floor(Math.floor(2 * stat + set.ivs['hp'] + 100) * set.level / 100 + 10);
}
return this.dex.natureModify(modStats, set);
return this.natureModify(modStats, set);
},

/**
Expand Down
33 changes: 33 additions & 0 deletions sim/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,39 @@ export class Battle {
return tr((tr(value * modifier) + 2048 - 1) / 4096);
}

/** Given a table of base stats and a pokemon set, return the actual stats. */
spreadModify(baseStats: StatsTable, set: PokemonSet): StatsTable {
const modStats: SparseStatsTable = {atk: 10, def: 10, spa: 10, spd: 10, spe: 10};
const tr = this.trunc;
let statName: keyof StatsTable;
for (statName in modStats) {
const stat = baseStats[statName];
modStats[statName] = tr(tr(2 * stat + set.ivs[statName] + tr(set.evs[statName] / 4)) * set.level / 100 + 5);
}
if ('hp' in baseStats) {
const stat = baseStats['hp'];
modStats['hp'] = tr(tr(2 * stat + set.ivs['hp'] + tr(set.evs['hp'] / 4) + 100) * set.level / 100 + 10);
}
return this.natureModify(modStats as StatsTable, set);
}

natureModify(stats: StatsTable, set: PokemonSet): StatsTable {
// Natures are calculated with 16-bit truncation.
// This only affects Eternatus-Eternmax in Pure Hackmons.
const tr = this.trunc;
const nature = this.dex.getNature(set.nature);
let stat: keyof StatsTable;
if (nature.plus) {
stat = nature.plus;
stats[stat] = tr(tr(stats[stat] * 110, 16) / 100);
}
if (nature.minus) {
stat = nature.minus;
stats[stat] = tr(tr(stats[stat] * 90, 16) / 100);
}
return stats;
}

getCategory(move: string | Move) {
return this.dex.getMove(move).category || 'Physical';
}
Expand Down
30 changes: 0 additions & 30 deletions sim/dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,36 +828,6 @@ export class ModdedDex {
return nature;
}

/** Given a table of base stats and a pokemon set, return the actual stats. */
spreadModify(baseStats: StatsTable, set: PokemonSet): StatsTable {
const modStats: SparseStatsTable = {atk: 10, def: 10, spa: 10, spd: 10, spe: 10};
const tr = this.trunc;
let statName: keyof StatsTable;
for (statName in modStats) {
const stat = baseStats[statName];
modStats[statName] = tr(tr(2 * stat + set.ivs[statName] + tr(set.evs[statName] / 4)) * set.level / 100 + 5);
}
if ('hp' in baseStats) {
const stat = baseStats['hp'];
modStats['hp'] = tr(tr(2 * stat + set.ivs['hp'] + tr(set.evs['hp'] / 4) + 100) * set.level / 100 + 10);
}
return this.natureModify(modStats as StatsTable, set);
}

natureModify(stats: StatsTable, set: PokemonSet): StatsTable {
const nature = this.getNature(set.nature);
let stat: keyof StatsTable;
if (nature.plus) {
stat = nature.plus;
stats[stat] = Math.floor(stats[stat] * 1.1);
}
if (nature.minus) {
stat = nature.minus;
stats[stat] = Math.floor(stats[stat] * 0.9);
}
return stats;
}

getHiddenPower(ivs: AnyObject) {
const hpTypes = [
'Fighting', 'Flying', 'Poison', 'Ground', 'Rock', 'Bug', 'Ghost', 'Steel',
Expand Down
2 changes: 1 addition & 1 deletion sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ export class Pokemon {
this.knownType = true;
this.weighthg = species.weighthg;

const stats = this.battle.dex.spreadModify(this.species.baseStats, this.set);
const stats = this.battle.spreadModify(this.species.baseStats, this.set);
if (this.species.maxHP) stats.hp = this.species.maxHP;

if (!this.maxhp) {
Expand Down