Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 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());
 }
Exemplo n.º 5
0
        public bool RemoveResource(Quantitiy <Resource.ResourceTags> resource)
        {
            if (resource == null)
            {
                return(false);
            }

            if (resource.NumResources > CountResourcesWithTags(resource.ResourceType))
            {
                return(false);
            }

            return(RemoveResourceImmediate(resource));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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;
                }
            }
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
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));
            }
        }
Exemplo n.º 12
0
 public Quantitiy(Quantitiy <T> other)
 {
     Type  = other.Type;
     Count = other.Count;
 }
Exemplo n.º 13
0
 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());
 }
Exemplo n.º 14
0
 public bool HasResource(Quantitiy <Resource.ResourceTags> resourceType)
 {
     return(GetResourceCount(resourceType.ResourceType) >= resourceType.NumResources);
 }
Exemplo n.º 15
0
 protected bool Equals(Quantitiy <T> other)
 {
     return(Equals(ResourceType, other.ResourceType) && NumResources == other.NumResources);
 }
Exemplo n.º 16
0
 public Quantitiy(Quantitiy <T> other)
 {
     ResourceType = other.ResourceType;
     NumResources = other.NumResources;
 }
Exemplo n.º 17
0
 protected bool Equals(Quantitiy <T> other)
 {
     return(Equals(Type, other.Type) && Count == other.Count);
 }