public void AddCacheResources(ResourceCache cache) { if (CacheResources.ContainsKey(cache.Type)) { CacheResources[cache.Type] = CacheResources[cache.Type].updateCount(cache.Count); } else { CacheResources[cache.Type] = new ResourceCache(cache.Type, cache.Count); } }
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); }
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]); } }