Beispiel #1
0
        void cmbEntities_DrawItem(object sender, DrawItemEventArgs e)
        {
            Graphics  g        = e.Graphics;
            Rectangle area     = e.Bounds;
            Rectangle iconArea = area;

            iconArea.Width = 16;
            if (e.Index >= 0)
            {
                e.DrawBackground();
                TileEntity ent  = (TileEntity)cmbTEntities.Items[e.Index];
                int        dist = (int)Vector3i.Distance((Vector3d)ent.Pos, PlayerPos);

                // Draw entity icon
                g.DrawImage(ent.Image, iconArea);

                // Entity name
                SizeF     entName = g.MeasureString(ent.ToString(), this.Font);
                Rectangle ctxt    = area;
                ctxt.X     = iconArea.Right + 3;
                ctxt.Width = (int)entName.Width + 1;
                g.DrawString(ent.ToString(), this.Font, new SolidBrush(e.ForeColor), ctxt);

                // Distance.
                string    derp     = string.Format("({0}m away)", dist);
                SizeF     entDist  = g.MeasureString(derp, this.Font);
                Rectangle distArea = area;
                distArea.X     = ctxt.Right + 3;
                distArea.Width = (int)entDist.Width;
                g.DrawString(derp, this.Font, new SolidBrush(Color.FromArgb(128, e.ForeColor)), distArea);
            }
        }
Beispiel #2
0
        public override int Compare(TileEntity x, TileEntity y)
        {
            double _x = Vector3i.Distance((Vector3d)x.Pos, PlayerPos);
            double _y = Vector3i.Distance((Vector3d)y.Pos, PlayerPos);

            return(_x.CompareTo(_y));
        }
Beispiel #3
0
 public static void GetPulpAroundPoint(User user, Vector3i position, int range)
 {
     try
     {
         for (int i = -range; i < range; i++)
         {
             for (int j = -range; j < range; j++)
             {
                 if (i == 0 && j == 0)
                 {
                     continue;
                 }
                 Vector3i positionAbove = World.GetTopPos(new Vector2i(position.x + i, position.z + j)) + Vector3i.Up;
                 Block    blockAbove    = World.GetBlockProbablyTop(positionAbove);
                 if (blockAbove.Is <TreeDebris>())
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <WoodPulpItem>(5))
                         {
                             World.DeleteBlock(positionAbove);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #4
0
        public override int Compare(Entity x, Entity y)
        {
            double _x = Vector3i.Distance(x.Pos, PlayerPos);
            double _y = Vector3i.Distance(y.Pos, PlayerPos);

            return(_x.CompareTo(_y));
        }
Beispiel #5
0
 /// <summary>
 /// Get a list of position of top Block that match the type T. Usefull when wanted to destroy plants or tree debris
 /// </summary>
 public static List <Vector3i> GetTopBlockPositionAroundPoint <T>(User user, Vector3i position, int range) where T : Block
 {
     try
     {
         List <Vector3i> blockLists = new List <Vector3i>();
         for (int i = -range; i < range; i++)
         {
             for (int j = -range; j < range; j++)
             {
                 if (i == 0 && j == 0)
                 {
                     continue;
                 }
                 Vector3i positionAbove = World.GetTopPos(new Vector2i(position.x + i, position.z + j)) + Vector3i.Up;
                 Block    blockAbove    = World.GetBlockProbablyTop(positionAbove);
                 if (blockAbove is T)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         InteractionInfo info = new InteractionInfo();
                         info.Method        = InteractionMethod.Right;
                         info.BlockPosition = positionAbove;
                         InteractionContext context = info.MakeContext(user.Player);
                         if (AuthManager.IsAuthorized(context))
                         {
                             blockLists.Add(positionAbove);
                         }
                     }
                 }
             }
         }
         return(blockLists);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #6
0
 /// <summary>Get the closest distance between this <see cref="Box3i"/> and the <see cref="Vector3i"/>.</summary>
 public double Distance( ref  Vector3i point)
 {
     Vector3i nearest;
         NearestPointTo(ref point, out nearest);
         return point.Distance(ref nearest);
 }
Beispiel #7
0
 public static float Distance(Vector3i a, Vector3i b)
 {
     return(Vector3i.Distance(a, b));
 }
Beispiel #8
0
 public static void GetPlantBlockAroundPoint(User user, Vector3i position, int range)
 {
     try
     {
         for (int i = -range; i < range; i++)
         {
             for (int j = -range; j < range; j++)
             {
                 if (i == 0 && j == 0)
                 {
                     continue;
                 }
                 Vector3i positionAbove = World.GetTopPos(new Vector2i(position.x + i, position.z + j)) + Vector3i.Up;
                 Block    blockAbove    = World.GetBlockProbablyTop(positionAbove);
                 if (blockAbove is CornBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <CornItem>(6))
                         {
                             if (user.Inventory.TryAddItems <CornSeedItem> (3))
                             {
                                 World.DeleteBlock(positionAbove);
                             }
                         }
                     }
                 }
                 else if (blockAbove is TomatoesBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <TomatoItem>(6))
                         {
                             if (user.Inventory.TryAddItems <TomatoSeedItem> (3))
                             {
                                 World.DeleteBlock(positionAbove);
                             }
                         }
                     }
                 }
                 else if (blockAbove is FireweedBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <FireweedShootsItem>(6))
                         {
                             if (user.Inventory.TryAddItems <FireweedSeedItem> (3))
                             {
                                 World.DeleteBlock(positionAbove);
                             }
                         }
                     }
                 }
                 else if (blockAbove is WheatBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <WheatItem>(5))
                         {
                             if (user.Inventory.TryAddItems <WheatSeedItem> (3))
                             {
                                 World.DeleteBlock(positionAbove);
                             }
                         }
                     }
                 }
                 else if (blockAbove is BeetsBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <BeetItem>(5))
                         {
                             if (user.Inventory.TryAddItems <BeetSeedItem> (3))
                             {
                                 World.DeleteBlock(positionAbove);
                             }
                         }
                     }
                 }
                 else if (blockAbove is BeansBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <BeansItem>(5))
                         {
                             World.DeleteBlock(positionAbove);
                         }
                     }
                 }
                 else if (blockAbove is RiceBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <RiceItem>(5))
                         {
                             World.DeleteBlock(positionAbove);
                         }
                     }
                 }
                 else if (blockAbove is FernBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <FiddleheadsItem>(5))
                         {
                             if (user.Inventory.TryAddItems <FernSporeItem> (3))
                             {
                                 World.DeleteBlock(positionAbove);
                             }
                         }
                     }
                 }
                 else if (blockAbove is KelpBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <KelpItem>(5))
                         {
                             World.DeleteBlock(positionAbove);
                         }
                     }
                 }
                 else if (blockAbove is PricklyPearBlock)
                 {
                     if (positionAbove != position && Vector3i.Distance(positionAbove, position) < range)
                     {
                         if (user.Inventory.TryAddItems <PricklyPearFruitItem>(5))
                         {
                             World.DeleteBlock(positionAbove);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }