Example #1
0
 public static void AOE(this World world, Position pos, float radius, bool players, Action <Entity> callback)   //Null for player
 {
     if (players)
     {
         foreach (var i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius))
         {
             var d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y);
             if (d < radius)
             {
                 callback(i);
             }
         }
     }
     else
     {
         foreach (var i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
         {
             if (!(i is Enemy))
             {
                 continue;
             }
             var d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y);
             if (d < radius)
             {
                 callback(i);
             }
         }
     }
 }
Example #2
0
        public static void AOE(this World world, Position pos, float radius, bool players, Action <Entity> callback)   //Null for player
        {
            if (players)
            {
                foreach (var i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius).Where(e => e is Player))
                {
                    var d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y);
                    if (d < radius)
                    {
                        callback(i);
                    }
                }
            }
            else
            {
                foreach (var i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
                {
                    var e = i as Enemy;
                    if (e == null || e.ObjectDesc.Static)
                    {
                        continue;
                    }

                    var d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y);
                    if (d < radius)
                    {
                        callback(i);
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// Finds all entities in a circular range from a world position, and performs callback action for each.
 /// </summary>
 /// <param name="world">The target World.</param>
 /// <param name="pos">The target Position.</param>
 /// <param name="radius">The maximum range of the search.</param>
 /// <param name="players">If false, searches for enemies.</param>
 /// <param name="callback">The action to be performed by the entities found in the radius.</param>
 public static void AOE(this World world, Position pos, float radius, bool players, Action <Entity> callback)
 {
     if (players)
     {
         foreach (Entity i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius))
         {
             if (!i.IsValid())
             {
                 continue;
             }
             if (MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y) < radius)
             {
                 callback(i);
             }
         }
     }
     else
     {
         foreach (Entity i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
         {
             if (!i.IsValid() || !(i is Enemy))
             {
                 continue;
             }
             if (MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y) < radius)
             {
                 callback(i);
             }
         }
     }
 }
Example #4
0
 /// <summary>
 /// Checks if there is a player within 16 tiles of the target coordinate in a certain world.
 /// </summary>
 /// <param name="world">The world to be checked.</param>
 /// <param name="x">The X coordinate of the target.</param>
 /// <param name="y">The Y coordinate of the target.</param>
 /// <returns>A boolean.</returns>
 public static bool AnyPlayerNearby(this World world, double x, double y)
 {
     foreach (Entity i in world.PlayersCollision.HitTest(x, y, 16))
     {
         if (MathsUtils.Dist(i.X, i.Y, x, y) < 16 * 16)
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
 public static bool AnyPlayerNearby(this World world, double x, double y, int radius = Player.Radius)
 {
     foreach (var i in world.PlayersCollision.HitTest(x, y, radius).Where(e => e is Player))
     {
         var d = MathsUtils.DistSqr(i.X, i.Y, x, y);
         if (d < radius * radius)
         {
             return(true);
         }
     }
     return(false);
 }
Example #6
0
        public static void AOE(this World world, Position pos, float radius, bool players, Action <Entity> callback)
        //Null for player
        {
            List <Entity> entityCallbacks = new List <Entity>();

            if (players)
            {
                foreach (Entity p in world.PlayersCollision.HitTest(pos.X, pos.Y, radius))
                {
                    double d = MathsUtils.Dist(p.X, p.Y, pos.X, pos.Y);
                    if (d < radius)
                    {
                        entityCallbacks.Add(p);
                    }
                }
                foreach (Entity ie in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
                {
                    if (ie is ItemEntity && (ie as ItemEntity).hittable)
                    {
                        double d = MathsUtils.Dist(ie.X, ie.Y, pos.X, pos.Y);
                        if (d < radius)
                        {
                            entityCallbacks.Add(ie);
                        }
                    }
                }
            }
            else
            {
                foreach (Entity e in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius))
                {
                    if (!(e is Enemy))
                    {
                        continue;
                    }
                    double d = MathsUtils.Dist(e.X, e.Y, pos.X, pos.Y);
                    if (d < radius)
                    {
                        entityCallbacks.Add(e);
                    }
                }
            }

            if (entityCallbacks.Count > 0)
            {
                foreach (Entity e in entityCallbacks)
                {
                    callback(e);
                }
            }
        }
Example #7
0
        public static bool AnyEnemyNearby(this World world, double x, double y, int radius = Player.Radius)
        {
            foreach (var i in world.EnemiesCollision.HitTest(x, y, radius))
            {
                if (!(i is Enemy))
                {
                    continue;
                }

                var d = MathsUtils.DistSqr(i.X, i.Y, x, y);
                if (d < radius * radius)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #8
0
 public static bool AnyPlayerNearby(this World world, double x, double y)
 {
     return(world.PlayersCollision.HitTest(x, y, 16).Select(i => MathsUtils.Dist(i.X, i.Y, x, y)).Any(d => d < 16 * 16));
 }
Example #9
0
 public static void AOE(this World world, Position pos, float radius, bool players, Action <Entity> callback)   //Null for player
 {
     if (players)
     {
         foreach (var i in from i in world.PlayersCollision.HitTest(pos.X, pos.Y, radius) let d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y) where d < radius select i)
         {
             callback(i);
         }
     }
     else
     {
         foreach (Enemy i in from i in world.EnemiesCollision.HitTest(pos.X, pos.Y, radius).OfType <Enemy>() let d = MathsUtils.Dist(i.X, i.Y, pos.X, pos.Y) where d < radius select i)
         {
             callback(i);
         }
     }
 }