Пример #1
0
    public void ToAttackByIndex(AttackType attackType, int index)
    {
        if (m_RoleFSMMgr == null)
        {
            return;
        }
        if (m_StateAttak == null)
        {
            m_StateAttak = (RoleStateAttack)m_RoleFSMMgr.GetState(RoleState.Attack);
            if (m_StateAttak == null)
            {
                return;
            }
        }
        m_RoleFSMMgr.CurRoleCtrl.CurAttackInfo = m_RoleFSMMgr.CurRoleCtrl.Attack.GetAttackInfoByIndex(attackType, index);
        m_StateAttak.AnimatorCondition         = (attackType == AttackType.PhyAttack ? ToAnimatorCondition.ToPhyAttack.ToString() : ToAnimatorCondition.ToSkillAttack.ToString());
        m_StateAttak.AnimatorConditionValue    = index;
        KeyValuePair <string, int> stateValue = GetAnimatorName(attackType, index);

        m_StateAttak.CurAnimatorName   = stateValue.Key;
        m_StateAttak.CurrentStateValue = stateValue.Value;
        //必须能进去
        m_RoleFSMMgr.ChangeState(RoleState.Attack);
    }
Пример #2
0
    public IEnumerator ToHurt(RoleTransferAttackInfo attackInfo)
    {
        if (m_RoleFSMMgr == null)
        {
            yield break;
        }
        SkillEntity      skillEntity      = SkillDBModel.Instance.Get(attackInfo.SkillId);
        SkillLevelEntity skillLevelEntity = SkillLevelDBModel.Instance.GetEnityBySkillIdAndSkillLevel(attackInfo.SkillId, attackInfo.SkillLevel);

        if (skillEntity == null || skillLevelEntity == null)
        {
            yield break;
        }
        yield return(new WaitForSeconds(skillEntity.ShowHurtEffectDelaySecond));

        //¼õѪ
        m_RoleFSMMgr.CurRoleCtrl.CurRoleInfo.CurrentHP -= attackInfo.HurtValue;
        if (OnHurt != null)
        {
            OnHurt();
        }
        if (m_RoleFSMMgr.CurRoleCtrl.CurRoleInfo.CurrentHP < 0)
        {
            m_RoleFSMMgr.CurRoleCtrl.CurRoleInfo.CurrentHP = 0;
            m_RoleFSMMgr.CurRoleCtrl.ToDie();
            yield break;
        }
        //²¥·ÅÊÜÉËÌØЧ
        int   fontSize = 1;
        Color color    = Color.red;

        if (attackInfo.IsCri)
        {
            fontSize = 2;
            color    = Color.yellow;
        }
        UISceneCtrl.Instance.CurrentUIScene.HUD.NewText("- " + attackInfo.HurtValue.ToString(), m_RoleFSMMgr.CurRoleCtrl.transform, color, fontSize, 15f, -1f, 2.2f, UnityEngine.Random.Range(0, 2) == 1 ? bl_Guidance.LeftDown : bl_Guidance.RightDown);
        if (!m_RoleFSMMgr.CurRoleCtrl.IsRigibody)
        {
            m_RoleFSMMgr.ChangeState(RoleState.Hurt);
        }
    }
Пример #3
0
 public void ToIdle()
 {
     CurrRoleFSMMgr.ChangeState(RoleState.Idle);
 }
Пример #4
0
 public void ToIdle(RoleIdleState state = RoleIdleState.IdleNormal)
 {
     CurrRoleFSMMgr.ToIdleState = state;
     CurrRoleFSMMgr.ChangeState(RoleState.Idle);
 }
