Created
March 4, 2017 08:39
-
-
Save happyDemon/b9ff57215ffae464f0792dd7e13d00bb to your computer and use it in GitHub Desktop.
Vue.js explained through Pokemon #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
calculateCritical(otherPokemonType) { | |
const random = Math.floor(Math.random() * 255); | |
const probability = (this.attack.type == 'normal') ? this.attacking.stats.speed / 512 : this.attacking.stats.speed / 256; | |
// Seems like we've got a critical hit | |
if (random < probability) { | |
Vuemit.fire(otherPokemonType+'.attack.effective', 'Critical hit!'); | |
// Lower leveled pokemon will have a smaller percentage of bonus | |
return ((this.attacking.stats.level * 2) + 5) / (this.attacking.stats.level + 5); | |
} | |
// Normal attack power | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment