Ejemplo n.º 1
0
        public MyFriendsResponse GetMyFriends(Guid managerId, int pageIndex, int pageSize)
        {
            var managerExtra = ManagerCore.Instance.GetManagerExtra(managerId);
            var manager      = ManagerCore.Instance.GetManager(managerId);
            int maxHelpCount = CacheFactory.VipdicCache.GetEffectValue(manager.VipLevel,
                                                                       EnumVipEffect.TrainHelpFriendCount);
            bool canHelp    = managerExtra.HelpTrainCount < maxHelpCount;
            int  totalCount = 0;
            var  response   = ResponseHelper.CreateSuccess <MyFriendsResponse>();

            response.Data                   = new MyFriendsData();
            response.Data.Friends           = FriendManagerMgr.GetMyFriends(managerId, pageIndex, pageSize, ref totalCount);
            response.Data.TotalCount        = totalCount;
            response.Data.TotalPage         = ShareUtil.CalPageCount(totalCount, pageSize);
            response.Data.DayHelpTrainCount = maxHelpCount - managerExtra.HelpTrainCount;
            DateTime curDate = DateTime.Today;

            foreach (var entity in response.Data.Friends)
            {
                if (canHelp)
                {
                    CalMatchTimes(entity, curDate);
                }
                entity.IsTrain = PlayerTrain.Instance.GetIsHaveTrain(entity.FriendId);
            }
            return(response);
        }
Ejemplo n.º 2
0
        public MatchCreateResponse Fight(Guid managerId, Guid awayId)
        {
            var lastTime = MemcachedFactory.FriendMutexClient.Get <DateTime>(managerId);

            if (lastTime > DateTime.Now)
            {
                return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.FriendMatchWait));
            }

            //好友比赛每天每个好友只能挑战3次, 只有第一次有奖励
            var friend = FriendManagerMgr.GetOne(managerId, awayId);

            if (friend.DayMatchCount >= 3)//每日三次比赛
            {
                return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.FriendMatchOver));
            }

            var matchId = ShareUtil.GenerateComb();
            var code    = MatchCore.CreateMatchFriendAsyn(matchId, managerId, awayId, friend, MatchCallback);

            if (code != MessageCode.Success)
            {
                return(ResponseHelper.Create <MatchCreateResponse>(code));
            }
            MemcachedFactory.FriendMutexClient.Set(managerId, DateTime.Now.AddSeconds(_friendMatchWaitTime));

            return(ResponseHelper.MatchCreateResponse(matchId));
        }
Ejemplo n.º 3
0
        public MyBlacksResponse DeleteBlack(Guid managerId, int recordId, int pageIndex, int pageSize)
        {
            var friend = FriendManagerMgr.GetById(recordId);

            if (friend == null || friend.ManagerId != managerId || friend.Status != 1)
            {
                return(ResponseHelper.InvalidParameter <MyBlacksResponse>());
            }
            var byFriend = FriendManagerMgr.GetOne(friend.FriendId, managerId);

            if (byFriend != null && byFriend.Status == 1)
            {
                friend.Status = 2;
                FriendManagerMgr.Update(friend);
            }
            else
            {
                FriendManagerMgr.Delete(friend.Idx, friend.RowVersion);
                if (byFriend != null && byFriend.Status == 2)
                {
                    FriendManagerMgr.Delete(byFriend.Idx, byFriend.RowVersion);
                }
            }
            return(GetMyBlacks(managerId, pageIndex, pageSize));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取被邀请好友列表
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public FriendsAddInfoResponse GetFriendRequestList(Guid managerId)
        {
            var response = ResponseHelper.Create <FriendsAddInfoResponse>(MessageCode.Success);

            response.Data = new FriendsAddInfo {
                FriendAddList = FriendManagerMgr.GetFriendAddList(managerId)
            };
            return(response);
        }
Ejemplo n.º 5
0
        public MessageCodeResponse AddFriend(Guid managerId, string name, bool hasTask)
        {
            var byManager = ManagerCore.Instance.GetManagerByName(name);

            if (byManager == null)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotExistsName));
            }
            if (managerId == byManager.Idx)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotSelf));
            }
            var manager = ManagerCore.Instance.GetManager(managerId);
            var friend  = FriendManagerMgr.GetOne(managerId, byManager.Idx);

            if (friend != null)
            {
                if (friend.Status == 0)
                {
                    return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendHasExists));
                }
                if (friend.Status == 2)
                {
                    return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendIsByBlack));
                }
            }
            int returnCode = 0;

            FriendManagerMgr.AddFriend(managerId, byManager.Idx, _friendMaxCount, (int)MessageCode.FriendCountOver,
                                       (int)MessageCode.FriendHasExists, ref returnCode);
            if (returnCode == 1) //自己已在对方好友列表
            {
                returnCode = 0;
            }
            else
            {
                InformationHelper.SendAddFriendPop(byManager.Idx, manager.Name);
            }

            if (returnCode == 0)
            {
                var response = ResponseHelper.CreateSuccess <MessageCodeResponse>();
                response.Data = new MessageDataEntity();
                if (hasTask)
                {
                    //response.Data.PopMsg = TaskHandler.Instance.FriendAdd(managerId);
                }
                return(response);
            }
            else
            {
                return(ResponseHelper.Create <MessageCodeResponse>(returnCode));
            }
        }
