/// <summary> /// 开始游戏 /// </summary> /// <param name="fightRoom"></param> private void startGame(FightRoom fightRoom)//List<int> uidList) { SingleExecute.Instance.processSingle( () => { //开始游戏广播 fightRoom.Broadcast(OpCode.MATCH, MatchCode.START_GAME_BOD, "0"); //创建牌库 fightRoom.CreateCardLibrary(); //初始化玩家手牌(发牌) fightRoom.InitPlayerCards(); foreach (var item in fightRoom.playerDtos) { //给每个客户端发送自己的手牌信息 List <CardDto> cardList = fightRoom.GetUserCard(item.UserID); ClientPeer clientPeer = UserCache.Instance.GetClientPeer(item.UserID); clientPeer.StartSend(OpCode.FIGHT, FightCode.GET_CARD_SRES, cardList); } //由第一个进入房间的玩家首先开始回合 PlayerDto firstPlayer = fightRoom.GetFirstPlayer(); fightRoom.Broadcast(OpCode.FIGHT, FightCode.NEXT_TURN_SBOD, firstPlayer.UserID); } ); }
public async void GetFightRoom() { FightRoom fightRoom = await GameUser.user.GetFightRoom(); if (fightRoom != null) { camGroup.SetActiveId(1); FreshFightRoom(fightRoom); sceneGroup.SetActiveId(1); if (fightRoom.CheckAllReady() && fightRoom.isFull == "true") { //Debug.LogError("ready!!! " + fightRoom.ip + ":" + fightRoom.port); if (fightRoom.ip != "" && fightRoom.port != "") { StopCoroutine(coroutine); GameUser.user.fightRoom = fightRoom; UnityEngine.SceneManagement.SceneManager.LoadScene("ZombieCity"); } } } else { sceneGroup.SetActiveId(0); camGroup.SetActiveId(0); } }
private void grabLandlord(ClientPeer client, bool result) { SingleExecute.Instance.Execute(() => { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); FightRoom fightRoom = fightCache.GetRoomByUId(userId); if (result == true) { fightRoom.SetLandlord(userId); //send message to all client who was landlord GrabDto dto = new GrabDto(userId, fightRoom.TableCardList, fightRoom.getUserCards(userId)); Broadcast(fightRoom, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BROADCAST, dto); //enter deal phase Broadcast(fightRoom, OpCode.FIGHT, FightCode.TURN_DEAL_BROADCAST, userId); } else { //don't grab int nextUserId = fightRoom.GetNextUserId(userId); Broadcast(fightRoom, OpCode.FIGHT, FightCode.TURN_GRAB_BROADCAST, nextUserId); } }); }
/// <summary> /// 轮换下注 /// </summary> /// <param name="client"></param> private void Turn(ClientPeer client, int turnUserId = -1) { // 清空计时器任务 TimerManager.Instance.Clear(); if (fightCache.IsFighting(client.Id) == false) { return; } FightRoom room = fightCache.GetFightRoomByUserId(client.Id); int nextID = room.Turn(); if (room.IsGiveUpCard(nextID) || room.IsLeaveRoom(nextID) || (turnUserId != -1 && nextID != turnUserId)) { // 如果下一位玩家离开或弃牌了,就继续轮换下注,直到改玩家不离开也不弃牌为止 Turn(client, turnUserId); } else { timerClient = DatabaseManager.GetClientPeerByUserId(nextID); // 添加计时器任务 TimerManager.Instance.AddTimerEvent(60, TimerDelegate); Console.WriteLine("当前下注者" + client.UserName); room.Broadcast(OpCode.Fight, FightCode.StartStakes_BRO, nextID); } }
/// <summary> /// 创建房间 /// </summary> /// <param name="uidList"></param> /// <returns></returns> public FightRoom Create(List <int> uidList) { FightRoom room = null; if (roomQueue.Count > 0) { room = roomQueue.Dequeue(); } else { room = new FightRoom(id.Add_Get(), uidList); } foreach (var item in uidList) { uidRoomDict.Add(item, room.Id); //上一次销毁后的房间数据信息不完整这里补充完整重用销毁的房间 if (room.playerList.Count < 3) { PlayerDto player = new PlayerDto(item); room.playerList.Add(player); } } idRomDict.Add(room.Id, room); return(room); }
/// <summary> /// 游戏结束 /// </summary> /// <param name="room"></param> private void GameOver(FightRoom room) { PlayerDto winPlayer = null; List <PlayerDto> loseList = new List <PlayerDto>(); foreach (var player in room.playerList) { // 胜利的玩家 if (!room.IsGiveUpCard(player.id) && !room.IsLeaveRoom(player.id)) { winPlayer = player; } // 失败的玩家们 else { loseList.Add(player); } } DatabaseManager.UpdateCoin(winPlayer.id, room.stakesSum); gameOverDto.Change(winPlayer, loseList, room.stakesSum); room.Broadcast(OpCode.Fight, FightCode.GameOver_BRO, gameOverDto); //销毁房间 fightCache.DesRoom(room); //清空定时任务 TimerManager.Instance.Clear(); }
/// <summary> /// 客户端的加注处理 /// </summary> /// <param name="client"></param> /// <param name="value"></param> private void AddStakes(ClientPeer client, int multiple) { SingleExecute.Instance.Exeecute(() => { if (fightCache.IsFighting(client.Id) == false) { return; } FightRoom room = fightCache.GetFightRoomByUserId(client.Id); room.lastPlayerStakes *= multiple; if (room.lastPlayerStakes > room.topStakes) // 顶注 { room.lastPlayerStakes = room.topStakes; } room.stakesSum += room.lastPlayerStakes; int stakesSum = room.UpdatePlayerStakesSum(client.Id, room.lastPlayerStakes); int remainCoin = DatabaseManager.UpdateCoin(client.Id, -room.lastPlayerStakes); stakesDto.Change(client.Id, remainCoin, room.lastPlayerStakes, stakesSum, StakesDto.StakesType.NoLook); room.Broadcast(OpCode.Fight, FightCode.PutStakes_BRO, stakesDto); // 剩余金币不够 if (remainCoin < room.lastPlayerStakes) { GiveUpCard(client); return; } Turn(client); }); }
/// <summary> /// 客户端跟注请求的处理 /// </summary> /// <param name="client"></param> private void Follow(ClientPeer client) { SingleExecute.Instance.Execute(() => { if (fightCache.IsFighting(client.Id) == false) { return; } FightRoom room = fightCache.GetFightRoomByUserId(client.Id); room.stakesSum += room.lastPlayerStakesCount; int stakesSum = room.UpdatePlayerStakesSum(client.Id, room.lastPlayerStakesCount); int remainCoin = DatabaseManager.UpdateCoinCount(client.Id, -(room.lastPlayerStakesCount)); stakesDto.Change(client.Id, remainCoin, room.lastPlayerStakesCount, stakesSum, StakesDto.StakesType.NoLook); room.Broadcast(OpCode.Fight, FightCode.PutStakes_BRO, stakesDto); if (remainCoin < room.lastPlayerStakesCount) { GiveUpCard(client); return; } //轮到下一个玩家下注 Turn(client); }); }
/// <summary> /// 客户端弃牌的请求处理 /// </summary> /// <param name="client"></param> private void GiveUpCard(ClientPeer client) { SingleExecute.Instance.Exeecute(() => { if (fightCache.IsFighting(client.Id) == false) { return; } FightRoom room = fightCache.GetFightRoomByUserId(client.Id); room.giveUpUserIdList.Add(client.Id); room.Broadcast(OpCode.Fight, FightCode.GiveUpCard_BRO, client.Id); // 离开的玩家是本次下注的玩家,这样的需转换下一个玩家下注 if (room.roundModel.CurrentStakesUserId == client.Id) { //轮换下注 Turn(client); } // 一个弃牌,一个逃跑 if (room.giveUpUserIdList.Count >= 1 && room.leaveUserIdList.Count >= 1) { GameOver(room); } // 两个逃跑 if (room.giveUpUserIdList.Count == 2) { GameOver(room); } }); }
/// <summary> /// 处理游戏结束 /// </summary> private void OnGameOver(FightRoom room, int winTeam) { room.Brocast(OpCode.FightCode, OpFight.GameOver, 0, "游戏结束", null, winTeam); //更新玩家的数据 foreach (MobaClient client in room.clientList) { //获取玩家数据模型 PlayerModel playerModel = playerCache.GetModel(client); //检测是否逃跑 if (room.leaveClient.Contains(client)) { //更新逃跑场次 playerCache.UpdateModel(playerModel, 2); } //胜利失败判断 HeroModel heroModel = room.GetHeroModel(playerModel.Id); if (heroModel.Team == winTeam) { //赢了 playerCache.UpdateModel(playerModel, 0); } else { //输了 playerCache.UpdateModel(playerModel, 1); } } //销毁战斗房间 fightCache.Destroy(room.Id); }
/// <summary> /// 使用技能 /// </summary> /// <param name="skillId"></param> /// <param name="targetId"></param> private void OnSkill(MobaClient client, int skillId, int attackId, int targetId, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId, client); //先判断是不是普通攻击 if (skillId == 1) { //参数 1使用者,2目标者 room.Brocast(OpCode.FightCode, OpFight.Skill, 0, "有人进行普通攻击", null, attackId, targetId); } //从技能配置获取技能信息,在广播 else { if (targetId == -1) { //定点技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "定点释放技能", null, skillId, attackId, -1, x, y, z); } else { //指定目标技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "选择目标释放技能", null, skillId, attackId, targetId); } } }
/// <summary> /// 转换下家 /// </summary> /// <param name="room">房间</param> /// <param name="subCode">是出牌转换还是抢地主转换</param> private void Turn(FightRoom room, int subCode) { int nextUserId = room.TurnNext(); if (room.leavePlayerIdList.Contains(nextUserId)) { //掉线了就不出牌, Turn(room, subCode); } else { //没有掉线 //var client = user.GetClientById(nextUserId); //client.StartSend(OpCode.FIGHT, FightCode.CHUPAI_TURN_BRO, null); Brocast(room, OpCode.FIGHT, subCode, nextUserId); //再添加一个延时任务 30s后不抢自动不抢 var client = user.GetClientById(nextUserId); if (subCode == FightCode.QIANG_TURN_BRO) { room.autoBuQiang = TimerMananger.Instance.AddTimeTask((int intPara) => { //30秒后自动不抢 Qiang_Landlord(client, false); Console.WriteLine("自动不抢。。。"); }, 10); } else if (subCode == FightCode.CHUPAI_TURN_BRO) { //TODO 30s后自动不出 } } }
/// <summary> /// 玩家跳过 /// </summary> /// <param name="clientPeer"></param> private void processPass(ClientPeer clientPeer) { SingleExecute.Instance.processSingle( () => { if (!UserCache.Instance.IsOnline(clientPeer)) { return; } int uid = UserCache.Instance.GetId(clientPeer); FightRoom fightRoom = FightRoomCache.Instance.GetRoomByUid(uid); PlayerDto playerDto = fightRoom.GetPlayerDto(uid); if (fightRoom.roundModle.BiggestUid == playerDto.UserID) { //clientPeer.StartSend(OpCode.FIGHT, FightCode.PASS_SRES, false); //最大出牌者不能不出 return; } else { turn(fightRoom); //轮换出牌 //clientPeer.StartSend(OpCode.FIGHT, FightCode.PASS_SRES, true); } } ); }
/// <summary> /// 处理玩家离开 /// </summary> /// <param name="clientPeer"></param> private void processLeave(ClientPeer clientPeer) { SingleExecute.Instance.processSingle( () => { if (!UserCache.Instance.IsOnline(clientPeer)) { return; } int uid = UserCache.Instance.GetId(clientPeer); if (!FightRoomCache.Instance.IsJoinFight(uid)) { //如果没有进入战斗房间 return; } FightRoom fightRoom = FightRoomCache.Instance.GetRoomByUid(uid); PlayerDto playerDto = fightRoom.GetPlayerDto(uid); fightRoom.LeavePlayerDtos.Add(playerDto); fightRoom.Leave(clientPeer); fightRoom.UidRaceidDic.Remove(uid); if (fightRoom.LeavePlayerDtos.Count >= 2) { //所有玩家都离开了 FightRoomCache.Instance.Destroy(fightRoom.ID); } } ); }
/// <summary> /// 使用技能 /// </summary> /// <param name="v1"></param> /// <param name="v2"></param> private void onSkill(MobaClient client, int skillId, int attackId, int targetId, float x, float y, float z) { int playerId = playerCache.GetId(client); FightRoom room = fightCache.GetRoom(playerId); //先判断 是不是普通攻击 if (skillId == 1) { //TODO //参数:1.攻击者ID 2.被攻击者ID room.Brocast(OpCode.FightCode, OpFight.Skill, 0, "有人普通攻击", null, attackId, targetId); } //是技能 从技能配置表里面通过技能ID获取到技能信息 然后再广播 else { if (targetId == -1) { //指定点的技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "有人释放指定点的技能了", null, skillId, attackId, -1, x, y, z); } else { //指定目标的技能 room.Brocast(OpCode.FightCode, OpFight.Skill, 1, "有人释放指定目标的技能了", null, skillId, attackId, targetId); } } }
/// <summary> /// 游戏结束 /// </summary> /// <param name="room"></param> /// <param name="winTeam"></param> private void onGameOver(FightRoom room, int winTeam) { //广播游戏结束的消息,参数是胜利的部队 room.Brocast(OpCode.FightCode, OpFight.GameOver, 0, "游戏结束", null, winTeam); //更新玩家的数据 foreach (MobaClient client in room.ClientList) { PlayerModel model = playerCache.GetModel(client); //检测是否逃跑 if (room.LeaveClient.Contains(client)) { //更新逃跑场次 playerCache.UpdateModel(model, 2); } //队伍1赢了 if (winTeam == 1) { HeroModel hero = room.GetHeroModel(model.Id); if (hero.Team == winTeam) { //赢了 playerCache.UpdateModel(model, 0); } else { //输了 playerCache.UpdateModel(model, 1); } } } //销毁房间 fightCache.Destroy(room.Id); }
/// <summary> /// 广播给一个房间内的一个玩家 /// </summary> /// <param name="room"></param> /// <param name="opCode"></param> /// <param name="subCode"></param> /// <param name="value"></param> /// <param name="exClient"></param> private void singleBrocast(FightRoom room, int opCode, int subCode, object value, int userId, ClientPeer exClient = null) { SocketMsg msg = new SocketMsg(); msg.OpCode = opCode; msg.SubCode = subCode; msg.Value = value; byte[] data = EncodeTool.EncodeMsg(msg); byte[] packet = EncodeTool.EncodePacket(data); foreach (var player in room.PlayerList) { if (userCache.IsOnline(player.UserId)) { ClientPeer client = userCache.GetClientPeer(player.UserId); if (player.UserId == userId) { if (client == exClient) { continue; } client.Send(packet); } } } }
/// <summary> /// 不出的处理 /// </summary> /// <param name="client"></param> private void Pass(ClientPeer client) { SingleExecute.Instance.Execute( delegate() { //玩家在线 if (user.IsOnLine(client) == false) { return; } int userId = user.GetIdByClient(client); FightRoom room = fight.GetRoom(userId); //2中情况 if (room.roundModel.BiggestUid == userId) { //我是最大的 我必须得出 client.Send(OpCode.FIGHT, FightCode.PASS_SRES, -1); return; } else { //可以不出 client.Send(OpCode.FIGHT, FightCode.PASS_SRES, 0); Turn(room); } } ); }
/// <summary> /// 处理种族选择请求 /// </summary> /// <param name="clientPeer"></param> /// <param name="race"></param> private void processSelectRice(ClientPeer clientPeer, int race) { SingleExecute.Instance.processSingle( () => { if (!UserCache.Instance.IsOnline(clientPeer)) { return; } int uid = UserCache.Instance.GetId(clientPeer); //获得战斗房间 FightRoom fightRoom = FightRoomCache.Instance.GetRoomByUid(uid); switch (race) { case RaceType.ORC: //选择了兽族 fightRoom.UidRaceidDic.Add(uid, RaceType.ORC); break; } if (fightRoom.UidRaceidDic.Count >= fightRoom.playerDtos.Count) { //如果房间内的所有人都选择完了种族 startGame(fightRoom); } } ); }
/// <summary> /// 游戏结束 /// </summary> private void GameOver(int userId, FightRoom room) { //确定身份 是农民还是地主 int identity = room.GetPlayerIdentity(userId); List <int> winUids = room.GetSameIdentityUids(identity); int winBeen = room.Mutiple * 1000; //给胜利的玩家 胜场 豆子 经验 等级..之后玩家数据模型刷新 for (int i = 0; i < winUids.Count; i++) { UserModel model = user.GetModelByUserId(winUids[i]); model.winCount++; model.been += winBeen; model.exp += 100; int maxExp = model.lv * 100; while (maxExp <= model.exp) { model.lv++; model.exp -= maxExp; maxExp = model.lv * 100; } user.Update(model); } //给失败的玩家 败场 豆子 经验 等级..之后玩家数据模型刷新 List <int> loseUids = room.GetDifIdentityUids(identity); for (int i = 0; i < winUids.Count; i++) { UserModel model = user.GetModelByUserId(loseUids[i]); model.loseCount++; model.been -= winBeen; model.exp += 10; int maxExp = model.lv * 100;; while (maxExp <= model.exp) { model.lv++; model.exp -= maxExp; maxExp = model.lv * 100; } user.Update(model); } //给逃跑的玩家 逃跑 豆子 经验 等级..之后玩家数据模型刷新 for (int i = 0; i < room.LeaveUidList.Count; i++) { UserModel model = user.GetModelByUserId(room.LeaveUidList[i]); model.runCount++; model.been -= (winBeen) * 3; model.exp += 0; user.Update(model); } //给客户端发消息 谁赢了。身份,豆子多少 OverDto dto = new OverDto(); dto.winIdentity = identity; dto.winUidList = winUids; dto.beenCount = winBeen; Brocast(room, OpCode.FIGHT, FightCode.OVER_BRO, dto); fight.Destroy(room); }
/// <summary> /// 抢地主处理 /// </summary> private void GrabLandLord(ClientPeer client, bool result) { SingleExecute.Instance.Execute( delegate() { if (user.IsOnLine(client) == false) { return; } int userId = user.GetIdByClient(client); FightRoom room = fight.GetRoomByUid(userId); if (result == true) { //抢 room.SetLandlord(userId); GrabDto grab = new GrabDto(userId, room.TableCardList, room.GetPlayerCard(userId)); //广播 谁是地主 三张底牌 Brocast(room, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BRO, grab); //发送一个出牌的命令 Brocast(room, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, userId); } else { //不抢 int nextUid = room.GetNextUid(userId); Brocast(room, OpCode.FIGHT, FightCode.TURN_GRAB__BRO, nextUid); } }); }
/// <summary> /// 开始战斗 /// </summary> public void StartFight(List <int> uidList) { SingleExecute.Instance.Execute( delegate() { //创建战斗房间 FightRoom room = fightCache.Create(uidList); room.InitPlayerCards(); room.Sort(); //发送给每个客户端 他自身有什么牌 foreach (int uid in uidList) { ClientPeer client = userCache.GetClientPeer(uid); List <CardDto> cardList = room.GetUserCards(uid); //int[] cardIds = new int[17]; //54 每一张牌 都是一个 id //红桃A 是 0 //红桃2 是 1 //红桃3 是 2 //红桃4 是 3 //红桃5 是 4 //发送的int数组 是 234 client.Send(OpCode.FIGHT, FightCode.GET_CARD_SRES, cardList); } //发送开始抢地主的响应 int firstUserId = room.GetFirstUId(); brocast(room, OpCode.FIGHT, FightCode.TURN_GRAB_BRO, firstUserId, null); }); }
/// <summary> /// 不出的处理 /// </summary> /// <param name="client"></param> private void pass(ClientPeer client) { SingleExecute.Instance.Execute( () => { if (userCache.IsOnline(client) == false) { return; } //必须确保在线 int userId = userCache.GetId(client); //if() FightRoom room = fightCache.GetRoomByUId(userId); //分两种情况 if (room.roundModel.BiggestUId == userId) { //当前玩家是最大出牌者 没管它 他不能不出 client.Send(OpCode.FIGHT, FightCode.PASS_SRES, -1); return; } else { //可以不出 client.Send(OpCode.FIGHT, FightCode.PASS_SRES, 0); turn(room); } }); }
public void Chat(ClientPeer client, int type) { SingleExecute.Instance.Execute(() => { if (!user.IsOnLine(client)) { return; } int userId = user.GetId(client); //匹配场景 if (match.IsMatching(userId)) { MatchRoom mr = match.GetRoom(userId); ChatDto dto = new ChatDto(userId, type); mr.Brocast(OpCode.CHAT, ChatCode.CHAT_SRES, dto); } else if (fight.IsFighting(userId)) { //战斗场景 FightRoom mr = fight.GetRoom(userId); ChatDto dto = new ChatDto(userId, type); //fight.(OpCode.CHAT, ChatCode.CHAT_SRES, dto); Brocast(mr, OpCode.CHAT, ChatCode.CHAT_SRES, dto); } }); }
/// <summary> /// 抢地主的处理 /// </summary> private void grabLandlord(ClientPeer client, bool result) { SingleExecute.Instance.Execute( delegate() { if (userCache.IsOnline(client) == false) { return; } //必须确保在线 int userId = userCache.GetId(client); //if() FightRoom room = fightCache.GetRoomByUId(userId); if (result == true) { //抢 room.SetLandlord(userId); //给每一个客户端发一个消息 谁当了地主 // 第一个:地主id 第二个:三张底牌 GrabDto dto = new GrabDto(userId, room.TableCardList, room.GetUserCards(userId)); brocast(room, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BRO, dto); //发送一个出牌命令 brocast(room, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, userId); } else { //不抢 int nextUId = room.GetNextUId(userId); brocast(room, OpCode.FIGHT, FightCode.TURN_GRAB_BRO, nextUId); } }); }
/// <summary> /// 用户离开 /// </summary> /// <param name="client"></param> private void leave(ClientPeer client) { SingleExecute.Instance.Execute(() => { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); if (fightCache.IsFighting(userId) == false) { return; } FightRoom fightRoom = fightCache.GetRoomByUId(userId); //中途退出 fightRoom.LeaveUIdList.Add(userId); Brocast(fightRoom, OpCode.FIGHT, FightCode.LEAVE_BRO, userId); if (fightRoom.LeaveUIdList.Count == 3) { //给逃跑玩家添加逃跑场次 for (int i = 0; i < fightRoom.LeaveUIdList.Count; i++) { UserModel um = userCache.GetModelById(fightRoom.LeaveUIdList[i]); um.RunCount++; um.Been -= fightRoom.Multiple * 1000 * 3; um.Exp += 0; userCache.Update(um); } //销毁缓存层的房间数据 fightCache.Destroy(fightRoom); } }); }
/// <summary> /// 抢地主 /// </summary> /// <param name="client"></param> /// <param name="result"></param> private void grabLandlord(ClientPeer client, bool result) { SingleExecute.Instance.Execute(() => { if (!userCache.IsOnline(client)) { return; } int userId = userCache.GetId(client); FightRoom fightRoom = fightCache.GetRoomByUId(userId); if (result == true) { //抢 fightRoom.SetLandlord(userId); //给每个客户端发送消息谁当了地主 GrabDto dto = new GrabDto(userId, fightRoom.TableCardList, fightRoom.getUserCards(userId)); Brocast(fightRoom, OpCode.FIGHT, FightCode.GRAB_LANDLORD_BRQ, dto); Brocast(fightRoom, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, userId); } else { //不抢 int nextUId = fightRoom.GetNextUId(userId); Brocast(fightRoom, OpCode.FIGHT, FightCode.TURN_GRAB_BRO, nextUId); } }); }
/// <summary> /// 转换出牌 /// </summary> /// <param name="room"></param> private void Turn(FightRoom room) { int nextUId = room.Turn(); //如果下一个玩家掉线 if (room.IsOffline(nextUId)) { //room.roundModel.BiggestUId = nextUId; //下一个也掉线了 递归 Console.WriteLine("下一个玩家掉线 " + nextUId); Turn(room); //TODO 掉线人物AI } else { //给客户端广播开始计时 td.Change(nextUId, 20 * 10000000, DateTime.Now.Ticks); //玩家不掉线就给他发消息让他出牌 Brocast(room, OpCode.FIGHT, FightCode.TURN_DEAL_BRO, nextUId); //添加定时任务 TimeOutManager.Instance.AddTimeEvent(20 * 10000000, nextUId, TimeOut); Brocast(room, OpCode.FIGHT, FightCode.START_TIMING_BRO, td); } }
public void FreshFightRoom(FightRoom fightRoom) { for (int i = 0; i < fightRoom.playerInfos.Count; i++) { var character = fightRoom.playerInfos[i].character; FreshCharacter(character, fightRoomPosList[i]); } }
/// <summary> /// 游戏结束 /// </summary> /// <param name="userId"></param> /// <param name="room"></param> private void gameOver(int userId, FightRoom room) { int winIdentity = room.GetPlayerIdeentity(userId); int winBeen = room.Multiple * 1000; List <int> winUIds = room.GetSameIdentityUIds(winIdentity); //给胜利的玩家添加胜场 for (int i = 0; i < winUIds.Count; i++) { UserModel um = userCache.GetModelById(winUIds[i]); um.WinCount++; um.Been = winBeen; um.Exp += 100; int maxExp = um.Lv * 100; while (maxExp <= um.Exp) { um.Lv++; um.Exp -= maxExp; } userCache.Update(um); } //给失败的玩家添加负场 List <int> loseUIds = room.GetDifferentIdentityUIds(winIdentity); for (int i = 0; i < loseUIds.Count; i++) { UserModel um = userCache.GetModelById(loseUIds[i]); um.LoseCount++; um.Been -= winBeen; um.Exp += 10; int maxExp = um.Lv * 100; while (maxExp <= um.Exp) { um.Lv++; um.Exp -= maxExp; } userCache.Update(um); } //给逃跑玩家添加逃跑场次 for (int i = 0; i < room.LeaveUIdList.Count; i++) { UserModel um = userCache.GetModelById(room.LeaveUIdList[i]); um.RunCount++; um.Been -= winBeen * 3; um.Exp += 0; userCache.Update(um); } //给客户端发消息 谁赢了以及赢的豆子,身份? OverDto dto = new OverDto(); dto.WinIdentity = winIdentity; dto.WinUIdList = winUIds; dto.BeenCount = winBeen; Brocast(room, OpCode.FIGHT, FightCode.OVER_BRO, dto); //在缓存层销毁房间数据 fightCache.Destroy(room); }