/// <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); }
public void TakeFencePastureAction(int actionId, BuildFencesActionData data) { TakeAction(actionId, data); }
public static void BuildFences(AgricolaPlayer player, ImmutableList <GameEventTrigger> eventTriggers, List <GameActionNotice> resultingNotices, BuildFencesActionData data, ImmutableArray <int[]> pastures) { var oldPastureCount = player.Farmyard.Pastures.Length; BuildFencesTrigger trigger = null; if (data != null) { if (data.Fences != null) { player.AddFences(data.Fences); if (resultingNotices != null) { var predicates = new List <INoticePredicate>(); predicates.Add(new BuildPredicate(data.Fences.Length, Buildable.Fence)); predicates.Add(new BuildPredicate(pastures.Length - oldPastureCount, Buildable.Pasture)); resultingNotices.Add(new GameActionNotice(player.Name, NoticeVerb.Build.ToString(), predicates)); } player.SetPastures(pastures); if (data.Fences.Length > 0) { trigger = new BuildFencesTrigger(data.Fences.Length); } } if (data.AnimalData != null) { player.UpdateAnimalManager(data.AnimalData.Assignments); if (data.AnimalData != null) { ActionService.AssignAnimals(player, data.AnimalData, resultingNotices); } } if (trigger != null) { ProcessEventTrigger(player, trigger, resultingNotices); } CheckTriggers(player, eventTriggers, resultingNotices); } }