public override void OnExecute(AgricolaPlayer player, List <GameActionNotice> resultingNotices)
            {
                int owned = 0;

                if (this.RequiredType.IsAnimal())
                {
                    owned = player.Farmyard.AnimalCount((AnimalResource)this.RequiredType);
                }
                else
                {
                    owned = player.GetResource(this.RequiredType);
                }

                if (!this.Repeat)
                {
                    if (owned >= this.RequiredCount)
                    {
                        ActionService.AssignResource(player, new ResourceCache(this.Type, this.Count), resultingNotices);
                    }
                }
                else
                {
                    var count = (int)(owned / this.RequiredCount);
                    ActionService.AssignResource(player, new ResourceCache(this.Type, this.Count * count), resultingNotices);
                }
            }
        public override int GetPoints(AgricolaPlayer player, out string title)
        {
            foreach (var option in options)
            {
                var count = player.GetResource(option.Resource);
                if (option.Resource == Resource.Vegetables || option.Resource == Resource.Grain)
                {
                    count += player.Farmyard.PlantedResourceCount(option.Resource);
                }


                if (option.RequiredCount <= count)
                {
                    title = option.RequiredCount + " " + option.Resource.ToString();
                    return(option.Points);
                }
            }
            title = null;
            return(0);
        }
Beispiel #3
0
        /// <summary>
        /// Checks if a player has the ability to cook any goods
        /// </summary>
        /// <param name="player"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static bool CanCook(AgricolaPlayer player, ResourceConversionData[] data)
        {
            var availableConversions = Curator.GetAnytimeResourceConversions(player);

            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);
                }

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

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

                if (Enum.IsDefined(typeof(AnimalResource), conversionDefinition.InType.ToString()))
                {
                    var animalType = (AnimalResource)(Enum.Parse(typeof(AnimalResource), conversionDefinition.InType.ToString()));
                    if (player.Farmyard.AnimalManager.GetAnimalCount(animalType) < conversion.Count)
                    {
                        return(false);
                    }
                }
                else if (player.GetResource(conversionDefinition.InType) < conversion.Count)
                {
                    return(false);
                }
            }

            return(true);
        }