Skip to content

Commit

Permalink
Gen II: Fix damage calculation
Browse files Browse the repository at this point in the history
Moves critical hit and item modifiers to the right places
  • Loading branch information
Marty-D committed Jan 23, 2021
1 parent 3f82cb6 commit 8947808
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 10 deletions.
153 changes: 150 additions & 3 deletions data/mods/gen2/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ export const Items: {[k: string]: ModdedItemData} = {
inherit: true,
isNonstandard: null,
},
blackbelt: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Fighting') {
return damage * 1.1;
}
},
},
blackglasses: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Dark') {
return damage * 1.1;
}
},
},
brightpowder: {
inherit: true,
desc: "An attack against the holder has its accuracy out of 255 lowered by 20.",
Expand All @@ -12,16 +30,25 @@ export const Items: {[k: string]: ModdedItemData} = {
return accuracy - 20;
},
},
charcoal: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Fire') {
return damage * 1.1;
}
},
},
dragonfang: {
inherit: true,
desc: "No competitive use.",
onBasePower() {},
},
dragonscale: {
inherit: true,
onBasePower(basePower, user, target, move) {
if (move.type === 'Dragon') {
return basePower * 1.1;
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Dragon') {
return damage * 1.1;
}
},
desc: "Holder's Dragon-type attacks have 1.1x power. Evolves Seadra (trade).",
Expand All @@ -36,6 +63,15 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
hardstone: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Rock') {
return damage * 1.1;
}
},
},
kingsrock: {
inherit: true,
onModifyMove(move) {
Expand Down Expand Up @@ -69,13 +105,67 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
magnet: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Electric') {
return damage * 1.1;
}
},
},
metalcoat: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Steel') {
return damage * 1.1;
}
},
},
metalpowder: {
inherit: true,
desc: "If held by a Ditto, its Defense and Sp. Def are 1.5x, even while Transformed.",
// In Gen 2 this happens in stat calculation directly.
onModifyDef() {},
onModifySpD() {},
},
miracleseed: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Grass') {
return damage * 1.1;
}
},
},
mysticwater: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Water') {
return damage * 1.1;
}
},
},
nevermeltice: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Ice') {
return damage * 1.1;
}
},
},
poisonbarb: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Poison') {
return damage * 1.1;
}
},
},
quickclaw: {
inherit: true,
desc: "Each turn, holder has a ~23.4% chance to move first in its priority bracket.",
Expand All @@ -85,6 +175,42 @@ export const Items: {[k: string]: ModdedItemData} = {
}
},
},
sharpbeak: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Flying') {
return damage * 1.1;
}
},
},
silverpowder: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Bug') {
return damage * 1.1;
}
},
},
softsand: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Ground') {
return damage * 1.1;
}
},
},
spelltag: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Ghost') {
return damage * 1.1;
}
},
},
stick: {
inherit: true,
desc: "If held by a Farfetch\u2019d, its critical hit ratio is always at stage 2. (25% crit rate)",
Expand All @@ -100,6 +226,15 @@ export const Items: {[k: string]: ModdedItemData} = {
// In Gen 2 this happens in stat calculation directly.
onModifyAtk() {},
},
twistedspoon: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Psychic') {
return damage * 1.1;
}
},
},
berserkgene: {
inherit: true,
isNonstandard: null,
Expand Down Expand Up @@ -138,10 +273,22 @@ export const Items: {[k: string]: ModdedItemData} = {
},
pinkbow: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Normal') {
return damage * 1.1;
}
},
isNonstandard: null,
},
polkadotbow: {
inherit: true,
onBasePower() {},
onModifyDamage(damage, source, target, move) {
if (move?.type === 'Normal') {
return damage * 1.1;
}
},
isNonstandard: null,
},
przcureberry: {
Expand Down
11 changes: 4 additions & 7 deletions data/mods/gen2/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,7 @@ export const Scripts: ModdedBattleScriptsData = {
let unboosted = false;
let noburndrop = false;

// The move is a critical hit. Several things happen here.
if (isCrit) {
// Level is doubled for damage calculation.
level *= 2;
if (!suppressMessages) this.add('-crit', target);
// Stat level modifications are ignored if they are neutral to or favour the defender.
// Reflect and Light Screen defensive boosts are only ignored if stat level modifications were also ignored as a result of that.
Expand Down Expand Up @@ -622,9 +619,6 @@ export const Scripts: ModdedBattleScriptsData = {

defense = typeIndexes[attackerLastType] || 1;
level = typeIndexes[defenderLastType] || 1;
if (isCrit) {
level *= 2;
}
this.hint("Gen 2 Present has a glitched damage calculation using the secondary types of the Pokemon for the Attacker's Level and Defender's Defense.", true);
}

Expand All @@ -651,7 +645,10 @@ export const Scripts: ModdedBattleScriptsData = {
damage *= basePower;
damage *= attack;
damage = Math.floor(damage / defense);
damage = this.clampIntRange(Math.floor(damage / 50), 1, 997);
damage = Math.floor(damage / 50);
if (isCrit) damage *= 2;
damage = Math.floor(this.runEvent('ModifyDamage', attacker, defender, move, damage));
damage = this.clampIntRange(damage, 1, 997);
damage += 2;

// Weather modifiers
Expand Down

0 comments on commit 8947808

Please sign in to comment.