def hostility_check(self, bytes): if len(bytes) < 10 or bytes[0] != 0x8c: return player_id_1 = utility.read_bytes(bytes, 1, 4) player_id_2 = utility.read_bytes(bytes, 5, 4) my_id = craw.get_player_id() if my_id == None: return if player_id_1 != my_id: return if bytes[9] < 0x08: return for hostility_handler in self.hostility_handlers: hostility_handler() in_town = utility.town_check() if in_town == None: return if not in_town and configuration.chicken_on_hostile: player_name = craw.get_name_by_id(player_id_2) if player_name == None: print 'Leaving the game because an unknown player has declared hostility against us' else: print 'Leaving the game because player %s has declared hostility against us' % player_name craw.leave_game()
def parse_move(bytes): if len(bytes) < 11 or bytes[0] != 0x0F: return None player_id = utility.read_bytes(bytes, 2, 4) x = utility.read_bytes(bytes, 7, 2) y = utility.read_bytes(bytes, 9, 2) return player_id, x, y
def object_assignment(bytes): if len(bytes) < 12 or bytes[0] != 0x51: return None object_type = bytes[1] object_id = utility.read_bytes(bytes, 2, 4) object_code = utility.read_bytes(bytes, 6, 2) x = utility.read_bytes(bytes, 8, 2) y = utility.read_bytes(bytes, 10, 2) return object_type, object_id, object_code, x, y
def parse_npc_move(bytes): if len(bytes) < 10 or bytes[0] not in [0x67, 0x68]: return None unit_id = utility.read_bytes(bytes, 1, 4) running = bytes[5] in [0x17, 0x18] x = utility.read_bytes(bytes, 6, 2) y = utility.read_bytes(bytes, 8, 2) return unit_id, running, x, y
def parse_set_skill(bytes): if len(bytes) < 13 or bytes[0] != 0x23: return None unit_type = bytes[1] unit_id = utility.read_bytes(bytes, 2, 4) side = bytes[6] skill = utility.read_bytes(bytes, 7, 2) return unit_type, unit_id, side, skill
def parse_join(bytes): if len(bytes) < 26 or bytes[0] != 0x5B: return None player_id = utility.read_bytes(bytes, 3, 4) player_name = utility.read_name(bytes, 8) character_class = bytes[7] level = utility.read_bytes(bytes, 24, 2) return player_id, player_name, character_class, level
def parse_reassignment(bytes): if len(bytes) < 11 or bytes[0] != 0x15: return None unit_type = bytes[1] unit_id = utility.read_bytes(bytes, 2, 4) x = utility.read_bytes(bytes, 6, 2) y = utility.read_bytes(bytes, 8, 2) boolean = bytes[10] return unit_type, unit_id, x, y, boolean
def parse_player_stop(bytes): if len(bytes) < 13 or bytes[0] != 0x0D: return None unit_type = bytes[1] unit_id = utility.read_bytes(bytes, 2, 4) x = utility.read_bytes(bytes, 7, 2) y = utility.read_bytes(bytes, 9, 2) life = bytes[12] return unit_type, unit_id, x, y, life
def parse_assignment(bytes): if len(bytes) < 26 or bytes[0] != 0x59: return None player_id = utility.read_bytes(bytes, 1, 4) character_class = bytes[5] player_name = utility.read_name(bytes, 6) x = utility.read_bytes(bytes, 22, 2) y = utility.read_bytes(bytes, 24, 2) return player_id, character_class, player_name, x, y
def parse_npc_assignment(bytes): if len(bytes) < 10 or bytes[0] != 0xAC: return None unit_id = utility.read_bytes(bytes, 1, 4) unit_code = utility.read_bytes(bytes, 5, 2) x = utility.read_bytes(bytes, 7, 2) y = utility.read_bytes(bytes, 7, 2) life = bytes[9] return unit_id, unit_code, x, y, life
def assign_mercenary(bytes): if len(bytes) != 20 or bytes[0] != 0x81: return None type = utility.read_bytes(bytes, 2, 2) try: mercenary_act = utility.mercenary_map[type] except KeyError: mercenary_act = None owner_id = utility.read_bytes(bytes, 4, 4) mercenary_id = utility.read_bytes(bytes, 8, 4) return mercenary_act, owner_id, mercenary_id
def parse_add_unit(bytes): if len(bytes) < 7 or bytes[0] != 0xAA: return None unit_type = bytes[1] unit_id = utility.read_bytes(bytes, 2, 4) return unit_type, unit_id
def object_removal(bytes): if len(bytes) != 6 or bytes[0] != 0x0A: return None type = bytes[1] id = utility.read_bytes(bytes, 2, 4) return type, id
def game_flags(bytes): if len(bytes) < 8 or bytes[0] != 0x01: return None difficulty = bytes[1] hardcore = utility.read_bytes(bytes, 4, 2) expansion = bytes[6] ladder = bytes[7] return difficulty, hardcore, expansion, ladder
def process_bytes(self, bytes): experience_formats = [ (0x1a, 1), (0x1b, 2) ] self.experience = craw.get_experience() if self.experience == None: return elif len(bytes) >= 5 and bytes[0] == 0x1c: new_experience = utility.read_bytes(bytes, 1, 4) self.process_experience(new_experience - self.experience) else: for identifier, size in experience_formats: if len(bytes) >= 1 + size and bytes[0] == identifier: experience_gained = utility.read_bytes(bytes, 1, size) self.process_experience(experience_gained) break
def life_check(self, bytes): if len(bytes) < 3: return configuration.chicken_data = craw.get_life() if configuration.chicken_data == None: return current_life, maximal_life = configuration.chicken_data if maximal_life > 0 and maximal_life < self.last_maximal_life and self.last_maximal_life != None: craw.print_text('Warning: Maximal life decreased to %d' % maximal_life) self.last_maximal_life = maximal_life if bytes[0] not in [0x18, 0x95]: return new_life = utility.read_bytes(bytes, 1, 2) & 0x7fff if new_life >= current_life: return damage = current_life - new_life ratio = float(new_life) / maximal_life percent = '%.2f%%' % (ratio * 100) if new_life == maximal_life: #hack for a strange bug return #print time.time() print '%d damage, %d/%d left (%s)' % (damage, new_life, maximal_life, percent) for damage_handler in self.damage_handlers: damage_handler(damage, (new_life, maximal_life)) if new_life <= 0: print 'I am dead.' return in_town = utility.town_check() if in_town == None: return if not in_town and configuration.chicken and ratio <= configuration.chicken_ratio: print 'Leaving the game because the chicken life ratio has been reached' craw.leave_game()
def portal_ownership(bytes): if len(bytes) < 29 or bytes[0] != 0x82: return None player_id = utility.read_bytes(bytes, 1, 4) portal_id = utility.read_bytes(bytes, 21, 4) return (player_id, portal_id)
def parse_invitiation(bytes): if len(bytes) < 6 or bytes[0] != 0x8B or bytes[5] != 0x02: return None player_id = utility.read_bytes(bytes, 1, 4) return player_id