def summoner_thread(self): while True: player = utility.get_my_player() if player == None: #print 'No summoner unit' time.sleep(configuration.summoner_check_delay) continue break if player.name not in configuration.summoners: #print 'This is not a summoner' return while True: my_unit = utility.get_my_unit() if my_unit == None: print 'Unable to retrieve summoner unit' return standing_still = my_unit.mode == 1 if standing_still and not utility.town_check(): targets = self.get_targets() if len(targets) == 0: craw.print_text('There are no nearby corpses') else: target = random.choice(targets) description, skill = random.choice(skills) craw.print_text('%s: %08x' % (description, target)) packets.set_right_skill(skill) time.sleep(configuration.summoner_switch_delay) packets.cast_right_skill_at_target(1, target) time.sleep(configuration.summoner_cast_delay) continue time.sleep(configuration.summoner_check_delay)
def invite_all(): print 'Inviting all players' my_player = utility.get_my_player() players = craw.get_players() for player in players: if my_player.id == player.id: continue packets.invite_player(player.id)
def attack(self): if utility.town_check(): print 'You cannot attack other players in town.' return self.i = utility.get_my_player() target = self.get_target() if target == None: return self.target = target print 'Picked target %s' % target.name if target.id in self.movement: x, y = self.movement[target.id] print 'It is a moving target: %d, %d' % (x, y) bone_spirit_attack = self.left_skill == bone_spirit_skill and self.skill_check([bone_prison_skill, teleport_skill], attack_mode_bone_prison_bone_spirit_tppk) bone_spear_attack = self.left_skill == bone_spear_skill and self.skill_check([bone_prison_skill], attack_mode_bone_prison_bone_spear_tppk) foh_attack = self.left_skill == fist_of_heavens_skill and self.skill_check([fist_of_heavens_skill], attack_mode_fist_of_heavens_tppk) self.start_of_attack = time.time() if bone_spirit_attack or bone_spear_attack: self.debug('Setting the right skill to Bone Prison') packets.set_right_skill(bone_prison_skill) elif foh_attack: if craw.get_skill_level(teleport_skill) > 0: self.debug('Setting the right skill to teleport') packets.set_right_skill(teleport_skill) else: if utility.get_d2_distance(utility.get_my_player(), target) > configuration.fist_of_heavens_distance: print 'You are not in range for a Fist of Heavens attack' return self.debug('Casting Fist of Heavens at the target') packets.cast_left_skill_at_target(0, self.target.id) nil.thread.create_thread(lambda: self.town_portal(configuration.fist_of_heavens_delay)) else: print 'Performing default attack "%s"' % attack_mode_cast_left_skill packets.cast_left_skill_at_target(0, self.target.id)
def process_experience(self, experience_gained): player = utility.get_my_player() if player == None: return experience_for_this_level = experience_table[player.level - 1] experience_for_next_level = experience_table[player.level] current_experience = self.experience remaining_experience = experience_for_next_level - current_experience kills_required = int(math.ceil(float(remaining_experience) / experience_gained)) experience_difference = current_experience - experience_for_this_level experience_in_this_level = experience_for_next_level - experience_for_this_level progress = float(experience_difference) / experience_in_this_level * 100.0 self.experience += experience_gained if kills_required > configuration.experience_peanut_limit: return print 'Gained %d experience points, kill %d more of these (%.2f%%)' % (experience_gained, kills_required, progress)
def get_target(self): players = craw.get_players() my_player = utility.get_my_player() players = filter(lambda x: x.level >= 9 and x.x != 0 and x.id != my_player.id and not self.is_a_friend(x), players) players = map(lambda x: (utility.get_d2_distance(my_player, x), x), players) players = filter(lambda x: x[0] <= configuration.maximal_attack_distance, players) players.sort(cmp = utility.sort_units) if len(players) == 0: print 'There are no suitable targets in range.' return None print 'List of targets:' counter = 1 for distance, player in players: print '%d. %s: %.2f (%d, %d)' % (counter, player.name, distance, player.x, player.y) counter += 1 target = players[0][1] return target
def attack_thread(self): self.attack_print('Attack thread has been launched') while self.attacking: self.i = utility.get_my_player() if self.i == None: return my_unit = utility.get_my_unit() if my_unit == None: self.attack_print('Unable to retrieve unit') return standing_still = my_unit.mode == 1 if standing_still and not utility.town_check(): targets = self.get_targets() if len(targets) == 0: self.attack_print('No targets in range') pass else: self.attack_print('Targets in range:') for distance, id in targets: self.attack_print('%08x: %.1f' % (id, distance)) if targets[0][0] <= configuration.follower_defence_radius: #a monster got too close, kill it, quickly! target = targets[0][1] self.attack_print('Dangerous close proximity monster detected') else: index = random.randint(0, min(len(targets), configuration.follower_attack_maximal_randomisation_position) - 1) target = targets[index][1] self.attack_print('Attacking target %08x' % target) packets.cast_left_skill_at_target(1, target) else: self.attack_print('Not standing still (player mode is %d)' % my_unit.mode) pass time.sleep(configuration.follower_attack_delay)
def process_command(self, name, message): self.player = utility.get_player_data_by_name(name) self.my_player = utility.get_my_player() if self.player.id == self.my_player.id: return if self.player == None or self.my_player == None: return enchant_level = craw.get_skill_level(enchant_handler_class.enchant_skill) if enchant_level == None: print 'Unable to retrieve the enchant skill level' return if enchant_level == 0: print 'Unable to enchant - this character does not even have this skill!' return self.enchant_level = enchant_level self.mana = craw.get_mana() if self.mana == None: print 'Unable to retrieve mana' return if message == configuration.enchant_command: self.launch_function(self.enchant_player) elif message == configuration.enchant_minions_command: self.launch_function(self.enchant_minions) elif message == configuration.enchant_all_command: self.launch_function(self.enchant_all) elif message == configuration.enchant_players_command: self.launch_function(self.enchant_players)
def process_bytes(self, bytes): set_skill = packets.parse_set_skill(bytes) if set_skill != None: unit_type, unit_id, side, skill = set_skill #if unit_id == my_player.id: if side == 0x01: self.left_skill = skill #print 'Left skill is set to %02x' % skill my_player = utility.get_my_player() if my_player == None: return move = packets.parse_move(bytes) if move != None: player_id, x, y = move self.movement[player_id] = (x, y) stop = packets.parse_player_stop(bytes) if stop != None: unit_type, unit_id, x, y, life = stop try: del self.movement[unit_id] except KeyError: pass if set_skill != None: if self.attack_mode == attack_mode_bone_prison_bone_spirit_tppk and skill == teleport_skill: self.debug('Right skill has been changed, casting teleport for Bone Spirit attack') teleport_x = self.target.x + configuration.bone_spirit_teleport_offset[0] teleport_y = self.target.y + configuration.bone_spirit_teleport_offset[1] packets.cast_right_skill_at_location(teleport_x, teleport_y) elif self.attack_mode == attack_mode_fist_of_heavens_tppk and skill == teleport_skill: self.debug('Right skill has been changed, casting teleport for Fist of Heavens attack') packets.cast_right_skill_at_target(0, self.target.id) elif self.attack_mode == attack_mode_bone_prison_bone_spirit_tppk and skill == bone_prison_skill: self.debug('Right skill has been changed, casting Bone Prison for the Bone Spirit attack') packets.cast_right_skill_at_target(0, self.target.id) nil.thread.create_thread(self.bone_prison_teleport) elif self.attack_mode == attack_mode_bone_prison_bone_spear_tppk and skill == bone_prison_skill: self.debug('Right skill has been changed, casting Bone Prison for the Bone Spear attack') packets.cast_right_skill_at_target(0, self.target.id) nil.thread.create_thread(self.bone_prison_bone_spear) reassignment = packets.parse_reassignment(bytes) if reassignment != None: unit_type, unit_id, x, y, boolean = reassignment if self.attack_mode in [attack_mode_bone_prison_bone_spirit_tppk, attack_mode_fist_of_heavens_tppk] and my_player.id == unit_id: self.debug('Detected reassignment, performing attack') if not self.is_in_range(self.target.id): print 'The player is no longer in range - unable to cast Bone Spirit' self.reset_attack() return packets.cast_left_skill_at_target(0, self.target.id) if self.attack_mode == attack_mode_fist_of_heavens_tppk: nil.thread.create_thread(lambda: self.town_portal(configuration.fist_of_heavens_delay)) else: nil.thread.create_thread(self.town_portal) message = packets.parse_message(bytes) if self.start_of_attack != None and message != None: name, message = message if name != utility.get_my_name(): self.process_message(name, message)
def cast_right_skill(): player = utility.get_my_player() if player == None: return cast_right_skill_at_location(player.x, player.y)