Пример #1
0
 public virtual void Queue( Activity activity )
 {
     if( NextActivity != null )
         NextActivity.Queue( activity );
     else
         NextActivity = activity;
 }
Пример #2
0
        public override Activity Tick(Actor self)
        {
            if (!target.IsValidFor(self))
                Cancel(self);

            var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
            if (limitedAmmo != null && !limitedAmmo.HasAmmo())
                Cancel(self);

            var attack = self.TraitOrDefault<AttackPlane>();
            if (attack != null)
                attack.DoAttack(self, target);

            if (inner == null)
            {
                if (IsCanceled)
                    return NextActivity;

                inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(50));
            }

            inner = Util.RunActivity(self, inner);

            return this;
        }
Пример #3
0
		public override Activity Tick(Actor self)
		{
			var targetIsValid = target.IsValidFor(self);

			// Inner move order has completed.
			if (inner == null)
			{
				// We are done here if the order was cancelled for any
				// reason except the target moving.
				if (IsCanceled || !repath || !targetIsValid)
					return NextActivity;

				// Target has moved, and MoveAdjacentTo is still valid.
				inner = mobile.MoveTo(() => CalculatePathToTarget(self));
				repath = false;
			}

			if (targetIsValid)
			{
				// Check if the target has moved
				var oldTargetPosition = targetPosition;
				targetPosition = self.World.Map.CellContaining(target.CenterPosition);

				var shouldStop = ShouldStop(self, oldTargetPosition);
				if (shouldStop || (!repath && ShouldRepath(self, oldTargetPosition)))
				{
					// Finish moving into the next cell and then repath.
					if (inner != null)
						inner.Cancel(self);

					repath = !shouldStop;
				}
			}
			else
			{
				// Target became invalid. Move to its last known position.
				target = Target.FromCell(self.World, targetPosition);
			}

			// Ticks the inner move activity to actually move the actor.
			inner = Util.RunActivity(self, inner);

			return this;
		}
Пример #4
0
 public Enter(Actor target, Activity inner)
 {
     this.target = Target.FromActor(target);
     this.inner = inner;
 }
Пример #5
0
            public override Activity Tick( Actor self )
            {
                if (autoTarget != null && --scanTicks <= 0)
                {
                    autoTarget.ScanAndAttack(self);
                    scanTicks = ScanInterval;
                }

                if( inner == null )
                    return NextActivity;

                inner = Util.RunActivity( self, inner );

                return this;
            }
Пример #6
0
 public AttackMoveActivity( Actor self, Activity inner )
 {
     this.inner = inner;
     this.autoTarget = self.TraitOrDefault<AutoTarget>();
 }
Пример #7
0
            public override Activity Tick( Actor self )
            {
                if (--scanTicks <= 0)
                {
                    self.Trait<AutoTarget>().ScanAndAttack(self, true);
                    scanTicks = ScanInterval;
                }

                if( inner == null )
                    return NextActivity;

                inner = Util.RunActivity( self, inner );

                return this;
            }
Пример #8
0
 public AttackMoveActivity( Activity inner )
 {
     this.inner = inner;
 }
Пример #9
0
        public override Activity Tick(Actor self)
        {
            var targetIsValid = target.IsValidFor(self);

            // Inner move order has completed.
            if (inner == null)
            {
                // We are done here if the order was cancelled for any
                // reason except the target moving.
                if (IsCanceled || !repath || !targetIsValid)
                    return NextActivity;

                // Target has moved, and MoveAdjacentTo is still valid.
                UpdateInnerPath(self);
                repath = false;
            }

            if (targetIsValid)
            {
                // Check if the target has moved
                var oldPosition = targetPosition;
                targetPosition = target.CenterPosition.ToCPos();
                if (!repath && targetPosition != oldPosition)
                {
                    // Finish moving into the next cell and then repath.
                    if (inner != null)
                        inner.Cancel(self);

                    repath = true;
                }
            }
            else
            {
                // Target became invalid. Cancel the inner order,
                // and then wait for it to move into the next cell
                // before finishing this order (handled above).
                inner.Cancel(self);
            }

            // Ticks the inner move activity to actually move the actor.
            inner = Util.RunActivity(self, inner);

            return this;
        }
Пример #10
0
        void UpdateInnerPath(Actor self)
        {
            var targetCells = Util.AdjacentCells(target);
            var searchCells = new List<CPos>();
            var loc = self.Location;

            foreach (var cell in targetCells)
                if (mobile.CanEnterCell(cell) && (domainIndex == null || domainIndex.IsPassable(loc, cell, movementClass)))
                    searchCells.Add(cell);

            if (searchCells.Any())
            {
                var ps1 = new PathSearch(self.World, mobile.Info, self)
                {
                    checkForBlocked = true,
                    heuristic = location => 0,
                    inReverse = true
                };

                foreach (var cell in searchCells)
                    ps1.AddInitialCell(cell);

                ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell);
                var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, targetPosition, true);
                var ret = pathFinder.FindBidiPath(ps1, ps2);

                inner = mobile.MoveTo(() => ret);
            }
        }