예제 #1
0
 public static bool InHurtZone(Role executor, Role target, SkillTplData skillTpl)
 {
     if (skillTpl.Affectdistance.Length > 1)
     {
         int     direction     = executor.getOrientation() == Role.Orientation.RIGHT ? 1 : -1;
         Vector2 rolePt        = executor.transform.position;
         Vector2 targetCheckPt = target.GetAttackablePosition(executor);
         if (skillTpl.Affectdistance[0] == 2)//圆形区域
         {
             return(Vector2.Distance(rolePt, targetCheckPt) < skillTpl.Affectdistance[1]);
         }
         else
         {
             Vector2 nearT = new Vector2(rolePt.x + skillTpl.Affectdistance[1] * direction * 0.01f, rolePt.y + skillTpl.Affectdistance[2] * 0.01f);
             Vector2 farB  = new Vector2(rolePt.x + skillTpl.Affectdistance[3] * direction * 0.01f, rolePt.y + skillTpl.Affectdistance[4] * 0.01f);
             if (direction == -1)
             {
                 float temp = nearT.x;
                 nearT.x = farB.x;
                 farB.x  = temp;
             }
             if (targetCheckPt.x > nearT.x && targetCheckPt.x < farB.x && targetCheckPt.y > farB.y && targetCheckPt.y < nearT.y)
             {
                 return(true);
             }
         }
     }
     else
     {
         Debug.LogError("技能没有配置受击区域,skillId=" + skillTpl.ID);
     }
     return(false);
 }
예제 #2
0
    public HeroAi(Hero hero) : base(hero)
    {
        _hero        = hero;
        skillTplData = TemplateManager.GetSkillTplData(_autoSkillId);

        _heroInfo = _hero.GetRoleInfo() as HeroInfo;
        _heroInfo.addListener(EventBase.CHANGE, OnHeroInfoChange);

        _releasedTimeCount = -1;
        OnHeroInfoChange(null);
    }
예제 #3
0
    private int SelectRandomSkill(Role target)
    {
        Vector2      targetAttackPt = target.GetAttackablePosition(_role);
        int          skillId        = _aiTpl.Skills[UnityEngine.Random.Range(0, _aiTpl.Skills.Length)];
        SkillTplData tplData        = _skillTpls[skillId];
        float        distance       = Vector2.Distance(targetAttackPt, _role.transform.position);

        if (tplData.Type == Skill.TYPE_BUFF_ONLY && (tplData.Targettype == Skill.TARGET_TYPE_SELF_TEAM || tplData.Targettype == Skill.TARGET_TYPE_SELF))
        {
            if (distance < _role.GetRoleInfo().SeeDistance)
            {
                if (releaseBuffSkillTime > 0 && lastSkill == tplData)
                {
                    return(-1);
                }
                if (releaseBuffSkillTime > 2.0f && lastSkill != tplData)
                {
                    return(-1);
                }
                lastSkill            = tplData;
                releaseBuffSkillTime = tplData.Interval;
                return(tplData.ID);
            }
            return(-1);
        }
        if (tplData.Type == Skill.TYPE_MAGIC && target is Wall)//如果是城墙,优先使用物理攻击
        {
            foreach (var item in _skillTpls)
            {
                if (item.Value.Type == Skill.TYPE_PHYSICS || item.Value.Type == Skill.TYPE_PHYSICS_FAR)
                {
                    return(-1);
                }
            }
        }

        if (distance < tplData.Distance &&
            Mathf.Abs(targetAttackPt.y - _role.transform.position.y) < _role.GetRoleInfo().Tpl.Vmaxdistance&&
            distance > _role.GetRoleInfo().MinDistance)
        {
            //if (InHurtZone(_role, target, tplData))
            //{
            //    lastSkill = tplData;
            //    return tplData.ID;
            //}
            lastSkill = tplData;
            return(tplData.ID);
        }
        return(-1);
    }
예제 #4
0
 public Skill(int skillId, Role executor, Vector2 pt, Role target = null) : base(executor)
 {
     _skillID     = skillId;
     _targetRole  = target;
     _targetPoint = pt;
     _skillTpl    = TemplateManager.GetSkillTplData(_skillID);
     if (_skillTpl == null)
     {
         Debug.LogError(string.Format("未找到技能,SkillId={0}", skillId));
     }
     _skillConfigs = TemplateManager.GetSkillConfigDatas(_skillTpl.Configid);
     if (_skillConfigs.Length == 0)
     {
         Debug.LogError(string.Format("未找到技能配置信息,SkillId={0}, ConfigId={1}", skillId, _skillTpl.Configid));
     }
 }