예제 #1
0
        private void DigTunnel()
        {
            // Calculate the next position.
            var pos = SHARED.GetHome(player).Offset(directionOffset.Multiply(mult));

            if (!IsTunnelable(player, pos))
            {
                mult += pattern.gap;
                return;
            }
            moving = true;

            currentMap            = player.functions.AsyncMoveToLocation(pos, token, fails < 8 ? MO : MOH);
            currentMap.Completed += areaMap => {
                fails  = 0;
                mult  += pattern.gap;
                moving = false;
            };
            currentMap.Cancelled += (areaMap, cuboid) => {
                fails++;
                moving = false;
            };

            if (!currentMap.Start() || (currentMap.Searched && currentMap.Complete && currentMap.Valid))
            {
                moving = false;
            }
        }
예제 #2
0
        /// Attempts to move to the shared home location
        /// if the bot has not reached it before.
        /// <returns>True if we are moving to the location.</returns>
        private bool MoveHome()
        {
            if (reachedHome)
            {
                return(false);
            }
            if (moving)
            {
                return(true);
            }

            currentMap            = player.functions.AsyncMoveToLocation(SHARED.GetHome(player), token, MOH);
            currentMap.Completed += areaMap => {
                reachedHome = true;
                moving      = false;
            };
            currentMap.Cancelled += (areaMap, cuboid) => {
                reachedHome = false;
                moving      = false;
            };

            //Start moving.
            this.moving = true;
            currentMap.Start();
            return(true);
        }
예제 #3
0
        public void OnTick()
        {
            if (player.status.entity.isDead)
            {
                return;
            }
            ++this.ticks;
            this.ticks = 0;
            if (player.physicsEngine.path != null && !player.physicsEngine.path.Complete && (player.physicsEngine.path.Valid || this.moving))
            {
                return;
            }
            int       num1     = Convert.ToInt32(((IEntity)player.status.entity).location.X) + Wander.rnd.Next(-10, 20);
            int       int32    = Convert.ToInt32(((IEntity)player.status.entity).location.Y);
            int       num2     = Convert.ToInt32(((IEntity)player.status.entity).location.Z) + Wander.rnd.Next(-10, 20);
            IAsyncMap location = player.functions.AsyncMoveToLocation((ILocation) new Location(num1, (float)int32, num2), (IStopToken)this.stopToken, this.LowDetailOption);

            // ISSUE: method pointer
            ((IAreaMap)location).Completed += OnPathReached;
            // ISSUE: method pointer
            ((IAreaMap)location).Cancelled += OnPathFailed;
            location.Start();
            if (((IAreaMap)location).Valid)
            {
                player.functions.LookAtBlock((ILocation) new Location(num1, (float)int32, num2), false);
            }
            this.moving = true;
            if (((IAreaMap)location).Searched && ((IAreaMap)location).Complete && ((IAreaMap)location).Valid)
            {
                this.OnPathReached((IAreaMap)location);
            }
        }
예제 #4
0
 /// <summary>
 /// Transforms a comonent into a caching factory of components
 /// </summary>
 /// <param name="component">Component to decorate with hash based caching</param>
 public AsyncMapCacheDecoratingFactory(IEquatableConverter <TArg> converter, IAsyncMap <TArg, TRes> component)
 {
     if (converter == null)
     {
         throw new ArgumentNullException("converter");
     }
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     this.component = component;
     this.converter = converter;
 }
 public CachingLinearWeightsProviderFactory2(IScatteredPointContextBasedLinearWeightProviderOnSphere <TContext> weightsProvider, IAsyncMap <INodes, TContext> contextProvider)
 {
     result = new AsyncLazy <IScatteredPointsLinearInterpolatorOnSphere>(async() =>
     {
         var contextProvidingFactory = new AsyncMapCacheDecoratingFactory <INodes, TContext>(new HashBasedEquatibleINodesConverter(), contextProvider);
         var cachingDecorator        = await contextProvidingFactory.CreateAsync();
         var adapter = new CellRequestToPointsAdapter <TContext>(weightsProvider);
         var facade  = new TwoPhaseScatteredPointsLenearInterpolatorFacade <TContext>(cachingDecorator, adapter);
         return(facade);
     });
 }
 public CachingLinearWeightsProviderFactory(IScatteredPointContextBasedLinearWeightProviderOnSphere <TContext> weightsProvider, IAsyncMap <INodes, TContext> contextProvider)
 {
     this.weightsProvider         = weightsProvider;
     this.contextProvidingFactory = new AsyncMapCacheDecoratingFactory <INodes, TContext>(converter, contextProvider);
 }
예제 #7
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);
        }
 public TwoPhaseScatteredPointsLenearInterpolatorFacade(IAsyncMap <INodes, TContext> contextProvider, ILinearWeightsFromContextProvider <TContext> weightsProvider)
 {
     this.contextProvider = contextProvider;
     this.weightsProvider = weightsProvider;
 }
예제 #9
0
 public NodesMapToVarioAdapter(IAsyncMap <RealValueNodes, VariogramModule.IVariogram> component)
 {
     this.component = component;
 }