Example #1
0
 public EntityFallingTile(int x, int y, int index, World.TileDepth tileDepth)
     : base(x, y)
 {
     this.index = index;
     this.tileDepth = tileDepth;
     stack = new ItemStack(Item.itemTile, 1, index);
 }
Example #2
0
        public override void update(Game game, World world)
        {
            bool gravityOn = true;

            if (pickUpDelay <= 0) {
                float d = Vector2.Distance(world.player.position, position);
                Rectangle pr = new Rectangle((int)world.player.position.X, (int)world.player.position.Y, (int)world.player.size.X, (int)world.player.size.Y);
                Rectangle r = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);

                foreach(Entity e in world.EntityList){
                    if (e is EntityItem) {
                        EntityItem ei = ((EntityItem)e);
                        if (e.uniqueID < uniqueID) {
                            if(ei.stack.getItem().index == stack.getItem().index && ei.stack.getData() == stack.getData()){
                                if(Vector2.Distance(ei.position, position) < (World.tileSizeInPixels)){
                                    ei.stack.setCount(stack.setCount(stack.getCount() + ei.stack.getCount()));
                                }
                            }
                        }
                    }
                }

                if (pr.Intersects(r)) {
                    stack = game.inventory.pickUp(stack);
                    if(stack.isEmpty()){
                        if (!playedSoundEffectRecently) {
                            SoundEffectPlayer.playSoundWithRandomPitch(SoundEffectPlayer.SoundPop);
                        }
                    }
                    pickUpDelay = maxPickupDelay;
                } else if (d < (6 * World.tileSizeInPixels)) {
                    position += ((world.player.position - position)/d) * 4;
                    gravityOn = false;
                }
            }

            if (stack.isEmpty()) {
                remove(game, world);
            }

            if (!collision(world, speed.X, 0)) {
                position.X += speed.X;
            } else {
                speed.X = 0;
            }

            if (!collision(world, 0, speed.Y)) {
                position.Y += speed.Y;
            } else {
                speed.Y = 0;
            }

            if (collision(world, 0, 1)) {

            } else if (gravityOn) {
                speed.Y += gravityAcc;
            }

            pickUpDelay--;
        }
Example #3
0
        public override bool processCommand(IStringPrinter printer, string[] options)
        {
            if (options.Length == 1 || options.Length == 2 || options.Length == 3) {
                int id = 0;
                int count = 1;
                int data = 0;

                try {
                    id = toInt(options[0]);
                } catch (NumberInvalidException e) {
                    foreach(Item item in Item.ItemList){
                        if(item != null){
                            if (equalsIgnoreCase(item.name, e.s)) {
                                id = item.index;
                                break;
                            }
                        }
                    }
                    if(id == 0){
                        throw new NoSuchItemException(e.s);
                    }
                }

                if(options.Length >= 2){
                    count = toInt(options[1]);
                }

                if (options.Length == 3) {
                    try {
                        data = toInt(options[2]);
                    } catch (NumberInvalidException e) {
                        if (id == Item.itemTile.index) {
                            foreach (Tile tile in Tile.TileList) {
                                if (tile != null) {
                                    if (equalsIgnoreCase(tile.name, e.s)) {
                                        data = tile.index;
                                        break;
                                    }
                                }
                            }
                            if (data == 0) {
                                throw new NoSuchTileException(e.s);
                            }
                        } else {
                            throw e;
                        }
                    }
                }

                if(id != Item.itemEmpty.index){
                    ItemStack stack = new ItemStack(Item.ItemList[id], count, data);
                    printer.println("Gave you "+stack.getDisplayName(false));
                    Game.instance.inventory.pickUp(stack);
                }

                return true;
            } else {
                throw new InvalidNumberOfArgumentsException(options.Length);
            }
        }
Example #4
0
 public override void drawHover(Game game, int mouseTileX, int mouseTileY, ItemStack currentItem)
 {
     if (game.currentWorld != null && (game.currentWorld.getTileIndex(mouseTileX, mouseTileY, World.TileDepth.wall) != Tile.TileAir.index || game.currentWorld.getTileIndex(mouseTileX, mouseTileY, World.TileDepth.tile) != Tile.TileAir.index)) {
         Rectangle r = new Rectangle((mouseTileX * World.tileSizeInPixels) - game.currentWorld.viewOffset.X, (mouseTileY * World.tileSizeInPixels) - game.currentWorld.viewOffset.Y, World.tileSizeInPixels, World.tileSizeInPixels);
         Game.drawRectangle(Game.dummyTexture, r, r, new Color(.5f, .5f, .5f, .5f), Game.RENDER_DEPTH_HOVER);
     }
 }
