예제 #1
0
        /// <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);
                }
            });
        }
예제 #2
0
        /// <summary>
        /// 游戏结束
        /// </summary>
        /// <param name="room"></param>
        /// <param name="userId"></param>
        private void GameOver(FightRoom room, int userId)
        {
            var winIdentity = room.GetPlayerIdentity(userId);
            var winUserIds  = room.GetSameIdentityUserIds(winIdentity);
            var beens       = room.multiple * 1000;

            //给胜利的玩家结算
            for (int i = 0; i < winUserIds.Count; i++)
            {
                var userModel = user.GetModelById(winUserIds[i]);
                userModel.winCount++;
                userModel.beens += winIdentity == Identity.Landlord ? beens : beens / 2;
                userModel.exp   += 100;
                user.Update(userModel);
            }
            var loseUserIds = room.GetDifferentIdentityUserIds(winIdentity);

            //给失败的玩家结算
            for (int i = 0; i < loseUserIds.Count; i++)
            {
                var userModel = user.GetModelById(loseUserIds[i]);
                userModel.loseCount++;
                userModel.beens -= winIdentity == Identity.Landlord ? beens / 2 : beens;
                userModel.exp   += 50;
                user.Update(userModel);
            }
            //给逃跑玩家结算  离开的时候已经结算了
            //for (int i = 0; i < room.leavePlayerIdList.Count; i++)
            //{
            //    var userModel = user.GetModelById(room.leavePlayerIdList[i]);
            //    userModel.runCount++;
            //    userModel.loseCount++;
            //    userModel.beens -= beens * 3;//逃跑的人减3倍
            //    user.Update(userModel);
            //}
            //给客户端发消息  游戏结束了
            var dto = new OverDto(winIdentity, winUserIds, beens);

            Brocast(room, OpCode.FIGHT, FightCode.OVER_BRO, dto);

            //游戏结束
            fight.Destroy(room);
        }
예제 #3
0
        /// <summary>
        /// 用户离开
        /// </summary>
        /// <param name="client"></param>
        private void Leave(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                () =>
            {
                //玩家在线
                if (user.IsOnLine(client) == false)
                {
                    return;
                }

                int userId = user.GetIdByClient(client);
                if (fight.IsFightIng(userId) == false)
                {
                    return;
                }
                ///TODO  玩家离开导致报错
                FightRoom room = fight.GetRoomByUid(userId);

                room.LeaveUidList.Add(userId);
                Brocast(room, OpCode.FIGHT, FightCode.LEAVE_BRO, userId);

                //全跑了
                if (room.LeaveUidList.Count == 3)
                {
                    for (int i = 0; i < room.LeaveUidList.Count; i++)
                    {
                        UserModel model = user.GetModelByUserId(room.LeaveUidList[i]);
                        model.runCount++;
                        model.been -= (room.Mutiple * 1000) * 3;
                        model.exp  += 0;
                        user.Update(model);
                    }
                    fight.Destroy(room);
                }
            }
                );
        }
예제 #4
0
 /// <summary>
 /// 用户离开
 /// </summary>
 /// <param name="client"></param>
 private void leave(ClientPeer client)
 {
     SingleExecute.Instance.Execute(
         () =>
     {
         if (userCache.IsOnline(client) == false)
         {
             return;
         }
         int userId = userCache.GetId(client);
         if (fightCache.IsFighting(userId) == false)
         {
             return;
         }
         FightRoom room = fightCache.GetRoomByUId(userId);
         //就算中途退出的人
         room.LeaveUIdList.Add(userId);
         //给逃跑玩家添加逃跑场次
         for (int i = 0; i < room.LeaveUIdList.Count; i++)
         {
             UserModel um = userCache.GetModelById(room.LeaveUIdList[i]);
             um.RunCount++;
             foreach (var player in room.PlayerList)
             {
                 if (player.UserId == room.LeaveUIdList[i])
                 {
                     um.Been -= 500;
                 }
             }
             um.Exp += 0;
             userCache.Update(um);
         }
         brocast(room, OpCode.FIGHT, FightCode.LEAVE_BRO, null);
         fightCache.Destroy(room);
     }
         );
 }
예제 #5
0
 /// <summary>
 /// 用户离开
 /// </summary>
 /// <param name="client"></param>
 private void Leave(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (UserCache.IsOnline(client) == false)
         {
             socketMsg.State = null;
             Console.WriteLine("当前用户不在线,不能从房间中剔除!");
             return;
         }
         int userId = UserCache.GetClientUserId(client);
         if (FightCache.IsFighting(userId) == false)
         {
             return;
         }
         FightRoom room = FightCache.GetRoomByUId(userId);
         //中途退出房间的玩家
         room.LeaveUIdList.Add(userId);
         //
         socketMsg.SubCode = FightCode.Leave_Bro;
         socketMsg.value   = userId;
         BroCast(room, socketMsg);
         //当前房间玩家是否都退出
         if (room.LeaveUIdList.Count == 3)
         {
             for (int i = 0; i < room.LeaveUIdList.Count; i++)
             {
                 UserCharacterInfo user = UserCache.GetUserInfo(room.LeaveUIdList[i]);
                 user.RunCount++;
                 user.Been -= (room.Multiple * 1000) * 3;
                 user.Exp  += 0;
                 UserCache.Update(user);
             }
             FightCache.Destroy(room);
         }
     });
 }
예제 #6
0
        private void gameOver(int userId, FightRoom room)
        {
            int        winIdentity   = room.GetPlayerIdentity(userId);
            int        winBean       = room.Multiple * 1000;
            List <int> winUserIdList = room.GetSameIdentityUserId(winIdentity);

            //win player pluas win count
            for (int i = 0; i < winUserIdList.Count; i++)
            {
                UserModel um = userCache.GetModelByAccountId(winUserIdList[i]);
                um.WinCount++;
                um.Been = winBean;
                um.Exp  = um.LV * 100;
                int maxExp = um.LV * 100;
                while (maxExp <= um.Exp)
                {
                    um.LV++;
                    um.Exp -= maxExp;
                }
                userCache.Update(um);
            }
            //add lose count to loser
            List <int> loseUIds = room.GetDifferentIdentityUserId(winIdentity);

            for (int i = 0; i < loseUIds.Count; i++)
            {
                UserModel um = userCache.GetModelById(loseUIds[i]);
                um.LoseCount++;
                um.Been -= winBean;
                um.Exp  += 10;
                int maxExp = um.LV * 100;
                while (maxExp <= um.Exp)
                {
                    um.LV++;
                    um.Exp -= maxExp;
                }
                userCache.Update(um);
            }
            OverDto dto = new OverDto();

            dto.WinIdentity   = winIdentity;
            dto.WinUserIdList = winUserIdList;
            dto.BeanCount     = winBean;
            Broadcast(room, OpCode.FIGHT, FightCode.Over_BROADCAST, dto);

            fightCache.Destroy(room);
        }