Add proper support for level dive-ins

This commit is contained in:
jvyden 2022-04-05 17:32:30 -04:00
commit 2b5c8fd782
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 27 additions and 5 deletions

View file

@ -88,9 +88,15 @@ public class MatchController : ControllerBase
room.State = (RoomState)playerData.RoomState;
}
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
// Check how many people are online in release builds, disabled for debug for ..well debugging.
#if DEBUG
if (matchData is FindBestRoom diveInData)
#else
if (matchData is FindBestRoom diveInData && MatchHelper.UserLocations.Count > 1)
#endif
{
FindBestRoomResponse? response = RoomHelper.FindBestRoom(user, gameToken.GameVersion, gameToken.Platform, gameToken.UserLocation);
FindBestRoomResponse? response = RoomHelper.FindBestRoom
(user, gameToken.GameVersion, diveInData.RoomSlot, gameToken.Platform, gameToken.UserLocation);
if (response == null) return this.NotFound();

View file

@ -42,11 +42,11 @@ public class RoomHelper
internal static int RoomIdIncrement => roomIdIncrement++;
public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, Platform? platform, string? location)
public static FindBestRoomResponse? FindBestRoom(User? user, GameVersion roomVersion, RoomSlot? slot, Platform? platform, string? location)
{
if (roomVersion == GameVersion.LittleBigPlanet1 || roomVersion == GameVersion.LittleBigPlanetPSP)
{
Logger.Log($"Returning null for FindBestRoom, game ({roomVersion}) does not support dive in", LoggerLevelMatch.Instance);
Logger.Log($"Returning null for FindBestRoom, game ({roomVersion}) does not support dive in (should never happen?)", LoggerLevelMatch.Instance);
return null;
}
@ -62,6 +62,14 @@ public class RoomHelper
rooms = rooms.Where(r => r.RoomVersion == roomVersion).ToList();
if (platform != null) rooms = rooms.Where(r => r.RoomPlatform == platform).ToList();
// If the user is in the pod while trying to look for a room, then they're diving in.
// Otherwise they're looking for people to play with in a particular level.
// We handle that here:
if (slot != null && slot.SlotType != SlotType.Pod && slot.SlotId != 0)
{
rooms = rooms.Where(r => r.Slot.SlotType == slot.SlotType && r.Slot.SlotId == slot.SlotId).ToList();
}
foreach (Room room in rooms)
// Look for rooms looking for players before moving on to rooms that are idle.
{

View file

@ -52,7 +52,7 @@
{
if (version == GameVersion.LittleBigPlanet1 || version == GameVersion.LittleBigPlanetPSP || version == GameVersion.Unknown) continue;
FindBestRoomResponse? response = RoomHelper.FindBestRoom(null, version, null, null);
FindBestRoomResponse? response = RoomHelper.FindBestRoom(null, version, null, null, null);
string text = response == null ? "No room found." : "Room " + response.RoomId;
<p><b>Best room for @version.ToPrettyString()</b>: @text</p>

View file

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels;
namespace LBPUnion.ProjectLighthouse.Types.Match;
@ -24,4 +25,11 @@ public class FindBestRoom : IMatchData
[JsonIgnore]
public IEnumerable<int> FirstSlot => this.Slots[0];
public RoomSlot RoomSlot
=> new()
{
SlotType = (SlotType)this.Slots[0][0],
SlotId = this.Slots[0][1],
};
}