Ejemplo n.º 6
0
        public MyBlacksResponse GetMyBlacks(Guid managerId, int pageIndex, int pageSize)
        {
            int totalCount = 0;
            var response   = ResponseHelper.CreateSuccess <MyBlacksResponse>();

            response.Data            = new MyBlacksData();
            response.Data.Blaks      = FriendManagerMgr.GetMyBlacks(managerId, pageIndex, pageSize, ref totalCount);
            response.Data.TotalCount = totalCount;
            response.Data.TotalPage  = ShareUtil.CalPageCount(totalCount, pageSize);
            return(response);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 忽略添加好友
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="friendId"></param>
        /// <returns></returns>
        public MessageCodeResponse IgnoreAddFriend(Guid managerId, Guid friendId)
        {
            int returnCode = 0;

            FriendManagerMgr.IgnoreAddFriend(managerId, friendId, ref returnCode);
            if (returnCode == -1)//已经是好友了
            {
                returnCode = 0;
            }
            return(ResponseHelper.Create <MessageCodeResponse>(returnCode));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 是否有好友邀请
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public bool HasFriendRequest(Guid managerId)
        {
            var list = FriendManagerMgr.GetFriendAddList(managerId);

            if (list == null)
            {
                return(false);
            }
            if (list.Count > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 9
0
        MessageCodeResponse AddBlack(Guid managerId, NbManagerEntity byManager)
        {
            if (byManager == null)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotExistsName));
            }
            if (managerId == byManager.Idx)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendNotSelf));
            }
            var friend = FriendManagerMgr.GetOne(managerId, byManager.Idx);

            if (friend != null && friend.Status == 1)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.FriendBlackExists));
            }
            FriendManagerMgr.AddBlack(managerId, byManager.Idx);
            return(ResponseHelper.CreateSuccess <MessageCodeResponse>());
        }
Ejemplo n.º 10
0
        public FriendManagerEntity GetFriendById(int recordId)
        {
            var entity = FriendManagerMgr.GetById(recordId);

            if (entity != null &&
                entity.RecordDate != DateTime.Today)
            {
                entity.DayHelpTrainCount = 0;
                entity.DayIntimacy       = 0;
                entity.DayMatchCount     = 0;

                entity.RecordDate = DateTime.Today;
            }
            if (entity != null && DateTime.Now >= entity.OpenBoxTime.AddHours(24))
            {
                entity.DayOpenBoxCount = 0;
            }
            return(entity);
        }
