Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the player can complete their harvest with the specified information
        /// </summary>
        /// <param name="player"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool CanCompleteHarvest(AgricolaPlayer player, HarvestData data)
        {
            if (!player.CanFeedFamily(data.FeedResources))
            {
                return(false);
            }

            var sheepUsedAsFood  = 0;
            var boarUsedAsFood   = 0;
            var cattleUsedAsFood = 0;

            var availableConversions = Curator.GetHarvestFoodValues(player);

            foreach (var conversion in data.FeedResources)
            {
                var conversionDefinition = availableConversions.FirstOrDefault(x => x.Id == conversion.Id &&
                                                                               x.InType == conversion.InType && x.InAmount == conversion.InAmount &&
                                                                               x.OutType == conversion.OutType);
                if (conversionDefinition == null)
                {
                    return(false);
                }

                if (conversionDefinition.InLimit.HasValue && conversionDefinition.InLimit.Value < conversion.Count / conversion.InAmount)
                {
                    return(false);
                }

                if (conversionDefinition.InType == Resource.Sheep)
                {
                    sheepUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
                else if (conversionDefinition.InType == Resource.Boar)
                {
                    boarUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
                else if (conversionDefinition.InType == Resource.Cattle)
                {
                    cattleUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
            }

            // Calculate how many animals are left over after feeding during harvest
            // We aren't concerned with cooked animals yet, as the only animals that can be passed in as cooked
            // are the baby animals
            var sheepAfterFeeding  = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Sheep) - sheepUsedAsFood;
            var boarAfterFeeding   = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Boar) - boarUsedAsFood;
            var cattleAfterFeeding = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Cattle) - cattleUsedAsFood;

            data.AnimalData.Free[AnimalResource.Sheep]  += sheepUsedAsFood;
            data.AnimalData.Free[AnimalResource.Boar]   += boarUsedAsFood;
            data.AnimalData.Free[AnimalResource.Cattle] += cattleUsedAsFood;

            // Figure out which animals will breed
            var newAnimals = new Dictionary <AnimalResource, int>();

            newAnimals[AnimalResource.Sheep]  = sheepAfterFeeding >= 2 ? 1 : 0;
            newAnimals[AnimalResource.Boar]   = boarAfterFeeding >= 2 ? 1 : 0;
            newAnimals[AnimalResource.Cattle] = cattleAfterFeeding >= 2 ? 1 : 0;

            if (!ActionService.CanAssignAnimals(player, data.AnimalData, newAnimals))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns true if the user has the ability to fence in any pastures given
 /// the number of fences remaining.
 ///
 /// This does not factor affording costs in.
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public static bool CanPlaceFences(AgricolaPlayer player)
 {
     return(player.Farmyard.EmptyLocations.Count > 0 && Curator.HasFencesLeft(player) && player.Farmyard.CanFencePasture());
 }