public InventoryAmount AddResources(InventoryAmount resHarvested) { var remainder = new InventoryAmount(); EnsureListSize(); if (resHarvested.Empty()) { return(remainder); } foreach (var resource in resHarvested.Amount) { var invType = resource.Key; var amount = resource.Value; if (amount == 0) { continue; } var localRemainder = AddItem(new InventoryItem(invType, amount)); if (localRemainder.Amount == 0) { continue; } remainder.Amount[invType] = remainder.Amount.ContainsKey(invType) ? remainder.Amount[invType] + localRemainder.Amount : localRemainder.Amount; } UpdateView(); return(remainder); }
public HarvestInfo ChangeResources(InventoryAmount changes, bool add = true)//TODO make simple clone { var rToHarvest = ResourcesToHarvest.ToDictionary(entry => entry.Key, entry => entry.Value); var initialResources = InitialResources.ToDictionary(entry => entry.Key, entry => entry.Value); foreach (var change in changes.Amount) { rToHarvest[change.Key] += add ? change.Value : -change.Value; } return(new HarvestInfo(CanBeChopped, CanBeMined, rToHarvest, initialResources, CanChop, CanMine, CanBeHarvestAttacked, CanHarvestAttack)); }
private InventoryAmount GetHarvestedResourcesCount(float harvestEffort) { if (harvestEffort < 1f) { return(new InventoryAmount(new Dictionary <InventoryType, int>())); } if (element.HarvestInfo.ResourcesToHarvest[InventoryType] <= 0) { return(new InventoryAmount(new Dictionary <InventoryType, int>())); } var harvested = new Dictionary <InventoryType, int>(); harvested[InventoryType] = 1; var InventoryAmount = new InventoryAmount(harvested); element.HarvestInfo = element.HarvestInfo.ChangeResources(InventoryAmount, false); return(InventoryAmount); }