Esempio n. 1
0
        private void OnNoticeRespond(byte[] data)
        {
            NoticeS2C msg = ProtobufUtils.Deserialize <NoticeS2C>(data);

            if (msg.type == NoticeType.NoticeOperation)
            {
                ShowOrderNotice(DataManager.GetInstance().GetPlayerHeadIcon(), (OrderType)msg.noticeOperation);
            }
        }
        private void HandleNoticeMessageFeedback(byte[] data)
        {
            UILockManager.ResetGroupState(UIEventGroup.Middle);

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

            if (feedback.type == NoticeType.BattleBegin)
            {
                view.currentUIType = FightMatchView.FightMatchUIType.None;
                view.OnExit(true);
            }
        }
        private void SetCurrentBattleResult(NoticeC2S noticeC2S = null)
        {
            NoticeS2C  noticeS2C = new NoticeS2C();
            NoticeType type      = NoticeType.BattleResultBlueWin;

            if (noticeC2S != null)
            {
                type = noticeC2S.type;
            }
            else
            {
                type = NoticeType.BattleResultBlueWin;
            }

            DebugUtils.Log(DebugUtils.Type.SimulateBattleMessage, string.Format("Send {0} feed back succeed ", MsgCode.NoticeMessage));

            // battle end need to stop send updateS2CS
            if (type == NoticeType.BattleResultBlueWin ||
                type == NoticeType.BattleResultRedWin ||
                type == NoticeType.BattleResultDraw)
            {
                DataManager clientData = DataManager.GetInstance();

                NoticeS2C.BattleResult resultData = new NoticeS2C.BattleResult();

                resultData.battleDuration = (int)(battleDurationTimer * 0.001f);

                FillSituantionData(MatchSide.Red, resultData.redBattleSituations);
                FillSituantionData(MatchSide.Blue, resultData.blueBattleSituations);

                resultData.gainGold    = 0;
                resultData.gainExp     = 0;
                resultData.currentExp  = 0;
                resultData.upLevelExp  = 0;
                resultData.playerLevel = 0;

                noticeS2C.battleResult = resultData;
                status = SimulateBattleStatus.End;
                DebugUtils.Log(DebugUtils.Type.SimulateBattleMessage, string.Format("Send battle result feed back succeed: {0}", type));
            }

            noticeS2C.type = type;
            byte[] dataS2C = ProtobufUtils.Serialize(noticeS2C);
            simMessageHandlers[MsgCode.NoticeMessage](dataS2C);
        }
Esempio n. 4
0
        private void OnNoticeRespond(byte[] data)
        {
            NoticeS2C msg = ProtobufUtils.Deserialize <NoticeS2C>(data);

            if (msg.type == NoticeType.BattleLoading)
            {
                int length = msg.loadingRatingInfos == null ? 0 : msg.loadingRatingInfos.Count;
                for (int i = 0; i < length; i++)
                {
                    UpdataProgressByID(msg.loadingRatingInfos[i].playerId, msg.loadingRatingInfos[i].playerLoadingRate);
                }
            }
            if (msg.type == NoticeType.BattleBegin)
            {
                DebugUtils.Assert(loadStep == LoadStep.Done, "Server notices the battle begins but the load step is " + loadStep);
                Invoke("OnEnterSence", 2);
            }
        }
