Esempio n. 1
0
 public override bool CanExecute(AgricolaPlayer player, Data.GameActionData data)
 {
     if (!base.CanExecute(player, data))
     {
         return(false);
     }
     return(ActionService.CanBuildFences(player, Id, (BuildFencesActionData)data, out pastures, out costs));
 }
Esempio n. 2
0
 public override bool CanExecute(AgricolaPlayer player, Data.GameActionData data)
 {
     ResourceCache[] costs;
     return(ActionService.CanBuildFences(player, Id, (BuildFencesActionData)data, out pastures, out costs));
 }
Esempio n. 3
0
        public override bool CanExecute(AgricolaPlayer player, Data.GameActionData data)
        {
            if (!base.CanExecute(player, data))
            {
                return(false);
            }

            var renovationData = (RenovationActionData)data;

            ResourceCache[] renovationCosts;
            additionalCosts = null;

            if (!ActionService.CanRenovate(player, out renovationCosts))
            {
                return(false);
            }

            switch (mode)
            {
            case RenovationActionMode.Fences:
                if (!(renovationData.FenceData == null ||
                      renovationData.FenceData.Fences.Length == 0 ||
                      ActionService.CanBuildFences(player, Id, renovationData.FenceData, out this.pastures, out additionalCosts)))
                {
                    return(false);
                }
                break;

            case RenovationActionMode.Improvement:
                if (!(renovationData.ImprovementData == null ||
                      ActionService.CanBuyImprovement(player, renovationData.ImprovementData, out additionalCosts)))
                {
                    return(false);
                }
                break;
            }

            var totalCosts = new Dictionary <Resource, ResourceCache>();

            if (renovationCosts != null)
            {
                foreach (var r in renovationCosts)
                {
                    totalCosts[r.Type] = r;
                }
            }

            if (additionalCosts != null)
            {
                foreach (var cost in additionalCosts)
                {
                    if (totalCosts.ContainsKey(cost.Type))
                    {
                        totalCosts[cost.Type] = totalCosts[cost.Type].updateCount(cost.Count);
                    }
                    else
                    {
                        totalCosts[cost.Type] = cost;
                    }
                }
            }

            return(Curator.CanAfford(player, totalCosts.Values.ToArray()));
        }