using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Text; using Sog; namespace World { //排队登录时间(秒) public enum WaitInLineTimeType { LoginDisconTime = 60, //登录下线后,60秒内重新连接登录不需要排队 WaitDisconTime = 60, //本身就在排队中,断线或离开后,60秒内不用重新排队 } public class WaitInLinePlayerTableDataOp : BaseReloadableService { private WaitInLinePlayerTableData m_table; public override int GetServiceType() { return WorldServiceType.WaitInLinePlayerTableOp; } //销毁的时候置空 public override void Dispose() { m_table = null; } public WaitInLinePlayerTableDataOp(WaitInLinePlayerTableData playerTable) { m_table = playerTable; } //获取等待玩家的数量 public int GetWaitInLlineLoginPlayerCount() { return m_table.m_waitInLinePlayer.Count; } //根据uid获取玩家 public WaitInLlineLoginPlayer GetWaitInLlineLoginPlayerByUid(long uid) { return m_table.m_waitInLinePlayer.FirstOrDefault(p => p.UserID == uid); } //获取第一个等待的玩家 public WaitInLlineLoginPlayer GetFirstWaitInLlineLoginPlayer() { if (GetWaitInLlineLoginPlayerCount() > 0) { return m_table.m_waitInLinePlayer.First(); } return null; } //获取某个玩家后面的第一个玩家 public WaitInLlineLoginPlayer GetNextAfterPlayer(long uid) { bool isThis = false; foreach (var waitPlayer in m_table.m_waitInLinePlayer) { if (isThis) { return waitPlayer; } if (waitPlayer.UserID == uid) { isThis = true; } } return null; } //获取某个玩家前面还有多少玩家在等待 public int GetBeforeMeWaitPlayerCount(long uid) { int count = 0; foreach (var waitPlayer in m_table.m_waitInLinePlayer) { if (waitPlayer.UserID == uid) { break; } count++; } return count; } public WaitInLlineLoginPlayer AddWaitInLlineLoginPlayer(long uid, long playersessionID) { var player = GetWaitInLlineLoginPlayerByUid(uid); if (player == null) { player = new WaitInLlineLoginPlayer(); player.UserID = uid; player.WaitBeginTime = WorldServerUtils.GetTimeSecond(); m_table.m_waitInLinePlayer.AddLast(player); } player.playersessionID = playersessionID; player.BeginDisConTime = 0; return player; } public bool DeleteWaitLoginPlayer(WaitInLlineLoginPlayer player) { return m_table.m_waitInLinePlayer.Remove(player); } //删除一个玩家,并返回这个玩家的下个玩家 public WaitInLlineLoginPlayer DeletePlayerReturnNext(WaitInLlineLoginPlayer player) { var nextPlayer = GetNextAfterPlayer(player.UserID); m_table.m_waitInLinePlayer.Remove(player); return nextPlayer; } } }