refactor:房间对战逻辑优化以及timer间隔修改为500ms

This commit is contained in:
lishuo committed 2023-06-28 17:14:39 +08:00
1 parent b51bac2abe
commit b6ea5934c5
2 files changed
+8 -7

No files matched your search

+7 -7
View File
@@ -112,7 +112,7 @@ namespace OnlineUserPool.ViewModels
Log.Information("服务启动成功");
timer = new System.Timers.Timer(1000);
timer = new System.Timers.Timer(500);
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = true;
timer.Start();
@@ -524,28 +524,28 @@ namespace OnlineUserPool.ViewModels
private void HandleGameRoomKick(ReceiveModel msg)
{
var msg1 = msg as GameRoomKickCommand;
var room = RoomList.ToList().Where(c => c.RoomId == msg1.RoomId).FirstOrDefault();
var room = RoomList.ToList().FirstOrDefault(c => c.RoomId == msg1.RoomId);
if (room != null)
{
var list = room.List;
var needRemove = list.Where(c => c.UserId == msg1.UserId).FirstOrDefault();
var needRemove = list.FirstOrDefault(c => c.UserId == msg1.UserId);
if (needRemove != null)
{
list.Remove(needRemove);
//如果当前是房主退出房间,房主替换成其他人, 房主客户端中断也算
if (needRemove.IsOwner && list.Count() > 0)
if (needRemove.IsOwner && list.Any())
{
var newOwner = list.FirstOrDefault();
newOwner.IsOwner = true;
room.UserId = newOwner.UserId;
}
}
//人数为0,删除房间
if (list.Count() == 0)
//房间没有产生记录且人数为0,删除房间
if (!room.Saved && !list.Any())
{
RoomList.Remove(room);
}
var mine = Clients.Where(c => c.MemberId == msg1.UserId).FirstOrDefault();
var mine = Clients.FirstOrDefault(c => c.MemberId == msg1.UserId);
if (mine != null)
{
mine.RoomId = 0;