def find_land_resource(map, position, ids, exhaust_db=None, func=None): spiral = Spiral(position.x / 8, position.y / 8) while True: if exhaust_db is None or not exhaust_db.is_exhausted( spiral.x, spiral.y): block = map.statics.load_block(spiral.x, spiral.y) if block is not None: for item_id, x, y, z, hue in block: if (item_id | 0x4000) in ids and \ (func is None or func(id, spiral.x * 8 + x, spiral.y * 8 + y, z)): return Target(x=spiral.x * 8 + x, y=spiral.y * 8 + y, z=z, graphic=item_id) block = map.land.load_block(spiral.x, spiral.y) if block is None: continue for x in range(8): for y in range(8): item_id = block.get_id(x, y) if item_id not in ids: continue z = block.get_height(x, y) if func is None or func(item_id, spiral.x * 8 + x, spiral.y * 8 + y, z): return Target(x=spiral.x * 8 + x, y=spiral.y * 8 + y, z=z) spiral.step()
def on_packet(self, packet): if isinstance(packet, p.TargetRequest): self.target_request = packet elif isinstance(packet, p.WorldItem): if self.target_request is not None: if packet.item_id == ITEM_GATE: self.target = Target(packet.serial, packet.x, packet.y, packet.z, packet.item_id) self._client.send( self.target.response(self.target_request.target_id, self.target_request.flags)) self._success()
def target_ok(self): client = self._client client.send(p.Use(self.crook.serial)) self.engine = SendTarget(client, Target(serial=self.target.serial)) d = self.engine.deferred d.addCallbacks(self._target_sent, self._target_failed)
def _target_ok(self): self._client.send(p.Cast(self.spell)) self.engine = SendTarget(self._client, Target(serial=self.target.serial)) self.engine.deferred.addCallbacks(self._target_sent, self._target_failed)
def _equipped(self, result): tree = reachable_resource(self.player.position, self.trees, 2) if tree is None: print "No tree??" reactor.callLater(0.5, self._walk) return tree = Target(x=tree.x, y=tree.y, z=tree.z, graphic=tree.item_id) d = Lumber(self._client, self.map, tree, self.exhaust_db).deferred d.addCallbacks(self._lumbered, self._success)
def find_reachable_target(map, world, ids): item = world.find_reachable_item(lambda x: x.item_id in ids) if item is not None: return item position = world.player.position static = find_static_near(map, position.x, position.y, 2, ids) if static is not None: return Target(x=static.x, y=static.y, z=static.z, graphic=static.item_id) return None
def __init__(self, client, item, target): Engine.__init__(self, client) if isinstance(item, Entity): item = item.serial if isinstance(target, Entity): target = Target(serial=target.serial) self.item = item self.target = target self.tries = 2 self.engine = None self.target_mutex = client.target_mutex self.target_mutex.get_target(self.target_ok, self.target_abort)
class WaitAndSendTarget(Engine): def __init__(self, client): Engine.__init__(self, client) self.target_request = None self.target = None def on_packet(self, packet): if isinstance(packet, p.TargetRequest): self.target_request = packet elif isinstance(packet, p.WorldItem): if self.target_request is not None: if packet.item_id == ITEM_GATE: self.target = Target(packet.serial, packet.x, packet.y, packet.z, packet.item_id) self._client.send( self.target.response(self.target_request.target_id, self.target_request.flags)) self._success()
class AutoEject(Engine): """Auto ejects not friended mobiles out of the house. house_rectangle is of format [pos1.x, pos1.y, pos2.x, pos2.y] where pos1 is the northwest and pos2 the southeast corner red_friends is of format [Serial1, Serial2, ]""" def __init__(self, client, red_friends, house_rectangle): Engine.__init__(self, client) self.target = None self.red_friends = red_friends self.xmin = house_rectangle[0] self.xmax = house_rectangle[2] self.ymin = house_rectangle[1] self.ymax = house_rectangle[3] def on_packet(self, packet): if isinstance(packet, p.MobileMoving): if self.is_in_house(packet.x, packet.y): self.check_visitor(packet) elif isinstance(packet, p.TargetRequest): self.send_eject_target(packet) def check_visitor(self, packet): if packet.notoriety == 3: self.eject_mobile(packet) elif packet.notoriety == 6 and not packet.serial in self.red_friends: self.eject_mobile(packet) def is_in_house(self, x, y): if x > self.xmin and x < self.xmax and \ y > self.ymin and y < self.ymax: return True return False def eject_mobile(self, packet): self.target = Target(packet.serial, packet.x, packet.y, packet.z, packet.body) self._client.send(p.TalkUnicode("remove thyself", 0x33)) def send_eject_target(self, packet): if self.target is not None: self._client.send( self.target.response(packet.target_id, packet.flags)) log.msg("Ejected " + str(self.target.serial))
class AutoEject(Engine): """Auto ejects not friended mobiles out of the house. house_rectangle is of format [pos1.x, pos1.y, pos2.x, pos2.y] where pos1 is the northwest and pos2 the southeast corner red_friends is of format [Serial1, Serial2, ]""" def __init__(self, client, red_friends, house_rectangle): Engine.__init__(self, client) self.target = None self.red_friends = red_friends self.xmin = house_rectangle[0] self.xmax = house_rectangle[2] self.ymin = house_rectangle[1] self.ymax = house_rectangle[3] def on_packet(self, packet): if isinstance(packet, p.MobileMoving): if self.is_in_house(packet.x, packet.y): self.check_visitor(packet) elif isinstance(packet, p.TargetRequest): self.send_eject_target(packet) def check_visitor(self, packet): if packet.notoriety == 3: self.eject_mobile(packet) elif packet.notoriety == 6 and not packet.serial in self.red_friends: self.eject_mobile(packet) def is_in_house(self, x, y): if x > self.xmin and x < self.xmax and \ y > self.ymin and y < self.ymax: return True return False def eject_mobile(self, packet): self.target = Target(packet.serial, packet.x, packet.y, packet.z, packet.body) self._client.send(p.TalkUnicode("remove thyself", 0x33)) def send_eject_target(self, packet): if self.target is not None: self._client.send(self.target.response(packet.target_id, packet.flags)) log.msg("Ejected " + str(self.target.serial))
def _target_sent(self, result): client = self._client self.engine = SendTarget(self._client, Target(serial=client.world.player.serial)) d = self.engine.deferred d.addCallbacks(self._player_sent, self._target_failed)
def eject_mobile(self, packet): self.target = Target(packet.serial, packet.x, packet.y, packet.z, packet.body) self._client.send(p.TalkUnicode("remove thyself", 0x33))