public static void MessageAnalyze(MsgCode protocolCode, byte[] data)
        {
            DebugUtils.Log(DebugUtils.Type.MessageAnalyze, string.Format("send protocolCode {0} total length:{1}", protocolCode, data.Length));

            if (protocolCode == MsgCode.UpdateMessage)
            {
                UpdateC2S u = ProtobufUtils.Deserialize <UpdateC2S>(data);
                DebugUtils.LogWarning(DebugUtils.Type.MessageAnalyze, string.Format("operation: {0} total length:{1}", u.operation.opType, data.Length));
            }
        }
        public override void Fire()
        {
            base.Fire();

            if (playerOwner)
            {
                // check brithPostion is suitable

                PathAgent  agent       = owner.pathAgent;
                FixVector3 destination = owner.position + owner.direction.normalized * 3; // 3 meter front of owner
                FixVector3 hitPosition;
                FixVector3 simpleOnMapPoint = FixVector3.zero;

                // mapping destination on navmesh
                bool sampleResult = agent.SamplePosition(destination, out simpleOnMapPoint);
                if (sampleResult)
                {
                    destination = simpleOnMapPoint;
                }

                bool result = agent.Raycast(destination, out hitPosition);
                if (result)
                {
                    // didn't encountered obstruction
                    destination = hitPosition;
                }

                UpdateC2S message = new UpdateC2S();
                message.timestamp = DataManager.GetInstance().GetFrame();
                Operation op = new Operation();
                op.unitId         = id;
                op.targetId       = owner.id;                              // test
                op.unitMetaId     = metaId;                                // test
                op.opType         = OperationType.SyncSkillTargetPosition; // wrong type
                op.x              = destination.vector3.x;
                op.y              = destination.vector3.y;
                op.z              = destination.vector3.z;
                message.operation = op;
                PostBattleMessage(MsgCode.UpdateMessage, message);

                DebugUtils.LogWarning(DebugUtils.Type.AI_Skill, string.Format("skill {0} {1},send sync position ", id, skillName));
            }

            DebugUtils.LogWarning(DebugUtils.Type.AI_Skill, string.Format("Fire skill {0} {1},waiting sync position ", id, skillName));
        }
Beispiel #3
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);
        }
        private void SprintState(int deltaTime)
        {
            LogicUnit  target   = owner.target;
            FixVector3 position = owner.position;
            PathAgent  agent    = owner.pathAgent;

            if (target != null && target.Alive() && target.id == owner.target.id)
            {
                if (FixVector3.SqrDistance(target.position, owner.targetPosition) > GameConstants.BEGINCHASE_DISTANCE)     // 5f is a testing distance
                {
                    // if target leave the position too far, need to refresh chase path
                    owner.targetPosition = target.position;
                    owner.FindChasePath(owner.target.position);
                    return;
                }

                if (TargetWithInAttackArea())
                {
                    if (target != null && target.Alive() && target.id == owner.target.id)
                    {
                        if (playerOwner)
                        {
                            FixVector3 direction   = (target.position - position).normalized;
                            FixVector3 destination = owner.position + direction * 5f;// Temp distance.

                            FixVector3 hitPosition      = FixVector3.zero;
                            FixVector3 simpleOnMapPoint = FixVector3.zero;

                            // mapping destination on navmesh
                            bool sampleResult = agent.SamplePosition(destination, out simpleOnMapPoint);
                            if (sampleResult)
                            {
                                destination = simpleOnMapPoint;
                            }

                            bool result = agent.Raycast(destination, out hitPosition);
                            if (result)
                            {
                                destination = hitPosition;
                            }

                            DataManager clientData = DataManager.GetInstance();

                            UpdateC2S message = new UpdateC2S();
                            message.timestamp = clientData.GetFrame();
                            Operation op = new Operation();
                            op.playerId       = clientData.GetPlayerId();
                            op.unitId         = id;
                            op.targetId       = owner.id;                              // test
                            op.unitMetaId     = metaId;                                // test
                            op.opType         = OperationType.SyncSkillTargetPosition; // wrong type
                            op.x              = destination.vector3.x;
                            op.y              = destination.vector3.y;
                            op.z              = destination.vector3.z;
                            message.operation = op;
                            PostBattleMessage(MsgCode.UpdateMessage, message);

                            DebugUtils.Log(DebugUtils.Type.AI_Skill, string.Format("YueGuangChongCi sync destination : {0}", destination));
                        }
                    }
                    else
                    {
                        Stop();
                    }
                }
                else
                {
                    if (!owner.CurrentPathAlreadyFinished())
                    {
                        owner.WaypointHandler();
                        FixVector3 d = owner.speed * deltaTime;
                        agent.Move(d);
                    }
                    else
                    {
                        // wait for chase path
                    }
                }
            }
            else
            {
                // Skill will be shut down when target death.
                Stop();
                owner.Idle();
            }
        }