mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-08-28 03:56:35 -05:00
Refactor some code to use randomChance
Mechanically refactor code which uses PRNG#random for booleans to use
PRNG#randomChance instead.
Take advantage of the following properties:
random(x) < y is equivalent to randomChance(y, x)
random(x) <= y is equivalent to random(x) < (y + 1), i.e. randomChance(y + 1, x)
random(x) >= y is equivalent to !(random(x) < y), i.e. !randomChance(y, x)
random(x) > y is equivalent to random(x) >= (y + 1), i.e. !randomChance(y + 1, x)
random(x) === 0 is equivalent to random(x) < 1, i.e. randomChance(1, x)
!random(x) is equivalent to random(x) === 0, i.e. randomChance(1, x)
Boolean(random(x)) is equivalent to random(x) > 0, i.e. !randomChance(1, x)
This commit should not change behaviour. In particular, PRNG#next is
called the same number of times with the same number of parameter as
before this commit, and PRNG#next's results are interpreted in the same
way as before this commit.
This commit is contained in:
committed by
Guangcong Luo
parent
45a876917d
commit
df5988bacf
@@ -1133,12 +1133,12 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
let ability1 = this.getAbility(abilities[1]);
|
||||
let ability2 = this.getAbility(abilities[2]);
|
||||
if (abilities[1]) {
|
||||
if (abilities[2] && ability1.rating <= ability2.rating && this.random(2)) {
|
||||
if (abilities[2] && ability1.rating <= ability2.rating && !this.randomChance(1, 2)) {
|
||||
[ability1, ability2] = [ability2, ability1];
|
||||
}
|
||||
if (ability0.rating <= ability1.rating && this.random(2)) {
|
||||
if (ability0.rating <= ability1.rating && !this.randomChance(1, 2)) {
|
||||
[ability0, ability1] = [ability1, ability0];
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating && this.random(3)) {
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating && !this.randomChance(1, 3)) {
|
||||
[ability0, ability1] = [ability1, ability0];
|
||||
}
|
||||
ability = ability0.name;
|
||||
@@ -1261,7 +1261,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
ability = 'Pickup';
|
||||
} else if (template.baseSpecies === 'Basculin') {
|
||||
ability = 'Adaptability';
|
||||
} else if (template.species === 'Lopunny' && hasMove['switcheroo'] && this.random(3)) {
|
||||
} else if (template.species === 'Lopunny' && hasMove['switcheroo'] && !this.randomChance(1, 3)) {
|
||||
ability = 'Klutz';
|
||||
} else if ((template.species === 'Rampardos' && !hasMove['headsmash']) || hasMove['rockclimb']) {
|
||||
ability = 'Sheer Force';
|
||||
@@ -1340,7 +1340,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
// To perma-taunt a Pokemon by giving it Assault Vest
|
||||
item = 'Assault Vest';
|
||||
} else if (hasMove['switcheroo'] || hasMove['trick']) {
|
||||
let randomNum = this.random(3);
|
||||
let randomNum = !this.randomChance(1, 3);
|
||||
if (counter.Physical >= 3 && (template.baseStats.spe < 60 || template.baseStats.spe > 108 || randomNum)) {
|
||||
item = 'Choice Band';
|
||||
} else if (counter.Special >= 3 && (template.baseStats.spe < 60 || template.baseStats.spe > 108 || randomNum)) {
|
||||
@@ -1363,7 +1363,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
} else if (hasMove['bellydrum']) {
|
||||
if (ability === 'Gluttony') {
|
||||
item = ['Aguav', 'Figy', 'Iapapa', 'Mago', 'Wiki'][this.random(5)] + ' Berry';
|
||||
} else if (template.baseStats.spe <= 50 && !teamDetails.zMove && this.random(2)) {
|
||||
} else if (template.baseStats.spe <= 50 && !teamDetails.zMove && !this.randomChance(1, 2)) {
|
||||
item = 'Normalium Z';
|
||||
} else {
|
||||
item = 'Sitrus Berry';
|
||||
@@ -1401,10 +1401,10 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
} else if (template.baseStats.spe <= 50 && hasMove['sleeppowder'] && counter.setupType && !teamDetails.zMove) {
|
||||
item = 'Grassium Z';
|
||||
} else if (counter.Physical >= 4 && !hasMove['bodyslam'] && !hasMove['dragontail'] && !hasMove['fakeout'] && !hasMove['flamecharge'] && !hasMove['rapidspin'] && !hasMove['suckerpunch']) {
|
||||
item = template.baseStats.atk >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && this.random(3) ? 'Choice Scarf' : 'Choice Band';
|
||||
item = template.baseStats.atk >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !this.randomChance(1, 3) ? 'Choice Scarf' : 'Choice Band';
|
||||
} else if (counter.Special >= 4 && !hasMove['acidspray'] && !hasMove['chargebeam'] && !hasMove['clearsmog'] && !hasMove['fierydance']) {
|
||||
item = template.baseStats.spa >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && this.random(3) ? 'Choice Scarf' : 'Choice Specs';
|
||||
} else if (((counter.Physical >= 3 && hasMove['defog']) || (counter.Special >= 3 && hasMove['uturn'])) && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && this.random(3)) {
|
||||
item = template.baseStats.spa >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !this.randomChance(1, 3) ? 'Choice Scarf' : 'Choice Specs';
|
||||
} else if (((counter.Physical >= 3 && hasMove['defog']) || (counter.Special >= 3 && hasMove['uturn'])) && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !this.randomChance(1, 3)) {
|
||||
item = 'Choice Scarf';
|
||||
} else if (ability === 'Defeatist' || hasMove['eruption'] || hasMove['waterspout']) {
|
||||
item = counter.Status <= 1 ? 'Expert Belt' : 'Leftovers';
|
||||
@@ -1420,7 +1420,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
item = 'Leftovers';
|
||||
} else if (hasMove['substitute']) {
|
||||
item = !counter['drain'] || counter.damagingMoves.length < 2 ? 'Leftovers' : 'Life Orb';
|
||||
} else if ((ability === 'Iron Barbs' || ability === 'Rough Skin') && this.random(2)) {
|
||||
} else if ((ability === 'Iron Barbs' || ability === 'Rough Skin') && !this.randomChance(1, 2)) {
|
||||
item = 'Rocky Helmet';
|
||||
} else if (counter.Physical + counter.Special >= 4 && template.baseStats.spd >= 65 && template.baseStats.hp + template.baseStats.def + template.baseStats.spd >= 235) {
|
||||
item = 'Assault Vest';
|
||||
@@ -1729,7 +1729,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
species = template.baseSpecies;
|
||||
}
|
||||
let battleForme = this.checkBattleForme(template);
|
||||
if (battleForme && (battleForme.isMega ? !teamDetails.megaStone : this.random(2))) {
|
||||
if (battleForme && (battleForme.isMega ? !teamDetails.megaStone : !this.randomChance(1, 2))) {
|
||||
template = this.getTemplate(template.otherFormes.length >= 2 ? template.otherFormes[this.random(template.otherFormes.length)] : template.otherFormes[0]);
|
||||
}
|
||||
|
||||
@@ -2183,10 +2183,10 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
ability = ability0.name;
|
||||
if (abilities[1]) {
|
||||
if (abilities[2] && ability2.rating === ability1.rating) {
|
||||
if (this.random(2)) ability1 = ability2;
|
||||
if (!this.randomChance(1, 2)) ability1 = ability2;
|
||||
}
|
||||
if (ability0.rating <= ability1.rating) {
|
||||
if (this.random(2)) ability = ability1.name;
|
||||
if (!this.randomChance(1, 2)) ability = ability1.name;
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating) {
|
||||
if (this.randomChance(1, 3)) ability = ability1.name;
|
||||
}
|
||||
@@ -2328,7 +2328,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
} else if (template.species === 'Unown') {
|
||||
item = 'Choice Specs';
|
||||
} else if (hasMove['trick'] || hasMove['switcheroo']) {
|
||||
let randomNum = this.random(2);
|
||||
let randomNum = !this.randomChance(1, 2);
|
||||
if (counter.Physical >= 3 && (template.baseStats.spe >= 95 || randomNum)) {
|
||||
item = 'Choice Band';
|
||||
} else if (counter.Special >= 3 && (template.baseStats.spe >= 95 || randomNum)) {
|
||||
@@ -2339,7 +2339,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
} else if (ability === 'Gluttony' || ability === 'Schooling') {
|
||||
item = ['Aguav', 'Figy', 'Iapapa', 'Mago', 'Wiki'][this.random(5)] + ' Berry';
|
||||
} else if (hasMove['bellydrum']) {
|
||||
if (template.baseStats.spe <= 50 && !teamDetails.zMove && this.random(2)) {
|
||||
if (template.baseStats.spe <= 50 && !teamDetails.zMove && !this.randomChance(1, 2)) {
|
||||
item = 'Normalium Z';
|
||||
} else {
|
||||
item = 'Sitrus Berry';
|
||||
@@ -2536,7 +2536,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
ivs: ivs,
|
||||
item: item,
|
||||
level: level,
|
||||
shiny: !this.random(template.id === 'missingno' ? 4 : 1024),
|
||||
shiny: this.randomChance(1, template.id === 'missingno' ? 4 : 1024),
|
||||
};
|
||||
}
|
||||
randomFactorySet(template, slot, teamData, tier) {
|
||||
@@ -2625,7 +2625,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
return {
|
||||
name: setData.set.name || template.baseSpecies,
|
||||
species: setData.set.species,
|
||||
gender: setData.set.gender || template.gender || (this.random(2) ? 'M' : 'F'),
|
||||
gender: setData.set.gender || template.gender || (!this.randomChance(1, 2) ? 'M' : 'F'),
|
||||
item: items + '' || setData.set.item || '',
|
||||
ability: abilities + '' || setData.set.ability || template.abilities['0'],
|
||||
shiny: typeof setData.set.shiny === 'undefined' ? this.randomChance(1, 1024) : setData.set.shiny,
|
||||
@@ -2691,7 +2691,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
// If not Monotype, limit to two of each type
|
||||
let skip = false;
|
||||
for (let t = 0; t < types.length; t++) {
|
||||
if (teamData.typeCount[types[t]] > 1 && this.random(5)) {
|
||||
if (teamData.typeCount[types[t]] > 1 && !this.randomChance(1, 5)) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
@@ -2849,7 +2849,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
return {
|
||||
name: setData.set.name || template.baseSpecies,
|
||||
species: setData.set.species,
|
||||
gender: setData.set.gender || template.gender || (this.random(2) ? 'M' : 'F'),
|
||||
gender: setData.set.gender || template.gender || (!this.randomChance(1, 2) ? 'M' : 'F'),
|
||||
item: setData.set.item || '',
|
||||
ability: setData.set.ability || template.abilities['0'],
|
||||
shiny: typeof setData.set.shiny === 'undefined' ? this.randomChance(1, 1024) : setData.set.shiny,
|
||||
@@ -2903,7 +2903,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
let types = template.types;
|
||||
let skip = false;
|
||||
for (let t = 0; t < types.length; t++) {
|
||||
if (teamData.typeCount[types[t]] > 1 && this.random(5)) {
|
||||
if (teamData.typeCount[types[t]] > 1 && !this.randomChance(1, 5)) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
@@ -3062,7 +3062,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
return {
|
||||
name: setData.set.nickname || setData.set.name || template.baseSpecies,
|
||||
species: setData.set.species,
|
||||
gender: setData.set.gender || template.gender || (this.random(2) ? 'M' : 'F'),
|
||||
gender: setData.set.gender || template.gender || (!this.randomChance(1, 2) ? 'M' : 'F'),
|
||||
item: setData.set.item || '',
|
||||
ability: setData.set.ability || template.abilities['0'],
|
||||
shiny: typeof setData.set.shiny === 'undefined' ? this.randomChance(1, 1024) : setData.set.shiny,
|
||||
@@ -3112,7 +3112,7 @@ class RandomTeams extends Dex.ModdedDex {
|
||||
let types = template.types;
|
||||
let skip = false;
|
||||
for (let t = 0; t < types.length; t++) {
|
||||
if (teamData.typeCount[types[t]] > 1 && this.random(5)) {
|
||||
if (teamData.typeCount[types[t]] > 1 && !this.randomChance(1, 5)) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ exports.BattleScripts = {
|
||||
} else {
|
||||
accuracy = this.runEvent('Accuracy', target, pokemon, move, accuracy);
|
||||
}
|
||||
if (accuracy !== true && this.random(100) >= accuracy) {
|
||||
if (accuracy !== true && !this.randomChance(accuracy, 100)) {
|
||||
if (!move.spreadHit) this.attrLastMove('[miss]');
|
||||
this.add('-miss', pokemon, target);
|
||||
return false;
|
||||
@@ -516,7 +516,7 @@ exports.BattleScripts = {
|
||||
accuracy = this.runEvent('ModifyAccuracy', target, pokemon, move, accuracy);
|
||||
if (!move.alwaysHit) {
|
||||
accuracy = this.runEvent('Accuracy', target, pokemon, move, accuracy);
|
||||
if (accuracy !== true && this.random(100) >= accuracy) break;
|
||||
if (accuracy !== true && !this.randomChance(accuracy, 100)) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ exports.BattleStatuses = {
|
||||
return;
|
||||
}
|
||||
this.add('-activate', pokemon, 'confusion');
|
||||
if (this.random(3) > 0) {
|
||||
if (!this.randomChance(1, 3)) {
|
||||
return;
|
||||
}
|
||||
this.activeTarget = pokemon;
|
||||
@@ -404,7 +404,7 @@ exports.BattleStatuses = {
|
||||
// However, just in case, use 1 if it is undefined.
|
||||
let counter = this.effectData.counter || 1;
|
||||
this.debug("Success chance: " + Math.round(100 / counter) + "%");
|
||||
return (this.random(counter) === 0);
|
||||
return this.randomChance(1, counter);
|
||||
},
|
||||
onRestart: function () {
|
||||
if (this.effectData.counter < this.effect.counterMax) {
|
||||
|
||||
@@ -168,7 +168,7 @@ class RandomGen1Teams extends RandomGen2Teams {
|
||||
// Limit 2 of any type as well. Diversity and minor weakness count.
|
||||
// The second of a same type has halved chance of being added.
|
||||
for (const type of template.types) {
|
||||
if (typeCount[type] > 1 || (typeCount[type] === 1 && this.random(2) && pokemonPool.length > 1)) {
|
||||
if (typeCount[type] > 1 || (typeCount[type] === 1 && !this.randomChance(1, 2) && pokemonPool.length > 1)) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ exports.BattleScripts = {
|
||||
if (move.target === 'self' && accuracy !== true) accuracy++;
|
||||
|
||||
// 1/256 chance of missing always, no matter what. Besides the aforementioned exceptions.
|
||||
if (accuracy !== true && this.random(256) >= accuracy) {
|
||||
if (accuracy !== true && !this.randomChance(accuracy, 256)) {
|
||||
this.attrLastMove('[miss]');
|
||||
this.add('-miss', pokemon);
|
||||
damage = false;
|
||||
@@ -571,7 +571,7 @@ exports.BattleScripts = {
|
||||
// If a move that was not fire-type would exist on Gen 1, it could burn a Pokémon.
|
||||
if (!(secondary.status && ['par', 'brn', 'frz'].includes(secondary.status) && target && target.hasType(move.type))) {
|
||||
let effectChance = Math.ceil(secondary.chance * 256 / 100);
|
||||
if (typeof secondary.chance === 'undefined' || this.random(256) < effectChance) {
|
||||
if (typeof secondary.chance === 'undefined' || this.randomChance(effectChance, 256)) {
|
||||
this.moveHit(target, pokemon, move, secondary, true, isSelf);
|
||||
}
|
||||
}
|
||||
@@ -832,7 +832,7 @@ exports.BattleScripts = {
|
||||
// We compare our critical hit chance against a random number between 0 and 255.
|
||||
// If the random number is lower, we get a critical hit. This means there is always a 1/255 chance of not hitting critically.
|
||||
if (critChance > 0) {
|
||||
move.crit = (this.random(256) < critChance);
|
||||
move.crit = this.randomChance(critChance, 256);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ exports.BattleStatuses = {
|
||||
return (this.random() * 4294967296 < 1);
|
||||
}
|
||||
this.debug("Success chance: " + Math.round(100 / counter) + "%");
|
||||
return (this.random(counter) === 0);
|
||||
return this.randomChance(1, counter);
|
||||
},
|
||||
onRestart: function () {
|
||||
if (this.effectData.counter < this.effect.counterMax) {
|
||||
|
||||
@@ -56,7 +56,7 @@ class RandomGen2Teams extends RandomGen3Teams {
|
||||
if (typeCount[types[0]] && this.randomChance(1, 3)) skip = true;
|
||||
} else if (types.length === 2) {
|
||||
if (typeCount[types[0]] > 1 || typeCount[types[1]] > 1) skip = true;
|
||||
if (typeCount[types[0]] && typeCount[types[1]] && this.random(3) > 0) skip = true;
|
||||
if (typeCount[types[0]] && typeCount[types[1]] && !this.randomChance(1, 3)) skip = true;
|
||||
}
|
||||
|
||||
// Ensure the weakness-resistance balance is 2 points or lower for all types,
|
||||
|
||||
@@ -197,7 +197,7 @@ exports.BattleScripts = {
|
||||
} else {
|
||||
accuracy = this.runEvent('Accuracy', target, pokemon, move, accuracy);
|
||||
}
|
||||
if (accuracy !== true && accuracy !== 255 && this.random(256) >= accuracy) {
|
||||
if (accuracy !== true && accuracy !== 255 && !this.randomChance(accuracy, 256)) {
|
||||
this.attrLastMove('[miss]');
|
||||
this.add('-miss', pokemon);
|
||||
damage = false;
|
||||
@@ -400,7 +400,7 @@ exports.BattleScripts = {
|
||||
// Unlike gen 1, though, paralysis works for all unless the target is immune to direct move (ie. ground-types and t-wave).
|
||||
if (!(secondary.status && ['brn', 'frz'].includes(secondary.status) && target && target.hasType(move.type))) {
|
||||
let effectChance = Math.floor(secondary.chance * 255 / 100);
|
||||
if (typeof secondary.chance === 'undefined' || this.random(256) < effectChance) {
|
||||
if (typeof secondary.chance === 'undefined' || this.randomChance(effectChance, 256)) {
|
||||
this.moveHit(target, pokemon, move, secondary, true, isSelf);
|
||||
}
|
||||
}
|
||||
@@ -485,7 +485,7 @@ exports.BattleScripts = {
|
||||
move.crit = move.willCrit || false;
|
||||
if (typeof move.willCrit === 'undefined') {
|
||||
if (move.critRatio) {
|
||||
move.crit = (this.random(critMult[move.critRatio]) === 0);
|
||||
move.crit = this.randomChance(1, critMult[move.critRatio]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ exports.BattleStatuses = {
|
||||
onStallMove: function () {
|
||||
let counter = Math.floor(this.effectData.counter) || 127;
|
||||
this.debug("Success chance: " + Math.round(counter * 1000 / 255) / 10 + "% (" + counter + "/255)");
|
||||
return (this.random(255) < counter);
|
||||
return this.randomChance(counter, 255);
|
||||
},
|
||||
onRestart: function () {
|
||||
this.effectData.counter /= 2;
|
||||
|
||||
@@ -430,7 +430,7 @@ class RandomGen3Teams extends RandomGen4Teams {
|
||||
if (ability0.gen !== 3) ability = ability1.name;
|
||||
if (ability0.gen === 3 && ability1.gen === 3) {
|
||||
if (ability0.rating <= ability1.rating) {
|
||||
if (this.random(2)) ability = ability1.name;
|
||||
if (!this.randomChance(1, 2)) ability = ability1.name;
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating) {
|
||||
if (this.randomChance(1, 3)) ability = ability1.name;
|
||||
}
|
||||
@@ -512,15 +512,15 @@ class RandomGen3Teams extends RandomGen4Teams {
|
||||
} else if (hasMove['leechseed']) {
|
||||
item = 'Leftovers';
|
||||
} else if (hasMove['endeavor'] || hasMove['flail'] || hasMove['reversal'] || hasMove['endure'] ||
|
||||
hasMove['substitute'] && counter.Status < 3 && template.baseStats.hp + template.baseStats.def + template.baseStats.spd < 250 && this.random(2)) {
|
||||
hasMove['substitute'] && counter.Status < 3 && template.baseStats.hp + template.baseStats.def + template.baseStats.spd < 250 && !this.randomChance(1, 2)) {
|
||||
if (template.baseStats.spe <= 90 && !counter['speedsetup'] && !hasMove['focuspunch']) {
|
||||
item = 'Salac Berry';
|
||||
} else if (counter.Physical > counter.Special || counter.Physical === counter.Special && this.random(2)) {
|
||||
} else if (counter.Physical > counter.Special || counter.Physical === counter.Special && !this.randomChance(1, 2)) {
|
||||
item = 'Liechi Berry';
|
||||
} else {
|
||||
item = 'Petaya Berry';
|
||||
}
|
||||
} else if ((counter.Physical >= 4 || counter.Physical >= 3 && counter.Special === 1 && this.random(2)) && !(hasMove['bodyslam'] && hasAbility['Serene Grace']) && !hasMove['fakeout'] && !hasMove['rapidspin']) {
|
||||
} else if ((counter.Physical >= 4 || counter.Physical >= 3 && counter.Special === 1 && !this.randomChance(1, 2)) && !(hasMove['bodyslam'] && hasAbility['Serene Grace']) && !hasMove['fakeout'] && !hasMove['rapidspin']) {
|
||||
item = 'Choice Band';
|
||||
} else if (hasMove['curse'] || hasMove['protect'] || hasMove['sleeptalk'] || hasMove['substitute']) {
|
||||
item = 'Leftovers';
|
||||
|
||||
@@ -450,7 +450,7 @@ class RandomGen4Teams extends RandomGen5Teams {
|
||||
ability = ability0.name;
|
||||
if (abilities[1]) {
|
||||
if (ability0.rating <= ability1.rating) {
|
||||
if (this.random(2)) ability = ability1.name;
|
||||
if (!this.randomChance(1, 2)) ability = ability1.name;
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating) {
|
||||
if (this.randomChance(1, 3)) ability = ability1.name;
|
||||
}
|
||||
@@ -539,7 +539,7 @@ class RandomGen4Teams extends RandomGen5Teams {
|
||||
} else if (template.species === 'Wobbuffet') {
|
||||
item = hasMove['destinybond'] ? 'Custap Berry' : ['Leftovers', 'Sitrus Berry'][this.random(2)];
|
||||
} else if (hasMove['switcheroo'] || hasMove['trick']) {
|
||||
let randomNum = this.random(3);
|
||||
let randomNum = !this.randomChance(1, 3);
|
||||
if (counter.Physical >= 3 && (template.baseStats.spe < 60 || template.baseStats.spe > 108 || randomNum)) {
|
||||
item = 'Choice Band';
|
||||
} else if (counter.Special >= 3 && (template.baseStats.spe < 60 || template.baseStats.spe > 108 || randomNum)) {
|
||||
@@ -568,9 +568,9 @@ class RandomGen4Teams extends RandomGen5Teams {
|
||||
|
||||
// Medium priority
|
||||
} else if (counter.Physical >= 4 && !(hasMove['bodyslam'] && hasAbility['Serene Grace']) && !hasMove['fakeout'] && !hasMove['rapidspin'] && !hasMove['suckerpunch']) {
|
||||
item = template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !hasMove['bodyslam'] && this.random(3) ? 'Choice Scarf' : 'Choice Band';
|
||||
item = template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !hasMove['bodyslam'] && !this.randomChance(1, 3) ? 'Choice Scarf' : 'Choice Band';
|
||||
} else if ((counter.Special >= 4 || (counter.Special >= 3 && (hasMove['batonpass'] || hasMove['uturn'] || hasMove['waterspout'] && hasMove['selfdestruct']))) && !hasMove['chargebeam']) {
|
||||
item = template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && ability !== 'Speed Boost' && !counter['priority'] && this.random(3) ? 'Choice Scarf' : 'Choice Specs';
|
||||
item = template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && ability !== 'Speed Boost' && !counter['priority'] && !this.randomChance(1, 3) ? 'Choice Scarf' : 'Choice Specs';
|
||||
} else if (hasMove['endeavor'] || hasMove['flail'] || hasMove['reversal']) {
|
||||
item = 'Focus Sash';
|
||||
} else if (ability === 'Slow Start' || hasMove['curse'] || hasMove['detect'] || hasMove['leechseed'] || hasMove['protect'] || hasMove['roar'] || hasMove['sleeptalk'] || hasMove['whirlwind']) {
|
||||
|
||||
@@ -371,12 +371,12 @@ class RandomGen5Teams extends RandomGen6Teams {
|
||||
let ability1 = this.getAbility(abilities[1]);
|
||||
let ability2 = this.getAbility(abilities[2]);
|
||||
if (abilities[1]) {
|
||||
if (abilities[2] && ability1.rating <= ability2.rating && this.random(2)) {
|
||||
if (abilities[2] && ability1.rating <= ability2.rating && !this.randomChance(1, 2)) {
|
||||
[ability1, ability2] = [ability2, ability1];
|
||||
}
|
||||
if (ability0.rating <= ability1.rating && this.random(2)) {
|
||||
if (ability0.rating <= ability1.rating && !this.randomChance(1, 2)) {
|
||||
[ability0, ability1] = [ability1, ability0];
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating && this.random(3)) {
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating && !this.randomChance(1, 3)) {
|
||||
[ability0, ability1] = [ability1, ability0];
|
||||
}
|
||||
ability = ability0.name;
|
||||
@@ -472,7 +472,7 @@ class RandomGen5Teams extends RandomGen6Teams {
|
||||
item = 'Focus Sash';
|
||||
} else if (template.species === 'Unown') {
|
||||
item = 'Choice Specs';
|
||||
} else if (template.species === 'Wobbuffet' && hasMove['destinybond'] && this.random(2)) {
|
||||
} else if (template.species === 'Wobbuffet' && hasMove['destinybond'] && !this.randomChance(1, 2)) {
|
||||
item = 'Custap Berry';
|
||||
} else if (ability === 'Imposter') {
|
||||
item = 'Choice Scarf';
|
||||
@@ -481,7 +481,7 @@ class RandomGen5Teams extends RandomGen6Teams {
|
||||
} else if (hasMove['trick'] && hasMove['gyroball']) {
|
||||
item = 'Iron Ball';
|
||||
} else if (hasMove['switcheroo'] || hasMove['trick']) {
|
||||
let randomNum = this.random(2);
|
||||
let randomNum = !this.randomChance(1, 2);
|
||||
if (counter.Physical >= 3 && (template.baseStats.spe >= 95 || randomNum)) {
|
||||
item = 'Choice Band';
|
||||
} else if (counter.Special >= 3 && (template.baseStats.spe >= 95 || randomNum)) {
|
||||
@@ -531,9 +531,9 @@ class RandomGen5Teams extends RandomGen6Teams {
|
||||
} else if (hasMove['lightscreen'] || hasMove['reflect']) {
|
||||
item = 'Light Clay';
|
||||
} else if (counter.Physical >= 4 && !hasMove['fakeout'] && !hasMove['suckerpunch'] && !hasMove['flamecharge'] && !hasMove['rapidspin']) {
|
||||
item = this.random(3) ? 'Choice Band' : 'Expert Belt';
|
||||
item = !this.randomChance(1, 3) ? 'Choice Band' : 'Expert Belt';
|
||||
} else if (counter.Special >= 4) {
|
||||
item = this.random(3) ? 'Choice Specs' : 'Expert Belt';
|
||||
item = !this.randomChance(1, 3) ? 'Choice Specs' : 'Expert Belt';
|
||||
} else if (this.getEffectiveness('Ground', template) >= 2 && ability !== 'Levitate' && !hasMove['magnetrise']) {
|
||||
item = 'Air Balloon';
|
||||
} else if ((hasMove['eruption'] || hasMove['waterspout']) && !counter['Status']) {
|
||||
|
||||
@@ -37,7 +37,7 @@ exports.BattleStatuses = {
|
||||
return (this.random() * 4294967296 < 1);
|
||||
}
|
||||
this.debug("Success chance: " + Math.round(100 / counter) + "%");
|
||||
return (this.random(counter) === 0);
|
||||
return this.randomChance(1, counter);
|
||||
},
|
||||
onRestart: function () {
|
||||
if (this.effectData.counter < this.effect.counterMax) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class RandomGen6Teams extends RandomTeams {
|
||||
species = template.baseSpecies;
|
||||
}
|
||||
let battleForme = this.checkBattleForme(template);
|
||||
if (battleForme && battleForme.tier !== 'AG' && (battleForme.isMega ? !teamDetails.megaStone : this.random(2))) {
|
||||
if (battleForme && battleForme.tier !== 'AG' && (battleForme.isMega ? !teamDetails.megaStone : !this.randomChance(1, 2))) {
|
||||
template = this.getTemplate(template.otherFormes.length >= 2 ? template.otherFormes[this.random(template.otherFormes.length)] : template.otherFormes[0]);
|
||||
}
|
||||
|
||||
@@ -604,12 +604,12 @@ class RandomGen6Teams extends RandomTeams {
|
||||
let ability1 = this.getAbility(abilities[1]);
|
||||
let ability2 = this.getAbility(abilities[2]);
|
||||
if (abilities[1]) {
|
||||
if (abilities[2] && ability1.rating <= ability2.rating && this.random(2)) {
|
||||
if (abilities[2] && ability1.rating <= ability2.rating && !this.randomChance(1, 2)) {
|
||||
[ability1, ability2] = [ability2, ability1];
|
||||
}
|
||||
if (ability0.rating <= ability1.rating && this.random(2)) {
|
||||
if (ability0.rating <= ability1.rating && !this.randomChance(1, 2)) {
|
||||
[ability0, ability1] = [ability1, ability0];
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating && this.random(3)) {
|
||||
} else if (ability0.rating - 0.6 <= ability1.rating && !this.randomChance(1, 3)) {
|
||||
[ability0, ability1] = [ability1, ability0];
|
||||
}
|
||||
ability = ability0.name;
|
||||
@@ -716,7 +716,7 @@ class RandomGen6Teams extends RandomTeams {
|
||||
ability = 'Pickup';
|
||||
} else if (template.baseSpecies === 'Basculin') {
|
||||
ability = 'Adaptability';
|
||||
} else if (template.species === 'Lopunny' && hasMove['switcheroo'] && this.random(3)) {
|
||||
} else if (template.species === 'Lopunny' && hasMove['switcheroo'] && !this.randomChance(1, 3)) {
|
||||
ability = 'Klutz';
|
||||
} else if ((template.species === 'Rampardos' && !hasMove['headsmash']) || hasMove['rockclimb']) {
|
||||
ability = 'Sheer Force';
|
||||
@@ -758,7 +758,7 @@ class RandomGen6Teams extends RandomTeams {
|
||||
// To perma-taunt a Pokemon by giving it Assault Vest
|
||||
item = 'Assault Vest';
|
||||
} else if (hasMove['switcheroo'] || hasMove['trick']) {
|
||||
let randomNum = this.random(3);
|
||||
let randomNum = !this.randomChance(1, 3);
|
||||
if (counter.Physical >= 3 && (template.baseStats.spe < 60 || template.baseStats.spe > 108 || randomNum)) {
|
||||
item = 'Choice Band';
|
||||
} else if (counter.Special >= 3 && (template.baseStats.spe < 60 || template.baseStats.spe > 108 || randomNum)) {
|
||||
@@ -814,10 +814,10 @@ class RandomGen6Teams extends RandomTeams {
|
||||
} else if (((ability === 'Speed Boost' && !hasMove['substitute']) || (ability === 'Stance Change')) && counter.Physical + counter.Special > 2) {
|
||||
item = 'Life Orb';
|
||||
} else if (counter.Physical >= 4 && !hasMove['bodyslam'] && !hasMove['dragontail'] && !hasMove['fakeout'] && !hasMove['flamecharge'] && !hasMove['rapidspin'] && !hasMove['suckerpunch']) {
|
||||
item = template.baseStats.atk >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && this.random(3) ? 'Choice Scarf' : 'Choice Band';
|
||||
item = template.baseStats.atk >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !this.randomChance(1, 3) ? 'Choice Scarf' : 'Choice Band';
|
||||
} else if (counter.Special >= 4 && !hasMove['acidspray'] && !hasMove['chargebeam'] && !hasMove['clearsmog'] && !hasMove['fierydance']) {
|
||||
item = template.baseStats.spa >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && this.random(3) ? 'Choice Scarf' : 'Choice Specs';
|
||||
} else if (((counter.Physical >= 3 && hasMove['defog']) || (counter.Special >= 3 && hasMove['uturn'])) && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && this.random(3)) {
|
||||
item = template.baseStats.spa >= 100 && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !this.randomChance(1, 3) ? 'Choice Scarf' : 'Choice Specs';
|
||||
} else if (((counter.Physical >= 3 && hasMove['defog']) || (counter.Special >= 3 && hasMove['uturn'])) && template.baseStats.spe >= 60 && template.baseStats.spe <= 108 && !counter['priority'] && !this.randomChance(1, 3)) {
|
||||
item = 'Choice Scarf';
|
||||
} else if (ability === 'Defeatist' || hasMove['eruption'] || hasMove['waterspout']) {
|
||||
item = counter.Status <= 1 ? 'Expert Belt' : 'Leftovers';
|
||||
@@ -831,7 +831,7 @@ class RandomGen6Teams extends RandomTeams {
|
||||
item = 'Leftovers';
|
||||
} else if (hasMove['substitute']) {
|
||||
item = !counter['drain'] || counter.damagingMoves.length < 2 ? 'Leftovers' : 'Life Orb';
|
||||
} else if ((ability === 'Iron Barbs' || ability === 'Rough Skin') && this.random(2)) {
|
||||
} else if ((ability === 'Iron Barbs' || ability === 'Rough Skin') && !this.randomChance(1, 2)) {
|
||||
item = 'Rocky Helmet';
|
||||
} else if (counter.Physical + counter.Special >= 4 && template.baseStats.spd >= 65 && template.baseStats.hp + template.baseStats.def + template.baseStats.spd >= 235) {
|
||||
item = 'Assault Vest';
|
||||
|
||||
@@ -172,7 +172,7 @@ exports.BattleScripts = {
|
||||
accuracy = this.runEvent('Accuracy', target, pokemon, move, accuracy);
|
||||
|
||||
// Stadium fixes the 1/256 accuracy bug.
|
||||
if (accuracy !== true && this.random(256) > accuracy) {
|
||||
if (accuracy !== true && !this.randomChance(accuracy + 1, 256)) {
|
||||
this.attrLastMove('[miss]');
|
||||
this.add('-miss', pokemon);
|
||||
damage = false;
|
||||
@@ -389,7 +389,7 @@ exports.BattleScripts = {
|
||||
// If a move that was not fire-type would exist on Gen 1, it could burn a Pokémon.
|
||||
if (!(secondary.status && ['par', 'brn', 'frz'].includes(secondary.status) && target && target.hasType(move.type))) {
|
||||
let effectChance = Math.floor(secondary.chance * 255 / 100);
|
||||
if (typeof secondary.chance === 'undefined' || this.random(256) <= effectChance) {
|
||||
if (typeof secondary.chance === 'undefined' || this.randomChance(effectChance + 1, 256)) {
|
||||
this.moveHit(target, pokemon, move, secondary, true, isSelf);
|
||||
}
|
||||
}
|
||||
@@ -508,7 +508,7 @@ exports.BattleScripts = {
|
||||
// We compare our critical hit chance against a random number between 0 and 255.
|
||||
// If the random number is lower, we get a critical hit. This means there is always a 1/255 chance of not hitting critically.
|
||||
if (critChance > 0) {
|
||||
move.crit = (this.random(256) < critChance);
|
||||
move.crit = this.randomChance(critChance, 256);
|
||||
}
|
||||
}
|
||||
// There is a critical hit.
|
||||
|
||||
@@ -2211,7 +2211,7 @@ class Battle extends Dex.ModdedDex {
|
||||
move.crit = move.willCrit || false;
|
||||
if (move.willCrit === undefined) {
|
||||
if (critRatio) {
|
||||
move.crit = (this.random(critMult[critRatio]) === 0);
|
||||
move.crit = this.randomChance(1, critMult[critRatio]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user