Пример #5
0
    public void ToAttack(RoleAttackType type, int skillId)
    {
        if (m_CurrRoleFSMMgr == null || m_CurrRoleFSMMgr.CurrRoleCtrl.IsRigidity)
        {
            if (type == RoleAttackType.SkillAttack)
            {
                m_NextSkillId = skillId;
            }
            return;
        }
        m_NextSkillId = -1;
        //1.角色类型只有玩家和怪才参与技能数值计算

        if (m_CurrRoleCtrl.CurrRoleType == RoleType.MainPlayer || m_CurrRoleCtrl.CurrRoleType == RoleType.Monster)
        {
            //2.获取技能信息
            SkillEntity skillEntity = SkillDBModel.Instance.Get(skillId);
            if (skillEntity == null)
            {
                return;
            }
            int skillLevel = m_CurrRoleCtrl.CurrRoleInfo.GetSkillLevel(skillId);
            //技能所需魔法值
            int spendMP = skillEntity.SpendMP + skillEntity.SpendMPLevelUp * (skillLevel - 1);
            //3.如果是主角
            if (m_CurrRoleCtrl.CurrRoleType == RoleType.MainPlayer && type == RoleAttackType.SkillAttack)
            {
                if (GlobalInit.Instance.SkillSlotsItem != null)
                {
                    if (spendMP > GlobalInit.Instance.PlayerInfo.CurrMP)
                    {
                        TipsUtil.ShowTextTips(1000504);
                        return;
                    }
                    GlobalInit.Instance.PlayerInfo.CurrMP -= spendMP;
                    GlobalInit.Instance.PlayerInfo.SetSkillCDEndTime(skillId);
                    if (m_CurrRoleCtrl.OnMPChange != null)
                    {
                        m_CurrRoleCtrl.OnMPChange(ValueChnageType.Reduce);
                    }
                    GlobalInit.Instance.SkillSlotsItem.AddTimer();
                    GlobalInit.Instance.SkillSlotsItem = null;
                }
            }
            m_EnemyList.Clear();
            //4.找敌人 如果是主角才找敌人 怪找敌人使用AI
            if (m_CurrRoleCtrl.CurrRoleType == RoleType.MainPlayer)
            {
                int attackTargetCount = skillEntity.AttackTargetCount;
                if (attackTargetCount == 1)
                {
                    #region ------ 单体攻击 ------
                    //单体攻击 必须有锁定敌人
                    if (m_CurrRoleCtrl.LockEnemy != null)
                    {
                        m_EnemyList.Add(m_CurrRoleCtrl.LockEnemy);
                    }
                    else
                    {
                        m_SearchList.Clear();
                        //没有锁定敌人
                        //发射射线去找 离当前攻击者最近的 就是锁定敌人
                        Collider[] searchList = Physics.OverlapSphere(m_CurrRoleCtrl.transform.position, skillEntity.AreaAttackRadius, 1 << LayerMask.NameToLayer("Role"));
                        if (searchList != null && searchList.Length > 0)
                        {
                            for (int i = 0; i < searchList.Length; i++)
                            {
                                if (searchList[i].GetComponent <RoleCtrl>().CurrRoleType != RoleType.MainPlayer)
                                {
                                    m_SearchList.Add(searchList[i]);
                                }
                            }
                        }
                        m_SearchList.Sort((c1, c2) =>
                        {
                            int ret = 0;
                            if (Vector3.Distance(c1.transform.position, m_CurrRoleCtrl.transform.position) <
                                Vector3.Distance(c2.transform.position, m_CurrRoleCtrl.transform.position))
                            {
                                ret = -1;
                            }
                            else
                            {
                                ret = 1;
                            }
                            return(ret);
                        });
                        if (m_SearchList.Count > 0)
                        {
                            m_CurrRoleCtrl.LockEnemy = m_SearchList[0].GetComponent <RoleCtrl>();
                            m_EnemyList.Add(m_CurrRoleCtrl.LockEnemy);
                        }
                    }
                    #endregion
                }
                else
                {
                    #region ------ 群体攻击 ------

                    int needAttackCount = attackTargetCount;
                    m_SearchList.Clear();
                    //没有锁定敌人
                    //发射射线去找 离当前攻击者最近的 就是锁定敌人
                    Collider[] searchList = Physics.OverlapSphere(m_CurrRoleCtrl.transform.position, skillEntity.AreaAttackRadius, 1 << LayerMask.NameToLayer("Role"));
                    if (searchList != null && searchList.Length > 0)
                    {
                        for (int i = 0; i < searchList.Length; i++)
                        {
                            if (searchList[i].GetComponent <RoleCtrl>().CurrRoleType != RoleType.MainPlayer)
                            {
                                m_SearchList.Add(searchList[i]);
                            }
                        }
                    }
                    m_SearchList.Sort((c1, c2) =>
                    {
                        int ret = 0;
                        if (Vector3.Distance(c1.transform.position, m_CurrRoleCtrl.transform.position) <
                            Vector3.Distance(c2.transform.position, m_CurrRoleCtrl.transform.position))
                        {
                            ret = -1;
                        }
                        else
                        {
                            ret = 1;
                        }
                        return(ret);
                    });

                    //群体攻击 如果有锁定敌人 锁定敌人必须是攻击目标之一
                    if (m_CurrRoleCtrl.LockEnemy != null)
                    {
                        m_EnemyList.Add(m_CurrRoleCtrl.LockEnemy);
                        needAttackCount--;
                        for (int i = 0; i < m_SearchList.Count; i++)
                        {
                            RoleCtrl ctrl = m_SearchList[i].GetComponent <RoleCtrl>();
                            if (ctrl.CurrRoleInfo.RoleId != m_CurrRoleCtrl.CurrRoleInfo.RoleId)
                            {
                                if ((i + 1) > needAttackCount)
                                {
                                    break;
                                }
                                m_EnemyList.Add(m_SearchList[i].GetComponent <RoleCtrl>());
                            }
                        }
                    }
                    else
                    {
                        if (m_SearchList.Count > 0)
                        {
                            m_CurrRoleCtrl.LockEnemy = m_SearchList[0].GetComponent <RoleCtrl>();
                            for (int i = 0; i < m_SearchList.Count; i++)
                            {
                                RoleCtrl ctrl = m_SearchList[i].GetComponent <RoleCtrl>();
                                if ((i + 1) > needAttackCount)
                                {
                                    break;
                                }
                                m_EnemyList.Add(ctrl);
                            }
                        }
                    }


                    #endregion
                }
            }
            else if (m_CurrRoleCtrl.CurrRoleType == RoleType.Monster)
            {
                if (m_CurrRoleCtrl.LockEnemy != null)
                {
                    m_EnemyList.Add(m_CurrRoleCtrl.LockEnemy);
                }
            }
            //Debug.Log(m_EnemyList.Count);
            //5.让敌人受伤
            for (int i = 0; i < m_EnemyList.Count; i++)
            {
                m_EnemyList[i].ToHurt(CalculateHurtValue(m_EnemyList[i], skillEntity));
            }
        }

        #region ------ 动画特效相关 ------
        RoleAttackInfo info = GetRoleAttackInfo(type, skillId);
        if (info == null)
        {
            return;
        }

        GlobalInit.Instance.StartCoroutine(PlayerEffect(info));
        //EffectManager.Instance.DestroyEffect(trans, info.EffectLifeTime);
        //if (info.IsDoCameraShake && CameraCtrl.Instance != null)
        //{
        //    CameraCtrl.Instance.CameraShake(info.CameraShakeDelay);
        //}

        if (m_RoleStateAttack == null)
        {
            m_RoleStateAttack = m_CurrRoleFSMMgr.GetRoleState(RoleState.Attack) as RoleStateAttack;
        }

        m_RoleStateAttack.AnimatorCondition      = type == RoleAttackType.PhyAttack ? "ToPhyAttack" : "ToSkill";
        m_RoleStateAttack.AnimatorConditionValue = info.Index;
        m_RoleStateAttack.AnimatorCurrState      = GameUtil.GetRoleAnimatorState(type, info.Index);

        #endregion

        m_CurrRoleFSMMgr.ChangeState(RoleState.Attack);
    }
