Exemple #1
0
        public override void HoldItem(Player player)
        {
            //this method determines if the pointed block is buildable and in range of the player
            //it shows the item icon if true
            //and it allows the actions in CanUseItem
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);                    //blocks
            //should have a connected solid tile (that is not empty nor a decorative element) or wall
            //should also be empty or a non-solid tile
            Tile tileTop   = Main.tile[myPlayer.pointedTileX, myPlayer.pointedTileY - 1];
            Tile tileBot   = Main.tile[myPlayer.pointedTileX, myPlayer.pointedTileY + 1];
            Tile tileLeft  = Main.tile[myPlayer.pointedTileX - 1, myPlayer.pointedTileY];
            Tile tileRight = Main.tile[myPlayer.pointedTileX + 1, myPlayer.pointedTileY];
            bool okTop     = tileTop.active() && Main.tileSolid[tileTop.type];
            bool okBot     = tileBot.active() && Main.tileSolid[tileBot.type];
            bool okLeft    = tileLeft.active() && Main.tileSolid[tileLeft.type];
            bool okRight   = tileRight.active() && Main.tileSolid[tileRight.type];

            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 &&
                (!myPlayer.pointedTile.active() || !Main.tileSolid[myPlayer.pointedTile.type] && !myPlayer.treeList.Contains(myPlayer.pointedTile.type)) &&
                (okTop || okBot || okLeft || okRight || myPlayer.pointedTile.wall != 0) &&
                VipixToolBoxWorld.toolEnabled["BlockWand"])
            {
                operationAllowed     = true;
                player.showItemIcon  = true;
                player.showItemIcon2 = mod.ItemType(toolNames[myPlayer.blockTool] + "Icon");
            }
            else
            {
                operationAllowed    = false;
                player.showItemIcon = false;
            }
        }
        public override bool CanUseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            if (Main.hardMode)
            {
                item.damage = 30;
            }
            else
            {
                item.damage = 10;
            }
            //the damage will be updated everytime the player tries to use the hammer...
            //CanUseItem will be called only once, so the UI won't 'slide'
            if (operationAllowed)
            {
                //basically a transfer from continuously updated variables to periodically updated variables of modplayer
                myPlayer.tileX    = myPlayer.pointedTileX;
                myPlayer.tileY    = myPlayer.pointedTileY;
                myPlayer.tbMouseX = Main.mouseX;
                myPlayer.tbMouseY = Main.mouseY;
                HammerUI.visible  = true;
            }
            return(true);
        }
Exemple #3
0
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(myMod);

            /*
             * bool choice;
             * if (!bool.TryParse(args[0], out choice))
             *      throw new UsageException(args[0] + " is not a valid value\ncenterUI accepts <true|false>");
             * else	myPlayer.centerUI = choice;*/
            if (args[0] == "fixed")
            {
                myPlayer.centerUI = 0;
            }
            else if (args[0] == "mouse")
            {
                myPlayer.centerUI = 1;
            }
            else if (args[0] == "free")
            {
                myPlayer.centerUI = 2;
            }
            else
            {
                throw new UsageException(args[0] + " is not a valid value\ncenterUI accepts <fixed|mouse|free>");
            }
        }
Exemple #4
0
        public void ButtonClicked(int index)
        {
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            myPlayer.blockTool = index;            //direct correspondance between list index and tool index
            visible            = false;
        }
Exemple #5
0
        public override void UpdateAccessory(Item item, Player player, bool hideVisual)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            if (item.Name == "World Shaper Soul") //feel free to create an item with this display name
            {
                myPlayer.fargoRange = 54;         //range of normal tools with fargo mod
            }
        }
Exemple #6
0
        public void ButtonClicked(int index)
        {
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            myPlayer.mossTool = index;
            visible           = false;
        }
Exemple #7
0
        public void ColorClicked(int index)
        {
            //Main.NewText(colorList[index].Left.Get().ToString(),255,255,255);
            //colorList[index].UIImageButtonTexture.Set();
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            //color button
            player.GetModPlayer <VipixToolBoxPlayer>().colorByte = (byte)index;
            visible = false;
        }
