This commit is contained in:
2023-07-30 21:14:14 +03:00
parent 4a8aae11e3
commit 5fc55eaddc
21 changed files with 124 additions and 78 deletions
+24 -20
View File
@@ -4,7 +4,7 @@ using Ragon.Protocol;
namespace Ragon.Client.Simulation; namespace Ragon.Client.Simulation;
public class Game : IRagonListener public class Game : IRagonListener, IRagonSceneRequestListener
{ {
private RagonFloat _health; private RagonFloat _health;
private RagonInt _points; private RagonInt _points;
@@ -36,23 +36,7 @@ public class Game : IRagonListener
public void OnJoined(RagonClient client) public void OnJoined(RagonClient client)
{ {
RagonLog.Trace("Joined");
_health = new RagonFloat(100.0f, false, 0);
_health.Changed += () => Console.WriteLine($"[Ragon Property] Health: {_health.Value}");
_points = new RagonInt(0, -1000, 1000, false, 0);
_points.Changed += () => Console.WriteLine($"[Ragon Property] Points: {_points.Value}");
_name = new RagonString("Edmand 000", false);
_name.Changed += () => Console.WriteLine($"[Ragon Property] Name: {_name.Value}");
_entity = new RagonEntity(12, 0);
_entity.State.AddProperty(_health);
_entity.State.AddProperty(_points);
_entity.State.AddProperty(_name);
client.Room.CreateEntity(_entity);
} }
public void OnFailed(RagonClient client, string message) public void OnFailed(RagonClient client, string message)
@@ -85,11 +69,25 @@ public class Game : IRagonListener
RagonLog.Trace("Owner ship changed"); RagonLog.Trace("Owner ship changed");
} }
public void OnLevel(RagonClient client, string sceneName) public void OnSceneLoaded(RagonClient client)
{ {
RagonLog.Trace($"New level: {sceneName}"); RagonLog.Trace("Joined");
client.Room.SceneLoaded(); _health = new RagonFloat(100.0f, false, 0);
_health.Changed += () => Console.WriteLine($"[Ragon Property] Health: {_health.Value}");
_points = new RagonInt(0, -1000, 1000, false, 0);
_points.Changed += () => Console.WriteLine($"[Ragon Property] Points: {_points.Value}");
_name = new RagonString("Edmand 000", false);
_name.Changed += () => Console.WriteLine($"[Ragon Property] Name: {_name.Value}");
_entity = new RagonEntity(12, 0);
_entity.State.AddProperty(_health);
_entity.State.AddProperty(_points);
_entity.State.AddProperty(_name);
client.Room.CreateEntity(_entity);
} }
private float _timer = 0; private float _timer = 0;
@@ -109,4 +107,10 @@ public class Game : IRagonListener
_timer = 0; _timer = 0;
} }
} }
public void OnRequestScene(RagonClient client, string sceneName)
{
client.Room.SceneLoaded();
}
} }
@@ -67,14 +67,15 @@ internal class JoinSuccessHandler : Handler
var ownerId = buffer.ReadString(); var ownerId = buffer.ReadString();
var min = buffer.ReadUShort(); var min = buffer.ReadUShort();
var max = buffer.ReadUShort(); var max = buffer.ReadUShort();
var map = buffer.ReadString(); var sceneName = buffer.ReadString();
var scene = new RagonScene(_client, _playerCache, _entityCache); var scene = new RagonScene(_client, _playerCache, _entityCache, sceneName);
var roomInfo = new RagonRoomInformation(roomId, localId, ownerId, min, max); var roomInfo = new RagonRoomInformation(roomId, localId, ownerId, min, max);
var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene); var room = new RagonRoom(_client, _entityCache, _playerCache, roomInfo, scene);
_playerCache.SetOwnerAndLocal(ownerId, localId); _playerCache.SetOwnerAndLocal(ownerId, localId);
_client.AssignRoom(room); _client.AssignRoom(room);
_listenerList.OnLevel(map);
_listenerList.OnSceneRequest(sceneName);
} }
} }
@@ -38,7 +38,8 @@ internal class SceneLoadHandler: Handler
var room = _client.Room; var room = _client.Room;
room.Cleanup(); room.Cleanup();
room.Update(sceneName);
_listenerList.OnLevel(sceneName); _listenerList.OnSceneRequest(sceneName);
} }
} }
@@ -117,6 +117,9 @@ internal class SnapshotHandler : Handler
entity.Attach(_client, entityId, entityType, hasAuthority, player); entity.Attach(_client, entityId, entityType, hasAuthority, player);
} }
if (_client.Status != RagonStatus.ROOM)
_listenerList.OnJoined(); _listenerList.OnJoined();
_listenerList.OnSceneLoaded();
} }
} }
@@ -22,10 +22,11 @@ namespace Ragon.Client
IRagonFailedListener, IRagonFailedListener,
IRagonJoinListener, IRagonJoinListener,
IRagonLeftListener, IRagonLeftListener,
IRagonLevelListener, IRagonSceneListener,
IRagonOwnershipChangedListener, IRagonOwnershipChangedListener,
IRagonPlayerJoinListener, IRagonPlayerJoinListener,
IRagonPlayerLeftListener IRagonPlayerLeftListener
{ {
} }
} }
@@ -16,7 +16,7 @@
namespace Ragon.Client; namespace Ragon.Client;
public interface IRagonLevelListener public interface IRagonSceneListener
{ {
void OnLevel(RagonClient client, string sceneName); void OnSceneLoaded(RagonClient client);
} }
@@ -0,0 +1,6 @@
namespace Ragon.Client;
public interface IRagonSceneRequestListener
{
void OnRequestScene(RagonClient client, string sceneName);
}
+2 -2
View File
@@ -162,7 +162,7 @@ namespace Ragon.Client
public void AddListener(IRagonFailedListener listener) => _listenerList.Add(listener); public void AddListener(IRagonFailedListener listener) => _listenerList.Add(listener);
public void AddListener(IRagonJoinListener listener) => _listenerList.Add(listener); public void AddListener(IRagonJoinListener listener) => _listenerList.Add(listener);
public void AddListener(IRagonLeftListener listener) => _listenerList.Add(listener); public void AddListener(IRagonLeftListener listener) => _listenerList.Add(listener);
public void AddListener(IRagonLevelListener listener) => _listenerList.Add(listener); public void AddListener(IRagonSceneListener listener) => _listenerList.Add(listener);
public void AddListener(IRagonOwnershipChangedListener listener) => _listenerList.Add(listener); public void AddListener(IRagonOwnershipChangedListener listener) => _listenerList.Add(listener);
public void AddListener(IRagonPlayerJoinListener listener) => _listenerList.Add(listener); public void AddListener(IRagonPlayerJoinListener listener) => _listenerList.Add(listener);
public void AddListener(IRagonPlayerLeftListener listener) => _listenerList.Add(listener); public void AddListener(IRagonPlayerLeftListener listener) => _listenerList.Add(listener);
@@ -173,7 +173,7 @@ namespace Ragon.Client
public void RemoveListener(IRagonFailedListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonFailedListener listener) => _listenerList.Remove(listener);
public void RemoveListener(IRagonJoinListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonJoinListener listener) => _listenerList.Remove(listener);
public void RemoveListener(IRagonLeftListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonLeftListener listener) => _listenerList.Remove(listener);
public void RemoveListener(IRagonLevelListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonSceneListener listener) => _listenerList.Remove(listener);
public void RemoveListener(IRagonOwnershipChangedListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonOwnershipChangedListener listener) => _listenerList.Remove(listener);
public void RemoveListener(IRagonPlayerJoinListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonPlayerJoinListener listener) => _listenerList.Remove(listener);
public void RemoveListener(IRagonPlayerLeftListener listener) => _listenerList.Remove(listener); public void RemoveListener(IRagonPlayerLeftListener listener) => _listenerList.Remove(listener);
+27 -10
View File
@@ -26,7 +26,8 @@ namespace Ragon.Client
private readonly List<IRagonFailedListener> _failedListeners = new(); private readonly List<IRagonFailedListener> _failedListeners = new();
private readonly List<IRagonJoinListener> _joinListeners = new(); private readonly List<IRagonJoinListener> _joinListeners = new();
private readonly List<IRagonLeftListener> _leftListeners = new(); private readonly List<IRagonLeftListener> _leftListeners = new();
private readonly List<IRagonLevelListener> _levelListeners = new(); private readonly List<IRagonSceneListener> _sceneListeners = new();
private readonly List<IRagonSceneRequestListener> _sceneRequestListeners = new();
private readonly List<IRagonOwnershipChangedListener> _ownershipChangedListeners = new(); private readonly List<IRagonOwnershipChangedListener> _ownershipChangedListeners = new();
private readonly List<IRagonPlayerJoinListener> _playerJoinListeners = new(); private readonly List<IRagonPlayerJoinListener> _playerJoinListeners = new();
private readonly List<IRagonPlayerLeftListener> _playerLeftListeners = new(); private readonly List<IRagonPlayerLeftListener> _playerLeftListeners = new();
@@ -44,7 +45,7 @@ namespace Ragon.Client
_failedListeners.Add(listener); _failedListeners.Add(listener);
_joinListeners.Add(listener); _joinListeners.Add(listener);
_leftListeners.Add(listener); _leftListeners.Add(listener);
_levelListeners.Add(listener); _sceneListeners.Add(listener);
_ownershipChangedListeners.Add(listener); _ownershipChangedListeners.Add(listener);
_playerJoinListeners.Add(listener); _playerJoinListeners.Add(listener);
_playerLeftListeners.Add(listener); _playerLeftListeners.Add(listener);
@@ -59,7 +60,7 @@ namespace Ragon.Client
_failedListeners.Remove(listener); _failedListeners.Remove(listener);
_joinListeners.Remove(listener); _joinListeners.Remove(listener);
_leftListeners.Remove(listener); _leftListeners.Remove(listener);
_levelListeners.Remove(listener); _sceneListeners.Remove(listener);
_ownershipChangedListeners.Remove(listener); _ownershipChangedListeners.Remove(listener);
_playerJoinListeners.Remove(listener); _playerJoinListeners.Remove(listener);
_playerLeftListeners.Remove(listener); _playerLeftListeners.Remove(listener);
@@ -80,6 +81,11 @@ namespace Ragon.Client
_authorizationListeners.Add(listener); _authorizationListeners.Add(listener);
} }
public void Add(IRagonSceneRequestListener listener)
{
_sceneRequestListeners.Add(listener);
}
public void Add(IRagonConnectionListener listener) public void Add(IRagonConnectionListener listener)
{ {
_connectionListeners.Add(listener); _connectionListeners.Add(listener);
@@ -100,9 +106,9 @@ namespace Ragon.Client
_leftListeners.Add(listener); _leftListeners.Add(listener);
} }
public void Add(IRagonLevelListener listener) public void Add(IRagonSceneListener listener)
{ {
_levelListeners.Add(listener); _sceneListeners.Add(listener);
} }
public void Add(IRagonOwnershipChangedListener listener) public void Add(IRagonOwnershipChangedListener listener)
@@ -120,6 +126,11 @@ namespace Ragon.Client
_playerLeftListeners.Add(listener); _playerLeftListeners.Add(listener);
} }
public void Remove(IRagonSceneRequestListener listener)
{
_delayedActions.Add(() => _sceneRequestListeners.Remove(listener));
}
public void Remove(IRagonAuthorizationListener listener) public void Remove(IRagonAuthorizationListener listener)
{ {
_delayedActions.Add(() => _authorizationListeners.Remove(listener)); _delayedActions.Add(() => _authorizationListeners.Remove(listener));
@@ -146,9 +157,9 @@ namespace Ragon.Client
_delayedActions.Add(() => _leftListeners.Remove(listener)); _delayedActions.Add(() => _leftListeners.Remove(listener));
} }
public void Remove(IRagonLevelListener listener) public void Remove(IRagonSceneListener listener)
{ {
_delayedActions.Add(() => _levelListeners.Remove(listener)); _delayedActions.Add(() => _sceneListeners.Remove(listener));
} }
public void Remove(IRagonOwnershipChangedListener listener) public void Remove(IRagonOwnershipChangedListener listener)
@@ -208,10 +219,16 @@ namespace Ragon.Client
listener.OnPlayerJoined(_client, player); listener.OnPlayerJoined(_client, player);
} }
public void OnLevel(string sceneName) public void OnSceneLoaded()
{ {
foreach (var listener in _levelListeners) foreach (var listener in _sceneListeners)
listener.OnLevel(_client, sceneName); listener.OnSceneLoaded(_client);
}
public void OnSceneRequest(string sceneName)
{
foreach (var listener in _sceneRequestListeners)
listener.OnRequestScene(_client, sceneName);
} }
public void OnJoined() public void OnJoined()
+7 -1
View File
@@ -27,6 +27,7 @@ namespace Ragon.Client
public string Id => _information.RoomId; public string Id => _information.RoomId;
public int MinPlayers => _information.Min; public int MinPlayers => _information.Min;
public int MaxPlayers => _information.Max; public int MaxPlayers => _information.Max;
public string Scene => _scene.Name;
public IReadOnlyList<RagonPlayer> Players => _playerCache.Players; public IReadOnlyList<RagonPlayer> Players => _playerCache.Players;
public RagonPlayer Local => _playerCache.Local; public RagonPlayer Local => _playerCache.Local;
@@ -51,7 +52,12 @@ namespace Ragon.Client
_playerCache.Cleanup(); _playerCache.Cleanup();
} }
public void LoadScene(string map) => _scene.Load(map); internal void Update(string sceneName)
{
_scene.Update(sceneName);
}
public void LoadScene(string sceneName) => _scene.Load(sceneName);
public void SceneLoaded() => _scene.SceneLoaded(); public void SceneLoaded() => _scene.SceneLoaded();
public void CreateEntity(RagonEntity entity) => CreateEntity(entity, null); public void CreateEntity(RagonEntity entity) => CreateEntity(entity, null);
+12 -3
View File
@@ -20,24 +20,33 @@ namespace Ragon.Client;
public class RagonScene public class RagonScene
{ {
public string Name { get; private set; }
private readonly RagonClient _client; private readonly RagonClient _client;
private readonly RagonEntityCache _entityCache; private readonly RagonEntityCache _entityCache;
private readonly RagonPlayerCache _playerCache; private readonly RagonPlayerCache _playerCache;
public RagonScene(RagonClient client, RagonPlayerCache playerCache, RagonEntityCache entityCache) public RagonScene(RagonClient client, RagonPlayerCache playerCache, RagonEntityCache entityCache, string sceneName)
{ {
Name = sceneName;
_client = client; _client = client;
_playerCache = playerCache; _playerCache = playerCache;
_entityCache = entityCache; _entityCache = entityCache;
} }
internal void Load(string map) internal void Update(string scene)
{
Name = scene;
}
internal void Load(string sceneName)
{ {
var buffer = _client.Buffer; var buffer = _client.Buffer;
buffer.Clear(); buffer.Clear();
buffer.WriteOperation(RagonOperation.LOAD_SCENE); buffer.WriteOperation(RagonOperation.LOAD_SCENE);
buffer.WriteString(map); buffer.WriteString(sceneName);
var sendData = buffer.ToArray(); var sendData = buffer.ToArray();
_client.Reliable.Send(sendData); _client.Reliable.Send(sendData);
+6 -6
View File
@@ -29,9 +29,9 @@ namespace Ragon.Client
_buffer = buffer; _buffer = buffer;
} }
public void CreateOrJoin(string map, int minPlayers, int maxPlayers) public void CreateOrJoin(string sceneName, int minPlayers, int maxPlayers)
{ {
var parameters = new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers}; var parameters = new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers};
CreateOrJoin(parameters); CreateOrJoin(parameters);
} }
@@ -46,14 +46,14 @@ namespace Ragon.Client
_client.Reliable.Send(sendData); _client.Reliable.Send(sendData);
} }
public void Create(string map, int minPlayers, int maxPlayers) public void Create(string sceneName, int minPlayers, int maxPlayers)
{ {
Create(null, new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers}); Create(null, new RagonRoomParameters() {Scene = sceneName, Min = minPlayers, Max = maxPlayers});
} }
public void Create(string roomId, string map, int minPlayers, int maxPlayers) public void Create(string roomId, string sceneNa, int minPlayers, int maxPlayers)
{ {
Create(roomId, new RagonRoomParameters() {Map = map, Min = minPlayers, Max = maxPlayers}); Create(roomId, new RagonRoomParameters() {Scene = sceneNa, Min = minPlayers, Max = maxPlayers});
} }
public void Create(string roomId, RagonRoomParameters parameters) public void Create(string roomId, RagonRoomParameters parameters)
@@ -19,20 +19,20 @@ namespace Ragon.Protocol
{ {
public class RagonRoomParameters: IRagonSerializable public class RagonRoomParameters: IRagonSerializable
{ {
public string Map { get; set; } public string Scene { get; set; }
public int Min { get; set; } public int Min { get; set; }
public int Max { get; set; } public int Max { get; set; }
public void Serialize(RagonBuffer buffer) public void Serialize(RagonBuffer buffer)
{ {
buffer.WriteString(Map); buffer.WriteString(Scene);
buffer.WriteInt(Min, 1, 32); buffer.WriteInt(Min, 1, 32);
buffer.WriteInt(Max, 1, 32); buffer.WriteInt(Max, 1, 32);
} }
public void Deserialize(RagonBuffer buffer) public void Deserialize(RagonBuffer buffer)
{ {
Map = buffer.ReadString(); Scene = buffer.ReadString();
Min = buffer.ReadInt(1, 32); Min = buffer.ReadInt(1, 32);
Max = buffer.ReadInt(1, 32); Max = buffer.ReadInt(1, 32);
} }
@@ -68,7 +68,7 @@ public sealed class RoomCreateOperation: IRagonOperation
var information = new RoomInformation() var information = new RoomInformation()
{ {
Map = _roomParameters.Map, Scene = _roomParameters.Scene,
Max = _roomParameters.Max, Max = _roomParameters.Max,
Min = _roomParameters.Min, Min = _roomParameters.Min,
}; };
@@ -87,7 +87,7 @@ public sealed class RoomCreateOperation: IRagonOperation
_ragonWebHookPlugin.RoomCreated(context, room, roomPlayer); _ragonWebHookPlugin.RoomCreated(context, room, roomPlayer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}"); _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
JoinSuccess(roomPlayer, room, writer); JoinSuccess(roomPlayer, room, writer);
@@ -103,7 +103,7 @@ public sealed class RoomCreateOperation: IRagonOperation
writer.WriteString(room.Owner.Id); writer.WriteString(room.Owner.Id);
writer.WriteUShort((ushort) room.PlayerMin); writer.WriteUShort((ushort) room.PlayerMin);
writer.WriteUShort((ushort) room.PlayerMax); writer.WriteUShort((ushort) room.PlayerMax);
writer.WriteString(room.Map); writer.WriteString(room.Scene);
var sendData = writer.ToArray(); var sendData = writer.ToArray();
player.Connection.Reliable.Send(sendData); player.Connection.Reliable.Send(sendData);
@@ -68,7 +68,7 @@ public sealed class RoomJoinOperation : IRagonOperation
writer.WriteString(room.Owner.Id); writer.WriteString(room.Owner.Id);
writer.WriteUShort((ushort) room.PlayerMin); writer.WriteUShort((ushort) room.PlayerMin);
writer.WriteUShort((ushort) room.PlayerMax); writer.WriteUShort((ushort) room.PlayerMax);
writer.WriteString(room.Map); writer.WriteString(room.Scene);
var sendData = writer.ToArray(); var sendData = writer.ToArray();
context.Connection.Reliable.Send(sendData); context.Connection.Reliable.Send(sendData);
@@ -49,7 +49,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
_roomParameters.Deserialize(reader); _roomParameters.Deserialize(reader);
if (context.Lobby.FindRoomByMap(_roomParameters.Map, out var existsRoom)) if (context.Lobby.FindRoomByScene(_roomParameters.Scene, out var existsRoom))
{ {
var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name); var player = new RagonRoomPlayer(context.Connection, lobbyPlayer.Id, lobbyPlayer.Name);
context.SetRoom(existsRoom, player); context.SetRoom(existsRoom, player);
@@ -62,7 +62,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
{ {
var information = new RoomInformation() var information = new RoomInformation()
{ {
Map = _roomParameters.Map, Scene = _roomParameters.Scene,
Max = _roomParameters.Max, Max = _roomParameters.Max,
Min = _roomParameters.Min, Min = _roomParameters.Min,
}; };
@@ -77,7 +77,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
context.Scheduler.Run(room); context.Scheduler.Run(room);
context.SetRoom(room, roomPlayer); context.SetRoom(room, roomPlayer);
_logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with map {information.Map}"); _logger.Trace($"Player {context.Connection.Id}|{context.LobbyPlayer.Name} create room {room.Id} with scene {information.Scene}");
JoinSuccess(roomPlayer, room, writer); JoinSuccess(roomPlayer, room, writer);
} }
@@ -92,7 +92,7 @@ public sealed class RoomJoinOrCreateOperation : IRagonOperation
writer.WriteString(room.Owner.Id); writer.WriteString(room.Owner.Id);
writer.WriteUShort((ushort) room.PlayerMin); writer.WriteUShort((ushort) room.PlayerMin);
writer.WriteUShort((ushort) room.PlayerMax); writer.WriteUShort((ushort) room.PlayerMax);
writer.WriteString(room.Map); writer.WriteString(room.Scene);
var sendData = writer.ToArray(); var sendData = writer.ToArray();
player.Connection.Reliable.Send(sendData); player.Connection.Reliable.Send(sendData);
@@ -33,7 +33,7 @@ public class SceneLoadOperation: IRagonOperation
if (roomOwner.Connection.Id != currentPlayer.Connection.Id) if (roomOwner.Connection.Id != currentPlayer.Connection.Id)
{ {
_logger.Warn("Only owner can change map!"); _logger.Warn("Only owner can change scene!");
return; return;
} }
+1 -1
View File
@@ -22,7 +22,7 @@ namespace Ragon.Server.Lobby;
public interface IRagonLobby public interface IRagonLobby
{ {
public bool FindRoomById(string roomId, [MaybeNullWhen(false)] out RagonRoom room); public bool FindRoomById(string roomId, [MaybeNullWhen(false)] out RagonRoom room);
public bool FindRoomByMap(string map, [MaybeNullWhen(false)] out RagonRoom room); public bool FindRoomByScene(string sceneName, [MaybeNullWhen(false)] out RagonRoom room);
public void Persist(RagonRoom room); public void Persist(RagonRoom room);
public bool RemoveIfEmpty(RagonRoom room); public bool RemoveIfEmpty(RagonRoom room);
} }
@@ -40,11 +40,11 @@ public class LobbyInMemory : IRagonLobby
return false; return false;
} }
public bool FindRoomByMap(string map, [MaybeNullWhen(false)] out RagonRoom room) public bool FindRoomByScene(string sceneName, [MaybeNullWhen(false)] out RagonRoom room)
{ {
foreach (var existsRoom in _rooms) foreach (var existsRoom in _rooms)
{ {
if (existsRoom.Map == map && existsRoom.PlayerCount < existsRoom.PlayerMax) if (existsRoom.Scene == sceneName && existsRoom.PlayerCount < existsRoom.PlayerMax)
{ {
room = existsRoom; room = existsRoom;
return true; return true;
@@ -61,7 +61,7 @@ public class LobbyInMemory : IRagonLobby
_logger.Trace($"New room: {room.Id}"); _logger.Trace($"New room: {room.Id}");
foreach (var r in _rooms) foreach (var r in _rooms)
_logger.Trace($"Room: {r.Id} Map: {r.Map} Players: {r.Players.Count} Entities: {r.Entities.Count}"); _logger.Trace($"Room: {r.Id} Scene: {r.Scene} Players: {r.Players.Count} Entities: {r.Entities.Count}");
} }
public bool RemoveIfEmpty(RagonRoom room) public bool RemoveIfEmpty(RagonRoom room)
@@ -76,7 +76,7 @@ public class LobbyInMemory : IRagonLobby
} }
foreach (var r in _rooms) foreach (var r in _rooms)
_logger.Trace($"Room: {r.Id} Map: {r.Map} Players: {r.Players.Count} Entities: {r.Entities.Count}"); _logger.Trace($"Room: {r.Id} Scene: {r.Scene} Players: {r.Players.Count} Entities: {r.Entities.Count}");
return result; return result;
} }
+4 -6
View File
@@ -25,7 +25,7 @@ namespace Ragon.Server.Room;
public class RagonRoom : IRagonRoom, IRagonAction public class RagonRoom : IRagonRoom, IRagonAction
{ {
public string Id { get; private set; } public string Id { get; private set; }
public string Map { get; private set; } public string Scene { get; private set; }
public int PlayerMax { get; private set; } public int PlayerMax { get; private set; }
public int PlayerMin { get; private set; } public int PlayerMin { get; private set; }
public int PlayerCount => WaitPlayersList.Count; public int PlayerCount => WaitPlayersList.Count;
@@ -49,7 +49,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin) public RagonRoom(string roomId, RoomInformation info, IRoomPlugin roomPlugin)
{ {
Id = roomId; Id = roomId;
Map = info.Map; Scene = info.Scene;
PlayerMax = info.Max; PlayerMax = info.Max;
PlayerMin = info.Min; PlayerMin = info.Min;
Plugin = roomPlugin; Plugin = roomPlugin;
@@ -182,7 +182,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
public void UpdateMap(string sceneName) public void UpdateMap(string sceneName)
{ {
Map = sceneName; Scene = sceneName;
DynamicEntitiesList.Clear(); DynamicEntitiesList.Clear();
StaticEntitiesList.Clear(); StaticEntitiesList.Clear();
@@ -218,9 +218,7 @@ public class RagonRoom : IRagonRoom, IRagonAction
public IRagonEntity? GetEntityById(ushort id) public IRagonEntity? GetEntityById(ushort id)
{ {
return Entities.TryGetValue(id, out var entity) ? return Entities.TryGetValue(id, out var entity) ? entity : null;
entity :
null;
} }
public IRagonEntity[] GetEntitiesOfPlayer(RagonRoomPlayer player) public IRagonEntity[] GetEntitiesOfPlayer(RagonRoomPlayer player)
@@ -18,7 +18,7 @@ namespace Ragon.Server;
public ref struct RoomInformation public ref struct RoomInformation
{ {
public string Map; public string Scene;
public int Min; public int Min;
public int Max; public int Max;
} }