Esempio n. 1
0
        public override bool Tick(Actor self)
        {
            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 = resLayer.Harvest(self.Location);

            if (resource == null)
            {
                return(true);
            }

            harv.AcceptResource(self, resource);

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

            QueueChild(new Wait(harvInfo.BaleLoadDelay));
            return(false);
        }
Esempio n. 2
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                if (territory != null)
                {
                    territory.UnclaimByActor(self);
                }
                return(NextActivity);
            }

            harv.LastHarvestedCell = self.Location;

            if (harv.IsFull)
            {
                if (territory != null)
                {
                    territory.UnclaimByActor(self);
                }
                return(NextActivity);
            }

            // Turn to one of the harvestable facings
            if (harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = Util.QuantizeFacing(current, harvInfo.HarvestFacings) * (256 / harvInfo.HarvestFacings);
                if (desired != current)
                {
                    return(Util.SequenceActivities(new Turn(self, desired), this));
                }
            }

            var resource = resLayer.Harvest(self.Location);

            if (resource == null)
            {
                if (territory != null)
                {
                    territory.UnclaimByActor(self);
                }
                return(NextActivity);
            }

            harv.AcceptResource(resource);

            foreach (var t in self.TraitsImplementing <INotifyHarvesterAction>())
            {
                t.Harvested(self, resource);
            }

            return(Util.SequenceActivities(new Wait(harvInfo.LoadTicksPerBale), this));
        }
Esempio n. 3
0
        public void Leech(Actor self)
        {
            CPos cell  = CPos.Zero;
            var  cells = self.World.Map.FindTilesInCircle(self.World.Map.CellContaining(self.CenterPosition), 6, true)
                         .Where(c =>
            {
                if (!self.World.Map.Contains(c))
                {
                    return(false);
                }
                if (resLayer.GetResource(c) != null)
                {
                    return(false);
                }
                return(true);
            });

            if (cells != null && cells.Any())
            {
                cell = self.ClosestCell(cells);
            }

            if (cell != CPos.Zero && resLayer.GetResourceDensity(cell) > 0)
            {
                var ammount = resLayer.GetResource(cell).Info.ValuePerUnit;

                if ((self.Owner.PlayerActor.Trait <PlayerResources>().Resources + ammount) <= self.Owner.PlayerActor.Trait <PlayerResources>().ResourceCapacity)
                {
                    var playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();
                    playerResources.GiveResources(ammount);

                    if (ammount > 0 && self.IsInWorld && !self.IsDead)
                    {
                        if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
                        {
                            self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition,
                                                                                   self.Owner.Color.RGB, FloatingText.FormatCashTick(ammount), 30)));
                        }
                    }
                    resLayer.Harvest(cell);
                }
            }
        }
Esempio n. 4
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                claimLayer.RemoveClaim(self);
                return NextActivity;
            }

            harv.LastHarvestedCell = self.Location;

            if (harv.IsFull)
            {
                claimLayer.RemoveClaim(self);
                return NextActivity;

            }

            if(harvInfo.HarvestFacings != 0)
            {
                var current = facing.Facing;
                var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
                if (desired != current)
                    return ActivityUtils.SequenceActivities(new Turn(self, desired), this);
            }

            var resource = resLayer.Harvest(self.Location);
            if(resource == null)
            {
                claimLayer.RemoveClaim(self);
                return NextActivity;
            }

            harv.AcceptResource(resource);

            foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
                t.Harvested(self, resource);

            return ActivityUtils.SequenceActivities(new Wait(harvInfo.BaleLoadDelay), this);
        }
        void ITick.Tick(Actor self)
        {
            if (IsTraitDisabled)
            {
                return;
            }

            if (tickler-- <= 0)
            {
                var cells = self.World.Map.FindTilesInCircle(self.Location, info.CollectRange, true)
                            .Where(c =>
                {
                    if (resLayer.GetResource(c) == null)
                    {
                        return(false);
                    }
                    if (info.ResourcesNames.Contains(resLayer.GetResource(c).Info.Name))
                    {
                        return(true);
                    }
                    return(false);
                });

                var zapRandom = CPos.Zero;

                if (cells != null && cells.Any() && cells.Count() > 1)
                {
                    zapRandom = cells.MinByOrDefault(c => (self.Location - c).LengthSquared);
                }
                else if (cells != null && cells.Any() && cells.Count() == 1)
                {
                    zapRandom = cells.First();
                }

                if (zapRandom != CPos.Zero)
                {
                    var ammount         = resLayer.GetResource(zapRandom).Info.ValuePerUnit;
                    var playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();

                    playerResources.GiveResources(ammount);

                    if (ammount > 0 && self.IsInWorld && !self.IsDead)
                    {
                        var floattest = ammount.ToString();

                        floattest = "+ " + floattest + " Essence";

                        if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
                        {
                            self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition,
                                                                                   self.Owner.Color.RGB, floattest, 30)));
                        }
                    }

                    resLayer.Harvest(zapRandom);
                    if (resLayer.GetResourceDensity(zapRandom) <= 0)
                    {
                        resLayer.Destroy(zapRandom);
                    }

                    var weapon = Info.WeaponInfo;
                    if (weapon == null)
                    {
                        return;
                    }

                    if (weapon.Report != null && weapon.Report.Any())
                    {
                        Game.Sound.Play(SoundType.World, weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
                    }

                    weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(zapRandom)), self, Enumerable.Empty <int>());

                    tickler = info.CollectInterval;
                }
            }
        }
