Beispiel #1
0
    public static Units FindNearst(Units self, Vector3 pos, global::TargetTag targetTag)
    {
        Units        result   = null;
        float        num      = 999999f;
        List <Units> mapUnits = MapManager.Instance.GetMapUnits(targetTag);

        for (int i = 0; i < mapUnits.Count; i++)
        {
            if (self != mapUnits[i])
            {
                float num2 = Vector3.Distance(self.mTransform.position, mapUnits[i].mTransform.position);
                if (num2 < num)
                {
                    num    = num2;
                    result = mapUnits[i];
                }
            }
        }
        return(result);
    }
Beispiel #2
0
    public static Units FindAutoSkillTarget(Units self, Vector3 pos, global::TargetTag targetTag, float radius, SkillTargetCamp skillTargetCamp = SkillTargetCamp.None, Skill skill = null)
    {
        List <Units> target_units = new List <Units>();
        Units        target       = null;

        if (targetTag == global::TargetTag.Hero)
        {
            target = PlayerControlMgr.Instance.GetSelectedTarget();
            if (target != null && Vector3.Distance(pos, target.mTransform.position) < radius)
            {
                return(target);
            }
            target = null;
        }
        else
        {
            if (skill == null)
            {
                target = FindTargetHelper.FindNearst(self, pos, targetTag);
            }
            else
            {
                target = FindTargetHelper.findClosestTarget(self, pos, skillTargetCamp, targetTag, skill.data.selectRangeType, skill.data.selectRange1, skill.data.selectRange2);
            }
            if (target != null && Vector3.Distance(pos, target.mTransform.position) < radius)
            {
                return(target);
            }
            target = null;
        }
        IList <Units> allHeroes = MapManager.Instance.GetAllHeroes();

        for (int i = 0; i < allHeroes.Count; i++)
        {
            target = allHeroes[i];
            if (Vector3.Distance(self.mTransform.position, target.mTransform.position) <= radius)
            {
                if (!(target == null) && target.isLive && target.CanSkillSelected && target.IsManualSelectable())
                {
                    if ((TeamManager.CanAttack(self, target) || (self != target && target.isHero && skillTargetCamp == SkillTargetCamp.AllWhitOutSelf) || skillTargetCamp == SkillTargetCamp.Partener || skillTargetCamp == SkillTargetCamp.All) && !target_units.Contains(target))
                    {
                        target_units.Add(target);
                    }
                }
            }
        }
        target = null;
        if (target_units.Count == 0)
        {
            return(target);
        }
        IList <Units> mapUnits = MapManager.Instance.GetMapUnits(self.TeamType, global::TargetTag.Hero);
        Units         x        = mapUnits.FirstOrDefault(delegate(Units unit)
        {
            target = unit.GetAttackTarget();
            if (target == null)
            {
                target = unit.GetSkillHitedTarget();
            }
            if (target == null)
            {
                target = unit.GetAttackedYouTarget();
            }
            if (target == null)
            {
                target = unit.GetSkillHitedYouTarget();
            }
            return(target_units.Contains(target));
        });

        if (x == null)
        {
            FindTargetHelper.SortTargets(self, GlobalSettings.Instance.AttackSortType, ref target_units);
            target = target_units[0];
        }
        return(target);
    }
Beispiel #3
0
    public static List <Units> findTargets(Units self, Vector3 pos, SkillTargetCamp targetType, global::TargetTag targetTag, float radius)
    {
        List <Units> list      = new List <Units>();
        int          layerMask = 1 << LayerMask.NameToLayer("UnitSelectObj");

        Collider[] array = Physics.OverlapSphere(pos, radius, layerMask);
        for (int i = 0; i < array.Length; i++)
        {
            if (array[i] != null)
            {
                Collider   collider   = array[i];
                GameObject gameObject = collider.transform.parent.gameObject;
                Units      component  = gameObject.GetComponent <Units>();
                if (!component.IsMonsterCreep() || !(self.GetAttackedYouTarget() != component))
                {
                    if (TagManager.CheckTag(component, targetTag))
                    {
                        if (TeamManager.CheckTeam(self.gameObject, gameObject, targetType, null))
                        {
                            if (!(component == null) && component.isLive && component.CanSkillSelected)
                            {
                                if (!list.Contains(component))
                                {
                                    list.Add(component);
                                }
                            }
                        }
                    }
                }
            }
        }
        return(list);
    }
