示例#1
0
    def __init__(self, addr=None, socket=None):
        self.addr = addr
        self.socket = socket
        self.team = []
        self.i_battle_state = NOT_READY

        self.b_tmp = False

        self.i_turn_readiness = NOT_READY

        self.active_poke = None
        self.i_active_poke_idx = 0

        self.i_active_move_idx = -1

        self.b_active_poke_is_new = False

        self.b_healing_wish = False

        self.b_lunar_dance = False

        self.battle = None

        self.baton_pass_stats = Stats()

        self.friends = []
示例#2
0
 def get_stats_range(self):
     return Stats(), Stats()
示例#3
0
    def __init__(self, num=1):
        self.i_num = num

        dic_poke = json.load(
            open(dir_path + '/pokeinfo/pokemon/' + str(num) + '.txt'))

        self.str_name = dic_poke["name"]

        self.i_happy = 255
        self.b_shiny = False
        self.i_lv = 100
        self.str_gender = "gay"

        self.type_1 = Type(dic_poke["type1"])
        self.type_2 = None
        if "type2" in dic_poke:
            self.type_2 = Type(dic_poke["type2"])
        self.type_3 = None

        self.l_possible_abi = [dic_poke["ability1"]]
        if "ability2" in dic_poke:
            self.l_possible_abi.append(dic_poke["ability2"])
        if "hiddenability" in dic_poke:
            self.l_possible_abi.append(dic_poke["hiddenability"])

        self.str_ability = choice(self.l_possible_abi)
        self.str_nature = "error"
        self.str_item = "error"

        # status effect variables
        self.str_status = 'none'
        self.i_toxic_idx = 1
        self.i_sleep_counter = 0
        self.i_confusion_counter = 0

        self.l_possible_moves = []
        for dic_move in dic_poke["levelmoves"]:
            self.l_possible_moves.append(dic_move["move"])
        for dic_move in dic_poke["eggmoves"]:
            self.l_possible_moves.append(dic_move["move"])
        for dic_move in dic_poke["tutormoves"]:
            self.l_possible_moves.append(dic_move["move"])
        for dic_move in dic_poke["tmmoves"]:
            self.l_possible_moves.append(dic_move["move"])
        self.l_possible_moves = list(set(self.l_possible_moves))
        if "error" in self.l_possible_moves:
            self.l_possible_moves.remove("error")

        self.l_moves = [
            Move(choice(self.l_possible_moves)),
            Move(choice(self.l_possible_moves)),
            Move(choice(self.l_possible_moves)),
            Move(choice(self.l_possible_moves))
        ]

        self.f_height = (dic_poke["height"])
        self.f_weight = (dic_poke["weight"])

        self.base_stats = Stats()
        self.base_stats.i_hp = int(dic_poke["HP"])
        self.base_stats.i_atk = int(dic_poke["ATK"])
        self.base_stats.i_def = int(dic_poke["DEF"])
        self.base_stats.i_spa = int(dic_poke["SPA"])
        self.base_stats.i_spd = int(dic_poke["SPD"])
        self.base_stats.i_spe = int(dic_poke["SPE"])

        self.usable_stats = Stats()

        self.usable_stats.i_hp = (((
            (2 * self.base_stats.i_hp + 31 + int(88 / 4)) * 100)) / 100 + 100 +
                                  10)
        self.usable_stats.i_atk = ((
            (2 * self.base_stats.i_atk + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_def = ((
            (2 * self.base_stats.i_def + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_spa = ((
            (2 * self.base_stats.i_spa + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_spd = ((
            (2 * self.base_stats.i_spd + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_spe = ((
            (2 * self.base_stats.i_spe + 31 + int(84 / 4)) * 100) / 100 + 5)

        #self.ev_stats = Stats()
        #self.iv_stats = Stats()
        #self.nature_stats = Stats()

        self.i_evasion = 0
        self.i_accuracy = 0

        self.item_stats = Stats(0, 0, 0, 0, 0, 0)
        self.modifier_stats = Stats(0, 0, 0, 0, 0, 0)

        self.i_hp = self.get_usable_stats().i_hp

        self.b_fainted = False

        self.l_last_move = []

        # ad hoc variables

        self.b_disguise_broke = False

        self.b_recharging = False
        self.b_charging = False

        self.b_protected = False
        self.i_protect_counter = 0
        self.b_baneful_bunker = False

        self.b_need_to_switch = False

        self.b_aqua_ring = False

        self.b_trapped = False

        self.b_cursed = False

        self.b_destiny_bonded = False

        self.i_doom_desire_idx = -1

        self.forced_move_type = None

        self.i_encore_idx = -1

        self.b_endure_idx = False

        self.f_critical_hit = 1

        self.i_future_sight_idx = -1

        self.b_grudge = False

        self.b_instruct = False

        self.b_kings_shield = False

        self.b_laser_focus = False

        self.b_lock_on = False

        self.b_magic_coat = False

        self.b_magnet_rise = 0

        self.b_perfect_aim = False

        self.b_powdered = False

        self.b_lunar_dance = False

        self.b_spiky_shield = False
示例#4
0
class Pokeman(object):
    def __init__(self, num=1):
        self.i_num = num

        dic_poke = json.load(
            open(dir_path + '/pokeinfo/pokemon/' + str(num) + '.txt'))

        self.str_name = dic_poke["name"]

        self.i_happy = 255
        self.b_shiny = False
        self.i_lv = 100
        self.str_gender = "gay"

        self.type_1 = Type(dic_poke["type1"])
        self.type_2 = None
        if "type2" in dic_poke:
            self.type_2 = Type(dic_poke["type2"])
        self.type_3 = None

        self.l_possible_abi = [dic_poke["ability1"]]
        if "ability2" in dic_poke:
            self.l_possible_abi.append(dic_poke["ability2"])
        if "hiddenability" in dic_poke:
            self.l_possible_abi.append(dic_poke["hiddenability"])

        self.str_ability = choice(self.l_possible_abi)
        self.str_nature = "error"
        self.str_item = "error"

        # status effect variables
        self.str_status = 'none'
        self.i_toxic_idx = 1
        self.i_sleep_counter = 0
        self.i_confusion_counter = 0

        self.l_possible_moves = []
        for dic_move in dic_poke["levelmoves"]:
            self.l_possible_moves.append(dic_move["move"])
        for dic_move in dic_poke["eggmoves"]:
            self.l_possible_moves.append(dic_move["move"])
        for dic_move in dic_poke["tutormoves"]:
            self.l_possible_moves.append(dic_move["move"])
        for dic_move in dic_poke["tmmoves"]:
            self.l_possible_moves.append(dic_move["move"])
        self.l_possible_moves = list(set(self.l_possible_moves))
        if "error" in self.l_possible_moves:
            self.l_possible_moves.remove("error")

        self.l_moves = [
            Move(choice(self.l_possible_moves)),
            Move(choice(self.l_possible_moves)),
            Move(choice(self.l_possible_moves)),
            Move(choice(self.l_possible_moves))
        ]

        self.f_height = (dic_poke["height"])
        self.f_weight = (dic_poke["weight"])

        self.base_stats = Stats()
        self.base_stats.i_hp = int(dic_poke["HP"])
        self.base_stats.i_atk = int(dic_poke["ATK"])
        self.base_stats.i_def = int(dic_poke["DEF"])
        self.base_stats.i_spa = int(dic_poke["SPA"])
        self.base_stats.i_spd = int(dic_poke["SPD"])
        self.base_stats.i_spe = int(dic_poke["SPE"])

        self.usable_stats = Stats()

        self.usable_stats.i_hp = (((
            (2 * self.base_stats.i_hp + 31 + int(88 / 4)) * 100)) / 100 + 100 +
                                  10)
        self.usable_stats.i_atk = ((
            (2 * self.base_stats.i_atk + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_def = ((
            (2 * self.base_stats.i_def + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_spa = ((
            (2 * self.base_stats.i_spa + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_spd = ((
            (2 * self.base_stats.i_spd + 31 + int(84 / 4)) * 100) / 100 + 5)
        self.usable_stats.i_spe = ((
            (2 * self.base_stats.i_spe + 31 + int(84 / 4)) * 100) / 100 + 5)

        #self.ev_stats = Stats()
        #self.iv_stats = Stats()
        #self.nature_stats = Stats()

        self.i_evasion = 0
        self.i_accuracy = 0

        self.item_stats = Stats(0, 0, 0, 0, 0, 0)
        self.modifier_stats = Stats(0, 0, 0, 0, 0, 0)

        self.i_hp = self.get_usable_stats().i_hp

        self.b_fainted = False

        self.l_last_move = []

        # ad hoc variables

        self.b_disguise_broke = False

        self.b_recharging = False
        self.b_charging = False

        self.b_protected = False
        self.i_protect_counter = 0
        self.b_baneful_bunker = False

        self.b_need_to_switch = False

        self.b_aqua_ring = False

        self.b_trapped = False

        self.b_cursed = False

        self.b_destiny_bonded = False

        self.i_doom_desire_idx = -1

        self.forced_move_type = None

        self.i_encore_idx = -1

        self.b_endure_idx = False

        self.f_critical_hit = 1

        self.i_future_sight_idx = -1

        self.b_grudge = False

        self.b_instruct = False

        self.b_kings_shield = False

        self.b_laser_focus = False

        self.b_lock_on = False

        self.b_magic_coat = False

        self.b_magnet_rise = 0

        self.b_perfect_aim = False

        self.b_powdered = False

        self.b_lunar_dance = False

        self.b_spiky_shield = False

    def pre_turn(self):
        if self.b_magnet_rise > 0:
            self.b_magnet_rise -= 1
        for move in self.l_moves:
            if move.i_disable_idx > 0:
                move.i_disable_idx -= 1
            if self.i_encore_idx > 0:
                self.i_encore_idx -= 1

    def get_last_move(self):
        if len(self.l_last_move) > 1:
            return self.l_last_move[-1]
        return Move("tackle")

    def get_moves(self):
        l_possible_moves = []

        for move in self.l_moves:
            #print(move.i_disable_idx,move.i_pp)
            if move.i_disable_idx > 0:
                continue
            if move.i_pp <= 0:
                continue
            l_possible_moves.append(move)

        if self.i_encore_idx > 0:
            l_possible_moves = [self.get_last_move()]

        if len(l_possible_moves) == 0:
            tmp_move = Move("struggle")
            tmp_move.i_max_pp = 1337
            tmp_move.i_pp = 1337
            l_possible_moves.append(tmp_move)

        return l_possible_moves

    def get_move_dic(self):
        l_possible_moves = self.get_moves()
        dic_moves = []
        for move in l_possible_moves:
            dic_moves.append(move.to_dic())
        return dic_moves

    def get_stats_range(self):
        return Stats(), Stats()

    def get_usable_stats(self):
        #print(self.modifier_stats.i_hp,self.modifier_stats.get_modifier_rates().i_hp)
        actually_usable_stats = self.usable_stats * self.modifier_stats.get_modifier_rates(
        )

        if self.str_status == "paralyze":
            actually_usable_stats.i_spe = actually_usable_stats.i_spe // 2

        return actually_usable_stats

    def is_type(self, str_type):
        if self.type_1.str_name == str_type:
            return True
        if self.type_2 == None:
            return False
        if self.type_2.str_name == str_type:
            return True
        return False

    def to_dic(self):
        dic_poke = {}

        dic_poke["num"] = self.i_num
        dic_poke["name"] = self.str_name

        dic_poke["status"] = self.str_status

        dic_poke["statchange"] = []
        if self.modifier_stats.i_atk != 0:
            dic_poke["statchange"].append("atk " +
                                          str(self.modifier_stats.i_atk))
        if self.modifier_stats.i_def != 0:
            dic_poke["statchange"].append("def " +
                                          str(self.modifier_stats.i_def))
        if self.modifier_stats.i_spa != 0:
            dic_poke["statchange"].append("spa " +
                                          str(self.modifier_stats.i_spa))
        if self.modifier_stats.i_spd != 0:
            dic_poke["statchange"].append("spd " +
                                          str(self.modifier_stats.i_spd))
        if self.modifier_stats.i_spe != 0:
            dic_poke["statchange"].append("spe " +
                                          str(self.modifier_stats.i_spe))

        #print(self.modifier_stats.to_dic({}),dic_poke["statchange"])

        self.get_usable_stats().to_dic(dic_poke, "base")

        dic_poke['hap'] = self.i_happy
        dic_poke['shiny'] = self.b_shiny
        dic_poke['lv'] = self.i_lv
        dic_poke['gender'] = self.str_gender

        dic_poke['type1'] = self.type_1.getName()
        if self.type_2 != None:
            dic_poke['type2'] = self.type_2.getName()

        dic_poke['ability'] = self.str_ability
        dic_poke['item'] = self.str_item

        l_tmp_move_dic = []
        for move in self.l_moves:
            l_tmp_move_dic.append(move.to_dic())
            #print(str(move))
        dic_poke['moves'] = l_tmp_move_dic

        dic_poke['eva'] = self.i_evasion

        dic_poke['hp'] = self.i_hp

        dic_poke['faint'] = self.b_fainted

        dic_poke['protect'] = self.b_protected

        return dic_poke

    # overriding str method
    def __str__(self):
        return self.str_name

    def is_usable(self):
        if self.b_endure_idx and self.i_hp <= 0:
            self.i_hp = 1

        if self.i_hp <= 0:
            self.i_hp = 0
            self.b_fainted = True
        return not self.b_fainted

    def is_trapped(self):
        return self.b_trapped
示例#5
0
    def __init__(self, name="tackle"):
        if name == None or name == "":
            name = "error"

        self.str_name = name

        dic_move = json.load(open(dir_path + '/pokeinfo/move/' + name +
                                  '.txt'))

        self.str_type = dic_move['type']
        self.str_cat = dic_move['cat']

        self.type = Type(self.str_type)

        self.i_pow = parse_move_json(dic_move['power'])
        self.i_acc = parse_move_json(dic_move['acc'])
        if self.i_acc == 0:
            self.i_acc = 100

        self.i_max_pp = parse_move_json(dic_move['pp'])
        self.i_pp = self.i_max_pp

        self.i_prob = parse_move_json(dic_move['prob'])

        self.i_priority = 0

        if self.str_name in ["helping-hand"]:
            self.i_priority = 5
        elif self.str_name in ["detect", "magic-coat", "protect", "snatch"]:
            self.i_priority = 4
        elif self.str_name in [
                "crafty-shield", "fake-out", "quick-guard", "wide-guard",
                "spotlight"
        ]:
            self.i_priority = 3
        elif self.str_name in [
                "ally-switch", "extreme-speed", "feint", "first-impression",
                "follow-me", "rage-powder"
        ]:
            self.i_priority = 2
        elif self.str_name in [
                "accelerock", "aqua-jet", "baby-doll-eyes", "bide",
                "bullet-punch", "ice-shard", "ion-deluge", "mach-punch",
                "powder", "quick-attack", "shadow-sneak", "sucker-punch",
                "vacuum-wave", "water-shuriken"
        ]:
            self.i_priority = 1
        elif self.str_name in ["vital-throw"]:
            self.i_priority = -1
        elif self.str_name in ["beak-blast", "focus-punch", "shell-trap"]:
            self.i_priority = -3
        elif self.str_name in ["avalanche", "revenge"]:
            self.i_priority = -4
        elif self.str_name in ["counter", "mirror-coat"]:
            self.i_priority = -5
        elif self.str_name in [
                "circle-throw", "dragon-tail", "roar", "whirlwind"
        ]:
            self.i_priority = -6
        elif self.str_name in ["trick-room"]:
            self.i_priority = -7

        #print(name)
        self.flag_contact = dic_move['flag_contact']
        self.flag_charge = dic_move['flag_charge']
        self.flag_recharge = dic_move['flag_recharge']
        self.flag_protect = dic_move['flag_protect']
        self.flag_reflectable = dic_move['flag_reflectable']
        self.flag_snatch = dic_move['flag_snatch']
        self.flag_mirror = dic_move['flag_mirror']
        self.flag_punch = dic_move['flag_punch']
        self.flag_sound = dic_move['flag_sound']
        self.flag_gravity = dic_move['flag_gravity']
        self.flag_defrost = dic_move['flag_defrost']
        self.flag_distance = dic_move['flag_distance']
        self.flag_heal = dic_move['flag_heal']
        self.flag_authentic = dic_move['flag_authentic']
        self.flag_powder = dic_move['flag_powder']
        self.flag_bite = dic_move['flag_bite']
        self.flag_pulse = dic_move['flag_pulse']
        self.flag_ballistics = dic_move['flag_ballistics']
        self.flag_mental = dic_move['flag_mental']
        self.flag_non_sky_battle = dic_move['flag_non-sky-battle']
        self.flag_dance = dic_move['flag_dance']

        self.str_anime_style = self.str_cat
        if self.flag_punch:
            self.str_anime_style = "flag_punch"
        if self.flag_sound:
            self.str_anime_style = "flag_sound"
        if self.flag_bite:
            self.str_anime_style = "flag_bite"
        if self.str_name in [
                "spikes", "stealth-rock", "toxic-spikes", "sticky-web"
        ]:
            self.str_anime_style = self.str_name

        self.b_stat_change = False
        if 'stacha' in dic_move:
            self.b_stat_change = True
            self.i_stat_change_chance = dic_move['stacha']

            self.users_stat_changes = Stats(dic_move['ihp'], dic_move['iatk'],
                                            dic_move['idef'], dic_move['ispa'],
                                            dic_move['ispd'], dic_move['ispe'])
            self.targets_stat_changes = Stats(
                dic_move['uhp'], dic_move['uatk'], dic_move['udef'],
                dic_move['uspa'], dic_move['uspd'], dic_move['uspe'])

            #print(name,"hey")

        self.b_status_effect = False
        if 'effcha' in dic_move:
            self.b_status_effect = True
            self.i_status_effect_chance = dic_move['effcha']
            self.str_status_effect = dic_move['eff']

        self.i_disable_idx = 0
示例#6
0
    def recieved_data(self, str_data):

        try:
            dic_data = json.loads(str_data.decode("utf-8"))
        except:
            print("Woah Error!")
            print(str_data.decode("utf-8"))
            return

        if dic_data["battlestate"] == "pokes":
            self.team = []
            for dic_poke in dic_data["pokes"]:
                poke = Pokeman(dic_poke["num"])

                poke.str_name = dic_poke["name"]

                poke.usable_stats = Stats(dic_poke['hp'], dic_poke['atk'],
                                          dic_poke['def'], dic_poke['spa'],
                                          dic_poke['spd'], dic_poke['spe'])

                #print(poke.str_name,poke.usable_stats.to_dic({}))

                poke.i_happy = dic_poke['hap']
                poke.i_lv = dic_poke['lv']
                poke.b_shiny = dic_poke['shiny']

                poke.l_moves = []
                for dic_move in dic_poke['moves']:
                    poke.l_moves.append(Move(dic_move))

                poke.i_hp = poke.get_usable_stats().i_hp

                #print("hey hey hey ", poke.get_usable_stats().i_atk)

                self.team.append(poke)
            self.i_battle_state = READY
            self.i_turn_readiness = READY
        elif dic_data["battlestate"] == "selectpoke":
            self.i_active_poke_idx = dic_data["poke"]
            self.active_poke = self.team[self.i_active_poke_idx]
            self.b_active_poke_is_new = True
            self.active_poke.modifier_stats = self.baton_pass_stats.get_copy()
            self.baton_pass_stats = Stats()

            if self.b_healing_wish or self.b_lunar_dance:
                self.b_healing_wish = False
                self.b_lunar_dance = False
                self.active_poke.i_hp = self.active_poke.get_usable_stats(
                ).i_hp
                self.str_status = "none"

            #print(dic_data["poke"])
            self.i_turn_readiness = READY
        elif dic_data["battlestate"] == "selectmove":
            self.i_active_move_idx = dic_data["move"]
            self.i_turn_readiness = READY
        elif dic_data["battlestate"] == "selectpass":
            self.i_turn_readiness = READY
        elif dic_data["battlestate"] == "pokewrite":
            file_in = open(dir_path + '/pokeSave.txt', 'r')
            sentPokes = file_in.read()
            file_in.close()
            loaded_pokes = json.loads(sentPokes)
            loaded_pokes[dic_data['username']] = dic_data["pokes"]
            sentPokes = json.dumps(loaded_pokes)
            file_in = open(dir_path + '/pokeSave.txt', 'w')
            file_in.write(sentPokes)
            file_in.close()

        elif dic_data["battlestate"] == "pokeread":
            file_in = open(dir_path + '/pokeSave.txt', 'r')
            sentPokes = file_in.read()
            file_in.close()

            loaded_pokes = json.loads(sentPokes)
            if dic_data['username'] in loaded_pokes:
                self.send_data(
                    "z" +
                    json.dumps({"pokes": loaded_pokes[dic_data['username']]}))
            else:
                self.send_data("badUserDic")
        elif dic_data["battlestate"] == "addfriend":
            file_in = open('friendList.txt', 'r')
            friendList = file_in.read()
            file_in.close()
            loaded_friends = json.loads(friendList)
            if dic_data["username"] in loaded_friends:
                self.friends = loaded_friends[dic_data["username"]]
                if dic_data["newfriend"] not in self.friends:
                    self.friends.append(dic_data["newfriend"])
                    loaded_friends[dic_data['username']] = self.friends
                    friendList = json.dumps(loaded_friends)
                    file_in = open('friendList.txt', 'w')
                    file_in.write(friendList)
                    file_in.close()
        elif dic_data["battlestate"] == "removefriend":
            file_in = open('friendList.txt', 'r')
            friendList = file_in.read()
            file_in.close()
            loaded_friends = json.loads(friendList)
            print(self.friends)
            print()
            if dic_data["username"] in loaded_friends:
                print("good 1")
                self.friends = loaded_friends[dic_data["username"]]
                if dic_data["newfriend"] in self.friends:
                    print("good2")
                    self.friends.remove(dic_data["newfriend"])
                    loaded_friends[dic_data['username']] = self.friends
                    friendList = json.dumps(loaded_friends)
                    file_in = open('friendList.txt', 'w')
                    file_in.write(friendList)
                    file_in.close()
                    sendingFriends = json.dumps(self.friends)
                    self.send_data("x" + sendingFriends)
            print()
            print(dic_data["newfriend"])
            print()
            print(self.friends)
        elif dic_data["battlestate"] == "friendread":
            file_in = open('friendList.txt', 'r')
            friendList = file_in.read()
            file_in.close()
            loaded_friends = json.loads(friendList)
            if dic_data['username'] in loaded_friends:
                self.friends = loaded_friends[dic_data['username']]
                sendingFriends = json.dumps(self.friends)
                self.send_data("x" + sendingFriends)
            else:
                self.send_data("badUserDic")
        elif dic_data["battlestate"] == "loadall":
            file_in = open('friendList.txt', 'r')
            friendList = file_in.read()
            file_in.close()
            loaded_friends = json.loads(friendList)

            if dic_data['username'] in loaded_friends:
                self.friends = loaded_friends[dic_data['username']]
                sendingFriends = self.friends
            else:
                sendingFriends = []

            file_in = open(dir_path + '/pokeSave.txt', 'r')
            sentPokes = file_in.read()
            file_in.close()

            loaded_pokes = json.loads(sentPokes)

            if dic_data['username'] in loaded_pokes:
                sendingPokes = {"pokes": loaded_pokes[dic_data['username']]}
            else:
                sendingPokes = {"pokes": []}

            sendingAll = json.dumps({
                "friends": sendingFriends,
                "pokemon": sendingPokes
            })

            self.send_data("y" + sendingAll)
        elif dic_data["battlestate"] == "login":
            file_in = open('usernames.txt', 'r')
            usernamelst = file_in.read()
            usernamelst = usernamelst.split('*')
            file_in.close()
            file_in = open('passwords.txt', 'r')
            passwordlst = file_in.read()
            passwordlst = passwordlst.split('*')
            file_in.close()
            print(passwordlst)
            if dic_data['username'] in usernamelst and encrypt(
                    dic_data['password']) in passwordlst:
                if len(dic_data['username']) > 0 and len(
                        dic_data['password']) > 0:
                    if usernamelst.index(
                            dic_data['username']) == passwordlst.index(
                                encrypt(dic_data['password'])):
                        self.send_data('ltrue')
                    else:
                        self.send_data('lfalse')
                else:
                    self.send_data('lfalse')
            else:
                self.send_data('lfalse')
        elif dic_data["battlestate"] == "register":
            file_in = open('usernames.txt', 'r')
            usernamelst = file_in.read()
            usernamelst = usernamelst.split('*')
            file_in.close()
            if dic_data['username'] not in usernamelst and len(
                    dic_data['username']) > 0 and len(
                        dic_data['password']) > 0:
                file_out = open('usernames.txt', "a")
                file_out.write('*')
                file_out.write(
                    dic_data['username']
                )  # 2. Convert the info to string and write in the file
                file_out.close()
                file_out = open('passwords.txt', "a")
                file_out.write('*')
                file_out.write(
                    encrypt(dic_data['password'])
                )  # 2. Convert the info to string and write in the file
                file_out.close()
                self.send_data('ltrue')
            else:
                self.send_data('lfalse')
        elif dic_data["battlestate"] == "command":
            l_words = dic_data["command"].split()
            if l_words[0] == "weakness":
                try:
                    str_poke_name = l_words[1]
                    tmp_poke = Pokeman(dic_name_to_num[str_poke_name])
                    self.send_data(DISPLAY_TEXT + str_poke_name + ":")
                    self.send_data(
                        DISPLAY_TEXT + "Very Weak: " + join_with_none(
                            get_def_types_with_eff_rate(
                                4, tmp_poke.type_1, tmp_poke.type_2)))
                    self.send_data(DISPLAY_TEXT + "Weak: " + join_with_none(
                        get_def_types_with_eff_rate(2, tmp_poke.type_1,
                                                    tmp_poke.type_2)))
                    self.send_data(DISPLAY_TEXT + "Resist: " + join_with_none(
                        get_def_types_with_eff_rate(0.5, tmp_poke.type_1,
                                                    tmp_poke.type_2)))
                    self.send_data(
                        DISPLAY_TEXT + "Very Resist: " + join_with_none(
                            get_def_types_with_eff_rate(
                                0.25, tmp_poke.type_1, tmp_poke.type_2)))
                    self.send_data(DISPLAY_TEXT + "Immune: " + join_with_none(
                        get_def_types_with_eff_rate(0, tmp_poke.type_1,
                                                    tmp_poke.type_2)))

                except:
                    self.send_data(
                        DISPLAY_TEXT +
                        "Error: Invalid Arguments 3006. Please contact support with the error code at [email protected]."
                    )
            elif l_words[0] == "data":
                try:
                    str_poke_name = l_words[1]
                    tmp_poke = Pokeman(dic_name_to_num[str_poke_name])
                    self.send_data(DISPLAY_TEXT + str_poke_name + ":")
                    self.send_data(DISPLAY_TEXT + "HP: " +
                                   str(tmp_poke.base_stats.get_hp()))
                    self.send_data(DISPLAY_TEXT + "ATK: " +
                                   str(tmp_poke.base_stats.get_atk()))
                    self.send_data(DISPLAY_TEXT + "DEF: " +
                                   str(tmp_poke.base_stats.get_def()))
                    self.send_data(DISPLAY_TEXT + "SPA: " +
                                   str(tmp_poke.base_stats.get_spa()))
                    self.send_data(DISPLAY_TEXT + "SPD: " +
                                   str(tmp_poke.base_stats.get_spd()))
                    self.send_data(DISPLAY_TEXT + "SPE: " +
                                   str(tmp_poke.base_stats.get_spe()))

                except:
                    self.send_data(
                        DISPLAY_TEXT +
                        "Error: Invalid Arguments 3006. Please contact support with the error code at [email protected]."
                    )
            elif l_words[0] == "strongness":
                try:
                    str_poke_name = l_words[1]
                    self.send_data(DISPLAY_TEXT + "strong")
                except:
                    self.send_data(
                        DISPLAY_TEXT +
                        "Error: Invalid Arguments 3007. Please contact support with the error code at [email protected]."
                    )
            else:
                self.send_data(
                    DISPLAY_TEXT +
                    "Error: Invalid Command 3009. Please contact support with the error code at [email protected]."
                )

        if self.battle != None:
            self.battle.recieved_data(self, dic_data)