Exemple #8
0
        private void DragStart(UIMouseEvent evt, UIElement listeningElement)
        {
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            if (myPlayer.centerUI == 2)
            {
                offset   = new Vector2(evt.MousePosition.X - backgroundPanel.Left.Pixels, evt.MousePosition.Y - backgroundPanel.Top.Pixels);
                dragging = true;
            }
        }
Exemple #9
0
        public void ButtonClicked(int index)
        {
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();
            Tile               tile     = Main.tile[myPlayer.tileX, myPlayer.tileY];

            //the tile change is done here instead of useItem otherwise you wouldnt have the time to click on the button
            switch (index)
            {
            case 0:
                tile.halfBrick(false);
                tile.slope(1);                //slope bottom left
                break;

            case 1:
                tile.halfBrick(false);
                tile.slope(2);                //slope bottom right
                break;

            case 2:
                tile.halfBrick(false);
                tile.slope(3);                //slope top left
                break;

            case 3:
                tile.halfBrick(false);
                tile.slope(4);                //slope top right
                break;

            case 4:
                tile.slope(0);
                tile.halfBrick(true);
                break;

            case 5:
                tile.halfBrick(false);
                tile.slope(0);
                break;
            }
            WorldGen.SquareTileFrame(myPlayer.tileX, myPlayer.tileY, true);
            if (Main.netMode == 1)
            {
                NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
            }
            Main.PlaySound(SoundID.Dig);            //hammer sound too
            for (int i = 0; i < 5; i++)
            {
                int dust = Dust.NewDust(new Vector2((myPlayer.tileX - 1) * 16, (myPlayer.tileY - 1) * 16), 40, 40, myMod.DustType("Sparkle"));
                //I don't know how to change the color according to the block (white dust for snow) SIMPLY
            }
            visible = false;
        }
Exemple #10
0
        public override bool CanUseItem(Item item, Player player)
        {
            List <int> mossToolList = new List <int>();

            mossToolList.Add(-1);//no TileID is -1
            mossToolList.Add(TileID.GreenMoss);
            mossToolList.Add(TileID.BrownMoss);
            mossToolList.Add(TileID.RedMoss);
            mossToolList.Add(TileID.BlueMoss);
            mossToolList.Add(TileID.PurpleMoss);
            mossToolList.Add(TileID.LavaMoss);
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);
            bool  moddedStaff           = false;
            float maxReach = 5.5f;//blocks. With testing I find 6 longer than vanilla reach and 5 shorter that vanilla reach

            if (item.type == ItemID.StaffofRegrowth && VipixToolBoxWorld.toolEnabled["StaffofRegrowthEdit"])
            {
                if (player.altFunctionUse == 2)
                {
                    myPlayer.tbMouseX = Main.mouseX;
                    myPlayer.tbMouseY = Main.mouseY;
                    MossUI.visible    = true;
                    moddedStaff       = true;
                }
                else if (myPlayer.mossTool != 0 &&
                         myPlayer.pointedTile.type != (ushort)mossToolList[myPlayer.mossTool] &&
                         Vector2.Distance(player.position, myPlayer.pointerCoord) < maxReach * 16 &&
                         (myPlayer.pointedTile.type == TileID.Stone || mossToolList.Contains(myPlayer.pointedTile.type)))
                {
                    //if tool is custom moss and not default AND
                    //if block to change isn't already the correct moss type AND
                    //if block to change is closer than 5 blocks AND
                    //if block to change is either stone or moss
                    myPlayer.pointedTile.type = (ushort)mossToolList[myPlayer.mossTool];
                    WorldGen.SquareTileFrame(myPlayer.pointedTileX, myPlayer.pointedTileY, true);
                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                    }
                    moddedStaff = true;
                }
            }
            if (moddedStaff)
            {
                return(false);
            }
            else
            {
                return(base.CanUseItem(item, player));
            }
        }
Exemple #11
0
        public override bool UseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            if (operationAllowed)
            {
                WorldGen.KillWall(myPlayer.pointedTileX, myPlayer.pointedTileY, false);
                if (Main.netMode == 1)
                {
                    NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                }
            }
            //no smartcursor
            //meh no control
            return(true);
        }
Exemple #12
0
        public override void HoldItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);            //blocks
            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 && VipixToolBoxWorld.toolEnabled["WallHammer"])
            {
                operationAllowed    = true;
                player.showItemIcon = true;
            }
            else
            {
                operationAllowed    = false;
                player.showItemIcon = false;
            }
        }
Exemple #13
0
        public void ToolClicked(int index)
        {
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            if (index >= 0 && index < 4)
            {
                //tool button
                player.GetModPlayer <VipixToolBoxPlayer>().paintStatus = index;
            }
            else if (index == 4)
            {
                myPlayer.spotlight = !myPlayer.spotlight;
            }
            visible = false;
        }
Exemple #14
0
        public override bool UseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            if (operationAllowed && validBlocks.Contains(myPlayer.pointedTile.type))
            {
                int index  = -1;
                int iindex = -1;

                for (int i = 0; i < player.inventory.Length; i++)
                {
                    if (validItems.Contains(player.inventory[i].type))
                    {
                        iindex = i;
                        index  = validItems.FindIndex(a => a == player.inventory[i].type);
                        break;
                    }
                }
                //need to check for resource first
                //player.inventory[boneIndex].stack--;
                if (index != -1)
                {
                    bool halfBrick = myPlayer.pointedTile.halfBrick();
                    byte slope     = myPlayer.pointedTile.slope();
                    bool inActive  = myPlayer.pointedTile.inActive();
                    byte color     = myPlayer.pointedTile.color();

                    WorldGen.KillTile(myPlayer.pointedTileX, myPlayer.pointedTileY);
                    WorldGen.PlaceTile(myPlayer.pointedTileX, myPlayer.pointedTileY, validBlocks[index]);
                    player.inventory[iindex].stack--;

                    myPlayer.pointedTile.halfBrick(halfBrick);
                    myPlayer.pointedTile.slope(slope);
                    myPlayer.pointedTile.inActive(inActive);
                    myPlayer.pointedTile.color(color);

                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);                   //player, X, Y, square "diameter". -1 as the player equals all ?
                    }
                    Main.PlaySound(SoundID.Dig);
                }
            }
            return(true);
        }
Exemple #15
0
        public override bool CanUseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            //Main.NewText(new Vector2(myPlayer.pointedTileX,myPlayer.pointedTileY).ToString(),255,255,255);
            if (operationAllowed)
            {
                if (player.altFunctionUse == 2)
                {
                    int index = hardenedSandList.FindIndex(i => i == myPlayer.pointedTile.type);                    //exception at -1 if the wrong mouse button is used
                    if (index != -1)
                    {
                        myPlayer.pointedTile.type = (ushort)sandList[index];
                    }
                }
                else
                {
                    int index = sandList.FindIndex(i => i == myPlayer.pointedTile.type);                    //exception at -1 if the wrong mouse button is used
                    if (index != -1)
                    {
                        if (myPlayer.pointedTileAbove.type == TileID.Cactus)
                        {
                            myPlayer.pointedTile.active(false);                                                                         //cactus on top, only exception to handle ?
                        }
                        WorldGen.SquareTileFrame(myPlayer.pointedTileX, myPlayer.pointedTileY, true);
                        myPlayer.pointedTile.type = (ushort)hardenedSandList[index];
                        myPlayer.pointedTile.active(true);
                    }
                }
                WorldGen.SquareTileFrame(myPlayer.pointedTileX, myPlayer.pointedTileY, true);
                if (Main.netMode == 1)
                {
                    NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                }
                Main.PlaySound(SoundID.Dig);
                for (int i = 0; i < 5; i++)
                {
                    int dust = Dust.NewDust(new Vector2((myPlayer.pointedTileX - 1) * 16, (myPlayer.pointedTileY - 1) * 16), 40, 40, mod.DustType("Sparkle"));
                }
            }
            //return base.CanUseItem(player);
            return(player.ownedProjectileCounts[item.shoot] < 1);            // This is to ensure the spear doesn't bug out when using autoReuse = true
        }
        public override void HoldItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);            //blocks

            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 &&
                !myPlayer.pointedTile.active() || !Main.tileSolid[myPlayer.pointedTile.type] &&
                !myPlayer.treeList.Contains(myPlayer.pointedTile.type) &&
                VipixToolBoxWorld.toolEnabled["LevitationWand"])
            {
                operationAllowed    = true;
                player.showItemIcon = true;
            }
            else
            {
                operationAllowed    = false;
                player.showItemIcon = false;
            }
        }
        public override void HoldItem(Player player)
        {
            //for showing the icon when an action is allowed
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);            //blocks
            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 && myPlayer.spotlight && VipixToolBoxWorld.toolEnabled["ColorPalette"])
            {
                Lighting.AddLight(myPlayer.pointerCoord, 2f, 2f, 2f);
            }
            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 &&
                (myPlayer.pointedTile.active() || myPlayer.pointedTile.wall != 0) &&
                VipixToolBoxWorld.toolEnabled["ColorPalette"])
            {
                player.showItemIcon = true;
                operationAllowed    = true;
                switch (myPlayer.paintStatus)
                {
                case 0:
                    player.showItemIcon2 = mod.ItemType("tilePaintIcon");
                    break;

                case 1:
                    player.showItemIcon2 = mod.ItemType("wallPaintIcon");
                    break;

                case 2:
                    player.showItemIcon2 = mod.ItemType("tileEraseIcon");
                    break;

                case 3:
                    player.showItemIcon2 = mod.ItemType("wallEraseIcon");
                    break;
                }
            }
            else
            {
                player.showItemIcon = false;
                operationAllowed    = false;
            }
        }
Exemple #18
0
        public override void Update(GameTime gametime)
        {
            //setting the UI at the mouse position
            Mod                myMod    = ModLoader.GetMod("VipixToolBox");
            Player             player   = Main.player[Main.myPlayer];
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();           //well that looks complicated

            if (myPlayer.centerUI == 1)
            {
                backgroundPanel.Left.Set(myPlayer.tbMouseX - panelWidth / 2, 0f);              //exceeding the coordinates of the screen seems already handled
                backgroundPanel.Top.Set(myPlayer.tbMouseY - panelHeight / 2, 0f);
                //Main.NewText(buttonList.Count.ToString(), 100, 110, 75, false);
                Recalculate();                 //without it nothing happens
            }
            else
            {
                backgroundPanel.Left.Set((float)Main.screenWidth / 2 - panelWidth / 2, 0f);
                backgroundPanel.Top.Set((float)Main.screenHeight / 2 - panelHeight / 2, 0f);
                Recalculate();
            }
        }
Exemple #19
0
        public override void HoldItem(Player player)
        {
            //this method determines if the pointed block is buildable and in range of the player
            //it shows the item icon if true
            //and it allows the actions in CanUseItem
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);//blocks
            //Main.NewText(validBlocks.Contains(myPlayer.pointedTile.type).ToString());
            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 &&
                myPlayer.pointedTile.active() &&
                Main.tileSolid[myPlayer.pointedTile.type])
            {
                operationAllowed    = true;
                player.showItemIcon = true;
            }
            else
            {
                operationAllowed    = false;
                player.showItemIcon = false;
            }
        }
Exemple #20
0
        public override void HoldItem(Player player)
        {
            //this method determines if the pointed block is a type of sand in range of the player
            //it shows the item icon if true
            //and it allows the actions in CanUseItem
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);            //blocks

            if (Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 &&
                (sandList.Contains(myPlayer.pointedTile.type) || hardenedSandList.Contains(myPlayer.pointedTile.type)) &&
                VipixToolBoxWorld.toolEnabled["RattlesnakeWand"])
            {
                operationAllowed    = true;
                player.showItemIcon = true;
            }
            else
            {
                operationAllowed    = false;
                player.showItemIcon = false;
            }
        }
        public override void HoldItem(Player player)
        {
            //for showing the icon when an action is allowed
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);            //blocks
            if (myPlayer.pointedTile.active() &&
                myPlayer.pointedTileAbove.type != TileID.Trees &&
                Vector2.Distance(player.position, myPlayer.pointerCoord) < toolRange * 16 &&
                Main.tileSolid[myPlayer.pointedTile.type] &&
                VipixToolBoxWorld.toolEnabled["AutoHammer"])
            {
                //no edit under tree, probably other exceptions to add
                //empty tile is considered solid by Main.tileSolid, need to combine with tile.active()
                player.showItemIcon = true;                //could the condition be checked only once in HoldItem OR CanUseItem ? problem wih UI
                operationAllowed    = true;
            }
            else
            {
                player.showItemIcon = false;
                operationAllowed    = false;
            }
        }
        public override bool CanUseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            if (player.altFunctionUse == 2)
            {
                //sending mouse coordinates (at the moment of the click) to VipixToolBoxPlayer for UI position
                myPlayer.tbMouseX = Main.mouseX;
                myPlayer.tbMouseY = Main.mouseY;
                ColorUI.visible   = true;
            }
            else
            {
                if (operationAllowed)
                {
                    int  i             = 0;       //need to check for resource first
                    bool found         = false;
                    bool operationDone = false;
                    while (i < player.inventory.Length)
                    {
                        if (paints.Contains(player.inventory[i].type))
                        {
                            break;
                        }
                        i++;
                    }
                    if (i < player.inventory.Length)
                    {
                        found = true;
                    }
                    switch (myPlayer.paintStatus)
                    {
                    case 0:
                        if (found && myPlayer.pointedTile.color() != myPlayer.colorByte)
                        {
                            //no painting of already painted tiles (would consume paint)
                            myPlayer.pointedTile.color(myPlayer.colorByte);
                            if (Main.rand.NextDouble() <= 0.2)
                            {
                                player.inventory[i].stack--;                                                           //80% not to consume paint
                            }
                            operationDone = true;
                        }
                        break;

                    case 1:
                        if (found && myPlayer.pointedTile.wallColor() != myPlayer.colorByte)
                        {
                            myPlayer.pointedTile.wallColor(myPlayer.colorByte);
                            if (Main.rand.NextDouble() <= 0.2)
                            {
                                player.inventory[i].stack--;                                                           //80% not to consume paint
                            }
                            operationDone = true;
                        }
                        break;

                    case 2:
                        if (myPlayer.pointedTile.color() != 0)
                        {
                            myPlayer.pointedTile.color(0);
                            operationDone = true;
                        }
                        break;

                    case 3:
                        if (myPlayer.pointedTile.wallColor() != 0)
                        {
                            myPlayer.pointedTile.wallColor(0);
                            operationDone = true;
                        }
                        break;
                    }
                    if (operationDone)
                    {
                        if (Main.netMode == 1)
                        {
                            NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                        }
                        Main.PlaySound(SoundID.Dig);
                        Vector2 dustSpawn;
                        for (int j = 0; j < 10; j++)
                        {
                            dustSpawn = new Vector2(myPlayer.pointerCoord.X - 4, myPlayer.pointerCoord.Y - 4); //dunno why the offset looks better
                            int dust = Dust.NewDust(dustSpawn, 15, 15, 33);                                    //,0f, 0f, 0, new Color(255, 255, 255),1f);//80 is the type
                        }
                    }
                }
                //tile.color((byte)Paints.Red);
            }
            return(false);
        }
        public override bool CanUseItem(Player player)
        {
            FlyingBlockTE      myTE;
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>(mod);

            toolRange = Math.Max(baseRange, myPlayer.fargoRange);            //blocks

            Tile tile = Main.tile[myPlayer.pointedTileX, myPlayer.pointedTileY];

            Item fargotest = player.inventory[0];

            //Main.tile[myPlayer.pointedTileX,myPlayer.pointedTileY].active(true);
            //Main.tile[myPlayer.pointedTileX,myPlayer.pointedTileY].type = TileID.Dirt;//this doesnt respect tile properties
            //Can't be used because we need a hook on the tile to link with the tile entity
            //this hook is only called when the tile is placed normally
            //also, we can't place tileEntity manually. At least we shouldn't try (cf documentation)

            //next condition: checking reach, checking pointed block: should be either air or non solid block (like grass) but not trees (trees are non-solid too)
            if (operationAllowed)
            {
                if (player.altFunctionUse != 2 && player.statMana >= manaDrain)
                {
                    WorldGen.KillTile(myPlayer.pointedTileX, myPlayer.pointedTileY, false, false, false);                      //otherwise, grass blocks the PlaceTile
                    WorldGen.PlaceTile(myPlayer.pointedTileX, myPlayer.pointedTileY, (ushort)mod.TileType("FlyingBlockTile")); //respects tile properties
                    //WorldGen.SquareTileFrame(myPlayer.pointedTileX, myPlayer.pointedTileY, true);
                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                    }
                    int id = mod.GetTileEntity <FlyingBlockTE>().Find(myPlayer.pointedTileX, myPlayer.pointedTileY);
                    if (id != -1)
                    {
                        //it should never be -1
                        myTE       = (FlyingBlockTE)TileEntity.ByID[id];
                        myTE.timer = 140;
                        myTE.tileX = myPlayer.pointedTileX;
                        myTE.tileY = myPlayer.pointedTileY;
                    }
                    player.statMana = Math.Max(0, player.statMana - manaDrain);
                    return(true);
                }
                else if (player.altFunctionUse == 2 && player.statMana >= manaDrain * 4)
                {
                    WorldGen.KillTile(myPlayer.pointedTileX, myPlayer.pointedTileY, false, false, false);
                    WorldGen.PlaceTile(myPlayer.pointedTileX, myPlayer.pointedTileY, (ushort)mod.TileType("FlyingHardBlockTile"));
                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                    }
                    int id = mod.GetTileEntity <FlyingBlockTE>().Find(myPlayer.pointedTileX, myPlayer.pointedTileY);
                    if (id != -1)
                    {
                        myTE       = (FlyingBlockTE)TileEntity.ByID[id];
                        myTE.timer = 400;
                        myTE.tileX = myPlayer.pointedTileX;
                        myTE.tileY = myPlayer.pointedTileY;
                    }
                    player.statMana = Math.Max(0, player.statMana - manaDrain * 5);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #24
0
        public override bool CanUseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            if (player.altFunctionUse == 2)
            {
                myPlayer.tbMouseX = Main.mouseX;
                myPlayer.tbMouseY = Main.mouseY;
                BlockUI.visible   = true;
            }
            else if (operationAllowed)
            {
                //need to check for resource first
                int  woodIndex   = -1;
                int  hiveIndex   = -1;
                int  boneIndex   = -1;
                bool doOperation = false;
                for (int i = 0; i < player.inventory.Length; i++)
                {
                    if (woods.Contains(player.inventory[i].type))
                    {
                        woodIndex = i;
                    }
                    if (player.inventory[i].type == ItemID.Hive)
                    {
                        hiveIndex = i;
                    }
                    if (player.inventory[i].type == ItemID.Bone)
                    {
                        boneIndex = i;
                    }
                }
                if ((myPlayer.blockTool == 1 || myPlayer.blockTool == 3) && woodIndex != -1)
                {
                    player.inventory[woodIndex].stack--;                            //100% chance to consume wood if placing wood, otherwise duplication is possible
                    doOperation = true;
                }
                else if ((myPlayer.blockTool == 0 || myPlayer.blockTool == 2) && woodIndex != -1)
                {
                    if (Main.rand.NextDouble() <= 0.5)
                    {
                        player.inventory[woodIndex].stack--;                                                           //50% chance not to consume ammo
                    }
                    doOperation = true;
                }
                else if (myPlayer.blockTool == 4 && hiveIndex != -1)
                {
                    if (Main.rand.NextDouble() <= 0.5)
                    {
                        player.inventory[hiveIndex].stack--;                                                           //50% chance not to consume ammo
                    }
                    doOperation = true;
                }
                else if (myPlayer.blockTool == 5 && boneIndex != -1)
                {
                    if (Main.rand.NextDouble() <= 0.5)
                    {
                        player.inventory[boneIndex].stack--;
                    }
                    doOperation = true;
                }
                if (doOperation)
                {
                    myPlayer.pointedTile.type = (ushort)toolList[myPlayer.blockTool];                            //actually the operation is done here
                    myPlayer.pointedTile.active(true);
                    WorldGen.SquareTileFrame(myPlayer.pointedTileX, myPlayer.pointedTileY, true);
                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);                                               //player, X, Y, square "diameter". -1 as the player equals all ?
                    }
                    Main.PlaySound(SoundID.Dig);
                    for (int j = 0; j < 5; j++)
                    {
                        int dust = Dust.NewDust(new Vector2((myPlayer.pointedTileX - 1) * 16, (myPlayer.pointedTileY - 1) * 16), 40, 40, mod.DustType("Sparkle"));
                    }
                }
            }
            return(true);
        }
