def get_weaknesses_and_strengths(type_list): t = pb.type_(type_list[0].lower()) damage = t.damage_relations half_from = type_to_name(damage.half_damage_from) double_from = type_to_name(damage.double_damage_from) no_from = type_to_name(damage.no_damage_from) half_to = type_to_name(damage.half_damage_to) double_to = type_to_name(damage.double_damage_to) no_to = type_to_name(damage.no_damage_to) if len(type_list) == 2: t = pb.type_(type_list[1].lower()) damage = t.damage_relations half_from2 = type_to_name(damage.half_damage_from) double_from2 = type_to_name(damage.double_damage_from) no_from2 = type_to_name(damage.no_damage_from) quad_from = set(double_from).intersection(set(double_from2)) quarter_from = set(half_from).intersection(set(half_from2)) no_combined_from = set(no_from + no_from2) double_combined_from = set(double_from + double_from2) - quad_from - set(half_from) - set(half_from2) - no_combined_from half_combined_from = set(half_from + half_from2) - quarter_from - set(double_from) - set(double_from2) - no_combined_from normal_damage = all_types - quad_from - double_combined_from - half_combined_from - quarter_from - no_combined_from relations = { "defense" : { "x4" : list(quad_from), "x2" : list(double_combined_from), "x1" : list(normal_damage), "x0.5" : list(half_combined_from), "x0.25" : list(quarter_from), "x0" : list(no_combined_from) } } else: normal_damage_from = all_types - set(double_from) - set(half_from) - set(no_from) normal_damage_to = all_types - set(double_to) - set(half_to) - set(no_to) relations = { "defense" : { "x2" : double_from, "x1" : list(normal_damage_from), "x0.5" : half_from, "x0" : no_from }, "attack": { "x2" : double_to, "x1" : list(normal_damage_to), "x0.5" : half_to, "x0": no_to } } return relations
def changeType(self, typesList): try: self.types[0] = pb.type_(typesList[0].lower()).name except: return False try: self.types[1] = pb.type_(typesList[1].lower()).name except: return False return True
def do_type_effectiveness(self, mon, phrase): desired_type = self._extract_type(phrase) if not desired_type: self.speak_dialog("no.type.specified") return type_name = desired_type.name effectiveness = 0 for type_slot in sorted(mon.types, key=lambda x: x.slot): pokemon_type = type_slot.type damage = pokemon_type.damage_relations if type_name in (t["name"] for t in damage.no_damage_from): effectiveness = None break elif type_name in (t["name"] for t in damage.double_damage_from): effectiveness += 1 elif type_name in (t["name"] for t in damage.half_damage_from): effectiveness -= 1 speak_dict = { "type": self._get_name_from_lang(type_(type_name).names), "pokemon": self._pokemon_name(mon) } if effectiveness is None: self.speak_dialog("type.is.none", speak_dict) elif effectiveness == 0: self.speak_dialog("type.is.normal", speak_dict) elif effectiveness < 0: self.speak_dialog("type.is.half", speak_dict) else: self.speak_dialog("type.is.super", speak_dict)
def moveTypeModifier(self, move, pokemon): pokeTypes = pokemon.types moveType = pokebase.type_(move.type) modifier = 1 #create lists to store what the moves effectiveness is against certain types doubleD = [] halfD = [] noD = [] for i in moveType.damage_relations.double_damage_to: doubleD.append(i["name"]) for i in moveType.damage_relations.half_damage_to: halfD.append(i["name"]) for i in moveType.damage_relations.no_damage_to: noD.append(i["name"]) #for each type the pokemon has for type in pokeTypes: if type == "": continue #change the modifier if it's in any of the lists if type in doubleD: modifier = modifier * 2 elif type in halfD: modifier = modifier * 0.5 elif type in noD: modifier = modifier * 0 return modifier
def _extract_type(self, message): name = _extract_name(message, self.type_names) if not name: return None try: return type_(name) except ValueError: LOG.error("Couldn't find type with name: '" + str(name)) raise
def __init__(self, nickname, pokemonSpecies, pokeTypes = ["", ""], stats = [0, 0, 0, 0], newMoves = ["", "", "", ""]): self.name = nickname self.species = pokemonSpecies self.types = ["", ""] self.stats = {} try: self.stats["hp"] = int(stats[0]) except ValueError: self.stats["hp"] = 0 try: self.stats["atk"] = int(stats[1]) except ValueError: self.stats["atk"] = 0 try: self.stats["def"] = int(stats[2]) except ValueError: self.stats["def"] = 0 try: self.stats["spd"] = int(stats[3]) except ValueError: self.stats["spd"] = 0 #making negative numbers = 0 for x in self.stats: if self.stats[x] < 0: self.stats[x] = 0 #making sure types are valid types try: self.types[0] = pb.type_(pokeTypes[0].lower()).name except: pass try: self.types[1] = pb.type_(pokeTypes[1].lower()).name except: pass #adding moves since they check themselves for validity self.moves = self._createMovesList(newMoves)
async def getType(type_): ty = pb.type_(GG.cleanWordSpace(type_)) em = discord.Embed() name = GG.getNames(ty.names) em.set_author(name=name) color = GG.getColorOfType(name.lower()) em.colour = int("0x" + color, 0) em.add_field(name="Take Damage:", value="\u200b", inline=False) NDF = "" for y in ty.damage_relations.no_damage_from: NDF += f"{GG.cleanWordDash(y['name'])}\n" if NDF == "": NDF = "-" em.add_field(name="No Effect (0%)", value=NDF) HDF = "" for y in ty.damage_relations.half_damage_from: HDF += f"{GG.cleanWordDash(y['name'])}\n" if HDF == "": HDF = "-" em.add_field(name="Not Very Effective (50%)", value=HDF) DDF = "" for y in ty.damage_relations.double_damage_from: DDF += f"{GG.cleanWordDash(y['name'])}\n" if DDF == "": DDF = "-" em.add_field(name="Super-Effective (200%)", value=DDF) em.add_field(name="Deal Damage:", value="\u200b", inline=False) NDT = "" for y in ty.damage_relations.no_damage_to: NDT += f"{GG.cleanWordDash(y['name'])}\n" if NDT == "": NDT = "-" em.add_field(name="No Effect (0%)", value=NDT) HDT = "" for y in ty.damage_relations.half_damage_to: HDT += f"{GG.cleanWordDash(y['name'])}\n" if HDT == "": HDT = "-" em.add_field(name="Not Very Effective (50%)", value=HDT) DDT = "" for y in ty.damage_relations.double_damage_to: DDT += f"{GG.cleanWordDash(y['name'])}\n" if DDT == "": DDT = "-" em.add_field(name="Super-Effective (200%)", value=DDT) return em
def search(cls, id_or_name): pb_type_ = pb.type_(id_or_name) type_ = cls(pb_type_.id, pb_type_.name) for relation in DamageRelation: if relation.name.lower() in pb_type_.damage_relations.__dict__: for t in pb_type_.damage_relations.__dict__[ relation.name.lower()]: name = t['name'] id = extract_id_or_name(t['url']) type_.set_damage_relation(relation, Type(id, name)) return type_
async def getStrength(type_): ty = pb.type_(GG.cleanWordSpace(type_)) em = discord.Embed() name = GG.getNames(ty.names) em.set_author(name=name) color = GG.getColorOfType(name.lower()) em.colour = int("0x" + color, 0) DDT = "" for y in ty.damage_relations.double_damage_to: DDT += f"{GG.cleanWordDash(y['name'])}\n" if DDT == "": DDT = "-" em.add_field(name="Strong against:", value=DDT) NDF = "" for y in ty.damage_relations.no_damage_from: NDF += f"{GG.cleanWordDash(y['name'])}\n" if NDF == "": NDF = "-" em.add_field(name="Take no damage from:", value=NDF) return em
def _evolution_details_str(self, evolution_details): """ :param evolution_details: Usually a dict :return: A string representing events needed to happen to evolve based on evolution_details """ # Use this to test: https://pokemondb.net/pokebase/168028/what-pokemon-have-a-unique-evolution-method # ==== variables ==== trigger = evolution_trigger(evolution_details["trigger"]["name"]) trigger_name = self._get_name_from_lang(trigger.names) if trigger_name: trigger_name = " " + self.translate("evolve.details.trigger", {"name": trigger_name}) held_item = evolution_details["held_item"] held_item_display = "" if held_item: item_name = held_item["name"] item_display_name = self._get_name_from_lang(item(item_name).names) held_item_display = " " + self.translate( "evolve.details.holding.item", {"item": item_display_name}) min_level = evolution_details["min_level"] # None or min level min_level_display = "" if min_level: min_level_display = " " + self.translate("evolve.details.at.level", {"level": min_level}) min_happiness = evolution_details[ "min_happiness"] # None or min happiness min_happiness_display = "" if min_happiness: min_happiness_display = " " + self.translate( "evolve.details.with.happiness", {"happiness": min_happiness}) min_beauty = evolution_details["min_beauty"] min_beauty_display = "" if min_beauty: min_beauty_display = " " + self.translate( "evolve.details.with.beauty", {"beauty": min_beauty}) min_affection = evolution_details["min_affection"] min_affection_display = "" if min_affection: min_affection_display = " " + self.translate( "evolve.details.with.affection", {"affection": min_affection}) time_of_day = evolution_details[ "time_of_day"] # None or "day" or "night" time_display = "" if time_of_day: time_display = " " + self.translate("evolve.details.time.of.day", {"time": time_of_day}) gender = evolution_details["gender"] # None, 1=female, 2=male gender_display = "" if gender: if gender == 1: gender_display = " " + self.translate( "evolve.details.if.female") else: gender_display = " " + self.translate("evolve.details.if.male") party_type_dict = evolution_details["party_type"] party_type_display = "" # must have this type of pokemon in their party if party_type_dict: party_type = type_(party_type_dict["name"]) party_type_display = " " + self.translate( "evolve.details.with.pokemon.party.type", {"type": self._get_name_from_lang(party_type.names)}) location_dict = evolution_details["location"] location_display = "" if location_dict: game_location = location(location_dict["name"]) location_display = " " + self.translate( "evolve.details.location", {"location": self._get_name_from_lang(game_location.names)}) needs_rain_display = "" if evolution_details["needs_overworld_rain"]: needs_rain_display = " " + self.translate( "evolve.details.with.rain") turn_upside_down_display = "" if evolution_details["turn_upside_down"]: turn_upside_down_display = " " + self.translate( "evolve.details.turn.upside.down") known_move = evolution_details["known_move"] known_move_display = "" if known_move: known_move_display = " " + self.translate( "evolve.details.knowing.move", { "move": self._get_name_from_lang(move(known_move["name"]).names) }) known_move_type = evolution_details["known_move_type"] known_move_type_display = "" if known_move_type: known_move_type_display = " " + self.translate( "evolve.details.knowing.move.type", { "type": self._get_name_from_lang( type_(known_move_type["name"]).names) }) relative_stats = evolution_details["relative_physical_stats"] relative_stats_display = "" if relative_stats is not None: if relative_stats == -1: relative_stats_display = " " + self.translate( "evolve.details.stats.attack.less.than.defense") elif relative_stats == 0: relative_stats_display = " " + self.translate( "evolve.details.stats.attack.equals.defense") else: assert relative_stats == 1 relative_stats_display = " " + self.translate( "evolve.details.stats.attack.greater.than.defense") party_species = evolution_details["party_species"] party_species_display = "" if party_species: species_name = self._species_name( pokemon_species(party_species["name"])) party_species_display = " " + self.translate( "evolve.details.with.pokemon.party", {"pokemon": species_name}) # ==== different triggers ==== if trigger.name == "shed": return trigger_name elif trigger.name == "use-item": used_item = item(evolution_details["item"]["name"]) return trigger_name + " " + self._get_name_from_lang( used_item.names) elif trigger.name == "trade": trade_species_dict = evolution_details["trade_species"] trade_species_display = "" if trade_species_dict: trade_species = pokemon_species(trade_species_dict["name"]) trade_species_display = " " + self.translate( "evolve.details.trade.species", {"species": self._get_name_from_lang(trade_species.names)}) return trigger_name + held_item_display + trade_species_display if trigger.name != "level-up": LOG.error( "This is bad! trigger.name should be level-up but it's: {}". format(trigger.name)) # === level up trigger below === level_up_display = trigger_name if min_level_display: level_up_display = min_level_display return (level_up_display + held_item_display + known_move_display + known_move_type_display + min_happiness_display + min_beauty_display + min_affection_display + time_display + location_display + needs_rain_display + gender_display + relative_stats_display + party_type_display + party_species_display + turn_upside_down_display)
async def getMatchup(pokemon): pkmn = "" if isinstance(pokemon, str): pkmn = pb.pokemon(pokemon.lower().replace("'", "")) if isinstance(pokemon, int): pkmn = pb.pokemon(pokemon) em = discord.Embed() em.set_author(name=GG.cleanWordDash(pkmn.name)) em.set_thumbnail(url="http://play.pokemonshowdown.com/sprites/xyani/" + pkmn.name.lower() + ".gif") types = pkmn.types if len(types) == 2: type = GG.cleanWordDash(types[1].type.name) color = GG.getColorOfType(type.lower()) else: type = GG.cleanWordDash(types[0].type.name) color = GG.getColorOfType(type.lower()) em.colour = int("0x" + color, 0) DNB = [] USEDTYPES = [] WT1 = [] IT1 = [] RT1 = [] WT2 = [] IT2 = [] RT2 = [] WT = [] IT = [] RT = [] if len(types) == 2: type1_ = pb.type_(GG.cleanWordSpace(types[0].type.name)) for y in type1_.damage_relations.double_damage_from: WT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type1_.damage_relations.no_damage_from: IT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type1_.damage_relations.half_damage_from: RT1.append(f"{GG.cleanWordDash(y['name'])}") type2_ = pb.type_(GG.cleanWordSpace(types[1].type.name)) for y in type2_.damage_relations.double_damage_from: WT2.append(f"{GG.cleanWordDash(y['name'])}") for y in type2_.damage_relations.no_damage_from: IT2.append(f"{GG.cleanWordDash(y['name'])}") for y in type2_.damage_relations.half_damage_from: RT2.append(f"{GG.cleanWordDash(y['name'])}") await doubleType(DNB, IT, IT1, IT2, RT, RT1, RT2, USEDTYPES, WT, WT1, WT2) else: type_ = pb.type_(GG.cleanWordSpace(types[0].type.name)) for y in type_.damage_relations.double_damage_from: WT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type_.damage_relations.no_damage_from: IT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type_.damage_relations.half_damage_from: RT1.append(f"{GG.cleanWordDash(y['name'])}") await singleType(IT,RT,WT,IT1,RT1,WT1,USEDTYPES) for x in GG.TYPES: if x not in USEDTYPES: DNB.append('{"type":"' + GG.cleanWordDash(x) + '","effectiveness":"1x"}') DNBString = "" for x in DNB: x = json.loads(x) DNBString += f"{x['type']}: {x['effectiveness']}\n" WTString = "" for x in WT: x = json.loads(x) WTString += f"{x['type']}: {x['effectiveness']}\n" if WTString == "": WTString = "\u200b" ITString = "" for x in IT: x = json.loads(x) ITString += f"{x['type']}: {x['effectiveness']}\n" if ITString == "": ITString = "\u200b" RTString = "" for x in RT: x = json.loads(x) RTString += f"{x['type']}: {x['effectiveness']}\n" if RTString == "": RTString = "\u200b" em.add_field(name="Damaged normally by", value=DNBString) em.add_field(name="Weak to", value=WTString) em.add_field(name="Immune to", value=ITString) em.add_field(name="Resistant to", value=RTString) return em
async def poketype(self, ctx, *args): query = ''.join(args).lower() try: poke = pb.pokemon(query) except ValueError as e: await self.bot.say( f"Sorry, {ctx.message.author.mention}, {query} was not found.") return name = poke.name.capitalize() rawTypes = poke.types typeVals = {} noDamage = [] for i in rawTypes: typeName = i.type.name pokeType = pb.type_(typeName) rawDamage = pokeType.damage_relations rawNo = rawDamage.no_damage_from rawHalf = rawDamage.half_damage_from rawDoub = rawDamage.double_damage_from if len(rawNo) > 0: for j in rawNo: if j['name'] not in noDamage: noDamage.append(j['name'].capitalize()) if len(rawHalf) > 0: for j in rawHalf: if j['name'] not in typeVals.keys(): typeVals[j['name']] = -1 else: typeVals[j['name']] -= 1 if len(rawDoub) > 0: for j in rawDoub: if j['name'] not in typeVals.keys(): typeVals[j['name']] = 1 else: typeVals[j['name']] += 1 dubdub = [] dub = [] neg = [] negneg = [] for i in list(typeVals.keys()): tempVal = typeVals[i] if tempVal == 2: dubdub.append(i.capitalize()) elif tempVal == 1: dub.append(i.capitalize()) elif tempVal == -1: neg.append(i.capitalize()) elif tempVal == -2: negneg.append(i.capitalize()) spec = pb.pokemon_species(poke.id) color = self.hex_colors[spec.color.name] ico_url = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/items/poke-ball.png" embed = discord.Embed(colour=discord.Colour(color)) embed.set_thumbnail(url=poke.sprites.front_default) embed.set_author(name=f"{poke.name.capitalize()}, Pokémon #{poke.id}", url="https://pokeapi.co", icon_url=ico_url) embed.set_footer( text="All information is sourced from https://pokeapi.co/", icon_url=ico_url) if len(dubdub) > 0: embed.add_field(name="4x Damage", value=', '.join(dubdub), inline=False) if len(dub) > 0: embed.add_field(name="2x Damage", value=', '.join(dub), inline=False) if len(neg) > 0: embed.add_field(name=".5x Damage", value=', '.join(neg), inline=False) if len(negneg) > 0: embed.add_field(name=".25x Damage", value=', '.join(negneg), inline=False) if len(noDamage) > 0: embed.add_field(name="No Damage", value=', '.join(noDamage), inline=False) await self.bot.say(embed=embed)
def weakness(attack, defense): if type(defense) == list: total = 0 y = [] #print(defense) 3##333# for x in defense: #print(x) atk_type = pb.type_(attack) #print(atk_type) # Check which damage_relation list the defense is in. Matches by name if x in [ t["name"] for t in atk_type.damage_relations.no_damage_to ]: return 0.0 elif x in [ t["name"] for t in atk_type.damage_relations.half_damage_to ]: total += 0.5 y.append(0.5) elif x in [ t["name"] for t in atk_type.damage_relations.double_damage_to ]: total += 2.0 y.append(2.0) else: total += 1.0 y.append(1.0) #print(total) if total == 3.0 or 2.5: total = 2.0 if y[0] == 1.0 and y[1] == 1.0: total = 1.0 elif y[0] == 0.5 and y[1] == 0.5: total = 0.25 if y[0] == 2.0 and y[1] == 2.0: total = 4.0 if (y[0] == 1.0 and y[1] == 0.5 or y[0] == 0.5 and y[1] == 1.0): total = 0.5 if (y[0] == 2.0 and y[1] == 0.5 or y[0] == 0.5 and y[1] == 2.0): total = 1.0 return total else: atk_type = pb.type_(attack) if defense in [ t["name"] for t in atk_type.damage_relations.no_damage_to ]: return 0.0 elif defense in [ t["name"] for t in atk_type.damage_relations.half_damage_to ]: return 0.5 elif defense in [ t["name"] for t in atk_type.damage_relations.double_damage_to ]: return 2.0 else: return 1.0
def getWeakness(pokemon): pkmn = "" if isinstance(pokemon, str): pkmn = pb.pokemon(pokemon.lower().replace("'", "")) if isinstance(pokemon, int): pkmn = pb.pokemon(pokemon) em = discord.Embed() em.set_author(name=GG.cleanWordDash(pkmn.name)) em.set_thumbnail(url="http://play.pokemonshowdown.com/sprites/xyani/" + pkmn.name.lower() + ".gif") types = pkmn.types if len(types) == 2: type = GG.cleanWordDash(types[1].type.name) color = GG.getColorOfType(type.lower()) else: type = GG.cleanWordDash(types[0].type.name) color = GG.getColorOfType(type.lower()) DNB = [] USEDTYPES = [] WT1 = [] IT1 = [] RT1 = [] WT2 = [] IT2 = [] RT2 = [] WT = [] IT = [] RT = [] if len(types) == 2: type1_ = pb.type_(GG.cleanWordSpace(types[0].type.name)) for y in type1_.damage_relations.double_damage_from: WT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type1_.damage_relations.no_damage_from: IT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type1_.damage_relations.half_damage_from: RT1.append(f"{GG.cleanWordDash(y['name'])}") type2_ = pb.type_(GG.cleanWordSpace(types[1].type.name)) for y in type2_.damage_relations.double_damage_from: WT2.append(f"{GG.cleanWordDash(y['name'])}") for y in type2_.damage_relations.no_damage_from: IT2.append(f"{GG.cleanWordDash(y['name'])}") for y in type2_.damage_relations.half_damage_from: RT2.append(f"{GG.cleanWordDash(y['name'])}") else: type = pb.type_(GG.cleanWordSpace(type.name)) for y in type.damage_relations.double_damage_from: WT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type.damage_relations.no_damage_from: IT1.append(f"{GG.cleanWordDash(y['name'])}") for y in type.damage_relations.half_damage_from: RT1.append(f"{GG.cleanWordDash(y['name'])}") for x in WT1: if x in WT2: WT.append('{"type":"' + x + '","effectiveness":"4x"}') USEDTYPES.append(x.lower()) else: if x in RT2: DNB.append('{"type":"' + x + '","effectiveness":"1x"}') USEDTYPES.append(x.lower()) else: WT.append('{"type":"' + x + '","effectiveness":"2x"}') USEDTYPES.append(x.lower()) for x in WT2: if x not in WT1 and x not in RT1 and x not in IT1 and x not in IT2: WT.append('{"type":"' + x + '","effectiveness":"2x"}') USEDTYPES.append(x.lower()) for x in IT1: IT.append('{"type":"' + x + '","effectiveness":"0x"}') USEDTYPES.append(x.lower()) for x in IT2: IT.append('{"type":"' + x + '","effectiveness":"0x"}') USEDTYPES.append(x.lower()) for x in RT1: if x in RT2: RT.append('{"type":"' + x + '","effectiveness":"0.25x"}') USEDTYPES.append(x.lower()) else: if x in WT2: DNB.append('{"type":"' + x + '","effectiveness":"1x"}') USEDTYPES.append(x.lower()) else: RT.append('{"type":"' + x + '","effectiveness":"0.5x"}') USEDTYPES.append(x.lower()) for x in RT2: if x not in RT1 and x not in WT1 and x not in IT1 and x not in IT2: RT.append('{"type":"' + x + '","effectiveness":"0.5x"}') USEDTYPES.append(x.lower()) for x in GG.TYPES: if x not in USEDTYPES: DNB.append('{"type":"' + GG.cleanWordDash(x) + '","effectiveness":"1x"}') DNBString = "" for x in DNB: x = json.loads(x) DNBString += f"{x['type']}: {x['effectiveness']}\n" WTString = "" for x in WT: x = json.loads(x) WTString += f"{x['type']}: {x['effectiveness']}\n" ITString = "" for x in IT: x = json.loads(x) ITString += f"{x['type']}: {x['effectiveness']}\n" RTString = "" for x in RT: x = json.loads(x) RTString += f"{x['type']}: {x['effectiveness']}\n" em.add_field(name="Damaged normally by", value=DNBString) em.add_field(name="Weak to", value=WTString) em.add_field(name="Immune to", value=ITString) em.add_field(name="Resistant to", value=RTString) return em