Exemple #1
0
    public override void TickAILogic()
    {
        if (runAI == false)
        {
            return;
        }

        if (currentAniState == AniState.Idle || currentAniState == AniState.Move)
        {
            if (battleMgr.isGamePause == true)
            {
                Idle();
                return;
            }

            float delta = Time.deltaTime;
            checkCountTime += delta;
            if (checkCountTime < checkTime)
            {
                return;
            }
            else
            {
                // 计算目标方向
                Vector2 dir = CalcTargetDir();

                // 判断目标是否在攻击范围了
                if (InAtkRange() == false)
                {
                    // 不在则设置移动方向,并进入移动状态
                    SetDir(dir);
                    Move();
                }
                else
                {
                    Debug.Log(GetType() + "/TickAILogic()/In Atk Range");

                    // 在:则停止移动,进行攻击
                    SetDir(Vector2.zero);
                    // 判读攻击间隔
                    atkCountTime += checkCountTime;
                    if (atkCountTime >= atkTime)
                    {
                        //达到攻击事件,转向并攻击
                        SetAtkRotation(dir);
                        Attack(md.mCfg.skillID);
                        atkCountTime = 0;
                    }
                    else
                    {
                        // 未达到攻击时间,Idle等待
                        Idle();
                    }
                }

                checkCountTime = 0;
                checkTime      = PETools.RDInt(1, 5) * 1.0f / 10;
            }
        }
    }
Exemple #2
0
    public override void TickAILogic()
    {
        if (!runAI)
        {
            return;
        }

        if (currentAniState == AniState.Idle || currentAniState == AniState.Move)
        {
            if (battleMgr.isPauseGame)
            {
                Idle();
                return;
            }

            float delta = Time.deltaTime;
            checkCountTime += delta;
            if (checkCountTime < checkTime)
            {
                return;
            }
            else
            {
                //计算目标方向
                Vector2 dir = CalcTargetDir();

                //判断目标是否在攻击范围
                if (!InAtkRange())
                {
                    //不在:设置移动方向,进入一定状态
                    SetDir(dir);
                    Move();
                }
                else
                {
                    //在:则停止移动,进行攻击
                    SetDir(Vector2.zero);
                    //判断攻击间隔
                    atkCountTime += checkCountTime;
                    if (atkCountTime > atkTime)
                    {
                        //达到攻击时间,转向并攻击
                        SetAtkRotation(dir);
                        Attack(md.mCfg.skillID);
                        atkCountTime = 0;
                    }
                    else
                    {
                        //未达到攻击时间,Idle等待
                        Idle();
                    }
                }
                checkCountTime = 0;
                checkTime      = PETools.RDint(1, 5) * 1.0f / 10;
            }
        }
    }
    private void NormalMonsterLogic()
    {
        //这里待修复为什么怪物出生以后是none状态,没有进入idle状态,暂时的解决办法是判断加入none
        if (currentState == AniState.Idle || currentState == AniState.Walk || currentState == AniState.None)
        {
            float delta = Time.deltaTime;
            checkTimeCount += delta;
            if (checkTimeCount < checkTime)
            {
                return;
            }
            else
            {
                if (md.mCfg.mType==MonsterType.Elite)
                {
                    if (checkTimeCount<bossCheckTime)
                    {
                        return;
                    }
                }
                //计算目标方向
                Vector2 dir = CalculateTargetDir();
                if (!InAtkRange(false))
                {
                    //不在范围:设置移动方向,进入移动状态
                    SetDir(dir);
                    Move();
                }
                else
                {
                    //在:停止移动,进行攻击
                    SetDir(Vector2.zero);//这里设置为0,controller就会把状态修改为idle
                                         //判断攻击间隔,移动过程的时间也在累计攻击间隔
                    atkTimeCount += delta;
                    atkTimeCount += checkTimeCount;
                    if (atkTimeCount > atkTime)
                    {
                        //达到攻击时间,转向并且攻击
                        SetAtkRotation(dir);
                        
                        Attack(md.mCfg.skillID);
                        atkTimeCount = 0;
                    }
                    else
                    {
                        Idle();
                    }
                    checkTimeCount = 0;
                }
                //让检测时间在0.1~0.5秒内浮动
                checkTime = PETools.RDInt(1, 5) * 1.0f / 10;
                bossCheckTime= PETools.RDInt(1, 5) * 1.0f / 10;
            }

        }
    }
 /// <summary>
 /// 怪物的 AI 逻辑
 /// </summary>
 public override void TickAILogic()
 {
     if (!runAI)
     {
         return;
     }
     // 防止还在 出生状态 就开始移动,从而出现滑动效果
     if (currentAniState == AniState.Idle || currentAniState == AniState.Move)
     {
         // 暂停游戏
         if (battleMgr.isPauseGame)
         {
             Idle();
             return;
         }
         // 检测时间间隔计算
         float delta = Time.deltaTime;
         checkCountTime += delta;
         if (checkCountTime < checkTime)
         {
             return;
         }
         else
         {
             // 计算目标方向
             Vector2 dir = CalcTargetDir();
             // 判断目标是否在攻击范围
             if (!InAtkRange())   // 不在,设置移动方向,移动
             {
                 SetDir(dir);
                 Move();
             }
             else   // 在,停止移动,攻击
             {
                 SetDir(Vector2.zero);
                 // 判断攻击间隔
                 atkCountTime += checkCountTime; // 把移动的时间当成时间间隔的一部分,防止移动到目标身边后还要等待一会才会攻击
                 if (atkCountTime > atkTime)     // 达到攻击时间,转向并攻击
                 {
                     SetAtkRotation(dir);
                     Attack(md.mCfg.skillID);
                     atkCountTime = 0;
                 }
                 else   // 等待
                 {
                     Idle();
                 }
             }
             checkCountTime = 0;
             checkTime      = PETools.RanInt(1, 5) * 1.0f / 10; // 第一次 2 s,之后随机检测时间间隔
         }
     }
 }
