Esempio n. 1
0
        /// <summary>
        /// 发出攻击
        /// </summary>
        /// <param name="hitActionId"></param>
        /// <param name="itwm"></param>
        /// <param name="rotation"></param>
        /// <param name="forward"></param>
        /// <param name="position"></param>
        public void OnAttacking(int hitActionId, Matrix4x4 ltwm, Quaternion rotation, Vector3 forward, Vector3 position)
        {
            SkillAction action = SkillAction.dataMap[hitActionId];

            if (action.removeCollider == 1)
            {
            }
            //动画动作
            int act = action.action;

            if (act > 0)
            {
                if (PlayerActionNames.animatorNames.ContainsKey(act))
                {
                    theOwner.skillActName = PlayerActionNames.animatorNames[act];
                }
                else
                {
                    Debug.LogWarning("找不到动作id");
                    theOwner.skillActName = "";
                }
                theOwner.SetAction(act);
            }
            AttackingFx(action);
            AttackingMove(action);
            AttackBuff(action);

            List <object> args = new List <object>();

            args.Add(ltwm);
            args.Add(rotation);
            args.Add(forward);
            args.Add(position);
            theOwner.delayAttackTimerID = TimerHeap.AddTimer((uint)(action.actionBeginDuration / theOwner.aiRate), 0, DelayAttack, hitActionId, args);
        }
Esempio n. 2
0
        /// <summary>
        /// 释放技能的时候移动
        /// </summary>
        /// <param name="action"></param>
        private void AttackingMove(SkillAction action)
        {
            GameMotor motor = theOwner.motor;

            if (motor == null)
            {
                return;
            }
            float extraSpeed = action.extraSpeed;

            if (extraSpeed != 0)
            {
                motor.SetExtraSpeed(extraSpeed);
                motor.SetMoveDirection(theOwner.Transform.forward);
                //延迟extraSt时间后,设置速度为0
                TimerHeap.AddTimer <GameMotor>((uint)action.extraSt, 0, (m) => { m.SetExtraSpeed(0); }, motor);
            }
            else
            {
                motor.SetExtraSpeed(0);
            }
            //如果该技能是带传送的,直接传送
            if (action.teleportDistance > 0 && extraSpeed <= 0)
            {
                Vector3 dst = Vector3.zero;
                dst = theOwner.Transform.position + theOwner.Transform.forward * action.teleportDistance;
                motor.TeleportTo(dst);
            }
        }
