Exemple #1
0
        public virtual void CreateMeatAndBones()
        {
            if (HasMeat)
            {
                ResourceLibrary.ResourceType type = Name + " " + ResourceLibrary.ResourceType.Meat;

                if (!ResourceLibrary.Resources.ContainsKey(type))
                {
                    ResourceLibrary.Add(new Resource(ResourceLibrary.Resources[ResourceLibrary.ResourceType.Meat])
                    {
                        Type      = type,
                        ShortName = type
                    });
                }

                Inventory.Resources.AddResource(new ResourceAmount(type, 1));
            }

            if (HasBones)
            {
                ResourceLibrary.ResourceType type = Name + " " + ResourceLibrary.ResourceType.Bones;

                if (!ResourceLibrary.Resources.ContainsKey(type))
                {
                    ResourceLibrary.Add(new Resource(ResourceLibrary.Resources[ResourceLibrary.ResourceType.Bones])
                    {
                        Type      = type,
                        ShortName = type
                    });
                }

                Inventory.Resources.AddResource(new ResourceAmount(type, 1));
            }
        }
Exemple #2
0
        public static void Initialize()
        {
            foreach (var potion in Potions)
            {
                Resource resource = new Resource();

                {
                    resource.Name               = potion.Key;
                    resource.PotionType         = potion.Key;
                    resource.CraftPrerequisites = potion.Value.Ingredients;
                    resource.CraftInfo          = new Resource.CraftItemInfo()
                    {
                        CraftItemType = potion.Key
                    };
                    resource.CanCraft    = true;
                    resource.MoneyValue  = 100;
                    resource.Description = potion.Value.Description;
                    resource.ShortName   = potion.Key;
                    resource.Tags        = new List <Resource.ResourceTags>()
                    {
                        Resource.ResourceTags.Potion
                    };
                    resource.GuiLayers = new List <Gui.TileReference>()
                    {
                        new Gui.TileReference("resources", potion.Value.Icon)
                    };
                    resource.CompositeLayers = new List <Resource.CompositeLayer>()
                    {
                        new Resource.CompositeLayer()
                        {
                            Asset     = ContentPaths.Entities.Resources.resources,
                            Frame     = new Microsoft.Xna.Framework.Point(potion.Value.Icon % 8, potion.Value.Icon / 8),
                            FrameSize = new Microsoft.Xna.Framework.Point(32, 32)
                        }
                    };
                    resource.Tint = Microsoft.Xna.Framework.Color.White;
                };
                ResourceLibrary.Add(resource);

                CraftItem craftItem = new CraftItem()
                {
                    CraftLocation     = "Apothecary",
                    Icon              = new Gui.TileReference("resources", potion.Value.Icon),
                    Category          = "Potions",
                    Name              = potion.Key,
                    DisplayName       = potion.Key,
                    AllowHeterogenous = true,
                    IsMagical         = true,
                    Type              = CraftItem.CraftType.Resource,
                    Verb              = StringLibrary.GetString("brew"),
                    PastTeseVerb      = StringLibrary.GetString("brewed"),
                    CurrentVerb       = StringLibrary.GetString("brewing"),
                    ResourceCreated   = potion.Key,
                    Description       = potion.Value.Description,
                    RequiredResources = potion.Value.Ingredients,
                    BaseCraftTime     = 10.0f,
                };
                CraftLibrary.Add(craftItem);
            }
        }
Exemple #3
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);
        }
        public CraftResourceTask(CraftItem selectedResource, int NumRepeats, List <ResourceAmount> SelectedResources, int id = -1)
        {
            this.NumRepeats = NumRepeats;

            Category = TaskCategory.CraftItem;
            TaskID   = id < 0 ? MaxID : id;
            MaxID++;
            Item = new CraftDesignation()
            {
                ItemType          = selectedResource,
                Location          = VoxelHandle.InvalidHandle,
                Valid             = true,
                SelectedResources = SelectedResources
            };
            Name     = String.Format("Craft order {0}", TaskID);
            Priority = PriorityType.Low;

            noise = ResourceLibrary.GetResourceByName(Item.ItemType.ResourceCreated).Tags.Contains(Resource.ResourceTags.Edible)
                ? "Cook"
                : "Craft";
            AutoRetry       = true;
            BoredomIncrease = 0.2f;
            if (selectedResource.IsMagical)
            {
                Category = TaskCategory.Research;
            }
        }
