Esempio n. 1
0
        private void DoAction(Mine2D game, int buttonNumber)
        {
            switch (buttonNumber)
            {
                case 0:
                    game.gameState = GameState.Playing;
                    break;

                case 1:
                    System.Windows.Forms.SaveFileDialog saveWorld = new System.Windows.Forms.SaveFileDialog();
                    saveWorld.Filter = "Сжатые миры Mine2D|*.m2d";
                    if (saveWorld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        game.gameState = GameState.SavingWorld;
                        new System.Threading.Thread(delegate()
                        {
                            LevelManager.SaveLevel(game, saveWorld.FileName);
                        }).Start();
                    }
                    break;

                case 2:
                    LevelManager.RecreateLevel(game);
                    game.gameState = GameState.MainMenu;
                    break;
            }
        }
Esempio n. 2
0
 public static void RecreateLevel(Mine2D game)
 {
     game.world = new World();
     game.camera = new Camera(new Rectangle(0, 0, 1024, 768));
     game.player = new Player(ref game.camera, game.Content);
     game.smallInventory = new SmallInventory();
     game.normalInventory = new NormalInventory();
 }
Esempio n. 3
0
        public void Draw(Mine2D game, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(game.workbenchInventoryTex, new Vector2(248, 135), Color.White);

            // Малый инвентарь
            for (int i = 0; i < 9; i++)
            {
                if (game.smallInventory.inventoryContents[i] != null)
                {
                    spriteBatch.Draw(game.smallInventory.inventoryContents[i].texture, new Vector2(248 + 20 + (i * 54 + 4), 135 + 423 + 3), Color.White);
                    game.smallInventory.inventoryContents[i].DrawDamage(spriteBatch, game, 248 + 20 + (i * 54 + 4), 135 + 423 + 3);
                    game.smallInventory.inventoryContents[i].DrawAmountNormalInventory(spriteBatch, game.font, i, 423);
                }
            }

            // Нормальный инвентарь
            for (int row = 0; row < 3; row++)
            {
                for (int i = 0; i < 9; i++)
                {
                    if (game.normalInventory.inventoryContents[(row * 9) + i] != null)
                    {
                        spriteBatch.Draw(game.normalInventory.inventoryContents[(row * 9) + i].texture, new Vector2(248 + 20 + (i * 54 + 4), 135 + (row * 54 + 249) + 3), Color.White);
                        game.normalInventory.inventoryContents[(row * 9) + i].DrawDamage(spriteBatch, game, 248 + 20 + (i * 54 + 4), 135 + (row * 54 + 249) + 3);
                        game.normalInventory.inventoryContents[(row * 9) + i].DrawAmountNormalInventory(spriteBatch, game.font, i, row * 54 + 249);
                    }
                }
            }

            // Инвентарь крафта
            for (int row = 0; row < 3; row++)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (inventoryContents[(row * 3) + i] != null)
                    {
                        spriteBatch.Draw(inventoryContents[(row * 3) + i].texture, new Vector2(248 + 86 + (i * 54 + 4), 135 + (row * 54 + 48) + 3), Color.White);
                        inventoryContents[(row * 3) + i].DrawDamage(spriteBatch, game, 248 + 86 + (i * 54 + 4), 135 + (row * 54 + 48) + 3);
                        inventoryContents[(row * 3) + i].DrawAmountWorkbenchInventory(spriteBatch, game.font, i, row * 54 + 48);
                    }
                }
            }
            if (inventoryContents[9] != null)
            {
                spriteBatch.Draw(inventoryContents[9].texture, new Vector2(248 + 368 + 4, 135 + 54 + 48 + 3), Color.White);
                inventoryContents[9].DrawDamage(spriteBatch, game, 248 + 368 + 4, 135 + 54 + 48 + 3);
                spriteBatch.DrawString(game.font, inventoryContents[9].count.ToString(), new Vector2(248 + 368 + 40, 135 + 54 + 48 + 38), Color.Black);
            }

            // Перемещаемая стопка
            if (draggingStack != null && draggingStack.isDragging)
            {
                spriteBatch.Draw(draggingStack.texture, new Vector2(Mouse.GetState().X - TextureAtlas.TEXTURE_SIZE / 2, Mouse.GetState().Y - TextureAtlas.TEXTURE_SIZE / 2), Color.White);
                draggingStack.DrawDamage(spriteBatch, game, Mouse.GetState().X - TextureAtlas.TEXTURE_SIZE / 2, Mouse.GetState().Y - TextureAtlas.TEXTURE_SIZE / 2);
                spriteBatch.DrawString(game.font, draggingStack.count.ToString(), new Vector2(Mouse.GetState().X + 40 - TextureAtlas.TEXTURE_SIZE / 2, Mouse.GetState().Y + 38 - TextureAtlas.TEXTURE_SIZE / 2), Color.Black);
            }
        }
Esempio n. 4
0
        public static void LoadLevel(Mine2D game, string filePath)
        {
            string tempFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"/Mine2D";
            Directory.CreateDirectory(tempFolder);
            ZipFile zip = new ZipFile(filePath);
            try { zip.ExtractAll(tempFolder, ExtractExistingFileAction.OverwriteSilently); }
            catch (IOException){}

            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                FileStream worldFile = new FileStream(tempFolder + @"/world.dat", FileMode.Open);
                game.world = (World)formatter.Deserialize(worldFile);
                worldFile.Close();

                FileStream playerFile = new FileStream(tempFolder + @"/player.dat", FileMode.Open);
                game.player = (Player)formatter.Deserialize(playerFile);
                playerFile.Close();

                FileStream smallInventoryFile = new FileStream(tempFolder + @"/smallInventory.dat", FileMode.Open);
                game.smallInventory = (SmallInventory)formatter.Deserialize(smallInventoryFile);
                smallInventoryFile.Close();

                FileStream normalInventoryFile = new FileStream(tempFolder + @"/normalInventory.dat", FileMode.Open);
                game.normalInventory = (NormalInventory)formatter.Deserialize(normalInventoryFile);
                normalInventoryFile.Close();
            }
            catch (Exception) { }

            foreach (Block block in game.world.blocks.Values)
            {
                block.FinishLoadAfterDeserialization(game.blocksAtlas);
            }
            game.player.FinishLoadAfterDeserialization(ref game.camera, game.Content);
            FinishLoadAfterDeserializationForInvStacks(game.smallInventory.inventoryContents, game);
            FinishLoadAfterDeserializationForInvStacks(game.normalInventory.inventoryContents, game);
            FinishLoadAfterDeserializationForInvStacks(game.normalInventory.craftContents, game);
            foreach (Block block in game.world.blocks.Values)
            {
                if (block is Blocks.Workbench)
                    FinishLoadAfterDeserializationForInvStacks((block as Blocks.Workbench).inventory.inventoryContents, game);
                else if (block is Blocks.Furnace)
                    FinishLoadAfterDeserializationForInvStacks((block as Blocks.Furnace).inventory.inventoryContents, game);
            }

            game.gameState = GameState.Playing;
        }
Esempio n. 5
0
        public void Draw(Mine2D game, SpriteBatch spriteBatch)
        {
            for (int i = 0; i < 3; i++)
            {
                if (!isButtonsActive[i])
                {
                    spriteBatch.Draw(game.button, buttonPositions[i], Color.White);
                }
                else
                {
                    spriteBatch.Draw(game.buttonActive, buttonPositions[i], Color.White);
                }

                spriteBatch.DrawString(game.font, buttonTexts[i], new Vector2(buttonPositions[i].X - game.font.MeasureString(buttonTexts[i]).X + game.font.MeasureString(buttonTexts[i]).X / 2 + 200, buttonPositions[i].Y - game.font.MeasureString(buttonTexts[i]).Y + game.font.MeasureString(buttonTexts[i]).Y / 2 + 20), Color.Black);
            }
        }
Esempio n. 6
0
        public static InventoryStack[] SplitStack(Mine2D game, InventoryStack stack)
        {
            InventoryStack[] stacks = new InventoryStack[2];

            if (stack != null && stack.count >= 2)
            {
                int stack1Count = stack.count / 2;
                int stack2Count = stack.count - stack1Count;
                stacks[0] = stack.Clone(game) as InventoryStack;
                stacks[0].RemoveAmount(stack1Count);
                stacks[1] = stack.Clone(game) as InventoryStack;
                stacks[1].RemoveAmount(stack2Count);
            }

            return stacks;
        }
Esempio n. 7
0
 static void Main(string[] args)
 {
     try
     {
         using (Mine2D game = new Mine2D())
         {
             game.Run();
         }
     }
     catch (Exception exc)
     {
         System.Windows.Forms.MessageBox.Show(
             "Исключение: \n" + exc.Message +
             "\nСтек вызова:\n" + exc.StackTrace,
             "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
     }
 }
Esempio n. 8
0
        public static void CheckBlocksCollisionWithLiving(Mine2D game, Dictionary<Vector2, Block> blocks, Living living, Texture2D livingTex, Color[] livingData)
        {
            foreach (KeyValuePair<Vector2, Block> block in blocks)
            {
                if (block.Value != null)
                {
                    string moveLivingLeftRight = "";
                    string moveLivingUpDown = "";
                    Vector2 blockPixelPos = game.world.GetBlockPixelPos(block.Key);

                    while (CollisionHelper.IntersectPixels(new Rectangle((int)living.pos.X, (int)living.pos.Y, livingTex.Width, livingTex.Height), livingData, new Rectangle((int)blockPixelPos.X, (int)blockPixelPos.Y, TextureAtlas.TEXTURE_SIZE, TextureAtlas.TEXTURE_SIZE), block.Value.textureColorData))
                    {
                        if (living.pos.X - blockPixelPos.X >= 0)
                            moveLivingLeftRight = "right";
                        else
                            moveLivingLeftRight = "left";

                        if (living.pos.Y - blockPixelPos.Y >= 0)
                            moveLivingUpDown = "down";
                        else
                            moveLivingUpDown = "up";

                        if (moveLivingLeftRight == "left")
                        {
                            living.pos.X -= 0.02F;
                        }
                        else if (moveLivingLeftRight == "right")
                        {
                            living.pos.X += 0.02F;
                        }

                        if (moveLivingUpDown == "up")
                        {
                            living.pos.Y -= 0.02F;
                        }
                        else if (moveLivingUpDown == "down")
                        {
                            living.pos.Y += 0.02F;
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public void Draw(Mine2D game, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(game.smallInventoryTex, new Vector2(233, 706), Color.White);

            Texture2D selectBackground = new Texture2D(game.GraphicsDevice, 1, 1);
            selectBackground.SetData<Color>(new Color[] { new Color(64, 64, 64, 64) });
            spriteBatch.Draw(selectBackground, new Rectangle(233 + (selectedStack * 62), 706, 64, 66), Color.White);

            int i = 0;
            foreach (InventoryStack inventoryContent in inventoryContents)
            {
                if (inventoryContent != null)
                {
                    spriteBatch.Draw(inventoryContent.texture, new Vector2(233 + (i * 62 + 9), 706 + 9), Color.White);
                    inventoryContent.DrawDamage(spriteBatch, game, 233 + (i * 62 + 9), 706 + 9);
                    inventoryContent.DrawAmountSmallInventory(spriteBatch, game.font, i);
                }
                i++;
            }
        }
Esempio n. 10
0
        public static void Generate(Mine2D game, TextureAtlas textureAtlas, World world, int seed)
        {
            LibNoise.Perlin noise = new LibNoise.Perlin();
            noise.Seed = seed;

            List<int> maxTreesY = new List<int>();
            for (int x = -256; x < 256; x++)
            {
                double Y = noise.GetValue((float)x / 17F, 1, 1) * 4;
                int y = (int)Y;
                maxTreesY.Add(16 - y - 16);
                Blocks.Grass grass = new Blocks.Grass(textureAtlas);
                world.SetBlock(new Vector2(x, 16 - y), grass);

                int dirtY = new Random(seed + x + y).Next(2, 5);
                int stoneY = y - new Random(seed + x + y + 1).Next(5, 8) + (3 - dirtY);
                for (int i = y - dirtY; i < y; i++)
                {
                    Blocks.Dirt dirt_ = new Blocks.Dirt(textureAtlas);
                    world.SetBlock(new Vector2(x, 16 - i), dirt_);
                }
                for (int i = -24; i < 4 + y + (4 - dirtY) + 1; i++)
                {
                    Blocks.Stone stone_ = new Blocks.Stone(textureAtlas);
                    world.SetBlock(new Vector2(x, 16 - i + 9), stone_);
                }
                for (int i = y + stoneY - 7; i < 4 + y + stoneY + 1; i++)
                {
                    Blocks.Cobblestone cobblestone_ = new Blocks.Cobblestone(textureAtlas);
                    world.SetBlockWithReplace(new Vector2(x, 16 - i + 10), cobblestone_);
                }
                GenerateOres(world, textureAtlas, x, y, stoneY, seed);

                Blocks.Bedrock bedrock_ = new Blocks.Bedrock(textureAtlas);
                world.SetBlock(new Vector2(x, 50), bedrock_);
            }
            GenerateTrees(-256, 256, maxTreesY.ToArray(), seed, world, textureAtlas);

            game.gameState = GameState.Playing;
        }
Esempio n. 11
0
        public void Draw(Mine2D game, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(game.logo, new Vector2(319, 200), Color.White);

            for (int i = 0; i < 3; i++)
            {
                if (!isButtonsActive[i])
                {
                    spriteBatch.Draw(game.button, buttonPositions[i], Color.White);
                }
                else
                {
                    spriteBatch.Draw(game.buttonActive, buttonPositions[i], Color.White);
                }

                spriteBatch.DrawString(game.font, buttonTexts[i], new Vector2(buttonPositions[i].X - game.font.MeasureString(buttonTexts[i]).X + game.font.MeasureString(buttonTexts[i]).X / 2 + 200, buttonPositions[i].Y - game.font.MeasureString(buttonTexts[i]).Y + game.font.MeasureString(buttonTexts[i]).Y / 2 + 20), Color.Black);
            }

            spriteBatch.DrawString(game.font, "Зерно для генератора мира:", new Vector2(312, 510), Color.Black);
            spriteBatch.Draw(game.textbox, new Vector2(312, 530), Color.White);
            spriteBatch.DrawString(game.font, textboxValue, new Vector2(315, 535), Color.Black);
        }
Esempio n. 12
0
        public static void SaveLevel(Mine2D game, string filePath)
        {
            string tempFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"/Mine2D";
            Directory.CreateDirectory(tempFolder);
            ZipFile zip = new ZipFile(filePath);
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                zip.RemoveEntries(new string[] { "world.dat", "player.dat", "smallInventory.dat", "normalInventory.dat" });
            }
            catch (ArgumentException) { }

            FileStream worldFile = new FileStream(tempFolder + @"/world.dat", FileMode.Create);
            formatter.Serialize(worldFile, game.world);
            worldFile.Close();
            zip.AddFile(tempFolder + @"/world.dat", "/");

            FileStream playerFile = new FileStream(tempFolder + @"/player.dat", FileMode.Create);
            formatter.Serialize(playerFile, game.player);
            playerFile.Close();
            zip.AddFile(tempFolder + @"/player.dat", "/");

            FileStream smallInventoryFile = new FileStream(tempFolder + @"/smallInventory.dat", FileMode.Create);
            formatter.Serialize(smallInventoryFile, game.smallInventory);
            smallInventoryFile.Close();
            zip.AddFile(tempFolder + @"/smallInventory.dat", "/");

            FileStream normalInventoryFile = new FileStream(tempFolder + @"/normalInventory.dat", FileMode.Create);
            formatter.Serialize(normalInventoryFile, game.normalInventory);
            normalInventoryFile.Close();
            zip.AddFile(tempFolder + @"/normalInventory.dat", "/");

            zip.Save();
            RecreateLevel(game);
            game.gameState = GameState.MainMenu;
        }
Esempio n. 13
0
        public void Update(Mine2D game)
        {
            MouseState mouse = Mouse.GetState();
            for (int i = 0; i < 3; i++)
            {
                if (mouse.X > buttonPositions[i].X &&
                    mouse.X < buttonPositions[i].X + 400 &&
                    mouse.Y > buttonPositions[i].Y &&
                    mouse.Y < buttonPositions[i].Y + 40)
                {
                    isButtonsActive[i] = true;

                    if (mouse.LeftButton == ButtonState.Released && isButtonPressed[i])
                    {
                        isButtonPressed[i] = false;
                        DoAction(game, i);
                    }
                    if (mouse.LeftButton == ButtonState.Pressed && !isButtonPressed[i])
                        isButtonPressed[i] = true;
                }
                else
                    isButtonsActive[i] = false;
            }
        }
Esempio n. 14
0
        public static InventoryStack GetOutputForRecipe(Type[] invStacks, Mine2D game)
        {
            int i = 0;
            if (invStacks.Length == 4)
            {
                foreach (Recipe recipe in smallRecipes)
                {
                    if (recipe.CompareTo(new Recipe(invStacks, null, 1)) == 1)
                    {
                        if (recipe.output.BaseType == typeof(Block))
                            return new InventoryStack((Block)Activator.CreateInstance(recipe.output, game.blocksAtlas), recipe.outputAmount);
                        else if (recipe.output.BaseType == typeof(Item))
                            return new InventoryStack((Item)Activator.CreateInstance(recipe.output, game.itemsAtlas), recipe.outputAmount);
                    }

                    i++;
                }

                return null;
            }
            else
            {
                i = 0;
                Type[] shortInvStacks = new Type[4];
                shortInvStacks[0] = invStacks[0];
                shortInvStacks[1] = invStacks[1];
                shortInvStacks[2] = invStacks[3];
                shortInvStacks[3] = invStacks[4];

                foreach (Recipe recipe in smallRecipes)
                {
                    if (recipe.CompareTo(new Recipe(shortInvStacks, null, 1)) == 1)
                    {
                        if (recipe.output.BaseType == typeof(Block))
                            return new InventoryStack((Block)Activator.CreateInstance(recipe.output, game.blocksAtlas), recipe.outputAmount);
                        else if (recipe.output.BaseType == typeof(Item))
                            return new InventoryStack((Item)Activator.CreateInstance(recipe.output, game.itemsAtlas), recipe.outputAmount);
                    }

                    i++;
                }

                i = 0;
                foreach (Recipe recipe in normalRecipes)
                {
                    if (recipe.CompareTo(new Recipe(invStacks, null, 1)) == 1)
                    {
                        if (recipe.output.BaseType == typeof(Block))
                            return new InventoryStack((Block)Activator.CreateInstance(recipe.output, game.blocksAtlas), recipe.outputAmount);
                        else if (recipe.output.BaseType == typeof(Item))
                            return new InventoryStack((Item)Activator.CreateInstance(recipe.output, game.itemsAtlas), recipe.outputAmount);
                    }

                    i++;
                }

                return null;
            }
        }
Esempio n. 15
0
        private void DoAction(Mine2D game, int buttonNumber)
        {
            switch (buttonNumber)
            {
                case 0:
                    game.gameState = GameState.GeneratingWorld;
                    new System.Threading.Thread(delegate() {
                        WorldGenerator.Generate(game, game.blocksAtlas, game.world, Convert.ToInt32(textboxValue));
                    }).Start();
                    break;

                case 1:
                    System.Windows.Forms.OpenFileDialog openWorld = new System.Windows.Forms.OpenFileDialog();
                    openWorld.Filter = "Сжатые миры Mine2D|*.m2d";
                    if (openWorld.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        game.gameState = GameState.LoadingWorld;
                        new System.Threading.Thread(delegate()
                        {
                            LevelManager.LoadLevel(game, openWorld.FileName);
                        }).Start();
                    }
                    break;

                case 2:
                    game.Exit();
                    break;
            }
        }
Esempio n. 16
0
 public static InventoryStack SumTwoStacks(Mine2D game, InventoryStack stack1, InventoryStack stack2)
 {
     InventoryStack stack = stack1.Clone(game) as InventoryStack;
     stack.AddAmount(stack2.count);
     return stack;
 }
Esempio n. 17
0
        public void UpdateWithoutGui(Mine2D game)
        {
            Type[] invStacks = CraftHelper.ConvertStacksToTypes(inventoryContents);
            if (CraftHelper.CheckIsExistingFurnaceRecipe(invStacks[0], invStacks[2]) && (this.inventoryContents[1] == null || InventoryHelper.CanSumTwoStacks(this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game))) && !isCooking)
            {
                cookingTime = 0;
                if (fuelTime <= 0)
                    fuelTime = Item.GetFuelValue(invStacks[2]);
                isCooking = true;
            }
            else if (!CraftHelper.CheckIsExistingFurnaceRecipe(invStacks[0], invStacks[2]) && isCooking)
            {
                cookingTime = 0;
                isCooking = false;
            }

            if (isCooking && fuelTime <= 0)
            {
                this.inventoryContents[2].RemoveAmount(1);
                if (!this.inventoryContents[2].needRemove)
                    fuelTime = Item.GetFuelValue(invStacks[2]);
            }
            else if (isCooking && fuelTime == Item.GetFuelValue(invStacks[2]))
            {
                this.inventoryContents[2].RemoveAmount(1);
            }
            if (fuelTime > 0)
                fuelTime--;

            if (isCooking && this.inventoryContents[1] == null && cookingTime >= 500)
            {
                InventoryStack output = CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game);
                this.inventoryContents[1] = output;

                this.inventoryContents[0].RemoveAmount(1);

                isCooking = false;
            }
            else if (isCooking && InventoryHelper.CanSumTwoStacks(this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game)) && cookingTime >= 500)
            {
                InventoryStack output = CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game);
                this.inventoryContents[1] = InventoryHelper.SumTwoStacks(game, this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game));

                this.inventoryContents[0].RemoveAmount(1);

                isCooking = false;
            }

            if (inventoryContents != null)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (inventoryContents[i] != null && inventoryContents[i].needRemove)
                        inventoryContents[i] = null;
                }
            }

            if (isCooking)
                cookingTime++;

            game.normalInventory.Update();
            base.Update();
        }
