예제 #1
0
        public override void EnterState()
        {
            base.EnterState();
            cmd = aiCharacter.lastCmd;
            aiCharacter.blackboard[AIParam.SkillCmd] = new AIEvent()
            {
                cmd = cmd.proto
            };

            var target       = cmd.skillAction.Target;
            var targetPlayer = ObjectManager.objectManager.GetPlayer(target);

            activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill();

            skillStateMachine     = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, targetPlayer);
            skillStateMachine.cmd = cmd.proto;

            var time    = Util.FrameToFloat(aiCharacter.lastCmd.skillAction.RunFrame);
            var dir     = cmd.skillAction.Dir;
            var physics = aiCharacter.GetAttr().GetComponent <IPhysicCom>();

            physics.TurnToDir(dir);
            holdTime = time;

            var npcConfig = aiCharacter.attribute.npcConfig;
            var actConfig = npcConfig.GetActionBySkillId(cmd.proto.SkillAction.SkillId);

            if (actConfig == null)
            {
                Debug.LogError("NpcSkill:" + MobaUtil.PrintObj(npcConfig) + ":" + cmd.proto);
            }
            var aniName = actConfig.aniName;

            aiCharacter.PlayAniInTime(aniName, time);
        }
예제 #2
0
        void SendMoveCmd()
        {
            var curPos = NetworkUtil.ConvertPos(transform.position);
            var dir    = (int)transform.localRotation.eulerAngles.y;
            var meAttr = gameObject.GetComponent <NpcAttribute>();

            if (curInfo.X != curPos [0] || curInfo.Y != curPos [1] || curInfo.Z != curPos [2] || curInfo.Dir != dir)
            {
                var mvTarget = new Vector3(curInfo.X / 100.0f, curInfo.Y / 100.0f + 0.2f, curInfo.Z / 100.0f);
                var cmd      = new ObjectCommand();
                cmd.targetPos = mvTarget;
                cmd.dir       = curInfo.Dir;
                cmd.commandID = ObjectCommand.ENUM_OBJECT_COMMAND.OC_MOVE;
                GetComponent <LogicCommand>().PushCommand(cmd);
            }

            if (curInfo.HasJumpForwardSpeed)
            {
                var intJumpSpeed = (int)(meAttr.JumpForwardSpeed * 100);
                if (intJumpSpeed != curInfo.JumpForwardSpeed)
                {
                    meAttr.JumpForwardSpeed = curInfo.JumpForwardSpeed / 100.0f;
                }
            }
        }
예제 #3
0
        /*
         * 执行当前的移动命令
         *  若上一个命令是移动命令则替换
         *  若上一个命令是技能命令则等待
         */
        IEnumerator CommandHandle()
        {
            while (true)
            {
                if (commandList.Count > 0)
                {
                    var peekCmd = commandList [0];
                    if (peekCmd.commandID == ObjectCommand.ENUM_OBJECT_COMMAND.OC_MOVE)
                    {
                        if (currentLogicCommand != null && currentLogicCommand.commandID == ObjectCommand.ENUM_OBJECT_COMMAND.OC_MOVE)
                        {
                            currentLogicCommand = peekCmd;
                            commandList.RemoveAt(0);
                        }
                    }

                    if (currentLogicCommand == null)
                    {
                        var cmd = commandList [0];
                        commandList.RemoveAt(0);

                        int logicCommandCount = commandList.Count;
                        logicSpeed = logicCommandCount * 0.5f + 1.0f;
                        DoLogicCommand(cmd);
                    }
                }
                yield return(null);
            }
        }
예제 #4
0
        public void NetworkAttack(SkillAction sk)
        {
            var cmd = new ObjectCommand(ObjectCommand.ENUM_OBJECT_COMMAND.OC_USE_SKILL);

            cmd.skillId    = sk.SkillId;
            cmd.skillLevel = sk.SkillLevel;
            Log.GUI("Other Player Attack LogicCommand");
            gameObject.GetComponent <LogicCommand>().PushCommand(cmd);
        }