Ejemplo n.º 11
0
        public MyFriendsResponse DeleteFriend(Guid managerId, int recordId, int pageIndex, int pageSize)
        {
            var friend = FriendManagerMgr.GetById(recordId);

            if (friend == null || friend.ManagerId != managerId || friend.Status != 0)
            {
                return(ResponseHelper.InvalidParameter <MyFriendsResponse>());
            }
            if (FriendManagerMgr.Delete(friend.Idx, friend.RowVersion))
            {
                int returnCode = 0;
                FriendManagerMgr.IgnoreAddFriend(managerId, friend.FriendId, ref returnCode);

                return(GetMyFriends(managerId, pageIndex, pageSize));
            }
            else
            {
                return(ResponseHelper.Create <MyFriendsResponse>(MessageCode.NbUpdateFail));
            }
        }
Ejemplo n.º 12
0
        public MessageCode MatchCallback(BaseMatchData matchData)
        {
            var fmatchData = (FriendMatchData)matchData;

            if (fmatchData == null || fmatchData.ErrorCode != (int)MessageCode.Success)
            {
                return(MessageCode.MatchCreateFail);
            }
            var  friendRecord = fmatchData.FriendRecord;
            bool isFriend     = friendRecord != null;
            var  coin         = 0;
            int  intimacy     = 0;

            if (isFriend)
            {
                var oldIntimacy = friendRecord.Intimacy;
                AddFriendMatchIntimacy(friendRecord);
                intimacy = friendRecord.Intimacy - oldIntimacy;
                if (friendRecord.DayMatchCount == 1)
                {
                    //第一次比赛有奖励
                    if (fmatchData.Home.Score > fmatchData.Away.Score)
                    {
                        coin = 30;
                    }
                    else if (fmatchData.Home.Score == fmatchData.Away.Score)
                    {
                        coin = 20;
                    }
                    else
                    {
                        coin = 10;
                    }
                }
            }
            var match = new FriendMatchEntity();

            match.Idx       = fmatchData.MatchId;
            match.HomeId    = fmatchData.Home.ManagerId;
            match.HomeName  = fmatchData.Home.Name;
            match.HomeScore = fmatchData.Home.Score;
            match.AwayId    = fmatchData.Away.ManagerId;
            match.AwayName  = fmatchData.Away.Name;
            match.AwayScore = fmatchData.Away.Score;
            match.Intimacy  = intimacy;
            match.IsFriend  = isFriend;
            match.RowTime   = DateTime.Now;
            match.Status    = 0;

            MatchCore.SaveMatchStat(match.HomeId, EnumMatchType.Friend, match.HomeScore, match.AwayScore, match.HomeScore);
            var winType = EnumWinType.Win;

            if (match.HomeScore == match.AwayScore)
            {
                winType = EnumWinType.Draw;
            }
            else if (match.HomeScore < match.AwayScore)
            {
                winType = EnumWinType.Lose;
            }

            using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
            {
                transactionManager.BeginTransaction();
                var trans       = transactionManager.TransactionObject;
                var messageCode = MessageCode.NbUpdateFail;
                do
                {
                    if (isFriend)
                    {
                        if (!FriendManagerMgr.Update(friendRecord, trans))
                        {
                            break;
                        }
                    }
                    if (!FriendMatchMgr.Insert(match, trans))
                    {
                        break;
                    }
                    //记录成就相关数据
                    var mess = AchievementTaskCore.Instance.UpdateFriendMatchComb(match.HomeId, winType, trans);
                    if (mess != MessageCode.Success)
                    {
                        break;
                    }

                    if (coin > 0)
                    {
                        //友谊赛金币奖励
                        var manager = ManagerCore.Instance.GetManager(fmatchData.Home.ManagerId);
                        if (manager != null)
                        {
                            mess = ManagerCore.Instance.AddCoin(manager, coin, EnumCoinChargeSourceType.FriendMatch,
                                                                ShareUtil.GenerateComb().ToString(), trans);
                            if (mess != MessageCode.Success)
                            {
                                break;
                            }
                        }
                    }
                    messageCode = MessageCode.Success;
                } while (false);
                if (messageCode == ShareUtil.SuccessCode)
                {
                    transactionManager.Commit();
                }
                else
                {
                    transactionManager.Rollback();
                }
            }
            return(MessageCode.Success);
        }