Esempio n. 1
0
        public void AddResources(List <ResourceAmount> resources)
        {
            foreach (ResourceAmount resource in resources)
            {
                ResourceLibrary.ResourceType resourceName = resource.ResourceType.Type;
                if (PutResources.ContainsKey(resourceName))
                {
                    ResourceAmount amount = PutResources[resourceName];
                    amount.NumResources += resource.NumResources;
                }
                else
                {
                    ResourceAmount amount = new ResourceAmount();
                    amount.NumResources += resource.NumResources;
                    amount.ResourceType  = resource.ResourceType;

                    PutResources[resourceName] = amount;
                }
            }

            if (MeetsBuildRequirements())
            {
                Build();
            }
        }
Esempio n. 2
0
 public bool HasResources(ResourceLibrary.ResourceType resource)
 {
     return(HasResources(new List <ResourceAmount>()
     {
         new ResourceAmount(resource)
     }));
 }
Esempio n. 3
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));
            }
        }
Esempio n. 4
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;
 }
Esempio n. 5
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));
        }
Esempio n. 6
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);
     }
 }
Esempio n. 7
0
 public Resource(ResourceLibrary.ResourceType type, float money, string description, NamedImageFrame image, int NewGuiSprite, Color tint, params ResourceTags[] tags)
 {
     Type              = type;
     MoneyValue        = money;
     Description       = description;
     Image             = image;
     this.NewGuiSprite = NewGuiSprite;
     Tint              = tint;
     Tags              = new List <ResourceTags>();
     Tags.AddRange(tags);
     FoodContent = 0;
 }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        /// <summary>
        /// If the creature has meat or bones, creates resources
        /// which get released when the creature dies.
        /// </summary>
        public virtual void CreateMeatAndBones()
        {
            if (HasMeat)
            {
                ResourceLibrary.ResourceType type = Species + " " + ResourceLibrary.ResourceType.Meat;

                if (!ResourceLibrary.Resources.ContainsKey(type))
                {
                    ResourceLibrary.Add(new Resource(ResourceLibrary.GetMeat(Species))
                    {
                        Type      = type,
                        ShortName = type
                    });
                }

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

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

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

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

            if (HasCorpse)
            {
                ResourceLibrary.ResourceType type = AI.Stats.FullName + "'s " + "Corpse";

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

                Inventory.AddResource(new ResourceAmount(type, 1));
            }
        }
Esempio n. 11
0
        public Point GetSpritesheetFrame(ResourceLibrary.ResourceType resourceType)
        {
            var resource = ResourceLibrary.GetResourceByName(resourceType);

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

            return(DefaultSpriteFrame);
        }
Esempio n. 12
0
        public float GetPrice(ResourceLibrary.ResourceType type)
        {
            Resource item  = ResourceLibrary.GetResourceByName(type);
            float    price = item.MoneyValue;

            if (IsRare(type))
            {
                price *= 2;
            }
            else if (IsCommon(type))
            {
                price *= 0.5f;
            }

            return(price);
        }
Esempio n. 13
0
        public static CraftItem ResourceToCraftItem(ResourceLibrary.ResourceType resource)
        {
            Resource res = ResourceLibrary.GetResourceByName(resource);

            return(new CraftItem()
            {
                Name = resource,
                BaseCraftTime = 30,
                CraftLocation = "Forge",
                Description = res.Description,
                Icon = res.GuiLayers[0],
                RequiredResources = res.CraftPrereqs,
                ResourceCreated = resource,
                Type = CraftItem.CraftType.Resource
            });
        }
Esempio n. 14
0
 public Resource(ResourceLibrary.ResourceType type, DwarfBux money, string description, NamedImageFrame image, int WidgetsSprite, Color tint, params ResourceTags[] tags)
 {
     Type           = type;
     MoneyValue     = money;
     Description    = description;
     Image          = image;
     this.GuiLayers = new List <TileReference>();
     GuiLayers.Add(new TileReference("resources", WidgetsSprite));
     Tint = tint;
     Tags = new List <ResourceTags>();
     Tags.AddRange(tags);
     FoodContent     = 0;
     CanCraft        = false;
     CraftPrereqs    = new List <Quantitiy <Resource.ResourceTags> >();
     CompositeLayers = null;
     AleName         = "";
 }
Esempio n. 15
0
        public bool IsAllowed(ResourceLibrary.ResourceType type)
        {
            Resource resource = ResourceLibrary.GetResourceByName(type);

            if (WhitelistResources.Count == 0)
            {
                if (BlacklistResources.Count == 0)
                {
                    return(true);
                }

                return(!BlacklistResources.Any(tag => resource.Tags.Any(otherTag => otherTag == tag)));
            }

            if (BlacklistResources.Count != 0)
            {
                return(true);
            }
            return(WhitelistResources.Count == 0 || WhitelistResources.Any(tag => resource.Tags.Any(otherTag => otherTag == tag)));
        }
Esempio n. 16
0
        public Mushroom(ComponentManager Manager,
                        Vector3 position,
                        string asset,
                        ResourceLibrary.ResourceType resource,
                        int numRelease, bool selfIlluminate, string seedlingsheet) :
            base(Manager, "Mushroom", Matrix.Identity, new Vector3(1.0f, 1.0f, 1.0f),
                 System.IO.Path.GetFileName(asset), 1.0f)
        {
            SeedlingAsset = seedlingsheet;
            Matrix matrix = Matrix.CreateRotationY(MathFunctions.Rand(-0.1f, 0.1f));

            matrix.Translation = position;// + new Vector3(0.5f, 0.0f, 0.5f);
            LocalTransform     = matrix;

            Inventory inventory = AddChild(new Inventory(Manager, "Inventory", BoundingBox.Extents(), LocalBoundingBoxOffset)) as Inventory;

            for (int i = 0; i < numRelease; i++)
            {
                inventory.Resources.Add(new Inventory.InventoryItem()
                {
                    MarkedForRestock = false,
                    MarkedForUse     = false,
                    Resource         = resource
                });
            }

            var particles = AddChild(new ParticleTrigger("Leaves", Manager, "LeafEmitter",
                                                         Matrix.Identity, LocalBoundingBoxOffset, GetBoundingBox().Extents())
            {
                SoundToPlay = ContentPaths.Audio.Oscar.sfx_env_bush_harvest_1
            }) as ParticleTrigger;

            AddChild(new Health(Manager.World.ComponentManager, "HP", 30, 0.0f, 30));
            AddChild(new Flammable(Manager.World.ComponentManager, "Flames"));

            Tags.Add("Mushroom");
            Tags.Add("Vegetation");
            CollisionType = CollisionManager.CollisionType.Static;
            PropogateTransforms();
        }
Esempio n. 17
0
        public ResourceEntity(ResourceLibrary.ResourceType resourceType, Vector3 position) :
            base(ResourceLibrary.Resources[resourceType].ResourceName, 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, type.Tint, 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);
            }
        }
Esempio n. 18
0
        private void CreateGraphics()
        {
            Physics.AddChild(new Shadow(Manager));

            var animFile = Bonesnake ? ContentPaths.Entities.Animals.Snake.bonesnake_animation :
                           ContentPaths.Entities.Animals.Snake.snake_animation;

            var tailFile = Bonesnake ? ContentPaths.Entities.Animals.Snake.bonetail_animation :
                           ContentPaths.Entities.Animals.Snake.tail_animation;


            var sprite = CreateSprite(animFile, Manager, 0.0f);

            Tail = new List <TailSegment>();

            for (int i = 0; i < 10; ++i)
            {
                var tailPiece = CreateSprite(tailFile, Manager, 0.0f, false);

                Tail.Add(
                    new TailSegment()
                {
                    Sprite = Manager.RootComponent.AddChild(tailPiece) as Body,
                    Target = Physics.LocalTransform.Translation
                });


                tailPiece.AddChild(new Shadow(Manager));

                var inventory = tailPiece.AddChild(new Inventory(Manager, "Inventory", Physics.BoundingBox.Extents(), Physics.LocalBoundingBoxOffset)) as Inventory;
                inventory.SetFlag(Flag.ShouldSerialize, false);

                if (HasMeat)
                {
                    ResourceLibrary.ResourceType type = Species + " " + ResourceLibrary.ResourceType.Meat;

                    if (!ResourceLibrary.Resources.ContainsKey(type))
                    {
                        ResourceLibrary.Add(new Resource(ResourceLibrary.GetMeat(Species))
                        {
                            Type      = type,
                            ShortName = type
                        });
                    }

                    inventory.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.AddResource(new ResourceAmount(type, 1));
                }
            }
        }
Esempio n. 19
0
 bool IsCommon(ResourceLibrary.ResourceType resource)
 {
     return(CommonThings.Any(tags => ResourceLibrary.GetResourceByName(resource).Tags.Contains(tags)));
 }
Esempio n. 20
0
 bool IsHated(ResourceLibrary.ResourceType resource)
 {
     return(HatedThings.Any(tags => ResourceLibrary.GetResourceByName(resource).Tags.Contains(tags)));
 }
Esempio n. 21
0
        public Tree(Vector3 position, string asset, ResourceLibrary.ResourceType seed, float treeSize) :
            base("Tree", PlayState.ComponentManager.RootComponent, Matrix.Identity, new Vector3(treeSize * 2, treeSize * 3, treeSize * 2), new Vector3(treeSize * 0.5f, treeSize * 0.25f, treeSize * 0.5f))
        {
            Seedlingsheet = new SpriteSheet(ContentPaths.Entities.Plants.vine, 32, 32);
            SeedlingFrame = new Point(0, 0);
            HurtTimer     = new Timer(1.0f, false);
            ComponentManager componentManager = PlayState.ComponentManager;
            Matrix           matrix           = Matrix.Identity;

            matrix.Translation = position;
            LocalTransform     = matrix;

            new Mesh(componentManager, "Model", this, Matrix.CreateRotationY((float)(PlayState.Random.NextDouble() * Math.PI)) * Matrix.CreateScale(treeSize, treeSize, treeSize) * Matrix.CreateTranslation(new Vector3(0.7f, 0.0f, 0.7f)), asset, false);

            Health health = new Health(componentManager, "HP", this, 100.0f * treeSize, 0.0f, 100.0f * treeSize);

            new Flammable(componentManager, "Flames", this, health);


            Tags.Add("Vegetation");
            Tags.Add("EmitsWood");

            //new MinimapIcon(this, new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.map_icons), 16, 1, 0));
            Voxel voxelUnder = new Voxel();

            if (PlayState.ChunkManager.ChunkData.GetFirstVoxelUnder(position, ref voxelUnder))
            {
                new VoxelListener(componentManager, this, PlayState.ChunkManager, voxelUnder);
            }

            Inventory inventory = new Inventory("Inventory", this)
            {
                Resources = new ResourceContainer
                {
                    MaxResources = 500
                }
            };

            inventory.Resources.AddResource(new ResourceAmount()
            {
                NumResources = (int)(treeSize * 10),
                ResourceType = ResourceLibrary.Resources[ResourceLibrary.ResourceType.Wood]
            });


            inventory.Resources.AddResource(new ResourceAmount()
            {
                NumResources = (int)(treeSize * 2),
                ResourceType = ResourceLibrary.Resources[seed]
            });


            Particles = new ParticleTrigger("Leaves", componentManager, "LeafEmitter", this,
                                            Matrix.Identity, new Vector3(treeSize * 2, treeSize * 3, treeSize * 2), new Vector3(treeSize * 0.5f, treeSize * 0.25f, treeSize * 0.5f))
            {
                SoundToPlay = ContentPaths.Audio.vegetation_break
            };


            AddToCollisionManager = true;
            CollisionType         = CollisionManager.CollisionType.Static;
        }
Esempio n. 22
0
 public ResourceAmount(ResourceLibrary.ResourceType type)
 {
     ResourceType = ResourceLibrary.Resources[type];
     NumResources = 1;
 }
Esempio n. 23
0
 public ResourceAmount(ResourceLibrary.ResourceType type, int num) :
     this(ResourceLibrary.Resources[type], num)
 {
 }
