Пример #1
0
        public static bool GetLineAoeCanHit(float spellrange, float spellwidth, Obj_AI_Base target, HitChance hitChance, Vector3 endRange,
                                            bool boundingRadius = true)
        {
            if (target == null || target.IsDashing())
            {
                return(false);
            }

            var targetPosition = target.ServerPosition.To2D();
            var fromPosition   = ObjectManager.GetLocalPlayer().ServerPosition;
            var width          = spellwidth + (boundingRadius ? target.BoundingRadius * BoundingRadiusMultiplicator : 0);
            var boundradius    = (boundingRadius
                ? target.BoundingRadius * BoundingRadiusMultiplicator
                : target.BoundingRadius);

            var rect = new MyPolygon.Rectangle(fromPosition, endRange, width);
            var circ = new MyPolygon.Circle(targetPosition, boundradius);

            return(circ.Points.Select(point => rect.IsInside(point)).FirstOrDefault());
        }
Пример #2
0
        public static Result GetCircleAoePrediction(this Spell spell, Obj_AI_Hero target, HitChance hitChance,
                                                    bool boundingRadius = true, bool extended = true, Vector3?sourcePosition = null)
        {
            try
            {
                if (spell == null || target == null)
                {
                    return(new Result(Vector3.Zero, new List <Obj_AI_Hero>()));
                }
                var fromPosition = sourcePosition ?? ObjectManager.GetLocalPlayer().ServerPosition;
                var hits         = new List <Obj_AI_Hero>();
                var center       = Vector3.Zero;
                var radius       = float.MaxValue;
                var range        = spell.Range + (extended ? spell.Width * 0.85f : 0) +
                                   (boundingRadius ? target.BoundingRadius * BoundingRadiusMultiplicator : 0);
                var positions = (from t in GameObjects.EnemyHeroes
                                 where t.IsValidTarget(range * 1.5f, false, false, fromPosition)
                                 let prediction = spell.GetPrediction(t)
                                                  where prediction.HitChance >= hitChance
                                                  select new Position(t, prediction.UnitPosition)).ToList();
                var spellWidth = spell.Width;
                if (positions.Any())
                {
                    var mainTarget    = positions.FirstOrDefault(p => p.Hero.NetworkId == target.NetworkId);
                    var possibilities =
                        ProduceEnumeration(
                            positions.Where(
                                p => p.UnitPosition.Distance(mainTarget.UnitPosition) <= spell.Width * 0.85f).ToList())
                        .Where(p => p.Count > 0 && p.Any(t => t.Hero.NetworkId == mainTarget.Hero.NetworkId))
                        .ToList();
                    foreach (var possibility in possibilities)
                    {
                        var mec      = Mec.GetMec(possibility.Select(p => p.UnitPosition.To2D()).ToList());
                        var distance = spell.From.Distance(mec.Center.To3D());
                        if (mec.Radius < spellWidth && distance < range)
                        {
                            var lHits  = new List <Obj_AI_Hero>();
                            var circle =
                                new MyPolygon.Circle(
                                    spell.From.Extend(
                                        mec.Center.To3D(), spell.Range > distance ? distance : spell.Range), spell.Width);

                            if (boundingRadius)
                            {
                                lHits.AddRange(
                                    from position in positions
                                    where
                                    new MyPolygon.Circle(
                                        position.UnitPosition,
                                        position.Hero.BoundingRadius * BoundingRadiusMultiplicator).Points.Any(
                                        p => circle.IsInside(p))
                                    select position.Hero);
                            }
                            else
                            {
                                lHits.AddRange(
                                    from position in positions
                                    where circle.IsInside(position.UnitPosition)
                                    select position.Hero);
                            }

                            if ((lHits.Count > hits.Count || lHits.Count == hits.Count && mec.Radius < radius ||
                                 lHits.Count == hits.Count &&
                                 spell.From.Distance(circle.Center.To3D()) < spell.From.Distance(center)) &&
                                lHits.Any(p => p.NetworkId == target.NetworkId))
                            {
                                center = To3D2(circle.Center);
                                radius = mec.Radius;
                                hits.Clear();
                                hits.AddRange(lHits);
                            }
                        }
                    }
                    if (!center.Equals(Vector3.Zero))
                    {
                        return(new Result(center, hits));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(new Result(Vector3.Zero, new List <Obj_AI_Hero>()));
        }