Exemple #1
0
        public void Hit(object message)
        {
            if (!(message is HitMessage))
            {
                return;
            }

            // Tree has been hit (by an axe), so we create some wood cylinders the player can pick up

            ContainingWorld.RemoveEntity(thisEntity);

            // Gather wood from "real" trees only, not from cacti etc.
            if (treeType != TreeType.Birch)
            {
                return;
            }

            int numberOfWoodCylinders = 3 * (int)(amountOfWood + 1.0f);

            for (int i = 0; i < numberOfWoodCylinders; ++i)
            {
                ItemEntity itemEntity = new ItemEntity(new MaterialItem(TerrainResource.FromName("BirchWood"), MaterialShape.Cylinder, new vec3(0.2f, 0.7f, 0.2f)));
                ContainingWorld.AddEntity(itemEntity, mat4.Translate(Position + new vec3(0, 1 + i, 0)));
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes all crafting rules
        /// </summary>
        public void InitCraftingRules()
        {
            Debug.Assert(craftingRules.Count == 0, "Expected empty ruleset");

            TerrainResource dirt       = TerrainResource.FromName("Dirt");
            TerrainResource wood       = TerrainResource.FromName("Wood");
            TerrainResource iron       = TerrainResource.FromName("Iron");
            TerrainResource coal       = TerrainResource.FromName("Coal");
            TerrainResource gold       = TerrainResource.FromName("Gold");
            TerrainResource copper     = TerrainResource.FromName("Copper");
            TerrainResource aoicrystal = TerrainResource.FromName("AoiCrystal");

            /*craftingRules.Add(new ExplicitCraftingRule(new MaterialItem(dirt, MaterialShape.Cube, new vec3(1)),
             *                                         new [] { new ResourceItem(dirt, 1f) } ,
             *                                         new [] { new ResourceItem(dirt, .5f) } ));*/

            // Tools

            craftingRules.Add(new ExplicitCraftingRule(new ToolItem(ToolType.Pickaxe),
                                                       (new [] { new ResourceItem(iron, 1f), new ResourceItem(wood, 1f) }),
                                                       (new [] { new ResourceItem(iron, .1f), new ResourceItem(wood, .2f) })));
            craftingRules.Add(new ExplicitCraftingRule(new ToolItem(ToolType.Axe),
                                                       (new [] { new ResourceItem(iron, 1f), new ResourceItem(wood, 1f) }),
                                                       (new [] { new ResourceItem(iron, .1f), new ResourceItem(wood, .2f) })));
            craftingRules.Add(new ExplicitCraftingRule(new ToolItem(ToolType.Shovel),
                                                       (new [] { new ResourceItem(iron, 1f), new ResourceItem(wood, 1f) }),
                                                       (new [] { new ResourceItem(iron, .1f), new ResourceItem(wood, .2f) })));
            craftingRules.Add(new ExplicitCraftingRule(new ToolItem(ToolType.Hammer),
                                                       (new [] { new ResourceItem(iron, 4f), new ResourceItem(wood, 2f) }),
                                                       (new [] { new ResourceItem(iron, .2f), new ResourceItem(wood, .3f) })));

            // MaterialItems
            List <TerrainResource> craftMaterials = new List <TerrainResource>();

            craftMaterials.Add(dirt);
            craftMaterials.Add(wood);
            craftMaterials.Add(coal);
            craftMaterials.Add(iron);
            craftMaterials.Add(gold);
            craftMaterials.Add(aoicrystal);
            craftMaterials.Add(copper);
            for (int i = 1; i <= 14; ++i)
            {
                craftMaterials.Add(TerrainResource.FromName("Stone." + i.ToString("00")));
            }

            foreach (var mat in craftMaterials)
            {
                craftingRules.Add(new MaterialCraftingRule(mat, MaterialShape.Cube, new vec3(1)));
                craftingRules.Add(new MaterialCraftingRule(mat, MaterialShape.Cylinder, new vec3(1)));
                craftingRules.Add(new MaterialCraftingRule(mat, MaterialShape.Sphere, new vec3(1)));
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes the terrain materials and settings.
        /// </summary>
        public static void init(World world)
        {
            Instance       = new UpvoidMinerWorldGenerator();
            Instance.world = world;

            // Register all terrain resources (and thus terrain materials).
            TerrainResource.RegisterResources(world.Terrain);

            // Get handle to dirt for generation.
            Instance.terrainDirt   = TerrainResource.FromName("Dirt");
            Instance.terrainRock   = TerrainResource.FromName("Stone.09");
            Instance.terrainDesert = TerrainResource.FromName("Desert");

            // load entities
            LoadEntities();

            // init terrain
            world.SetTerrainGenerator(new TerrainGenerator());
            world.TerrainGenerator.SetCsgNode(Instance.createTerrain());
        }
        /// <summary>
        /// Starts
        /// </summary>
        public static void Startup(IntPtr _unmanagedModule)
        {
            // Get and save the resource domain of the mod, needed for loading resources.
            UpvoidMiner.Mod       = Module.FromHandle(_unmanagedModule);
            UpvoidMiner.ModDomain = UpvoidMiner.Mod.ResourceDomain;

            // Create the world. Multiple worlds could be created here, but we only want one.
            // Use the UpvoidMinerWorldGenerator, which will create a simple terrain with some vegetation.
            World world = Universe.CreateWorld("UpvoidMinerWorld");

            UpvoidMinerWorldGenerator.init(world);
            world.Start();

            for (int i = 0; i < 3; ++i)
            {
                TerrainResource mat = TerrainResource.FromName("Stone." + (i + 1).ToString("00"));
                Debug.Assert(mat != null, "Invalid material");
                MaterialItem testItem = new MaterialItem(mat, MaterialShape.Cube, new vec3(1), 1);

                world.AddEntity(new ItemEntity(testItem), mat4.Translate(new vec3(5f, i * 2f, ((i % 3) * 2f))));
            }
        }
Exemple #5
0
        public override void OnUse(Player player, vec3 _worldPos, vec3 _worldNormal, Entity _hitEntity)
        {
            switch (ToolType)
            {
            case ToolType.Pickaxe:
                // Pickaxe has small radius but can dig everywhere
                player.DigMaterial(_worldNormal, _worldPos, digRadiusPickaxe, null);

                return;

            case ToolType.Shovel:
                // Shovel has big radius but can only dig dirt
                player.DigMaterial(_worldNormal, _worldPos, digRadiusShovel, new[] { TerrainResource.FromName("Dirt").Index, TerrainResource.FromName("Desert").Index });
                return;

            case ToolType.Axe:
                if (_hitEntity != null)
                {
                    _hitEntity[TriggerId.getIdByName("Hit")] |= new HitMessage(player.thisEntity);
                }
                return;

            case ToolType.DroneChain:
                // Add a drone to the use-position.
                player.AddDrone(_worldPos);
                // Remove that drone from inventory.
                player.Inventory.RemoveItem(new ToolItem(ToolType));
                return;

            case ToolType.Hammer:
                // TODO
                return;

            default:
                throw new InvalidOperationException("Unknown tool");
            }
        }
Exemple #6
0
        /// <summary>
        /// Populates the inventory with a list of items that we start with.
        /// </summary>
        void generateInitialItems()
        {
            if (!File.Exists(UpvoidMiner.SavePathInventory))
            {
                // Tools
                Inventory.AddItem(new ToolItem(ToolType.Shovel));
                Inventory.AddItem(new ToolItem(ToolType.Pickaxe));
                Inventory.AddItem(new ToolItem(ToolType.Axe));
                //Inventory.AddItem(new ToolItem(ToolType.Hammer));
                Inventory.AddItem(new ToolItem(ToolType.DroneChain, 5));

                // Testing resource/material items.

                /*TerrainResource dirt = ContainingWorld.Terrain.QueryMaterialFromName("Dirt");
                *  TerrainResource stone06 = ContainingWorld.Terrain.QueryMaterialFromName("Stone.06");
                *  Inventory.AddResource(dirt, 10);
                *  Inventory.AddItem(new ResourceItem(dirt, 3f));
                *  Inventory.AddItem(new MaterialItem(stone06, MaterialShape.Sphere, new vec3(1)));
                *  Inventory.AddItem(new MaterialItem(stone06, MaterialShape.Sphere, new vec3(1), 2));
                *  Inventory.AddItem(new MaterialItem(stone06, MaterialShape.Cylinder, new vec3(1,2,2)));
                *  Inventory.AddItem(new MaterialItem(stone06, MaterialShape.Sphere, new vec3(2)));
                *  Inventory.AddItem(new MaterialItem(stone06, MaterialShape.Cube, new vec3(2)));
                *  Inventory.AddItem(new MaterialItem(stone06, MaterialShape.Cylinder, new vec3(1,2,2)));
                *  Inventory.AddItem(new MaterialItem(dirt, MaterialShape.Sphere, new vec3(1)));*/
                Inventory.AddItem(new MaterialItem(TerrainResource.FromName("AoiCrystal"), MaterialShape.Sphere, new vec3(1)));
                Inventory.AddItem(new MaterialItem(TerrainResource.FromName("FireRock"), MaterialShape.Cube, new vec3(1)));
                Inventory.AddItem(new MaterialItem(TerrainResource.FromName("AlienRock"), MaterialShape.Cylinder, new vec3(1)));
            }
            else // Load inventory
            {
                InventorySave save = JsonConvert.DeserializeObject <InventorySave>(File.ReadAllText(UpvoidMiner.SavePathInventory));

                Dictionary <long, Item> id2item = new Dictionary <long, Item>();
                foreach (var item in save.toolItems)
                {
                    id2item.Add(item.Id, new ToolItem(item.Type, item.StackSize));
                    Inventory.AddItem(id2item[item.Id]);
                }
                foreach (var item in save.materialItems)
                {
                    id2item.Add(item.Id, new MaterialItem(TerrainResource.FromName(item.Resource), item.Shape, new vec3(item.SizeX, item.SizeY, item.SizeZ), item.StackSize));
                    Inventory.AddItem(id2item[item.Id]);
                }
                foreach (var item in save.resourceItems)
                {
                    id2item.Add(item.Id, new ResourceItem(TerrainResource.FromName(item.Resource), item.Volume));
                    Inventory.AddItem(id2item[item.Id]);
                }

                Inventory.ClearQuickAccess();
                for (int i = 0; i < Inventory.QuickaccessSlots; ++i)
                {
                    if (id2item.ContainsKey(save.quickAccess[i]))
                    {
                        Inventory.SetQuickAccess(id2item[save.quickAccess[i]], i);
                    }
                }
                Inventory.Select(save.currentQuickAccess);
            }

            Gui.OnUpdate();
        }