Exemplo n.º 1
0
 private void ScanNeighbourChunk(ILocation[] location, OreBulk ores)
 {
     for (int i = 0; i < location.Length; i++)
     {
         ScanNeighbourOres(location[i], ores);
     }
 }
Exemplo n.º 2
0
        private bool MineOres()
        {
            // Check if we have an ore set, if we don't
            // then we still haven't dug out a valid branch.
            if (ores == null)
            {
                return(false);
            }

            // Check if the ore list is empty, if it's
            // not empty take out locations and use them
            // until we run out.
            var loc = ores.Take();

            if (loc == null)
            {
                ores = null;
                return(false);
            }
            // Check if the ore is still the same block
            // (if not we have already mined it)
            if (player.world.GetBlockId(loc.location) != loc.id)
            {
                return(true); // Ignore this ore.
            }

            // By moving to the ores location we
            // guarantee to mine it and pick it up.
            moving = true;

            // Offset Y by -1 so that the bot would stand on the location
            // instead of stand above it.
            var map = player.functions.AsyncMoveToLocation(loc.location.Offset(-1), token, MOO);

            map.Completed += areaMap => {
                ScanNeighbourOres(loc.location, ores);           // Scan the block that we are standing on.
                ScanNeighbourOres(loc.location.Offset(2), ores); // Scan the block that our head is in.
                moving = false;
            };
            map.Cancelled += (areaMap, cuboid) => {
                moving = false; // Remove the current ore and
                                // ignore it (by not readding it)
            };
            //Check if the path is instantly completed.
            if (!map.Start() || (map.Searched && map.Complete && map.Valid))
            {
                moving = false;
            }
            return(true);
        }
Exemplo n.º 3
0
 private void ScanNeighbourOres(ILocation location, OreBulk ores)
 {
     // Scan neighbours in an 3x3 area.
     for (int x = -1; x < 2; x++)
     {
         for (int y = -1; y < 2; y++)
         {
             for (int z = -1; z < 2; z++)
             {
                 var loc = location.Offset(x, y, z);
                 var id  = player.world.GetBlockId(loc);
                 if (IsOre(id, loc))
                 {
                     ores.Add(new OreLocation(loc, id));
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        private bool DigBranch()
        {
            if (mult == 0)
            {
                return(false);
            }

            // Calculate current position
            // where we should branch from.
            var pos = SHARED.GetHome(player).Offset(directionOffset.Multiply(mult - pattern.gap));

            if (!IsTunnelable(player, pos))
            {
                return(false);
            }

            if (step == 1 || step == 3)   // Reset.

            {
                moving                = true;
                currentMap            = player.functions.AsyncMoveToLocation(pos, token, MOH);
                currentMap.Completed += areaMap =>
                {
                    if (step == 3)
                    {
                        step = 0;
                    }
                    else
                    {
                        step++;
                    }
                    moving = false;
                };
                currentMap.Cancelled += (areaMap, cuboid) => {
                    moving = false;
                };
                if (!currentMap.Start() || (currentMap.Searched && currentMap.Complete && currentMap.Valid))
                {
                    moving = false;
                }

                return(true);
            }

            // Swap x and z to get offset
            // to walls instead of tunenl.
            ILocation wallOffset = new Location(directionOffset.z, directionOffset.y, directionOffset.x);

            if (step == 2)   // If we are on step 1 then we should mine the other side.
            {
                wallOffset = wallOffset.Multiply(-1);
            }

            // Calculate the position we should check for a valid branch.
            var start = pos.Offset(wallOffset);

            if (!BlocksGlobal.blockHolder.IsSolid(player.world.GetBlockId(start.Offset(1))) ||
                !BlocksGlobal.blockHolder.IsSolid(player.world.GetBlockId(start.Offset(2))))
            {
                return(false);
            }

            // Calculate the position we should mine to.
            var temp = wallOffset.Multiply(pattern.lenght);
            var end  = pos.Offset(temp);

            if (!IsTunnelable(player, end))
            {
                //step++;
                step = 0;
                return(false);
            }
            moving = true;

            currentMap            = player.functions.AsyncMoveToLocation(end, token, MO);
            currentMap.Completed += areaMap => {
                step++;

                // Collect each location that we just mined.
                ILocation[] locations = new ILocation[pattern.lenght * 2];
                for (int i = 0; i < pattern.lenght; i++)
                {
                    locations[i * 2]     = pos.Offset(wallOffset.Multiply(i + 1).Offset(1));
                    locations[i * 2 + 1] = pos.Offset(wallOffset.Multiply(i + 1).Offset(2));
                }

                // Scan the branch that we just mined.
                var ores = new OreBulk();
                ScanNeighbourChunk(locations, ores);
                if (!ores.IsEmpty())
                {
                    this.ores = ores;
                }
                moving = false;
            };
            currentMap.Cancelled += (areaMap, cuboid) => {
                step++;
                moving = false;
            };
            if (!currentMap.Start() || (currentMap.Searched && currentMap.Complete && currentMap.Valid))
            {
                moving = false;
            }
            return(true);
        }