Added support for all power-boosting items

Removed redundancy from code

Moved to tooltips file

Reduced code

Reduced code

Reduced code

Reduced globals to 1

Minor error corrections
This commit is contained in:
Harshvardhan 2015-12-16 17:24:56 +05:30 committed by Harshvardhan Kalra
parent df4cc30de4
commit 311acb8fcd
4 changed files with 116 additions and 151 deletions

View File

@ -15,7 +15,7 @@ module.exports = {
"fs": false, "gui": false, "ga": false, "macgap": false, "nwWindow": false, "webkitNotifications": false,
// Battle stuff
"Battle": true, "Pokemon": true, "BattleSound": true,
"Battle": true, "Pokemon": true, "BattleSound": true, "BattleTooltips": true,
"BattleAbilities": false, "BattleAliases": false, "BattleBackdrops": false, "BattleBackdropsFour": false, "BattleBackdropsThree": false, "BattleEffects": false,
"BattleFormats": false, "BattleFormatsData": false, "BattleLearnsets": false, "BattleItems": false, "BattleMoveAnims": false, "BattleMovedex": false, "BattleNatures": false,
"BattleOtherAnims": false, "BattlePokedex": false,"BattlePokemonSprites": false, "BattlePokemonSpritesBW": false, "BattleSearchCountIndex": false, "BattleSearchIndex": false,

View File

@ -0,0 +1,81 @@
var BattleTooltips = (function () {
function BattleTooltips() {}
BattleTooltips.prototype.boostBasePower = function (BattleRoom, move, pokemon, target, basePower, basePowerComment) {
var myPokemon = BattleRoom.myPokemon[pokemon.slot];
var ability = Tools.getAbility(myPokemon.baseAbility).name;
var thereIsWeather = (BattleRoom.battle.weather in {'sunnyday': 1, 'desolateland': 1, 'raindance': 1, 'primordialsea': 1, 'sandstorm': 1, 'hail':1});
if (!BattleRoom.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
var item = Tools.getItem(myPokemon.item);
var pos = BattleRoom.choice.choices.length;
var moveType = BattleRoom.getMoveType(move, BattleRoom.battle.mySide.active[pos]);
var splitItemName = item.name.split(' ');
var moveName = move.name;
if (basePower) {
// Gems
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && (moveName != 'Struggle' || moveName != 'Water Pledge' || moveName != 'Grass Pledge' || moveName != 'Fire Pledge' || moveName != 'Fling')) {
basePower *= BattleRoom.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + item.name + ')';
}
// Plates
if (splitItemName[1] == 'Plate' && item.onPlate && moveType == item.onPlate) {
basePower *= 1.2;
basePowerComment += ' (Boosted by ' + item.name + ')';
}
// Type-enhancing items
if (item.name == 'Black Belt' && moveType == 'Fighting' || item.name == 'Black Glasses' && moveType == 'Dark' || item.name == 'Charcoal' && moveType == 'Fire' || item.name == 'Dragon Fang' && moveType == 'Dragon' || item.name == 'Hard Stone' && moveType == 'Rock' || item.name == 'Magnet' && moveType == 'Electric' || item.name == 'Metal Coat' && moveType == 'Steel' || item.name == 'Miracle Seed' && moveType == 'Grass' || item.name == 'Mystic Water' && moveType == 'Water' || item.name == 'Never-Melt Ice' && moveType == 'Ice' || item.name == 'Poison Barb' && moveType == 'Poison' || item.name == 'Sharp Beak' && moveType == 'Flying' || item.name == 'Silk Scarf' && moveType == 'Normal' || item.name == 'SilverPowder' && moveType == 'Bug' || item.name == 'Soft Sand' && moveType == 'Ground' || item.name == 'Spell Tag' && moveType == 'Ghost' || item.name == 'TwistedSpoon' && moveType == 'Psychic') {
basePower *= BattleRoom.battle.gen >= 4 ? 1.2 : 1.1;
basePowerComment += ' (Boosted by ' + item.name + ')';
}
// Incenses
if ((item.name == 'Wave Incense' || item.name == 'Sea Incense') && moveType == 'Water' || item.name == 'Rose Incense' && moveType == 'Grass' || item.name == 'Rock Incense' && moveType == 'Rock' || item.name == 'Odd Incense' && moveType == 'Psychic') {
basePower *= 1.2;
basePowerComment += ' (Boosted by ' + item.name + ')';
}
}
basePower = Math.floor(basePower);
return basePower == 0 ? basePowerComment : basePower + basePowerComment;
}
};
BattleTooltips.prototype.boostBasePower_Ball = function (BattleRoom, move, pokemon, target, basePower, basePowerComment, min, max) {
var myPokemon = BattleRoom.myPokemon[pokemon.slot];
var ability = Tools.getAbility(myPokemon.baseAbility).name;
var item = Tools.getItem(myPokemon.item);
var pos = BattleRoom.choice.choices.length;
var moveType = BattleRoom.getMoveType(move, BattleRoom.battle.mySide.active[pos]);
var splitItemName = item.name.split(' ');
var moveName = move.name;
var itemCheck = false;
if (!BattleRoom.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0]) {
min *= BattleRoom.battle.gen >= 6 ? 1.3 : 1.5;
max *= BattleRoom.battle.gen >= 6 ? 1.3 : 1.5;
itemCheck = true;
}
if (splitItemName[1] == 'Plate' && item.onPlate && moveType == item.onPlate) {
min *= 1.2;
max *= 1.2;
itemCheck = true;
}
if (item.name == 'Magnet' && moveType == 'Electric' || item.name == 'Metal Coat' && moveType == 'Steel') {
min *= BattleRoom.battle.gen >= 4 ? 1.2 : 1.1;
max *= BattleRoom.battle.gen >= 4 ? 1.2 : 1.1;
itemCheck = true;
}
if (ability === 'Technician') {
if (min <= 60) min *= 1.5;
if (max <= 60) max *= 1.5;
basePowerComment += '' + ((min === max) ? Math.floor(max) : Math.floor(min) + ' to ' + Math.floor(max)) + ' (Technician boosted)';
if (itemCheck) {
basePowerComment += ' (Boosted by ' + item.name + ')';
}
} else {
basePowerComment += (min === max) ? Math.floor(max) : Math.floor(min) + ' to ' + Math.floor(max);
if (itemCheck) {
basePowerComment += ' (Boosted by ' + item.name + ')';
}
}
}
return basePowerComment;
};
return BattleTooltips;
})();

