Exemple #1
0
    def dispatch(self, core, session):
        user = session.user
        sess = meta.Session()

        if self.target is None:
            target = user
        else:
            try:
                target = sess.query(User).filter(User.name == self.target).one()
            except (NoResultFound, MultipleResultsFound):
                user.sendEx(core.bus, PacketError(severity=SEVERITY_WARN, msg="User not found."))
                return

        if not target.online:
            # lie about it and pretend the user doesn't exist
            user.sendEx(core.bus, PacketError(severity=SEVERITY_WARN, msg="User not found."))
            return

        tile = target.location
        chunk = tile.chunk

        acoords = dissolve(chunk.cx, chunk.cy, tile.rx, tile.ry, CHUNK_STRIDE)

        packet = PacketUser(
            name=target.name,
            level=target.level,
            profession=target.profession.name,
            location={
                "x"     : acoords[0],
                "y"     : acoords[1],
                "realm" : chunk.realm.name
            },
            hp={ "now" : target.hp, "max" : target.hpmax },
            ap={ "now" : target.ap, "max" : target.apmax },
            xp={ "now" : target.xp, "max" : target.xpmax }
        )

        if self.target is not None:
            packet.target = target.name

        user.sendEx(core.bus, packet)
Exemple #2
0
    def dispatch(self, core, session):
        user = session.user
        sess = meta.Session()

        # TODO: optimize these queries (more joins!)
        tile = sess.query(Tile).get(user.location_id)
        terrain = tile.terrain
        chunk = tile.chunk
        realm = chunk.realm

        # get the players here
        things = []

        for target in sess.query(User).filter(and_(User.location_id == tile.id, User.online == True, User.id != user.id)):
            things.append({
                "name"  : target.name,
                "level" : target.level,
                "type"  : "user"
            })

        acoords = dissolve(chunk.cx, chunk.cy, tile.rx, tile.ry, CHUNK_STRIDE)

        user.sendEx(core.bus, PacketInfo(
            location={
                "x"     : acoords[0],
                "y"     : acoords[1],
                "realm" : realm.name,
            },
            terrain={
                "img"   : terrain.img,
                "name"  : terrain.name,
            },
            size={
                "cw"    : realm.cw,
                "ch"    : realm.ch
            },
            things=things
        ))