コード例 #1
0
        public List <ResourceAmount> GenerateResources()
        {
            Dictionary <ResourceLibrary.ResourceType, ResourceAmount> toReturn =
                new Dictionary <ResourceLibrary.ResourceType, ResourceAmount>();

            foreach (var tags in TradeGoods)
            {
                int num = MathFunctions.RandInt(tags.Value - 5, tags.Value + 5);


                List <Resource> resources = ResourceLibrary.GetResourcesByTag(tags.Key);

                if (resources.Count <= 0)
                {
                    continue;
                }

                for (int i = 0; i < num; i++)
                {
                    Resource randResource = Datastructures.SelectRandom(resources);

                    if (randResource.Type == ResourceLibrary.ResourceType.Trinket ||
                        randResource.Type == ResourceLibrary.ResourceType.GemTrinket ||
                        tags.Key == Resource.ResourceTags.Craft)
                    {
                        Resource.ResourceTags craftTag        = Datastructures.SelectRandom(Crafts);
                        List <Resource>       availableCrafts = ResourceLibrary.GetResourcesByTag(craftTag);

                        Resource trinket = ResourceLibrary.GenerateTrinket(
                            Datastructures.SelectRandom(availableCrafts).Type, MathFunctions.Rand(0.1f, 3.0f));

                        if (MathFunctions.RandEvent(0.3f) && Encrustings.Count > 0)
                        {
                            List <Resource> availableGems =
                                ResourceLibrary.GetResourcesByTag(Datastructures.SelectRandom(Encrustings));
                            randResource = ResourceLibrary.EncrustTrinket(trinket.Type,
                                                                          Datastructures.SelectRandom(availableGems).Type);
                        }
                        else
                        {
                            randResource = trinket;
                        }
                    }

                    if (!toReturn.ContainsKey(randResource.Type))
                    {
                        toReturn[randResource.Type] = new ResourceAmount(randResource.Type, 1);
                    }
                    else
                    {
                        toReturn[randResource.Type].NumResources += 1;
                    }
                }
            }

            List <ResourceAmount> resList = toReturn.Select(amount => amount.Value).ToList();

            return(resList);
        }
コード例 #2
0
ファイル: EntityFactory.cs プロジェクト: Solsund/dwarfcorp
        public static ResourceEntity CreateRandomTrinket(Vector3 pos)
        {
            Resource randResource = ResourceLibrary.GenerateTrinket("Gold", MathFunctions.Rand(0.1f, 3.5f));

            if (MathFunctions.RandEvent(0.5f))
            {
                randResource = ResourceLibrary.EncrustTrinket(randResource, "Emerald");
            }

            return(new ResourceEntity(randResource.Type, pos));
        }
コード例 #3
0
        private static GameComponent __factory0(ComponentManager Manager, Vector3 Position, Blackboard Data)
        {
            var randResource = ResourceLibrary.GenerateTrinket(Datastructures.SelectRandom(ResourceLibrary.Resources.Where(r => r.Value.Tags.Contains(Resource.ResourceTags.Material))).Key, MathFunctions.Rand(0.1f, 3.5f));

            if (MathFunctions.RandEvent(0.5f))
            {
                randResource = ResourceLibrary.EncrustTrinket(randResource.Name, Datastructures.SelectRandom(ResourceLibrary.Resources.Where(r => r.Value.Tags.Contains(Resource.ResourceTags.Gem))).Key);
            }

            return(new ResourceEntity(Manager, new ResourceAmount(randResource.Name), Position));
        }
コード例 #4
0
        public static ResourceEntity CreateRandomTrinket(WorldManager world, Vector3 pos)
        {
            Resource randResource = ResourceLibrary.GenerateTrinket(Datastructures.SelectRandom(ResourceLibrary.Resources.Where(r => r.Value.Tags.Contains(Resource.ResourceTags.Material))).Key, MathFunctions.Rand(0.1f, 3.5f));

            if (MathFunctions.RandEvent(0.5f))
            {
                randResource = ResourceLibrary.EncrustTrinket(randResource.Type, Datastructures.SelectRandom(ResourceLibrary.Resources.Where(r => r.Value.Tags.Contains(Resource.ResourceTags.Gem))).Key);
            }

            return(new ResourceEntity(world.ComponentManager, new ResourceAmount(randResource.Type), pos));
        }
コード例 #5
0
ファイル: CraftItemAct.cs プロジェクト: svifylabs/dwarfcorp
        public IEnumerable <Status> CreateResources()
        {
            List <ResourceAmount> stashed = Agent.Blackboard.GetData <List <ResourceAmount> >("ResourcesStashed");

            ItemType.SelectedResources = stashed;
            if (ItemType.Name == ResourceLibrary.ResourceType.Trinket)
            {
                Resource craft = ResourceLibrary.GenerateTrinket(stashed.ElementAt(0).ResourceType.Type,
                                                                 (Agent.Stats.Dexterity + Agent.Stats.Intelligence) / 15.0f * MathFunctions.Rand(0.5f, 1.75f));
                ItemType.ResourceCreated = craft.Type;
            }
            else if (ItemType.Name == ResourceLibrary.ResourceType.Meal)
            {
                if (stashed.Count < 2)
                {
                    yield return(Act.Status.Fail);

                    yield break;
                }
                Resource craft = ResourceLibrary.CreateMeal(stashed.ElementAt(0).ResourceType, stashed.ElementAt(1).ResourceType);
                ItemType.ResourceCreated = craft.Type;
            }
            else if (ItemType.Name == ResourceLibrary.ResourceType.Ale)
            {
                Resource craft = ResourceLibrary.CreateAle(stashed.ElementAt(0).ResourceType);
                ItemType.ResourceCreated = craft.Type;
            }
            else if (ItemType.Name == ResourceLibrary.ResourceType.Bread)
            {
                Resource craft = ResourceLibrary.CreateBread(stashed.ElementAt(0).ResourceType);
                ItemType.ResourceCreated = craft.Type;
            }
            else if (ItemType.Name == ResourceLibrary.ResourceType.GemTrinket)
            {
                Resource gem     = null;
                Resource trinket = null;
                foreach (ResourceAmount stashedResource in stashed)
                {
                    if (stashedResource.ResourceType.Tags.Contains(Resource.ResourceTags.Craft))
                    {
                        trinket = stashedResource.ResourceType;
                    }

                    if (stashedResource.ResourceType.Tags.Contains(Resource.ResourceTags.Gem))
                    {
                        gem = stashedResource.ResourceType;
                    }
                }


                if (gem == null || trinket == null)
                {
                    yield return(Status.Fail);

                    yield break;
                }

                Resource craft = ResourceLibrary.EncrustTrinket(trinket, gem.Type);
                ItemType.ResourceCreated = craft.Type;
            }

            Resource resource = ResourceLibrary.Resources[ItemType.ResourceCreated];

            Creature.Inventory.Resources.AddResource(new ResourceAmount(resource, 1));
            yield return(Status.Success);
        }
コード例 #6
0
        public IEnumerable <Status> CreateResources(List <ResourceAmount> stashed)
        {
            if (stashed == null || stashed.Count == 0)
            {
                yield return(Act.Status.Fail);

                yield break;
            }

            Item.SelectedResources = stashed;
            ResourceType ResourceCreated = Item.ItemType.ResourceCreated;

            switch (Item.ItemType.CraftActBehavior)
            {
            case CraftItem.CraftActBehaviors.Object:
            {
                Resource craft = Item.ItemType.ToResource(Creature.World, stashed);
                ResourceCreated = craft.Name;
            }
            break;

            case CraftItem.CraftActBehaviors.Trinket:
            {
                Resource craft = ResourceLibrary.GenerateTrinket(stashed.ElementAt(0).ResourceType,
                                                                 (Agent.Stats.Dexterity + Agent.Stats.Intelligence) / 15.0f * MathFunctions.Rand(0.5f, 1.75f));
                ResourceCreated = craft.Name;
            }
            break;

            case CraftItem.CraftActBehaviors.Meal:
            {
                if (stashed.Count < 2)
                {
                    yield return(Act.Status.Fail);

                    yield break;
                }
                Resource craft = ResourceLibrary.CreateMeal(stashed.ElementAt(0).ResourceType, stashed.ElementAt(1).ResourceType);
                ResourceCreated = craft.Name;
            }
            break;

            case CraftItem.CraftActBehaviors.Ale:
            {
                Resource craft = ResourceLibrary.CreateAle(stashed.ElementAt(0).ResourceType);
                ResourceCreated = craft.Name;
            }
            break;

            case CraftItem.CraftActBehaviors.Bread:
            {
                Resource craft = ResourceLibrary.CreateBread(stashed.ElementAt(0).ResourceType);
                ResourceCreated = craft.Name;
            }
            break;

            case CraftItem.CraftActBehaviors.GemTrinket:
            {
                Resource gem     = null;
                Resource trinket = null;
                foreach (ResourceAmount stashedResource in stashed)
                {
                    if (ResourceLibrary.GetResourceByName(stashedResource.ResourceType).Tags.Contains(Resource.ResourceTags.Craft))
                    {
                        trinket = ResourceLibrary.GetResourceByName(stashedResource.ResourceType);
                    }

                    if (ResourceLibrary.GetResourceByName(stashedResource.ResourceType).Tags.Contains(Resource.ResourceTags.Gem))
                    {
                        gem = ResourceLibrary.GetResourceByName(stashedResource.ResourceType);
                    }
                }


                if (gem == null || trinket == null)
                {
                    yield return(Status.Fail);

                    yield break;
                }

                Resource craft = ResourceLibrary.EncrustTrinket(trinket.Name, gem.Name);
                ResourceCreated = craft.Name;
            }
            break;

            case CraftItem.CraftActBehaviors.Normal:
            default:
                break;
            }

            Resource resource = ResourceLibrary.Resources[ResourceCreated];

            Creature.Inventory.AddResource(new ResourceAmount(resource, Item.ItemType.CraftedResultsCount));
            Creature.AI.AddXP((int)Item.ItemType.BaseCraftTime);
            yield return(Status.Success);
        }
コード例 #7
0
ファイル: Race.cs プロジェクト: polytronicgr/dwarfcorp
        public List <ResourceAmount> GenerateResources(WorldManager world)
        {
            Dictionary <ResourceType, ResourceAmount> toReturn =
                new Dictionary <ResourceType, ResourceAmount>();

            Resource.ResourceTags[] blacklistTags = { Resource.ResourceTags.Money, Resource.ResourceTags.Corpse };
            foreach (var tags in TradeGoods)
            {
                int num = MathFunctions.RandInt(tags.Value - 5, tags.Value + 5);


                IEnumerable <Resource> resources = ResourceLibrary.GetResourcesByTag(tags.Key);

                if (resources.Count() <= 0)
                {
                    continue;
                }

                for (int i = 0; i < num; i++)
                {
                    Resource randResource = Datastructures.SelectRandom(resources);

                    if (randResource.Tags.Any(blacklistTags.Contains))
                    {
                        continue;
                    }

                    if (tags.Key == Resource.ResourceTags.Craft)
                    {
                        Resource.ResourceTags  craftTag        = Datastructures.SelectRandom(Crafts);
                        IEnumerable <Resource> availableCrafts = ResourceLibrary.GetResourcesByTag(craftTag);

                        Resource trinket = ResourceLibrary.GenerateTrinket(
                            Datastructures.SelectRandom(availableCrafts).Name, MathFunctions.Rand(0.1f, 3.0f));

                        if (MathFunctions.RandEvent(0.3f) && Encrustings.Count > 0)
                        {
                            IEnumerable <Resource> availableGems =
                                ResourceLibrary.GetResourcesByTag(Datastructures.SelectRandom(Encrustings));
                            randResource = ResourceLibrary.EncrustTrinket(trinket.Name,
                                                                          Datastructures.SelectRandom(availableGems).Name);
                        }
                        else
                        {
                            randResource = trinket;
                        }
                    }

                    if (!toReturn.ContainsKey(randResource.Name))
                    {
                        toReturn[randResource.Name] = new ResourceAmount(randResource.Name, 1);
                    }
                    else
                    {
                        toReturn[randResource.Name].NumResources += 1;
                    }
                }
            }

            for (int i = 0; i < NumFurniture; i++)
            {
                var randomObject = Datastructures.SelectRandom(CraftLibrary.EnumerateCraftables().Where(type => type.Type == CraftItem.CraftType.Object && type.RequiredResources.All((tags) =>
                                                                                                                                                                                      TradeGoods.Any(good => good.Key == tags.ResourceType))));
                if (randomObject == null)
                {
                    continue;
                }
                List <ResourceAmount> selectedResources = new List <ResourceAmount>();
                foreach (var requirement in randomObject.RequiredResources)
                {
                    IEnumerable <Resource> resources = ResourceLibrary.GetResourcesByTag(requirement.ResourceType);
                    selectedResources.Add(new ResourceAmount(Datastructures.SelectRandom(resources), requirement.NumResources));
                }
                var randResource = randomObject.ToResource(world, selectedResources, Posessive + " ");
                if (!toReturn.ContainsKey(randResource.Name))
                {
                    toReturn[randResource.Name] = new ResourceAmount(randResource.Name, 1);
                }
                else
                {
                    toReturn[randResource.Name].NumResources += 1;
                }
            }

            List <ResourceAmount> resList = toReturn.Select(amount => amount.Value).ToList();

            return(resList);
        }