Esempio n. 18
0
        public void Draw(Mine2D game, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(game.furnaceInventoryTex, new Vector2(248, 135), new Rectangle(0, 0, 528, 498), Color.White);
            if (cookingTime > 0)
            {
                spriteBatch.Draw(game.furnaceInventoryTex, new Vector2(248 + 240, 135 + 102), new Rectangle(531, 42, (int)(cookingTime / 5 / 1.5151F), 47), Color.White);
            }
            if (fuelTime > 0 && Item.GetFuelValue(CraftHelper.ConvertStacksToTypes(inventoryContents)[2]) > 0 && Item.GetFuelValue(CraftHelper.ConvertStacksToTypes(inventoryContents)[2]) / 100F > 0F)
            {
                int fire = (int)((fuelTime / (Item.GetFuelValue(CraftHelper.ConvertStacksToTypes(inventoryContents)[2]) / 100)) / 2.3809F);
                spriteBatch.Draw(game.furnaceInventoryTex, new Vector2(248 + 168, 135 + 109 + (42 -  fire)), new Rectangle(528, 42 - fire, 42, fire), Color.White);
            }

            // Малый инвентарь
            for (int i = 0; i < 9; i++)
            {
                if (game.smallInventory.inventoryContents[i] != null)
                {
                    spriteBatch.Draw(game.smallInventory.inventoryContents[i].texture, new Vector2(248 + 20 + (i * 54 + 4), 135 + 423 + 3), Color.White);
                    game.smallInventory.inventoryContents[i].DrawDamage(spriteBatch, game, 248 + 20 + (i * 54 + 4), 135 + 423 + 3);
                    game.smallInventory.inventoryContents[i].DrawAmountNormalInventory(spriteBatch, game.font, i, 423);
                }
            }

            // Нормальный инвентарь
            for (int row = 0; row < 3; row++)
            {
                for (int i = 0; i < 9; i++)
                {
                    if (game.normalInventory.inventoryContents[(row * 9) + i] != null)
                    {
                        spriteBatch.Draw(game.normalInventory.inventoryContents[(row * 9) + i].texture, new Vector2(248 + 20 + (i * 54 + 4), 135 + (row * 54 + 249) + 3), Color.White);
                        game.normalInventory.inventoryContents[(row * 9) + i].DrawDamage(spriteBatch, game, 248 + 20 + (i * 54 + 4), 135 + (row * 54 + 249) + 3);
                        game.normalInventory.inventoryContents[(row * 9) + i].DrawAmountNormalInventory(spriteBatch, game.font, i, row * 54 + 249);
                    }
                }
            }

            // Инвентарь печки:
            // - Вход
            if (inventoryContents[0] != null)
            {
                spriteBatch.Draw(inventoryContents[0].texture, new Vector2(248 + 164 + 4, 135 + 48 + 3), Color.White);
                inventoryContents[0].DrawDamage(spriteBatch, game, 248 + 164 + 4, 135 + 48 + 3);
                spriteBatch.DrawString(game.font, inventoryContents[0].count.ToString(), new Vector2(248 + 164 + 40, 135 + 48 + 38), Color.Black);
            }
            // - Выход
            if (inventoryContents[1] != null)
            {
                spriteBatch.Draw(inventoryContents[1].texture, new Vector2(248 + 344 + 4, 135 + 102 + 3), Color.White);
                inventoryContents[1].DrawDamage(spriteBatch, game, 248 + 344 + 4, 135 + 102 + 3);
                spriteBatch.DrawString(game.font, inventoryContents[1].count.ToString(), new Vector2(248 + 344 + 40, 135 + 102 + 38), Color.Black);
            }
            // - Топливо
            if (inventoryContents[2] != null)
            {
                spriteBatch.Draw(inventoryContents[2].texture, new Vector2(248 + 164 + 4, 135 + 156 + 3), Color.White);
                inventoryContents[2].DrawDamage(spriteBatch, game, 248 + 164 + 4, 135 + 156 + 3);
                spriteBatch.DrawString(game.font, inventoryContents[2].count.ToString(), new Vector2(248 + 164 + 40, 135 + 156 + 38), Color.Black);
            }

            // Перемещаемая стопка
            if (draggingStack != null && draggingStack.isDragging)
            {
                spriteBatch.Draw(draggingStack.texture, new Vector2(Mouse.GetState().X - TextureAtlas.TEXTURE_SIZE / 2, Mouse.GetState().Y - TextureAtlas.TEXTURE_SIZE / 2), Color.White);
                draggingStack.DrawDamage(spriteBatch, game, Mouse.GetState().X - TextureAtlas.TEXTURE_SIZE / 2, Mouse.GetState().Y - TextureAtlas.TEXTURE_SIZE / 2);
                spriteBatch.DrawString(game.font, draggingStack.count.ToString(), new Vector2(Mouse.GetState().X + 40 - TextureAtlas.TEXTURE_SIZE / 2, Mouse.GetState().Y + 38 - TextureAtlas.TEXTURE_SIZE / 2), Color.Black);
            }
        }
Esempio n. 19
0
        public void Update(Mine2D game)
        {
            MouseState mouse = Mouse.GetState();

            // Обычный инвентарь
            if (draggingStack == null)
            {
                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 249) + 3 &&
                            mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                            mouse.LeftButton == ButtonState.Pressed &&
                            game.normalInventory.inventoryContents[(row * 9) + i] != null)
                        {
                            draggingStack = game.normalInventory.inventoryContents[(row * 9) + i].Clone(game) as InventoryStack;
                            draggingStack.isDragging = true;
                            game.normalInventory.inventoryContents[(row * 9) + i].needRemove = true;
                            goto escapeFor;
                        }
                    }
                }
            }
            else
            {
                if (mouse.LeftButton == ButtonState.Pressed && !isMousePressed)
                    isMousePressed = true;
                else if (mouse.LeftButton == ButtonState.Released && isMousePressed)
                {
                    isMousePressed = false;
                    for (int row = 0; row < 3; row++)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            // Обычный инвентарь
                            if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                                mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + (row * 54 + 249) + 3 &&
                                mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                                (game.normalInventory.inventoryContents[(row * 9) + i] == null ||
                                InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack)))
                            {
                                if (game.normalInventory.inventoryContents[(row * 9) + i] == null)
                                    game.normalInventory.inventoryContents[(row * 9) + i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack))
                                    game.normalInventory.inventoryContents[(row * 9) + i] = InventoryHelper.SumTwoStacks(game, game.normalInventory.inventoryContents[(row * 9) + i], draggingStack);
                                draggingStack = null;
                            }
                            // Малый инвентарь
                            else if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                                mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + 423 + 3 &&
                                mouse.Y < 135 + 423 + 3 + 48 &&
                                (game.smallInventory.inventoryContents[i] == null ||
                                InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack)))
                            {
                                if (game.smallInventory.inventoryContents[i] == null)
                                    game.smallInventory.inventoryContents[i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack))
                                    game.smallInventory.inventoryContents[i] = InventoryHelper.SumTwoStacks(game, game.smallInventory.inventoryContents[i], draggingStack);
                                draggingStack = null;
                            }
                        }
                    }
                    // Инвентарь печки:
                    // - Вход
                    if (mouse.X > 248 + 164 + 4 &&
                        mouse.X < 248 + 164 + 4 + 48 &&
                        mouse.Y > 135 + 48 + 3 &&
                        mouse.Y < 135 + 48 + 3 + 48 &&
                        (inventoryContents[0] == null ||
                        InventoryHelper.CanSumTwoStacks(inventoryContents[0], draggingStack)))
                    {
                        if (inventoryContents[0] == null)
                            inventoryContents[0] = draggingStack.Clone(game) as InventoryStack;
                        else if (InventoryHelper.CanSumTwoStacks(inventoryContents[0], draggingStack))
                            inventoryContents[0] = InventoryHelper.SumTwoStacks(game, inventoryContents[0], draggingStack);
                        draggingStack = null;
                    }
                    // - Топливо
                    if (mouse.X > 248 + 164 + 4 &&
                        mouse.X < 248 + 164 + 4 + 48 &&
                        mouse.Y > 135 + 156 + 3 &&
                        mouse.Y < 135 + 156 + 3 + 48 &&
                        (inventoryContents[2] == null ||
                        InventoryHelper.CanSumTwoStacks(inventoryContents[2], draggingStack)))
                    {
                        if (inventoryContents[2] == null)
                            inventoryContents[2] = draggingStack.Clone(game) as InventoryStack;
                        else if (InventoryHelper.CanSumTwoStacks(inventoryContents[2], draggingStack))
                            inventoryContents[2] = InventoryHelper.SumTwoStacks(game, inventoryContents[2], draggingStack);
                        draggingStack = null;
                    }
                }
            }

            if (draggingStack == null)
            {
                for (int i = 0; i < 9; i++)
                {
                    if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                        mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                        mouse.Y > 135 + 423 + 3 &&
                        mouse.Y < 135 + 423 + 3 + 48 &&
                        mouse.LeftButton == ButtonState.Pressed &&
                        game.smallInventory.inventoryContents[i] != null)
                    {
                        draggingStack = game.smallInventory.inventoryContents[i].Clone(game) as InventoryStack;
                        draggingStack.isDragging = true;
                        game.smallInventory.inventoryContents[i].needRemove = true;
                        goto escapeFor;
                    }
                }
            }

            if (draggingStack == null)
            {
                // Инвентарь печки:
                // - Вход
                if (mouse.X > 248 + 164 + 4 &&
                    mouse.X < 248 + 164 + 4 + 48 &&
                    mouse.Y > 135 + 48 + 3 &&
                    mouse.Y < 135 + 48 + 3 + 48 &&
                    mouse.LeftButton == ButtonState.Pressed &&
                    inventoryContents[0] != null)
                {
                    draggingStack = inventoryContents[0].Clone(game) as InventoryStack;
                    draggingStack.isDragging = true;
                    inventoryContents[0].needRemove = true;
                    goto escapeFor;
                }
                // - Выход
                if (mouse.X > 248 + 344 + 4 &&
                    mouse.X < 248 + 344 + 4 + 48 &&
                    mouse.Y > 135 + 102 + 3 &&
                    mouse.Y < 135 + 102 + 3 + 48 &&
                    mouse.LeftButton == ButtonState.Pressed &&
                    inventoryContents[1] != null)
                {
                    draggingStack = inventoryContents[1].Clone(game) as InventoryStack;
                    draggingStack.isDragging = true;
                    inventoryContents[1].needRemove = true;
                    goto escapeFor;
                }
                // - Топливо
                if (mouse.X > 248 + 164 + 4 &&
                    mouse.X < 248 + 164 + 4 + 48 &&
                    mouse.Y > 135 + 156 + 3 &&
                    mouse.Y < 135 + 156 + 3 + 48 &&
                    mouse.LeftButton == ButtonState.Pressed &&
                    inventoryContents[2] != null)
                {
                    draggingStack = inventoryContents[2].Clone(game) as InventoryStack;
                    draggingStack.isDragging = true;
                    inventoryContents[2].needRemove = true;
                    fuelTime = 0;
                    goto escapeFor;
                }
            }

            // Разделение стопок
            if (mouse.RightButton == ButtonState.Pressed && !isMouse2Pressed)
                isMouse2Pressed = true;
            else if (mouse.RightButton == ButtonState.Released && isMouse2Pressed)
            {
                isMouse2Pressed = false;

                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        // Обычный инвентарь
                        if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 249) + 3 &&
                            mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                            InventoryHelper.CanSplitStack(game.normalInventory.inventoryContents[(row * 9) + i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.normalInventory.inventoryContents[(row * 9) + i]);
                            game.normalInventory.inventoryContents[(row * 9) + i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }
                        // Малый инвентарь
                        else if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + 423 + 3 &&
                            mouse.Y < 135 + 423 + 3 + 48 &&
                            InventoryHelper.CanSplitStack(game.smallInventory.inventoryContents[i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.smallInventory.inventoryContents[i]);
                            game.smallInventory.inventoryContents[i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }

                    }

                }
                // Инвентарь печки:
                // - Вход
                if (mouse.X > 248 + 164 + 4 &&
                    mouse.X < 248 + 164 + 4 + 48 &&
                    mouse.Y > 135 + 48 + 3 &&
                    mouse.Y < 135 + 48 + 3 + 48 &&
                    InventoryHelper.CanSplitStack(inventoryContents[0]) &&
                    draggingStack == null)
                {
                    InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[0]);
                    inventoryContents[0] = splittedStack[0];
                    draggingStack = splittedStack[1];
                    draggingStack.isDragging = true;
                }
                // - Выход
                if (mouse.X > 248 + 344 + 4 &&
                    mouse.X < 248 + 344 + 4 + 48 &&
                    mouse.Y > 135 + 102 + 3 &&
                    mouse.Y < 135 + 102 + 3 + 48 &&
                    InventoryHelper.CanSplitStack(inventoryContents[1]) &&
                    draggingStack == null)
                {
                    InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[1]);
                    inventoryContents[1] = splittedStack[0];
                    draggingStack = splittedStack[1];
                    draggingStack.isDragging = true;
                }
                // - Топливо
                if (mouse.X > 248 + 164 + 4 &&
                    mouse.X < 248 + 164 + 4 + 48 &&
                    mouse.Y > 135 + 156 + 3 &&
                    mouse.Y < 135 + 156 + 3 + 48 &&
                    InventoryHelper.CanSplitStack(inventoryContents[2]) &&
                    draggingStack == null)
                {
                    InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[2]);
                    inventoryContents[2] = splittedStack[0];
                    draggingStack = splittedStack[1];
                    draggingStack.isDragging = true;
                }
            }

            escapeFor:
            Type[] invStacks = CraftHelper.ConvertStacksToTypes(inventoryContents);
            if (CraftHelper.CheckIsExistingFurnaceRecipe(invStacks[0], invStacks[2]) && (this.inventoryContents[1] == null || InventoryHelper.CanSumTwoStacks(this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game))) && !isCooking)
            {
                cookingTime = 0;
                if (fuelTime <= 0)
                    fuelTime = Item.GetFuelValue(invStacks[2]);
                isCooking = true;
            }
            else if (!CraftHelper.CheckIsExistingFurnaceRecipe(invStacks[0], invStacks[2]) && isCooking)
            {
                cookingTime = 0;
                isCooking = false;
            }

            if (isCooking && fuelTime <= 0)
            {
                this.inventoryContents[2].RemoveAmount(1);
                if (!this.inventoryContents[2].needRemove)
                    fuelTime = Item.GetFuelValue(invStacks[2]);
            }
            else if (isCooking && fuelTime == Item.GetFuelValue(invStacks[2]))
            {
                this.inventoryContents[2].RemoveAmount(1);
            }
            if (fuelTime > 0)
                fuelTime--;

            if (isCooking && this.inventoryContents[1] == null && cookingTime >= 500)
            {
                InventoryStack output = CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game);
                this.inventoryContents[1] = output;

                this.inventoryContents[0].RemoveAmount(1);

                isCooking = false;
                cookingTime = 0;
            }
            else if (isCooking && InventoryHelper.CanSumTwoStacks(this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game)) && cookingTime >= 500)
            {
                InventoryStack output = CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game);
                this.inventoryContents[1] = InventoryHelper.SumTwoStacks(game, this.inventoryContents[1], CraftHelper.GetOutputForFurnaceRecipe(invStacks[0], game));

                this.inventoryContents[0].RemoveAmount(1);

                isCooking = false;
                cookingTime = 0;
            }

            if (inventoryContents != null)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (inventoryContents[i] != null && inventoryContents[i].needRemove)
                        inventoryContents[i] = null;
                }
            }

            if (isCooking)
                cookingTime++;

            game.normalInventory.Update();
            base.Update();
        }
