示例#1
0
        public bool MoveToTarget(Vector3 vTarget, object moveParam = null, bool bSysncPath = true, bool bSync = true)
        {
            IMapSystem mapSys = m_ClientGlobal.GetMapSystem();

            if (mapSys == null)
            {
                return(false);
            }

            if (m_Host == null)
            {
                return(false);
            }

            // 需要添加一个寻路的过程
            List <Vector2> path   = null;
            Vector3        curPos = m_Host.GetPos();

            if (!mapSys.FindPath(new Vector2(curPos.x, curPos.z), new Vector2(vTarget.x, vTarget.z), out path))
            {
                //string msg = string.Format("寻路失败: 地图{0} src({1},{2})->desc({3},{4})", mapSys.GetMapID(), curPos.x, curPos.z, vTarget.x, vTarget.z);
                Engine.Utility.Log.Error("寻路失败: 地图{0} src({1},{2})->desc({3},{4})", mapSys.GetMapID(), curPos.x, curPos.z, vTarget.x, vTarget.z);
                if (Application.isEditor)
                {
                    //ControllerSystem.m_ClientGlobal.netService.SendToMe(new Pmd.stMessageBoxChatUserPmd_S() { szInfo = msg });
                }

                return(false);
            }

            // 移动
            Move move = new Move();

            move.m_speed   = m_Host.GetProp((int)WorldObjProp.MoveSpeed) * EntityConst.MOVE_SPEED_RATE; // 速度为测试速度
            move.m_target  = vTarget;
            move.strRunAct = Client.EntityAction.Run;
            movePathList.Clear();
            move.path  = movePathList;
            move.param = moveParam;

            move.path.Add(new Vector3(curPos.x, 0, curPos.z)); // 把起点也放在路径里面
            for (int i = 0; i < path.Count; ++i)
            {
                move.path.Add(new Vector3(path[i].x, 0, path[i].y));
                Engine.Utility.Log.Trace("Move[{0}: {1},{2}]", i, path[i].x, path[i].y);
            }
            m_Host.SendMessage(EntityMessage.EntityCommand_MovePath, (object)move);


            // 把当前位置也发给服务器

            if (ControllerSystem.m_ClientGlobal.IsMainPlayer(m_Host))
            {
                // 同步移动
                //GameCmd.stUserMoveUpPosListMoveUserCmd_C movePath = new GameCmd.stUserMoveUpPosListMoveUserCmd_C();
                //movePath.mapid = mapSys.GetMapID();
                //for (int i = path.Count - 1; i >= 0; --i)
                //{
                //    GameCmd.Pos pp = new GameCmd.Pos();
                //    if (i != path.Count - 1)
                //    {
                //        pp.x = (uint)path[i].x;
                //        pp.y = (uint)-path[i].y;
                //    }
                //    else
                //    {
                //        pp.x = (uint)(path[i].x * 100);
                //        pp.y = (uint)(-path[i].y * 100);
                //    }

                //    //Engine.Utility.Log.Trace("Move[{0}: {1},{2}]", i, pp.x, pp.y);
                //    movePath.poslist.Add(pp);
                //}
                GameCmd.stUserMoveMoveUserCmd_C movePath = new GameCmd.stUserMoveMoveUserCmd_C();
                movePath.client_time = (uint)m_Host.SendMessage(EntityMessage.EntityCommand_ServerTime, null);
                if (bSysncPath)
                {
                    // 起点也发送给服务器
                    path.Insert(0, new Vector2(curPos.x, curPos.z));
                    //GameCmd.stUserMoveMoveUserCmd_C movePath = new GameCmd.stUserMoveMoveUserCmd_C();
                    //movePath.client_time = m_ClientGlobal.GetEntitySystem().serverTime;
                    Engine.Utility.Log.LogGroup("XXF", "Move {0}", movePath.client_time);
                    for (int i = 0; i < path.Count; ++i)
                    {
                        GameCmd.Pos pp = new GameCmd.Pos();
                        //if (i != path.Count - 1)
                        //{
                        //    pp.x = (uint)path[i].x;
                        //    pp.y = (uint)-path[i].y;
                        //}
                        //else
                        {
                            pp.x = (uint)(path[i].x * 100);
                            pp.y = (uint)(-path[i].y * 100);
                        }

                        //Engine.Utility.Log.Trace("Move[{0}: {1},{2}]", i, pp.x, pp.y);
                        movePath.poslist.Add(pp);
                    }
                }
                else // 只发送起点
                {
                    //movePath.client_time = m_ClientGlobal.GetEntitySystem().serverTime;
                    Engine.Utility.Log.LogGroup("XXF", "Move {0}", movePath.client_time);
                    GameCmd.Pos pp = new GameCmd.Pos();
                    {
                        pp.x = (uint)(curPos.x * 100);
                        pp.y = (uint)(-curPos.z * 100);
                    }

                    movePath.poslist.Add(pp);
                }
                // 同步移动消息
                m_ClientGlobal.netService.Send(movePath);
            }
            return(true);
        }