Example #5
0
 public override ItemStack rightClick(Game game, ItemStack stack, int xTile, int yTile, int distance)
 {
     if (game.currentWorld.player.swingTime <= 0 || game.currentWorld.player.swingTime > swingMaxTime) {
         game.currentWorld.player.swingTime = swingMaxTime;
     }
     return stack;
 }
Example #6
0
 public Inventory()
 {
     for (int i = 0; i < items.Length; i++) {
         items[i] = new ItemStack(Item.itemEmpty);
     }
     pickUp(new ItemStack(Item.itemSupick));
     updateValaidRecipes();
 }
Example #7
0
        public bool Equals(ItemStack i)
        {
            if ((object)i == null) {
                return false;
            }

            return item.index == i.item.index && count == i.count && data == i.data;
        }
Example #8
0
 public override bool drawHover(Game game, int mouseTileX, int mouseTileY, ItemStack currentItem)
 {
     if (canBePlacedHere(game.currentWorld, mouseTileX, mouseTileY, World.TileDepth.tile)) {
         Rectangle rect = get8(0, 0);
         rect.Height = 24;
         Game.drawRectangle(Tile.TileSheet, new Rectangle((mouseTileX * World.tileSizeInPixels) - game.currentWorld.viewOffset.X, ((mouseTileY-2) * World.tileSizeInPixels) - game.currentWorld.viewOffset.Y, World.tileSizeInPixels, World.tileSizeInPixels*3), rect, new Color(.5f, .5f, .5f, .5f), Game.RENDER_DEPTH_HOVER);
     }
     return true;
 }
Example #9
0
 public override bool drawHover(Game game, int mouseTileX, int mouseTileY, ItemStack currentItem)
 {
     if (canBePlacedHere(game.currentWorld, mouseTileX, mouseTileY, World.TileDepth.tile)) {
         Rectangle rect = get8(0, 0);
         rect.Width = 8 * size.X;
         rect.Height = 8 * size.Y;
         game.spriteBatch.Draw(Tile.TileSheet, new Rectangle(((mouseTileX) * World.tileSizeInPixels) - game.currentWorld.viewOffset.X, ((mouseTileY - (size.Y - 1)) * World.tileSizeInPixels) - game.currentWorld.viewOffset.Y, World.tileSizeInPixels * size.X, World.tileSizeInPixels * size.Y), rect, new Color(.5f, .5f, .5f, .5f), 0, Vector2.Zero, game.currentWorld.player.facingRight ? SpriteEffects.None : SpriteEffects.FlipHorizontally, Game.RENDER_DEPTH_HOVER);
     }
     return true;
 }
Example #10
0
        public override ItemStack leftClick(Game game, ItemStack stack, int xTile, int yTile, int distance)
        {
            if (getPower(game.currentWorld.getTileObjectNoCheck(xTile, yTile, World.TileDepth.tile).material) <= 0) {
                return stack;
            }

            if (game.currentWorld.player.swingTime <= 0 && mine(game, stack, xTile, yTile, distance, World.TileDepth.tile)) {
                game.currentWorld.player.swingTime = swingMaxTime;
            }
            return stack;
        }
Example #11
0
 public override void drawHover(Game game, int mouseTileX, int mouseTileY, ItemStack currentItem)
 {
     if (!Tile.getTileObject(currentItem.getData()).drawHover(game, mouseTileX, mouseTileY, currentItem)) {
         Tile tile = Tile.getTileObject(currentItem.getData());
         bool tileGoesHere = tile.canBePlacedHere(game.currentWorld, mouseTileX, mouseTileY, World.TileDepth.tile);
         bool wallGoesHere = tile.canBePlacedHere(game.currentWorld, mouseTileX, mouseTileY, World.TileDepth.wall);
         if (tileGoesHere || wallGoesHere) {
             Game.drawRectangle(Tile.TileSheet, new Rectangle((mouseTileX * World.tileSizeInPixels) - game.currentWorld.viewOffset.X, (mouseTileY * World.tileSizeInPixels) - game.currentWorld.viewOffset.Y, World.tileSizeInPixels, World.tileSizeInPixels), Tile.getTileObject(currentItem.getData()).getTextureInfo(mouseTileX, mouseTileY, game.currentWorld, World.TileDepth.tile).rectangle, new Color(.5f, .5f, .5f, .5f), Game.RENDER_DEPTH_HOVER);
         }
     }
 }
Example #12
0
 public override ItemStack leftClick(Game game, ItemStack stack, int xTile, int yTile, int distance)
 {
     if (Tile.getTileObject(stack.getData()) != null && distance <= reach) {
         if (game.currentWorld.getTileIndex(xTile, yTile, World.TileDepth.tile) == Tile.TileAir.index) {
             if (Tile.getTileObject(stack.getData()).canBePlacedHere(game.currentWorld, xTile, yTile, World.TileDepth.tile)) {
                 if (!collision(game.currentWorld, xTile, yTile, Tile.getTileObject(stack.getData()).isSolid(game.currentWorld, xTile, yTile))) {
                     if (game.currentWorld.setTileWithUpdate(xTile, yTile, stack.getData(), World.TileDepth.tile)) {
                         game.currentWorld.getTileObjectNoCheck(xTile, yTile, World.TileDepth.tile).justPlaced(game.currentWorld, xTile, yTile, World.TileDepth.tile);
                         stack.setCount(stack.getCount() - 1);
                     }
                 }
             }
         }
     }
     return stack;
 }
Example #13
0
        public bool mine(Game game, ItemStack stack, int xTile, int yTile, int distance, World.TileDepth tileDepth)
        {
            int del = delay;
            Tile.Material mat = game.currentWorld.getTileObjectNoCheck(xTile, yTile, tileDepth).material;

            if (mat == Tile.Material.furniture) {
                del = 20;
            }
            int power = getPower(mat);
            if (power <= 0) {
                return false;
            }
            game.inventory.t++;
            if (game.inventory.t >= del && distance <= reach) {
                game.inventory.t = 0;
                Tile tile = game.currentWorld.getTileObject(xTile, yTile, tileDepth);
                if (tile.index != Tile.TileAir.index) {
                    SoundEffectPlayer.playSoundWithRandomPitch(SoundEffectPlayer.SoundTink);
                    int m = ((int)game.currentWorld.getCrackNoCheck(xTile, yTile));
                    if (m == 0) {
                        game.inventory.t = 0;
                    }
                    int n = m + power;
                    int max = (Tile.getTileObject(tile.index)).toughness;
                    if (n > max) {
                        n = max;
                    }
                    game.currentWorld.setCrackNoCheck(xTile, yTile, (byte)n);

                    if (n == max) {
                        if (game.currentWorld.mineTile(xTile, yTile, this, tileDepth)) {
                            game.currentWorld.setCrackNoCheck(xTile, yTile, 0);
                        }
                    }
                    return true;
                }
            }
            return false;
        }
Example #14
0
        public override void drawOverPlayer(Game game, ItemStack currentItem, bool facingRight, Vector2 position, Color color, Point mousePosition)
        {
            if (game.currentWorld.player.swingTime >= 0) {
                Rectangle rect = currentItem.getItem().textureInfo.rectangle;

                float rotation = 0;

                int x = (int)(position.X - (rect.Width / 2) - game.currentWorld.viewOffset.X);
                int y = (int)(position.Y - game.currentWorld.viewOffset.Y + (rect.Width / 2));

                if(swings){
                    rotation = (((float)game.currentWorld.player.swingTime / (float)swingMaxTime) * 225.0f) - 135.0f;
                    rotation = facingRight ? -rotation : rotation;
                } else {
                    rotation = MathHelper.ToDegrees((float)Math.Atan2((y - mousePosition.Y), (x - mousePosition.X))) + 45;
                    rotation = facingRight ? rotation+180 : rotation-90;
                }

                rotation = MathHelper.ToRadians(rotation);
                Vector2 origin = new Vector2(facingRight ? 0 : textureInfo.rectangle.Width, textureInfo.rectangle.Height);
                game.spriteBatch.Draw(ItemSheet, new Rectangle(x, y, rect.Width * 2, rect.Height * 2), rect, color, rotation, origin, facingRight ? SpriteEffects.None : SpriteEffects.FlipHorizontally, Game.RENDER_DEPTH_OVER_PLAYER);
            }
        }
Example #15
0
 public override ItemStack use(Game game, ItemStack currentItem, int mouseTileX, int mouseTileY, int mouseTileDistanceFromPlayer, World.TileDepth tileDepth)
 {
     game.currentWorld.setTileWithDataWithUpdate(mouseTileX, mouseTileY, index, game.currentWorld.getTileData(mouseTileX, mouseTileY, tileDepth)==0?1:0, tileDepth);
     return base.use(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer, tileDepth);
 }
Example #16
0
        public override void draw(Game game, GameTime gameTime)
        {
            if (game.currentWorld.player == null) {
                return;
            }

            int xx = 0;
            int yy = 0;
            int itemIndex = 0;
            Rectangle r;

            if (currentItem!=null) {
               Game.drawString(currentItem.getDisplayName(false), new Vector2(8, 4), hotBarColor, Game.RENDER_DEPTH_GUI_TEXT);
               }

            for(int i=0; i < 10; i++){
                xx = x + (selectedSlot == i ? (cursorItem.isEmpty() ? 4 : 2) : 0) + inventoryMove + 4;
                yy = y + (i * gridSize);
                r = new Rectangle(xx + squareBorderSize, yy + squareBorderSize, itemSize, itemSize);
                Game.drawRectangle(guiTexture, new Rectangle(xx, yy, squareSize, squareSize), new Rectangle(0, 0, 20, 20), hotBarColor, Game.RENDER_DEPTH_GUI_IMAGE_BG);
                items[itemIndex].draw(game, r, hotBarColor, Game.RENDER_DEPTH_GUI_IMAGE_FG, Game.RENDER_DEPTH_GUI_TEXT);
                Game.drawString((i == 9 ? 0 : i + 1) + "", new Vector2(xx + 22, yy + 3), hotBarColor, Game.RENDER_DEPTH_GUI_TEXT);

                itemIndex++;
            }

            if (inventoryFade>0) {
                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 4; j++) {
                        xx = x + (j * gridSize) + inventoryMove - (gridSize * 4);
                        yy = y + (i * gridSize);
                        r = new Rectangle(xx + squareBorderSize, yy + squareBorderSize, itemSize, itemSize);
                        Game.drawRectangle(guiTexture, new Rectangle(xx, yy, squareSize, squareSize), new Rectangle(0, 0, 20, 20), inventoryColor, Game.RENDER_DEPTH_GUI_IMAGE_BG);
                        items[itemIndex].draw(game, r, inventoryColor, Game.RENDER_DEPTH_GUI_IMAGE_FG, Game.RENDER_DEPTH_GUI_TEXT);

                        itemIndex++;
                    }
                }

                float a = inventoryFade * (mouseInCrafting ? 1 : .5f);
                Color color = new Color(a, a, a, a);
                Game.drawString(" Crafting", new Vector2(inventoryMove - (gridSize * 4), craftingAreaY - gridSize*.5f), color, Game.RENDER_DEPTH_GUI_TEXT);

                for (int i = -2; i <= 2; i++) {
                    int j = i + craftingScroll;
                    if (j >= 0 && j < valaidRecipes.Count()) {
                        xx = x + (i * gridSize) + inventoryMove - (gridSize * 2);
                        yy = y + craftingAreaY;
                        r = new Rectangle(xx + squareBorderSize, yy + squareBorderSize, itemSize, itemSize);
                        int abs = Math.Abs(i);
                        a = (inventoryFade * (abs == 3 ? .1f : (abs == 2 ? .2f : (abs == 1 ? .5f : 1)))) * (mouseInCrafting ? 1 : .1f);
                        color = new Color(a, a, a, a);
                        Game.drawRectangle(guiTexture, new Rectangle(xx, yy, squareSize, squareSize), new Rectangle(0, 0, 20, 20), color, Game.RENDER_DEPTH_GUI_IMAGE_BG);
                        valaidRecipes[j].result.draw(game, r, color, Game.RENDER_DEPTH_GUI_IMAGE_FG, Game.RENDER_DEPTH_GUI_TEXT);
                        for (int k = 0; k < valaidRecipes[j].ingredients.Length; k++) {
                            xx = x + (i * gridSize) + inventoryMove - (gridSize * 2);
                            yy = y + 4 + ((k + 1) * gridSize) + craftingAreaY;
                            r = new Rectangle(xx + squareBorderSize, yy + squareBorderSize, itemSize, itemSize);
                            valaidRecipes[j].ingredients[k].draw(game, r, color, Game.RENDER_DEPTH_GUI_IMAGE_FG, Game.RENDER_DEPTH_GUI_TEXT);
                        }
                    }
                }

            }

            MouseState mouseState = Mouse.GetState();

            xx = mouseState.X + 10;
            yy = mouseState.Y + 10;
            r = new Rectangle(xx + 2, yy + 2, itemSize, itemSize);

            if (inventoryFade > 0 && !cursorItem.isEmpty()) {
                cursorItem.draw(game, r, inventoryColor, Game.RENDER_DEPTH_GUI_CURSOR_IMAGE_FG, Game.RENDER_DEPTH_GUI_CURSOR_TEXT);
                Game.drawString(cursorItem.getDisplayName(true), new Vector2(r.X + 24, r.Y), inventoryColor, Game.RENDER_DEPTH_GUI_CURSOR_TEXT);
            } else if (inventoryFade > 0 && mouseItemSlot != -1 && !items[mouseItemSlot].isEmpty()) {
                Game.drawString(items[mouseItemSlot].getDisplayName(true), new Vector2(xx + 2, yy + 2), inventoryColor, Game.RENDER_DEPTH_GUI_CURSOR_TEXT);
            } else if (inventoryFade > 0 && !items[selectedSlot].isEmpty()) {
                items[selectedSlot].draw(game, r, (mouseTileDistanceFromPlayer <= items[selectedSlot].getItem().reach) ? Color.White : new Color(.1f, .1f, .1f, .1f), Game.RENDER_DEPTH_GUI_CURSOR_IMAGE_FG, Game.RENDER_DEPTH_GUI_TEXT);
            }

            currentItem = cursorItem.isEmpty() ? items[selectedSlot] : cursorItem;

            if ((mouseTileDistanceFromPlayer <= currentItem.getItem().reach)) {
                currentItem.getItem().drawHover(game, mouseTileX, mouseTileY, currentItem);
            }

            Game.drawRectangle(guiTexture, new Rectangle(mouseState.X, mouseState.Y, 16, 16), new Rectangle(0, 20, 16, 16), Game.cursorColor, Game.RENDER_DEPTH_GUI_CURSOR_IMAGE_BG);
        }
