mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 18:18:39 +00:00
Fix state updating
This commit is contained in:
parent
ba60328eaf
commit
00e3d2013a
4 changed files with 43 additions and 11 deletions
|
@ -135,10 +135,11 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
else return this.BadRequest();
|
||||
}
|
||||
|
||||
Room newRoom = RoomHelper.CreateRoom(users, createRoom.RoomSlot);
|
||||
|
||||
// Delete old rooms based on host
|
||||
RoomHelper.Rooms.RemoveAll(r => r.Host == newRoom.Host);
|
||||
RoomHelper.Rooms.RemoveAll(r => r.Host == user);
|
||||
|
||||
// Create a new one as requested
|
||||
Room newRoom = RoomHelper.CreateRoom(users, createRoom.RoomSlot);
|
||||
|
||||
// Remove players in this new room from other rooms
|
||||
foreach (Room room in RoomHelper.Rooms)
|
||||
|
|
|
@ -17,6 +17,10 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
SlotId = 0,
|
||||
};
|
||||
|
||||
private static int roomIdIncrement = 0;
|
||||
|
||||
internal static int RoomIdIncrement => roomIdIncrement++ - 1;
|
||||
|
||||
public static FindBestRoomResponse? FindBestRoom(User user, string location)
|
||||
{
|
||||
bool anyRoomsLookingForPlayers = Rooms.Any(r => r.IsLookingForPlayers);
|
||||
|
@ -99,16 +103,28 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
);
|
||||
public static Room CreateRoom(List<User> users, RoomSlot? slot = null)
|
||||
{
|
||||
Room room = new();
|
||||
|
||||
room.Players = users;
|
||||
room.State = RoomState.Idle;
|
||||
room.Slot = slot ?? PodSlot;
|
||||
Room room = new()
|
||||
{
|
||||
RoomId = RoomIdIncrement,
|
||||
Players = users,
|
||||
State = RoomState.Idle,
|
||||
Slot = slot ?? PodSlot,
|
||||
};
|
||||
|
||||
Rooms.Add(room);
|
||||
return room;
|
||||
}
|
||||
|
||||
public static Room? FindRoomByUser(User user) => Rooms.FirstOrDefault(r => r.Players.Contains(user));
|
||||
public static Room? FindRoomByUser(User user)
|
||||
{
|
||||
foreach (Room room in Rooms)
|
||||
{
|
||||
foreach (User player in room.Players)
|
||||
{
|
||||
if (user == player) return room;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
|||
{
|
||||
public class Room
|
||||
{
|
||||
public int RoomId;
|
||||
|
||||
public List<User> Players;
|
||||
public RoomState State;
|
||||
public RoomSlot Slot;
|
||||
|
@ -13,5 +15,18 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
|||
public bool IsLookingForPlayers => this.State == RoomState.DivingIntoLevel || this.State == RoomState.DivingInWaiting;
|
||||
|
||||
public User Host => this.Players[0];
|
||||
|
||||
#nullable enable
|
||||
public static bool operator ==(Room? room1, Room? room2)
|
||||
{
|
||||
if (ReferenceEquals(room1, room2)) return true;
|
||||
if ((object?)room1 == null || (object?)room2 == null) return false;
|
||||
|
||||
return room1.RoomId == room2.RoomId;
|
||||
}
|
||||
public static bool operator !=(Room? room1, Room? room2) => !(room1 == room2);
|
||||
|
||||
public override int GetHashCode() => this.RoomId;
|
||||
#nullable disable
|
||||
}
|
||||
}
|
|
@ -197,10 +197,10 @@ namespace LBPUnion.ProjectLighthouse.Types
|
|||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ConditionIsAlwaysTrueOrFalse")]
|
||||
public static bool operator ==(User user1, User user2)
|
||||
public static bool operator ==(User? user1, User? user2)
|
||||
{
|
||||
if (ReferenceEquals(user1, user2)) return true;
|
||||
if ((object)user1 == null || (object)user2 == null) return false;
|
||||
if ((object?)user1 == null || (object?)user2 == null) return false;
|
||||
|
||||
return user1.UserId == user2.UserId;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue