Ejemplo n.º 1
0
        public override Activity Tick(Actor self)
        {
            turnActivity = moveActivity = null;
            attackStatus = AttackStatus.UnableToAttack;

            foreach (var attack in attackTraits.Where(x => !x.IsTraitDisabled))
            {
                var status = TickAttack(self, attack);
                attack.IsAniming = status == AttackStatus.Attacking || status == AttackStatus.NeedsToTurn;
            }

            if (attackStatus.HasFlag(AttackStatus.Attacking))
            {
                return(this);
            }

            if (attackStatus.HasFlag(AttackStatus.NeedsToTurn))
            {
                return(turnActivity);
            }

            if (attackStatus.HasFlag(AttackStatus.NeedsToMove))
            {
                return(moveActivity);
            }

            return(NextActivity);
        }
Ejemplo n.º 2
0
        public override Activity Tick(Actor self)
        {
            turnActivity = moveActivity = null;
            attackStatus = AttackStatus.UnableToAttack;

            foreach (var attack in attackTraits.Where(x => !x.IsTraitDisabled))
            {
                var activity = InnerTick(self, attack);
                attack.IsAttacking = activity == this;
            }

            if (attackStatus.HasFlag(AttackStatus.Attacking))
                return this;

            if (attackStatus.HasFlag(AttackStatus.NeedsToTurn))
                return turnActivity;

            if (attackStatus.HasFlag(AttackStatus.NeedsToMove))
                return moveActivity;

            return NextActivity;
        }
Ejemplo n.º 3
0
        public override Activity Tick(Actor self)
        {
            if (ChildActivity != null)
            {
                ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
                return(this);
            }

            if (IsCanceling)
            {
                return(NextActivity);
            }

            bool targetIsHiddenActor;

            target = RecalculateTarget(self, out targetIsHiddenActor);
            if (!targetIsHiddenActor && target.Type == TargetType.Actor)
            {
                lastVisibleTarget       = Target.FromTargetPositions(target);
                lastVisibleMaximumRange = attackTraits.Where(x => !x.IsTraitDisabled)
                                          .Min(x => x.GetMaximumRangeVersusTarget(target));

                lastVisibleOwner       = target.Actor.Owner;
                lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes();
            }

            var oldUseLastVisibleTarget = useLastVisibleTarget;

            useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);

            // If we are ticking again after previously sequencing a MoveWithRange then that move must have completed
            // Either we are in range and can see the target, or we've lost track of it and should give up
            if (wasMovingWithinRange && targetIsHiddenActor)
            {
                return(NextActivity);
            }

            // Update target lines if required
            if (useLastVisibleTarget != oldUseLastVisibleTarget)
            {
                self.SetTargetLine(useLastVisibleTarget ? lastVisibleTarget : target, Color.Red, false);
            }

            // Target is hidden or dead, and we don't have a fallback position to move towards
            if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
            {
                return(NextActivity);
            }

            wasMovingWithinRange = false;
            var pos         = self.CenterPosition;
            var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;

            // We don't know where the target actually is, so move to where we last saw it
            if (useLastVisibleTarget)
            {
                // We've reached the assumed position but it is not there or we can't move any further - give up
                if (checkTarget.IsInRange(pos, lastVisibleMaximumRange) || move == null || lastVisibleMaximumRange == WDist.Zero)
                {
                    return(NextActivity);
                }

                // Move towards the last known position
                wasMovingWithinRange = true;
                QueueChild(self, move.MoveWithinRange(target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red), true);
                return(this);
            }

            attackStatus = AttackStatus.UnableToAttack;

            foreach (var attack in attackTraits.Where(x => !x.IsTraitDisabled))
            {
                var status = TickAttack(self, attack);
                attack.IsAiming = status == AttackStatus.Attacking || status == AttackStatus.NeedsToTurn;
            }

            if (attackStatus.HasFlag(AttackStatus.NeedsToMove))
            {
                wasMovingWithinRange = true;
            }

            if (attackStatus >= AttackStatus.NeedsToTurn)
            {
                return(this);
            }

            return(NextActivity);
        }