예제 #5
0
        //所有命令执行函数需要注意命令执行结束的时候 设定当前命令为null
        void EnterUseSkill(ObjectCommand cmd)
        {
            //判断是否可以使用技能
            var msg = new MyAnimationEvent.Message(MyAnimationEvent.MsgType.DoSkill);

            msg.skillData = Util.GetSkillData(cmd.skillId, cmd.skillLevel);
            GetComponent <MyAnimationEvent>().InsertMsg(msg);
            currentLogicCommand = null;
        }
예제 #6
0
        public override void EnterState()
        {
            base.EnterState();
            cmd         = aiCharacter.lastCmd;
            activeSkill = GetAttr().GetComponent <SkillInfoComponent>().GetActiveSkill();
            var target       = cmd.skillAction.Target;
            var targetPlayer = ObjectManager.objectManager.GetPlayer(target);

            skillStateMachine = SkillLogic.CreateSkillStateMachine(GetAttr().gameObject, activeSkill.skillData, GetAttr().transform.position, targetPlayer);
            var time = Util.FrameToFloat(aiCharacter.lastCmd.skillAction.RunFrame);
            var dir  = cmd.skillAction.Dir;

            holdTime = time;
        }
예제 #7
0
 public void OnCommand(ObjectCommand cmd)
 {
     lastCmd = cmd;
     if (cmd.commandID == ObjectCommand.ENUM_OBJECT_COMMAND.OC_USE_SKILL)
     {
         var skillData = Util.GetSkillData(cmd.skillId, cmd.skillLevel);
         var skillPart = GetSkill();
         skillPart.SetActiveSkill(skillData);
         ChangeState(AIStateEnum.CAST_SKILL);
     }
     else if (cmd.commandID == ObjectCommand.ENUM_OBJECT_COMMAND.OC_MOVE)
     {
         ChangeState(AIStateEnum.MOVE);
     }
 }
예제 #8
0
        public void PushCommand(ObjectCommand cmd)
        {
            Log.Important("Push Command What " + cmd.commandID + " target " + cmd.targetPos + " dir " + cmd.dir);

            /*
             * if (commandList.Count == 0 && state == State.Idle)
             * {
             *  DoLogicCommand(cmd);
             * }
             * else
             * {
             *  commandList.Add(cmd);
             * }
             */
            commandList.Add(cmd);
        }
예제 #9
0
        /// <summary>
        /// 直线移动到目标位置
        /// </summary>
        /// <param name="pos"></param>
        /// <param name=""></param>
        public void MoveTo(ObjectCommand cmd)
        {
            logicFrameId++;
            runTime   = Util.FrameToFloat(cmd.runFrame);
            passTime  = 0.0f;
            curPos    = transform.position;
            targetPos = cmd.targetPos;
            var deltaPos = targetPos - curPos;

            deltaPos.y = 0;
            var dx      = deltaPos.x;
            var dz      = deltaPos.z;
            var moveDir = new Vector2(dx, dz);

            moveDir.Normalize();
            directionTo = new Vector3(moveDir.x, 0, moveDir.y);
            var hval = Vector2.Dot(moveDir, cr);
            var vval = Vector2.Dot(moveDir, cf);

            vcontroller.inputVector.x = hval;
            vcontroller.inputVector.y = vval;
            state = State.InMove;
        }
예제 #10
0
        bool DoLogicCommand(ObjectCommand cmd)
        {
            Log.AI("DoLogicCommad " + cmd.commandID);
            currentLogicCommand = cmd;

            bool ret = false;

            switch (cmd.commandID)
            {
            case ObjectCommand.ENUM_OBJECT_COMMAND.OC_MOVE:
                StartCoroutine(Move());
                break;

            case ObjectCommand.ENUM_OBJECT_COMMAND.OC_USE_SKILL:
                EnterUseSkill(cmd);
                break;

            default:
                Debug.LogError("LogicCommand:: UnImplement Command " + cmd.commandID.ToString());
                break;
            }
            return(ret);
        }