Exemple #5
0
    public string GetRDNameData(bool man = true)
    {
        string rdName = surnameLst[PETools.RDint(0, surnameLst.Count - 1)];

        if (man)
        {
            rdName += manLst[PETools.RDint(0, manLst.Count - 1)];
        }
        else
        {
            rdName += womanLst[PETools.RDint(0, womanLst.Count - 1)];
        }
        return(rdName);
    }
Exemple #6
0
    /// <summary>
    /// 获取一个随机的名字
    /// </summary>
    /// <param name="man">默认男人名字,false 为女人</param>
    /// <returns></returns>
    public string GetRanName(bool man = true)
    {
        string ranName = surnameLst[PETools.RanInt(0, surnameLst.Count - 1)];

        if (man)
        {
            ranName += manLst[PETools.RanInt(0, manLst.Count - 1)];
        }
        else
        {
            ranName += womanLst[PETools.RanInt(0, womanLst.Count - 1)];
        }
        return(ranName);
    }
Exemple #7
0
    public override void TickAILogic()
    {
        if (!runAI)
        {
            return;
        }

        if (currentAniState == AniState.Idle || currentAniState == AniState.Move)
        {
            if (battleMgr.isPauseGame)
            {
                Idle();
                return;
            }

            float delta = Time.deltaTime;
            checkCountTime += delta;
            if (checkCountTime < checkTime)
            {
                return;
            }
            else
            {
                Vector2 dir = CalcTargetDir();
                if (!InAtkRange())
                {
                    SetDir(dir);
                    Move();
                }
                else
                {
                    SetDir(Vector2.zero);
                    atkCountTime += checkCountTime;
                    if (atkCountTime > atkTime)
                    {
                        SetAtkRotation(dir);
                        Attack(md.mCfg.skillID);
                        atkCountTime = 0;
                    }
                    else
                    {
                        Idle();
                    }
                }
                checkCountTime = 0;
                checkTime      = PETools.RDInt(1, 5) * 1.0f / 10;
            }
        }
    }
    public override void TickAILogic()
    {
        if (!runAI)
        {
            return;
        }

        if (CurrentAniState == AniState.Idle || CurrentAniState == AniState.Move)
        {
            if (BattleMgr.IsPauseGame)
            {
                Idle();
                return;
            }

            float delta = Time.deltaTime;
            m_CheckCountTime += delta;
            if (m_CheckCountTime < m_CheckTime)
            {
                return;
            }
            else
            {
                Vector2 dir = CalcTargetDir();
                if (!InAtkRange())
                {
                    SetDir(dir);
                    Move();
                }
                else
                {
                    SetDir(Vector2.zero);//设置静止
                    m_AtkCountTime += m_CheckCountTime;
                    if (m_AtkCountTime > m_AtkTime)
                    {
                        SetAtkRotation(dir, false);
                        Attack(Md.mCfg.skillID);
                        m_AtkCountTime = 0;
                    }
                    else
                    {
                        Idle();
                    }
                }
                m_CheckCountTime = 0;
                m_CheckTime      = PETools.RDInt(1, 5) * 1.0f / 10;
            }
        }
    }