示例#2
0
        private void OnEvent(int nEventID, object param)
        {
            // 地表没有创建成功的时候,就已经收到了角色和NPC的创建 这里重新设置位置和地表做碰撞
            if (nEventID == (int)GameEventID.SYSTEM_LOADSCENECOMPELETE)
            {
                //List<IPlayer> lstPlayer;
                FindAllEntity <IPlayer>(ref lstPlayer);
                for (int i = 0; i < lstPlayer.Count; ++i)
                {
                    Vector3 pos = lstPlayer[i].GetPos();
                    lstPlayer[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                }
                lstPlayer.Clear();

                //List<INPC> lstNPC;
                FindAllEntity <INPC>(ref lstNPC);
                for (int i = 0; i < lstNPC.Count; ++i)
                {
                    Vector3 pos = lstNPC[i].GetPos();
                    lstNPC[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                }
                lstNPC.Clear();

                //List<IBox> lstBox;
                FindAllEntity <IBox>(ref lstBox);
                for (int i = 0; i < lstBox.Count; ++i)
                {
                    Vector3 pos = lstBox[i].GetPos();
                    pos.y += 0.2f;
                    lstBox[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                }
                lstBox.Clear();

                //List<IRobot> lstRobot;
                FindAllEntity <IRobot>(ref lstRobot);
                for (int i = 0; i < lstRobot.Count; ++i)
                {
                    Vector3 pos = lstRobot[i].GetPos();
                    lstRobot[i].SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                }
                lstRobot.Clear();
                // 请求同步移动时间
                ReqMoveServerTime();
            }
            else if (nEventID == (int)GameEventID.RECONNECT_SUCESS) // 重新连接成功
            {
                stReconnectSucess st = (stReconnectSucess)param;
                if (st.isLogin)
                {
                    Clear(false); // 不清理除主角
                    // 请求同步移动时间
                    ReqMoveServerTime();
                }
                else
                {//强制同步
                    GameCmd.stUserMoveMoveUserCmd_C cmd = new GameCmd.stUserMoveMoveUserCmd_C();
                    cmd.client_time = 0;
                    List <GameCmd.Pos> list = new List <GameCmd.Pos>();
                    GameCmd.Pos        pp   = new GameCmd.Pos();
                    pp.x = 0;
                    pp.y = 0;
                    list.Add(pp);
                    cmd.poslist.AddRange(list);
                    m_ClientGlobal.netService.Send(cmd);
                }
            }
            else if (nEventID == (int)GameEventID.NETWORK_CONNECTE_CLOSE)// 网络断开
            {
                if (m_ClientGlobal.MainPlayer != null)
                {
                    m_ClientGlobal.MainPlayer.SendMessage(EntityMessage.EntityCommand_RemoveLinkAllEffect);
                }
            }
            else if (nEventID == (int)GameEventID.ENTITYSYSTEM_ENTITYDEAD) // 实体死亡
            {
                stEntityDead ed = (stEntityDead)param;
                if (m_ClientGlobal.IsMainPlayer(ed.uid))
                {
                    Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem();
                    if (rs != null)
                    {
                        rs.EnableGray(true);
                    }
                }
                IEntity en = FindEntity(ed.uid);
                if (en != null)
                {
                    AddEffectOnEntity(en, false);
                }
            }
            else if (nEventID == (int)GameEventID.ENTITYSYSTEM_RELIVE)
            {
                stEntityRelive ed = (stEntityRelive)param;
                if (m_ClientGlobal.IsMainPlayer(ed.uid))
                {
                    Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem();
                    if (rs != null)
                    {
                        rs.EnableGray(false);
                    }
                }

                IEntity en = FindEntity(ed.uid);
                if (en != null)
                {
                    AddEffectOnEntity(en, true);
                }
            }
            else if (nEventID == (int)GameEventID.PLAYER_LOGIN_SUCCESS)
            {
                Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem();
                if (rs != null)
                {
                    rs.EnableGray(false);
                }

                // 请求同步移动时间
                ReqMoveServerTime();
            }
            else if (nEventID == (int)GameEventID.ENTITYSYSTEM_LEAVEMAP) // 离开地图
            {
                // 清理地图上所有对象
                Clear(false);

                // 切地图时让主角停止移动
                IPlayer mainPlayer = EntitySystem.m_ClientGlobal.MainPlayer;
                if (mainPlayer != null)
                {
                    bool ismoving = (bool)mainPlayer.SendMessage(Client.EntityMessage.EntityCommand_IsMove, null);
                    if (ismoving)
                    {
                        mainPlayer.SendMessage(Client.EntityMessage.EntityCommand_StopMove, mainPlayer.GetPos());
                    }
                }
            }
            else if (nEventID == (int)GameEventID.ENTITYSYSTEM_CHANGEAREA) // 区域变化 动作处理
            {
                stEntityChangeArea changeArea = (stEntityChangeArea)param;
                IEntity            en         = FindEntity(changeArea.uid);
                if (en != null && en.GetEntityType() == EntityType.EntityType_Player)
                {
                    string strCurAni   = (string)en.SendMessage(EntityMessage.EntityCommand_GetCurAni, null);
                    bool   bChangeArea = false;
                    if (changeArea.eType == MapAreaType.Safe || changeArea.eType == MapAreaType.Fish)
                    {
                        if (strCurAni == EntityAction.Stand_Combat)
                        {
                            strCurAni   = EntityAction.Stand;
                            bChangeArea = true;
                        }

                        if (strCurAni == EntityAction.Run_Combat)
                        {
                            strCurAni   = EntityAction.Run;
                            bChangeArea = true;
                        }
                    }
                    else
                    {
                        if (strCurAni == EntityAction.Stand)
                        {
                            strCurAni   = EntityAction.Stand_Combat;
                            bChangeArea = true;
                        }

                        if (strCurAni == EntityAction.Run)
                        {
                            strCurAni   = EntityAction.Run_Combat;
                            bChangeArea = true;
                        }
                    }

                    if (bChangeArea)
                    {
                        PlayAni anim_param = new PlayAni();
                        anim_param.strAcionName = strCurAni;
                        anim_param.fSpeed       = 1;
                        anim_param.nStartFrame  = 0;
                        anim_param.nLoop        = -1;
                        anim_param.fBlendTime   = 0.1f;
                        en.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param);
                    }
                }
            }
            else if (nEventID == (int)GameEventID.ENTITYSYSTEM_CREATEENTITY)
            {
                stCreateEntity create = (stCreateEntity)param;
                IEntity        en     = FindEntity(create.uid);
                if (en != null)
                {
                    EntityManager.Instance().OnCreateEntity(en);
                }
            }
        }