ET framework---MatchRoomComponent study notes

MatchRoomComponent

Please follow me on Weibo: @NormanLin_BadPixel Bad Pixel


This is the component that manages matching rooms. Now that we have a component to manage matching players, of course we also need this component.

Let's remember first, the properties in our component.

//所有房间列表
public readonly Dictionary<long, Room> rooms = new Dictionary<long, Room>();

//游戏中房间列表
public readonly Dictionary<long, Room> gameRooms = new Dictionary<long, Room>();

//等待中房间列表
public readonly Dictionary<long, Room> readyRooms = new Dictionary<long, Room>();

//空闲房间列表
public readonly Queue<Room> idleRooms = new Queue<Room>();

//房间总数
public int TotalCount { get { return this.rooms.Count; } }

//游戏中房间数
public int GameRoomCount { get { return gameRooms.Count; } }

//等待中房间数
public int ReadyRoomCount { get { return readyRooms.Where(p => p.Value.Count < 3).Count(); } }

//空闲房间数
public int IdleRoomCount { get { return idleRooms.Count; } }

These are shared properties, we can get and modify them at any time.

It should be noted here that the method of obtaining the number of waiting rooms is not simply returning the length of the waiting room list. Because some rooms may be full, but some players are not ready, or the homeowner has not started the game. At this time, the state of the room is still waiting . However, our component is for matching, and we want to get rooms that can be added, so it will exclude rooms that are full.

As for the logic of this component, it is in the extension. Let's take a look.

The methods inside are relatively simple, and the author has made detailed comments. I will not talk nonsense, it is nothing more than performing various operations on the above properties.

Here is a little talk about the method of getting the matching room in waiting . It uses FirstOrDefault on IEnemerable . Maybe some people don't know this method very well (me too haha). Here is a blog post for you. Find() and First() differ from FirstOrDefault() .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325815582&siteId=291194637