Exemple #25
0
        public override bool CanUseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            return(true);
        }
Exemple #26
0
        public override bool UseItem(Player player)
        {
            VipixToolBoxPlayer myPlayer = player.GetModPlayer <VipixToolBoxPlayer>();

            if (operationAllowed)
            {
                int tileToCreate = -1;
                int itemIndex    = -1;

                for (int i = 0; i < player.inventory.Length; i++)
                {
                    tileToCreate = player.inventory[i].createTile;

                    if (tileToCreate > -1 && Main.tileSolid[player.inventory[i].createTile] && player.inventory[i].stack > 0)
                    {
                        itemIndex = i;
                        break;
                    }
                }


                //need to check for resource first
                if (tileToCreate > -1 && itemIndex > -1 && tileToCreate != myPlayer.pointedTile.type)
                {
                    bool halfBrick = myPlayer.pointedTile.halfBrick();
                    byte slope     = myPlayer.pointedTile.slope();
                    bool inActive  = myPlayer.pointedTile.inActive();
                    byte color     = myPlayer.pointedTile.color();

                    // A very hacky block swap to keep furniture in place
                    int  worldHeight = Main.maxTilesY - 1;
                    Tile oldTile     = Main.tile[0, worldHeight];
                    WorldGen.PlaceTile(0, worldHeight, myPlayer.pointedTile.type, false, true);
                    Tile newTile = Main.tile[0, worldHeight];
                    WorldGen.KillTile(0, worldHeight);

                    Vector2 playerPos = new Vector2((int)player.position.X, (int)player.position.Y);
                    for (int i = 0; i < Main.maxItems; i++)
                    {
                        if (Main.item[i].position.X <32 && Main.item[i].position.Y> Main.bottomWorld - 32)
                        {
                            Main.item[i].position = playerPos;
                            break;
                        }
                    }
                    WorldGen.PlaceTile(0, worldHeight, oldTile.type, false, true);

                    WorldGen.PlaceTile(myPlayer.pointedTileX, myPlayer.pointedTileY, tileToCreate, false, true);
                    player.inventory[itemIndex].stack--;
                    myPlayer.pointedTile.halfBrick(halfBrick);
                    myPlayer.pointedTile.slope(slope);
                    myPlayer.pointedTile.inActive(inActive);
                    myPlayer.pointedTile.color(color);

                    if (Main.netMode == 1)
                    {
                        NetMessage.SendTileSquare(-1, myPlayer.pointedTileX, myPlayer.pointedTileY, 1);
                    }
                    Main.PlaySound(SoundID.Dig);
                }
            }
            return(true);
        }