Esempio n. 20
0
 public void DrawDamage(SpriteBatch spriteBatch, Mine2D game, int X, int Y)
 {
     if (this.stackType == InventoryStackTypes.Item && Item.IsTool(this.GetItem()) && this.GetItem().damage > 0)
     {
         spriteBatch.Draw(game.durabilityBarEmpty, new Vector2(X + 1, Y + 46), Color.White);
         spriteBatch.Draw(game.durabilityBarFull, new Vector2(X + 1, Y + 46), new Rectangle(0, 0, (int)((100F - ((float)this.GetItem().damage / (float)Item.GetToolDurability(Type.GetType("Mine2D.Items+" + this.GetItem().name)) * 100F)) / 2.1739F), 6), Color.White);
     }
 }
Esempio n. 21
0
        public void Update(Mine2D game, GameTime gameTime)
        {
            KeyboardState keyboard = Keyboard.GetState();

            if (keyboard.IsKeyDown(Keys.A))
            {
                pos.X -= 3F;
                direction = Direction.Left;
            }
            else if (keyboard.IsKeyDown(Keys.D))
            {
                pos.X += 3F;
                direction = Direction.Right;
            }

            if (keyboard.IsKeyDown(Keys.W))
            {
                pos.Y -= 6F;
            }
            else if (keyboard.IsKeyDown(Keys.S))
            {
                pos.Y += 5F;
            }

            if (keyboard.IsKeyDown(Keys.E) && !isOpeningInventory)
                isOpeningInventory = true;
            else if (keyboard.IsKeyUp(Keys.E) && isOpeningInventory)
            {
                if (game.isWorkbenchInventoryOpen)
                    game.isWorkbenchInventoryOpen = false;
                else if (game.isFurnaceInventoryOpen)
                    game.isFurnaceInventoryOpen = false;
                else
                    game.isNormalInventoryOpen = !game.isNormalInventoryOpen;

                isOpeningInventory = false;
            }

            camera.Pos = new Vector2(pos.X, pos.Y);

            if (direction == Direction.Right)
                CollisionHelper.CheckBlocksCollisionWithLiving(game, game.world.blocks, this, this.playerRight, this.playerRightColorData);
            else
                CollisionHelper.CheckBlocksCollisionWithLiving(game, game.world.blocks, this, this.playerLeft, this.playerLeftColorData);

            if (!(game.isNormalInventoryOpen || game.isWorkbenchInventoryOpen))
            {
                MouseState mouse = Mouse.GetState();

                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    Vector2 mousePosInWorld = new Vector2((int)(mouse.X - 512 + pos.X) / TextureAtlas.TEXTURE_SIZE, (int)(mouse.Y - 384 + pos.Y) / TextureAtlas.TEXTURE_SIZE);
                    if (mousePosInWorld.X < 0)
                        mousePosInWorld.X--;
                    if (mousePosInWorld.Y < 0)
                        mousePosInWorld.Y--;

                    if (destroyingBlock != new Vector2(float.PositiveInfinity) && mousePosInWorld != destroyingBlock)
                    {
                        if (game.world.GetBlock(destroyingBlock) != null)
                        {
                            game.world.GetBlock(destroyingBlock).isSelected = false;
                            game.world.GetBlock(destroyingBlock).destroyingState = 0;
                        }
                    }

                    Block block = game.world.GetBlock(mousePosInWorld);
                    if (block != null && block.canDestroy)
                    {
                        isDestroyingBlock = true;
                        destroyingBlock = mousePosInWorld;
                        int destroyingTime;
                        bool isDestroyingWithTool = false;

                        if (game.smallInventory.inventoryContents[game.smallInventory.selectedStack] != null)
                        {
                            if (game.smallInventory.inventoryContents[game.smallInventory.selectedStack].stackType == InventoryStack.InventoryStackTypes.Item)
                            {
                                if (Item.IsTool(game.smallInventory.inventoryContents[game.smallInventory.selectedStack].GetItem()))
                                {
                                    try
                                    {
                                        destroyingTime = block.destroyTimesWithTools[game.smallInventory.inventoryContents[game.smallInventory.selectedStack].GetItem().name];
                                        isDestroyingWithTool = true;
                                    }
                                    catch
                                    {
                                        destroyingTime = block.destroyTimesWithTools["Null"];
                                        isDestroyingWithTool = false;
                                    }
                                }
                                else
                                    destroyingTime = block.destroyTimesWithTools["Null"];
                            }
                            else
                                destroyingTime = block.destroyTimesWithTools["Null"];
                        }
                        else
                            destroyingTime = block.destroyTimesWithTools["Null"];

                        if (!block.isSelected)
                            block.isSelected = true;

                        if (timer > destroyingTime)
                            timer = 0;

                        if (timer == destroyingTime && block.destroyingState < block.maxDestroyingState)
                        {
                            block.destroyingState++;
                            timer = 0;
                        }
                        else if (timer == destroyingTime && block.destroyingState == block.maxDestroyingState)
                        {
                            if (game.world.GetBlock(mousePosInWorld).drop == null)
                            {
                                if (!game.smallInventory.AddStackToInventory(new InventoryStack(block, 1)))
                                    game.normalInventory.AddStackToInventory(new InventoryStack(block, 1));
                            }
                            else
                            {
                                InventoryStack drop = block.drop;

                                if (drop.stackType == InventoryStack.InventoryStackTypes.Item)
                                {
                                    drop.GetItem().textureFromAtlas = game.itemsAtlas.getTexture(drop.GetItem().texPos);
                                    drop.GetItem().textureColorData = new Color[TextureAtlas.TEXTURE_SIZE * TextureAtlas.TEXTURE_SIZE];
                                    drop.GetItem().textureFromAtlas.GetData<Color>(drop.GetItem().textureColorData);
                                    drop.texture = drop.GetItem().textureFromAtlas;

                                    if (!game.smallInventory.AddStackToInventory(drop))
                                        game.normalInventory.AddStackToInventory(drop);
                                }
                            }

                            if (isDestroyingWithTool)
                            {
                                game.smallInventory.inventoryContents[game.smallInventory.selectedStack].GetItem().damage++;
                                if (game.smallInventory.inventoryContents[game.smallInventory.selectedStack].GetItem().damage >= Item.GetToolDurability(Type.GetType("Mine2D.Items+" + game.smallInventory.inventoryContents[game.smallInventory.selectedStack].GetItem().name)))
                                    game.smallInventory.inventoryContents[game.smallInventory.selectedStack].needRemove = true;
                            }

                            SoundManager.PlayDestroySoundForBlock(game.world.GetBlock(mousePosInWorld).name);

                            game.world.DeleteBlock(mousePosInWorld);

                            timer = 0;
                        }
                        else
                            timer++;
                    }
                }
                else if (mouse.LeftButton == ButtonState.Released && isDestroyingBlock)
                {
                    isDestroyingBlock = false;
                    if (game.world.GetBlock(destroyingBlock) != null)
                    {
                        game.world.GetBlock(destroyingBlock).destroyingState = 0;
                        game.world.GetBlock(destroyingBlock).isSelected = false;
                    }
                    destroyingBlock = new Vector2(float.PositiveInfinity);
                }

                if (mouse.RightButton == ButtonState.Pressed && !isSettingBlock)
                    isSettingBlock = true;
                else if (mouse.RightButton == ButtonState.Released && isSettingBlock)
                {
                    isSettingBlock = false;
                    Vector2 mousePosInWorld = new Vector2((int)(mouse.X - 512 + pos.X) / TextureAtlas.TEXTURE_SIZE, (int)(mouse.Y - 384 + pos.Y) / TextureAtlas.TEXTURE_SIZE);
                    if (mousePosInWorld.X < 0)
                        mousePosInWorld.X--;
                    if (mousePosInWorld.Y < 0)
                        mousePosInWorld.Y--;

                    if (game.smallInventory.inventoryContents[game.smallInventory.selectedStack] != null)
                    {
                        if (game.smallInventory.inventoryContents[game.smallInventory.selectedStack].stackType == InventoryStack.InventoryStackTypes.Block)
                        {
                            Block block = game.smallInventory.inventoryContents[game.smallInventory.selectedStack].GetBlock();
                            if (block != null)
                            {
                                block.isSelected = false;
                                block.destroyingState = 0;
                                if (game.world.SetBlock(mousePosInWorld, block.Clone(game.blocksAtlas) as Block))
                                    game.smallInventory.inventoryContents[game.smallInventory.selectedStack].RemoveAmount(1);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 22
0
        private static void FinishLoadAfterDeserializationForInvStacks(InventoryStack[] invStacks, Mine2D game)
        {
            foreach (InventoryStack invStack in invStacks)
            {
                if (invStack != null)
                {
                    if (invStack.stackType == InventoryStack.InventoryStackTypes.Block)
                        invStack.GetBlock().FinishLoadAfterDeserialization(game.blocksAtlas);
                    else if (invStack.stackType == InventoryStack.InventoryStackTypes.Item)
                        invStack.GetItem().FinishLoadAfterDeserialization(game.itemsAtlas);

                    invStack.FinishLoadAfterDeserialization();
                }
            }
        }
Esempio n. 23
0
 public virtual void Update(Mine2D game, Vector2 thisBlockPos)
 {
 }
Esempio n. 24
0
        public static InventoryStack GetOutputForFurnaceRecipe(Type input, Mine2D game)
        {
            foreach (FurnaceRecipe recipe in furnaceRecipes)
            {
                if (recipe.CompareTo(new FurnaceRecipe(input, null, 1)) == 1)
                {
                    if (recipe.output.BaseType == typeof(Block))
                        return new InventoryStack((Block)Activator.CreateInstance(recipe.output, game.blocksAtlas), recipe.outputAmount);
                    else if (recipe.output.BaseType == typeof(Item))
                        return new InventoryStack((Item)Activator.CreateInstance(recipe.output, game.itemsAtlas), recipe.outputAmount);
                }
                else
                    continue;
            }

            return null;
        }
Esempio n. 25
0
        public void Update(Mine2D game, GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();
            for (int i = 0; i < 3; i++)
            {
                if (mouse.X > buttonPositions[i].X &&
                    mouse.X < buttonPositions[i].X + 400 &&
                    mouse.Y > buttonPositions[i].Y &&
                    mouse.Y < buttonPositions[i].Y + 40)
                {
                    isButtonsActive[i] = true;

                    if (mouse.LeftButton == ButtonState.Released && isButtonPressed[i])
                    {
                        isButtonPressed[i] = false;
                        DoAction(game, i);
                    }
                    if (mouse.LeftButton == ButtonState.Pressed && !isButtonPressed[i])
                        isButtonPressed[i] = true;
                }
                else
                    isButtonsActive[i] = false;
            }

            KeyboardState keyboard = Keyboard.GetState();
            if (mouse.X > 312 &&
                mouse.X < 712 &&
                mouse.Y > 530 &&
                mouse.Y < 555 &&
                mouse.LeftButton == ButtonState.Pressed && !isTextboxPressed)
                isTextboxPressed = true;
            else if (mouse.X > 312 &&
                mouse.X < 712 &&
                mouse.Y > 530 &&
                mouse.Y < 555 &&
                mouse.LeftButton == ButtonState.Released && isTextboxPressed)
            {
                if (lastPressedKeys == null)
                    lastPressedKeys = new Keys[0];

                Keys[] pressedKeys = keyboard.GetPressedKeys();

                foreach (Keys key in lastPressedKeys)
                {
                    if (!pressedKeys.Contains(key))
                        OnKeyUp(key);
                }

                foreach (Keys key in pressedKeys)
                {
                    if (!lastPressedKeys.Contains(key))
                        OnKeyDown(key);
                }

                lastPressedKeys = pressedKeys;
            }
            else if (!(mouse.X > 312 &&
                mouse.X < 712 &&
                mouse.Y > 530 &&
                mouse.Y < 555) &&
                mouse.LeftButton == ButtonState.Pressed && isTextboxPressed)
                isTextboxPressed = false;
        }
Esempio n. 26
0
        public object Clone(Mine2D game)
        {
            InventoryStack invStack = null;

            if (stackType == InventoryStackTypes.Block)
                invStack = new InventoryStack((Block)this.GetBlock().Clone(game.blocksAtlas), this.count, this.maxCount);
            else if (stackType == InventoryStackTypes.Item)
                invStack = new InventoryStack((Item)this.GetItem().Clone(game.itemsAtlas), this.count, this.maxCount);

            return invStack;
        }
Esempio n. 27
0
        public void Update(Mine2D game)
        {
            if (craftContents == null)
                craftContents = new InventoryStack[5];

            MouseState mouse = Mouse.GetState();

            // Обычный инвентарь
            if (draggingStack == null)
            {
                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 249) + 3 &&
                            mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                            mouse.LeftButton == ButtonState.Pressed &&
                            inventoryContents[(row * 9) + i] != null)
                        {
                            draggingStack = inventoryContents[(row * 9) + i].Clone(game) as InventoryStack;
                            draggingStack.isDragging = true;
                            inventoryContents[(row * 9) + i].needRemove = true;
                            goto escapeFor;
                        }
                    }
                }
            }
            else
            {
                if (mouse.LeftButton == ButtonState.Pressed && !isMousePressed)
                    isMousePressed = true;
                else if (mouse.LeftButton == ButtonState.Released && isMousePressed)
                {
                    isMousePressed = false;
                    for (int row = 0; row < 3; row++)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            // Обычный инвентарь
                            if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                                mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + (row * 54 + 249) + 3 &&
                                mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                                (inventoryContents[(row * 9) + i] == null ||
                                InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 9) + i], draggingStack)))
                            {
                                if (inventoryContents[(row * 9) + i] == null)
                                    inventoryContents[(row * 9) + i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 9) + i], draggingStack))
                                    inventoryContents[(row * 9) + i] = InventoryHelper.SumTwoStacks(game, inventoryContents[(row * 9) + i], draggingStack);
                                draggingStack = null;
                            }
                            // Малый инвентарь
                            else if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                                mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + 423 + 3 &&
                                mouse.Y < 135 + 423 + 3 + 48 &&
                                (game.smallInventory.inventoryContents[i] == null ||
                                InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack)))
                            {
                                if (game.smallInventory.inventoryContents[i] == null)
                                    game.smallInventory.inventoryContents[i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack))
                                    game.smallInventory.inventoryContents[i] = InventoryHelper.SumTwoStacks(game, game.smallInventory.inventoryContents[i], draggingStack);
                                draggingStack = null;
                            }
                        }
                        for (int i = 0; i < 2; i++)
                        {

                            // Инвентарь крафта: верх
                            if (mouse.X > 248 + 260 + (i * 54 + 4) &&
                                mouse.X < 248 + 260 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + 75 + 3 &&
                                mouse.Y < 135 + 75 + 3 + 48 &&
                                (this.craftContents[i] == null ||
                                InventoryHelper.CanSumTwoStacks(this.craftContents[i], draggingStack)))
                            {
                                if (this.craftContents[i] == null)
                                    this.craftContents[i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(this.craftContents[i], draggingStack))
                                    this.craftContents[i] = InventoryHelper.SumTwoStacks(game, this.craftContents[i], draggingStack);
                                draggingStack = null;
                            }
                            // Инвентарь крафта: низ
                            else if (mouse.X > 248 + 260 + (i * 54 + 4) &&
                                mouse.X < 248 + 260 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + 129 + 3 &&
                                mouse.Y < 135 + 129 + 3 + 48 &&
                                (this.craftContents[i + 2] == null ||
                                InventoryHelper.CanSumTwoStacks(this.craftContents[i + 2], draggingStack)))
                            {
                                if (this.craftContents[i + 2] == null)
                                    this.craftContents[i + 2] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(this.craftContents[i + 2], draggingStack))
                                    this.craftContents[i + 2] = InventoryHelper.SumTwoStacks(game, this.craftContents[i + 2], draggingStack);
                                draggingStack = null;
                            }
                        }
                    }
                }
            }

            // Малый инвентарь
            if (draggingStack == null)
            {
                for (int i = 0; i < 9; i++)
                {
                    if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                        mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                        mouse.Y > 135 + 423 + 3 &&
                        mouse.Y < 135 + 423 + 3 + 48 &&
                        mouse.LeftButton == ButtonState.Pressed &&
                        game.smallInventory.inventoryContents[i] != null)
                    {
                        draggingStack = game.smallInventory.inventoryContents[i].Clone(game) as InventoryStack;
                        draggingStack.isDragging = true;
                        game.smallInventory.inventoryContents[i].needRemove = true;
                        goto escapeFor;
                    }
                }
            }

            // Инвентарь крафта
            if (draggingStack == null)
            {
                for (int i = 0; i < 2; i++)
                {
                    // Верх
                    if (mouse.X > 248 + 260 + (i * 54 + 4) &&
                        mouse.X < 248 + 260 + (i * 54 + 4) + 48 &&
                        mouse.Y > 135 + 75 + 3 &&
                        mouse.Y < 135 + 75 + 3 + 48 &&
                        mouse.LeftButton == ButtonState.Pressed &&
                        craftContents[i] != null)
                    {
                        draggingStack = craftContents[i].Clone(game) as InventoryStack;
                        draggingStack.isDragging = true;
                        craftContents[i].needRemove = true;
                    }

                    // Низ
                    else if (mouse.X > 248 + 260 + (i * 54 + 4) &&
                         mouse.X < 248 + 260 + (i * 54 + 4) + 48 &&
                         mouse.Y > 135 + 129 + 3 &&
                         mouse.Y < 135 + 129 + 3 + 48 &&
                         mouse.LeftButton == ButtonState.Pressed &&
                         craftContents[i + 2] != null)
                    {
                        draggingStack = craftContents[i + 2].Clone(game) as InventoryStack;
                        draggingStack.isDragging = true;
                        craftContents[i + 2].needRemove = true;
                    }

                    // Выход
                    else if (mouse.X > 248 + 428 + 4 &&
                         mouse.X < 248 + 428 + 4 + 48 &&
                         mouse.Y > 135 + 105 + 3 &&
                         mouse.Y < 135 + 105 + 3 + 48 &&
                         mouse.LeftButton == ButtonState.Pressed &&
                         craftContents[4] != null)
                    {
                        for (int i_ = 0; i_ < 4; i_++)
                        {
                            if (this.craftContents[i_] != null)
                                this.craftContents[i_].RemoveAmount(1);
                        }

                        draggingStack = craftContents[4].Clone(game) as InventoryStack;
                        draggingStack.isDragging = true;
                        craftContents[4].needRemove = true;
                        goto escapeFor;
                    }
                }
            }

            // Разделение стопок
            if (mouse.RightButton == ButtonState.Pressed && !isMouse2Pressed)
                isMouse2Pressed = true;
            else if (mouse.RightButton == ButtonState.Released && isMouse2Pressed)
            {
                isMouse2Pressed = false;

                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        // Обычный инвентарь
                        if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 249) + 3 &&
                            mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                            InventoryHelper.CanSplitStack(inventoryContents[(row * 9) + i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[(row * 9) + i]);
                            inventoryContents[(row * 9) + i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }
                        // Малый инвентарь
                        else if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + 423 + 3 &&
                            mouse.Y < 135 + 423 + 3 + 48 &&
                            InventoryHelper.CanSplitStack(game.smallInventory.inventoryContents[i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.smallInventory.inventoryContents[i]);
                            game.smallInventory.inventoryContents[i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }
                    }
                }
                for (int i = 0; i < 2; i++)
                {

                    // Инвентарь крафта: верх
                    if (mouse.X > 248 + 260 + (i * 54 + 4) &&
                        mouse.X < 248 + 260 + (i * 54 + 4) + 48 &&
                        mouse.Y > 135 + 75 + 3 &&
                        mouse.Y < 135 + 75 + 3 + 48 &&
                        InventoryHelper.CanSplitStack(this.craftContents[i]) &&
                        draggingStack == null)
                    {
                        InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, this.craftContents[i]);
                        this.craftContents[i] = splittedStack[0];
                        draggingStack = splittedStack[1];
                        draggingStack.isDragging = true;
                    }
                    // Инвентарь крафта: низ
                    else if (mouse.X > 248 + 260 + (i * 54 + 4) &&
                        mouse.X < 248 + 260 + (i * 54 + 4) + 48 &&
                        mouse.Y > 135 + 129 + 3 &&
                        mouse.Y < 135 + 129 + 3 + 48 &&
                        InventoryHelper.CanSplitStack(this.craftContents[i + 2]) &&
                        draggingStack == null)
                    {
                        InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, this.craftContents[i + 2]);
                        this.craftContents[i + 2] = splittedStack[0];
                        draggingStack = splittedStack[1];
                        draggingStack.isDragging = true;
                    }
                }
            }

            escapeFor:
            InventoryStack[] invStacks = new InventoryStack[] { craftContents[0], craftContents[1], craftContents[2], craftContents[3] };
            if (CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks)) && this.craftContents[4] == null)
            {
                InventoryStack output = CraftHelper.GetOutputForRecipe(CraftHelper.ConvertStacksToTypes(invStacks), game);
                this.craftContents[4] = output;
            }
            else if (!CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks)))
            {
                if (craftContents[4] != null)
                    this.craftContents[4].needRemove = true;
            }

            if (craftContents != null)
            {
                for (int i = 0; i < 5; i++)
                {
                    if (craftContents[i] != null && craftContents[i].needRemove)
                        craftContents[i] = null;
                }
            }

            base.Update();
        }
