Ejemplo n.º 1
0
        public override void DecideWhatToDo()
        {
            // don't replace, we want to keep this move attack at the base
            bool isAttacking = findTargetGoal.TryAssignAttack(replace: false);

            if (isAttacking)
            {
                walkGoal = null;
            }
            if (!isAttacking)
            {
                bool isWalking = Owner.ImmediateGoal?.Path?.Count > 0;

                if (!isWalking)
                {
                    if (walkGoal == null)
                    {
                        walkGoal                = new WalkToHighLevelGoal();
                        walkGoal.Owner          = Owner;
                        walkGoal.TargetPosition =
                            new Microsoft.Xna.Framework.Vector3(TargetX, TargetY, 0);

                        walkGoal.DecideWhatToDo();
                    }
                    else
                    {
                        hasReachedTarget = true;
                    }
                }
            }
        }
        public override void DecideWhatToDo()
        {
            if (IsInRangeToReturnResource())
            {
                // We're close enough to our target return destination: unload!

                StopMoving();

                // If we are trying to return a resource, but the building is a smoldering pile of ashes, stop walking.
                bool areWeReturningResourcesToDestroyedBuilding = Owner.HasResourceToReturn && ResourceReturnBuilding.CurrentHealth <= 0;
                if (areWeReturningResourcesToDestroyedBuilding)
                {
                    currentWalkGoal          = null;
                    shouldWeGiveUpCollecting = true;
                    return;
                }

                var screen = FlatRedBall.Screens.ScreenManager.CurrentScreen as GameScreen;

                // Increment appropriate resource.
                switch (Owner.ResourceTypeToReturn)
                {
                case ResourceType.Gold:
                    screen.Gold += Owner.UnitData.ResourceHarvestAmount;
                    break;

                case ResourceType.Lumber:
                    screen.Lumber += Owner.UnitData.ResourceHarvestAmount;
                    break;

                case ResourceType.Stone:
                    screen.Stone += Owner.UnitData.ResourceHarvestAmount;
                    break;
                }
                //Try to play the collect sound.
                screen.TryPlayResourceCollectSound(Owner.ResourceTypeToReturn.Value, Owner.Position);

                // Update UI
                screen.UpdateResourceDisplay();

                ClearResourceState();
                // Default to !isWalking later to set up return-to-resource trip.
            }
            else if (IsInRangeToCollect())
            {
                // We're close enough to our target resource: harvest!

                StopMoving();

                var screen = FlatRedBall.Screens.ScreenManager.CurrentScreen as GameScreen;

                // Delay resource pick-up once arrived.
                if (arrivedAtResourceTime == 0)
                {
                    arrivedAtResourceTime = screen.PauseAdjustedCurrentTime;
                }

                //Try to play gather sfx
                Unit.TryToPlayResourceGatheringSfx(Owner.Position, this.TargetResourceType);

                bool canCollect = screen.PauseAdjustedSecondsSince(arrivedAtResourceTime) >= CollectFrequencyInSeconds;

                if (canCollect)
                {
                    Owner.SetResourceToReturn(TargetResourceType);
                    arrivedAtResourceTime = 0;
                    // Default to !isWalking later to set up return-to-resource trip.
                }
            }
            else
            {
                bool isWalking = Owner?.ImmediateGoal?.Path?.Count > 0;
                if (!isWalking)
                {
                    if (currentWalkGoal == null)
                    {
                        // Do we already have a resource we should be returning but aren't currently gathering?
                        if (Owner.HasResourceToReturn)
                        {
                            currentWalkGoal = GetResourceReturnWalkGoal();
                            if (currentWalkGoal == null)
                            {
                                // Couldn't get a walk goal back from resource collection. Time to call it quits here.
                                shouldWeGiveUpCollecting = true;
                            }
                            else
                            {
                                // Start hiking, unit!
                                currentWalkGoal.DecideWhatToDo();
                            }
                        }
                        else
                        {
                            Vector3 pointSlightlySkewedTowardOwner = DeterminePositionWithinTileSlightlyCloserToOwner(SingleTargetResourceTileCenter, SingleTargetResourceTile.Width);
                            currentWalkGoal                = new WalkToHighLevelGoal();
                            currentWalkGoal.Owner          = Owner;
                            currentWalkGoal.TargetPosition = pointSlightlySkewedTowardOwner;
                            currentWalkGoal.ForceAttemptToGetToExactTarget = true;
                            currentWalkGoal.DecideWhatToDo();
                        }
                    }
                }
            }
        }
        public override void DecideWhatToDo()
        {
            if (IsInRangeToReturnResource())
            {
                // We're close enough to our target return destination: unload!
                StopMoving();

                var screen = FlatRedBall.Screens.ScreenManager.CurrentScreen as GameScreen;

                // If we are trying to return a resource, but the building is a smoldering pile of ashes, stop walking.
                bool areWeReturningResourcesToDestroyedBuilding = Owner.HasResourceToReturn && ResourceReturnBuilding.CurrentHealth <= 0;
                if (areWeReturningResourcesToDestroyedBuilding)
                {
                    currentWalkGoal         = null;
                    shouldWeGiveUpReturning = true;
                    return;
                }

                // Increment appropriate resource.
                switch (TargetResourceType)
                {
                case ResourceType.Gold:
                    screen.Gold += Owner.UnitData.ResourceHarvestAmount;
                    break;

                case ResourceType.Lumber:
                    screen.Lumber += Owner.UnitData.ResourceHarvestAmount;
                    break;

                case ResourceType.Stone:
                    screen.Stone += Owner.UnitData.ResourceHarvestAmount;
                    break;
                }
                //Try to play the collect sound.
                screen.TryPlayResourceCollectSound(TargetResourceType, Owner.Position);

                // Update UI
                screen.UpdateResourceDisplay();

                ClearResourceState();
                shouldWeGiveUpReturning = true;
            }
            else
            {
                bool isWalking = Owner?.ImmediateGoal?.Path?.Count > 0;
                if (!isWalking)
                {
                    if (currentWalkGoal == null)
                    {
                        currentWalkGoal = GetResourceReturnWalkGoal();
                        if (currentWalkGoal == null)
                        {
                            // Couldn't get a walk goal back from resource collection. Time to call it quits here.
                            shouldWeGiveUpReturning = true;
                        }
                        else
                        {
                            // Start hiking, unit!
                            currentWalkGoal.DecideWhatToDo();
                        }
                    }
                }
            }
        }