Exemple #9
0
    public string GetRDNameData(bool man = true)
    {
        System.Random rd     = new System.Random();
        string        rdName = surNameList[PETools.RDInt(0, surNameList.Count - 1)];

        if (man)
        {
            rdName += manList[PETools.RDInt(0, manList.Count - 1)];
        }
        else
        {
            rdName += womanList[PETools.RDInt(0, womanList.Count - 1)];
        }
        return(rdName);
    }
Exemple #10
0
    public override void TickAILogic()
    {
        if (runAI == false)
        {
            return;
        }

        if (currentAnimState == AniState.Idle || currentAnimState == AniState.Move)
        {
            float delta = Time.deltaTime;
            checkCountTime += delta;
            if (checkCountTime < checkTime)
            {
                return;
            }

            Vector2 dir = CalcTargetDir();

            //判断是否在攻击范围内
            if (InAttackRange())
            {
                SetDir(Vector2.zero);
                atkCheckTime += delta;
                if (atkCheckTime > atkTime)
                {
                    //攻击
                    SetAtkDir(dir, false);
                    Attack(msd.mCfg.skillID);
                    atkCheckTime = 0;
                }
                else
                {
                    //休息
                    Idle();
                }
            }
            else
            {
                //移动
                SetDir(dir);
                Move();
            }

            checkCountTime = 0;
            checkTime      = PETools.RDInit(1, 5) * 0.1f / 10;
        }
    }
    private void CalcDamage(EntityBase caster, EntityBase target, SkillCfg skillCfg, int damage)
    {
        int dmgSum = damage;

        if (skillCfg.dmgType == DamageType.AD)
        {
            //计算闪避
            int dodgeNum = PETools.RDInt(1, 100, rd);
            if (dodgeNum <= target.Props.dodge)
            {
                //UI显示闪避 TODO
                target.SetDodge();
                return;
            }
            //计算属性加成
            dmgSum += caster.Props.ad;

            //计算暴击
            int criticalNum = PETools.RDInt(1, 100, rd);
            if (criticalNum <= caster.Props.critical)
            {
                float criticalRate = 1 + (PETools.RDInt(1, 100, rd) / 100.0f);
                dmgSum = (int)criticalRate * dmgSum;
                //PECommon.Log("暴击Rate:" + criticalNum + "/" + caster.Props.critical);
                target.SetCritical(dmgSum);
            }

            //计算穿甲
            int addef = (int)((1 - caster.Props.pierce / 100.0f) * target.Props.addef);
            dmgSum -= addef;
        }
        else if (skillCfg.dmgType == DamageType.AP)
        {
            //计算属性加成
            dmgSum += caster.Props.ap;
            //计算魔法抗性
            dmgSum -= target.Props.apdef;
        }
        else
        {
        }

        //最终伤害
        if (dmgSum < 0)
        {
            dmgSum = 0;
            return;
        }
        target.SetHurt(dmgSum);

        if (target.HP < dmgSum)
        {
            target.HP = 0;
            //目标死亡
            target.Die();
            if (target.entityType == EntityType.Monster)
            {
                target.BattleMgr.RmvMonster(target.Name);
            }
            else if (target.entityType == EntityType.Player)
            {
                target.BattleMgr.EndBattle(false, 0);
                target.BattleMgr.EntitySelfPlayer = null;
            }
        }
        else
        {
            target.HP -= dmgSum;
            if (target.entityState == EntityState.None && target.GetBreakState())
            {
                target.Hit();
            }
        }
    }
    //boss行动逻辑
    private void BossLogic()
    {
        if (currentState == AniState.Idle || currentState == AniState.Walk || currentState == AniState.None)
        {
            float delta = Time.deltaTime;
            checkTimeCount += delta;
            if (checkTimeCount < bossCheckTime)
            {
                return;
            }
            else
            {
                if (skillEnd)
                {
                    BossSkillSelect();
                    skillEnd = false;
                }
                //计算目标方向
                Vector2 dir = CalculateTargetDir();
                if (!InAtkRange(true))
                {
                    //不在范围:设置移动方向,进入移动状态
                    SetDir(dir);
                    Move();
                    //攻击4秒钟还没打出去,直接调用黑气,可以修改地形压迫玩家走位
                    if (checkTimeCount>=4)
                    {
                        SetDir(Vector2.zero);
                        atkTimeCount += delta;
                        atkTimeCount += checkTimeCount;
                        if (atkTimeCount > atkTime)
                        {
                            SetAtkRotation(dir);
                            Attack(bossSkillArray[1]);
                            skillEnd = true;
                            atkTimeCount = 0;
                        }
                        else
                        {//攻击间隔就追踪移动,可能回过于灵敏
                         //贴身的时候要进入idle状态
                            SetDir(dir);
                            SetAtkRotation(dir);
                            if (DistanceTooClose())
                            {
                                Attack(bossSkillArray[0]);
                            }
                            else
                            {
                                Move();
                            }
                        }
                        checkTimeCount = 0;
                        bossCheckTime = PETools.RDInt(1, 5) * 1.0f / 10;
                    }
                }
                else
                {
                    //在:停止移动,进行攻击
                    SetDir(Vector2.zero);//这里设置为0,controller就会把状态修改为idle
                                         //判断攻击间隔,移动过程的时间也在累计攻击间隔
                    atkTimeCount += delta;
                    atkTimeCount += checkTimeCount;
                    if (atkTimeCount > atkTime)
                    {
                        //达到攻击时间,转向并且攻击
                        SetAtkRotation(dir);
                        
                        Attack(currentBossSkill);
                        skillEnd = true;
                        atkTimeCount = 0;
                    }
                    else
                    {//攻击间隔就追踪移动,可能回过于灵敏
                        //贴身的时候就会发动攻击
                        SetDir(dir);
                        SetAtkRotation(dir);
                        if (DistanceTooClose())
                        {
                            Attack(bossSkillArray[0]);
                        }
                        else
                        {
                            Move();
                        }
                    }
                    checkTimeCount = 0;
                }
                //让检测时间在0.1~0.5秒内浮动
                checkTime = PETools.RDInt(1, 5) * 1.0f / 10;
                bossCheckTime = PETools.RDInt(1, 5) * 1.0f / 10;
            }

        }
    }
