Skip to content

Instantly share code, notes, and snippets.

@happyDemon
Created March 4, 2017 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happyDemon/b9ff57215ffae464f0792dd7e13d00bb to your computer and use it in GitHub Desktop.
Save happyDemon/b9ff57215ffae464f0792dd7e13d00bb to your computer and use it in GitHub Desktop.
Vue.js explained through Pokemon #5
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