Exemplo n.º 1
0
        void ICrushResource.CrushResource(Actor self, CPos cell)
        {
            if (resourceValue == 0)
            {
                return;
            }

            var resourceAmount = resourceLayer.RemoveResource(Info.ResourceType, cell, int.MaxValue);

            if (resourceAmount == 0)
            {
                return;
            }

            var value = Util.ApplyPercentageModifiers(resourceValue * resourceAmount, new int[] { Info.ValueModifier });

            playerResources.ChangeCash(value);
            if (Info.ShowTicks && self.Owner.IsAlliedWith(self.World.RenderPlayer))
            {
                self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(value), Info.TickLifetime)));
            }

            if (Info.NotifyOtherActors)
            {
                foreach (var notify in self.World.ActorsWithTrait <INotifyResourceAccepted>())
                {
                    if (notify.Actor.Owner != self.Owner)
                    {
                        continue;
                    }

                    notify.Trait.OnResourceAccepted(notify.Actor, self, Info.ResourceType, resourceAmount, resourceValue);
                }
            }
        }
Exemplo n.º 2
0
        public override bool Tick(Actor self)
        {
            if (harv.IsTraitDisabled)
            {
                Cancel(self, true);
            }

            if (IsCanceling || harv.IsFull)
            {
                return(true);
            }

            // Move towards the target cell
            if (self.Location != targetCell)
            {
                foreach (var n in notifyHarvesterActions)
                {
                    n.MovingToResources(self, targetCell);
                }

                QueueChild(move.MoveTo(targetCell, 0));
                return(false);
            }

            if (!harv.CanHarvestCell(self, self.Location))
            {
                return(true);
            }

            // Turn to one of the harvestable facings
            if (harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
                if (desired != current)
                {
                    QueueChild(new Turn(self, desired));
                    return(false);
                }
            }

            var resource = resourceLayer.GetResource(self.Location);

            if (resource.Type == null || resourceLayer.RemoveResource(resource.Type, self.Location) != 1)
            {
                return(true);
            }

            harv.AcceptResource(self, resource.Type);

            foreach (var t in notifyHarvesterActions)
            {
                t.Harvested(self, resource.Type);
            }

            QueueChild(new Wait(harvInfo.BaleLoadDelay));
            return(false);
        }