Esempio n. 5
0
        private void BroadCastFeedBack(long frame)
        {
            byte[] dataS2C = null;

            UpdateS2C updateS2C = new UpdateS2C();

            updateS2C.battleId  = 0;
            updateS2C.timestamp = frame;

            if (status == LocalBattleStatus.Start)
            {
                NoticeS2C noticeS2C = new NoticeS2C();
                noticeS2C.type = NoticeType.BattleBegin;
                dataS2C        = ProtobufUtils.Serialize(noticeS2C);

                localMessageHandlers[MsgCode.NoticeMessage](dataS2C);
                status = LocalBattleStatus.Normaly;
            }

            for (int i = messageList.Count - 1; i >= 0; i--)
            {
                if (messageList[i].msgCode == MsgCode.UpdateMessage)
                {
                    UpdateC2S updateC2S = ProtobufUtils.Deserialize <UpdateC2S>(messageList[i].data);
                    updateS2C.ops.Add(updateC2S.operation);
                }
                else if (messageList[i].msgCode == MsgCode.NoticeMessage)
                {
                    NoticeC2S noticeC2S = ProtobufUtils.Deserialize <NoticeC2S>(messageList[i].data);

                    NoticeS2C noticeS2C = new NoticeS2C();
                    noticeS2C.type = noticeC2S.type;
                    dataS2C        = ProtobufUtils.Serialize(noticeS2C);

                    DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Send {0} feed back succeed ", messageList[i].msgCode));
                    localMessageHandlers[MsgCode.NoticeMessage](dataS2C);

                    // battle end need to stop send updateS2CS
                    if (noticeC2S.type == NoticeType.BattleResultBlueWin ||
                        noticeC2S.type == NoticeType.BattleResultRedWin ||
                        noticeC2S.type == NoticeType.BattleResultDraw)
                    {
                        status = LocalBattleStatus.End;
                    }
                }
                else if (messageList[i].msgCode == MsgCode.SyncMessage)
                {
                    SyncC2S syncC2S = ProtobufUtils.Deserialize <SyncC2S>(messageList[i].data);

                    Sync s = new Sync();
                    s.syncState        = syncC2S.syncState;
                    s.unitId           = syncC2S.uintId;
                    s.continuedWalkNum = syncC2S.continuedWalkNum;
                    s.timestamp        = frame;
                    foreach (Position item in syncC2S.positions)
                    {
                        s.positions.Add(item);
                    }

                    Operation operation = new Operation();
                    operation.sync   = s;
                    operation.opType = OperationType.SyncPath;

                    updateS2C.ops.Add(operation);
                }
                else if (messageList[i].msgCode == MsgCode.QuitBattleMessage)
                {
                    QuitBattleC2S quitBattleC2S = ProtobufUtils.Deserialize <QuitBattleC2S>(messageList[i].data);
                    QuitBattleS2C quitBattleS2C = new QuitBattleS2C();
                    quitBattleS2C.serverIp   = "127.0.0.1";
                    quitBattleS2C.serverPort = 0;
                    quitBattleS2C.serverType = ServerType.GameServer;
                    dataS2C = ProtobufUtils.Serialize(quitBattleS2C);

                    DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Send {0} feed back succeed ", messageList[i].msgCode));
                    localMessageHandlers[MsgCode.QuitBattleMessage](dataS2C);
                    status = LocalBattleStatus.End;

                    return;
                }
                else if (messageList[i].msgCode == MsgCode.UploadSituationMessage)
                {
                    UploadSituationC2S uploadSituationC2S = ProtobufUtils.Deserialize <UploadSituationC2S>(messageList[i].data);

                    UploadSituationS2C uploadSituationS2C = new UploadSituationS2C();
                    uploadSituationS2C.type = uploadSituationC2S.type;
                    dataS2C = ProtobufUtils.Serialize(uploadSituationS2C);

                    DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Send {0} feed back succeed ", messageList[i].msgCode));

                    Action <byte[]> callback = null;
                    if (localMessageHandlers.TryGetValue(MsgCode.UploadSituationMessage, out callback))
                    {
                        callback.Invoke(dataS2C);
                    }
                }
                else
                {
                    DebugUtils.LogError(DebugUtils.Type.LocalBattleMessage, string.Format("Can't handle this local message now message code = {0} ", messageList[i].msgCode));
                }

                messageList.RemoveAt(i);
            }

            dataS2C = ProtobufUtils.Serialize(updateS2C);

            for (int i = 0; i < updateS2C.ops.Count; i++)
            {
                DebugUtils.Log(DebugUtils.Type.LocalBattleMessage, string.Format("Frame: Send feed back operation {0}", updateS2C.ops[i].opType));
            }

            localMessageHandlers[MsgCode.UpdateMessage](dataS2C);
        }