Esempio n. 3
0
        public void OnMessage(MessageBuffer msg)
        {
            int cproto = msg.ReadInt();

            Debug.Log(cproto);
            switch (cproto)
            {
            case cProto.CONNECT:
                //                   SceneManager.instance.InitViewMap();
                int roleId = msg.ReadInt();
                //                    SceneManager.instance.viewMap.CreateMe(roleId);
                SceneManager.instance.viewMap.LogicMap.m_curRoleId = roleId;
                Debug.Log("玩家,id = " + roleId);
                break;

            case cProto.READY:
                break;

            case cProto.SYNC_POS:
                int    cRoleId = msg.ReadInt();
                string pos     = msg.ReadString();
                SceneManager.instance.viewMap.SyncPos(cRoleId, pos);

                Debug.Log(string.Format("玩家 {0} ,pos = {1}", cRoleId, pos));
                break;

            case cProto.SYNC_KEY:
                int servFrameCount = msg.ReadInt();
                if (servFrameCount >= SceneManager.instance.viewMap.LogicMap.m_curFrameCount)
                {
                    string   keyStr  = msg.ReadString();
                    string[] keyData = keyStr.Split(';');
                    for (int i = 0; i < keyData.Length; ++i)
                    {
                        if (keyData[i] == "")
                        {
                            continue;
                        }
                        KeyData data = new KeyData(keyData[i]);
                        SceneManager.instance.viewMap.LogicMap.DoCmd(data);
                    }
                    SceneManager.instance.viewMap.LogicMap.m_curFrameCount += 1;
                }
                break;

            case cProto.START:
                string players = msg.ReadString();
                SceneManager.instance.viewMap.CreateAllPlayer(players);
                Debug.LogError("   start  =========================  ");



                TimerHeap.AddTimer(0, 50, SycMePos);
                TimerHeap.AddTimer(0, 100, SycKey);
                break;
            }
        }
        private void ProcessHit(EntityParent theOwner, int spellId, List <object> args)
        {
            int actionId = (int)args[0];

            UnityEngine.Matrix4x4  ltwm     = (UnityEngine.Matrix4x4)args[1];
            UnityEngine.Quaternion rotation = (UnityEngine.Quaternion)args[2];
            UnityEngine.Vector3    forward  = (UnityEngine.Vector3)args[3];
            UnityEngine.Vector3    position = (UnityEngine.Vector3)args[4];
            if (theOwner is EntityDummy && theOwner.animator != null)
            {
                theOwner.animator.applyRootMotion = true;
            }
            SkillAction action   = SkillAction.dataMap[actionId];
            SkillData   skill    = SkillData.dataMap[spellId];
            int         duration = action.duration;

            if (duration <= 0 && skill.skillAction.Count > 1)
            {
                if (SkillAction.dataMap[skill.skillAction[0]].duration <= 0)
                {
                    //攻击结束,进入idle状态
                    theOwner.AddCallbackInFrames <int, EntityParent>((_actionId, _theOwner) =>
                    {
                    }, actionId, theOwner);
                }
            }
            else if (duration > 0 && action.action > 0)
            {
                TimerHeap.AddTimer <int, EntityParent>((uint)duration, 0, (_actionID, _theOwner) =>
                {
                    GameMotor theMotor = _theOwner.motor;
                    if (_theOwner.Transform)
                    {
                        theMotor.enableStick = true;
                        theMotor.SetExtraSpeed(0);                 //额外速度为0
                        theMotor.SetMoveDirection(Vector3.zero);   //移动方向为(0,0,0)
                    }
                    _theOwner.ChangeMotionState(MotionState.IDLE); //改变状态为idle
                }, actionId, theOwner);
            }
            //移除技能特效
            if (action.duration > 0)
            {
                TimerHeap.AddTimer <int, EntityParent>((uint)action.duration, 0, (_actionID, _theOwner) =>
                {
                    _theOwner.RemoveSfx(_actionID);
                }, actionId, theOwner);
            }
            theOwner.OnAttacking(actionId, ltwm, rotation, forward, position);
        }
        /// <summary>
        /// 普通攻击
        /// </summary>
        public void NormalAttack()
        {
            if (GameWorld.isInTown || (theOnwer as EntityMyself).DeathFlag == 1)
            {
                return;
            }
            //cd在冷却中
            if ((m_skillManager as PlayerSkillManager).IsCommonCooldown())
            {
                preCmds.Add(0);
                return;
            }
            //取得下一个普攻的id
            int nextSkill = (m_skillManager as PlayerSkillManager).GetNormalAttackId();

            //如果是和当前的技能id一样的话,就直接跳过
            if (nextSkill == theOnwer.currSpellID && theOnwer.currSpellID != -1)
            {
                preCmds.Add(0);
                return;
            }
            if ((m_skillManager as PlayerSkillManager).IsSkillCooldown(nextSkill))
            {
                (m_skillManager as PlayerSkillManager).ClearComboSkill();
                preCmds.Add(0);
                return;
            }
            if (!(m_skillManager as PlayerSkillManager).HasDependence(nextSkill))
            {
                ClearPreSkill();
            }
            (m_skillManager as PlayerSkillManager).ResetCoolTime(nextSkill);
            EntityMyself.preSkillTime = Time.realtimeSinceStartup;
            theOnwer.CastSkill(nextSkill);
            TimerHeap.AddTimer((uint)((m_skillManager as PlayerSkillManager).GetCommonCd(nextSkill)), 0, NextCmd);
        }
        public void Process(EntityParent theOwner, params object[] args)
        {
            if (args.Length != 1)
            {
                Debug.LogError("没有攻击技能");
                return;
            }
            int       spellId = (int)args[0];
            SkillData s       = SkillData.dataMap[spellId];

            theOwner.motor.speed       = 0;
            theOwner.motor.targetSpeed = 0;
            int baseTime = 0;

            for (int i = 0; i < s.skillAction.Count; i++)
            {
                SkillAction   action = SkillAction.dataMap[s.skillAction[0]];
                List <object> args1  = new List <object>();
                args1.Add(s.skillAction[0]);
                args1.Add(theOwner.Transform.localToWorldMatrix);
                args1.Add(theOwner.Transform.rotation);
                args1.Add(theOwner.Transform.forward);
                args1.Add(theOwner.Transform.position);
                //播放技能的第一个动作
                if (i == 0)
                {
                    ProcessHit(theOwner, spellId, args1);
                    if (theOwner is EntityMyself)
                    {
                        theOwner.motor.enableStick = action.enableStick > 0;
                    }
                }
                //如果没有后续动作了就跳出循环
                if (i + 1 == s.skillAction.Count)
                {
                    break;
                }
                //记录加到定时器里面的hit动作
                uint          tid   = 0;
                List <object> args2 = new List <object>();
                args2.Add(s.skillAction[i + 1]);
                args2.Add(theOwner.Transform.localToWorldMatrix);
                args2.Add(theOwner.Transform.rotation);
                args2.Add(theOwner.Transform.forward);
                args2.Add(theOwner.Transform.position);
                if (action.actionTime > 0)
                {
                    tid       = TimerHeap.AddTimer((uint)((baseTime + action.actionTime) / theOwner.aiRate), 0, ProcessHit, theOwner, spellId, args2);
                    baseTime += action.actionTime;
                }
                if (action.nextHitTime > 0)
                {
                    tid       = TimerHeap.AddTimer((uint)((baseTime + action.nextHitTime) / theOwner.aiRate), 0, ProcessHit, theOwner, spellId, args2);
                    baseTime += action.nextHitTime;
                }
                theOwner.hitTimer.Add(tid);
            }

            /*int actionID = (int)args[0];
             * SkillActionData action = SkillActionData.dataMap[actionID];
             * SkillData skill = SkillData.dataMap[theOwner.currSpellID];
             * int duration = action.duration;
             * if (duration <= 0 && skill.skillAction.Count > 1 && theOwner.hitActionIdx >= (skill.skillAction.Count - 1))
             * {
             *  if (SkillActionData.dataMap[skill.skillAction[0]].duration <= 0)
             *  {
             *       //攻击结束,进入idle状态
             *      theOwner.AddCallbackInFrames<EntityParent>((_theOwner) =>
             *      {
             *
             *      },theOwner);
             *  }
             * }
             * else if (duration > 0 && action.action > 0)
             * {
             *  TimerHeap.AddTimer<int, EntityParent>((uint)duration, 0, (_actionID,_theOwner) =>
             *  {
             *      GameMotor theMotor = _theOwner.motor;
             *      if (_theOwner.Transform)
             *      {
             *          theMotor.enableStick = true;//驱动设置为静止
             *          theMotor.SetExtraSpeed(0);//额外速度为0
             *          theMotor.SetMoveDirection(Vector3.zero);//移动方向为(0,0,0)
             *      }
             *      _theOwner.ChangeMotionState(MotionState.IDLE);//改变状态为idle
             *  },actionID,theOwner);
             * }
             * if (action.duration > 0)
             * {
             *  TimerHeap.AddTimer<int, EntityParent>((uint)action.duration, 0, (_actionID, _theOwner) =>
             *  {
             *
             *  },actionID,theOwner);
             * }*/
        }