Esempio n. 24
0
 public static void Initialize()
 {
     EntityFuncs = new Dictionary <string, Func <Vector3, Blackboard, GameComponent> >();
     RegisterEntity("Crate", (position, data) => new Crate(position));
     foreach (var resource in ResourceLibrary.Resources)
     {
         ResourceLibrary.ResourceType type = resource.Value.Type;
         RegisterEntity(resource.Key + " Resource", (position, data) => new ResourceEntity(type, position));
     }
     RegisterEntity("Balloon", (position, data) => CreateBalloon(position + new Vector3(0, 1000, 0), position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, null, PlayState.PlayerFaction));
     RegisterEntity("Work Pile", (position, data) => new WorkPile(position));
     RegisterEntity("Pine Tree", (position, data) => new Tree(position, "pine", data.GetData("Scale", 1.0f)));
     RegisterEntity("Snow Pine Tree", (position, data) => new Tree(position, "snowpine", data.GetData("Scale", 1.0f)));
     RegisterEntity("Palm Tree", (position, data) => new Tree(position, "palm", data.GetData("Scale", 1.0f)));
     RegisterEntity("Berry Bush", (position, data) => new Bush(position, "berrybush", data.GetData("Scale", 1.0f)));
     RegisterEntity("Bird", (position, data) => new Bird(ContentPaths.Entities.Animals.Birds.GetRandomBird(), position, PlayState.ComponentManager, PlayState.ChunkManager, GameState.Game.GraphicsDevice, GameState.Game.Content, "Bird"));
     RegisterEntity("Deer", (position, data) => new Deer(ContentPaths.Entities.Animals.Deer.deer, position, PlayState.ComponentManager, PlayState.ChunkManager, GameState.Game.GraphicsDevice, GameState.Game.Content, "Deer"));
     RegisterEntity("Dwarf", (position, data) => GenerateDwarf(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.PlayerFaction, PlayState.PlanService, "Player", JobLibrary.Classes[JobLibrary.JobType.Worker], 0));
     RegisterEntity("TestDwarf", (position, data) => GenerateTestDwarf(position));
     RegisterEntity("TestGoblin", (position, data) => GenerateTestGoblin(position));
     RegisterEntity("TestSkeleton", (position, data) => GenerateTestSeketon(position));
     RegisterEntity("TestMoleman", (position, data) => GenerateTestMoleman(position));
     RegisterEntity("AxeDwarf", (position, data) => GenerateDwarf(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.PlayerFaction, PlayState.PlanService, "Player", JobLibrary.Classes[JobLibrary.JobType.AxeDwarf], 0));
     RegisterEntity("CraftsDwarf", (position, data) => GenerateDwarf(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.PlayerFaction, PlayState.PlanService, "Player", JobLibrary.Classes[JobLibrary.JobType.CraftsDwarf], 0));
     RegisterEntity("Wizard", (position, data) => GenerateDwarf(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.PlayerFaction, PlayState.PlanService, "Player", JobLibrary.Classes[JobLibrary.JobType.Wizard], 0));
     RegisterEntity("Moleman", (position, data) => GenerateMoleman(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.ComponentManager.Factions.Factions["Molemen"], PlayState.PlanService, "Molemen"));
     RegisterEntity("Goblin", (position, data) => GenerateGoblin(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.ComponentManager.Factions.Factions["Goblins"], PlayState.PlanService, "Goblins"));
     RegisterEntity("Skeleton", (position, data) => GenerateSkeleton(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.ComponentManager.Factions.Factions["Undead"], PlayState.PlanService, "Undead"));
     RegisterEntity("Necromancer", (position, data) => GenerateNecromancer(position, PlayState.ComponentManager, GameState.Game.Content, GameState.Game.GraphicsDevice, PlayState.ChunkManager, PlayState.Camera, PlayState.ComponentManager.Factions.Factions["Undead"], PlayState.PlanService, "Undead"));
     RegisterEntity("Bed", (position, data) => new Bed(position));
     RegisterEntity("Bear Trap", (position, data) => new BearTrap(position));
     RegisterEntity("Lamp", (position, data) => new Lamp(position));
     RegisterEntity("Table", (position, data) => new Table(position));
     RegisterEntity("Chair", (position, data) => new Chair(position));
     RegisterEntity("Flag", (position, data) => new Flag(position));
     RegisterEntity("Mushroom", (position, data) => new Mushroom(position));
     RegisterEntity("Wheat", (position, data) => new Wheat(position));
     RegisterEntity("BookTable", (position, data) => new Table(position, new SpriteSheet(ContentPaths.Entities.Furniture.interior_furniture, 32), new Point(0, 4))
     {
         Tags = new List <string>()
         {
             "Research"
         }, Battery = new Table.ManaBattery()
         {
             Charge = 0.0f, MaxCharge = 100.0f
         }
     });
     RegisterEntity("PotionTable", (position, data) => new Table(position, new SpriteSheet(ContentPaths.Entities.Furniture.interior_furniture, 32), new Point(1, 4))
     {
         Tags = new List <string>()
         {
             "Research"
         }, Battery = new Table.ManaBattery()
         {
             Charge = 0.0f, MaxCharge = 100.0f
         }
     });
     RegisterEntity("Anvil", (position, data) => new Anvil(position));
     RegisterEntity("Forge", (position, data) => new Forge(position));
     RegisterEntity("Elf", (position, data) => GenerateElf(position, PlayState.ComponentManager.Factions.Factions["Elf"], "Elf"));
     RegisterEntity("Arrow", (position, data) => new ArrowProjectile(position, data.GetData("Velocity", Vector3.Up * 10 + MathFunctions.RandVector3Box(-10, 10, 0, 0, -10, 10)), data.GetData("Faction", "Elf")));
     RegisterEntity("Fairy", (position, data) => new Fairy("Player", position));
     RegisterEntity("Target", (position, data) => new Target(position));
     RegisterEntity("Strawman", (position, data) =>
     {
         float value = (float)PlayState.Random.NextDouble();
         return(value < 0.33
             ? (Body)(new Strawman(position))
             : (value < 0.66 ? (Body)(new WeightRack(position)) : (Body)(new PunchingBag(position))));
     });
     RegisterEntity("Bookshelf", (position, data) => new Bookshelf(position));
     RegisterEntity("Door", (position, data) => new Door(position));
     RegisterEntity("Ladder", (position, data) => new Ladder(position));
 }