Exemple #5
0
        public List <ResourceAmount> ListResourcesWithTag(Resource.ResourceTags tag, bool allowHeterogenous = true)
        {
            Dictionary <string, ResourceAmount> resources = ListResources();

            if (allowHeterogenous)
            {
                return((from pair in resources
                        where ResourceLibrary.GetResourceByName(pair.Value.ResourceType).Tags.Contains(tag)
                        select pair.Value).ToList());
            }
            ResourceAmount maxAmount = null;

            foreach (var pair in resources)
            {
                var resource = ResourceLibrary.GetResourceByName(pair.Value.ResourceType);
                if (!resource.Tags.Contains(tag))
                {
                    continue;
                }
                if (maxAmount == null || pair.Value.NumResources > maxAmount.NumResources)
                {
                    maxAmount = pair.Value;
                }
            }
            return(maxAmount != null ? new List <ResourceAmount>()
            {
                maxAmount
            } : new List <ResourceAmount>());
        }
Exemple #6
0
        public bool Pickup(Item item)
        {
            if (item == null || item.UserData == null || item.UserData.IsDead)
            {
                return(false);
            }

            bool success = Resources.AddResource
                               (new ResourceAmount
            {
                NumResources = 1,
                ResourceType = ResourceLibrary.GetResourceByName(item.UserData.Tags[0])
            });

            if (!success)
            {
                return(false);
            }

            if (item.IsInZone)
            {
                item.Zone = null;
            }
            item.UserData.GetRootComponent().Delete();

            return(true);
        }
Exemple #7
0
        public bool Pickup(Item item)
        {
            if (item == null || item.UserData == null || item.UserData.IsDead)
            {
                return(false);
            }

            bool success = Resources.AddResource
                               (new ResourceAmount
            {
                NumResources = 1,
                ResourceType = ResourceLibrary.GetResourceByName(item.UserData.Tags[0])
            });

            if (!success)
            {
                return(false);
            }

            if (item.IsInZone)
            {
                item.Zone = null;
            }


            TossMotion toss = new TossMotion(0.5f + MathFunctions.Rand(0.05f, 0.08f),
                                             1.0f, item.UserData.GlobalTransform, Position);

            item.UserData.AnimationQueue.Add(toss);
            toss.OnComplete += () => item.UserData.GetRootComponent().Delete();

            return(true);
        }
Exemple #8
0
        public bool Remove(IEnumerable <Quantitiy <Resource.ResourceTags> > amount, RestockType type)
        {
            foreach (var quantity in amount)
            {
                for (int i = 0; i < quantity.NumResources; i++)
                {
                    int kRemove = -1;
                    for (int k = 0; k < Resources.Count; k++)
                    {
                        if (type == RestockType.None && Resources[k].MarkedForRestock)
                        {
                            continue;
                        }
                        else if (type == RestockType.RestockResource && !Resources[k].MarkedForRestock)
                        {
                            continue;
                        }

                        if (!ResourceLibrary.GetResourceByName(Resources[k].Resource)
                            .Tags.Contains(quantity.ResourceType))
                        {
                            continue;
                        }
                        kRemove = k;
                        break;
                    }
                    if (kRemove < 0)
                    {
                        return(false);
                    }
                    Resources.RemoveAt(kRemove);
                }
            }
            return(true);
        }
Exemple #9
0
        public CraftResourceTask(CraftItem selectedResource, int NumRepeats, List <ResourceAmount> SelectedResources, int id = -1)
        {
            this.NumRepeats = NumRepeats;

            TaskID = id < 0 ? MaxID : id;
            MaxID++;
            Item = new CraftDesignation()
            {
                ItemType          = selectedResource,
                Location          = VoxelHandle.InvalidHandle,
                Valid             = true,
                SelectedResources = SelectedResources
            };
            Name     = String.Format("Craft order {0}: {1} {2}s", TaskID, NumRepeats, selectedResource.DisplayName);
            Priority = PriorityType.Medium;

            if (ResourceLibrary.GetResourceByName(Item.ItemType.ResourceCreated).Tags.Contains(Resource.ResourceTags.Edible))
            {
                noise    = "Cook";
                Category = TaskCategory.Cook;
            }
            else
            {
                noise    = "Craft";
                Category = selectedResource.IsMagical ? TaskCategory.Research : TaskCategory.CraftItem;
            }

            AutoRetry       = true;
            BoredomIncrease = GameSettings.Default.Boredom_NormalTask;
        }
Exemple #10
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());
 }
Exemple #11
0
 public List <GItem> GetResources(List <ResourceAmount> resources)
 {
     return((from r in resources
             where r.NumResources > 0
             let resource = ResourceLibrary.GetResourceByName(r.ResourceType)
                            select new GItem(resource, resource.Image, resource.Tint, 0, 1000, r.NumResources, resource.MoneyValue)).ToList());
 }
Exemple #12
0
        private static GameComponent __factory(ComponentManager Manager, Vector3 Position, Blackboard Data)
        {
            var resources = Data.GetData <List <ResourceAmount> >("Resources", null);
            var craftType = Data.GetData <string>("CraftType", null);

            if (resources == null && craftType != null)
            {
                resources = new List <ResourceAmount>();
                var craftItem = CraftLibrary.GetCraftable(craftType);
                foreach (var resource in craftItem.RequiredResources)
                {
                    var genericResource = ResourceLibrary.GetResourcesByTag(resource.ResourceType).FirstOrDefault();
                    resources.Add(new ResourceAmount(genericResource, resource.NumResources));
                }
            }
            else if (resources == null && craftType == null)
            {
                craftType = "Wooden Ladder";
                resources = new List <ResourceAmount>()
                {
                    new ResourceAmount(ResourceType.Wood)
                };
            }
            else if (craftType == null)
            {
                craftType = "Wooden Ladder";
            }

            return(new Ladder(
                       Manager,
                       Position,
                       resources, craftType));
        }
        private static GameComponent __factory1(ComponentManager Manager, Vector3 Position, Blackboard Data)
        {
            IEnumerable <Resource> foods = ResourceLibrary.GetResourcesByTag(Resource.ResourceTags.RawFood);
            Resource randresource        = ResourceLibrary.CreateMeal(Datastructures.SelectRandom(foods).Name, Datastructures.SelectRandom(foods).Name);

            return(new ResourceEntity(Manager, new ResourceAmount(randresource.Name), Position));
        }
Exemple #14
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);
        }
 public Resource GetResource()
 {
     if (_value == null)
     {
         return(null);
     }
     return(ResourceLibrary.GetResourceByName(_value));
 }
Exemple #16
0
        private static GameComponent CreateRandomFood(WorldManager world, Vector3 position)
        {
            IEnumerable <Resource> foods = ResourceLibrary.GetResourcesByTag(Resource.ResourceTags.RawFood);

            Resource randresource = ResourceLibrary.CreateMeal(Datastructures.SelectRandom(foods).Type,
                                                               Datastructures.SelectRandom(foods).Type);

            return(new ResourceEntity(world.ComponentManager, new ResourceAmount(randresource.Type), position));
        }
