using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; namespace World { public class PlayerTableOp : BaseReloadableService { private PlayerTable m_table; public override int GetServiceType() { return WorldServiceType.PlayerTableOp; } //销毁的时候置空 public override void Dispose() { m_table = null; } public PlayerTableOp(PlayerTable playerTable) { m_table = playerTable; } public PlayerInfoWorld GetPlayerInfo(long uid) { //是否存在 if(m_table.m_playerTable.ContainsKey(uid)) { return m_table.m_playerTable[uid]; } return null; } public bool AddPlayerInfo(PlayerInfoWorld playerInfo) { if (m_table.m_playerTable.ContainsKey(playerInfo.UserID) == false) { m_table.m_playerTable.Add(playerInfo.UserID, playerInfo); return true; } return false; } public bool RemovePlayerInfo(long uid) { if (m_table.m_playerTable.ContainsKey(uid) == false) { TraceLog.Error("PlayerTableOp.RemovePlayerInfo uid {0} not in table", uid); return false; } return m_table.m_playerTable.Remove(uid); } //获取有效的在线人数,在线的或离线不超过一定时间的(LoginDisconTime) public int GetValidOnlinePlayerCount() { return m_table.m_playerTable.Count(p => p.Value.IsOnline == true) + m_table.m_playerUidList.Count; } public bool AddPlayerTolist(long Uid) { if (m_table.m_playerUidList.Contains(Uid) == false) { m_table.m_playerUidList.Add(Uid); } return true; } public bool RemovePlayerFromList(long Uid) { if (m_table.m_playerUidList.Contains(Uid) == false) { return false; } return m_table.m_playerUidList.Remove(Uid); } public int GetObjCount() { return m_table.m_playerTable.Count; } } }