Exemplo n.º 1
0
 public static bool CanAfford(AgricolaPlayer player, ResourceCache[] costs)
 {
     foreach (var c in costs)
     {
         if (player.GetResource(c.Type) < c.Count)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if a player can afford to renovate their house
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public static bool CanAffordRenovation(AgricolaPlayer player, out ResourceCache[] costs)
        {
            costs = GetRenovationCost(player);
            foreach (var cost in costs)
            {
                if (player.GetResource(cost.Type) < cost.Count)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if a player can afford a given improvement
        /// </summary>
        /// <param name="player"></param>
        /// <param name="cardId"></param>
        /// <param name="paymentIndex"></param>
        /// <returns></returns>
        public static bool CanAffordCard(AgricolaPlayer player, int cardId, int paymentIndex, out ResourceCache[] costs)
        {
            costs = null;
            var card = ((AgricolaGame)player.Game).GetCard(cardId);

            if (paymentIndex < 0 || paymentIndex >= card.Costs.Length)
            {
                return(false);
            }

            var cost = card.Costs[paymentIndex];

            if (cost is ResourceCardCost)
            {
                var rcCost = (ResourceCardCost)cost;
                costs = rcCost.Resources.ToArray();

                foreach (var resource in rcCost.Resources)
                {
                    if (resource.Type.IsAnimal())
                    {
                        if (resource.Count > player.Farmyard.AnimalManager.GetAnimalCount((AnimalResource)resource.Type))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (resource.Count > player.GetResource(resource.Type))
                        {
                            return(false);
                        }
                    }
                }
            }
            else if (cost is ReturnCardCardCost)
            {
                var miCost     = (ReturnCardCardCost)cost;
                var ownedCards = player.OwnedCardIds;

                return(miCost.Ids.Intersect(ownedCards).Count() > 0);
            }
            return(true);
        }