mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 01:58:40 +00:00
Dive in works again probably
This commit is contained in:
parent
a5eb9400fe
commit
42b4906c2c
2 changed files with 13 additions and 9 deletions
|
@ -98,10 +98,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (matchData is UpdateMyPlayerData playerData)
|
if (matchData is UpdateMyPlayerData playerData)
|
||||||
{
|
{
|
||||||
MatchHelper.SetUserLocation(user.UserId, token.UserLocation);
|
MatchHelper.SetUserLocation(user.UserId, token.UserLocation);
|
||||||
|
Room? room = RoomHelper.FindRoomByUser(user, true);
|
||||||
|
|
||||||
if (playerData.RoomState != null)
|
if (playerData.RoomState != null)
|
||||||
{
|
{
|
||||||
Room? room = RoomHelper.FindRoomByUser(user);
|
|
||||||
if (room != null && Equals(room.Host, user)) room.State = (RoomState)playerData.RoomState;
|
if (room != null && Equals(room.Host, user)) room.State = (RoomState)playerData.RoomState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Kettu;
|
||||||
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Match;
|
using LBPUnion.ProjectLighthouse.Types.Match;
|
||||||
|
@ -20,16 +22,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
|
|
||||||
private static int roomIdIncrement = 0;
|
private static int roomIdIncrement = 0;
|
||||||
|
|
||||||
internal static int RoomIdIncrement => roomIdIncrement++ - 1;
|
internal static int RoomIdIncrement => roomIdIncrement++;
|
||||||
|
|
||||||
public static FindBestRoomResponse? FindBestRoom(User user, string location)
|
public static FindBestRoomResponse? FindBestRoom(User user, string location)
|
||||||
{
|
{
|
||||||
bool anyRoomsLookingForPlayers = Rooms.Any(r => r.IsLookingForPlayers);
|
bool anyRoomsLookingForPlayers = Rooms.Any(r => r.IsLookingForPlayers);
|
||||||
|
|
||||||
// Look for rooms looking for players before moving on to rooms that are idle.
|
List<Room> rooms = anyRoomsLookingForPlayers ? Rooms.Where(r => anyRoomsLookingForPlayers && r.IsLookingForPlayers).ToList() : Rooms;
|
||||||
foreach (Room room in Rooms.Where(r => !anyRoomsLookingForPlayers || r.IsLookingForPlayers))
|
foreach (Room room in rooms)
|
||||||
|
// Look for rooms looking for players before moving on to rooms that are idle.
|
||||||
{
|
{
|
||||||
if (MatchHelper.DidUserRecentlyDiveInWith(user.UserId, room.Players[0].UserId)) continue;
|
if (MatchHelper.DidUserRecentlyDiveInWith(user.UserId, room.Host.UserId)) continue;
|
||||||
|
|
||||||
Dictionary<int, string> relevantUserLocations = new();
|
Dictionary<int, string> relevantUserLocations = new();
|
||||||
|
|
||||||
|
@ -56,6 +59,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
FindBestRoomResponse response = new();
|
FindBestRoomResponse response = new();
|
||||||
|
|
||||||
response.Players = new List<Player>();
|
response.Players = new List<Player>();
|
||||||
|
response.Locations = new List<string>();
|
||||||
foreach (User player in room.Players)
|
foreach (User player in room.Players)
|
||||||
{
|
{
|
||||||
response.Players.Add
|
response.Players.Add
|
||||||
|
@ -115,14 +119,14 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
Slot = slot ?? PodSlot,
|
Slot = slot ?? PodSlot,
|
||||||
};
|
};
|
||||||
|
|
||||||
Rooms.Add(room);
|
|
||||||
|
|
||||||
CleanupRooms(room.Host, room);
|
CleanupRooms(room.Host, room);
|
||||||
|
Rooms.Add(room);
|
||||||
|
Logger.Log($"Created room (id: {room.RoomId}) for host {room.Host.Username} (id: {room.Host.UserId})", LoggerLevelMatch.Instance);
|
||||||
|
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Room? FindRoomByUser(User user)
|
public static Room? FindRoomByUser(User user, bool createIfDoesNotExist = false)
|
||||||
{
|
{
|
||||||
foreach (Room room in Rooms)
|
foreach (Room room in Rooms)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +135,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
if (user == player) return room;
|
if (user == player) return room;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return createIfDoesNotExist ? CreateRoom(user) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "InvertIf")]
|
[SuppressMessage("ReSharper", "InvertIf")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue