public List <ResourceAmount> GetResources(Quantitiy <Resource.ResourceTags> tags) { List <ResourceAmount> toReturn = new List <ResourceAmount>(); int amountLeft = tags.NumResources; foreach (ResourceAmount resourceAmount in Resources.Values) { if (amountLeft <= 0) { break; } if (resourceAmount.NumResources == 0) { continue; } if (ResourceLibrary.GetResourceByName(resourceAmount.ResourceType).Tags.Contains(tags.ResourceType)) { int amountToRemove = Math.Min(tags.NumResources, amountLeft); if (amountToRemove > 0) { toReturn.Add(new ResourceAmount(resourceAmount.ResourceType, amountToRemove)); amountLeft -= amountToRemove; } } } return(toReturn); }
private void BuildResource_OnClicked() { List <Task> assignments = new List <Task>(); SelectedResource.SelectedResources = new List <ResourceAmount>(); for (int i = 0; i < BuildResourceTab.SelectedResourceBoxes.Count; i++) { ComboBox box = BuildResourceTab.SelectedResourceBoxes[i]; if (box.CurrentValue == "<Not enough!>") { return; } Quantitiy <Resource.ResourceTags> tags = SelectedResource.RequiredResources[i]; SelectedResource.SelectedResources.Add(new ResourceAmount(box.CurrentValue, tags.NumResources)); } assignments.Add(new CraftResourceTask(SelectedResource)); if (assignments.Count > 0) { TaskManager.AssignTasks(assignments, Faction.FilterMinionsWithCapability(Master.SelectedMinions, GameMaster.ToolMode.Craft)); } }
private void BuildItemButton_OnClicked() { SelectedItem.SelectedResources = new List <ResourceAmount>(); for (int i = 0; i < BuildItemTab.SelectedResourceBoxes.Count; i++) { ComboBox box = BuildItemTab.SelectedResourceBoxes[i]; if (box.CurrentValue == "<Not enough!>") { return; } Quantitiy <Resource.ResourceTags> tags = SelectedItem.RequiredResources[i]; SelectedItem.SelectedResources.Add(new ResourceAmount(box.CurrentValue, tags.NumResources)); } IsVisible = false; Master.Faction.RoomBuilder.CurrentRoomData = null; Master.VoxSelector.SelectionType = VoxelSelectionType.SelectEmpty; Master.Faction.WallBuilder.CurrentVoxelType = null; Master.Faction.CraftBuilder.IsEnabled = true; Master.Faction.CraftBuilder.CurrentCraftType = SelectedItem; Master.CurrentToolMode = GameMaster.ToolMode.Build; GUI.ToolTipManager.Popup("Click and drag to build " + SelectedItem.Name); }
public List <ResourceAmount> GetResources(Quantitiy <Resource.ResourceTags> quantitiy, RestockType type = RestockType.RestockResource) { return((from resource in Resources where ResourceLibrary.GetResourceByName(resource.Resource).Tags.Contains(quantitiy.ResourceType) && ((type == RestockType.RestockResource && resource.MarkedForRestock) || (type == RestockType.None && !resource.MarkedForRestock) || (type == RestockType.Any)) select new ResourceAmount(resource.Resource)).ToList()); }
public bool RemoveResource(Quantitiy <Resource.ResourceTags> resource) { if (resource == null) { return(false); } if (resource.NumResources > CountResourcesWithTags(resource.ResourceType)) { return(false); } return(RemoveResourceImmediate(resource)); }
public List <Quantitiy <Resource.ResourceTags> > GetRequiredResources(int numVoxels, Faction faction) { List <Quantitiy <Resource.ResourceTags> > toReturn = new List <Quantitiy <Resource.ResourceTags> >(); foreach (var resources in RequiredResources) { Quantitiy <Resource.ResourceTags> required = new Quantitiy <Resource.ResourceTags>(resources.Value) { NumResources = (int)(numVoxels * resources.Value.NumResources * 0.25f) }; toReturn.Add(required); } return(toReturn); }
public bool HasResource(Quantitiy <Resource.ResourceTags> itemToStock) { Dictionary <String, int> resourceCounts = new Dictionary <String, int>(); foreach (var resource in Resources) { if (Library.GetResourceType(resource.Resource).Tags.Contains(itemToStock.Type)) { if (!resourceCounts.ContainsKey(resource.Resource)) { resourceCounts[resource.Resource] = 0; } resourceCounts[resource.Resource]++; } } return(resourceCounts.Count > 0 && resourceCounts.Max(r => r.Value >= itemToStock.Count)); }
public void AddResources(List <Quantitiy <Resource.ResourceTags> > resources) { foreach (Quantitiy <Resource.ResourceTags> resource in resources) { if (PutResources.ContainsKey(resource.ResourceType)) { Quantitiy <Resource.ResourceTags> amount = PutResources[resource.ResourceType]; amount.NumResources += resource.NumResources; } else { Quantitiy <Resource.ResourceTags> amount = new Quantitiy <Resource.ResourceTags>(); amount.NumResources += resource.NumResources; amount.ResourceType = resource.ResourceType; PutResources[resource.ResourceType] = amount; } } }
public bool HasAvailableResources(int numVoxels, Faction faction) { foreach (var resources in RequiredResources) { Quantitiy <Resource.ResourceTags> required = new Quantitiy <Resource.ResourceTags>(resources.Value) { NumResources = (int)(numVoxels * resources.Value.NumResources * 0.25f) }; if (!faction.HasResources(new List <Quantitiy <Resource.ResourceTags> >() { required })) { return(false); } } return(true); }
public bool RemoveResourceImmediate(Quantitiy <Resource.ResourceTags> tags) { int numLeft = tags.NumResources; foreach (ResourceAmount resource in Resources.Values) { if (numLeft == 0) { return(true); } if (ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(tags.ResourceType)) { int rm = Math.Min(resource.NumResources, numLeft); resource.NumResources -= rm; numLeft -= rm; currentResourceCount -= rm; } } return(numLeft == 0); }
public bool HasResource(Quantitiy <Resource.ResourceTags> itemToStock, bool allowHeterogenous = false) { if (allowHeterogenous) { return(Resources.Count(resource => ResourceLibrary.GetResourceByName(resource.Resource).Tags.Contains(itemToStock.ResourceType)) >= itemToStock.NumResources); } else { Dictionary <ResourceType, int> resourceCounts = new Dictionary <ResourceType, int>(); foreach (var resource in Resources) { if (ResourceLibrary.GetResourceByName(resource.Resource).Tags.Contains(itemToStock.ResourceType)) { if (!resourceCounts.ContainsKey(resource.Resource)) { resourceCounts[resource.Resource] = 0; } resourceCounts[resource.Resource]++; } } return(resourceCounts.Count > 0 && resourceCounts.Max(r => r.Value >= itemToStock.NumResources)); } }
public Quantitiy(Quantitiy <T> other) { Type = other.Type; Count = other.Count; }
public List <ResourceAmount> GetResources(Quantitiy <Resource.ResourceTags> quantitiy) { return((from resource in Resources where ResourceLibrary.GetResourceByName(resource.Resource).Tags.Contains(quantitiy.ResourceType) select new ResourceAmount(resource.Resource)).ToList()); }
public bool HasResource(Quantitiy <Resource.ResourceTags> resourceType) { return(GetResourceCount(resourceType.ResourceType) >= resourceType.NumResources); }
protected bool Equals(Quantitiy <T> other) { return(Equals(ResourceType, other.ResourceType) && NumResources == other.NumResources); }
public Quantitiy(Quantitiy <T> other) { ResourceType = other.ResourceType; NumResources = other.NumResources; }
protected bool Equals(Quantitiy <T> other) { return(Equals(Type, other.Type) && Count == other.Count); }