public override GameAction OnExecute(AgricolaPlayer player, GameActionData data)
        {
            base.OnExecute(player, data);

            if (Mode == BuildingResourcesActionMode.DoubleResourceOrFamilyGrowth && ((BuildingResourcesActionData)data).Growth == true)
            {
                player.AddFamilyMember();
                AddUser(player);    // Add the baby to the action display

                this.ResultingNotices.Add(new GameActionNotice(player.Name, NoticeVerb.GrowFamily.ToString()));
            }
            else
            {
                var resource1 = ((BuildingResourcesActionData)data).Resource1;
                var resource2 = ((BuildingResourcesActionData)data).Resource2;

                switch (Mode)
                {
                case BuildingResourcesActionMode.SingleResource:
                    ActionService.AssignCacheResource(player, eventTriggers, ResultingNotices, new ResourceCache(resource1.Value, 1));
                    break;

                case BuildingResourcesActionMode.SingleResourceWithFood:
                    ActionService.AssignCacheResources(player,
                                                       eventTriggers, ResultingNotices,
                                                       new ResourceCache[] {
                        new ResourceCache(resource1.Value, 1),
                        new ResourceCache(Resource.Food, 1)
                    });
                    break;

                case BuildingResourcesActionMode.DoubleResource:
                case BuildingResourcesActionMode.DoubleResourceOrFamilyGrowth:
                    ActionService.AssignCacheResources(player, eventTriggers, ResultingNotices,
                                                       new ResourceCache[] {
                        new ResourceCache(resource1.Value, 1),
                        new ResourceCache(resource2.Value, 1)
                    });
                    break;
                }
            }

            return(this);
        }
Esempio n. 2
0
        public override GameAction OnExecute(AgricolaPlayer player, GameActionData data)
        {
            base.OnExecute(player, data);

            var resources = CacheResources.Values.ToList();

            foreach (var cache in TakeResourceCaches)
            {
                resources.Add(cache);
            }

            ActionService.AssignCacheResources(player, eventTriggers, ResultingNotices, resources.ToArray());

            foreach (var cache in resources)
            {
                if (CacheResources.ContainsKey(cache.Type))
                {
                    CacheResources[cache.Type] = new ResourceCache(cache.Type, 0);
                }
            }

            return(this);
        }
Esempio n. 3
0
        public void TakeCaches(AgricolaPlayer player, Dictionary <Resource, int> leaveBehind, Dictionary <Resource, int> gained)
        {
            var taking = new Dictionary <Resource, int>();

            foreach (var cache in CacheResources)
            {
                if (!taking.ContainsKey(cache.Value.Type))
                {
                    taking[cache.Value.Type] = cache.Value.Count;
                }
                else
                {
                    taking[cache.Value.Type] += cache.Value.Count;
                }
            }

            if (leaveBehind != null)
            {
                foreach (var cache in leaveBehind)
                {
                    if (taking.ContainsKey(cache.Key))
                    {
                        taking[cache.Key] -= leaveBehind[cache.Key];
                    }
                }
            }

            var takingCaches = taking.Select(x => new ResourceCache(x.Key, x.Value));

            if (eventTriggers != null)
            {
                foreach (var trigger in eventTriggers)
                {
                    if (trigger.GetType() == typeof(TravelingPlayersActionTrigger))
                    {
                        ((TravelingPlayersActionTrigger)trigger).FoodTaken = taking[Resource.Food];
                    }
                }
            }

            if (gained != null)
            {
                foreach (var kvp in gained)
                {
                    if (!taking.ContainsKey(kvp.Key))
                    {
                        taking[kvp.Key] = kvp.Value;
                    }
                    else
                    {
                        taking[kvp.Key] += kvp.Value;
                    }
                }
            }


            if (takingCaches.Count() > 1)
            {
                ActionService.AssignCacheResources(player,
                                                   eventTriggers,
                                                   ResultingNotices,
                                                   taking.Select(x => new ResourceCache(x.Key, x.Value)).ToArray());

                foreach (var kvp in taking)
                {
                    if (CacheResources.ContainsKey(kvp.Key))
                    {
                        var cache = CacheResources[kvp.Key];
                        CacheResources[kvp.Key] = cache.updateCount(-kvp.Value);
                    }
                }
            }
            else
            {
                var cache = CacheResources.Values.First();
                if (cache.Type.IsAnimal())
                {
                    //player.Game.AddInterrupt(new AssignAnimalsAction(player, cache, ResultingNotices));
                }
                else
                {
                    ActionService.AssignCacheResource(player, eventTriggers, ResultingNotices, new ResourceCache(cache.Type, taking[cache.Type]));
                }
                CacheResources[cache.Type] = cache.updateCount(-taking[cache.Type]);
            }
        }