Esempio n. 1
0
        /// <summary>
        /// Applies the requested animal assignment data, cooking animals
        /// for food in the process
        /// </summary>
        /// <param name="player"></param>
        /// <param name="data"></param>
        public static void AssignAnimals(AgricolaPlayer player, AnimalCacheActionData data, List <GameActionNotice> resultingNotices)
        {
            player.AssignAnimals(data.Assignments);

            var cooking = false;

            foreach (var count in data.Cook.Values)
            {
                if (count > 0)
                {
                    cooking = true;
                    break;
                }
            }

            var freedAnimalsPredicates = new List <INoticePredicate>();

            foreach (var animal in data.Free.Keys)
            {
                if (data.Free[animal] > 0)
                {
                    freedAnimalsPredicates.Add(new ResourceCache((Resource)animal, data.Free[animal]));
                }
            }
            if (freedAnimalsPredicates.Count > 0)
            {
                resultingNotices.Add(new GameActionNotice(player.Name, NoticeVerb.FreeAnimals.ToString(), freedAnimalsPredicates));
            }


            if (cooking)
            {
                var conversions            = Curator.GetHarvestFoodValues(player);
                var cookedAnimalPredicates = new List <INoticePredicate>();
                foreach (var animal in data.Cook.Keys)
                {
                    if (data.Cook[animal] > 0)
                    {
                        var definition  = conversions.Where(x => x.InType.ToString() == animal.ToString()).OrderByDescending(x => x.OutAmount).First();
                        var inputCache  = new ResourceCache((Resource)animal, data.Cook[animal]);
                        var outputCache = new ResourceCache(Resource.Food, definition.OutAmount * data.Cook[animal]);
                        player.AddResource(outputCache);
                        cookedAnimalPredicates.Add(new ConversionPredicate(inputCache, outputCache));
                    }
                }
                if (cookedAnimalPredicates.Count > 0)
                {
                    resultingNotices.Add(new GameActionNotice(player.Name, NoticeVerb.Converted.ToString(), cookedAnimalPredicates));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Ensures that the requested animal assignment data is valid.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="data"></param>
        /// <param name="newAnimals"></param>
        /// <returns></returns>
        public static bool CanAssignAnimals(AgricolaPlayer player, AnimalCacheActionData data, AnimalManager manager, Dictionary <AnimalResource, int> newAnimals)
        {
            var requestedTotals = AnimalHousingData.GetTotals(data.Assignments);

            requestedTotals[AnimalResource.Sheep]  += data.Free[AnimalResource.Sheep] + data.Cook[AnimalResource.Sheep];
            requestedTotals[AnimalResource.Boar]   += data.Free[AnimalResource.Boar] + data.Cook[AnimalResource.Boar];
            requestedTotals[AnimalResource.Cattle] += data.Free[AnimalResource.Cattle] + data.Cook[AnimalResource.Cattle];

            var currentSheep = player.Farmyard.AnimalCount(AnimalResource.Sheep);

            // If the incoming total of animals in all assignments is different then the currently
            // assigned total animals plus the new animals being taken from the cache return false.
            if (requestedTotals[AnimalResource.Sheep] != currentSheep + (newAnimals != null && newAnimals.ContainsKey(AnimalResource.Sheep) ? newAnimals[AnimalResource.Sheep] : 0) ||
                requestedTotals[AnimalResource.Boar] != player.Farmyard.AnimalCount(AnimalResource.Boar) + (newAnimals != null && newAnimals.ContainsKey(AnimalResource.Boar) ? newAnimals[AnimalResource.Boar] : 0) ||
                requestedTotals[AnimalResource.Cattle] != player.Farmyard.AnimalCount(AnimalResource.Cattle) + (newAnimals != null && newAnimals.ContainsKey(AnimalResource.Cattle) ? newAnimals[AnimalResource.Cattle] : 0))
            {
                return(false);
            }

            if (!manager.AreAssignmentsValid(data.Assignments))
            {
                return(false);
            }

            var cooking = false;

            foreach (var count in data.Cook.Values)
            {
                if (count > 0)
                {
                    cooking = true;
                }
            }

            if (cooking && !Curator.CanCook(player))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
 public void TakeAssignAnimalsAction(int actionId, AnimalCacheActionData data)
 {
     TakeAction(actionId, data);
 }
Esempio n. 4
0
 /// <summary>
 /// Ensures that the requested animal assignment data is valid.
 /// </summary>
 /// <param name="player"></param>
 /// <param name="data"></param>
 /// <param name="newAnimals"></param>
 /// <returns></returns>
 public static bool CanAssignAnimals(AgricolaPlayer player, AnimalCacheActionData data, Dictionary <AnimalResource, int> newAnimals)
 {
     return(ActionService.CanAssignAnimals(player, data, player.Farmyard.AnimalManager, newAnimals));
 }