Exemple #17
0
        private static GameComponent CreateRandomFood(Vector3 position)
        {
            List <Resource> foods = ResourceLibrary.GetResourcesByTag(Resource.ResourceTags.RawFood);

            Resource randresource = ResourceLibrary.CreateMeal(Datastructures.SelectRandom(foods),
                                                               Datastructures.SelectRandom(foods));

            return(new ResourceEntity(randresource.Type, position));
        }
        public static Resource GetResourceByName(string name)
        {
            if (!ResourceLibrary.IsInitialized)
            {
                ResourceLibrary.Initialize();
            }

            return(Resources.ContainsKey((ResourceType)name) ? Resources[name] : null);
        }
Exemple #19
0
 public Resource(ResourceLibrary.ResourceType type, float money, string description, NamedImageFrame image, params ResourceTags[] tags)
 {
     Type = type;
     MoneyValue = money;
     Description = description;
     Image = image;
     Tags = new List<ResourceTags>();
     Tags.AddRange(tags);
     FoodContent = 0;
 }
Exemple #20
0
        protected override void LoadContent()
        {
#if SHARP_RAVEN
            try
            {
#endif
            // Prepare GemGui
            GumInputMapper = new Gui.Input.GumInputMapper(Window.Handle);
            GumInput       = new Gui.Input.Input(GumInputMapper);

            // Register all bindable actions with the input system.
            GumInput.AddAction("TEST", Gui.Input.KeyBindingType.Pressed);

            GumSkin = new RenderData(GraphicsDevice, Content,
                                     "newgui/xna_draw", "Content/newgui/sheets.txt");

            if (SoundManager.Content == null)
            {
                SoundManager.Content = Content;
                SoundManager.LoadDefaultSounds();
#if XNA_BUILD
                //SoundManager.SetActiveSongs(ContentPaths.Music.dwarfcorp, ContentPaths.Music.dwarfcorp_2,
                //    ContentPaths.Music.dwarfcorp_3, ContentPaths.Music.dwarfcorp_4, ContentPaths.Music.dwarfcorp_5);
#endif
            }

            if (GameSettings.Default.DisplayIntro)
            {
                StateManager.PushState(new IntroState(this, StateManager));
            }
            else
            {
                StateManager.PushState(new MainMenuState(this, StateManager));
            }

            BiomeLibrary.InitializeStatics();
            Embarkment.Initialize();
            VoxelChunk.InitializeStatics();
            ControlSettings.Load();
            Drawer2D.Initialize(Content, GraphicsDevice);
            ResourceLibrary.Initialize();
            base.LoadContent();
#if SHARP_RAVEN
        }

        catch (Exception exception)
        {
            if (ravenClient != null)
            {
                ravenClient.Capture(new SentryEvent(exception));
            }
            throw;
        }
#endif
        }
Exemple #21
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));
        }
Exemple #22
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            base.CreateCosmeticChildren(manager);

            Resource type = ResourceLibrary.GetResourceByName(Resource.ResourceType);

            Tinter sprite = null;

            if (type.CompositeLayers == null || type.CompositeLayers.Count == 0)
            {
                sprite = AddChild(new SimpleSprite(Manager, "Sprite",
                                                   Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                   false,
                                                   new SpriteSheet(type.Image.AssetName, 32),
                                                   new Point(type.Image.SourceRect.X / 32, type.Image.SourceRect.Y / 32))
                {
                    OrientationType = SimpleSprite.OrientMode.Spherical,
                    WorldHeight     = 0.75f,
                    WorldWidth      = 0.75f,
                }) as Tinter;
                sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f);
            }
            else
            {
                var layers = new List <LayeredSimpleSprite.Layer>();

                foreach (var layer in type.CompositeLayers)
                {
                    if (layer.Value != null)
                    {
                        layers.Add(new LayeredSimpleSprite.Layer
                        {
                            Sheet = new SpriteSheet(layer.Value, 32),
                            Frame = layer.Key
                        });
                    }
                }

                sprite = AddChild(new LayeredSimpleSprite(Manager, "Sprite",
                                                          Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                          false,
                                                          layers)
                {
                    OrientationType = LayeredSimpleSprite.OrientMode.Spherical,
                    WorldHeight     = 0.75f,
                    WorldWidth      = 0.75f,
                }) as Tinter;
            }

            sprite.Tint = type.Tint;
            sprite.SetFlag(Flag.ShouldSerialize, false);

            sprite.AddChild(new Bobber(Manager, 0.05f, 2.0f, MathFunctions.Rand() * 3.0f, sprite.LocalTransform.Translation.Y)).SetFlag(Flag.ShouldSerialize, false);
        }
        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));
        }
