OpenRA.Mods.Common.Activities.Transform.Tick C# (CSharp) Method

Tick() public method

public Tick ( Actor self ) : Activity
self Actor
return OpenRA.Activities.Activity
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
                return NextActivity;

            self.World.AddFrameEndTask(w =>
            {
                if (self.IsDead)
                    return;

                foreach (var nt in self.TraitsImplementing<INotifyTransform>())
                    nt.OnTransform(self);

                var selected = w.Selection.Contains(self);
                var controlgroup = w.Selection.GetControlGroupForActor(self);

                self.Dispose();
                foreach (var s in Sounds)
                    Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);

                Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Notification, self.Owner.Faction.InternalName);

                var init = new TypeDictionary
                {
                    new LocationInit(self.Location + Offset),
                    new OwnerInit(self.Owner),
                    new FacingInit(Facing),
                };

                if (SkipMakeAnims)
                    init.Add(new SkipMakeAnimsInit());

                if (Faction != null)
                    init.Add(new FactionInit(Faction));

                var health = self.TraitOrDefault<Health>();
                if (health != null)
                {
                    var newHP = ForceHealthPercentage > 0 ? ForceHealthPercentage : (health.HP * 100) / health.MaxHP;
                    init.Add(new HealthInit(newHP));
                }

                var cargo = self.TraitOrDefault<Cargo>();
                if (cargo != null)
                    init.Add(new RuntimeCargoInit(cargo.Passengers.ToArray()));

                var a = w.CreateActor(ToActor, init);
                foreach (var nt in self.TraitsImplementing<INotifyTransform>())
                    nt.AfterTransform(a);

                if (selected)
                    w.Selection.Add(w, a);
                if (controlgroup.HasValue)
                    w.Selection.AddToControlGroup(a, controlgroup.Value);
            });

            return this;
        }