コード例 #1
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);
        }
コード例 #2
0
 /// <summary>
 /// Adds one of a resource to the cache
 /// </summary>
 /// <param name="resource"></param>
 public State AddResource(Resource resource)
 {
     PersonalSupply = PersonalSupply.AddResource(resource, 1);
     return(State);
 }
コード例 #3
0
 /// <summary>
 /// Removes one of the resource from the personal supply
 /// </summary>
 /// <param name="resource"></param>
 /// <param name="count"></param>
 public State RemoveResource(Resource resource, Int32 count)
 {
     PersonalSupply = PersonalSupply.AddResource(resource, -count);
     return(State);
 }
コード例 #4
0
 /// <summary>
 /// Gets the quantity of a resource
 /// </summary>
 /// <param name="resource"></param>
 /// <returns></returns>
 public int GetResource(Resource resource)
 {
     return(PersonalSupply.GetResource(resource));
 }