Ejemplo n.º 1
0
    def send_move_to(self, waypoints, speed, spline_flag):
        self.reset()
        self.speed = speed

        start_time = int(WorldManager.get_seconds_since_startup() * 1000)

        data = pack('<Q12sIBI', self.unit.guid,
                    self.unit.location.to_bytes(include_orientation=False),
                    start_time, 0, spline_flag)

        waypoints_data = b''
        waypoints_length = len(waypoints)
        last_waypoint = self.unit.location
        total_distance = 0
        total_time = 0
        current_id = 0
        for waypoint in waypoints:
            waypoints_data += waypoint.to_bytes(include_orientation=False)
            current_distance = last_waypoint.distance(waypoint)
            current_time = current_distance / speed
            total_distance += current_distance
            total_time += current_time

            self.pending_waypoints.append(
                PendingWaypoint(current_id, total_time, waypoint))
            last_waypoint = waypoint
            current_id += 1

        data += pack('<2I%us' % len(waypoints_data), int(total_time * 1000),
                     waypoints_length, waypoints_data)

        GridManager.send_surrounding(PacketWriter.get_packet(
            OpCode.SMSG_MONSTER_MOVE, data),
                                     self.unit,
                                     include_self=self.is_player)

        # Player should dismount after some seconds have passed since FP destination is reached (Blizzlike).
        # This is also kind of a hackfix (at least for now) since the client always takes a bit more time to reach
        # the actual destination than the time you specify in SMSG_MONSTER_MOVE.
        if self.is_player and spline_flag == SplineFlags.SPLINEFLAG_FLYING:
            self.total_waypoint_time = total_time + (0.15 * waypoints_length)
        else:
            self.total_waypoint_time = total_time

        # Generate the spline
        spline = MovementSpline()
        spline.flags = spline_flag
        spline.spot = self.unit.location
        spline.guid = self.unit.guid
        spline.facing = self.unit.location.o
        spline.elapsed = 0
        spline.total_time = int(self.total_waypoint_time * 1000)
        spline.points = waypoints
        self.unit.movement_spline = spline

        self.last_position = self.unit.location
        self.should_update_waypoints = True
Ejemplo n.º 2
0
    def send_move_to(self, waypoints, speed, spline_flag):
        self.reset()
        self.speed = speed

        start_time = int(WorldManager.get_seconds_since_startup() * 1000)

        location_bytes = self.unit.location.to_bytes(include_orientation=False)
        data = pack(f'<Q{len(location_bytes)}sIBI', self.unit.guid,
                    location_bytes, start_time, 0, spline_flag)

        waypoints_data = b''
        waypoints_length = len(waypoints)
        last_waypoint = self.unit.location
        total_distance = 0
        total_time = 0
        current_id = 0
        for waypoint in waypoints:
            waypoints_data += waypoint.to_bytes(include_orientation=False)
            current_distance = last_waypoint.distance(waypoint)
            current_time = current_distance / speed
            total_distance += current_distance
            total_time += current_time

            self.pending_waypoints.append(
                PendingWaypoint(current_id, total_time, waypoint))
            last_waypoint = waypoint
            current_id += 1

        data += pack(f'<2I{len(waypoints_data)}s', int(total_time * 1000),
                     waypoints_length, waypoints_data)

        GridManager.send_surrounding(PacketWriter.get_packet(
            OpCode.SMSG_MONSTER_MOVE, data),
                                     self.unit,
                                     include_self=self.is_player)

        # Player shouldn't instantly dismount after reaching the taxi destination
        if self.is_player and spline_flag == SplineFlags.SPLINEFLAG_FLYING:
            self.total_waypoint_time = total_time + 1.0  # Add 1 extra second
        else:
            self.total_waypoint_time = total_time

        # Generate the spline
        spline = MovementSpline()
        spline.flags = spline_flag
        spline.spot = self.unit.location
        spline.guid = self.unit.guid
        spline.facing = self.unit.location.o
        spline.elapsed = 0
        spline.total_time = int(self.total_waypoint_time * 1000)
        spline.points = waypoints
        self.unit.movement_spline = spline

        self.last_position = self.unit.location
        self.should_update_waypoints = True
Ejemplo n.º 3
0
    def serverinfo(world_session, args):
        os_platform = f'{platform.system()} {platform.release()} ({platform.version()})'
        message = f'Platform: {os_platform}.\n'

        server_time = f'{datetime.now()}'
        message += f'Server Time: {server_time}.\n'

        server_uptime = timedelta(seconds=WorldManager.get_seconds_since_startup())
        message += f'Uptime: {server_uptime}.\n'

        current_commit_hash = GitUtils.get_current_commit_hash()
        current_branch = GitUtils.get_current_branch()
        message += f'Commit: [{current_branch}] {current_commit_hash}.'

        return 0, message
Ejemplo n.º 4
0
    def try_build_movement_packet(self, waypoints=None, is_initial=False):
        # If this is a partial packet, use pending waypoints.
        if not waypoints:
            waypoints = [pending_wp.location for pending_wp in list(self.pending_waypoints)]

        # Sending no waypoints crashes the client.
        if len(waypoints) == 0:
            return None

        start_time = int(WorldManager.get_seconds_since_startup() * 1000)
        location_bytes = self.unit.location.to_bytes(include_orientation=False)
        data = pack(
            f'<Q{len(location_bytes)}sIB',
            self.unit.guid,
            location_bytes,
            start_time,
            self.unit.movement_spline.spline_type
        )

        if self.unit.movement_spline.spline_type == SplineType.SPLINE_TYPE_STOP:
            return PacketWriter.get_packet(OpCode.SMSG_MONSTER_MOVE, data)
        elif self.unit.movement_spline.spline_type == SplineType.SPLINE_TYPE_FACING_SPOT:
            spot_bytes = self.unit.movement_spline.spot.to_bytes(include_orientation=False)
            data += pack(f'<{len(location_bytes)}s', spot_bytes)
        elif self.unit.movement_spline.spline_type == SplineType.SPLINE_TYPE_FACING_TARGET:
            data += pack('<Q', self.unit.movement_spline.guid)
        elif self.unit.movement_spline.spline_type == SplineType.SPLINE_TYPE_FACING_ANGLE:
            data += pack('<f', self.unit.movement_spline.facing)

        data += pack('<I', self.unit.movement_spline.flags)

        waypoints_data = b''
        waypoints_length = len(waypoints)
        last_waypoint = self.unit.location
        total_distance = 0
        total_time = 0
        current_id = 0
        for waypoint in waypoints:
            waypoints_data += waypoint.to_bytes(include_orientation=False)
            current_distance = last_waypoint.distance(waypoint)
            current_time = current_distance / self.unit.movement_spline.speed
            total_distance += current_distance
            total_time += current_time

            if is_initial:
                self.pending_waypoints.append(PendingWaypoint(current_id, total_time, waypoint))
            last_waypoint = waypoint
            current_id += 1

        data += pack(
            f'<2I{len(waypoints_data)}s',
            int(total_time * 1000),
            waypoints_length,
            waypoints_data
        )

        if is_initial:
            # Player shouldn't instantly dismount after reaching the taxi destination
            if self.is_player and self.unit.movement_spline.flags == SplineFlags.SPLINEFLAG_FLYING:
                self.total_waypoint_time = total_time + 1.0  # Add 1 extra second
            else:
                self.total_waypoint_time = total_time

        # Avoid empty move packet.
        if len(waypoints_data) == 0:
            return None

        return PacketWriter.get_packet(OpCode.SMSG_MONSTER_MOVE, data)