void EndCapture(Actor self)
 {
     if (target.Type == TargetType.Actor && capturable.CaptureInProgress)
     {
         capturable.EndCapture();
     }
     if (capturingToken != ConditionManager.InvalidConditionToken)
     {
         capturingToken = conditionManager.RevokeCondition(self, capturingToken);
     }
 }
Beispiel #2
0
        public override Activity Tick(Actor self)
        {
            if (target.Type != TargetType.Actor)
            {
                return(NextActivity);
            }

            if (IsCanceled || !self.IsInWorld || self.IsDead || !target.IsValidFor(self))
            {
                if (capturable.CaptureInProgress)
                {
                    capturable.EndCapture();
                }

                return(NextActivity);
            }

            var nearest = target.Actor.OccupiesSpace.NearestCellTo(mobile.ToCell);

            if ((nearest - mobile.ToCell).LengthSquared > 2)
            {
                return(ActivityUtils.SequenceActivities(new MoveAdjacentTo(self, target), this));
            }

            if (!capturable.CaptureInProgress)
            {
                capturable.BeginCapture(self);
            }
            else
            {
                if (capturable.Captor != self)
                {
                    return(NextActivity);
                }

                if (capturable.CaptureProgressTime % 25 == 0)
                {
                    self.World.Add(new FlashTarget(target.Actor, self.Owner));
                    self.World.Add(new FlashTarget(self));
                }

                if (capturable.CaptureProgressTime == capturable.Info.CaptureCompleteTime * 25)
                {
                    self.World.AddFrameEndTask(w =>
                    {
                        if (target.Actor.IsDead)
                        {
                            return;
                        }

                        var oldOwner = target.Actor.Owner;

                        target.Actor.ChangeOwner(self.Owner);

                        foreach (var t in target.Actor.TraitsImplementing <INotifyCapture>())
                        {
                            t.OnCapture(target.Actor, self, oldOwner, self.Owner);
                        }

                        capturable.EndCapture();

                        if (capturesInfo != null && capturesInfo.ConsumeActor)
                        {
                            self.Dispose();
                        }
                    });
                }
            }

            return(this);
        }