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))