Esempio n. 25
0
        public Mushroom(ComponentManager componentManager,
                        Vector3 position,
                        string asset,
                        ResourceLibrary.ResourceType resource,
                        int numRelease, bool selfIlluminate) :
            base("Mushroom", componentManager.RootComponent, Matrix.Identity, new Vector3(1.0f, 1.0f, 1.0f), Vector3.Zero)
        {
            Seedlingsheet = new SpriteSheet(ContentPaths.Entities.Plants.deadbush, 32, 32);
            SeedlingFrame = new Point(0, 0);
            Matrix matrix = Matrix.CreateRotationY(MathFunctions.Rand(-0.1f, 0.1f));

            matrix.Translation = position + new Vector3(0.5f, -0.25f, 0.5f);
            LocalTransform     = matrix;

            SpriteSheet spriteSheet = new SpriteSheet(asset);

            List <Point> frames = new List <Point>
            {
                new Point(0, 0)
            };
            Animation animation = new Animation(GameState.Game.GraphicsDevice, spriteSheet, "Mushroom", 32, 32, frames, false, Color.White, 0.01f, 1.0f, 1.0f, false);

            Sprite sprite = new Sprite(componentManager, "sprite", this, Matrix.Identity, spriteSheet, false)
            {
                OrientationType  = Sprite.OrientMode.Fixed,
                LightsWithVoxels = !selfIlluminate
            };

            sprite.AddAnimation(animation);

            Sprite sprite2 = new Sprite(componentManager, "sprite2", this, Matrix.CreateRotationY((float)Math.PI * 0.5f), spriteSheet, false)
            {
                OrientationType  = Sprite.OrientMode.Fixed,
                LightsWithVoxels = !selfIlluminate
            };

            sprite2.AddAnimation(animation);

            Voxel voxelUnder = new Voxel();
            bool  success    = componentManager.World.ChunkManager.ChunkData.GetFirstVoxelUnder(position, ref voxelUnder);

            if (success)
            {
                VoxelListener listener = new VoxelListener(componentManager.World.ComponentManager, this, componentManager.World.ChunkManager, voxelUnder);
            }

            Inventory inventory = new Inventory("Inventory", this)
            {
                Resources = new ResourceContainer()
                {
                    MaxResources = 2,
                    Resources    = new Dictionary <ResourceLibrary.ResourceType, ResourceAmount>()
                    {
                        {
                            resource,
                            new ResourceAmount(resource, numRelease)
                        }
                    }
                }
            };

            Health health = new Health(componentManager.World.ComponentManager, "HP", this, 30, 0.0f, 30);

            new Flammable(componentManager.World.ComponentManager, "Flames", this, health);

            animation.Play();
            Tags.Add("Mushroom");
            Tags.Add("Vegetation");
            CollisionType = CollisionManager.CollisionType.Static;
        }
