Skip to content

Instantly share code, notes, and snippets.

@Naramsim
Last active August 5, 2019 20:27
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 Naramsim/49c99ea914e6129ce57d2405b609417d to your computer and use it in GitHub Desktop.
Save Naramsim/49c99ea914e6129ce57d2405b609417d to your computer and use it in GitHub Desktop.
pokemon types multipliers
console.log(getMultipliers(['poison','fire']))
function getMultipliers(types) {
var multipliers = {
defense: {},
attack: {}
}
types.forEach( (type) => {
var damage_relations = all_types[type]
var no_damage_to = damage_relations.attack.zero
var no_damage_from = damage_relations.defense.zero
var half_damage_to = damage_relations.attack.half
var half_damage_from = damage_relations.defense.half
var double_damage_to = damage_relations.attack.double
var double_damage_from = damage_relations.defense.double
no_damage_to.forEach((type) => {
if(multipliers.attack.hasOwnProperty(type)){multipliers.attack[type] = multipliers.attack[type] * 0}
else{multipliers.attack[type] = 0}
})
no_damage_from.forEach((type) => {
if(multipliers.defense.hasOwnProperty(type)){multipliers.defense[type] = multipliers.defense[type] * 0}
else{multipliers.defense[type] = 0}
})
half_damage_to.forEach((type) => {
if(multipliers.attack.hasOwnProperty(type)){multipliers.attack[type] = multipliers.attack[type] * 0.5}
else{multipliers.attack[type] = 0.5}
})
half_damage_from.forEach((type) => {
if(multipliers.defense.hasOwnProperty(type)){multipliers.defense[type] = multipliers.defense[type] * 0.5}
else{multipliers.defense[type] = 0.5}
})
double_damage_to.forEach((type) => {
if(multipliers.attack.hasOwnProperty(type)){multipliers.attack[type] = multipliers.attack[type] * 2}
else{multipliers.attack[type] = 2}
})
double_damage_from.forEach((type) => {
if(multipliers.defense.hasOwnProperty(type)){multipliers.defense[type] = multipliers.defense[type] * 2}
else{multipliers.defense[type] = 2}
})
})
return multipliers
}
var all_types = {
bug: {
attack: {
double: ['psychic', 'grass', 'dark'],
half: ['fighting', 'fire', 'flying', 'ghost', 'poison', 'steel', 'fairy'],
zero: []
},
defense: {
half: ['fighting', 'grass', 'ground'],
double: ['fire', 'flying', 'rock'],
zero: []
}
},
dark: {
attack: {
double: ['ghost', 'psychic'],
half: ['dark', 'fighting', 'fairy'],
zero: []
},
defense: {
half: ['dark', 'ghost'],
double: ['bug', 'fighting', 'fairy'],
zero: ['psychic']
}
},
dragon: {
attack: {
double: ['dragon'],
half: ['steel'],
zero: ['fairy']
},
defense: {
half: ['electric', 'fire', 'grass', 'water'],
double: ['dragon', 'ice', 'fairy'],
zero: []
}
},
electric: {
attack: {
double: ['flying', 'water'],
half: ['dragon', 'electric', 'grass'],
zero: ['ground']
},
defense: {
half: ['electric', 'flying', 'steel'],
double: ['ground'],
zero: []
}
},
fairy: {
attack: {
double: ['dark', 'dragon', 'fighting'],
half: ['fire', 'poison', 'steel'],
zero: []
},
defense: {
half: ['bug', 'dark', 'fighting'],
double: ['poison', 'steel'],
zero: ['dragon']
}
},
fighting: {
attack: {
double: ['dark', 'ice', 'normal', 'rock', 'steel'],
half: ['bug', 'fairy', 'flying', 'poison', 'psychic'],
zero: ['ghost']
},
defense: {
half: ['bug', 'dark', 'rock'],
double: ['fairy', 'flying', 'psychic'],
zero: []
}
},
fire: {
attack: {
double: ['bug', 'grass', 'ice', 'steel'],
half: ['dragon', 'fire', 'rock', 'water'],
zero: []
},
defense: {
half: ['bug', 'fairy', 'fire', 'grass', 'ice', 'steel'],
double: ['bug', 'fire', 'flying', 'ice', 'poison'],
zero: []
}
},
flying: {
attack: {
double: ['bug', 'fighting', 'grass'],
half: ['electric', 'rock', 'steel'],
zero: []
},
defense: {
half: ['bug', 'fighting', 'grass'],
double: ['electric', 'ice', 'rock'],
zero: ['ground']
}
},
ghost: {
attack: {
double: ['ghost', 'psychic'],
half: ['dark'],
zero: ['normal']
},
defense: {
half: ['bug', 'poison'],
double: ['ghost', 'dark'],
zero: ['normal', 'fighting']
}
},
grass: {
attack: {
double: ['ground', 'rock', 'water'],
half: ['bug', 'dragon', 'fire', 'flying', 'grass', 'poison', 'steel'],
zero: []
},
defense: {
half: ['electric', 'grass', 'ground', 'water'],
double: ['bug', 'fire', 'flying', 'ice', 'poison'],
zero: []
}
},
ground: {
attack: {
double: ['electric', 'fire', 'poison', 'rock', 'steel'],
half: ['bug', 'grass'],
zero: ['flying']
},
defense: {
half: ['poison', 'rock'],
double: ['grass', 'ice', 'water'],
zero: ['electric']
}
},
ice: {
attack: {
double: ['dragon', 'flying', 'grass', 'ground'],
half: ['fire', 'ice', 'steel', 'water'],
zero: []
},
defense: {
half: ['ice'],
double: ['fighting', 'fire', 'rock', 'steel'],
zero: []
}
},
normal: {
attack: {
double: [],
half: ['rock', 'steel'],
zero: ['ghost']
},
defense: {
half: [],
double: ['fighting'],
zero: ['ghost']
}
},
poison: {
attack: {
double: ['grass', 'fairy'],
half: ['ghost', 'ground', 'poison', 'rock'],
zero: ['steel']
},
defense: {
half: ['bug', 'fairy', 'fighting', 'grass', 'poison'],
double: ['ground', 'psychic'],
zero: []
}
},
psychic: {
attack: {
double: ['fighting', 'poison'],
half: ['psychic', 'steel'],
zero: ['dark']
},
defense: {
half: ['fighting', 'psychic'],
double: ['bug', 'dark', 'ghost'],
zero: []
}
},
rock: {
attack: {
double: ['bug', 'fire', 'flying', 'ice'],
half: ['fighting', 'ground', 'steel'],
zero: []
},
defense: {
half: ['fire', 'flying', 'normal', 'poison'],
double: ['fighting', 'grass', 'ground', 'steel', 'water'],
zero: []
}
},
steel: {
attack: {
double: ['fairy', 'ice', 'rock'],
half: ['electric', 'fire', 'steel', 'water'],
zero: []
},
defense: {
half: ['bug', 'dragon', 'fairy', 'flying', 'grass', 'ice', 'normal', 'psychic', 'rock', 'steel'],
double: ['fighting', 'fire', 'ground'],
zero: ['poison']
}
},
water: {
attack: {
double: ['fire', 'ground', 'rock'],
half: ['dragon', 'grass', 'steel'],
zero: []
},
defense: {
half: ['fire', 'ice', 'steel', 'water'],
double: ['electric', 'grass'],
zero: []
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment