Skip to content

Commit

Permalink
removed some duplicated code from getWeight
Browse files Browse the repository at this point in the history
  • Loading branch information
Zrp200 committed Mar 1, 2024
1 parent c24e9e8 commit 55d22fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions calc/src/mechanics/gen56.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export function calculateBasePowerBWXY(
break;
case 'Low Kick':
case 'Grass Knot':
const w = getWeight(defender, desc, true);
const w = getWeight(defender, desc, 'defender');
basePower = w >= 200 ? 120 : w >= 100 ? 100 : w >= 50 ? 80 : w >= 25 ? 60 : w >= 10 ? 40 : 20;
desc.moveBP = basePower;
break;
Expand All @@ -472,8 +472,8 @@ export function calculateBasePowerBWXY(
case 'Heavy Slam':
case 'Heat Crash':
const wr =
getWeight(attacker, desc, false) /
getWeight(defender, desc, true);
getWeight(attacker, desc, 'attacker') /
getWeight(defender, desc, 'defender');
basePower = wr >= 5 ? 120 : wr >= 4 ? 100 : wr >= 3 ? 80 : wr >= 2 ? 60 : 40;
desc.moveBP = basePower;
break;
Expand Down
6 changes: 3 additions & 3 deletions calc/src/mechanics/gen789.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ export function calculateBasePowerSMSSSV(
break;
case 'Low Kick':
case 'Grass Knot':
const w = getWeight(defender, desc, true);
const w = getWeight(defender, desc, 'defender');
basePower = w >= 200 ? 120 : w >= 100 ? 100 : w >= 50 ? 80 : w >= 25 ? 60 : w >= 10 ? 40 : 20;
desc.moveBP = basePower;
break;
Expand All @@ -733,8 +733,8 @@ export function calculateBasePowerSMSSSV(
case 'Heavy Slam':
case 'Heat Crash':
const wr =
getWeight(attacker, desc, false) /
getWeight(defender, desc, true);
getWeight(attacker, desc, 'attacker') /
getWeight(defender, desc, 'defender');
basePower = wr >= 5 ? 120 : wr >= 4 ? 100 : wr >= 3 ? 80 : wr >= 2 ? 60 : 40;
desc.moveBP = basePower;
break;
Expand Down
8 changes: 3 additions & 5 deletions calc/src/mechanics/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,22 +552,20 @@ export function getShellSideArmCategory(source: Pokemon, target: Pokemon): MoveC
return physicalDamage > specialDamage ? 'Physical' : 'Special';
}

export function getWeight(pokemon: Pokemon, desc: RawDesc, isDefender: boolean) {
export function getWeight(pokemon: Pokemon, desc: RawDesc, role: 'defender' | 'attacker') {
let factor = 1;

let abilityUsed = true;
if (pokemon.hasAbility('Heavy Metal')) factor *= 2;
else if (pokemon.hasAbility('Light Metal')) factor *= 0.5;
else abilityUsed = false;
if (abilityUsed) {
if (isDefender) desc.defenderAbility = pokemon.ability;
else desc.attackerAbility = pokemon.ability;
desc[`${role}Ability`] = pokemon.ability;
}

if (pokemon.hasItem('Float Stone')) {
factor *= 0.5;
if (isDefender) desc.defenderItem = pokemon.item;
else desc.attackerItem = pokemon.item;
desc[`${role}Item`] = pokemon.item;
}

return Math.max(Math.trunc(factor * pokemon.weightkg * 10), 1) / 10;
Expand Down

0 comments on commit 55d22fd

Please sign in to comment.