Beispiel #1
0
        /// <summary>
        /// Returns true if the player has any cards that allow them to convert resources into food.
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public static bool CanCook(AgricolaPlayer player)
        {
            var ids = player.OwnedCardIds;

            foreach (var id in ids)
            {
                var card = ((AgricolaGame)player.Game).GetCard(id);
                if (card.ResourceConversions != null)
                {
                    foreach (var rc in card.ResourceConversions)
                    {
                        if (rc.OutType == Resource.Food)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Assigns a major improvement to a player
        /// </summary>
        /// <param name="id"></param>
        /// <param name="player"></param>
        public void AssignMajorImprovement(int id, AgricolaPlayer player)
        {
            if (!majorImprovementOwners.Keys.Contains(id))
            {
                throw new ArgumentException("Invalid major improvement id:" + id);
            }

            var oldPlayer = majorImprovementOwners[id];

            if (oldPlayer != null)
            {
                oldPlayer.RemoveMajorImprovement(id);
            }

            majorImprovementOwners = majorImprovementOwners.SetItem(id, player);
            if (player != null)
            {
                player.AddMajorImprovement(id);
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="resolvingPlayer"></param>
        /// <param name="triggeringPlayer"></param>
        /// <param name="trigger"></param>
        /// <returns></returns>
        public List <EventData> GetCardEventData(AgricolaPlayer triggeringPlayer, GameEventTrigger trigger)
        {
            var resolvingPlayer = (AgricolaPlayer)this;
            var events          = new List <EventData>();

            foreach (var card in resolvingPlayer.OwnedCards)
            {
                if (card.Events == null)
                {
                    continue;
                }

                var cardEvents = card.Events.Where(x => x.Triggers.Any(s => s.Triggered(resolvingPlayer, triggeringPlayer, trigger)));
                foreach (var cardEvent in cardEvents)
                {
                    EventData data = new EventData(trigger, cardEvent, card);
                    events.Add(data);
                }
            }

            return(events);
        }
Beispiel #4
0
        public static int CalculateSheepScore(AgricolaPlayer player)
        {
            var sheep = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Sheep);

            // 165 - yoeman farmer
            if (sheep == 0)
            {
                return(player.OwnsCard(165) ? 0 : -1);
            }
            else if (sheep < 4)
            {
                return(1);
            }
            else if (sheep < 6)
            {
                return(2);
            }
            else if (sheep < 8)
            {
                return(3);
            }
            return(4);
        }
Beispiel #5
0
        /// <summary>
        /// Returns the values of all resources at harvest time
        /// </summary>
        /// <param name="player"></param>
        /// <param name="resource"></param>
        /// <returns></returns>
        public static List <ResourceConversion> GetHarvestFoodValues(AgricolaPlayer player)
        {
            resourceConversions.Clear();
            resourceConversions.Add(new ResourceConversion(-1, Resource.Food, 1, null, Resource.Food, 1));
            resourceConversions.Add(new ResourceConversion(-2, Resource.Grain, 1, null, Resource.Food, 1));
            resourceConversions.Add(new ResourceConversion(-3, Resource.Vegetables, 1, null, Resource.Food, 1));

            var cards = player.OwnedCards;

            foreach (var card in cards)
            {
                if (card.ResourceConversions != null)
                {
                    foreach (var rc in card.ResourceConversions)
                    {
                        //updateResourceConversions(card.Id, rc.InType, rc.InAmount, rc.InLimit, rc.OutType, rc.OutAmount);
                        resourceConversions.Add(rc);
                    }
                }
            }

            return(resourceConversions);
        }
Beispiel #6
0
        private bool TakeInterruptAction(AgricolaPlayer player, Int32 actionId, GameActionData param, out IClientGameUpdate update, out List <GameActionNotice> notices)
        {
            if (player == Interrupt.Player)
            {
                var        interrupt = this.Interrupt;
                GameAction action    = interrupt;
                if (action != null)
                {
                    GameAction updatedAction;
                    if (action.TryExecute(player, param, out updatedAction))
                    {
                        this.Interrupt = null;
                        if (!CheckForInterrupt() && this.Mode == GameMode.Work)
                        {
                            if (NextActivePlayer(action.ResultingNotices))
                            {
                                update = BuildPartialUpdate(player, action);
                            }
                            else
                            {
                                update = StartNextRound(action.ResultingNotices);
                            }
                        }
                        else
                        {
                            update = BuildPartialUpdate(player, action);
                        }
                        notices = action.ResultingNotices;

                        return(true);
                    }
                }
            }
            update  = null;
            notices = null;
            return(false);
        }
Beispiel #7
0
        public bool CompleteHarvest(AgricolaPlayer player, HarvestData data, out IClientGameUpdate update, out List <GameActionNotice> notices)
        {
            if (Mode == GameMode.Harvest && player.Harvesting && CanCompleteHarvest(player, data))
            {
                var conversions = data.FeedResources;
                var feedNotice  = new List <INoticePredicate>();
                int begAmount;
                player.FeedFamily(data.FeedResources, feedNotice, out begAmount);

                notices = new List <GameActionNotice>();
                ActionService.AssignAnimals(player, data.AnimalData, notices);

                UpdateScorecards();

                if (begAmount > 0)
                {
                    feedNotice.Add(new IdPredicate(begAmount));
                }

                notices.Add(new GameActionNotice(player.Name, NoticeVerb.Fed.ToString(), feedNotice));
                if (IsHarvestComplete())
                {
                    update = StartNextRound(notices);
                }
                else
                {
                    update = new PartialGameUpdate();
                    ((PartialGameUpdate)update).AddPlayer(player);
                }
                return(true);
            }

            update  = null;
            notices = null;
            return(false);
        }
Beispiel #8
0
        /// <summary>
        /// Executes the requested anytime action id.
        /// </summary>
        /// <param name="player"></param>
        /// <param name="actionId"></param>
        /// <param name="cardId"></param>
        /// <param name="param"></param>
        /// <param name="update"></param>
        /// <param name="notices"></param>
        /// <returns></returns>
        public bool TakeAnytimeAction(AgricolaPlayer player, Int32 actionId, int cardId, GameActionData param, out IClientGameUpdate update, out List <GameActionNotice> notices)
        {
            if (player.OwnedCardIds.Contains(cardId))
            {
                var card = GetCard(cardId);
                if (card.AnytimeAction?.Id == actionId)
                {
                    var        action = card.AnytimeAction;
                    GameAction outAction;
                    if (action.TryExecute(player, param, out outAction))
                    {
                        UpdateScorecards();
                        notices = action.ResultingNotices;
                        CheckForInterrupt();

                        update = BuildPartialUpdate(player, action);
                        return(true);
                    }
                }
            }
            update  = null;
            notices = null;
            return(false);
        }
Beispiel #9
0
 private void CalculateCattleScore(AgricolaPlayer player)
 {
     Cattle = Curator.CalculateCattleScore(player);
 }
Beispiel #10
0
 private void CalculateBoarScore(AgricolaPlayer player)
 {
     Boar = Curator.CalculateBoarScore(player);
 }
Beispiel #11
0
 private void CalculateSheepScore(AgricolaPlayer player)
 {
     Sheep = Curator.CalculateSheepScore(player);
 }
Beispiel #12
0
 private void CalculateVegetablesScore(AgricolaPlayer player)
 {
     Vegetables = Curator.CalculateVegetablesScore(player);
 }
Beispiel #13
0
 private void CalculateGrainScore(AgricolaPlayer player)
 {
     Grain = Curator.CalculateGrainScore(player);
 }
Beispiel #14
0
 private void CalculatePasturesScore(AgricolaPlayer player)
 {
     Pastures = Curator.CalculatePasturesScore(player);
 }
Beispiel #15
0
 public static bool HasFencesLeft(AgricolaPlayer player)
 {
     return(Farmyard.MAX_FENCES - player.Farmyard.Fences.Count > 0);
 }
Beispiel #16
0
 private void CalculateBeggingScore(AgricolaPlayer player)
 {
     Begging = Curator.CalculateBeggingScore(player);
 }
Beispiel #17
0
 private void CalculateRoomsScore(AgricolaPlayer player)
 {
     Rooms = Curator.CalculateRoomsScore(player);
 }
Beispiel #18
0
 private void CalculateUnusedSpaceScore(AgricolaPlayer player)
 {
     UnusedSpace = Curator.CalculateUnusedSpaceScore(player);
 }
Beispiel #19
0
        /// <summary>
        /// Checks if the player can complete their harvest with the specified information
        /// </summary>
        /// <param name="player"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool CanCompleteHarvest(AgricolaPlayer player, HarvestData data)
        {
            if (!player.CanFeedFamily(data.FeedResources))
            {
                return(false);
            }

            var sheepUsedAsFood  = 0;
            var boarUsedAsFood   = 0;
            var cattleUsedAsFood = 0;

            var availableConversions = Curator.GetHarvestFoodValues(player);

            foreach (var conversion in data.FeedResources)
            {
                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 (conversionDefinition.InType == Resource.Sheep)
                {
                    sheepUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
                else if (conversionDefinition.InType == Resource.Boar)
                {
                    boarUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
                else if (conversionDefinition.InType == Resource.Cattle)
                {
                    cattleUsedAsFood += conversion.Count * conversionDefinition.InAmount;
                }
            }

            // Calculate how many animals are left over after feeding during harvest
            // We aren't concerned with cooked animals yet, as the only animals that can be passed in as cooked
            // are the baby animals
            var sheepAfterFeeding  = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Sheep) - sheepUsedAsFood;
            var boarAfterFeeding   = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Boar) - boarUsedAsFood;
            var cattleAfterFeeding = player.Farmyard.AnimalManager.GetAnimalCount(AnimalResource.Cattle) - cattleUsedAsFood;

            data.AnimalData.Free[AnimalResource.Sheep]  += sheepUsedAsFood;
            data.AnimalData.Free[AnimalResource.Boar]   += boarUsedAsFood;
            data.AnimalData.Free[AnimalResource.Cattle] += cattleUsedAsFood;

            // Figure out which animals will breed
            var newAnimals = new Dictionary <AnimalResource, int>();

            newAnimals[AnimalResource.Sheep]  = sheepAfterFeeding >= 2 ? 1 : 0;
            newAnimals[AnimalResource.Boar]   = boarAfterFeeding >= 2 ? 1 : 0;
            newAnimals[AnimalResource.Cattle] = cattleAfterFeeding >= 2 ? 1 : 0;

            if (!ActionService.CanAssignAnimals(player, data.AnimalData, newAnimals))
            {
                return(false);
            }

            return(true);
        }
Beispiel #20
0
 /// <summary>
 /// Gets the cost of the fence for the player
 /// </summary>
 /// <param name="player"></param>
 /// <param name="count"></param>
 /// <returns></returns>
 public static int GetFenceCost(AgricolaPlayer player, int count)
 {
     return(count);
 }
Beispiel #21
0
 /// <summary>
 /// Returns the amount of points lost for begging cards for a player
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public static int CalculateBeggingScore(AgricolaPlayer player)
 {
     return(-player.BeggingCards * 3);
 }
Beispiel #22
0
 /// <summary>
 /// Calculates the points gained for each family member a player has
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public static int CalculateFamilyMemberScore(AgricolaPlayer player)
 {
     return(player.FamilySize * 3);
 }
Beispiel #23
0
 public static int CalculateUnusedSpaceScore(AgricolaPlayer player)
 {
     return(-player.Farmyard.EmptyLocations.Count());
 }
Beispiel #24
0
 private void CalculateFencedStablesScore(AgricolaPlayer player)
 {
     FencedStables = Curator.CalculateFencedStablesScore(player);
 }
Beispiel #25
0
 /// <summary>
 /// Returns true if the player has an Oven on their farm
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public static bool HasOven(AgricolaPlayer player)
 {
     return(player.OwnedCards.Where(x => x is Improvement).Any(x => (x as Improvement).Oven));
 }
Beispiel #26
0
 private void CalculateFamilyMemberScore(AgricolaPlayer player)
 {
     FamilyMembers = Curator.CalculateFamilyMemberScore(player);
 }
Beispiel #27
0
 public void AddPlayer(AgricolaPlayer player)
 {
     players.Add(player);
 }
Beispiel #28
0
 private void CalculateFieldsScore(AgricolaPlayer player)
 {
     Fields = Curator.CalculateFieldsScore(player);
 }
Beispiel #29
0
 /// <summary>
 /// Returns true if the user has the ability to fence in any pastures given
 /// the number of fences remaining.
 ///
 /// This does not factor affording costs in.
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public static bool CanPlaceFences(AgricolaPlayer player)
 {
     return(player.Farmyard.EmptyLocations.Count > 0 && Curator.HasFencesLeft(player) && player.Farmyard.CanFencePasture());
 }