private void RemoveData(long friendId)
 {
     currentFriendId   = 0;
     currentFriendItem = null;
     matcherReadyDatas.Remove(matcherReadyDatas.Find(p => p.playerId == friendId));
     view.beInvited = false;
     view.OpenMatchUI();
 }
        private void HandleInvationMatchFeedback(byte[] data)
        {
            InvitationMatchS2C feedback = ProtobufUtils.Deserialize <InvitationMatchS2C>(data);

            if (feedback.result)
            {
                switch (feedback.state)
                {
                case InvitationState.FriendInBattle:
                    view.PopFriendInBattle();
                    SendInvitationListC2S();
                    currentFriendItem = null;
                    break;

                case InvitationState.FriendInMatching:
                    view.PopFriendInMatching();
                    SendInvitationListC2S();
                    currentFriendItem = null;
                    break;

                case InvitationState.WaitingProcess:
                    currentFriendItem.SetInvationButtonState(false);
                    isInvite = true;
                    break;

                case InvitationState.AcceptInvitation:
                    break;

                case InvitationState.RefuseInvitation:
                    break;

                case InvitationState.CancelInvitation:
                    matcherReadyDatas.Clear();
                    currentFriendItem = null;
                    view.OnExit(true);
                    break;

                case InvitationState.FriendReady:
                    view.SetFriendReadyState(true);
                    break;

                case InvitationState.FriendCancelReady:
                    view.SetFriendReadyState(false);
                    break;

                case InvitationState.StartMatch:
                    currentFriendId = GetFriendMatcherReadyData().playerId;
                    SendApplyRoomC2S();
                    break;

                case InvitationState.RepeatSendInvitation:
                    break;

                case InvitationState.DestroyInvitation:
                    break;
                }
            }
        }
        public override GameObject InstantiateCell()
        {
            MatchFriendItem item = base.InstantiateCell().AddComponent <MatchFriendItem>();

            if (onCreateItemHandler != null)
            {
                onCreateItemHandler(item);
            }
            return(item.gameObject);
        }
        private void HandleInvationNoticeFeedback(byte[] data)
        {
            InvitationNoticeS2C feedback = ProtobufUtils.Deserialize <InvitationNoticeS2C>(data);

            switch (feedback.state)
            {
            case InvitationState.FriendInBattle:
                break;

            case InvitationState.WaitingProcess:
                MessageDispatcher.PostMessage(Constants.MessageType.OpenFriendInvationAlert, feedback.friendId, feedback.battleType, feedback.friendName, feedback.friendPortrait);
                break;

            case InvitationState.AcceptInvitation:
                view.SetStartMatchBtState(false);
                break;

            case InvitationState.RefuseInvitation:
                view.PopFriendRefuse(feedback.friendName);
                currentFriendItem.SetInvationButtonState(true);
                currentFriendItem = null;
                break;

            case InvitationState.FriendOffline:
            case InvitationState.CancelInvitation:
                RemoveData(feedback.friendId);
                view.SetFriendUI(false);
                SendInvitationListC2S();
                break;

            case InvitationState.FriendReady:
                view.SetStartMatchBtState(true);
                break;

            case InvitationState.FriendCancelReady:
                view.SetStartMatchBtState(false);
                break;

            case InvitationState.StartMatch:
                currentFriendId = feedback.friendId;
                SendApplyRoomC2S();
                view.SetStartMatchState(true);
                break;

            case InvitationState.DestroyInvitation:
                break;
            }
        }
 public void SendInvitationFriend(MatchFriendItem item)
 {
     if (currentFriendItem != null)
     {
         return;
     }
     if (currentBattleType != BattleType.BattleP2vsP2)
     {
         return;
     }
     if (matcherReadyDatas.Count > 1)
     {
         return;
     }
     currentFriendItem = item;
     SendInvitationC2S(item.info.playerId, currentBattleType, InvitationState.SendInvitation);
 }
        public void SendCancelInvitation()
        {
            if (currentFriendItem == null && !view.beInvited)
            {
                currentFriendId = 0;
                view.OnExit(true);
                return;
            }

            long playerId;

            if (view.beInvited)
            {
                playerId = matcherReadyDatas.FindAll(p => p.playerId != DataManager.GetInstance().GetPlayerId())[0].playerId;
            }
            else
            {
                playerId = currentFriendItem.info.playerId;
            }

            SendInvitationC2S(playerId, currentBattleType, InvitationState.CancelInvitation);
            currentFriendItem = null;
            currentFriendId   = 0;
        }
        private void HandleMatchFeedback(byte[] data)
        {
            UILockManager.ResetGroupState(UIEventGroup.Middle);

            MatchS2C feedback = ProtobufUtils.Deserialize <MatchS2C>(data);

            switch (feedback.result)
            {
            case MatchServerMessageType.RoomCreatedSucceed:
                DebugUtils.Log(DebugUtils.Type.Match, "Room Created Succeed~");
                //view.timeLeft_room = feedback.matchTime / 1000;

                view.OpenMatchingUI();
                break;

            case MatchServerMessageType.RoomCreatedFail:
                DebugUtils.Log(DebugUtils.Type.Match, "Match Room Created Fail~");
                break;

            case MatchServerMessageType.RoomFound:
                DebugUtils.Log(DebugUtils.Type.Match, "Room Found~");

                break;

            case MatchServerMessageType.RoomReady:
                DebugUtils.Log(DebugUtils.Type.Match, "Room Ready~");
                view.OpenMatchSucceedUI();
                view.timeLeft_matchSucceed = feedback.matchTime / 1000;
                MatchSucceedUIData(feedback.matchers);
                break;

            case MatchServerMessageType.Cancelled:
            case MatchServerMessageType.MatchingTimeout:
                DebugUtils.Log(DebugUtils.Type.Match, feedback.result.ToString() + "~");

                isTimeOut = false;
                ConnectGameServer(feedback);
                matcherReadyDatas.Remove(matcherReadyDatas.Find(p => p.playerId != DataManager.GetInstance().GetPlayerId()));
                view.SetFriendUI(false);
                view.beInvited    = false;
                currentFriendItem = null;
                currentFriendId   = 0;
                view.OpenMatchUI();
                view.SetStartMatchState(false);
                break;

            case MatchServerMessageType.CancelFailed:
                DebugUtils.Log(DebugUtils.Type.Match, "Match Cancel Failed~");
                break;

            case MatchServerMessageType.MatcherFound:
                DebugUtils.Log(DebugUtils.Type.Match, "Matcher Found~");

                break;

            case MatchServerMessageType.MatcherCancelled:
                DebugUtils.Log(DebugUtils.Type.Match, "Matcher Cancelled~");
                MatcherCancelledUIData(feedback.matchers);
                //view.timeLeft_room = feedback.matchTime / 1000;
                //TODO: if the friend cancelled  ,  need do something

                break;

            case MatchServerMessageType.MatcherReady:
                DebugUtils.Log(DebugUtils.Type.Match, "Matcher Ready~");
                MatchSucceedUIData(feedback.matchers);
                break;

            default:
                DebugUtils.Log(DebugUtils.Type.Match, "Match result is wrong~");
                break;
            }
        }
 private void OnCreateMatchFriendItem(MatchFriendItem item)
 {
     item.inviationEvent = ( MatchFriendItem ite ) => { controller.SendInvitationFriend(ite); };
 }