Пример #6
0
 /// <summary>
 /// 切换到待机
 /// </summary>
 public void ToIdle()
 {
     RoleFSMMgr.ChangeState(RoleStateType.Idle);
 }
Пример #7
0
 /// <summary>
 /// Çд©µ½Idle
 /// </summary>
 public void ToIdle(IdleType idleType)
 {
     FSM.NextIdleType = idleType;
     FSM.ChangeState(RoleState.Idle);
 }
Пример #8
0
    /// <summary> 角色受伤 </summary>
    /// <param name="attackInfo"></param>
    public IEnumerator ToHurt(RoleTransferAttackInfo attackInfo)
    {
        if (m_CurrRoleFSMMgr == null)
        {
            yield break;
        }
        //如果角色已经死亡了 直接返回
        if (m_CurrRoleFSMMgr.CurrRoleStateEnum == RoleState.Die)
        {
            yield break;
        }
        SkillEntity skillEntity = SkillDBModel.Instance.Get(attackInfo.SkillId);

        if (skillEntity == null)
        {
            yield break;
        }

        yield return(new WaitForSeconds(skillEntity.ShowHurtEffectDelaySecond));

        //1.减血

        m_CurrRoleFSMMgr.CurrRoleCtrl.CurrRoleInfo.CurrHP -= attackInfo.HurtValue;
        int   fontSize = 15;
        Color color    = Color.red;

        if (attackInfo.IsCri)
        {
            fontSize = 30;
            color    = Color.yellow;
        }
        UISceneCtrl.Instance.CurrentUIScene.HUDText.NewText("- " + attackInfo.HurtValue, m_CurrRoleFSMMgr.CurrRoleCtrl.transform, color, fontSize, 15f, -1f, 2.2f, UnityEngine.Random.Range(0, 2) == 1? bl_Guidance.RightDown:bl_Guidance.LeftDown);
        if (OnRoleHurt != null)
        {
            OnRoleHurt();
        }
        if (m_CurrRoleFSMMgr.CurrRoleCtrl.CurrRoleInfo.CurrHP <= 0)
        {
            //角色死亡
            m_CurrRoleFSMMgr.CurrRoleCtrl.CurrRoleInfo.CurrHP = 0;
            m_CurrRoleFSMMgr.CurrRoleCtrl.ToDie();

            yield break;
        }
        //2.播放受伤特效
        Transform hurtTrans = EffectManager.Instance.PlayEffect("Effect_Hurt", "Common");

        //TODO 设置特效位置
        hurtTrans.position = m_CurrRoleFSMMgr.CurrRoleCtrl.transform.position;
        hurtTrans.rotation = m_CurrRoleFSMMgr.CurrRoleCtrl.transform.rotation;
        EffectManager.Instance.DestroyEffect(hurtTrans, 2f);


        //3.弹出受伤数字 HUDText(包括暴击效果)

        //4.屏幕泛红

        //不是僵直状态才播放受伤动画
        if (!m_CurrRoleFSMMgr.CurrRoleCtrl.IsRigidity)
        {
            m_CurrRoleFSMMgr.ChangeState(RoleState.Hurt);
        }
    }