Exemple #13
0
    //计算伤害
    public void CalcDamge(EntityBase self, EntityBase target, SkillCfg skillCfg, int damage)
    {
        int damageSum = damage;

        if (skillCfg.dmgType == DamageType.AD)
        {
            //物理伤害
            //计算目标闪避
            int dodgeNum = PETools.RDInit(1, 100, rd);
            if (dodgeNum <= target.battleProps.dodge)
            {
                PECommon.Log("闪避:" + target.battleProps.dodge + "/" + dodgeNum);
                target.Dodge();
                return;
            }

            //计算属性加成伤害
            damageSum += self.battleProps.ad;

            //计算暴击
            int criticalNum = PETools.RDInit(1, 100, rd);
            if (criticalNum < self.battleProps.critical)
            {
                //计算暴击伤害倍率 1.5f~2.0f
                float hitDoubly = 1.0f + PETools.RDInit(50, 100, rd) / 100f;
                damageSum = (int)(damageSum * hitDoubly);
                target.Critical(damageSum);
                PECommon.Log("闪避:" + target.battleProps.critical + "/" + criticalNum);
            }

            //计算穿甲
            int adPierce = (int)((1 - self.battleProps.pierce / 100f) * target.battleProps.addef);
            damageSum -= adPierce;
        }
        else if (skillCfg.dmgType == DamageType.AP)
        {
            //魔法伤害
            //计算属性加成伤害
            damageSum += self.battleProps.ap;
            //计算魔法抗性
            damageSum -= self.battleProps.apdef;
        }


        //最终伤害
        if (damageSum < 0)
        {
            damageSum = 0;
        }

        if (target.HP <= damageSum)
        {
            //死亡
            target.HP = 0;
            target.Die();
            target.Remove();
        }
        else
        {
            //受伤 扣血
            target.HP -= damageSum;
            if (target.entityState != EntityState.BtState && target.GetBreakState())
            {
                target.Hit();
            }

            if (target.enitityType == EnitityType.Player)
            {
                AudioSource audioSource = target.GetAudioSource();
                AudioSvc.PlayAudio(Constants.AssasinHit, audioSource);
            }
            target.Hurt(damageSum);
        }

        PECommon.Log("Damage:" + damageSum, LogType.Warn);
    }
