コード例 #1
0
 public PersonValued(Actor self, PersonValuedInfo info)
 {
     this.info = info;
 }
コード例 #2
0
        public void SpawnNewActor(Actor self)
        {
            //basic setup of values
            var owner = self.Owner;
            var exit  = self.Location + info.MoveOffset;


            //find produced unit cost values
            var ValidActors = new HashSet <string>();

            ;
            var Actorcount = 1;

            var guysFound      = new HashSet <Actor>();
            var underWay       = 0;
            var alreadyReached = 0;

            //find enough actors

            Actor            actor       = null;
            PersonValuedInfo BuilderInfo = null;

            if (self.World.Map.Rules.Actors[info.SpawnActor].HasTraitInfo <PersonValuedInfo>())
            {
                BuilderInfo = self.World.Map.Rules.Actors[info.SpawnActor].TraitInfo <PersonValuedInfo>();
            }

            if (BuilderInfo != null && info.UseConverting)
            {
                ValidActors = BuilderInfo.ConvertingActors;
                actor       = PossibleActor(self, guysFound, ValidActors);
            }
            else if (info.TrainingActors.Any() && info.UseConverting)
            {
                ValidActors = info.TrainingActors;
                actor       = PossibleActor(self, guysFound, ValidActors);
            }
            else
            {
                if (!self.IsDead || self.IsInWorld)
                {
                    self.World.AddFrameEndTask(w =>
                    {
                        var td = new TypeDictionary
                        {
                            new ParentActorInit(self),
                            new LocationInit(self.Location + info.MoveOffset),
                            new CenterPositionInit(self.CenterPosition + info.Offset),
                            new OwnerInit(self.Owner),
                            new FactionInit(self.Owner.Faction.InternalName),
                            new FacingInit(0)
                        };
                        RespawnActor = w.CreateActor(info.SpawnActor, td);
                        var moveto   = RespawnActor.TraitOrDefault <IMove>();
                        RespawnActor.CancelActivity();
                        RespawnActor.QueueActivity(moveto.VisualMove(RespawnActor, RespawnActor.CenterPosition,
                                                                     self.World.Map.CenterOfCell(self.Location + info.MoveOffset)));

                        if (RespawnActor.Info.HasTraitInfo <HarvesterInfo>())
                        {
                            RespawnActor.QueueActivity(new FindResources(RespawnActor));
                        }

                        if (InUse.Contains(RespawnActor))
                        {
                            InUse.Remove(RespawnActor);
                        }
                    });
                    Ticker = info.RespawnTime;
                    return;
                }
            }
            Ticker = info.RespawnTime;
            if (actor == null)
            {
                Ticker = 50;
                return;
            }

            var infiltrate = self.CenterPosition + info.Offset;

            //Actor is possible to move?
            RespawnActor = actor;
            InUse.Add(actor);
            var move = actor.TraitOrDefault <IMove>();

            if ((!actor.IsInWorld || !actor.IsDead))
            {
                //beginn movement
                actor.CancelActivity();
                actor.QueueActivity(move.MoveTo(exit, 5));
                //what happens when actor or barracks dies
                actor.QueueActivity(new CallFunc(() =>
                {
                    if (StillValid(actor, self))
                    {
                        return;
                    }

                    //if not died continue and recalculate ow position
                    //visually enter the building
                    var selfposition = actor.CenterPosition;
                    actor.QueueActivity(move.VisualMove(actor, selfposition, infiltrate));
                    //if dead before finished
                    actor.QueueActivity(new CallFunc(() =>
                    {
                        if (StillValid(actor, self))
                        {
                            return;
                        }

                        var td = new TypeDictionary
                        {
                            new ParentActorInit(self),
                            new LocationInit(self.Location + info.MoveOffset),
                            new CenterPositionInit(self.CenterPosition + info.Offset),
                            new OwnerInit(self.Owner),
                            new FactionInit(self.Owner.Faction.InternalName),
                            new FacingInit(0)
                        };


                        self.World.AddFrameEndTask(w =>
                        {
                            RespawnActor = w.CreateActor(info.SpawnActor, td);
                            var moveto   = RespawnActor.TraitOrDefault <IMove>();
                            RespawnActor.QueueActivity(move.MoveIntoWorld(RespawnActor, exit));
                            RespawnActor.QueueActivity(move.MoveTo(exit, 2));

                            if (RespawnActor.Info.HasTraitInfo <HarvesterInfo>())
                            {
                                RespawnActor.QueueActivity(new FindResources(RespawnActor));
                            }

                            if (InUse.Contains(RespawnActor))
                            {
                                InUse.Remove(RespawnActor);
                            }
                        });
                    }));
                    //set reached units state +1 and units in movement state -1
                    actor.QueueActivity(new RemoveSelf());                     //of he goes
                }));
            }
        }