Exemplo n.º 1
0
        public override BtResult Execute()
        {
            m_curIntervalTime -= FSPParam.clientFrameMsTime;
            if (m_curIntervalTime > 0)
            {
                return(BtResult.Running);
            }

            //// 休闲时,继续巡逻
            if (m_creature.m_stateMgr.GetCurState() == StateID.eFspStopMove)
            {
                Debug.Log("设置移动");
                //Vector2 pPos = m_creature.m_bornPoint;
                Vector2 pPos = m_creature.GetPos().ToVector2();
                Vector2 end  = CMapMgr.m_map.GetRandomPos(pPos.x, pPos.y, 10, m_creature.m_aiType);

                CmdFspAutoMove cmd = new CmdFspAutoMove();
                cmd.m_pos = end.ToVector2d();
                if (m_creature.m_aiType == eAIType.Player)
                {
                    m_creature.SendFspCmd(cmd);
                }
                else
                {
                    m_creature.PushCommand(cmd);
                }
                m_curIntervalTime = 30 * FSPParam.clientFrameMsTime;
            }
            return(BtResult.Running);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 指令对象转消息内容并发送
        /// </summary>
        /// <param name="cmd"></param>
        public void SendFspCmd(IFspCmdType cmd)
        {
            // 如果本地单机测试
            if (Client.Inst().isSingleTest)
            {
                PushCommand(cmd);
                return;
            }

            CmdFspEnum  type = cmd.GetCmdType();
            FspMsgFrame msg  = (FspMsgFrame)NetManager.Inst.GetMessage(eNetMessageID.FspMsgFrame);
            FspVKey     key  = new FspVKey();

            key.vkey     = (int)type;
            key.playerId = (uint)GetUid();
            switch (type)
            {
            case CmdFspEnum.eFspStopMove:
                msg.m_frameData.vkeys.Add(key);
                break;

            case CmdFspEnum.eFspMove:
                CmdFspMove moveCmd = cmd as CmdFspMove;
                key.args    = new int[2];
                key.args[0] = (int)(moveCmd.m_dir.x * 100);
                key.args[1] = (int)(moveCmd.m_dir.y * 100);
                msg.m_frameData.vkeys.Add(key);
                break;

            case CmdFspEnum.eFspAutoMove:
                CmdFspAutoMove amoveCmd = cmd as CmdFspAutoMove;
                key.args    = new int[2];
                key.args[0] = (int)(amoveCmd.m_pos.x * 100);
                key.args[1] = (int)(amoveCmd.m_pos.y * 100);
                Debug.Log("send :" + key.args[0] + "  " + key.args[1]);
                msg.m_frameData.vkeys.Add(key);
                break;

            case CmdFspEnum.eFspSendSkill:
                CmdFspSendSkill skill = cmd as CmdFspSendSkill;
                key.args    = new int[7];
                key.args[0] = (int)skill.m_casterUid;
                key.args[1] = (int)skill.m_skillIndex;
                key.args[2] = (int)skill.m_targetId;

                key.args[3] = (int)(skill.m_dir.x * 100);
                key.args[4] = (int)(skill.m_dir.y * 100);

                key.args[5] = (int)(skill.m_endPos.x * 100);
                key.args[6] = (int)(skill.m_endPos.y * 100);

                msg.m_frameData.vkeys.Add(key);
                break;
            }
            FspNetRunTime.Inst.SendMessage(msg);
        }
Exemplo n.º 3
0
        public override BtResult Execute()
        {
            GetSkillDis();
            if (m_skillDis == 0)
            {
                AIParam.SendSkill(m_creature, m_dataBase);
                return(BtResult.Ended);
            }

            // 1.实时获取当前选择的技能和目标计算 当前的移动位置
            // 2.如果到达,即可结束
            int       targetUid = m_dataBase.GetData <int>((int)eAIParam.INT_TARGET_UID);
            CCreature targetCC  = CCreatureMgr.Get(targetUid);

            if (targetCC != null)
            {
                FixedPoint dis2 = FPCollide.GetDis2(targetCC.GetPos(), m_creature.GetPos());
                if (dis2 < new FixedPoint(m_skillDis * m_skillDis))
                {
                    return(BtResult.Ended);
                }
                else
                {
                    // 一秒执行一次
                    m_curTime += FSPParam.clientFrameMsTime;
                    if (m_curTime >= 30 * FSPParam.clientFrameMsTime)
                    {
                        m_curTime = 0;

                        //Vector2 pPos = targetCC.GetPos();
                        //m_creature.GoTo(pPos);

                        Vector2d dir    = targetCC.GetPos() - m_creature.GetPos();
                        Vector2d target = m_creature.GetPos() + dir.normalized * new FixedPoint(m_skillDis);
                        Vector2d endPos = CMapMgr.m_map.GetRandomPos(target.x.value, target.y.value, 3, m_creature.m_aiType).ToVector2d();
                        //Vector2d pPos = targetCC.GetPos();

                        CmdFspAutoMove cmd = new CmdFspAutoMove();
                        cmd.m_pos = endPos;

                        if (m_creature.m_aiType == eAIType.Player)
                        {
                            m_creature.SendFspCmd(cmd);
                        }
                        else
                        {
                            m_creature.PushCommand(cmd);
                        }
                    }
                    return(BtResult.Running);
                }
            }

            return(BtResult.Ended);
        }
Exemplo n.º 4
0
        public override void Enter(IFspCmdType cmd)
        {
            m_cmdFspAutoMove = cmd as CmdFspAutoMove;

            List <Vector2d> m_movePath = new List <Vector2d>();

            CMapMgr.m_map.GetPath(m_creature, m_creature.GetPos(), m_cmdFspAutoMove.m_pos, ref m_movePath);
            //m_moveEnd = moveEnd;

            FixedPoint divSpeed = 1 / m_creature.GetSpeed();

            StartAutoMove(ref m_movePath, divSpeed);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 消息内容转指令对象
        /// </summary>
        private void HandleServerCmd(FspVKey cmd)
        {
            CmdFspEnum type = (CmdFspEnum)cmd.vkey;
            uint       uid  = cmd.playerId;

            if (uid == 0)
            {
                return;
            }
            CCreature   player   = CCreatureMgr.Get(uid);
            IFspCmdType logicCmd = null;

            switch (type)
            {
            case CmdFspEnum.eFspStopMove:
                //Debug.Log(uid + " 停止移动");
                logicCmd = new CmdFspStopMove();
                break;

            case CmdFspEnum.eFspMove:
                //Debug.Log(uid + " 客户端调用移动命令 " + cmd.args[0] + " " + cmd.args[1]);
                Vector2d v = new Vector2d(cmd.args[0] * 0.01f, cmd.args[1] * 0.01f);
                logicCmd = new CmdFspMove(ref v);
                break;

            case CmdFspEnum.eFspAutoMove:
                Vector2d v1 = new Vector2d(cmd.args[0] * 0.01f, cmd.args[1] * 0.01f);
                logicCmd = new CmdFspAutoMove(ref v1);
                break;

            case CmdFspEnum.eFspSendSkill:
                //Debug.Log(uid + " 客户端调用技能 " + cmd.args[0] + " " + cmd.args[1]);

                CmdFspSendSkill skill = new CmdFspSendSkill();
                skill.m_casterUid  = cmd.args[0];
                skill.m_skillIndex = cmd.args[1];
                skill.m_targetId   = cmd.args[2];
                Vector2d dir    = new Vector2d(cmd.args[3] * 0.01f, cmd.args[4] * 0.01f);
                Vector2d endPos = new Vector2d(cmd.args[5] * 0.01f, cmd.args[6] * 0.01f);
                skill.m_dir    = dir;
                skill.m_endPos = endPos;
                logicCmd       = skill;
                break;
            }
            player.PushCommand(logicCmd);
        }
Exemplo n.º 6
0
        public AutoMoveState(CCreature go)
            : base(go)
        {
            m_stateId = StateID.eFspAutoMove;

            if (m_movePath == null)
            {
                m_movePath = new List <Vector2d>();
            }
            if (m_pathTime == null)
            {
                m_pathTime = new List <FixedPoint>();
            }
            if (m_dirList == null)
            {
                m_dirList = new List <Vector2d>();
            }
            if (m_cmdFspAutoMove == null)
            {
                m_cmdFspAutoMove = new CmdFspAutoMove();
            }
        }