def bone_prison_bone_spear(self): self.sleep(configuration.bone_prison_delay) if not self.is_in_range(self.target.id): print 'The player is no longer in range - unable to cast Bone Spear' self.reset_attack() return packets.cast_left_skill_at_target(0, self.target.id) self.town_portal()
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 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_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)