Exemplo n.º 1
0
        public static void Cook(AgricolaPlayer player, ImmutableList <GameEventTrigger> eventTriggers, ResourceConversionData[] data, List <GameActionNotice> resultingNotices)
        {
            var availableConversions = Curator.GetAnytimeResourceConversions(player);

            var trigger = new ResourceConversionTrigger();

            foreach (var conversion in data)
            {
                var conversionDefinition = availableConversions.Where(x => x.Id == conversion.Id &&
                                                                      x.InType == conversion.InType && x.InAmount == conversion.InAmount &&
                                                                      x.OutType == conversion.OutType).OrderByDescending(a => a.OutAmount).FirstOrDefault();


                if (!conversionDefinition.InType.IsAnimal())
                {
                    var inputCache  = new ResourceCache(conversionDefinition.InType, -conversion.Count);
                    var outputCache = new ResourceCache(conversionDefinition.OutType, (conversion.Count / conversionDefinition.InAmount) * conversionDefinition.OutAmount);
                    // Deduct the cost
                    player.AddResource(inputCache);

                    if (!conversionDefinition.OutType.IsAnimal())
                    {
                        // Add the converted resources
                        player.AddResource(outputCache);
                    }
                    else
                    {
                        ((AgricolaGame)player.Game).AddInterrupt(new AssignAnimalsAction(player, (AnimalResource)conversionDefinition.OutType, conversionDefinition.OutAmount, resultingNotices));
                    }

                    inputCache = new ResourceCache(inputCache.Type, inputCache.Count * -1);
                    resultingNotices.Add(new GameActionNotice(player.Name, NoticeVerb.Converted.ToString(), new ConversionPredicate(inputCache, outputCache)));

                    trigger.AddConvertedResources(ResourcesConvertedData.FromResourceConversion(conversionDefinition, conversion.Count / conversionDefinition.InAmount));
                }
            }

            ProcessEventTrigger(player, trigger, resultingNotices);

            CheckTriggers(player, eventTriggers, resultingNotices);
        }
Exemplo n.º 2
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);
        }