Пример #1
0
        /// <summary>
        /// Feeds the players family with the given resources.
        /// Any shortage adds begging cards to the player.
        /// </summary>
        /// <param name="data">The list of resources with which to feed your family.</param>
        /// <returns>The number of new begger cards</returns>
        public State FeedFamily(ResourceConversionData[] data, List <INoticePredicate> notices, out int begTotal)
        {
            var availableConversions = Curator.GetHarvestFoodValues(this);
            var foodValue            = 0;
            var foodNeeded           = FamilySize * 2 - NumBabies;

            begTotal = 0;
            foreach (var conversion in data)
            {
                var conversionDefinition = availableConversions.FirstOrDefault(x => x.Id == conversion.Id &&
                                                                               x.InType == conversion.InType && x.InAmount == conversion.InAmount &&
                                                                               x.OutType == conversion.OutType);
                if (conversionDefinition.OutType == Resource.Food)
                {
                    foodValue += (conversion.Count / conversionDefinition.InAmount) * conversionDefinition.OutAmount;

                    notices.Add(new ResourceCache(conversionDefinition.InType, conversion.Count));

                    if (!Enum.IsDefined(typeof(AnimalResource), conversionDefinition.InType.ToString()))
                    {
                        this.PersonalSupply = this.PersonalSupply.AddResource(conversionDefinition.InType, -conversion.Count);
                    }
                }
                else
                {
                    if (!Enum.IsDefined(typeof(AnimalResource), conversionDefinition.InType.ToString()))
                    {
                        this.PersonalSupply = this.PersonalSupply.AddResource(conversionDefinition.InType, -conversion.Count);
                    }

                    // This does not handle what happens if an item can be converted into animals.
                    // Not sure this actually exists in the game.
                    this.PersonalSupply = this.PersonalSupply.AddResource(conversionDefinition.OutType, (conversion.Count / conversionDefinition.InAmount) * conversionDefinition.OutAmount);
                }
            }

            if (foodValue < foodNeeded)
            {
                begTotal      = foodNeeded - foodValue;
                BeggingCards += begTotal;
            }

            var remainder = foodValue - foodNeeded;

            if (remainder > 0)
            {
                this.PersonalSupply = this.PersonalSupply.AddResource(Resource.Food, remainder);
            }

            Harvesting = false;
            return(State);
        }
Пример #2
0
        public bool CanFeedFamily(ResourceConversionData[] data)
        {
            var availableConversions = Curator.GetHarvestFoodValues(this);

            foreach (var conversion in data)
            {
                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);
                }

                // Invalid input amount
                if (conversion.Count % conversionDefinition.InAmount != 0)
                {
                    return(false);
                }

                if (Enum.IsDefined(typeof(AnimalResource), conversionDefinition.InType.ToString()))
                {
                    var owned = this.Farmyard.AnimalCount((AnimalResource)Enum.Parse(typeof(AnimalResource), conversionDefinition.InType.ToString()));
                    if (owned < conversion.Count)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (PersonalSupply.GetResource(conversionDefinition.InType) < conversion.Count)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #3
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);
        }