예제 #1
0
        public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)
        {
            if (IsTraitDisabled)
            {
                return(false);
            }

            // Some things appear chronoshiftable, but instead they just die.
            if (Info.ExplodeInstead)
            {
                self.World.AddFrameEndTask(w =>
                {
                    // Damage is inflicted by the chronosphere
                    if (!self.Disposed)
                    {
                        self.Kill(chronosphere, Info.DamageTypes);
                    }
                });
                return(true);
            }

            // Set up return-to-origin info
            // If this actor is already counting down to return to
            // an existing location then we shouldn't override it
            if (ReturnTicks <= 0)
            {
                Origin      = self.Location;
                ReturnTicks = duration;
            }

            this.duration     = duration;
            this.chronosphere = chronosphere;
            this.killCargo    = killCargo;

            if (Info.ExposeInfectors)
            {
                foreach (var i in self.TraitsImplementing <IRemoveInfector>())
                {
                    i.RemoveInfector(self, false);
                }
            }

            // Set up the teleport
            self.QueueActivity(false, new Teleport(chronosphere, targetLocation, null, killCargo, true, Info.ChronoshiftSound));

            // AllowImpassable was true, but we can't enter here, kill the unit.
            if (iPositionable == null || !iPositionable.CanExistInCell(targetLocation))
            {
                self.World.AddFrameEndTask(w =>
                {
                    // Damage is inflicted by the chronosphere
                    if (!self.Disposed)
                    {
                        self.Kill(chronosphere, Info.DamageTypes);
                    }
                });
                return(true);
            }

            return(true);
        }