Esempio n. 6
0
        public int Leech(Actor self)
        {
            var validRes = new HashSet <string>();

            foreach (var restype in resourceTypesPreres)
            {
                var hash = new List <string>();
                hash.Add(restype.Value);

                if (restype.Value == "NONE")
                {
                    validRes.Add(restype.Key);
                }
                else if (self.Owner.PlayerActor.TraitOrDefault <TechTree>().HasPrerequisites(hash))
                {
                    validRes.Add(restype.Key);
                }
            }

            CPos cell  = CPos.Zero;
            var  cells = self.World.Map.FindTilesInCircle(self.World.Map.CellContaining(self.CenterPosition), 6, true)
                         .Where(c =>
            {
                if (!self.World.Map.Contains(c))
                {
                    return(false);
                }
                if (resLayer.GetResource(c) == null)
                {
                    return(false);
                }
                if (resLayer.GetResourceDensity(c) == 0)
                {
                    return(false);
                }
                if (validRes.Contains(resLayer.GetResource(c).Info.Type))
                {
                    return(true);
                }

                return(false);
            });

            if (cells != null && cells.Any())
            {
                cell = self.ClosestCell(cells);
            }

            if (cell != CPos.Zero && resLayer.GetResourceDensity(cell) > 0)
            {
                var type    = resLayer.GetResource(cell);
                var ammount = type.Info.ValuePerUnit + ReturnExtraTime(type);

                if ((self.Owner.PlayerActor.Trait <PlayerResources>().Resources + ammount) <= self.Owner.PlayerActor.Trait <PlayerResources>().ResourceCapacity)
                {
                    var playerResources = self.Owner.PlayerActor.Trait <PlayerResources>();
                    playerResources.GiveResources(ammount);

                    if (ammount > 0 && self.IsInWorld && !self.IsDead)
                    {
                        var floattest = ammount.ToString();

                        floattest = "+ " + floattest + " Essence";

                        if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
                        {
                            self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition,
                                                                                   self.Owner.Color.RGB, floattest, 30)));
                        }
                    }

                    resLayer.Harvest(cell);
                    if (resLayer.GetResourceDensity(cell) <= 0)
                    {
                        resLayer.Destroy(cell);
                    }

                    return(ammount);
                }
            }

            return(0);
        }
Esempio n. 7
0
        public override Activity Tick(Actor self)
        {
            if (ChildActivity != null)
            {
                ChildActivity = ActivityUtils.RunActivityTick(self, ChildActivity);
                if (ChildActivity != null)
                {
                    return(this);
                }
            }

            //if (IsCanceling || harv.IsFull)
            //	return NextActivity;

            // Move towards the target cell
            if (self.Location != targetCell)
            {
                //foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
                //	n.MovingToResources(self, targetCell, new FindAndDeliverResources(self));

                self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false);
                QueueChild(self, move.MoveTo(targetCell, 2), true);
                return(this);
            }

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

            // 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(self, new Turn(self, desired), true);
            //		return this;
            //	}
            //}

            var resource = resLayer.Harvest(self.Location);

            if (resource == null)
            {
                return(NextActivity);
            }

            harv.AcceptResource(self, resource);


            // это событие ловится WithHarverAnimation классом, чтобы 1 раз проиграть анимацию сборки спайса.
            //foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
            //	t.Harvested(self, resource);

            foreach (var t in self.TraitsImplementing <INotifyAttack>())
            {
                if (t is OpenRA.Mods.Common.Traits.Render.WithAttackOverlay)                 //возьмем анимацию для поедания из анимации атаки.
                {
                    t.PreparingAttack(self, new Target(), null, null);
                }
            }
            //этой Activity делается пауза после одного съедания спайса, чтобы не сосать как пылесосом и подождать анимацию глотания спайса

            //QueueChild(self, new Wait(500), true);
            return(this);
        }
Esempio n. 8
0
        public override Activity Tick(Actor self)
        {
            if (ChildActivity != null)
            {
                ChildActivity = ActivityUtils.RunActivityTick(self, ChildActivity);
                if (ChildActivity != null)
                {
                    return(this);
                }
            }

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

            // Move towards the target cell
            if (self.Location != targetCell)
            {
                foreach (var n in self.TraitsImplementing <INotifyHarvesterAction>())
                {
                    n.MovingToResources(self, targetCell, new FindAndDeliverResources(self));
                }

                self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false);
                QueueChild(self, move.MoveTo(targetCell, 2), true);
                return(this);
            }

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

            // 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(self, new Turn(self, desired), true);
                    return(this);
                }
            }

            var resource = resLayer.Harvest(self.Location);

            if (resource == null)
            {
                return(NextActivity);
            }

            harv.AcceptResource(self, resource);

            foreach (var t in self.TraitsImplementing <INotifyHarvesterAction>())
            {
                t.Harvested(self, resource);
            }

            QueueChild(self, new Wait(harvInfo.BaleLoadDelay), true);
            return(this);
        }