Exemple #14
0
    /// <summary>
    /// 技能伤害计算
    /// </summary>
    /// <param name="caster">施法者</param>
    /// <param name="target">目标</param>
    /// <param name="skillCfg">技能数据配置</param>
    /// <param name="damage">技能原本伤害值</param>
    private void CalcDamage(EntityBase caster, EntityBase target, SkillCfg skillCfg, int damage)
    {//伤害除了技能本身伤害,还需要加上自身属性值
        int dmgSum = damage;

        //计算属性加成
        dmgSum += caster.AttackValue;
        //暴击
        int criticalNum = PETools.RDInt(1, 100, rd);

        if (criticalNum <= caster.BattleProps.critical)
        {
            //暴击伤害比率在110%~200%之间
            float criticalRate = 1 + (PETools.RDInt(10, 100, rd) / 100.0f);
            dmgSum = (int)criticalRate * dmgSum;
            target.SetCritical(dmgSum);
            //Debug.Log("暴击伤害率:"+criticalRate+" 暴击率:"+caster.BattleProps.critical);
        }
        //计算防御扣减
        dmgSum -= target.BattleProps.defend;
        //最小伤害为0
        if (dmgSum < 0)
        {
            dmgSum = 0;
            return;
        }
        target.SetHurt(dmgSum);
        if (target.Hp <= dmgSum)
        {
            target.Hp = 0;
            //死亡
            target.Die();
            if (target.entityType == EntityType.Monster)
            {
                target.battleMg.RemoveMonster(target.Name);
            }
            else if (target.entityType == EntityType.Player)
            {
                target.battleMg.EndBattle(false, 0);
                target.battleMg.entitySelfPlayer = null;
            }
        }
        else
        {
            target.Hp -= dmgSum;
            //判断是否符合获取霸体条件
            target.GetUnBreakState();
            //TODO,是否处于剑刃风暴状态,是则反弹伤害
            if (!target.unBreakable && !target.cantStop)
            {
                target.Wound();
            }
            else
            {//为了对玩家友好,霸体状态下也会受伤提示
                if (target is EntityPlayer)
                {
                    AudioSource characterAudio = target.GetAudio();
                    AudioSvc.instance.PlayCharacterAudio(Constants.archerSpecialWound, characterAudio);
                }
            }
        }
    }
Exemple #15
0
    /// <summary>
    /// 技能伤害计算
    /// </summary>
    /// <param name="caster"></param>
    /// <param name="target"></param>
    /// <param name="skillCfg"></param>
    /// <param name="damage"></param>
    private void CalcDamage(EntityBase caster, EntityBase target, SkillCfg skillCfg, int damage)
    {
        //Debug.Log(GetType() + "/CalcDamage()/ ");

        int dmgSum = damage;

        if (skillCfg.dmgType == DamageType.AD)
        {
            // 计算闪避
            int dodgeNum = PETools.RDInt(1, 100, rd);
            if (dodgeNum <= target.Props.dodge)
            {
                // UI 显示闪避
                Debug.Log(GetType() + "/()/ Dodge Rate : " + dodgeNum + "/" + target.Props.dodge);
                target.SetDodge();
                return;
            }

            // 计算属性加成
            dmgSum += caster.Props.ad;

            //计算暴击
            int criticalNum = PETools.RDInt(1, 100, rd);
            if (criticalNum <= caster.Props.critical)
            {
                float criticalRate = 1 + PETools.RDInt(1, 100, rd) / 100.0f;
                dmgSum += (int)criticalRate * dmgSum;

                // UI 暴击
                Debug.Log(GetType() + "/()/ Critical Rate : " + criticalNum + "/" + caster.Props.critical);
                target.SetCiritical(dmgSum);
            }

            //计算穿甲
            int addef = (int)((1 - caster.Props.pierce / 100.0f) * target.Props.addef);
            dmgSum -= addef;
        }
        else if (skillCfg.dmgType == DamageType.AP)
        {
            // 计算属性加成
            dmgSum += caster.Props.ap;

            // 计算魔法抗性
            dmgSum -= target.Props.apdef;
        }
        else
        {
        }

        // 最终的伤害不能小于0(根据自己的项目来设定)
        if (dmgSum < 0)
        {
            dmgSum = 0;

            return;
        }

        // UI 显示最终伤害
        target.SetHurt(dmgSum);

        if (target.HP < dmgSum)
        {
            target.HP = 0;
            //目标死亡
            target.Die();
            if (target.entityType == EntityType.Monster)
            {
                target.battleMgr.RmvMonster(target.Name);
            }
            else if (target.entityType == EntityType.Player)
            {
                target.battleMgr.EndBattle(false, 0);
                target.battleMgr.entityPlayer = null;
            }
        }
        else
        {
            target.HP -= dmgSum;

            // 霸体状态可受伤害,但是不会切换到受伤状态
            if (target.entityState == EntityState.None && target.GetBreakState() == true)
            {
                // 目标受到攻击
                target.Hit();
            }
        }
    }