Example #17
0
 private void setCurrentItem(ItemStack itemStack, bool cursor)
 {
     if (cursor) {
         cursorItem = itemStack;
     } else {
         items[selectedSlot] = itemStack;
     }
 }
Example #18
0
 private void setCurrentItem(ItemStack itemStack)
 {
     if (cursorItem.isEmpty()) {
         items[selectedSlot] = itemStack;
     } else {
         cursorItem = itemStack;
     }
 }
Example #19
0
 private void removeItemStacks(int minSlot, int maxSlot, ItemStack[] stacks)
 {
     foreach(ItemStack stack in stacks){
         for (int i = minSlot; i <= maxSlot; i++) {
             if (items[i].sameItem(stack)) {
                 if (items[i].getCount() >= stack.getCount()) {
                     items[i].setCount(items[i].getCount()-stack.getCount());
                 }
             }
         }
     }
 }
Example #20
0
 private bool inventoryContainsStack(int minSlot, int maxSlot, ItemStack stack)
 {
     for (int i = minSlot; i <= maxSlot; i++) {
         if (items[i].getItem().index == stack.getItem().index) {
             if (items[i].getData() == stack.getData()) {
                 if (items[i].getCount() >= stack.getCount()) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Example #21
0
        public override InputState update(Game game, InputState inputState)
        {
            mouseInCrafting = mouseInCraftingArea(inputState);

            if(game.currentWorld.player==null){
                return inputState;
            }

            #region Scrolling and Fading

            int xx = 0;
            int yy = 0;

            int scrollDif = inputState.getScrollWheelValue() - lastScrollValue;

            if (scrollDif != 0) {

                if (mouseInCrafting && inventoryFadingIn) {
                    if (scrollDif > 0) {
                        scrollDif -= 1;
                        craftingScroll -= 1;
                    }
                    if (scrollDif < 0) {
                        scrollDif += 1;
                        craftingScroll += 1;
                    }
                    while (craftingScroll < 0) {
                        craftingScroll++;
                    }
                    while (craftingScroll >= valaidRecipes.Count()) {
                        craftingScroll--;
                    }
                }else{
                    if (scrollDif > 0) {
                        scrollDif -= 1;
                        selectedSlot -= 1;
                    }
                    if (scrollDif < 0) {
                        scrollDif += 1;
                        selectedSlot += 1;
                    }
                    while (selectedSlot >= 10) {
                        selectedSlot -= 10;
                    }
                    while (selectedSlot < 0) {
                        selectedSlot += 10;
                    }
                    hotBarFadingIn = true;
                }
            }

            if (hotBarFadingIn) {
                if (hotBarFade < 2f) {
                    hotBarFade += .05f;
                } else {
                    hotBarFadingIn = false;
                }
            } else {
                if (hotBarFade > .2f) {
                    hotBarFade -= .01f;
                }
            }

            if(inputState.pressed(Game.KEY_INV)){
                inventoryFadingIn = !inventoryFadingIn;
            }
            if (inventoryFadingIn) {
                if (inventoryFade < 1f) {
                    inventoryFade += .05f;
                }
            } else {
                if (inventoryFade > 0f) {
                    inventoryFade -= .05f;
                } else {
                    dropItem(game, cursorItem);
                    cursorItem = new ItemStack(Item.itemEmpty);
                }
            }

            inventoryMove = (int)(inventoryFade * ((gridSize * 3) + gridSize + 2));

            if (hotBarFade<0) {
                hotBarFade = 0;
            }

            if (inventoryFade < 0) {
                inventoryFade = 0;
            }

            float f = Math.Max(hotBarFade, inventoryFade);
            hotBarColor = new Color(f, f, f, f);
            inventoryColor = new Color(inventoryFade, inventoryFade, inventoryFade, inventoryFade);
            lastScrollValue = inputState.getScrollWheelValue();

            if(inputState.pressed(Game.KEY_D1)){
                selectedSlot = 0;
            } else if (inputState.pressed(Game.KEY_D2)) {
                selectedSlot = 1;
            } else if (inputState.pressed(Game.KEY_D3)) {
                selectedSlot = 2;
            } else if (inputState.pressed(Game.KEY_D4)) {
                selectedSlot = 3;
            } else if (inputState.pressed(Game.KEY_D5)) {
                selectedSlot = 4;
            } else if (inputState.pressed(Game.KEY_D6)) {
                selectedSlot = 5;
            } else if (inputState.pressed(Game.KEY_D7)) {
                selectedSlot = 6;
            } else if (inputState.pressed(Game.KEY_D8)) {
                selectedSlot = 7;
            } else if (inputState.pressed(Game.KEY_D9)) {
                selectedSlot = 8;
            } else if (inputState.pressed(Game.KEY_D0)) {
                selectedSlot = 9;
            }

            #endregion

            mouseItemSlot = -1;
            mouseCraftSlot = -1;

            int itemIndex = 0;

            for (int i = 0; i < 10; i++) {
                xx = x + (selectedSlot == i ? 4 : 0) + inventoryMove + 4;
                yy = y + (i * gridSize);
                if (new Rectangle(xx, yy, gridSize, gridSize).Contains(inputState.mouseX(), inputState.mouseY())) {
                    mouseItemSlot = itemIndex;
                }
                itemIndex++;
            }

            if (inventoryFade > 0) {

                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 4; j++) {
                        xx = x + (j * gridSize) + inventoryMove - (gridSize * 4);
                        yy = y + (i * gridSize);
                        if (new Rectangle(xx, yy, gridSize, gridSize).Contains(inputState.mouseX(), inputState.mouseY())) {
                            mouseItemSlot = itemIndex;
                        }
                        itemIndex++;
                    }
                }

                for (int i = -2; i <= 2; i++) {
                    int j = i + craftingScroll;
                    if (j >= 0 && j < valaidRecipes.Count()) {
                        xx = x + (i * gridSize) + inventoryMove - (gridSize * 2);
                        yy = y + craftingAreaY;
                        if (new Rectangle(xx, yy, gridSize, gridSize).Contains(inputState.mouseX(), inputState.mouseY())) {
                            mouseCraftSlot = j;
                        }
                    }
                }
            }

            bool isCursor = !cursorItem.isEmpty();
            ItemStack currentItem = isCursor ? cursorItem : items[selectedSlot];
            if (game.currentWorld != null) {
                mouseTileX = (inputState.mouseX() + game.currentWorld.viewOffset.X) / World.tileSizeInPixels;
                mouseTileY = (inputState.mouseY() + game.currentWorld.viewOffset.Y) / World.tileSizeInPixels;
                mouseTileDistanceFromPlayer = (int)Vector2.Distance(new Vector2(mouseTileX * World.tileSizeInPixels, mouseTileY * World.tileSizeInPixels), game.currentWorld.player.position + (game.currentWorld.player.size / 2));
            }

            if (mouseItemSlot == -1 && mouseCraftSlot == -1) {

                if (inputState.downMouse(InputState.Left)) {
                    setCurrentItem(currentItem.getItem().leftClick(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer), isCursor);
                }
                if (inputState.downMouse(InputState.Right)) {
                    setCurrentItem(currentItem.getItem().rightClick(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer), isCursor);
                }
                if(inputState.pressed(Game.KEY_USE)){
                    ItemStack useItem = currentItem;
                    Tile tileWall = game.currentWorld.getTileObject(mouseTileX, mouseTileY, World.TileDepth.wall);
                    Tile tileTile = game.currentWorld.getTileObject(mouseTileX, mouseTileY, World.TileDepth.tile);
                    if (tileWall.index != Tile.TileAir.index || tileTile.index != Tile.TileAir.index) {
                        useItem = (tileTile.index == Tile.TileAir.index ? tileWall : tileTile).use(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer, tileTile.index == Tile.TileAir.index?World.TileDepth.wall:World.TileDepth.tile);
                    }
                    if(useItem!=null){
                        setCurrentItem(useItem);
                    }
                }

            }

            currentItem.getItem().updateAfterClick(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer);

            bool leftClick = false;
            bool rightClick = false;

            int speed1Time = 40;
            int speed2Time = 200;
            int speed3Time = 400;

            if (inputState.downMouse(InputState.Left)) {
                if (leftClickTimer == 0) {
                    leftClick = true;
                } else if (leftClickTimer > speed1Time) {
                    if (leftClickTimer > speed3Time) {
                        leftClick = true;
                    } else if (leftClickTimer > speed2Time) {
                        if (leftClickTimer % 2 == 0) {
                            leftClick = true;
                        }
                    } else if (leftClickTimer % 10 == 0) {
                        leftClick = true;
                    }
                }
                leftClickTimer++;
            } else {
                leftClickTimer = 0;
            }

            if (inputState.downMouse(InputState.Right)) {
                if (rightClickTimer == 0) {
                    rightClick = true;
                } else if (rightClickTimer > speed1Time) {
                    if (rightClickTimer > speed3Time) {
                        rightClick = true;
                    } else if (rightClickTimer > speed2Time) {
                        if (rightClickTimer % 2 == 0) {
                            rightClick = true;
                        }
                    } else if (rightClickTimer % 10 == 0) {
                        rightClick = true;
                    }
                }
                rightClickTimer++;
            } else {
                rightClickTimer = 0;
            }

            if(inventoryFade == 0){
                if (mouseItemSlot >= 0 && mouseItemSlot < 10) {
                    hotBarFadingIn = true;

                    if (leftClick) {
                        selectedSlot = mouseItemSlot;
                    }
                }
            }else if (!(mouseItemSlot == -1 && mouseCraftSlot == -1)) {
                if (mouseItemSlot == -1 && mouseCraftSlot == craftingScroll) {
                    if (leftClick) {
                        if (inputState.getKeyboardState().IsKeyDown(Game.KEY_INV_MOVE_ITEM_TO_OTHER)) {
                            removeItemStacks(0, 49, valaidRecipes[mouseCraftSlot].ingredients);
                            pickUp(valaidRecipes[mouseCraftSlot].result.clone());
                        } else {
                            if (cursorItem.sameItem(valaidRecipes[mouseCraftSlot].result)) {
                                if (cursorItem.getCount() + valaidRecipes[mouseCraftSlot].result.getCount() <= cursorItem.getItem().maxStack) {
                                    cursorItem.setCount(cursorItem.getCount() + valaidRecipes[mouseCraftSlot].result.getCount());
                                    removeItemStacks(0, 49, valaidRecipes[mouseCraftSlot].ingredients);
                                }
                            } else if (cursorItem.isEmpty()) {
                                cursorItem = valaidRecipes[mouseCraftSlot].result.clone();
                                removeItemStacks(0, 49, valaidRecipes[mouseCraftSlot].ingredients);
                            }
                        }
                        updateValaidRecipes();
                    }
                } else if (mouseItemSlot == -1 && (mouseCraftSlot >= 0)) {
                    if (leftClick) {
                        craftingScroll = mouseCraftSlot;
                    }
                } else {
                    if (leftClick) {
                        if (cursorItem.sameItem(items[mouseItemSlot])) {
                            if (items[mouseItemSlot].getCount() < cursorItem.getItem().maxStack && cursorItem.getCount() > 0) {
                                cursorItem.setCount(items[mouseItemSlot].setCount(items[mouseItemSlot].getCount() + cursorItem.getCount()));
                            } else {
                                ItemStack c = cursorItem.clone();
                                cursorItem = items[mouseItemSlot].clone();
                                items[mouseItemSlot] = c.clone();
                            }
                        } else {
                            ItemStack c = cursorItem.clone();
                            cursorItem = items[mouseItemSlot].clone();
                            items[mouseItemSlot] = c.clone();
                        }
                        updateValaidRecipes();
                    }
                    if (rightClick) {
                        if (cursorItem.isEmpty() && items[mouseItemSlot].isEmpty()) {

                        }else if (cursorItem.isEmpty()) {

                            double c = items[mouseItemSlot].getCount() / 2.0;
                            Game.updateMessage += c;
                            cursorItem = items[mouseItemSlot].clone();
                            cursorItem.setCount((int)Math.Ceiling(c));
                            items[mouseItemSlot].setCount((int)Math.Floor(c));

                        } else if (items[mouseItemSlot].isEmpty()) {

                            items[mouseItemSlot] = cursorItem.clone();
                            items[mouseItemSlot].setCount(1);
                            cursorItem.setCount(cursorItem.getCount() - 1);

                        } else {
                            if (cursorItem.sameItem(items[mouseItemSlot])) {
                                if (!items[mouseItemSlot].isMax()) {
                                    items[mouseItemSlot].setCount(items[mouseItemSlot].getCount()+1);
                                    cursorItem.setCount(cursorItem.getCount() - 1);
                                }
                            } else {
                                ItemStack c = cursorItem.clone();
                                cursorItem = items[mouseItemSlot].clone();
                                items[mouseItemSlot] = c.clone();
                            }
                        }
                        updateValaidRecipes();
                    }
                }
            }

            if(inputState.pressed(Game.KEY_DROP)){
                game.currentWorld.EntityAddingList.Add(new EntityItem(game.currentWorld.player.position, new ItemStack(currentItem.getItem(), 1, currentItem.getData()), 60));
                currentItem.setCount(currentItem.getCount()-1);
                setCurrentItem(currentItem);
            }

            tick++;
            inputState.eatMouse();
            inputState.eatKey(Game.KEY_INV);
            inputState.eatKey(Game.KEY_INV_MOVE_ITEM_TO_OTHER);
            inputState.eatKey(Game.KEY_DROP);
            inputState.eatKey(Game.KEY_D0);
            inputState.eatKey(Game.KEY_D1);
            inputState.eatKey(Game.KEY_D2);
            inputState.eatKey(Game.KEY_D3);
            inputState.eatKey(Game.KEY_D4);
            inputState.eatKey(Game.KEY_D5);
            inputState.eatKey(Game.KEY_D6);
            inputState.eatKey(Game.KEY_D7);
            inputState.eatKey(Game.KEY_D8);
            inputState.eatKey(Game.KEY_D9);
            return inputState;
        }
Example #22
0
 public virtual bool drawHover(Game game, int mouseTileX, int mouseTileY, ItemStack currentItem)
 {
     return(false);
 }
Example #23
0
 public virtual void drawOverPlayer(Game game, ItemStack currentItem, bool facingRight, Vector2 position, Color color, Point mousePosition)
 {
 }
Example #24
0
        public override bool processCommand(IStringPrinter printer, string[] options)
        {
            if (options.Length == 1 || options.Length == 2 || options.Length == 3)
            {
                int id    = 0;
                int count = 1;
                int data  = 0;

                try {
                    id = toInt(options[0]);
                } catch (NumberInvalidException e) {
                    foreach (Item item in Item.ItemList)
                    {
                        if (item != null)
                        {
                            if (equalsIgnoreCase(item.name, e.s))
                            {
                                id = item.index;
                                break;
                            }
                        }
                    }
                    if (id == 0)
                    {
                        throw new NoSuchItemException(e.s);
                    }
                }

                if (options.Length >= 2)
                {
                    count = toInt(options[1]);
                }

                if (options.Length == 3)
                {
                    try {
                        data = toInt(options[2]);
                    } catch (NumberInvalidException e) {
                        if (id == Item.itemTile.index)
                        {
                            foreach (Tile tile in Tile.TileList)
                            {
                                if (tile != null)
                                {
                                    if (equalsIgnoreCase(tile.name, e.s))
                                    {
                                        data = tile.index;
                                        break;
                                    }
                                }
                            }
                            if (data == 0)
                            {
                                throw new NoSuchTileException(e.s);
                            }
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }

                if (id != Item.itemEmpty.index)
                {
                    ItemStack stack = new ItemStack(Item.ItemList[id], count, data);
                    printer.println("Gave you " + stack.getDisplayName(false));
                    Game.instance.inventory.pickUp(stack);
                }

                return(true);
            }
            else
            {
                throw new InvalidNumberOfArgumentsException(options.Length);
            }
        }
Example #25
0
 public bool sameItem(ItemStack i)
 {
     return i.data == data && i.getItem().index == getItem().index;
 }
Example #26
0
 public virtual void updateAfterClick(Game game, ItemStack currentItem, int mouseTileX, int mouseTileY, int mouseTileDistanceFromPlayer)
 {
 }
Example #27
0
 public virtual ItemStack use(Game game, ItemStack currentItem, int mouseTileX, int mouseTileY, int mouseTileDistanceFromPlayer, World.TileDepth tileDepth)
 {
     return(null);
 }
Example #28
0
 public virtual ItemStack rightClick(Game game, ItemStack stack, int xTile, int yTile, int distance)
 {
     return stack;
 }
Example #29
0
 public Recipe(ItemStack[] ingredients, ItemStack result)
 {
     Recipes.Add(this);
     this.ingredients = ingredients;
     this.result = result;
 }
Example #30
0
 public virtual void drawHover(Game game, int mouseTileX, int mouseTileY, ItemStack currentItem)
 {
 }
Example #31
0
 public void dropItem(Game game, ItemStack item)
 {
     if (item.getItem().index != Item.itemEmpty.index) {
         Entity e = new EntityItem(game.currentWorld.player.position, item, 40);
         game.currentWorld.EntityAddingList.Add(e);
     }
 }
Example #32
0
 public override ItemStack use(Game game, ItemStack currentItem, int mouseTileX, int mouseTileY, int mouseTileDistanceFromPlayer, World.TileDepth tileDepth)
 {
     return base.use(game, currentItem, mouseTileX, mouseTileY, mouseTileDistanceFromPlayer, tileDepth);
 }
Example #33
0
 public ItemStack pickUp(ItemStack stack)
 {
     for (int i = 0; i < items.Length;i++ ) {
         if(items[i].sameItem(stack)){
             if (items[i].getCount() < stack.getItem().maxStack && stack.getCount() > 0) {
                 stack.setCount(items[i].setCount(items[i].getCount() + stack.getCount()));
                 updateValaidRecipes();
                 return stack;
             }
         }
     }
     for (int i = 0; i < items.Length;i++ ) {
         if(items[i].isEmpty()){
             items[i] = stack;
             updateValaidRecipes();
             return new ItemStack(Item.itemEmpty);
         }
     }
     return stack;
 }