Exemple #24
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            base.CreateCosmeticChildren(manager);

            var type = ResourceLibrary.GetResourceByName(Resource.ResourceType);

            Tinter sprite = null;

            int numSprites = Math.Min(Resource.NumResources, 3);

            for (int i = 0; i < numSprites; i++)
            {
                // Minor optimization for single layer resources.
                if (type.CompositeLayers.Count == 1)
                {
                    var layer = type.CompositeLayers[0];
                    sprite = AddChild(new SimpleBobber(Manager, "Sprite",
                                                       Matrix.CreateTranslation(Vector3.UnitY * 0.25f),
                                                       new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                                                       layer.Frame, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = SimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                    sprite.LocalTransform = Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f);
                }
                else
                {
                    var layers = new List <LayeredSimpleSprite.Layer>();

                    foreach (var layer in type.CompositeLayers)
                    {
                        layers.Add(new LayeredSimpleSprite.Layer
                        {
                            Sheet = new SpriteSheet(layer.Asset, layer.FrameSize.X, layer.FrameSize.Y),
                            Frame = layer.Frame
                        });
                    }

                    sprite = AddChild(new LayeredBobber(Manager, "Sprite",
                                                        Matrix.CreateTranslation(Vector3.UnitY * 0.25f + MathFunctions.RandVector3Cube() * 0.1f),
                                                        layers, 0.15f, MathFunctions.Rand() + 2.0f, MathFunctions.Rand() * 3.0f)
                    {
                        OrientationType = LayeredSimpleSprite.OrientMode.Spherical,
                        WorldHeight     = 0.75f,
                        WorldWidth      = 0.75f,
                    }) as Tinter;
                }

                sprite.LightRamp = type.Tint;
                sprite.SetFlag(Flag.ShouldSerialize, false);
            }
        }
Exemple #25
0
        override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            base.Update(gameTime, chunks, camera);

            LifeTimer.Update(gameTime);
            if (LifeTimer.HasTriggered)
            {
                Die();
            }
            this.SetVertexColorRecursive(ResourceLibrary.GetResourceByName(this.Resource.ResourceType).Tint);
        }
Exemple #26
0
        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));
        }
Exemple #27
0
        public override IEnumerable <Status> Run()
        {
            if (Zone == null)
            {
                Creature.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                yield return(Status.Fail);

                yield break;
            }

            if (Resource.NumResources <= 0)
            {
                yield return(Status.Success);

                yield break;
            }

            List <Body> createdItems = Creature.Inventory.RemoveAndCreate(Resource, Inventory.RestockType.RestockResource);

            if (createdItems.Count == 0)
            {
                yield return(Status.Success);
            }

            foreach (Body b in createdItems)
            {
                if (Zone.AddItem(b))
                {
                    Creature.Stats.NumItemsGathered++;
                }
            }

            Creature.NoiseMaker.MakeNoise("Stockpile", Creature.AI.Position);
            Creature.CurrentCharacterMode = Creature.AttackMode;
            Creature.Sprite.ResetAnimations(Creature.AttackMode);
            Creature.Sprite.PlayAnimations(Creature.AttackMode);
            while (!Creature.Sprite.AnimPlayer.IsDone())
            {
                yield return(Status.Running);
            }

            var resource = ResourceLibrary.GetResourceByName(Resource.ResourceType);

            if (resource.Tags.Contains(DwarfCorp.Resource.ResourceTags.Corpse))
            {
                Creature.AddThought(Thought.ThoughtType.BuriedDead);
            }

            yield return(Status.Running);

            Creature.CurrentCharacterMode = CharacterMode.Idle;
            yield return(Status.Success);
        }
