Exemplo n.º 1
0
class PacketGestion():
    def __init__(self, interface, socket_to_server):
        self.character = Character(interface, socket_to_server)
        self.interface = interface
        self.socket_to_server = socket_to_server
        self.interface.set_character(self.character)
        self.map_frame = MapFrame(interface, self.character)
        self.combat = Combat(self.map_frame)
        self.script = Script(self.character)

    def set_socket(self, socket_to_server):
        self.socket_to_server = socket_to_server
        self.character.set_socket(self.socket_to_server)
        #self.interface.ongletsMap.set_socket(self.socket_to_server)

    def server_packet(self, packet):

        #character information
        if packet[:3] == "ASK":
            info_perso = packet[3:].split("|")
            self.character.base(id_=info_perso[1],
                                pseudo=info_perso[2],
                                lvl=info_perso[3],
                                id_class=info_perso[4],
                                sexe=info_perso[5],
                                gfx=info_perso[6])
            self.interface.ongletsPersonnage.create_charater(
                self.character.gfx, self.character.pseudo, self.character.id_,
                self.character.lvl)
        #spell   (lvl,available spell...)
        elif packet[:2] == "SL" and packet[2:4] != "o+":
            spells_data = packet[2:].split(";")
            self.character.spells.update_spells(spells_data)
        #character stats (all stats pa, pm, res fix, rex....)
        elif packet[:2] == "As":
            self.character.character_stats(packet[2:].split("|"))
            self.interface.base_start(self.character)
            #self.map_frame.player_id = self.character.id_
            self.interface.ongletsPersonnage.create_label_caracteristique(
                self.character)

        #map information (mapid, date of creation,key)
        elif packet[:3] == "GDM":
            data = packet.split("|")
            mapID = data[1]
            map_date = data[2]
            decryption_key = data[3]
            self.character.map.data(mapID, map_date, decryption_key)
            self.interface.ongletsMap.print_map(self.character.map)
        #entity map information
        elif packet[:2] == "GM":
            self.map_frame.parse_data(packet)
        elif packet[:3] == "GDF" and len(packet) > 7:
            self.map_frame.update_interactive(packet)
        elif self.character.entity:
            if packet[:2] == "GA":
                self.map_frame.update_entity(packet)
            elif packet[:3] == "GIC":
                self.combat.mouv_start_cell(packet)
            elif packet[:2] == "GE":
                self.character.isfighting = False
            elif packet[:3] == "GTM":
                self.combat.update_carac_entity(packet)
            elif packet[:3] == "GTS":
                data = packet[3:].split("|")
                if data[0] == self.character.id_:
                    print("debut du tour...")
                    threading.Thread(None, self.combat.fight).start()
Exemplo n.º 2
0
class Gestion_Packet():
    def __init__(self):
        self.interface = Interface()
        self.map = None
        self.entitie = []
        self.map_frame = None

    def gestion_server(self, packet):
        self.entitie_remove = []

        #print("Server:" + packet)
        self.interface.print_richTextBox1("Server:" + packet)
        #character information
        if packet[:3] == "ASK":
            info_perso = packet[3:].split("|")
            self.character = Character(id_=info_perso[1],
                                       pseudo=info_perso[2],
                                       lvl=info_perso[3],
                                       id_class=info_perso[4],
                                       sexe=info_perso[5],
                                       gfx=info_perso[6])
            self.interface.create_charater(self.character.gfx,
                                           self.character.pseudo,
                                           self.character.id_,
                                           self.character.lvl)
        #spell   (lvl,available spell...)
        elif packet[:2] == "SL":
            spells_data = packet[2:].split(";")
            self.spells = Spells(self.interface, spells_data)
        #character stats (all stats pa, pm, res fix, rex....)
        elif packet[:2] == "As":
            self.character.character_stats(packet[2:].split("|"))
            self.interface.base_start(self.character)
            self.interface.create_label_caracteristique(self.character)
        #map information (mapid, date of creation,key)
        elif packet[:3] == "GDM":
            data = packet.split("|")
            self.mapID = data[1]
            self.map_date = data[2]
            self.decryption_key = data[3]
            self.entitie = []
            self.map = Map(self.mapID, self.map_date, self.decryption_key)
            self.interface.update_map(self.map)
        #character pods
        elif packet[:2] == "Ow":
            data = packet[2:].split("|")
            pods_actu = data[0]
            pods_max = data[1]
        #entity map information
        elif packet[:2] == "GM":
            #print(packet)
            self.map_frame = Map_Frame(packet, self.map, self.entitie,
                                       self.character.id_)
            self.entitie = self.map_frame.entities
            self.entitie_remove = self.map_frame.entities_remove
            #Enlever les try:exp... probleme avec les entities reglée
            self.interface.update_entity(self.entitie, self.entitie_remove)
        elif packet[:2] == "GA":
            print(packet)
            if packet != "GA;0" and packet[:3] != "GAS" and packet[:3] != "GAF":
                data = packet[2:].split(";")
                action_id = int(data[1])
                entity_id = int(data[2])

                #Travel on the map
                if action_id == 1:
                    cell = hash.get_Cell_Id_From_Hash(data[3][len(data[3]) -
                                                              2:])
                    for i in range(len(self.entitie)):
                        if entity_id == self.entitie[i].id:
                            self.entitie_remove.append(copy(self.entitie[i]))
                            self.entitie[i].cell = cell

                    if self.map_frame != None:
                        self.map_frame.update_entity(self.entitie,
                                                     self.entitie_remove)
                        self.entitie = self.map_frame.entities
                        self.entitie_remove = self.map_frame.entities_remove

                        self.interface.update_entity(self.entitie,
                                                     self.entitie_remove)

                #Le personnage recolte
                elif action_id == 501:
                    harvest_time = int(data[3].split(",")[1]) / 1000
                    cell_id = data[3].split(",")[0]
                    type_of_harvest = data[0]
                    print(
                        f"Le personnage recolte un resource sur la cellid {cell_id} temps d'attente {str(harvest_time)} s \n(type de resource = {type_of_harvest})"
                    )

        elif packet[:3] == "GDF":
            cells_id = self.map_frame.update_interactive(packet)
            self.interface.update_resource(cells_id)

        return packet

    def gestion_client(self, packet):
        #print("Client: "+packet)
        self.interface.print_richTextBox1("Client:" + packet)
        return packet