using System; using System.Collections.Generic; using System.Linq; using Sog; namespace Battle { public class PlayerTableOp : BaseReloadableService { public PlayerTable Table; public override int GetServiceType() { return BattleServiceType.PlayerTableOp; } public override void Dispose() { Table = null; } public PlayerTableOp(PlayerTable table) { Table = table; } public int GetUserCount() { return Table.m_playerTable.Count; } public PlayerOnBattle GetPlayer(long uid) { PlayerOnBattle player; Table.m_playerTable.TryGetValue(uid, out player); return player; } public bool AddPlayer(PlayerOnBattle player) { if(Table.m_playerTable.ContainsKey(player.RoleBase.Uid)) { TraceLog.Error("PlayerTableOp.AddPlayer fail, uid {0} already exist", player.RoleBase.Uid); return false; } Table.m_playerTable.Add(player.RoleBase.Uid, player); return true; } public bool RemovePlayer(PlayerOnBattle player) { return Table.m_playerTable.Remove(player.RoleBase.Uid); } public int GetPlayerCheckFailCount(long uid) { if (Table.m_playerCheckFailCount.TryGetValue(uid, out int count)) { return count; } return 0; } public void AddPlayerCheckFailCount(long uid) { if(Table.m_playerCheckFailCount.TryGetValue(uid, out int count)) { ++count; Table.m_playerCheckFailCount[uid] = count; } else { Table.m_playerCheckFailCount.Add(uid, 1); } } public long GetPlayerLastRestILTime(long uid) { if (Table.m_playerLastRestILTime.TryGetValue(uid, out long count)) { return count; } return 0; } public void AddPlayerLastRestILTime(long uid) { if (Table.m_playerLastRestILTime.ContainsKey(uid)) { Table.m_playerLastRestILTime[uid] = AppTime.GetNowSysSecond(); } else { Table.m_playerLastRestILTime.Add(uid, AppTime.GetNowSysSecond()); } } } }