View File

@ -1331,18 +1331,8 @@
var ability = Tools.getAbility(myPokemon.baseAbility).name;
var basePower = move.basePower;
var basePowerComment = '';
var Tooltips = new BattleTooltips();
var thereIsWeather = (this.battle.weather in {'sunnyday': 1, 'desolateland': 1, 'raindance': 1, 'primordialsea': 1, 'sandstorm': 1, 'hail':1});
if (myPokemon.item && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && basePower && (moveName != 'Struggle' || moveName != 'Water Pledge' || moveName != 'Grass Pledge' || moveName != 'Fire Pledge' || moveName != 'Fling')) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
}
if (move.id === 'acrobatics') {
if (!myPokemon.item) {
basePower *= 2;
@ -1351,29 +1341,10 @@
}
if (move.id === 'crushgrip' || move.id === 'wringout') {
basePower = Math.floor(Math.floor((120 * (100 * Math.floor(target.hp * 4096 / target.maxhp)) + 2048 - 1) / 4096) / 100) || 1;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
basePowerComment += ' (Approximation)';
basePowerComment = ' (Approximation)';
}
if (move.id === 'eruption' || move.id === 'waterspout') {
basePower = Math.floor(150 * pokemon.hp / pokemon.maxhp) || 1;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
}
}
if (move.id === 'flail' || move.id === 'reversal') {
if (this.battle.gen > 4) {
@ -1390,20 +1361,10 @@
else if (ratio < ratios[3]) basePower = 80;
else if (ratio < ratios[4]) basePower = 40;
else basePower = 20;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
}
if (move.id === 'hex' && target.status) {
basePower *= 2;
basePowerComment += ' (Boosted by status)';
basePowerComment = ' (Boosted by status)';
}
if (move.id === 'punishment') {
var boosts = Object.keys(target.boosts);
@ -1412,22 +1373,12 @@
if (target.boosts[boosts[i]] > 0) multiply += target.boosts[boosts[i]];
}
basePower = 60 + 20 * multiply;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
if (basePower > 200) basePower = 200;
}
if (move.id === 'smellingsalts') {
if (target.status === 'par') {
basePower *= 2;
basePowerComment += ' (Boosted by status)';
basePowerComment = ' (Boosted by status)';
}
}
if (move.id === 'storedpower') {
@ -1437,16 +1388,6 @@
if (pokemon.boosts[boosts[i]] > 0) multiply += pokemon.boosts[boosts[i]];
}
basePower = 20 + 20 * multiply;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
}
if (move.id === 'trumpcard') {
basePower = 40;
@ -1454,41 +1395,21 @@
else if (move.pp === 2) basePower = 80;
else if (move.pp === 3) basePower = 60;
else if (move.pp === 4) basePower = 50;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
}
if (move.id === 'venoshock') {
if (target.status === 'psn' || target.status === 'tox') {
basePower *= 2;
basePowerComment += ' (Boosted by status)';
basePowerComment = ' (Boosted by status)';
}
}
if (move.id === 'wakeupslap') {
if (target.status === 'slp') {
basePower *= 2;
basePowerComment += ' (Boosted by status)';
basePowerComment = ' (Boosted by status)';
}
}
if (move.id === 'weatherball' && thereIsWeather) {
basePower = 100;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
}
// Moves that check opponent speed.
if (move.id === 'electroball') {
@ -1510,23 +1431,16 @@
else max = 40;
// Special case due to being a range. Other moves are checked by technician below.
basePower = 0;
if (ability === 'Technician') {
if (min <= 60) min *= 1.5;
if (max <= 60) max *= 1.5;
basePowerComment = '' + ((min === max) ? max : min + ' to ' + max) + ' (Technician boosted)';
if (!myPokemon.item) {
if (ability === 'Technician') {
if (min <= 60) min *= 1.5;
if (max <= 60) max *= 1.5;
basePowerComment = '' + ((min === max) ? max : min + ' to ' + max) + ' (Technician boosted)';
} else {
basePowerComment = (min === max) ? max : min + ' to ' + max;
}
} else {
basePowerComment = (min === max) ? max : min + ' to ' + max;
}
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
min *= this.battle.gen >= 6 ? 1.3 : 1.5;
max *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
return Tooltips.boostBasePower_Ball(this, move, pokemon, target, basePower, basePowerComment, min, max);
}
}
if (move.id === 'gyroball') {
@ -1537,24 +1451,17 @@
if (min > 150) min = 150;
if (max > 150) max = 150;
// Special case due to range as well.
basePower = 0;
if (ability === 'Technician') {
if (min <= 60) min *= 1.5;
if (max <= 60) max = Math.max(max * 1.5, 90);
basePowerComment = '' + ((min === max) ? max : min + ' to ' + max) + ' (Technician boosted)';
if (!myPokemon.item) {
if (ability === 'Technician') {
if (min <= 60) min *= 1.5;
if (max <= 60) max *= 1.5;
basePowerComment = '' + ((min === max) ? max : min + ' to ' + max) + ' (Technician boosted)';
} else {
basePowerComment = (min === max) ? max : min + ' to ' + max;
}
} else {
basePowerComment = (min === max) ? max : min + ' to ' + max;
}
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
min *= this.battle.gen >= 6 ? 1.3 : 1.5;
max *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
return Tooltips.boostBasePower_Ball(this, move, pokemon, target, basePower, basePowerComment, min, max);
}
}
// Movements which have base power changed due to items.
@ -1582,17 +1489,7 @@
else if (targetWeight >= 50) basePower = 80;
else if (targetWeight >= 25) basePower = 60;
else if (targetWeight >= 10) basePower = 40;
// No base power initially
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
if (target.volatiles && target.volatiles.autotomize) basePowerComment += ' (Approximation)';
if (target.volatiles && target.volatiles.autotomize) basePowerComment = ' (Approximation)';
}
if (move.id === 'heavyslam' || move.id === 'heatcrash') {
basePower = 40;
@ -1600,16 +1497,7 @@
else if (pokemonWeight > targetWeight * 4) basePower = 100;
else if (pokemonWeight > targetWeight * 3) basePower = 80;
else if (pokemonWeight > targetWeight * 2) basePower = 60;
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
if (target.volatiles && target.volatiles.autotomize) basePowerComment += ' (Approximation)';
if (target.volatiles && target.volatiles.autotomize) basePowerComment = ' (Approximation)';
}
}
if (!basePower) return basePowerComment;
@ -1617,24 +1505,19 @@
// Other ability boosts.
if (ability === 'Technician' && basePower <= 60) {
basePower *= 1.5;
basePowerComment += ' (Technician boosted)';
basePowerComment = ' (Technician boosted)';
}
if (move.type === 'Normal' && move.category !== 'Status' && !(move.id in {'naturalgift': 1, 'struggle': 1}) && (!thereIsWeather || thereIsWeather && move.id !== 'weatherball')) {
if (ability in {'Aerilate': 1, 'Pixilate': 1, 'Refrigerate': 1}) {
basePower = Math.floor(basePower * 1.3);
var itemName = Tools.getItem(myPokemon.item).name;
var pos = this.choice.choices.length;
var moveType = this.getMoveType(move, this.battle.mySide.active[pos]);
var splitItemName = itemName.split(' ');
var moveName = move.name;
if (splitItemName[1] == 'Gem' && moveType == splitItemName[0] && !this.battle.hasPseudoWeather('Magic Room') && (!pokemon.volatiles || !pokemon.volatiles['embargo'])) {
basePower *= this.battle.gen >= 6 ? 1.3 : 1.5;
basePowerComment += ' (Boosted by ' + itemName + ')';
}
basePowerComment += ' (' + ability + ' boosted)';
basePowerComment = ' (' + ability + ' boosted)';
}
}
return basePower + basePowerComment;
if (myPokemon.item) {
return Tooltips.boostBasePower(this, move, pokemon, target, basePower, basePowerComment);
} else {
return basePower == 0 ? basePowerComment : basePower + basePowerComment;
}
}
});

View File

@ -98,6 +98,7 @@
<script src="js/client-ladder.js"></script>
<script src="js/client-chat.js"></script>
<script src="js/client-chat-tournament.js"></script>
<script src="js/client-battle-tooltips.js"></script>
<script src="js/client-battle.js"></script>
<script src="js/client-rooms.js"></script>
<script src="js/storage.js"></script>