Example #1
0
        public void UnblockRefinery(Actor self)
        {
            // Check that we're not in a critical location and being useless (refinery drop-off):
            var lastproc = LastLinkedProc ?? LinkedProc;

            if (lastproc != null && !lastproc.Disposed)
            {
                var deliveryLoc = lastproc.Location + lastproc.Trait <IAcceptResources>().DeliveryOffset;
                if (self.Location == deliveryLoc)
                {
                    // Get out of the way:
                    var unblockCell = LastHarvestedCell ?? (deliveryLoc + Info.UnblockCell);
                    var moveTo      = mobile.NearestMoveableCell(unblockCell, 1, 5);

                    // TODO: The harvest-deliver-return sequence is a horrible mess of duplicated code and edge-cases
                    var notify        = self.TraitsImplementing <INotifyHarvesterAction>();
                    var findResources = new FindResources(self);
                    foreach (var n in notify)
                    {
                        n.MovingToResources(self, moveTo, findResources);
                    }

                    self.QueueActivity(mobile.MoveTo(moveTo, 1));
                    self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
                }
            }
        }
Example #2
0
        public void UnblockRefinery(Actor self)
        {
            // Check that we're not in a critical location and being useless (refinery drop-off):
            var lastproc = LastLinkedProc ?? LinkedProc;

            if (lastproc != null && !lastproc.Disposed)
            {
                var deliveryLoc = lastproc.Location + lastproc.Trait <IAcceptResources>().DeliveryOffset;
                if (self.Location == deliveryLoc)
                {
                    // Get out of the way:
                    var unblockCell = LastHarvestedCell ?? (deliveryLoc + Info.UnblockCell);
                    var moveTo      = mobile.NearestMoveableCell(unblockCell, 1, 5);
                    self.QueueActivity(mobile.MoveTo(moveTo, 1));
                    self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);

                    var territory = self.World.WorldActor.TraitOrDefault <ResourceClaimLayer>();
                    if (territory != null)
                    {
                        territory.ClaimResource(self, moveTo);
                    }

                    var notify = self.TraitsImplementing <INotifyHarvesterAction>();
                    var next   = new FindResources(self);
                    foreach (var n in notify)
                    {
                        n.MovingToResources(self, moveTo, next);
                    }

                    self.QueueActivity(next);
                }
            }
        }
Example #3
0
        public ResourcesResponse Any(FindResources request)
        {
            //return ExecuteFaultHandledMethod(() =>
            //{
            ResourcesResponse response = new ResourcesResponse();
            var query = BuildQuery <JarsResource>(request);
            //var _repository = _DataRepositoryFactory.GetDataRepository<IResourceRepository>();
            var _repository = _DataRepositoryFactory.GetDataRepository <IGenericEntityRepositoryBase <JarsResource, IDataContextNhJars> >();
            var res         = _repository.Where(query, request.FetchEagerly).ToList();
            var resDto      = res.ConvertAllTo <ResourceDto>().ToList();

            response.Resources = resDto;

            return(response);
            // });
        }
Example #4
0
        /// <summary>
        /// A helper method used for building the query, depending on if the LoadLazy option was set.
        /// </summary>
        /// <typeparam name="T">A query over object required by the QueryOver Method on the repository</typeparam>
        /// <param name="request">The same request passed into the service</param>
        /// <param name="hasWhere">a bool value indicating if there is a where string</param>
        /// <returns></returns>
        private Expression <Func <T, bool> > BuildQuery <T>(FindResources request) where T : Entities.JarsResource
        {
            Expression <Func <T, bool> > query = LinqExpressionBuilder.True <T>();

            //Id
            if (request.Id != 0)
            {
                query = query.And(o => o.Id == request.Id);
            }

            //ExternalRef
            if (request.ExternalRef != null && request.ExternalRef != string.Empty)
            {
                query = query.And(j => j.ExtRef == request.ExternalRef);
            }

            //ExternalRef1
            if (request.ExternalRef1 != null && request.ExternalRef1 != string.Empty)
            {
                query = query.And(O => O.ExtRef1 == request.ExternalRef1);
            }

            //ExternalRef2
            if (request.ExternalRef2 != null && request.ExternalRef2 != string.Empty)
            {
                query = query.And(O => O.ExtRef2 == request.ExternalRef2);
            }

            //DisplayName
            if (request.DisplayName != null && request.DisplayName != string.Empty)
            {
                query = query.And(j => j.DisplayName == request.DisplayName);
            }

            //IsActive
            if (request.IsActive.HasValue)
            {
                query = query.And(o => o.IsActive == request.IsActive.Value);
            }

            return(query);
        }