Esempio n. 28
0
            public override void Update(Mine2D game, Vector2 thisBlockPos)
            {
                MouseState mouse = Mouse.GetState();
                Vector2 mousePosInWorld = new Vector2((int)Mouse.GetState().X - 512 + game.player.pos.X, (int)Mouse.GetState().Y - 384 + game.player.pos.Y);
                if (mousePosInWorld.X < 0)
                    mousePosInWorld.X--;
                if (mousePosInWorld.Y < 0)
                    mousePosInWorld.Y--;
                Vector2 blockPosInPixels = game.world.GetBlockPixelPos(thisBlockPos);

                if (mousePosInWorld.X > blockPosInPixels.X &&
                    mousePosInWorld.X < blockPosInPixels.X + TextureAtlas.TEXTURE_SIZE &&
                    mousePosInWorld.Y > blockPosInPixels.Y &&
                    mousePosInWorld.Y < blockPosInPixels.Y + TextureAtlas.TEXTURE_SIZE &&
                    mouse.RightButton == ButtonState.Pressed && !isOpeningInventory)
                    isOpeningInventory = true;
                else if (mousePosInWorld.X > blockPosInPixels.X &&
                    mousePosInWorld.X < blockPosInPixels.X + TextureAtlas.TEXTURE_SIZE &&
                    mousePosInWorld.Y > blockPosInPixels.Y &&
                    mousePosInWorld.Y < blockPosInPixels.Y + TextureAtlas.TEXTURE_SIZE &&
                    mouse.RightButton == ButtonState.Released && isOpeningInventory)
                {
                    if (!game.isNormalInventoryOpen && !game.isFurnaceInventoryOpen)
                    {
                        game.workbenchInventory = this.inventory;
                        game.isWorkbenchInventoryOpen = true;
                    }

                    isOpeningInventory = false;
                }
            }
