mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 03:59:35 +08:00
132 lines
3.8 KiB
C#
132 lines
3.8 KiB
C#
using System.Collections;
|
|
using Milimoe.FunGame.Core.Entity;
|
|
using Milimoe.FunGame.Core.Library.Constant;
|
|
|
|
namespace Milimoe.FunGame.Core.Model
|
|
{
|
|
public class RoomList : IEnumerable<Room>
|
|
{
|
|
private readonly Dictionary<string, Room> _List = new();
|
|
private readonly Dictionary<string, List<User>> _PlayerList = new();
|
|
private readonly Dictionary<string, List<User>> _ReadyPlayerList = new();
|
|
|
|
public Room this[string RoomID] => GetRoom(RoomID);
|
|
|
|
public int Count => _List.Count;
|
|
|
|
public int GetPlayerCount(string RoomID) => GetPlayerList(RoomID).Count;
|
|
|
|
public int GetReadyPlayerCount(string RoomID) => GetReadyPlayerList(RoomID).Count;
|
|
|
|
public List<Room> ListRoom => _List.Values.ToList();
|
|
|
|
public List<string> ListRoomID => _List.Keys.ToList();
|
|
|
|
public List<User> GetPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID] : new();
|
|
|
|
public List<User> GetReadyPlayerList(string RoomID) => _ReadyPlayerList.ContainsKey(RoomID) ? _ReadyPlayerList[RoomID] : new();
|
|
|
|
public List<User> GetNotReadyPlayerList(string RoomID) => _PlayerList.ContainsKey(RoomID) ? _PlayerList[RoomID].Except(GetReadyPlayerList(RoomID)).ToList() : new();
|
|
|
|
public void Clear()
|
|
{
|
|
_List.Clear();
|
|
_PlayerList.Clear();
|
|
_ReadyPlayerList.Clear();
|
|
}
|
|
|
|
public void AddRoom(Room Room)
|
|
{
|
|
_List.Add(Room.Roomid, Room);
|
|
_PlayerList.Add(Room.Roomid, new());
|
|
_ReadyPlayerList.Add(Room.Roomid, new());
|
|
}
|
|
|
|
public void AddRooms(List<Room> Rooms)
|
|
{
|
|
foreach (Room Room in Rooms)
|
|
{
|
|
AddRoom(Room);
|
|
}
|
|
}
|
|
|
|
public void RemoveRoom(string RoomID)
|
|
{
|
|
_List.Remove(RoomID);
|
|
_PlayerList.Remove(RoomID);
|
|
_ReadyPlayerList.Remove(RoomID);
|
|
}
|
|
|
|
public void RemoveRoom(Room Room) => RemoveRoom(Room.Roomid);
|
|
|
|
public void IntoRoom(string RoomID, User User)
|
|
{
|
|
if (RoomID != "-1" && User.Id != 0)
|
|
{
|
|
GetPlayerList(RoomID).Add(User);
|
|
}
|
|
}
|
|
|
|
public void QuitRoom(string RoomID, User User)
|
|
{
|
|
if (RoomID != "-1" && User.Id != 0)
|
|
{
|
|
GetPlayerList(RoomID).Remove(User);
|
|
}
|
|
}
|
|
|
|
public void SetReady(string RoomID, User User)
|
|
{
|
|
if (RoomID != "-1" && User.Id != 0)
|
|
{
|
|
GetReadyPlayerList(RoomID).Add(User);
|
|
}
|
|
}
|
|
|
|
public void CancelReady(string RoomID, User User)
|
|
{
|
|
if (RoomID != "-1" && User.Id != 0)
|
|
{
|
|
GetReadyPlayerList(RoomID).Remove(User);
|
|
}
|
|
}
|
|
|
|
public Room GetRoom(string RoomID) => _List.ContainsKey(RoomID) ? _List[RoomID] : General.HallInstance;
|
|
|
|
public bool IsExist(string RoomID) => _List.ContainsKey(RoomID);
|
|
|
|
public User GetRoomMaster(string RoomID)
|
|
{
|
|
foreach (Room room in ListRoom.Where(r => r.Roomid == RoomID && r.RoomMaster != null))
|
|
{
|
|
return room.RoomMaster;
|
|
}
|
|
return General.UnknownUserInstance;
|
|
}
|
|
|
|
public void SetRoomMaster(string RoomID, User User)
|
|
{
|
|
if (RoomID != "-1" && User.Id != 0)
|
|
{
|
|
this[RoomID].RoomMaster = User;
|
|
}
|
|
}
|
|
|
|
public IEnumerator GetEnumerator()
|
|
{
|
|
foreach (Room room in ListRoom)
|
|
{
|
|
yield return room;
|
|
}
|
|
}
|
|
|
|
IEnumerator<Room> IEnumerable<Room>.GetEnumerator()
|
|
{
|
|
foreach (Room room in ListRoom)
|
|
{
|
|
yield return room;
|
|
}
|
|
}
|
|
}
|
|
}
|