Exemplo n.º 1
0
        /// <summary>
        /// Checks if the fence data is valid.
        /// </summary>
        /// <param name="player">The player building the fences</param>
        /// <param name="data">Data defining the fences to be built</param>
        /// <param name="pastures">A list of pastures resulting from the fences built</param>
        /// <param name="costs">The costs of the requested fences</param>
        /// <returns>True if the fence data is valid</returns>
        public static bool CanBuildFences(AgricolaPlayer player, int actionId, BuildFencesActionData data, out List <int[]> pastures, out ResourceCache[] costs)
        {
            var fenceData = (BuildFencesActionData)data;

            pastures = null;
            if (!Curator.CanAffordFences(player, actionId, fenceData.Fences.Length, out costs))
            {
                return(false);
            }

            var fenceValidator = new FencePlacementValidator(fenceData.Fences, player.Farmyard, out pastures);

            if (!fenceValidator.Valid || !player.Farmyard.IsValidPastureLocations(pastures))
            {
                return(false);
            }

            var tempAnimalManager = new AnimalManager();

            tempAnimalManager = tempAnimalManager.Update(player.Farmyard.Grid, pastures.ToImmutableArray(), data.AnimalData.Assignments);
            if (!ActionService.CanAssignAnimals(player, (AnimalCacheActionData)fenceData.AnimalData, tempAnimalManager, null))
            {
                return(false);
            }

            return(true);
        }