Esempio n. 29
0
        public void Update(Mine2D game)
        {
            MouseState mouse = Mouse.GetState();

            // Обычный инвентарь
            if (draggingStack == null)
            {
                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 249) + 3 &&
                            mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                            mouse.LeftButton == ButtonState.Pressed &&
                            game.normalInventory.inventoryContents[(row * 9) + i] != null)
                        {
                            draggingStack = game.normalInventory.inventoryContents[(row * 9) + i].Clone(game) as InventoryStack;
                            draggingStack.isDragging = true;
                            game.normalInventory.inventoryContents[(row * 9) + i].needRemove = true;
                            goto escapeFor;
                        }
                    }
                }
            }
            else
            {
                if (mouse.LeftButton == ButtonState.Pressed && !isMousePressed)
                    isMousePressed = true;
                else if (mouse.LeftButton == ButtonState.Released && isMousePressed)
                {
                    isMousePressed = false;
                    for (int row = 0; row < 3; row++)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            // Обычный инвентарь
                            if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                                mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + (row * 54 + 249) + 3 &&
                                mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                                (game.normalInventory.inventoryContents[(row * 9) + i] == null ||
                                InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack)))
                            {
                                if (game.normalInventory.inventoryContents[(row * 9) + i] == null)
                                    game.normalInventory.inventoryContents[(row * 9) + i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(game.normalInventory.inventoryContents[(row * 9) + i], draggingStack))
                                    game.normalInventory.inventoryContents[(row * 9) + i] = InventoryHelper.SumTwoStacks(game, game.normalInventory.inventoryContents[(row * 9) + i], draggingStack);
                                draggingStack = null;
                            }
                            // Малый инвентарь
                            else if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                                mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + 423 + 3 &&
                                mouse.Y < 135 + 423 + 3 + 48 &&
                                (game.smallInventory.inventoryContents[i] == null ||
                                InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack)))
                            {
                                if (game.smallInventory.inventoryContents[i] == null)
                                    game.smallInventory.inventoryContents[i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(game.smallInventory.inventoryContents[i], draggingStack))
                                    game.smallInventory.inventoryContents[i] = InventoryHelper.SumTwoStacks(game, game.smallInventory.inventoryContents[i], draggingStack);
                                draggingStack = null;
                            }
                        }
                        for (int i = 0; i < 3; i++)
                        {
                            // Инвентарь крафта
                            if (mouse.X > 248 + 86 + (i * 54 + 4) &&
                                mouse.X < 248 + 86 + (i * 54 + 4) + 48 &&
                                mouse.Y > 135 + (row * 54 + 48) + 3 &&
                                mouse.Y < 135 + (row * 54 + 48) + 3 + 48 &&
                                (inventoryContents[(row * 3) + i] == null ||
                                    InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 3) + i], draggingStack)))
                            {
                                if (inventoryContents[(row * 3) + i] == null)
                                    inventoryContents[(row * 3) + i] = draggingStack.Clone(game) as InventoryStack;
                                else if (InventoryHelper.CanSumTwoStacks(inventoryContents[(row * 3) + i], draggingStack))
                                    inventoryContents[(row * 3) + i] = InventoryHelper.SumTwoStacks(game, inventoryContents[(row * 3) + i], draggingStack);
                                draggingStack = null;
                            }
                        }
                    }
                }
            }

            if (draggingStack == null)
            {
                for (int i = 0; i < 9; i++)
                {
                    if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                        mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                        mouse.Y > 135 + 423 + 3 &&
                        mouse.Y < 135 + 423 + 3 + 48 &&
                        mouse.LeftButton == ButtonState.Pressed &&
                        game.smallInventory.inventoryContents[i] != null)
                    {
                        draggingStack = game.smallInventory.inventoryContents[i].Clone(game) as InventoryStack;
                        draggingStack.isDragging = true;
                        game.smallInventory.inventoryContents[i].needRemove = true;
                        goto escapeFor;
                    }
                }
            }

            if (draggingStack == null)
            {
                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (mouse.X > 248 + 86 + (i * 54 + 4) &&
                            mouse.X < 248 + 86 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 48) + 3 &&
                            mouse.Y < 135 + (row * 54 + 48) + 3 + 48 &&
                            mouse.LeftButton == ButtonState.Pressed &&
                            inventoryContents[(row * 3) + i] != null)
                        {
                            draggingStack = inventoryContents[(row * 3) + i].Clone(game) as InventoryStack;
                            draggingStack.isDragging = true;
                            inventoryContents[(row * 3) + i].needRemove = true;
                            goto escapeFor;
                        }
                    }
                }

                if (mouse.X > 248 + 368 + 4 &&
                    mouse.X < 248 + 368 + 4 + 48 &&
                    mouse.Y > 135 + 54 + 48 + 3 &&
                    mouse.Y < 135 + 54 + 48 + 3 + 48 &&
                    mouse.LeftButton == ButtonState.Pressed &&
                    inventoryContents[9] != null)
                {
                    for (int i_ = 0; i_ < 9; i_++)
                    {
                        if (inventoryContents[i_] != null)
                            inventoryContents[i_].RemoveAmount(1);
                    }
                    draggingStack = inventoryContents[9].Clone(game) as InventoryStack;
                    draggingStack.isDragging = true;
                    inventoryContents[9].needRemove = true;
                    goto escapeFor;
                }
            }

            // Разделение стопок
            if (mouse.RightButton == ButtonState.Pressed && !isMouse2Pressed)
                isMouse2Pressed = true;
            else if (mouse.RightButton == ButtonState.Released && isMouse2Pressed)
            {
                isMouse2Pressed = false;

                for (int row = 0; row < 3; row++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        // Обычный инвентарь
                        if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 249) + 3 &&
                            mouse.Y < 135 + (row * 54 + 249) + 3 + 48 &&
                            InventoryHelper.CanSplitStack(game.normalInventory.inventoryContents[(row * 9) + i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.normalInventory.inventoryContents[(row * 9) + i]);
                            game.normalInventory.inventoryContents[(row * 9) + i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }
                        // Малый инвентарь
                        else if (mouse.X > 248 + 20 + (i * 54 + 4) &&
                            mouse.X < 248 + 20 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + 423 + 3 &&
                            mouse.Y < 135 + 423 + 3 + 48 &&
                            InventoryHelper.CanSplitStack(game.smallInventory.inventoryContents[i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, game.smallInventory.inventoryContents[i]);
                            game.smallInventory.inventoryContents[i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }

                    }
                    for (int i = 0; i < 3; i++)
                    {
                        // Инвентарь крафта
                        if (mouse.X > 248 + 86 + (i * 54 + 4) &&
                            mouse.X < 248 + 86 + (i * 54 + 4) + 48 &&
                            mouse.Y > 135 + (row * 54 + 48) + 3 &&
                            mouse.Y < 135 + (row * 54 + 48) + 3 + 48 &&
                            InventoryHelper.CanSplitStack(inventoryContents[(row * 3) + i]) &&
                            draggingStack == null)
                        {
                            InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[(row * 3) + i]);
                            inventoryContents[(row * 3) + i] = splittedStack[0];
                            draggingStack = splittedStack[1];
                            draggingStack.isDragging = true;
                        }
                    }
                    if (mouse.X > 248 + 368 + 4 &&
                        mouse.X < 248 + 368 + 4 + 48 &&
                        mouse.Y > 135 + 54 + 48 + 3 &&
                        mouse.Y < 135 + 54 + 48 + 3 + 48 &&
                        InventoryHelper.CanSplitStack(inventoryContents[9]) &&
                        draggingStack == null)
                    {
                        InventoryStack[] splittedStack = InventoryHelper.SplitStack(game, inventoryContents[9]);
                        inventoryContents[9] = splittedStack[0];
                        draggingStack = splittedStack[1];
                        draggingStack.isDragging = true;
                    }
                }
            }

            escapeFor:
            InventoryStack[] invStacks = new InventoryStack[9];
            Array.ConstrainedCopy(inventoryContents, 0, invStacks, 0, 9);
            if (CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks)) && this.inventoryContents[9] == null)
            {
                InventoryStack output = CraftHelper.GetOutputForRecipe(CraftHelper.ConvertStacksToTypes(invStacks), game);
                this.inventoryContents[9] = output;
            }
            else if (!CraftHelper.CheckIsExistingRecipe(CraftHelper.ConvertStacksToTypes(invStacks)))
            {
                if (inventoryContents[9] != null)
                    this.inventoryContents[9].needRemove = true;
            }

            if (inventoryContents != null)
            {
                for (int i = 0; i < 10; i++)
                {
                    if (inventoryContents[i] != null && inventoryContents[i].needRemove)
                        inventoryContents[i] = null;
                }
            }

            game.normalInventory.Update();
            base.Update();
        }