Exemple #28
0
        public List <ResourceAmount> GetResourcesWithTags(List <Quantitiy <Resource.ResourceTags> > tags)
        {
            Dictionary <Resource.ResourceTags, int> tagsRequired = new Dictionary <Resource.ResourceTags, int>();
            Dictionary <Resource.ResourceTags, int> tagsGot      = new Dictionary <Resource.ResourceTags, int>();
            Dictionary <ResourceLibrary.ResourceType, ResourceAmount> amounts = new Dictionary <ResourceLibrary.ResourceType, ResourceAmount>();

            foreach (Quantitiy <Resource.ResourceTags> quantity in tags)
            {
                tagsRequired[quantity.ResourceType] = quantity.NumResources;
                tagsGot[quantity.ResourceType]      = 0;
            }

            foreach (Stockpile stockpile in Stockpiles)
            {
                foreach (ResourceAmount resource in stockpile.Resources)
                {
                    foreach (var requirement in tagsRequired)
                    {
                        int got = tagsGot[requirement.Key];

                        if (requirement.Value <= got)
                        {
                            continue;
                        }

                        if (!ResourceLibrary.GetResourceByName(resource.ResourceType).Tags.Contains(requirement.Key))
                        {
                            continue;
                        }

                        int amountToRemove = System.Math.Min(resource.NumResources, requirement.Value - got);

                        if (amountToRemove <= 0)
                        {
                            continue;
                        }

                        tagsGot[requirement.Key] += amountToRemove;

                        if (amounts.ContainsKey(resource.ResourceType))
                        {
                            amounts[resource.ResourceType].NumResources += amountToRemove;
                        }
                        else
                        {
                            amounts[resource.ResourceType] = new ResourceAmount(resource.ResourceType, amountToRemove);
                        }
                    }
                }
            }

            return(amounts.Values.ToList());
        }
Exemple #29
0
        protected static float GetHealth(ResourceLibrary.ResourceType type)
        {
            var resource = ResourceLibrary.GetResourceByName(type);

            foreach (var tag in resource.Tags)
            {
                if (Healths.ContainsKey(tag))
                {
                    return(Healths[tag]);
                }
            }
            return(DefaultHealth);
        }
Exemple #30
0
        public static IEnumerable <Act.Status> EatStockedFood(this Creature agent)
        {
            List <ResourceAmount> foods = agent.Faction.ListResourcesWithTag(Resource.ResourceTags.Edible);

            if (foods.Count == 0)
            {
                if (agent.Allies == "Dwarf")
                {
                    agent.Manager.World.MakeAnnouncement("We're out of food!", "Our stockpiles don't have any food. Our employees will starve!");
                }
                yield return(Act.Status.Fail);

                yield break;
            }
            else
            {
                foreach (ResourceAmount resourceAmount in foods)
                {
                    if (resourceAmount.NumResources > 0)
                    {
                        Resource resource = ResourceLibrary.GetResourceByName(resourceAmount.ResourceType);
                        bool     removed  = agent.Faction.RemoveResources(new List <ResourceAmount>()
                        {
                            new ResourceAmount(resourceAmount.ResourceType, 1)
                        }, agent.AI.Position);
                        agent.Status.Hunger.CurrentValue += resource.FoodContent;
                        agent.NoiseMaker.MakeNoise("Chew", agent.AI.Position);
                        if (!removed)
                        {
                            yield return(Act.Status.Fail);
                        }
                        else
                        {
                            agent.DrawIndicator(resource.Image, resource.Tint);
                            agent.AI.AddThought(Thought.ThoughtType.AteFood);
                            yield return(Act.Status.Success);
                        }
                        yield break;
                    }
                }

                if (agent.Allies == "Dwarf")
                {
                    agent.Manager.World.MakeAnnouncement("We're out of food!", "Our stockpiles don't have any food. Our employees will starve!");
                }

                yield return(Act.Status.Fail);

                yield break;
            }
        }