Beispiel #4
0
    public static List <Units> findTargets(Units self, Vector3 pos, SkillTargetCamp targetType, global::TargetTag targetTag, EffectiveRangeType rangeType, float param1 = 0f, float param2 = 0f, int max_num = -1)
    {
        List <Units> list    = new List <Units>();
        List <int>   targets = null;

        switch (targetType)
        {
        case SkillTargetCamp.Self:
            list.Add(self);
            break;

        case SkillTargetCamp.Enemy:
            targets = TeamManager.GetOtherTeam(self.team, Relation.Hostility, true);
            break;

        case SkillTargetCamp.Partener:
            targets = TeamManager.GetOtherTeam(self.team, Relation.Friendly, true);
            break;

        case SkillTargetCamp.AttackYouTarget:
        {
            Units attackedYouTarget = self.GetAttackedYouTarget();
            if (attackedYouTarget != null)
            {
                list.Add(attackedYouTarget);
            }
            targets = TeamManager.GetOtherTeam(self.team, Relation.Hostility, true);
            break;
        }

        case SkillTargetCamp.SkillHitTarget:
        {
            Units skillHitedTarget = self.GetSkillHitedTarget();
            if (skillHitedTarget != null)
            {
                list.Add(skillHitedTarget);
            }
            return(list);
        }

        case SkillTargetCamp.AttackTarget:
        {
            Units attackTarget = self.GetAttackTarget();
            if (attackTarget != null)
            {
                list.Add(attackTarget);
            }
            targets = TeamManager.GetOtherTeam(self.team, Relation.Hostility, true);
            break;
        }

        case SkillTargetCamp.SkillHitYouTarget:
        {
            Units skillHitedYouTarget = self.GetSkillHitedYouTarget();
            if (skillHitedYouTarget != null)
            {
                list.Add(skillHitedYouTarget);
            }
            return(list);
        }

        case SkillTargetCamp.SelectTarget:
            if (self.currentSkillOrAttack != null)
            {
                return(self.currentSkillOrAttack.attackTargets);
            }
            return(list);
        }
        if (list.Count <= 0)
        {
            switch (rangeType)
            {
            case EffectiveRangeType.JuXing:
            case EffectiveRangeType.YuanXing:
            case EffectiveRangeType.ShanXing:
            case EffectiveRangeType.Single:
            {
                float      radius    = (param1 <= param2) ? param2 : param1;
                int        layerMask = 1 << LayerMask.NameToLayer("Vehicle");
                Collider[] array     = Physics.OverlapSphere(pos, radius, layerMask);
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] != null)
                    {
                        Collider   collider   = array[i];
                        GameObject gameObject = collider.transform.parent.gameObject;
                        Units      component  = gameObject.GetComponent <Units>();
                        if (max_num == -1 || list.Count < max_num)
                        {
                            if (TagManager.CheckTag(component, targetTag))
                            {
                                if (UnitFeature.TargetInRange(collider.transform.position, rangeType, pos, self.transform.eulerAngles, param1, param2))
                                {
                                    if (TeamManager.CheckTeam(self.gameObject, gameObject, targetType, null))
                                    {
                                        if (!(component == null) && component.isLive && component.CanSkillSelected)
                                        {
                                            if (!list.Contains(component))
                                            {
                                                list.Add(component);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            }

            case EffectiveRangeType.AllMap:
            {
                Dictionary <int, Units>             allMapUnits = MapManager.Instance.GetAllMapUnits();
                Dictionary <int, Units> .Enumerator enumerator  = allMapUnits.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    KeyValuePair <int, Units> current = enumerator.Current;
                    Units value = current.Value;
                    if (!(value == null) && value.isLive && value.CanSkillSelected)
                    {
                        if (max_num == -1 || list.Count < max_num)
                        {
                            if (TagManager.CheckTag(value, targetTag))
                            {
                                if (TeamManager.CheckTeamType(value.teamType, targets))
                                {
                                    if (!list.Contains(value))
                                    {
                                        list.Add(value);
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            }

            case EffectiveRangeType.Link:
            {
                float num        = (param1 <= param2) ? param2 : param1;
                int   layerMask2 = 1 << LayerMask.NameToLayer("Vehicle");
                if (max_num > 0)
                {
                    if (!(self == null))
                    {
                        Units attackTarget2 = self.GetAttackTarget();
                        if (!(attackTarget2 == null))
                        {
                            list.Add(attackTarget2);
                            pos = attackTarget2.transform.position;
                            while (list.Count < max_num)
                            {
                                bool       flag   = false;
                                Units      units  = null;
                                float      num2   = -1f;
                                Collider[] array2 = Physics.OverlapSphere(pos, num, layerMask2);
                                for (int j = 0; j < array2.Length; j++)
                                {
                                    if (array2[j] != null)
                                    {
                                        Collider   collider2   = array2[j];
                                        GameObject gameObject2 = collider2.transform.parent.gameObject;
                                        Units      component2  = gameObject2.GetComponent <Units>();
                                        if (max_num != -1 && list.Count >= max_num)
                                        {
                                            break;
                                        }
                                        if (TagManager.CheckTag(component2, targetTag))
                                        {
                                            if (TeamManager.CheckTeam(self.gameObject, gameObject2, targetType, null))
                                            {
                                                if (!(component2 == null) && component2.isLive && component2.CanSkillSelected)
                                                {
                                                    if (!list.Contains(component2))
                                                    {
                                                        if ((units == null || num2 > (pos - component2.transform.position).sqrMagnitude) && (pos - component2.transform.position).sqrMagnitude < num * num)
                                                        {
                                                            units = component2;
                                                            num2  = (pos - component2.transform.position).sqrMagnitude;
                                                        }
                                                        if (units != null)
                                                        {
                                                            flag = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (!flag)
                                {
                                    break;
                                }
                                list.Add(units);
                                pos = units.transform.position;
                            }
                        }
                    }
                }
                break;
            }
            }
        }
        return(list);
    }
Beispiel #5
0
    public static Units findDyingTarget(Units self, Vector3 pos, SkillTargetCamp targetType, global::TargetTag targetTag, EffectiveRangeType rangeType, float param1 = 0f, float param2 = 0f)
    {
        Units        result = null;
        List <Units> list   = FindTargetHelper.findTargets(self, pos, targetType, targetTag, rangeType, param1, param2, -1);

        if (list != null)
        {
            if (list.Count > 1)
            {
                result = FindTargetHelper.findDyingTarget(self.transform.position, list);
            }
            else
            {
                result = list[0];
            }
        }
        return(result);
    }
Beispiel #6
0
    public static Units findClosestTarget(Units self, Vector3 pos, SkillTargetCamp targetType, global::TargetTag targetTag, EffectiveRangeType rangeType, float param1 = 0f, float param2 = 0f)
    {
        List <Units> list   = FindTargetHelper.findTargets(self, pos, targetType, targetTag, rangeType, param1, param2, -1);
        Units        result = null;

        if (list != null)
        {
            if (list.Count > 1)
            {
                result = FindTargetHelper.findClosestTarget(pos, list);
            }
            else if (list.Count == 1)
            {
                result = list[0];
            }
        }
        return(result);
    }