Esempio n. 26
0
 public int GetResourceCount(ResourceLibrary.ResourceType resourceType)
 {
     return(!Resources.ContainsKey(resourceType) ? 0 : Resources[resourceType].NumResources);
 }
Esempio n. 27
0
        public Tree(string name, ComponentManager manager, Vector3 position, string asset, ResourceLibrary.ResourceType seed, float treeSize, string seedlingAsset, bool emitWood = true) :
            base(manager, name, Matrix.Identity,
                 new Vector3(
                     PrimitiveLibrary.BatchBillboardPrimitives[asset].Width * 0.75f * treeSize,
                     PrimitiveLibrary.BatchBillboardPrimitives[asset].Height * treeSize,
                     PrimitiveLibrary.BatchBillboardPrimitives[asset].Width * 0.75f * treeSize),
                 asset, treeSize)
        {
            SeedlingAsset = seedlingAsset;
            HurtTimer     = new Timer(1.0f, false);
            Matrix matrix = Matrix.Identity;

            matrix.Translation = position;
            LocalTransform     = matrix;


            AddChild(new Health(Manager, "HP", 100.0f * treeSize, 0.0f, 100.0f * treeSize));
            AddChild(new Flammable(Manager, "Flames"));

            Tags.Add("Vegetation");
            if (emitWood)
            {
                Tags.Add("EmitsWood");
            }

            /*
             * var voxelUnder = VoxelHelpers.FindFirstVoxelBelow(new VoxelHandle(
             *  manager.World.ChunkManager.ChunkData,
             *  GlobalVoxelCoordinate.FromVector3(position)));
             * if (voxelUnder.IsValid)
             *  AddChild(new VoxelListener(manager, manager.World.ChunkManager,
             *      voxelUnder));
             * //*/

            Inventory inventory = AddChild(new Inventory(Manager, "Inventory", BoundingBoxSize, LocalBoundingBoxOffset)) as Inventory;

            // Can these be spawned when the tree dies rather than when it is created?
            if (emitWood)
            {
                for (int i = 0; i < treeSize * 2; i++)
                {
                    inventory.Resources.Add(new Inventory.InventoryItem()
                    {
                        MarkedForRestock = false,
                        MarkedForUse     = false,
                        Resource         = ResourceLibrary.ResourceType.Wood
                    });
                }
            }

            for (int i = 0; i < treeSize * 2; i++)
            {
                inventory.Resources.Add(new Inventory.InventoryItem()
                {
                    MarkedForRestock = false,
                    MarkedForUse     = false,
                    Resource         = seed
                });
            }

            AddChild(new ParticleTrigger("Leaves", Manager, "LeafEmitter",
                                         Matrix.Identity, LocalBoundingBoxOffset, GetBoundingBox().Extents())
            {
                SoundToPlay = ContentPaths.Audio.Oscar.sfx_env_tree_cut_down_1
            });

            CollisionType = CollisionManager.CollisionType.Static;
            PropogateTransforms();
        }