/// <summary> /// 创始成功之后处理事件 /// </summary> public void OnCreateAfter(GameUser user) { var cacheSet = new ShareCacheStruct<UserNickName>(); UserNickName u = new UserNickName(user.UserId); u.NickName = user.NickName; cacheSet.Add(u); }
private GameUser CreateRole() { GameUser user = new GameUser(UserId); user.SessionID = Sid; user.Pid = Pid; user.HeadIcon = HeadID; user.RetailId = RetailID; user.NickName = UserName; user.RealName = ""; user.Hobby = ""; user.Profession = ""; user.Sex = Sex.ToBool(); user.UserLv = (short)ConfigEnvSet.GetInt("User.Level", 1); user.GiftGold = ConfigEnvSet.GetInt("User.GiftGold", 100); user.GameCoin = ConfigEnvSet.GetInt("User.GameCoin", 1000); user.VipLv = ConfigEnvSet.GetInt("User.VipLv"); user.UserStatus = UserStatus.Normal; user.MsgState = true; user.MobileType = MobileType; user.ScreenX = ScreenX; user.ScreenY = ScreenY; user.ClientAppVersion = ReqAppVersion; user.LoginDate = DateTime.Now; user.CreateDate = DateTime.Now; user.TitleId = 1001; user.Property.GameId = GameID; user.Property.ServerId = ServerID; user.Birthday = new DateTime(1970, 1, 1); user.RemoteAddress = httpGet.RemoteAddress; var cacheSet = new GameDataCacheSet<GameUser>(); cacheSet.Add(user); cacheSet.Update(); //增加初始背包、玩家任务表、玩家成就表 var itemCacheSet = new GameDataCacheSet<UserItemPackage>(); itemCacheSet.Add(new UserItemPackage(UserId)); itemCacheSet.Update(); var taskCacheSet = new GameDataCacheSet<UserTask>(); taskCacheSet.Add(new UserTask(UserId)); taskCacheSet.Update(); var achieveCacheSet = new GameDataCacheSet<UserAchieve>(); achieveCacheSet.Add(new UserAchieve(UserId)); achieveCacheSet.Update(); UserDailyRestrain restrain = new UserDailyRestrain(UserId); restrain.RefreshDate = DateTime.Now.AddDays(-1); var restrainCacheSet = new GameDataCacheSet<UserDailyRestrain>(); restrainCacheSet.Add(restrain); restrainCacheSet.Update(); return user; }
public static bool IsAllow(GameUser user, ChatType chatType) { if (user != null) { if (chatType == ChatType.World && (DateTime.Now - user.Property.ChatDate).TotalSeconds >= IntervalSend) { return true; } else if (chatType != ChatType.World) { return true; } } return false; }
public void SendWhisper(GameUser toUser, string content) { if (_user == null || toUser == null) { throw new Exception("发送人或接收人为空值"); } _user.Property.ChatDate = DateTime.Now; var chat = new ChatData { Version = 0, FromUserID = _user.UserId, FromUserName = _user.NickName, ToUserID = toUser.UserId.ToInt(), ChatType = ChatType.Whisper, Content = content, SendDate = DateTime.Now, RoomId = _user.Property.RoomId, TableId = _user.Property.TableId }; SendWhisper(toUser.UserId.ToInt(), chat); }
public DdzChatService(GameUser user) : base(user.UserId.ToInt()) { _wordServer = new SensitiveWordService(); this._user = user; }
/// <summary> /// 桌子占位 /// </summary> /// <param name="table"></param> /// <param name="pos"></param> /// <param name="user"></param> /// <param name="roomId"></param> private static void SetTablePosition(int roomId, TableData table, PositionData pos, GameUser user) { pos.Init(user); user.Property.InitTablePos(roomId, table.TableId, pos.Id); }
/// <summary> /// 检查逃跑,并结束当局游戏,扣分两家平分 /// </summary> /// <param name="user"></param> /// <param name="table"></param> /// <param name="userPos"></param> private void CheckFlee(GameUser user, TableData table, PositionData userPos) { table.IsClosed = true; if (table.IsStarting) { int multipleMinNum = ConfigEnvSet.GetInt("Game.FleeMultipleNum", 10); PositionData pos = null; List<PositionData> posList = new List<PositionData>(); //计算炸弹数量 foreach (PositionData position in table.Positions) { if (position.UserId == user.UserId) { pos = position; } else { posList.Add(position); } var obj = _cardRole.ParseCardGroup(position.CardData.ToArray()); for (int i = 0; i < obj.Count; i++) { var item = obj.GetSame(i); if (item.Length == 4 || (item.Length == 2 && _cardRole.GetCardSize(item[0]) > (int)CardSize.C_2)) { table.DoDouble(); } } } table.IsFlee = true; if (table.MultipleNum < multipleMinNum) { table.SetDouble(multipleMinNum); } DoSettlement(table, false, pos, posList); var param = new Parameters(); param.Add("FleeUserId", user.UserId); var userList = ClientNotifier.GetUserList(table, user.UserId); SyncNotifyAction(ActionIDDefine.Cst_Action2013, userList, param, c => { DoComplatedSettlement(table); //todo TraceLog.WriteComplement("桌子:{0}玩家{1}逃跑通知", table.TableId, user.UserId); }); NotifyUserChange(user.UserId); } else { //还没有开始时,可以离开位置等待新玩家 user.Property.InitTablePos(); userPos.Init(); table.IsClosed = false; int periodAiStart = ConfigEnvSet.GetInt("Game.Table.AIIntoTime", 5000); table.ReStartTimer(periodAiStart); var userList = ClientNotifier.GetUserList(table, user.UserId); SyncNotifyAction(ActionIDDefine.Cst_Action2003, userList, null, null); } }
/// <summary> /// 明牌 /// </summary> /// <param name="user"></param> /// <param name="tableData"></param> public void ShowCard(GameUser user, TableData tableData) { var pos = GetUserPosition(user, tableData); if (pos != null && pos.IsLandlord && !tableData.IsShow) { tableData.DoDouble(); pos.IsShow = true; tableData.IsShow = true; SyncNotifyAction(ActionIDDefine.Cst_Action2008, tableData, null, null); //todo TraceLog.WriteComplement("桌子:{0}玩家{1}明牌通知成功", tableData.TableId, user.UserId); } }
public void SyncNotifyAction(int actionId, GameUser user, Parameters parameters, Action<int> callback) { ClientNotifier.NotifyAction(actionId, user, parameters, callback); }
/// <summary> /// 获取桌面对象数据Pyton中调用 /// </summary> /// <param name="user"></param> /// <returns></returns> public TableData GetTableData(GameUser user) { TableData tableData = GetTableData(user.Property.RoomId, user.Property.TableId); //if (tableData == null) //{ // var param = new Parameters(); // param.Add("FleeUserId", 0); // var list = new List<GameUser>(); // list.Add(user); // GameTable.Current.SyncNotifyAction(ActionIDDefine.Cst_Action2013, list, param, null); //} return tableData; }
/// <summary> /// 选择桌位,找不到桌子自动新开一个 /// </summary> /// <param name="user"></param> /// <param name="roomData"></param> /// <param name="roomInfo"></param> /// <returns></returns> public TableData SelectTable(GameUser user, RoomData roomData, RoomInfo roomInfo) { TableData useTable = null; roomData.Tables.Foreach((key, table) => { if (SelectPosition(user, roomData, table)) { useTable = table; //退出Foreach return false; } return true; }); if (roomData.TablePool.Count == 0) { //初始桌数 int minTableCount = ConfigEnvSet.GetInt("Game.Table.MinTableCount", 10); var pokers = PokerList; TableData tableData = null; for (int i = 0; i < minTableCount; i++) { int tableId = roomData.NewTableId; tableData = new TableData(roomData.RoomId, tableId, roomInfo.PlayerNum, roomInfo.AnteNum, roomInfo.MultipleNum, DoTableTimer, roomInfo.CardPackNum); roomData.TablePool.Enqueue(tableData); CreateCardData(tableData, pokers); } } if (useTable == null && roomData.TablePool.TryDequeue(out useTable)) { SetTablePosition(roomData.RoomId, useTable, useTable.Positions[0], user); roomData.Tables.Add(useTable.TableId, useTable); } if (useTable != null && !useTable.IsTimerStarted) { int periodAiStart = ConfigEnvSet.GetInt("Game.Table.AIIntoTime", 5000); useTable.ReStartTimer(periodAiStart); } return useTable; }
/// <summary> /// /// </summary> public DdzBroadcastService(GameUser user) { _user = user; _wordServer = new SensitiveWordService(); }
/// <summary> /// 游戏大厅 /// </summary> /// <param name="user"></param> public GameHall(GameUser user) { _user = user; }
/// <summary> /// 触发通知 --单个玩家 /// </summary> /// <param name="actionId"></param> /// <param name="user"></param> /// <param name="parameters"></param> /// <param name="callback"></param> public static void NotifyAction(int actionId, GameUser user, Parameters parameters, Action<int> callback = null) { var list = new List<GameUser>(); list.Add(user); NotifyAction(actionId, list, parameters, callback); }
/// <summary> /// 离开桌位 /// </summary> /// <param name="user"></param> /// <param name="table"></param> public void ExitTablePosition(GameUser user, TableData table) { if (table.IsFlee) { return; } foreach (var pos in table.Positions) { if (pos.Id == user.Property.PositionId) { CheckFlee(user, table, pos); break; } } }
/// <summary> /// 初始化AI /// </summary> public void InitAI(int roomId, int tableId, int userId, string nickName, string head) { //todo test var ai = new GameUser(userId); ai.NickName = nickName; ai.HeadIcon = head; ai.Property.InitTablePos(roomId, tableId, _id); Init(ai, true); }
/// <summary> /// 初始化 /// </summary> public void Init(GameUser user = null, bool isAI = false) { UserId = user == null ? 0 : user.UserId; NickName = user == null ? "" : user.NickName; HeadIcon = user == null ? "" : user.HeadIcon; IsAI = isAI; ReSendCard(); }
/// <summary> /// 检查赠送金豆 /// </summary> /// <param name="user"></param> /// <param name="roomInfo"></param> public bool CheckDailyGiffCoin(GameUser user, RoomInfo roomInfo) { UserDailyRestrain restrain = new GameDataCacheSet<UserDailyRestrain>().FindKey(user.PersonalId); if (restrain != null) { RefreshRestrain(restrain); int dailyGiffCoinTime = ConfigEnvSet.GetInt("User.DailyGiffCoinTime", 1); if (restrain.RestrainProperty.DailyGiffCoinTime < dailyGiffCoinTime) { user.GameCoin = MathUtils.Addition(user.GameCoin, roomInfo.GiffCion); restrain.RestrainProperty.DailyGiffCoinTime = MathUtils.Addition(restrain.RestrainProperty.DailyGiffCoinTime, 1); return true; } } return false; }
/// <summary> /// 进入房间 /// </summary> public void Enter(GameUser user, RoomInfo roomInfo) { List<PositionData> list = new List<PositionData>(); string key = roomInfo.Id.ToString(); RoomData roomData; if (_roomStruct.TryGet(key, out roomData)) { var tableData = GameTable.Current.SelectTable(user, roomData, roomInfo); if (tableData != null && tableData.Positions.Length > 0) { GameTable.Current.SyncNotifyAction(ActionIDDefine.Cst_Action2003, tableData, null, c => { GameTable.Current.CheckStart(tableData); }); } } }
/// <summary> /// 找桌位,已经进入过保留原位置 /// </summary> /// <param name="user"></param> /// <param name="roomData"></param> /// <param name="table"></param> /// <returns></returns> public bool SelectPosition(GameUser user, RoomData roomData, TableData table) { var userPos = Array.Find(table.Positions, m => m.UserId == user.UserId); if (userPos != null) { //已经在桌上 SetTablePosition(roomData.RoomId, table, userPos, user); return true; } if (!table.IsSettlemented && table.BackCardData.Count > 0) { //已经发牌 return false; } if (table.IsSettlemented && table.BackCardData.Count > 0) { DoComplatedSettlement(table); return false; } foreach (var pos in table.Positions) { lock (table) { if (pos.UserId == 0) { SetTablePosition(roomData.RoomId, table, pos, user); return true; } } } return false; }
/// <summary> /// 获取玩家手上的牌,并自动整理牌从大到小排列 /// </summary> /// <returns></returns> public List<int> GetUserCardData(GameUser user, TableData tableData, bool isSort = true) { var list = new List<int>(); var pos = GetUserPosition(user, tableData); if (pos != null) { if (pos.CardData.Count > 0) { list.AddRange(pos.CardData); if (isSort) { _cardRole.SortCard(pos.CardData); } } } return list; }
/// <summary> /// 离开房间 /// </summary> /// <param name="user"></param> /// <returns></returns> public bool Exit(GameUser user) { if (user.Property.RoomId == 0) { return true; } string key = user.Property.RoomId.ToString(); RoomData roomData; if (_roomStruct.TryGet(key, out roomData)) { TableData table; if (roomData.Tables.TryGetValue(user.Property.TableId, out table)) { GameTable.Current.ExitTablePosition(user, table); user.Property.RoomId = 0; return true; } } return false; }
/// <summary> /// 获取个人元宝 /// </summary> /// <param name="user"></param> /// <returns></returns> public static void Trigger(GameUser user) { new DdzPaymentNotify().Notify(user); }
/// <summary> /// 获取玩家座位 /// </summary> /// <param name="user"></param> /// <param name="tableData"></param> /// <returns></returns> public PositionData GetUserPosition(GameUser user, TableData tableData) { return GetUserPosition(user.Property.PositionId, tableData); }