Example #5
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Harvest")
            {
                // NOTE: An explicit harvest order allows the harvester to decide which refinery to deliver to.
                LinkProc(self, OwnerLinkedProc = null);
                idleSmart = true;

                self.CancelActivity();

                CPos?loc;
                if (order.TargetLocation != CPos.Zero)
                {
                    // Find the nearest claimable cell to the order location (useful for group-select harvest):
                    loc = mobile.NearestCell(order.TargetLocation, p => mobile.CanEnterCell(p) && claimLayer.TryClaimCell(self, p), 1, 6);
                }
                else
                {
                    // A bot order gives us a CPos.Zero TargetLocation.
                    loc = self.Location;
                }

                var findResources = new FindResources(self);
                self.QueueActivity(findResources);
                self.SetTargetLine(Target.FromCell(self.World, loc.Value), Color.Red);

                foreach (var n in notify)
                {
                    n.MovingToResources(self, loc.Value, findResources);
                }

                LastOrderLocation = loc;

                // This prevents harvesters returning to an empty patch when the player orders them to a new patch:
                LastHarvestedCell = LastOrderLocation;
            }
            else if (order.OrderString == "Deliver")
            {
                // NOTE: An explicit deliver order forces the harvester to always deliver to this refinery.
                var iao = order.TargetActor.TraitOrDefault <IAcceptResources>();
                if (iao == null || !iao.AllowDocking || !IsAcceptableProcType(order.TargetActor))
                {
                    return;
                }

                if (order.TargetActor != OwnerLinkedProc)
                {
                    LinkProc(self, OwnerLinkedProc = order.TargetActor);
                }

                idleSmart = true;

                self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green);

                self.CancelActivity();

                var deliver = new DeliverResources(self);
                self.QueueActivity(deliver);

                foreach (var n in notify)
                {
                    n.MovingToRefinery(self, order.TargetLocation, deliver);
                }
            }
            else if (order.OrderString == "Stop" || order.OrderString == "Move")
            {
                foreach (var n in notify)
                {
                    n.MovementCancelled(self);
                }

                // Turn off idle smarts to obey the stop/move:
                idleSmart = false;
            }
        }
Example #6
0
        public void ResolveOrder(Actor self, Order order)
        {
            if (order.OrderString == "Harvest")
            {
                // NOTE: An explicit harvest order allows the harvester to decide which refinery to deliver to.
                LinkProc(self, OwnerLinkedProc = null);
                idleSmart = true;

                self.CancelActivity();

                if (order.TargetLocation != CPos.Zero)
                {
                    var loc       = order.TargetLocation;
                    var territory = self.World.WorldActor.TraitOrDefault <ResourceClaimLayer>();

                    if (territory != null)
                    {
                        // Find the nearest claimable cell to the order location (useful for group-select harvest):
                        loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && territory.ClaimResource(self, p), 1, 6);
                    }
                    else
                    {
                        // Find the nearest cell to the order location (useful for group-select harvest):
                        var taken = new HashSet <CPos>();
                        loc = mobile.NearestCell(loc, p => mobile.CanEnterCell(p) && taken.Add(p), 1, 6);
                    }

                    self.QueueActivity(mobile.MoveTo(loc, 0));
                    self.SetTargetLine(Target.FromCell(self.World, loc), Color.Red);

                    var notify = self.TraitsImplementing <INotifyHarvesterAction>();
                    var next   = new FindResources(self);
                    foreach (var n in notify)
                    {
                        n.MovingToResources(self, loc, next);
                    }

                    LastOrderLocation = loc;
                }
                else
                {
                    // A bot order gives us a CPos.Zero TargetLocation, so find some good resources for him:
                    var loc = FindNextResourceForBot(self);

                    // No more resources? Oh well.
                    if (!loc.HasValue)
                    {
                        return;
                    }

                    self.QueueActivity(mobile.MoveTo(loc.Value, 0));
                    self.SetTargetLine(Target.FromCell(self.World, loc.Value), Color.Red);

                    LastOrderLocation = loc;
                }

                // This prevents harvesters returning to an empty patch when the player orders them to a new patch:
                LastHarvestedCell = LastOrderLocation;
                self.QueueActivity(new FindResources(self));
            }
            else if (order.OrderString == "Deliver")
            {
                // NOTE: An explicit deliver order forces the harvester to always deliver to this refinery.
                var iao = order.TargetActor.TraitOrDefault <IAcceptResources>();
                if (iao == null || !iao.AllowDocking || !IsAcceptableProcType(order.TargetActor))
                {
                    return;
                }

                if (order.TargetActor != OwnerLinkedProc)
                {
                    LinkProc(self, OwnerLinkedProc = order.TargetActor);
                }

                if (IsEmpty)
                {
                    return;
                }

                idleSmart = true;

                self.SetTargetLine(Target.FromOrder(self.World, order), Color.Green);

                self.CancelActivity();

                var next = new DeliverResources(self);
                self.QueueActivity(next);

                var notify = self.TraitsImplementing <INotifyHarvesterAction>();
                foreach (var n in notify)
                {
                    n.MovingToRefinery(self, order.TargetLocation, next);
                }
            }
            else if (order.OrderString == "Stop" || order.OrderString == "Move")
            {
                var notify = self.TraitsImplementing <INotifyHarvesterAction>();
                foreach (var n in notify)
                {
                    n.MovementCancelled(self);
                }

                // Turn off idle smarts to obey the stop/move:
                idleSmart = false;
            }
        }