예제 #11
0
        /// <summary>
        /// 只确保在某一帧执行某个命令
        /// 不保证命令状态本身的完整性
        /// linear 插值
        /// step
        /// pulse
        /// </summary>
        /// <param name="cmd"></param>
        void DoLogicCommand(ObjectCommand cmd)
        {
            Log.AI("DoLogicCommad " + cmd.commandID);
            state      = State.InCommand;
            currentCmd = cmd;
            switch (cmd.commandID)
            {
            case ObjectCommand.ENUM_OBJECT_COMMAND.OC_MOVE:
                //简单直线移动
                RunMoveCmd(cmd as MoveCMD);
                break;

            case ObjectCommand.ENUM_OBJECT_COMMAND.OC_USE_SKILL:
                EnterUseSkill(cmd as SkillCMD);
                break;

            default:
                state = State.Idle;
                Debug.LogError("LogicCommand:: UnImplement Command " + cmd.commandID.ToString());
                break;
            }
            //waitTime = currentCmd.runFrame * 1.0f / Util.FramePerSecond;
            waitTime = Util.FrameToFloat(currentCmd.runFrame);
        }
예제 #12
0
 /*
  * NetWork Command Input
  */
 public void PushCommand(ObjectCommand cmd)
 {
     Log.Important("Push Command What " + cmd.commandID + " target " + cmd.targetPos + " dir " + cmd.dir);
     commandList.Add(cmd);
 }
예제 #13
0
        /*
         * 监督执行移动命令当有新的移动命令注入的时候当前的移动命令则失效
         * 异常拯救函数
         */
        IEnumerator Move()
        {
            var samplePos    = transform.position; //new List<Vector3>(){transform.position};
            var lastSameTime = 0f;

            while (currentLogicCommand != null)
            {
                Vector3 mypos = transform.position;

                var lastOne = samplePos;
                var diff    = Util.XZSqrMagnitude(lastOne, mypos);
                if (diff < 1)
                {
                    if (lastSameTime == 0)
                    {
                        lastSameTime = Time.time;
                    }
                }
                else
                {
                    lastSameTime = 0;
                    samplePos    = mypos;
                }


                Vector3 tarPos = currentLogicCommand.targetPos;
                float   dx     = tarPos.x - mypos.x;
                float   dz     = tarPos.z - mypos.z;
                var     dy     = tarPos.y - mypos.y;
                if (Mathf.Abs(dy) > 0.5f)
                {
                    transform.position = tarPos;
                }

                Vector2 vdir = new Vector2(dx, dz);
                if (vdir.sqrMagnitude < 0.1f)
                {
                    mvController.vcontroller.inputVector.x = 0;
                    mvController.vcontroller.inputVector.y = 0;
                    break;
                }

                //超过1s卡在某个位置 和目标位置相差超过1距离 使用超能移动 和目标相距3长时间
                if (lastSameTime != 0 && (Time.time - lastSameTime > 1) && vdir.sqrMagnitude >= 2)
                {
                    transform.position = tarPos;
                    break;
                }

                vdir.Normalize();

                Vector2 mRight   = new Vector2(mvController.camRight.x, mvController.camRight.z);
                Vector2 mForward = new Vector2(mvController.camForward.x, mvController.camForward.z);

                float hval = Vector2.Dot(vdir, mRight);
                float vval = Vector2.Dot(vdir, mForward);

                mvController.vcontroller.inputVector.x = hval;
                mvController.vcontroller.inputVector.y = vval;
                yield return(null);
            }

            //简单实现
            if (currentLogicCommand != null)
            {
                transform.localRotation = Quaternion.Euler(new Vector3(0, currentLogicCommand.dir, 0));
            }
            //再次检测Move位置状态,如果不正常则重新开始
            currentLogicCommand = null;
        }