Exemple #31
0
        public Point GetSpritesheetFrame(ResourceType resourceType)
        {
            var resource = ResourceLibrary.GetResourceByName(resourceType);

            foreach (var tag in resource.Tags)
            {
                if (Sprites.ContainsKey(tag))
                {
                    return(Sprites[tag]);
                }
            }

            return(DefaultSpriteFrame);
        }
Exemple #32
0
        public ResourceEntity(ResourceLibrary.ResourceType resourceType, Vector3 position)
            : base(ResourceLibrary.ResourceNames[resourceType], PlayState.ComponentManager.RootComponent, Matrix.CreateTranslation(position), new Vector3(0.25f, 0.25f, 0.25f), Vector3.Zero, 0.5f, 0.5f, 0.999f, 0.999f, new Vector3(0, -10, 0))
        {
            Restitution = 0.1f;
            Friction = 0.1f;
            Resource type = ResourceLibrary.Resources[resourceType];
            SpriteSheet spriteSheet = new SpriteSheet(type.Image.AssetName);

            int frameX = type.Image.SourceRect.X / 32;
            int frameY = type.Image.SourceRect.Y / 32;

            List<Point> frames = new List<Point>
            {
                new Point(frameX, frameY)
            };
            Animation animation = new Animation(GameState.Game.GraphicsDevice, new SpriteSheet(type.Image.AssetName), "Animation", 32, 32, frames, false, Color.White, 0.01f, 0.75f, 0.75f, false);

            Sprite sprite = new Sprite(PlayState.ComponentManager, "Sprite", this, Matrix.CreateTranslation(Vector3.UnitY * 0.25f), spriteSheet, false)
            {
                OrientationType = Sprite.OrientMode.Spherical,
                LightsWithVoxels = !type.SelfIlluminating
            };
            sprite.AddAnimation(animation);

            animation.Play();

            Tags.Add(type.ResourceName);
            Tags.Add("Resource");
            Bobber bobber = new Bobber(0.05f, 2.0f, MathFunctions.Rand() * 3.0f, sprite);

            if (type.IsFlammable)
            {
                Health health = new Health(PlayState.ComponentManager, "health", this, 10.0f, 0.0f, 10.0f);
                new Flammable(PlayState.ComponentManager, "Flames", this, health);

            }
        }
Exemple #33
0
 public bool Verify(List<Voxel> refs, ResourceLibrary.ResourceType type)
 {
     ResourceAmount requiredResources = new ResourceAmount(type, refs.Count);
     List<ResourceAmount> res = new List<ResourceAmount>() {requiredResources};
     return Faction.HasResources(res);
 }
Exemple #34
0
 public ResourceAmount(ResourceLibrary.ResourceType type)
 {
     ResourceType = ResourceLibrary.Resources[type];
     NumResources = 1;
 }
Exemple #35
0
 public ResourceAmount(ResourceLibrary.ResourceType type, int num)
     : this(ResourceLibrary.Resources[type], num)
 {
 }
Exemple #36
0
 public int GetNumRequiredResources(ResourceLibrary.ResourceType name)
 {
     if(ToBuild.RoomData.RequiredResources.ContainsKey(name))
     {
         return Math.Max((int) (ToBuild.RoomData.RequiredResources[name].NumResources * VoxelOrders.Count * 0.25f), 1);
     }
     else
     {
         return 0;
     }
 }
Exemple #37
0
        public bool IsResourceSatisfied(ResourceLibrary.ResourceType name)
        {
            int required = GetNumRequiredResources(name);
            int current = 0;

            if(PutResources.ContainsKey(name))
            {
                current = (int) PutResources[name].NumResources;
            }

            return current >= required;
        }