Ejemplo n.º 1
0
        public override void RightClick(Player player)
        {
            Item item      = player.HeldItem;
            bool favorited = item.favorited;
            int  stack     = item.stack;
            Item obj1      = new Item();

            obj1.netDefaults(item.netID);
            Item obj2 = obj1.CloneWithModdedDataFrom(item);

            obj2.Prefix(this.item.prefix);
            int index = GetIndexInArray(player.inventory, item);

            item                    = obj2.Clone();
            item.position.X         = player.position.X + (float)(player.width / 2) - (float)(item.width / 2);
            item.position.Y         = player.position.Y + (float)(player.height / 2) - (float)(item.height / 2);
            item.favorited          = favorited;
            item.stack              = stack;
            player.inventory[index] = item;
            ItemLoader.PostReforge(item);
            ItemText.NewText(item, item.stack, true, false);
            Main.PlaySound(SoundID.Item37, -1, -1);
        }
Ejemplo n.º 2
0
        private bool TryPlaceItem(ref Item item, ref Item target, bool isCoin, bool incrementStack)
        {
            bool dispose = false;

            if (target.type == 0 && !incrementStack)
            {
                target = item;
                ItemText.NewText(item, item.stack);
                AchievementsHelper.NotifyItemPickup(Player, item);
                dispose = true;
            }
            else if (incrementStack && target.type > 0 && target.stack < target.maxStack && item.IsTheSameAs(target))
            {
                if (item.stack + target.stack <= target.maxStack)
                {
                    target.stack += item.stack;
                    ItemText.NewText(item, item.stack);
                    AchievementsHelper.NotifyItemPickup(Player, item);
                    dispose = true;
                }
                else
                {
                    AchievementsHelper.NotifyItemPickup(Player, item, target.maxStack - target.stack);
                    item.stack -= target.maxStack - target.stack;
                    ItemText.NewText(item, target.maxStack - target.stack);
                    target.stack = target.maxStack;
                }
            }

            Main.PlaySound(isCoin ? SoundID.CoinPickup : SoundID.Grab, (int)Player.position.X, (int)Player.position.Y, 1, 1f, 0f);
            if (Player.whoAmI == Main.myPlayer)
            {
                API.FindRecipes();
            }
            return(dispose);
        }
Ejemplo n.º 3
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            // Here we have a lot of code. This code is mainly adapted from the vanilla code for the reforge option.
            // This code draws "Place an item here" when no item is in the slot and draws the reforge cost and a reforge button when an item is in the slot.
            // This code could possibly be better as different UIElements that are added and removed, but that's not the main point of this example.
            // If you are making a UI, add UIElements in OnInitialize that act on your ItemSlot or other inputs rather than the non-UIElement approach you see below.

            int slotX = 50;
            int slotY = 270;

            if (!vanillaItemSlot.item.IsAir)
            {
                int awesomePrice = Item.buyPrice(0, 1, 0, 0);

                string costText  = Lang.inter[46].Value + ": ";
                string coinsText = "";
                int[]  coins     = Utils.CoinsSplit(awesomePrice);
                if (coins[3] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinPlatinum).Hex3() + ":" + coins[3] + " " + Lang.inter[15].Value + "] ";
                }
                if (coins[2] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinGold).Hex3() + ":" + coins[2] + " " + Lang.inter[16].Value + "] ";
                }
                if (coins[1] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinSilver).Hex3() + ":" + coins[1] + " " + Lang.inter[17].Value + "] ";
                }
                if (coins[0] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinCopper).Hex3() + ":" + coins[0] + " " + Lang.inter[18].Value + "] ";
                }
                ItemSlot.DrawSavings(Main.spriteBatch, slotX + 130, Main.instance.invBottom, true);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, costText, new Vector2((slotX + 50), slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, coinsText, new Vector2((slotX + 50) + Main.fontMouseText.MeasureString(costText).X, (float)slotY), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                int       reforgeX = slotX + 70;
                int       reforgeY = slotY + 40;
                bool      hoveringOverReforgeButton = Main.mouseX > reforgeX - 15 && Main.mouseX <reforgeX + 15 && Main.mouseY> reforgeY - 15 && Main.mouseY < reforgeY + 15 && !PlayerInput.IgnoreMouseInterface;
                Texture2D reforgeTexture = Main.reforgeTexture[hoveringOverReforgeButton ? 1 : 0];
                Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 2f, 0.8f, SpriteEffects.None, 0f);
                if (hoveringOverReforgeButton)
                {
                    Main.hoverItemName = Lang.inter[19].Value;
                    if (!tickPlayed)
                    {
                        Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                    }
                    tickPlayed = true;
                    Main.LocalPlayer.mouseInterface = true;
                    if (Main.mouseLeftRelease && Main.mouseLeft && Main.LocalPlayer.CanBuyItem(awesomePrice, -1) && ItemLoader.PreReforge(vanillaItemSlot.item))
                    {
                        Main.LocalPlayer.BuyItem(awesomePrice, -1);
                        bool favorited   = vanillaItemSlot.item.favorited;
                        int  stack       = vanillaItemSlot.item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(vanillaItemSlot.item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(vanillaItemSlot.item);
                        // This is the main effect of this slot. Giving the Awesome prefix 90% of the time and the ReallyAwesome prefix the other 10% of the time. All for a constant 1 gold. Useless, but informative.
                        if (Main.rand.NextBool(10))
                        {
                            reforgeItem.Prefix(ExampleMod.instance.PrefixType("ReallyAwesome"));
                        }
                        else
                        {
                            reforgeItem.Prefix(ExampleMod.instance.PrefixType("Awesome"));
                        }
                        vanillaItemSlot.item            = reforgeItem.Clone();
                        vanillaItemSlot.item.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(vanillaItemSlot.item.width / 2);
                        vanillaItemSlot.item.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(vanillaItemSlot.item.height / 2);
                        vanillaItemSlot.item.favorited  = favorited;
                        vanillaItemSlot.item.stack      = stack;
                        ItemLoader.PostReforge(vanillaItemSlot.item);
                        ItemText.NewText(vanillaItemSlot.item, vanillaItemSlot.item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }
                else
                {
                    tickPlayed = false;
                }
            }
            else
            {
                string message = "Place an item here to Awesomeify";
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            }
        }
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            // This will hide the crafting menu similar to the reforge menu. For best results this UI is placed before "Vanilla: Inventory" to prevent 1 frame of the craft menu showing.
            Main.HidePlayerCraftingMenu = true;

            // Here we have a lot of code. This code is mainly adapted from the vanilla code for the reforge option.
            // This code draws "Place an item here" when no item is in the slot and draws the reforge cost and a reforge button when an item is in the slot.
            // This code could possibly be better as different UIElements that are added and removed, but that's not the main point of this example.
            // If you are making a UI, add UIElements in OnInitialize that act on your ItemSlot or other inputs rather than the non-UIElement approach you see below.

            const int slotX = 50;
            const int slotY = 270;

            ItemSlot.DrawSavings(Main.spriteBatch, slotX + 130, Main.instance.invBottom, true);

            //image 1
            if (!_vanillaItemSlot.Item.IsAir && reforgeCheck == false)
            {
                Image.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckEmpty"));
            }
            else if (_vanillaItemSlot.Item.IsAir && reforgeCheck == false)
            {
                Image.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckRed"));
            }
            else if (!_vanillaItemSlot.Item.IsAir && reforgeCheck == true)
            {
                Image.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckGreen"));
            }

            //image 2
            if (!_vanillaItemSlot2.Item.IsAir && reforgeCheck2 == false)
            {
                Image2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckEmpty"));
            }
            else if (_vanillaItemSlot2.Item.IsAir && reforgeCheck2 == false)
            {
                Image2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckRed"));
            }
            else if (!_vanillaItemSlot2.Item.IsAir && reforgeCheck2 == true)
            {
                Image2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckGreen"));
            }

            //image 3
            if (!_vanillaItemSlot3.Item.IsAir && reforgeCheck3 == false)
            {
                Image3.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckEmpty"));
            }
            else if (_vanillaItemSlot3.Item.IsAir && reforgeCheck3 == false)
            {
                Image3.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckRed"));
            }
            else if (!_vanillaItemSlot3.Item.IsAir && reforgeCheck3 == true)
            {
                Image3.SetImage(ModContent.GetTexture("ExtraExplosives/UI/UICheckGreen"));
            }

            if (_vanillaItemSlot.Item.IsAir && reforgeCheck == true)
            {
                reforgeCheck = false;
            }

            if (_vanillaItemSlot2.Item.IsAir && reforgeCheck2 == true)
            {
                reforgeCheck2 = false;
            }

            if (_vanillaItemSlot3.Item.IsAir && reforgeCheck3 == true)
            {
                reforgeCheck3 = false;
            }

            if (ExtraExplosivesPlayer.reforgePub)
            {
                Main.LocalPlayer.mouseInterface = true;

                if (!_vanillaItemSlot.Item.IsAir)
                {
                    if (ItemLoader.PreReforge(_vanillaItemSlot.Item))
                    {
                        bool favorited   = _vanillaItemSlot.Item.favorited;
                        int  stack       = _vanillaItemSlot.Item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(_vanillaItemSlot.Item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(_vanillaItemSlot.Item);
                        // This is the main effect of this slot. Giving the Awesome prefix 90% of the time and the ReallyAwesome prefix the other 10% of the time. All for a constant 1 gold. Useless, but informative.
                        reforgeItem.Prefix(-2);
                        _vanillaItemSlot.Item            = reforgeItem.Clone();
                        _vanillaItemSlot.Item.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(_vanillaItemSlot.Item.width / 2);
                        _vanillaItemSlot.Item.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(_vanillaItemSlot.Item.height / 2);
                        _vanillaItemSlot.Item.favorited  = favorited;
                        _vanillaItemSlot.Item.stack      = stack;
                        ItemLoader.PostReforge(_vanillaItemSlot.Item);
                        ItemText.NewText(_vanillaItemSlot.Item, _vanillaItemSlot.Item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }

                if (!_vanillaItemSlot2.Item.IsAir)
                {
                    if (ItemLoader.PreReforge(_vanillaItemSlot2.Item))
                    {
                        bool favorited   = _vanillaItemSlot2.Item.favorited;
                        int  stack       = _vanillaItemSlot2.Item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(_vanillaItemSlot2.Item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(_vanillaItemSlot2.Item);
                        // This is the main effect of this slot. Giving the Awesome prefix 90% of the time and the ReallyAwesome prefix the other 10% of the time. All for a constant 1 gold. Useless, but informative.
                        reforgeItem.Prefix(-2);
                        _vanillaItemSlot2.Item            = reforgeItem.Clone();
                        _vanillaItemSlot2.Item.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(_vanillaItemSlot2.Item.width / 2);
                        _vanillaItemSlot2.Item.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(_vanillaItemSlot2.Item.height / 2);
                        _vanillaItemSlot2.Item.favorited  = favorited;
                        _vanillaItemSlot2.Item.stack      = stack;
                        ItemLoader.PostReforge(_vanillaItemSlot2.Item);
                        ItemText.NewText(_vanillaItemSlot2.Item, _vanillaItemSlot2.Item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }

                if (!_vanillaItemSlot3.Item.IsAir)
                {
                    if (ItemLoader.PreReforge(_vanillaItemSlot3.Item))
                    {
                        bool favorited   = _vanillaItemSlot3.Item.favorited;
                        int  stack       = _vanillaItemSlot3.Item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(_vanillaItemSlot3.Item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(_vanillaItemSlot3.Item);
                        // This is the main effect of this slot. Giving the Awesome prefix 90% of the time and the ReallyAwesome prefix the other 10% of the time. All for a constant 1 gold. Useless, but informative.
                        reforgeItem.Prefix(-2);
                        _vanillaItemSlot3.Item            = reforgeItem.Clone();
                        _vanillaItemSlot3.Item.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(_vanillaItemSlot3.Item.width / 2);
                        _vanillaItemSlot3.Item.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(_vanillaItemSlot3.Item.height / 2);
                        _vanillaItemSlot3.Item.favorited  = favorited;
                        _vanillaItemSlot3.Item.stack      = stack;
                        ItemLoader.PostReforge(_vanillaItemSlot3.Item);
                        ItemText.NewText(_vanillaItemSlot3.Item, _vanillaItemSlot3.Item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }

                ExtraExplosivesPlayer.reforgePub = false; //Only reforge once
                reforgeCheck  = true;                     //Check to see if the reforge went off
                reforgeCheck2 = true;
                reforgeCheck3 = true;

                if (_vanillaItemSlot.Item.IsAir && _vanillaItemSlot2.Item.IsAir && _vanillaItemSlot3.Item.IsAir)
                {
                    Main.NewText("Nothing to reforge...");
                }
            }
            else
            {
                //string message = "Place an item in one(or all) of the slots to reforge";
                //ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(screenX - 200, screenY - 55), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            }
        }
Ejemplo n.º 5
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            GnomeWordsmithPlayer gnomeWordsmithPlayer = Main.LocalPlayer.GetModPlayer <GnomeWordsmithPlayer>(GnomeWordsmith.instance);

            // Make sure the inventory is still open
            if (!Main.playerInventory || Main.player[Main.myPlayer].chest != -1 || Main.npcShop != 0 || Main.player[Main.myPlayer].talkNPC == -1)
            {
                visible = false;

                // Drop item if closed
                if (!gnomeWordsmithPlayer.ReforgeItem.IsAir)
                {
                    Main.LocalPlayer.QuickSpawnClonedItem(gnomeWordsmithPlayer.ReforgeItem, gnomeWordsmithPlayer.ReforgeItem.stack);
                    gnomeWordsmithPlayer.ReforgeItem.TurnToAir();
                }

                // Make sure our player instance knows we don't have an item
                gnomeWordsmithPlayer.hasItem = false;

                // Remove list of purchasable items
                UpdateCurrentPrefixesForItem(null);

                // Restore crafting interface fully.
                if (MaxRecipesCache > Recipe.maxRecipes)
                {
                    Recipe.maxRecipes = MaxRecipesCache;
                }

                Recipe.FindRecipes();
                return;
            }

            Item[] slot = new Item[1];
            slot[0] = gnomeWordsmithPlayer.ReforgeItem;

            // HACK: Hide crafting interface
            if (Recipe.maxRecipes > 0)
            {
                MaxRecipesCache = Recipe.maxRecipes;
            }

            if (Main.numAvailableRecipes > 0)
            {
                Main.numAvailableRecipes = 0;
            }

            /**
             * Create a point for where the mouse is. Used to check whether the
             * cursor is inside certain regions of the interface.
             */
            Point mousePoint = new Point(Main.mouseX, Main.mouseY);

            // Calculate Position of ItemSlot
            Main.inventoryScale = 0.85f;
            float xPosition = 50f;
            float yPosition = Main.instance.invBottom + 12f;

            // Pre-calculate slot width and height.
            int slotWidth  = (int)(Main.inventoryBackTexture.Width * Main.inventoryScale);
            int slotHeight = (int)(Main.inventoryBackTexture.Height * Main.inventoryScale);

            // Create our "collision" rectangle
            Rectangle slotRectangle = new Rectangle((int)xPosition, (int)yPosition, slotWidth, slotHeight);

            if (slotRectangle.Contains(mousePoint))
            {
                Main.LocalPlayer.mouseInterface = true;
                if (Main.mouseLeftRelease && Main.mouseLeft)
                {
                    /**
                     * Check if we should attempt to swap items with the slot.
                     * Item.Prefix(-3) checks if the item can be forged.
                     *
                     * This re-implements part of ItemSlot.LeftClick
                     */
                    if (Main.mouseItem.type == 0 || Main.mouseItem.Prefix(-3))
                    {
                        Utils.Swap(ref slot[0], ref Main.mouseItem);
                        if (slot[0].type == 0 || slot[0].stack < 1)
                        {
                            slot[0] = new Item();
                        }

                        if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                        {
                            Main.mouseItem = new Item();
                        }

                        if (Main.mouseItem.type > 0 || slot[0].type > 0)
                        {
                            Main.PlaySound(SoundID.Grab);
                        }
                    }

                    gnomeWordsmithPlayer.hasItem = !slot[0].IsAir;
                    UpdateCurrentPrefixesForItem(gnomeWordsmithPlayer.hasItem ? slot[0] : null);
                }
                else
                {
                    ItemSlot.MouseHover(slot, ItemSlot.Context.PrefixItem);
                }
            }

            slot[0].newAndShiny = false;
            ItemSlot.Draw(Main.spriteBatch, slot, ItemSlot.Context.PrefixItem, 0, new Vector2(xPosition, yPosition), default(Color));
            gnomeWordsmithPlayer.ReforgeItem = slot[0];

            bool favorited = Main.reforgeItem.favorited;
            int  stack     = Main.reforgeItem.stack;

            // If there's no purchasable prefixes, stop drawing the interface.
            if (purchasableItemsLength == 0)
            {
                return;
            }

            xPosition += slotWidth + 8;
            string labelText = Language.GetTextValue("Mods.GnomeWordsmith.ReforgeUI.ShopLabel");

            ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, labelText, new Vector2(xPosition, yPosition), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            yPosition -= slotHeight / 2;

            // List all purchasable prefixes.
            for (int i = 0; i < purchasableItemsLength; i++)
            {
                yPosition += slotHeight + 8;

                Item   item    = purchasableItems[i];
                int    buyCost = item.value * 2;
                string price   = FormatValue(buyCost);

                ItemSlot.Draw(Main.spriteBatch, purchasableItems, ItemSlot.Context.CraftingMaterial, i, new Vector2(xPosition, yPosition), default(Color));
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, price, new Vector2(xPosition + slotWidth + 8, yPosition), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                purchasableItems[i] = item;

                slotRectangle = new Rectangle((int)xPosition, (int)yPosition, slotWidth, slotHeight);
                if (slotRectangle.Contains(mousePoint))
                {
                    Main.LocalPlayer.mouseInterface = true;
                    ItemSlot.MouseHover(purchasableItems, ItemSlot.Context.PrefixItem, i);

                    if (Main.mouseLeftRelease && Main.mouseLeft && Main.player[Main.myPlayer].CanBuyItem(buyCost, -1))
                    {
                        Main.mouseLeft        = false;
                        Main.mouseLeftRelease = false;

                        Main.player[Main.myPlayer].BuyItem(buyCost, -1);

                        // Show text and play forge sound
                        ItemText.NewText(item, item.stack, true, false);
                        Main.PlaySound(SoundID.Item37);

                        /**
                         * Place purchased item in the reforge slot, but Hide
                         * all purchasable prefixes.
                         */
                        gnomeWordsmithPlayer.ReforgeItem = item;
                        UpdateCurrentPrefixesForItem(null);
                        return;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override bool OnPickup(Item item, Player player)
        {
            PartsPlayer p = player.GetModPlayer <PartsPlayer>();
            PartRecipe  pr;

            if (p.autoDestroy && item.active)
            {
                if (!ARareItemSwapJPANs.tokenList.Contains(ARareItemSwapJPANs.ItemToTag(item)) && PartRecipes.ContainsAsResult(item))
                {
                    List <PartRecipe> smallest = new List <PartRecipe>();
                    int j = 0;
                    for (j = 0; j < PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)].Count; j++)
                    {
                        pr = PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][j];
                        if (pr.isAvailable() && !pr.irreversible && item.stack >= pr.result.stack)
                        {
                            smallest.Add(pr);
                            break;
                        }
                    }
                    if (smallest.Count <= 0)
                    {
                        return(base.OnPickup(item, player));
                    }
                    for (int i = j; i < PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)].Count; i++)
                    {
                        if (PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].isAvailable() && !PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].irreversible)
                        {
                            if (PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].result.stack < smallest[0].result.stack)
                            {
                                smallest.Clear();
                                smallest.Add(PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i]);
                            }
                            else if (PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i].result.stack == smallest[0].result.stack)
                            {
                                smallest.Add(PartRecipes.recipesByResult[ARareItemSwapJPANs.ItemToTag(item)][i]);
                            }
                        }
                    }

                    pr = smallest[Main.rand.Next(smallest.Count)];
                    int stack;
                    int cnt = 0;
                    do
                    {
                        stack = item.stack;
                        pr.refund(p, ref item);
                        // Main.NewText(stack + " = " + item.stack);
                        cnt++;
                    }while (item.stack > 0 && stack != item.stack);
                    if (cnt > 0)
                    {
                        int i = 1;
                        foreach (Item prt in pr.parts)
                        {
                            Item cln = prt.Clone();
                            cln.position = new Microsoft.Xna.Framework.Vector2(item.position.X, item.position.Y + 30 * i);
                            cln.stack    = (int)prt.stack * cnt;
                            Main.PlaySound(SoundID.Grab, player.position);
                            ItemText.NewText(cln, (int)prt.stack * cnt);
                            i++;
                        }
                    }
                    if (item.stack <= 0)
                    {
                        item.TurnToAir();

                        /*
                         * for (j = 0; j < 400; j++)
                         * {
                         *  if (Main.item[j] == item)
                         *  {
                         *
                         *      Main.item[j] = new Item();
                         *      if (Main.netMode == 1)
                         *      {
                         *          Main.NewText("Updated Item " + j);
                         *          NetMessage.SendData(21, -1, -1, null, item.whoAmI, 0f, 0f, 0f, 0, 0, 0);
                         *      }
                         *  }
                         * }*/
                        return(false);
                    }
                }
            }
            return(base.OnPickup(item, player));
        }
Ejemplo n.º 7
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            Main.HidePlayerCraftingMenu = true;
            const int slotX = 50;
            const int slotY = 270;

            if (!_vanillaItemSlot.Item.IsAir)
            {
                int    dismantleFee = Item.buyPrice(0, 1, 0, 0);
                string costText     = Language.GetTextValue("LegacyInterface.46") + ": ";
                string coinsText    = "";
                int[]  coins        = Utils.CoinsSplit(dismantleFee);
                if (coins[3] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinPlatinum).Hex3() + ":" + coins[3] + " " + Language.GetTextValue("LegacyInterface.15") + "] ";
                }
                if (coins[2] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinGold).Hex3() + ":" + coins[2] + " " + Language.GetTextValue("LegacyInterface.16") + "] ";
                }
                if (coins[1] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinSilver).Hex3() + ":" + coins[1] + " " + Language.GetTextValue("LegacyInterface.17") + "] ";
                }
                if (coins[0] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinCopper).Hex3() + ":" + coins[0] + " " + Language.GetTextValue("LegacyInterface.18") + "] ";
                }
                ItemSlot.DrawSavings(Main.spriteBatch, slotX + 130, Main.instance.invBottom, true);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, costText, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, coinsText, new Vector2(slotX + 50 + Main.fontMouseText.MeasureString(costText).X, (float)slotY), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                int       reforgeX = slotX + 70;
                int       reforgeY = slotY + 40;
                bool      hoveringOverReforgeButton = Main.mouseX > reforgeX - 15 && Main.mouseX <reforgeX + 15 && Main.mouseY> reforgeY - 15 && Main.mouseY < reforgeY + 15 && !PlayerInput.IgnoreMouseInterface;
                Texture2D reforgeTexture = Main.reforgeTexture[hoveringOverReforgeButton ? 1 : 0];
                Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 2f, 0.8f, SpriteEffects.None, 0f);
                if (hoveringOverReforgeButton)
                {
                    Main.hoverItemName = Language.GetTextValue("LegacyInterface.19");
                    if (!tickPlayed)
                    {
                        Main.PlaySound(SoundID.MenuTick, -1, -1, 1, 1f, 0f);
                    }
                    tickPlayed = true;
                    Main.LocalPlayer.mouseInterface = true;
                    if (Main.mouseLeftRelease && Main.mouseLeft && Main.LocalPlayer.CanBuyItem(dismantleFee, -1) && ItemLoader.PreReforge(_vanillaItemSlot.Item))
                    {
                        Player player = Main.player[Main.myPlayer];
                        Main.LocalPlayer.BuyItem(dismantleFee, -1);
                        int  stack       = _vanillaItemSlot.Item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(_vanillaItemSlot.Item.netID);
                        switch (_vanillaItemSlot.Item.type)
                        {
                        case ItemID.Sandgun:
                            Item.NewItem(player.Hitbox, ItemType <SandgunHandle>());
                            Item.NewItem(player.Hitbox, ItemType <SandgunChamber>());
                            Item.NewItem(player.Hitbox, ItemType <SandgunBarrel>());
                            break;

                        case ItemID.Shotgun:
                            Item.NewItem(player.Hitbox, ItemID.Shotgun);
                            break;

                        case ItemID.Handgun:
                            Item.NewItem(player.Hitbox, ItemType <HandgunHandle>());
                            Item.NewItem(player.Hitbox, ItemType <HandgunChamber>());
                            Item.NewItem(player.Hitbox, ItemType <HandgunBarrel>());
                            break;

                        case ItemID.SniperRifle:
                            Item.NewItem(player.Hitbox, ItemID.SniperRifle);
                            break;

                        case ItemID.TacticalShotgun:
                            Item.NewItem(player.Hitbox, ItemID.TacticalShotgun);
                            break;

                        case ItemID.Uzi:
                            Item.NewItem(player.Hitbox, ItemID.Uzi);
                            break;
                        }
                        _vanillaItemSlot.Item.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(_vanillaItemSlot.Item.width / 2);
                        _vanillaItemSlot.Item.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(_vanillaItemSlot.Item.height / 2);
                        _vanillaItemSlot.Item.stack      = stack;
                        ItemLoader.PostReforge(_vanillaItemSlot.Item);
                        ItemText.NewText(_vanillaItemSlot.Item, _vanillaItemSlot.Item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                        _vanillaItemSlot.Item.TurnToAir();
                    }
                }
                else
                {
                    tickPlayed = false;
                }
            }
            else
            {
                string message = "Place a valid gun to dismantle";
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            }
        }
Ejemplo n.º 8
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            // Hide the crafting menu
            Main.HidePlayerCraftingMenu = true;

            // Get reference to current player
            DaesPlayer player = Main.LocalPlayer.GetModPlayer <DaesPlayer>();

            /**
             * If the player:
             * - has closed their inventory
             * - has opened a chest
             * - has opened another npcs shop
             * - is no longer in range of the gnome
             * Close the reforge ui.
             */

            if (!Main.playerInventory || Main.player[Main.myPlayer].chest != -1 || Main.npcShop != 0 || Main.player[Main.myPlayer].talkNPC == -1)
            {
                HideInterface(player);
                return;
            }

            /**
             * Create a point for where the mouse is. Used to check whether the
             * cursor is inside certain regions of the interface.
             */
            Point mousePoint = new Point(Main.mouseX, Main.mouseY);

            // Calculate Position of ItemSlot
            Main.inventoryScale = 0.85f;
            float xPosition = 50f;
            float yPosition = Main.instance.invBottom + 12f;

            // Pre-calculate slot width and height.
            int slotWidth  = (int)(Main.inventoryBackTexture.Width * Main.inventoryScale);
            int slotHeight = (int)(Main.inventoryBackTexture.Height * Main.inventoryScale);

            // Create our "collision" rectangle
            Rectangle slotRectangle = new Rectangle((int)xPosition, (int)yPosition, slotWidth, slotHeight);

            if (slotRectangle.Contains(mousePoint))
            {
                Main.LocalPlayer.mouseInterface = true;
                if (Main.mouseLeftRelease && Main.mouseLeft)
                {
                    // Item.Prefix(-3) checks whether an item can be reforged.
                    if (Main.mouseItem.IsAir || Main.mouseItem.Prefix(-3))
                    {
                        Utils.Swap(ref player.ReforgeItem, ref Main.mouseItem);

                        if (!Main.mouseItem.IsAir || !player.ReforgeItem.IsAir)
                        {
                            Main.PlaySound(SoundID.Grab);
                        }
                    }

                    UpdateCurrentPrefixesForItem(player.ReforgeItem);
                }
                else
                {
                    ItemSlot.MouseHover(new Item[] { player.ReforgeItem }, ItemSlot.Context.PrefixItem);
                }
            }

            player.ReforgeItem.newAndShiny = false;
            ItemSlot.Draw(Main.spriteBatch, new Item[] { player.ReforgeItem }, ItemSlot.Context.PrefixItem, 0, new Vector2(xPosition, yPosition), default);

            // If there's no purchasable prefixes, stop drawing the interface.
            if (purchasableItemsLength > 0)
            {
                xPosition += slotWidth + 8;
                string labelText = Language.GetTextValue(ValueIDPrefix + "ShopLabel");
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, labelText, new Vector2(xPosition, yPosition), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                yPosition -= slotHeight / 2;

                // List all purchasable prefixes.
                for (int i = 0; i < purchasableItemsLength; i++)
                {
                    yPosition += slotHeight + 8;

                    Item   item    = purchasableItems[i];
                    int    buyCost = item.value * 2;
                    string price   = FormatCoinCost(buyCost);

                    // Draw item slot containing the item with the purchasable prefix
                    ItemSlot.Draw(Main.spriteBatch, purchasableItems, ItemSlot.Context.CraftingMaterial, i, new Vector2(xPosition, yPosition), default);

                    // Draw the cost of the item
                    ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, price, new Vector2(xPosition + slotWidth + 8, yPosition), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);

                    // TODO: Investigate this re-assignment
                    purchasableItems[i] = item;

                    slotRectangle = new Rectangle((int)xPosition, (int)yPosition, slotWidth, slotHeight);
                    if (!slotRectangle.Contains(mousePoint))
                    {
                        continue;
                    }

                    Main.LocalPlayer.mouseInterface = true;
                    ItemSlot.MouseHover(purchasableItems, ItemSlot.Context.PrefixItem, i);

                    // Check if the player has clicked to buy the reforge AND can afford it.
                    if (Main.mouseItem.IsAir && Main.mouseLeftRelease && Main.mouseLeft && Main.player[Main.myPlayer].CanBuyItem(buyCost, -1))
                    {
                        Main.mouseLeft        = false;
                        Main.mouseLeftRelease = false;

                        Main.player[Main.myPlayer].BuyItem(buyCost, -1);

                        item.favorited  = player.ReforgeItem.favorited;
                        item.stack      = player.ReforgeItem.stack;
                        item.position.X = Main.player[Main.myPlayer].position.X + (Main.player[Main.myPlayer].width / 2) - (item.width / 2);
                        item.position.Y = Main.player[Main.myPlayer].position.Y + (Main.player[Main.myPlayer].height / 2) - (item.height / 2);

                        Main.mouseItem = item;
                        player.ReforgeItem.TurnToAir();
                        ItemText.NewText(item, item.stack, noStack: true);
                        Main.PlaySound(SoundID.Item37);

                        ClearCurrentPrefixes();
                        // player.ReforgeItem = item;
                        // ClearCurrentPrefixes();
                        break;
                    }
                }
            }

            base.Draw(spriteBatch);
        }
Ejemplo n.º 9
0
        private void ItemSlot_LeftClick(On.Terraria.UI.ItemSlot.orig_LeftClick_ItemArray_int_int orig, Item[] inv, int context, int slot)
        {
            //Invoke ItemSlot.OverrideLeftClick and save it as a varible to check for later
            var OverrideLeftClick = MethodInfo_ItemSlot_OverrideLeftClick.Invoke(null, new object[3]
            {
                inv, context, slot
            });

            //Check if ItemSlot.OverrideLeftClick returns true, if so return
            if ((bool)OverrideLeftClick)
            {
                return;
            }

            inv[slot].newAndShiny = false;

            Player player = Main.player[Main.myPlayer];
            bool   flag   = false;

            switch (context)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
                flag = player.chest == -1;
                break;
            }

            if (ItemSlot.ShiftInUse && flag)
            {
                //Invoke the ItemSlot.SellOrTrash method
                MethodInfo_ItemSlot_SellOrTrash.Invoke(null, new object[3]
                {
                    inv, context, slot
                });
                return;
            }

            if (player.itemAnimation == 0 && player.itemTime == 0)
            {
                int num = ItemSlot.PickItemMovementAction(inv, context, slot, Main.mouseItem);

                if (num == 0)
                {
                    if (context == 6 && Main.mouseItem.type != 0)
                    {
                        inv[slot].SetDefaults(0, false);
                    }

                    //Check if the inventory isnt the lock. If not, procide with the pickup
                    if (Main.LocalPlayer.inventory[slot].type != ModContent.ItemType <ItemLock>())
                    {
                        Utils.Swap(ref inv[slot], ref Main.mouseItem);
                    }

                    if (inv[slot].stack > 0)
                    {
                        if (context != 0)
                        {
                            switch (context)
                            {
                            case 8:
                            case 9:
                            case 10:
                            case 11:
                            case 12:
                            case 16:
                            case 17:
                                AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                break;
                            }
                        }
                        else
                        {
                            AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                        }
                    }

                    if (inv[slot].type == 0 || inv[slot].stack < 1)
                    {
                        inv[slot] = new Item();
                    }

                    if (Main.mouseItem.IsTheSameAs(inv[slot]))
                    {
                        Utils.Swap(ref inv[slot].favorited, ref Main.mouseItem.favorited);
                        if (inv[slot].stack != inv[slot].maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack)
                        {
                            if (Main.mouseItem.stack + inv[slot].stack <= Main.mouseItem.maxStack)
                            {
                                inv[slot].stack     += Main.mouseItem.stack;
                                Main.mouseItem.stack = 0;
                            }
                            else
                            {
                                int stack = Main.mouseItem.maxStack - inv[slot].stack;
                                inv[slot].stack      += stack;
                                Main.mouseItem.stack -= stack;
                            }
                        }
                    }

                    if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                    {
                        Main.mouseItem = new Item();
                    }

                    if (Main.mouseItem.type > 0 || inv[slot].type > 0)
                    {
                        Recipe.FindRecipes();

                        if (Main.LocalPlayer.inventory[slot].type != ModContent.ItemType <ItemLock>())
                        {
                            Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        }
                    }

                    if (context == 3 && Main.netMode == 1)
                    {
                        NetMessage.SendData(32, -1, -1, null, player.chest, slot, 0f, 0f, 0, 0, 0);
                    }
                }
                else if (num == 1)
                {
                    if (Main.mouseItem.stack == 1 && Main.mouseItem.type > 0 && inv[slot].type > 0 && inv[slot].IsNotTheSameAs(Main.mouseItem))
                    {
                        Utils.Swap(ref inv[slot], ref Main.mouseItem);
                        Main.PlaySound(7, -1, -1, 1, 1f, 0f);

                        if (inv[slot].stack > 0)
                        {
                            if (context != 0)
                            {
                                switch (context)
                                {
                                case 8:
                                case 9:
                                case 10:
                                case 11:
                                case 12:
                                case 16:
                                case 17:
                                    AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    break;
                                }
                            }
                            else
                            {
                                AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                            }
                        }
                    }
                    else if (Main.mouseItem.type == 0 && inv[slot].type > 0)
                    {
                        Utils.Swap(ref inv[slot], ref Main.mouseItem);

                        if (inv[slot].type == 0 || inv[slot].stack < 1)
                        {
                            inv[slot] = new Item();
                        }

                        if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                        {
                            Main.mouseItem = new Item();
                        }

                        if (Main.mouseItem.type > 0 || inv[slot].type > 0)
                        {
                            Recipe.FindRecipes();
                            Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        }
                    }
                    else if (Main.mouseItem.type > 0 && inv[slot].type == 0)
                    {
                        if (Main.mouseItem.stack == 1)
                        {
                            Utils.Swap(ref inv[slot], ref Main.mouseItem);

                            if (inv[slot].type == 0 || inv[slot].stack < 1)
                            {
                                inv[slot] = new Item();
                            }

                            if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                            {
                                Main.mouseItem = new Item();
                            }

                            if (Main.mouseItem.type > 0 || inv[slot].type > 0)
                            {
                                Recipe.FindRecipes();
                                Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                            }
                        }
                        else
                        {
                            Main.mouseItem.stack--;
                            inv[slot].SetDefaults(Main.mouseItem.type, false);
                            Recipe.FindRecipes();
                            Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        }

                        if (inv[slot].stack > 0)
                        {
                            if (context != 0)
                            {
                                switch (context)
                                {
                                case 8:
                                case 9:
                                case 10:
                                case 11:
                                case 12:
                                case 16:
                                case 17:
                                    AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    break;
                                }
                            }
                            else
                            {
                                AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                            }
                        }
                    }
                }
                else if (num == 2)
                {
                    if (Main.mouseItem.stack == 1 && Main.mouseItem.dye > 0 && inv[slot].type > 0 && inv[slot].type != Main.mouseItem.type)
                    {
                        Utils.Swap(ref inv[slot], ref Main.mouseItem);
                        Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        if (inv[slot].stack > 0)
                        {
                            if (context != 0)
                            {
                                switch (context)
                                {
                                case 8:
                                case 9:
                                case 10:
                                case 11:
                                case 12:
                                case 16:
                                case 17:
                                    AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    break;
                                }
                            }
                            else
                            {
                                AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                            }
                        }
                    }
                    else if (Main.mouseItem.type == 0 && inv[slot].type > 0)
                    {
                        Utils.Swap(ref inv[slot], ref Main.mouseItem);

                        if (inv[slot].type == 0 || inv[slot].stack < 1)
                        {
                            inv[slot] = new Item();
                        }

                        if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                        {
                            Main.mouseItem = new Item();
                        }

                        if (Main.mouseItem.type > 0 || inv[slot].type > 0)
                        {
                            Recipe.FindRecipes();
                            Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        }
                    }
                    else if (Main.mouseItem.dye > 0 && inv[slot].type == 0)
                    {
                        if (Main.mouseItem.stack == 1)
                        {
                            Utils.Swap(ref inv[slot], ref Main.mouseItem);

                            if (inv[slot].type == 0 || inv[slot].stack < 1)
                            {
                                inv[slot] = new Item();
                            }

                            if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                            {
                                Main.mouseItem = new Item();
                            }

                            if (Main.mouseItem.type > 0 || inv[slot].type > 0)
                            {
                                Recipe.FindRecipes();
                                Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                            }
                        }
                        else
                        {
                            Main.mouseItem.stack--;
                            inv[slot].SetDefaults(Main.mouseItem.type, false);
                            Recipe.FindRecipes();
                            Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        }

                        if (inv[slot].stack > 0)
                        {
                            if (context != 0)
                            {
                                switch (context)
                                {
                                case 8:
                                case 9:
                                case 10:
                                case 11:
                                case 12:
                                case 16:
                                case 17:
                                    AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    break;
                                }
                            }
                            else
                            {
                                AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                            }
                        }
                    }
                }
                else if (num == 3 && PlayerHooks.CanBuyItem(player, Main.npc[player.talkNPC], inv, inv[slot]))
                {
                    Main.mouseItem       = inv[slot].Clone();
                    Main.mouseItem.stack = 1;

                    if (inv[slot].buyOnce)
                    {
                        Main.mouseItem.value *= 5;
                    }
                    else
                    {
                        Main.mouseItem.Prefix(-1);
                    }

                    Main.mouseItem.position = player.Center - new Vector2(Main.mouseItem.width, Main.mouseItem.headSlot) / 2f;
                    ItemText.NewText(Main.mouseItem, Main.mouseItem.stack, false, false);

                    if (inv[slot].buyOnce && --inv[slot].stack <= 0)
                    {
                        inv[slot].SetDefaults(0, false);
                    }

                    if (inv[slot].value > 0)
                    {
                        Main.PlaySound(18, -1, -1, 1, 1f, 0f);
                    }
                    else
                    {
                        Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                    }

                    PlayerHooks.PostBuyItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem);
                }
                else if (num == 4 && PlayerHooks.CanSellItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem))
                {
                    Chest chest = Main.instance.shop[Main.npcShop];

                    if (player.SellItem(Main.mouseItem.value, Main.mouseItem.stack))
                    {
                        int soldItemIndex = chest.AddShop(Main.mouseItem);
                        Main.mouseItem.SetDefaults(0, false);
                        Main.PlaySound(18, -1, -1, 1, 1f, 0f);
                        PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[soldItemIndex]);
                    }
                    else if (Main.mouseItem.value == 0)
                    {
                        int soldItemIndex = chest.AddShop(Main.mouseItem);
                        Main.mouseItem.SetDefaults(0, false);
                        Main.PlaySound(7, -1, -1, 1, 1f, 0f);
                        PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[soldItemIndex]);
                    }

                    Recipe.FindRecipes();
                }
                switch (context)
                {
                case 0:
                case 1:
                case 2:
                case 5:
                    return;

                case 3:
                case 4:
                default:
                    inv[slot].favorited = false;
                    return;
                }
            }
        }
Ejemplo n.º 10
0
        public override void PostAI(Projectile projectile)
        {
            if ((projectile.minion || projectile.sentry) && !ProjectileID.Sets.StardustDragon[projectile.type] && !LongMinion)
            {
                if (setDefMinionDamage)
                {
                    DefMinionDamageMultiply = Main.player[projectile.owner].minionDamage + Main.player[projectile.owner].allDamage - 1f;
                    DefMinionDamage         = (int)(projectile.damage / DefMinionDamageMultiply);
                    setDefMinionDamage      = false;
                }
                if ((Main.player[projectile.owner].minionDamage + Main.player[projectile.owner].allDamage - 1f) != DefMinionDamageMultiply)
                {
                    int damage = (int)(DefMinionDamage * (Main.player[projectile.owner].minionDamage + Main.player[projectile.owner].allDamage - 1f));
                    if (damage <= 0)
                    {
                        damage = 1;
                    }
                    projectile.damage = damage;
                }
            }
            if (projectile.type == ProjectileID.PureSpray)
            {
                Convert((int)(projectile.position.X + (projectile.width / 2)) / 16, (int)(projectile.position.Y + (projectile.height / 2)) / 16);
            }

            if (projectile.bobber)
            {
                if (Main.player[projectile.owner].GetModPlayer <AAPlayer>().StripeManFish)
                {
                    Rectangle rectangle = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height);
                    Rectangle value     = new Rectangle((int)Main.player[projectile.owner].position.X, (int)Main.player[projectile.owner].position.Y, Main.player[projectile.owner].width, Main.player[projectile.owner].height);
                    if (rectangle.Intersects(value) && projectile.ai[1] > 0f)
                    {
                        Item item        = new Item();
                        int  itemtype    = 0;
                        int  projectileX = (int)(projectile.Center.X / 16f);
                        int  projectileY = (int)(projectile.Center.Y / 16f);
                        int  WorldHeightType;
                        if (projectileY < Main.worldSurface * 0.5)
                        {
                            WorldHeightType = 0;
                        }
                        else if (projectileY < Main.worldSurface)
                        {
                            WorldHeightType = 1;
                        }
                        else if (projectileY < Main.rockLayer)
                        {
                            WorldHeightType = 2;
                        }
                        else if (projectileY < Main.maxTilesY - 300)
                        {
                            WorldHeightType = 3;
                        }
                        else
                        {
                            WorldHeightType = 4;
                        }
                        if (Main.rand.Next(100) < 20f)
                        {
                            if (Main.rand.Next(3) == 0)
                            {
                                itemtype = 2336;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneCorrupt)
                            {
                                itemtype = 3203;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneCrimson)
                            {
                                itemtype = 3204;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneHoly)
                            {
                                itemtype = 3207;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneDungeon)
                            {
                                itemtype = 3205;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneJungle)
                            {
                                itemtype = 3208;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneSnow)
                            {
                                itemtype = mod.ItemType("IceCrate");
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneDesert)
                            {
                                itemtype = mod.ItemType("DesertCrate");
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].GetModPlayer <AAPlayer>().ZoneInferno)
                            {
                                itemtype = mod.ItemType("InfernoCrate");
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].GetModPlayer <AAPlayer>().ZoneMire)
                            {
                                itemtype = mod.ItemType("MireCrate");
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].GetModPlayer <AAPlayer>().ZoneVoid)
                            {
                                itemtype = mod.ItemType("VoidCrate");
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].GetModPlayer <AAPlayer>().ZoneHoard)
                            {
                                itemtype = ItemID.GoldenCrate;
                            }
                            else if (Main.rand.Next(3) == 0 && Main.player[projectile.owner].ZoneUnderworldHeight)
                            {
                                itemtype = mod.ItemType("HellCrate");
                            }
                            else if (Main.rand.Next(3) == 0 && WorldHeightType == 0)
                            {
                                itemtype = 3206;
                            }
                            else if (Main.rand.Next(2) == 0)
                            {
                                itemtype = 2335;
                            }
                            else
                            {
                                itemtype = 2334;
                            }
                        }
                        bool junk       = false;
                        int  liquidtype = 0;
                        int  tileX      = 0;
                        int  tileY      = 0;
                        while (tileX < 20 && tileY < 20)
                        {
                            if (Main.tile[projectileX - 10 + tileX, projectileY - 20 + tileY].lava())
                            {
                                liquidtype = 1;
                            }
                            else if (Main.tile[projectileX - 10 + tileX, projectileY - 20 + tileY].honey())
                            {
                                liquidtype = 2;
                            }
                            tileY++;
                            if (tileY >= 20)
                            {
                                tileX++;
                                tileY = 0;
                            }
                        }
                        while (itemtype == 0)
                        {
                            PlayerHooks.CatchFish(Main.player[projectile.owner], Main.player[projectile.owner].inventory[Main.player[projectile.owner].selectedItem], int.MaxValue, liquidtype, int.MaxValue, WorldHeightType, 0, ref itemtype, ref junk);
                        }
                        item.SetDefaults(itemtype, false);
                        ItemLoader.CaughtFishStack(item);
                        item.newAndShiny = true;
                        Item CreatItem = Main.player[projectile.owner].GetItem(projectile.owner, item, false, false);
                        if (CreatItem.stack > 0)
                        {
                            int number = Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, item.type, 1, false, 0, true, false);
                            if (Main.netMode == 1)
                            {
                                NetMessage.SendData(21, -1, -1, null, number, 1f, 0f, 0f, 0, 0, 0);
                            }
                        }
                        else
                        {
                            item.position.X = projectile.Center.X - item.width / 2;
                            item.position.Y = projectile.Center.Y - item.height / 2;
                            item.active     = true;
                            ItemText.NewText(item, 0, false, false);
                        }
                    }
                }
            }

            base.PostAI(projectile);
        }
Ejemplo n.º 11
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            // This will hide the crafting menu similar to the reforge menu. For best results this UI is placed before "Vanilla: Inventory" to prevent 1 frame of the craft menu showing.
            Main.HidePlayerCraftingMenu = true;

            // Here we have a lot of code. This code is mainly adapted from the vanilla code for the reforge option.
            // This code draws "Place an item here" when no item is in the slot and draws the reforge cost and a reforge button when an item is in the slot.
            // This code could possibly be better as different UIElements that are added and removed, but that's not the main point of this example.
            // If you are making a UI, add UIElements in OnInitialize that act on your ItemSlot or other inputs rather than the non-UIElement approach you see below.

            const int slotX = 50;
            const int slotY = 270;

            if (!_vanillaItemSlot.Item.IsAir)
            {
                int upgradeCost = Item.buyPrice(0, 1, 0, 0);

                string costText  = Language.GetTextValue("LegacyInterface.46") + ": ";
                string coinsText = "";
                int[]  coins     = Utils.CoinsSplit(upgradeCost);
                if (coins[3] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinPlatinum).Hex3() + ":" + coins[3] + " " + Language.GetTextValue("LegacyInterface.15") + "] ";
                }
                if (coins[2] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinGold).Hex3() + ":" + coins[2] + " " + Language.GetTextValue("LegacyInterface.16") + "] ";
                }
                if (coins[1] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinSilver).Hex3() + ":" + coins[1] + " " + Language.GetTextValue("LegacyInterface.17") + "] ";
                }
                if (coins[0] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinCopper).Hex3() + ":" + coins[0] + " " + Language.GetTextValue("LegacyInterface.18") + "] ";
                }
                ItemSlot.DrawSavings(Main.spriteBatch, slotX + 130, Main.instance.invBottom, true);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, costText, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, coinsText, new Vector2(slotX + 50 + Main.fontMouseText.MeasureString(costText).X, (float)slotY), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                int       reforgeX = slotX + 70;
                int       reforgeY = slotY + 40;
                bool      hoveringOverReforgeButton = Main.mouseX > reforgeX - 15 && Main.mouseX <reforgeX + 15 && Main.mouseY> reforgeY - 15 && Main.mouseY < reforgeY + 15 && !PlayerInput.IgnoreMouseInterface;
                Texture2D reforgeTexture = Main.reforgeTexture[hoveringOverReforgeButton ? 1 : 0];
                Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 2f, 0.8f, SpriteEffects.None, 0f);
                if (hoveringOverReforgeButton)
                {
                    Main.hoverItemName = Language.GetTextValue("LegacyInterface.19");
                    if (!tickPlayed)
                    {
                        Main.PlaySound(SoundID.MenuTick, -1, -1, 1, 1f, 0f);
                    }
                    tickPlayed = true;
                    Main.LocalPlayer.mouseInterface = true;
                    if (Main.mouseLeftRelease && Main.mouseLeft && Main.LocalPlayer.CanBuyItem(upgradeCost, -1) && ItemLoader.PreReforge(_vanillaItemSlot.Item))
                    {
                        Main.LocalPlayer.BuyItem(upgradeCost, -1);
                        bool favorited   = _vanillaItemSlot.Item.favorited;
                        int  stack       = _vanillaItemSlot.Item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(_vanillaItemSlot.Item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(_vanillaItemSlot.Item);
                        switch (Main.rand.Next(13))                           //This case swich could be transformed into an array quite easily
                        {
                        case 0:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("SlimeSlaying"));
                            break;

                        case 1:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("UndeadSlaying"));
                            break;

                        case 2:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("SkySlaying"));
                            break;

                        case 3:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("WaterSlaying"));
                            break;

                        case 4:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("HellSlaying"));
                            break;

                        case 5:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("CorruptionSlaying"));
                            break;

                        case 6:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("CrimsonSlaying"));
                            break;

                        case 7:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("BloodSlaying"));
                            break;

                        case 8:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("SnowSlaying"));
                            break;

                        case 9:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("PirateSlaying"));
                            break;

                        case 10:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("JungleSlaying"));
                            break;

                        case 11:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("HollowSlaying"));
                            break;

                        default:
                            reforgeItem.Prefix(GetInstance <StoneworkRoseCafe>().PrefixType("SolarEclipseSlaying"));
                            break;
                        }

                        _vanillaItemSlot.Item            = reforgeItem.Clone();
                        _vanillaItemSlot.Item.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(_vanillaItemSlot.Item.width / 2);
                        _vanillaItemSlot.Item.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(_vanillaItemSlot.Item.height / 2);
                        _vanillaItemSlot.Item.favorited  = favorited;
                        _vanillaItemSlot.Item.stack      = stack;
                        ItemLoader.PostReforge(_vanillaItemSlot.Item);
                        ItemText.NewText(_vanillaItemSlot.Item, _vanillaItemSlot.Item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }
                else
                {
                    tickPlayed = false;
                }
            }
            else
            {
                string message = "Make this item slay specific creatures";
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            }
        }
Ejemplo n.º 12
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);
            int slotX = -35;
            int slotY = 320;

            if (!vanillaItemSlot.item.IsAir)
            {
                int awesomePrice = Item.buyPrice(0, 1, 0, 0);

                string costText  = Lang.inter[46].Value + ": ";
                string coinsText = "";
                int[]  coins     = Utils.CoinsSplit(awesomePrice);
                if (coins[3] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinPlatinum).Hex3() + ":" + coins[3] + " " + Lang.inter[15].Value + "] ";
                }
                if (coins[2] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinGold).Hex3() + ":" + coins[2] + " " + Lang.inter[16].Value + "] ";
                }
                if (coins[1] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinSilver).Hex3() + ":" + coins[1] + " " + Lang.inter[17].Value + "] ";
                }
                if (coins[0] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinCopper).Hex3() + ":" + coins[0] + " " + Lang.inter[18].Value + "] ";
                }
                ItemSlot.DrawSavings(Main.spriteBatch, slotX + 130, Main.instance.invBottom, true);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, costText, new Vector2((slotX + 50), slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, coinsText, new Vector2((slotX + 50) + Main.fontMouseText.MeasureString(costText).X, (float)slotY), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                int       reforgeX = slotX + 70;
                int       reforgeY = slotY + 40;
                bool      hoveringOverReforgeButton = Main.mouseX > reforgeX - 15 && Main.mouseX <reforgeX + 15 && Main.mouseY> reforgeY - 15 && Main.mouseY < reforgeY + 15 && !PlayerInput.IgnoreMouseInterface;
                Texture2D reforgeTexture = Main.reforgeTexture[hoveringOverReforgeButton ? 1 : 0];
                Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 2f, 0.8f, SpriteEffects.None, 0f);
                if (hoveringOverReforgeButton)
                {
                    Main.hoverItemName = Lang.inter[19].Value;
                    if (!tickPlayed)
                    {
                        Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                    }
                    tickPlayed = true;
                    Main.LocalPlayer.mouseInterface = true;
                    if (Main.mouseLeftRelease && Main.mouseLeft && Main.LocalPlayer.CanBuyItem(awesomePrice, -1) && ItemLoader.PreReforge(vanillaItemSlot.item))
                    {
                        Main.LocalPlayer.BuyItem(awesomePrice, -1);
                        bool favorited   = vanillaItemSlot.item.favorited;
                        int  stack       = vanillaItemSlot.item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(vanillaItemSlot.item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(vanillaItemSlot.item);
                        // This is the main effect of this slot. Giving the Awesome prefix 90% of the time and the ReallyAwesome prefix the other 10% of the time. All for a constant 1 gold. Useless, but informative.
                        if (Main.rand.NextBool(10))
                        {
                            reforgeItem.Prefix(PrimordialSands.instance.PrefixType("Abused"));
                        }
                        else
                        {
                            reforgeItem.Prefix(PrimordialSands.instance.PrefixType("Molested"));
                        }
                        vanillaItemSlot.item            = reforgeItem.Clone();
                        vanillaItemSlot.item.position.X = Main.player[Main.myPlayer].position.X + (float)(Main.player[Main.myPlayer].width / 2) - (float)(vanillaItemSlot.item.width / 2);
                        vanillaItemSlot.item.position.Y = Main.player[Main.myPlayer].position.Y + (float)(Main.player[Main.myPlayer].height / 2) - (float)(vanillaItemSlot.item.height / 2);
                        vanillaItemSlot.item.favorited  = favorited;
                        vanillaItemSlot.item.stack      = stack;
                        ItemLoader.PostReforge(vanillaItemSlot.item);
                        ItemText.NewText(vanillaItemSlot.item, vanillaItemSlot.item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }
                else
                {
                    tickPlayed = false;
                }
            }
            else
            {
                string message = "Artifact";
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            }
        }
Ejemplo n.º 13
0
        public override void AI()
        {
            Player player = Main.player[projectile.owner];

            projectile.timeLeft = 60;
            if (player.HeldItem.fishingPole == 0 || player.CCed || player.noItems || player.pulley || player.dead || !player.active || !player.GetModPlayer <JoostPlayer>().fishingSapling)
            {
                projectile.Kill();
            }
            if (projectile.ai[1] > 0f && projectile.localAI[1] >= 0f)
            {
                projectile.localAI[1] = -1f;
                if (!projectile.lavaWet && !projectile.honeyWet)
                {
                    for (int i = 0; i < 100; i++)
                    {
                        int  num  = Dust.NewDust(new Vector2(projectile.position.X - 6f, projectile.position.Y - 10f), projectile.width + 12, 24, Dust.dustWater(), 0f, 0f, 0, default(Color), 1f);
                        Dust dust = Main.dust[num];
                        dust.velocity.Y = dust.velocity.Y - 4f;
                        Dust dust2 = Main.dust[num];
                        dust2.velocity.X         = dust2.velocity.X * 2.5f;
                        Main.dust[num].scale     = 0.8f;
                        Main.dust[num].alpha     = 100;
                        Main.dust[num].noGravity = true;
                    }
                    Main.PlaySound(19, (int)projectile.position.X, (int)projectile.position.Y, 0, 1f, 0f);
                }
            }
            if (projectile.ai[0] >= 1f)
            {
                if (projectile.ai[0] == 2f)
                {
                    projectile.ai[0] += 1f;
                    Main.PlaySound(SoundID.Item17, projectile.position);
                    if (!projectile.lavaWet && !projectile.honeyWet)
                    {
                        for (int j = 0; j < 100; j++)
                        {
                            int  num2  = Dust.NewDust(new Vector2(projectile.position.X - 6f, projectile.position.Y - 10f), projectile.width + 12, 24, Dust.dustWater(), 0f, 0f, 0, default(Color), 1f);
                            Dust dust3 = Main.dust[num2];
                            dust3.velocity.Y = dust3.velocity.Y - 4f;
                            Dust dust4 = Main.dust[num2];
                            dust4.velocity.X          = dust4.velocity.X * 2.5f;
                            Main.dust[num2].scale     = 0.8f;
                            Main.dust[num2].alpha     = 100;
                            Main.dust[num2].noGravity = true;
                        }
                        Main.PlaySound(19, (int)projectile.position.X, (int)projectile.position.Y, 0, 1f, 0f);
                    }
                }
                if (projectile.localAI[0] < 100f)
                {
                    projectile.localAI[0] += 1f;
                }
                projectile.tileCollide = false;
                float num3 = 15.9f;
                int   num4 = 10;
                float num5 = player.Center.X - projectile.Center.X;
                float num6 = player.Center.Y - projectile.Center.Y;
                float num7 = (float)Math.Sqrt((double)(num5 * num5 + num6 * num6));
                if (num7 > 3000f)
                {
                    projectile.Kill();
                }
                num7  = num3 / num7;
                num5 *= num7;
                num6 *= num7;
                projectile.velocity.X = (projectile.velocity.X * (float)(num4 - 1) + num5) / (float)num4;
                projectile.velocity.Y = (projectile.velocity.Y * (float)(num4 - 1) + num6) / (float)num4;
                if (Main.myPlayer == projectile.owner)
                {
                    Rectangle rectangle = new Rectangle((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height);
                    Rectangle value     = new Rectangle((int)player.position.X, (int)player.position.Y, player.width, player.height);
                    if (rectangle.Intersects(value))
                    {
                        if (projectile.ai[1] > 0f)
                        {
                            int  num8 = (int)projectile.ai[1];
                            Item item = new Item();
                            item.SetDefaults(num8, false);
                            if (num8 == 3196)
                            {
                                int num9     = player.FishingLevel();
                                int minValue = (num9 / 20 + 3) / 2;
                                int num10    = (num9 / 10 + 6) / 2;
                                if (Main.rand.Next(50) < num9)
                                {
                                    num10++;
                                }
                                if (Main.rand.Next(100) < num9)
                                {
                                    num10++;
                                }
                                if (Main.rand.Next(150) < num9)
                                {
                                    num10++;
                                }
                                if (Main.rand.Next(200) < num9)
                                {
                                    num10++;
                                }
                                int stack = Main.rand.Next(minValue, num10 + 1);
                                item.stack = stack;
                            }
                            if (num8 == 3197)
                            {
                                int num11     = player.FishingLevel();
                                int minValue2 = (num11 / 4 + 15) / 2;
                                int num12     = (num11 / 2 + 30) / 2;
                                if (Main.rand.Next(50) < num11)
                                {
                                    num12 += 4;
                                }
                                if (Main.rand.Next(100) < num11)
                                {
                                    num12 += 4;
                                }
                                if (Main.rand.Next(150) < num11)
                                {
                                    num12 += 4;
                                }
                                if (Main.rand.Next(200) < num11)
                                {
                                    num12 += 4;
                                }
                                int stack2 = Main.rand.Next(minValue2, num12 + 1);
                                item.stack = stack2;
                            }
                            ItemLoader.CaughtFishStack(item);
                            item.newAndShiny = true;
                            Item item2 = player.GetItem(projectile.owner, item, false, false);
                            if (item2.stack > 0)
                            {
                                int number = Item.NewItem((int)projectile.position.X, (int)projectile.position.Y, projectile.width, projectile.height, num8, 1, false, 0, true, false);
                                if (Main.netMode == 1)
                                {
                                    NetMessage.SendData(21, -1, -1, null, number, 1f, 0f, 0f, 0, 0, 0);
                                }
                            }
                            else
                            {
                                item.position.X = projectile.Center.X - (float)(item.width / 2);
                                item.position.Y = projectile.Center.Y - (float)(item.height / 2);
                                item.active     = true;
                                ItemText.NewText(item, 0, false, false);
                            }
                        }
                        projectile.Kill();
                    }
                }
                projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
                return;
            }
            bool  flag  = false;
            float num13 = player.Center.X - projectile.Center.X;
            float num14 = player.Center.Y - projectile.Center.Y;

            projectile.rotation = (float)Math.Atan2((double)num14, (double)num13) + 1.57f;
            float num15 = (float)Math.Sqrt((double)(num13 * num13 + num14 * num14));

            if (num15 > 900f)
            {
                projectile.ai[0] = 1f;
            }
            if (projectile.wet)
            {
                projectile.rotation   = 0f;
                projectile.velocity.X = projectile.velocity.X * 0.9f;
                int   num16 = (int)(projectile.Center.X + (float)((projectile.width / 2 + 8) * projectile.direction)) / 16;
                int   num17 = (int)(projectile.Center.Y / 16f);
                float num18 = projectile.position.Y / 16f;
                int   num19 = (int)((projectile.position.Y + (float)projectile.height) / 16f);
                if (Main.tile[num16, num17] == null)
                {
                    Main.tile[num16, num17] = new Tile();
                }
                if (Main.tile[num16, num19] == null)
                {
                    Main.tile[num16, num19] = new Tile();
                }
                if (projectile.velocity.Y > 0f)
                {
                    projectile.velocity.Y = projectile.velocity.Y * 0.5f;
                }
                num16 = (int)(projectile.Center.X / 16f);
                num17 = (int)(projectile.Center.Y / 16f);
                float num20 = projectile.position.Y + (float)projectile.height;
                if (Main.tile[num16, num17 - 1] == null)
                {
                    Main.tile[num16, num17 - 1] = new Tile();
                }
                if (Main.tile[num16, num17] == null)
                {
                    Main.tile[num16, num17] = new Tile();
                }
                if (Main.tile[num16, num17 + 1] == null)
                {
                    Main.tile[num16, num17 + 1] = new Tile();
                }
                if (Main.tile[num16, num17 - 1].liquid > 0)
                {
                    num20  = (float)(num17 * 16);
                    num20 -= (float)(Main.tile[num16, num17 - 1].liquid / 16);
                }
                else if (Main.tile[num16, num17].liquid > 0)
                {
                    num20  = (float)((num17 + 1) * 16);
                    num20 -= (float)(Main.tile[num16, num17].liquid / 16);
                }
                else if (Main.tile[num16, num17 + 1].liquid > 0)
                {
                    num20  = (float)((num17 + 2) * 16);
                    num20 -= (float)(Main.tile[num16, num17 + 1].liquid / 16);
                }
                if (projectile.Center.Y > num20)
                {
                    projectile.velocity.Y = projectile.velocity.Y - 0.1f;
                    if (projectile.velocity.Y < -8f)
                    {
                        projectile.velocity.Y = -8f;
                    }
                    if (projectile.Center.Y + projectile.velocity.Y < num20)
                    {
                        projectile.velocity.Y = num20 - projectile.Center.Y;
                    }
                }
                else
                {
                    projectile.velocity.Y = num20 - projectile.Center.Y;
                }
                if ((double)projectile.velocity.Y >= -0.01 && (double)projectile.velocity.Y <= 0.01)
                {
                    flag = true;
                }
            }
            else
            {
                if (projectile.velocity.Y == 0f)
                {
                    projectile.velocity.X = projectile.velocity.X * 0.95f;
                }
                projectile.velocity.X = projectile.velocity.X * 0.98f;
                projectile.velocity.Y = projectile.velocity.Y + 0.2f;
                if (projectile.velocity.Y > 15.9f)
                {
                    projectile.velocity.Y = 15.9f;
                }
            }
            if (Main.myPlayer == projectile.owner)
            {
                int num21 = player.FishingLevel();
                if (num21 < 0 && num21 == -1)
                {
                    player.displayedFishingInfo = Language.GetTextValue("GameUI.FishingWarning");
                }
            }
            if (projectile.ai[1] != 0f)
            {
                flag = true;
            }
            if (flag)
            {
                if (projectile.ai[1] == 0f && Main.myPlayer == projectile.owner)
                {
                    int num22 = player.FishingLevel();
                    if (num22 == -9000)
                    {
                        projectile.localAI[1] += 5f;
                        projectile.localAI[1] += (float)Main.rand.Next(1, 3);
                        if (projectile.localAI[1] > 660f)
                        {
                            projectile.localAI[1] = 0f;
                            projectile.FishingCheck();
                            return;
                        }
                    }
                    else
                    {
                        if (Main.rand.Next(300) < num22)
                        {
                            projectile.localAI[1] += (float)Main.rand.Next(1, 3);
                        }
                        projectile.localAI[1] += (float)(num22 / 30);
                        projectile.localAI[1] += (float)Main.rand.Next(1, 3);
                        if (Main.rand.Next(60) == 0)
                        {
                            projectile.localAI[1] += 60f;
                        }
                        if (projectile.localAI[1] > 660f)
                        {
                            projectile.localAI[1] = 0f;
                            projectile.FishingCheck();
                            return;
                        }
                    }
                }
                else if (projectile.ai[1] < 0f)
                {
                    if (projectile.velocity.Y == 0f || (projectile.honeyWet && (double)projectile.velocity.Y >= -0.01 && (double)projectile.velocity.Y <= 0.01))
                    {
                        projectile.velocity.Y = (float)Main.rand.Next(100, 500) * 0.015f;
                        projectile.velocity.X = (float)Main.rand.Next(-100, 101) * 0.015f;
                        projectile.wet        = false;
                        projectile.lavaWet    = false;
                        projectile.honeyWet   = false;
                    }
                    projectile.ai[1] += (float)Main.rand.Next(1, 5);
                    if (projectile.ai[1] >= 0f)
                    {
                        projectile.ai[1]      = 0f;
                        projectile.localAI[1] = 0f;
                        projectile.netUpdate  = true;
                    }
                }
            }
            AutoFish();
            return;
        }
Ejemplo n.º 14
0
        protected override void DrawSelf(SpriteBatch spriteBatch)         //TODO Clean this mess up
        {
            base.DrawSelf(spriteBatch);

            if (_vanillaItemSlot.IsMouseHovering || Indicator.IsMouseHovering)
            {
                Main.hoverItemName = "Explosive";
                Main.LocalPlayer.mouseInterface = true;
            }
            else if (_vanillaItemSlot2.IsMouseHovering || Indicator2.IsMouseHovering)
            {
                Main.hoverItemName = "Bullets (10 required)";
                Main.LocalPlayer.mouseInterface = true;
            }
            else if (combineButton.IsMouseHovering)
            {
                combineButton.SetImage(Main.reforgeTexture[1]);
                hoveringOverReforgeButton       = true;
                Main.hoverItemName              = "Combine +1";
                Main.LocalPlayer.mouseInterface = true;
            }
            else if (combineButtonTen.IsMouseHovering)
            {
                combineButtonTen.SetImage(Main.reforgeTexture[1]);
                hoveringOverReforgeButtonTen    = true;
                Main.hoverItemName              = "Combine +10";
                Main.LocalPlayer.mouseInterface = true;
            }
            else
            {
                combineButton.SetImage(Main.reforgeTexture[0]); hoveringOverReforgeButton = false; combineButtonTen.SetImage(Main.reforgeTexture[0]); hoveringOverReforgeButtonTen = false;
            }

            // This will hide the crafting menu similar to the reforge menu. For best results this UI is placed before "Vanilla: Inventory" to prevent 1 frame of the craft menu showing.
            Main.HidePlayerCraftingMenu = true;

            // Here we have a lot of code. This code is mainly adapted from the vanilla code for the reforge option.
            // This code draws "Place an item here" when no item is in the slot and draws the reforge cost and a reforge button when an item is in the slot.
            // This code could possibly be better as different UIElements that are added and removed, but that's not the main point of this example.
            // If you are making a UI, add UIElements in OnInitialize that act on your ItemSlot or other inputs rather than the non-UIElement approach you see below.

            const int slotX = 50;
            const int slotY = 270;

            //string message2 = "Element/Ammo"; //Will be check depending on whats the first slot, for insance, if the first slot has a bullet boom then it will select ammo

            //ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, "Currently Working Explosives: Bullet Boom", new Vector2(slotX, slotY + 80), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);

            Indicator.SetImage(ModContent.GetTexture("ExtraExplosives/UI/Indicator"));
            Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/Indicator"));

            bool Craftable = false;
            bool CraftTen  = false;

            //ammo
            if (!_vanillaItemSlot2.Item.IsAir && _vanillaItemSlot.Item.IsAir)
            {
                if (_vanillaItemSlot2.Item.ammo == AmmoID.Bullet && _vanillaItemSlot2.Item.stack >= 10)
                {
                    Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorGreen"));
                    Indicator.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorRed"));
                }
                else if (_vanillaItemSlot2.Item.ammo == AmmoID.Bullet)
                {
                    Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorYellow"));

                    if (hoveringOverReforgeButton || hoveringOverReforgeButtonTen)
                    {
                        Main.hoverItemName = $"You need to add {10 - _vanillaItemSlot2.Item.stack} bullets";
                        Main.LocalPlayer.mouseInterface = true;
                    }

                    Indicator.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorRed"));
                }
                else
                {
                    Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorRed"));

                    if (hoveringOverReforgeButton || hoveringOverReforgeButtonTen)
                    {
                        Main.hoverItemName = "You need to add 10 bullets and an empty shell";
                        Main.LocalPlayer.mouseInterface = true;
                    }

                    Indicator.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorRed"));
                }
            }

            //explosives
            if (!_vanillaItemSlot.Item.IsAir)             //check to see if the slot is air or not
            {
                //bomb
                if (_vanillaItemSlot.Item.type == ModContent.ItemType <BulletBoomEmptyItem>())
                {
                    Indicator.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorGreen"));
                }
                else
                {
                    Indicator.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorRed"));
                }

                //ammo
                if (_vanillaItemSlot2.Item.ammo == AmmoID.Bullet && _vanillaItemSlot2.Item.stack >= 10)
                {
                    Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorGreen"));

                    if (hoveringOverReforgeButtonTen && _vanillaItemSlot2.Item.stack <= 100)
                    {
                        Main.hoverItemName = $"You need to add {100 - _vanillaItemSlot2.Item.stack} bullets for +10";
                        Main.LocalPlayer.mouseInterface = true;
                    }
                }
                else if (_vanillaItemSlot2.Item.ammo == AmmoID.Bullet)
                {
                    Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorYellow"));

                    if (hoveringOverReforgeButton || hoveringOverReforgeButtonTen)
                    {
                        Main.hoverItemName = $"You need to add {10 -_vanillaItemSlot2.Item.stack} bullets";
                        Main.LocalPlayer.mouseInterface = true;
                    }
                }
                else
                {
                    Indicator2.SetImage(ModContent.GetTexture("ExtraExplosives/UI/IndicatorRed"));

                    if (hoveringOverReforgeButton || hoveringOverReforgeButtonTen)
                    {
                        Main.hoverItemName = "You need to add 10 bullets";
                        Main.LocalPlayer.mouseInterface = true;
                    }
                }

                //------------------------------------------------------ Indicators above -----------------------------------------------

                if (_vanillaItemSlot.Item.type == ModContent.ItemType <BulletBoomEmptyItem>() && _vanillaItemSlot2.Item.ammo == AmmoID.Bullet)                //Check to see if the slot has a bulletboom here and ammo in the ammo slot
                {
                    if (_vanillaItemSlot.Item.stack >= 1 && _vanillaItemSlot2.Item.stack >= 10)
                    {
                        Craftable = true;
                    }
                    if (_vanillaItemSlot.Item.stack >= 10 && _vanillaItemSlot2.Item.stack >= 100)
                    {
                        CraftTen = true;
                    }
                    //if (_vanillaItemSlot.Item.stack >= 1 && _vanillaItemSlot2.Item.stack < 10 && !_vanillaItemSlot2.Item.IsAir)
                    //{
                    //	ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, "Need 10!", new Vector2(slotX + 150, slotY + 50), new Color(255, 0, 0), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                    //}
                }
                else
                {
                    //if (_vanillaItemSlot.Item.type == ModContent.ItemType<BulletBoomEmptyItem>() && _vanillaItemSlot2.Item.ammo != AmmoID.Bullet && !_vanillaItemSlot2.Item.IsAir) //check to see if the item is a bullet boom and the second slot is not ammo and not air
                    //{
                    //	ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message2, new Vector2(slotX + 150, slotY + 50), new Color(255, 0, 0), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                    //}
                    Craftable = false;
                    CraftTen  = false;
                }

                if (!_vanillaItemSlot.Item.IsAir && !_vanillaItemSlot2.Item.IsAir && (Craftable || CraftTen))                 //if both spots are full summon the combine -----------------------
                {
                    int reforgeX = slotX + 290;
                    int reforgeY = slotY + 40;

                    //hoveringOverReforgeButton = Main.mouseX > reforgeX - 15 && Main.mouseX < reforgeX + 15 && Main.mouseY > reforgeY - 15 && Main.mouseY < reforgeY + 15 && !PlayerInput.IgnoreMouseInterface;

                    //ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, "Combine", new Vector2(slotX + 250, (float)slotY), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);

                    //Texture2D reforgeTexture = Main.reforgeTexture[hoveringOverReforgeButton ? 1 : 0];

                    //Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 1.5f, 0.8f, SpriteEffects.None, 0f);
                    if (hoveringOverReforgeButton)
                    {
                        Main.hoverItemName = "Combine";
                        if (!tickPlayed)
                        {
                            Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                        }
                        tickPlayed = true;
                        Main.LocalPlayer.mouseInterface = true;
                        if (Main.mouseLeftRelease && Main.mouseLeft && Craftable)                         //add a check here to see if its an item that can be combined and if it can produce it here
                        {
                            if (_vanillaItemSlot.Item.type == ModContent.ItemType <BulletBoomEmptyItem>() && _vanillaItemSlot2.Item.ammo == AmmoID.Bullet)
                            {
                                ItemAmmo = _vanillaItemSlot2.Item.type; //get the id for the ammo

                                // Now that we've spawned the item back onto the player, we reset the item by turning it into air.
                                if (_vanillaItemSlot.Item.stack >= 1 && _vanillaItemSlot2.Item.stack >= 10 && Main.netMode != NetmodeID.Server)
                                {
                                    Player player = Main.player[Main.myPlayer];
                                    spriteBatch.End();
                                    bool flag = false;
                                    foreach (Item checkItem in Main.player[Main.myPlayer].inventory)
                                    {
                                        if (checkItem.type == ModContent.ItemType <BulletBoomItem>())
                                        {
                                            BulletBoomItem modCheckItem = (BulletBoomItem)checkItem.modItem;
                                            if (modCheckItem.item.shoot == _vanillaItemSlot2.Item.shoot && modCheckItem.overStack <= 998)
                                            {
                                                modCheckItem.overStack++;
                                                ItemText.NewText(modCheckItem.item, modCheckItem.overStack, true, false);
                                                flag = true;
                                            }
                                        }
                                    }

                                    if (!flag)
                                    {
                                        string        bulletType = "";
                                        StringBuilder sb         = new StringBuilder(_vanillaItemSlot2.Item.Name);
                                        sb.Replace(" bullet", "");
                                        sb.Replace(" Bullet", "");
                                        int itemInt = Item.NewItem(player.position, ModContent.ItemType <BulletBoomItem>(),
                                                                   1);
                                        //Main.player[Main.myPlayer].QuickSpawnItem(ModContent.ItemType<TestItem>());
                                        Main.item[itemInt].instanced = true;
                                        Main.item[itemInt].shoot     = _vanillaItemSlot2.Item.shoot;
                                        //Main.item[itemInt].modItem.DisplayName.SetDefault(Main.item[itemInt].Name + " " + _vanillaItemSlot2.Item.Name);
                                        Main.item[itemInt]
                                        .SetNameOverride(sb.ToString() + " Bullet Boom");
                                        Main.item[itemInt].damage = _vanillaItemSlot2.Item.damage;
                                        BulletBoomItem tmp = (BulletBoomItem)Main.item[itemInt].modItem;
                                        tmp.bulletType = _vanillaItemSlot2.Item.Name;
                                        tmp.overStack++;
                                    }

                                    spriteBatch.Begin();
                                    // Removes the correct amount of each item
                                    _vanillaItemSlot.Item.stack  = _vanillaItemSlot.Item.stack - 1;
                                    _vanillaItemSlot2.Item.stack = _vanillaItemSlot2.Item.stack - 10;
                                }
                                else
                                {
                                    _vanillaItemSlot.Item.TurnToAir();
                                    _vanillaItemSlot2.Item.TurnToAir();
                                }

                                //ItemLoader.PostReforge(_vanillaItemSlot.Item);
                                //ItemLoader.PostReforge(_vanillaItemSlot2.Item);
                                Main.PlaySound(SoundID.Item37, -1, -1);
                            }
                        }
                    }

                    if (hoveringOverReforgeButtonTen && CraftTen)
                    {
                        Main.hoverItemName = "Combine Ten";
                        if (!tickPlayed)
                        {
                            Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                        }
                        tickPlayed = true;
                        Main.LocalPlayer.mouseInterface = true;
                        if (Main.mouseLeftRelease && Main.mouseLeft && CraftTen)                         //add a check here to see if its an item that can be combined and if it can produce it here
                        {
                            if (_vanillaItemSlot.Item.type == ModContent.ItemType <BulletBoomEmptyItem>() && _vanillaItemSlot2.Item.ammo == AmmoID.Bullet)
                            {
                                ItemAmmo = _vanillaItemSlot2.Item.type;                                 //get the id for the ammo

                                // Now that we've spawned the item back onto the player, we reset the item by turning it into air.
                                if (_vanillaItemSlot.Item.stack >= 10 && _vanillaItemSlot2.Item.stack >= 100 && Main.netMode != NetmodeID.Server)
                                {
                                    Player player = Main.player[Main.myPlayer];
                                    spriteBatch.End();
                                    bool flag = false;
                                    foreach (Item checkItem in Main.player[Main.myPlayer].inventory)
                                    {
                                        if (checkItem.type == ModContent.ItemType <BulletBoomItem>())
                                        {
                                            BulletBoomItem modCheckItem = (BulletBoomItem)checkItem.modItem;
                                            if (modCheckItem.item.shoot == _vanillaItemSlot2.Item.shoot && modCheckItem.overStack <= 998)
                                            {
                                                modCheckItem.overStack += 10;
                                                ItemText.NewText(modCheckItem.item, modCheckItem.overStack, true, false);
                                                flag = true;
                                            }
                                        }
                                    }

                                    if (!flag)
                                    {
                                        string        bulletType = "";
                                        StringBuilder sb         = new StringBuilder(_vanillaItemSlot2.Item.Name);
                                        sb.Replace(" bullet", "");
                                        sb.Replace(" Bullet", "");
                                        int itemInt = Item.NewItem(player.position, ModContent.ItemType <BulletBoomItem>(),
                                                                   1);
                                        //Main.player[Main.myPlayer].QuickSpawnItem(ModContent.ItemType<TestItem>());
                                        Main.item[itemInt].instanced = true;
                                        Main.item[itemInt].shoot     = _vanillaItemSlot2.Item.shoot;
                                        //Main.item[itemInt].modItem.DisplayName.SetDefault(Main.item[itemInt].Name + " " + _vanillaItemSlot2.Item.Name);
                                        Main.item[itemInt]
                                        .SetNameOverride(sb.ToString() + " Bullet Boom");
                                        Main.item[itemInt].damage = _vanillaItemSlot2.Item.damage;
                                        BulletBoomItem tmp = (BulletBoomItem)Main.item[itemInt].modItem;
                                        tmp.bulletType = _vanillaItemSlot2.Item.Name;
                                        tmp.overStack += 10;
                                    }

                                    spriteBatch.Begin();
                                    // Removes the correct amount of each item
                                    _vanillaItemSlot.Item.stack  = _vanillaItemSlot.Item.stack - 10;
                                    _vanillaItemSlot2.Item.stack = _vanillaItemSlot2.Item.stack - 100;
                                }
                                else
                                {
                                    _vanillaItemSlot.Item.TurnToAir();
                                    _vanillaItemSlot2.Item.TurnToAir();
                                }

                                //ItemLoader.PostReforge(_vanillaItemSlot.Item);
                                //ItemLoader.PostReforge(_vanillaItemSlot2.Item);
                                Main.PlaySound(SoundID.Item37, -1, -1);
                            }
                        }
                    }
                }
            }
            //else
            //{
            //	string message = "Explosive";
            //	ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 60, slotY + 170), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            //}

            //if (!_vanillaItemSlot2.Item.IsAir)
            //{
            //}
            //else
            //{
            //	ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message2, new Vector2(slotX + 150, slotY + 50), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
            //}
        }
Ejemplo n.º 15
0
        //TODO make IL
        //I method swapped because I could not get IL working
        private void On_LeftClick(On.Terraria.UI.ItemSlot.orig_LeftClick_ItemArray_int_int orig, Item[] inv, int context, int slot)
        {
            //Main.NewText(Main.cursorOverride);
            if (!(bool)overrideLeftClick.Invoke(null, new object[] { inv, context, slot }))
            {
                inv[slot].newAndShiny = false;
                Player player = Main.player[Main.myPlayer];
                bool   flag   = false;
                if ((uint)context <= 4u)
                {
                    flag = (player.chest == -1);
                }
                if (ControlInUse & flag)
                {
                    sellOrTrash.Invoke(null, new object[] { inv, context, slot });
                }
                else if (player.itemAnimation == 0 && player.itemTime == 0)
                {
                    switch (ItemSlot.PickItemMovementAction(inv, context, slot, Main.mouseItem))
                    {
                    case 0:
                        if (context == 6 && Main.mouseItem.type != ItemID.None)
                        {
                            inv[slot].SetDefaults(0, false);
                        }
                        Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                        if (inv[slot].stack > 0)
                        {
                            if (context != 0)
                            {
                                if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u)
                                {
                                    AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                }
                            }
                            else
                            {
                                AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                            }
                        }
                        if (inv[slot].type == ItemID.None || inv[slot].stack < 1)
                        {
                            inv[slot] = new Item();
                        }
                        if (Main.mouseItem.IsTheSameAs(inv[slot]))
                        {
                            Utils.Swap <bool>(ref inv[slot].favorited, ref Main.mouseItem.favorited);
                            if (inv[slot].stack != inv[slot].maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack)
                            {
                                if (Main.mouseItem.stack + inv[slot].stack <= Main.mouseItem.maxStack)
                                {
                                    inv[slot].stack     += Main.mouseItem.stack;
                                    Main.mouseItem.stack = 0;
                                }
                                else
                                {
                                    int num3 = Main.mouseItem.maxStack - inv[slot].stack;
                                    inv[slot].stack      += num3;
                                    Main.mouseItem.stack -= num3;
                                }
                            }
                        }
                        if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1)
                        {
                            Main.mouseItem = new Item();
                        }
                        if (Main.mouseItem.type > ItemID.None || inv[slot].type > ItemID.None)
                        {
                            Recipe.FindRecipes();
                            Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                        }
                        if (context == 3 && Main.netMode == NetmodeID.MultiplayerClient)
                        {
                            NetMessage.SendData(MessageID.SyncChestItem, -1, -1, null, player.chest, slot, 0f, 0f, 0, 0, 0);
                        }
                        break;

                    case 1:
                        if (Main.mouseItem.stack == 1 && Main.mouseItem.type > ItemID.None && inv[slot].type > ItemID.None && inv[slot].IsNotTheSameAs(Main.mouseItem))
                        {
                            Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                            Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                            if (inv[slot].stack > 0)
                            {
                                if (context != 0)
                                {
                                    if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u)
                                    {
                                        AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    }
                                }
                                else
                                {
                                    AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                                }
                            }
                        }
                        else if (Main.mouseItem.type == ItemID.None && inv[slot].type > ItemID.None)
                        {
                            Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                            if (inv[slot].type == ItemID.None || inv[slot].stack < 1)
                            {
                                inv[slot] = new Item();
                            }
                            if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1)
                            {
                                Main.mouseItem = new Item();
                            }
                            if (Main.mouseItem.type <= ItemID.None && inv[slot].type <= ItemID.None)
                            {
                                break;
                            }
                            Recipe.FindRecipes();
                            Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                        }
                        else if (Main.mouseItem.type > ItemID.None && inv[slot].type == ItemID.None)
                        {
                            if (Main.mouseItem.stack == 1)
                            {
                                Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                                if (inv[slot].type == ItemID.None || inv[slot].stack < 1)
                                {
                                    inv[slot] = new Item();
                                }
                                if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1)
                                {
                                    Main.mouseItem = new Item();
                                }
                                if (Main.mouseItem.type > ItemID.None || inv[slot].type > ItemID.None)
                                {
                                    Recipe.FindRecipes();
                                    Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                                }
                            }
                            else
                            {
                                Main.mouseItem.stack--;
                                inv[slot].SetDefaults(Main.mouseItem.type, false);
                                Recipe.FindRecipes();
                                Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                            }
                            if (inv[slot].stack > 0)
                            {
                                if (context != 0)
                                {
                                    if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u)
                                    {
                                        AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    }
                                }
                                else
                                {
                                    AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                                }
                            }
                        }
                        break;

                    case 2:
                        if (Main.mouseItem.stack == 1 && Main.mouseItem.dye > 0 && inv[slot].type > ItemID.None && inv[slot].type != Main.mouseItem.type)
                        {
                            Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                            Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                            if (inv[slot].stack > 0)
                            {
                                if (context != 0)
                                {
                                    if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u)
                                    {
                                        AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    }
                                }
                                else
                                {
                                    AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                                }
                            }
                        }
                        else if (Main.mouseItem.type == ItemID.None && inv[slot].type > ItemID.None)
                        {
                            Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                            if (inv[slot].type == ItemID.None || inv[slot].stack < 1)
                            {
                                inv[slot] = new Item();
                            }
                            if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1)
                            {
                                Main.mouseItem = new Item();
                            }
                            if (Main.mouseItem.type <= ItemID.None && inv[slot].type <= ItemID.None)
                            {
                                break;
                            }
                            Recipe.FindRecipes();
                            Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                        }
                        else if (Main.mouseItem.dye > 0 && inv[slot].type == ItemID.None)
                        {
                            if (Main.mouseItem.stack == 1)
                            {
                                Utils.Swap <Item>(ref inv[slot], ref Main.mouseItem);
                                if (inv[slot].type == ItemID.None || inv[slot].stack < 1)
                                {
                                    inv[slot] = new Item();
                                }
                                if (Main.mouseItem.type == ItemID.None || Main.mouseItem.stack < 1)
                                {
                                    Main.mouseItem = new Item();
                                }
                                if (Main.mouseItem.type > ItemID.None || inv[slot].type > ItemID.None)
                                {
                                    Recipe.FindRecipes();
                                    Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                                }
                            }
                            else
                            {
                                Main.mouseItem.stack--;
                                inv[slot].SetDefaults(Main.mouseItem.type, false);
                                Recipe.FindRecipes();
                                Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                            }
                            if (inv[slot].stack > 0)
                            {
                                if (context != 0)
                                {
                                    if ((uint)(context - 8) <= 4u || (uint)(context - 16) <= 1u)
                                    {
                                        AchievementsHelper.HandleOnEquip(player, inv[slot], context);
                                    }
                                }
                                else
                                {
                                    AchievementsHelper.NotifyItemPickup(player, inv[slot]);
                                }
                            }
                        }
                        break;

                    case 3:
                        if (PlayerHooks.CanBuyItem(player, Main.npc[player.talkNPC], inv, inv[slot]))
                        {
                            Main.mouseItem       = inv[slot].Clone();
                            Main.mouseItem.stack = 1;
                            if (inv[slot].buyOnce)
                            {
                                Main.mouseItem.value *= 5;
                            }
                            else
                            {
                                Main.mouseItem.Prefix(-1);
                            }
                            Main.mouseItem.position = player.Center - new Vector2(Main.mouseItem.width, Main.mouseItem.headSlot) / 2f;
                            ItemText.NewText(Main.mouseItem, Main.mouseItem.stack, false, false);
                            if (inv[slot].buyOnce && --inv[slot].stack <= 0)
                            {
                                inv[slot].SetDefaults(0, false);
                            }
                            if (inv[slot].value > 0)
                            {
                                Main.PlaySound(SoundID.Coins, -1, -1, 1, 1f, 0f);
                            }
                            else
                            {
                                Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                            }
                            PlayerHooks.PostBuyItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem);
                        }
                        break;

                    case 4:
                        if (PlayerHooks.CanSellItem(player, Main.npc[player.talkNPC], inv, Main.mouseItem))
                        {
                            Chest chest = Main.instance.shop[Main.npcShop];
                            if (player.SellItem(Main.mouseItem.value, Main.mouseItem.stack))
                            {
                                int num = chest.AddShop(Main.mouseItem);
                                Main.mouseItem.SetDefaults(0, false);
                                Main.PlaySound(SoundID.Coins, -1, -1, 1, 1f, 0f);
                                PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[num]);
                            }
                            else if (Main.mouseItem.value == 0)
                            {
                                int num2 = chest.AddShop(Main.mouseItem);
                                Main.mouseItem.SetDefaults(0, false);
                                Main.PlaySound(SoundID.Grab, -1, -1, 1, 1f, 0f);
                                PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[num2]);
                            }
                            Recipe.FindRecipes();
                        }
                        break;
                    }
                    if ((uint)context > 2u && context != 5)
                    {
                        inv[slot].favorited = false;
                    }
                }
            }
        }
Ejemplo n.º 16
0
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            // This will hide the crafting menu similar to the reforge menu. For best results this UI is placed before "Vanilla: Inventory" to prevent 1 frame of the craft menu showing.
            Main.HidePlayerCraftingMenu = true;

            // Here we have a lot of code. This code is mainly adapted from the vanilla code for the reforge option.
            // This code draws "Place an item here" when no item is in the slot and draws the reforge cost and a reforge button when an item is in the slot.
            // This code could possibly be better as different UIElements that are added and removed, but that's not the main point of this example.
            // If you are making a UI, add UIElements in OnInitialize that act on your ItemSlot or other inputs rather than the non-UIElement approach you see below.

            const int slotX = 30;
            const int slotY = 270;

            if (!_vanillaItemSlot.Item.IsAir && _vanillaItemSlot.Item.pick > 0)
            {
                int lightPrice = Item.buyPrice(0, 1, 0, 0);

                string costText  = Language.GetTextValue("LegacyInterface.46") + ": ";
                string coinsText = "";
                int[]  coins     = Utils.CoinsSplit(lightPrice);
                if (coins[3] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinPlatinum).Hex3() + ":" + coins[3] + " " + Language.GetTextValue("LegacyInterface.15") + "] ";
                }
                if (coins[2] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinGold).Hex3() + ":" + coins[2] + " " + Language.GetTextValue("LegacyInterface.16") + "] ";
                }
                if (coins[1] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinSilver).Hex3() + ":" + coins[1] + " " + Language.GetTextValue("LegacyInterface.17") + "] ";
                }
                if (coins[0] > 0)
                {
                    coinsText = coinsText + "[c/" + Colors.AlphaDarken(Colors.CoinCopper).Hex3() + ":" + coins[0] + " " + Language.GetTextValue("LegacyInterface.18") + "] ";
                }
                ItemSlot.DrawSavings(Main.spriteBatch, slotX + 130, Main.instance.invBottom, true);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, costText, new Vector2(slotX + 50, slotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, coinsText, new Vector2(slotX + 50 + Main.fontMouseText.MeasureString(costText).X, slotY), Color.White, 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                int       reforgeX = slotX + 70;
                int       reforgeY = slotY + 40;
                bool      hoveringOverReforgeButton = Main.mouseX > reforgeX - 15 && Main.mouseX <reforgeX + 15 && Main.mouseY> reforgeY - 15 && Main.mouseY < reforgeY + 15 && !PlayerInput.IgnoreMouseInterface;
                Texture2D reforgeTexture = Main.reforgeTexture[hoveringOverReforgeButton ? 1 : 0];
                Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 2f, 1.17f, SpriteEffects.None, 0f); //1.5f, changes size
                if (hoveringOverReforgeButton)
                {
                    Main.hoverItemName = Language.GetTextValue("LegacyInterface.19");
                    if (!tickPlayed)
                    {
                        Main.PlaySound(12, -1, -1, 1, 1f, 0f);
                    }
                    tickPlayed = true;
                    Main.LocalPlayer.mouseInterface = true;
                    if (Main.mouseLeftRelease && Main.mouseLeft && Main.LocalPlayer.CanBuyItem(lightPrice, -1) && ItemLoader.PreReforge(_vanillaItemSlot.Item))
                    {
                        Main.LocalPlayer.BuyItem(lightPrice, -1);
                        bool favorited   = _vanillaItemSlot.Item.favorited;
                        int  stack       = _vanillaItemSlot.Item.stack;
                        Item reforgeItem = new Item();
                        reforgeItem.netDefaults(_vanillaItemSlot.Item.netID);
                        reforgeItem = reforgeItem.CloneWithModdedDataFrom(_vanillaItemSlot.Item);
                        // This is the main effect of this slot. Giving the Awesome prefix 90% of the time and the ReallyAwesome prefix the other 10% of the time. All for a constant 1 gold. Useless, but informative.
                        reforgeItem.Prefix(PrefixID.Light);
                        _vanillaItemSlot.Item            = reforgeItem.Clone();
                        _vanillaItemSlot.Item.position.X = Main.LocalPlayer.position.X + Main.LocalPlayer.width / 2 - _vanillaItemSlot.Item.width / 2;
                        _vanillaItemSlot.Item.position.Y = Main.LocalPlayer.position.Y + Main.LocalPlayer.height / 2 - _vanillaItemSlot.Item.height / 2;
                        _vanillaItemSlot.Item.favorited  = favorited;
                        _vanillaItemSlot.Item.stack      = stack;
                        ItemLoader.PostReforge(_vanillaItemSlot.Item);
                        ItemText.NewText(_vanillaItemSlot.Item, _vanillaItemSlot.Item.stack, true, false);
                        Main.PlaySound(SoundID.Item37, -1, -1);
                    }
                }
                else
                {
                    tickPlayed = false;
                }
            }
            else
            {
                if (ModLoader.GetMod("AutoTrash") != null)
                {
                    string message = "Place a pickaxe here to reforge\n it to 'Light'";
                    ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 56, slotY + 5), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                }
                else
                {
                    string message = "Place a pickaxe here to reforge it to 'Light'";
                    ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, Main.fontMouseText, message, new Vector2(slotX + 56, slotY + 5), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                    //const int slotX = 50; //from left
                    //const int slotY = 270; //from top
                }
            }
        }
    //Makes it so that grabbed items will not enter the first hotbar slot
    //also changes all text to short, and doesn't count fallen star and snowball as ammo (side effects)
    public override bool OnPickup(Item item, Player player)
    {
        bool flag = item.type >= 71 && item.type <= 74;
        int  num1 = 50;
        int  num2 = 0;

        //if ammo then use normal
        if (((item.ammo > 0 || item.bait > 0) && !item.notAmmo || item.type == 530) && (item.type != 75 && item.type != 949))
        {
            return(true);
        }

        //use coin numbers
        if (flag)
        {
            return(true);
        }

        //if heart or star vairant, use normal
        if (item.type == 58 || item.type == 1867 || item.type == 1734 || item.type == 184 || item.type == 1868 || item.type == 1735 || (item.type > 3453 && item.type <= 3455))
        {
            return(true);
        }

        //if adding to a stack, use normal
        for (int index = num2; index < 50; ++index)
        {
            int i = index;
            if (i < 0)
            {
                i = 54 + index;
            }
            if (player.inventory[i].type > 0 && player.inventory[i].stack < player.inventory[i].maxStack && item.IsTheSameAs(player.inventory[i]))
            {
                if (item.stack + player.inventory[i].stack <= player.inventory[i].maxStack)
                {
                    return(true);
                }
            }
        }

        //start at 1, eliminating use of the first slot for usable items
        if (!flag && item.useStyle > 0)
        {
            for (int i = 1; i < 10; ++i)
            {
                if (player.inventory[i].type == 0)
                {
                    player.inventory[i] = item;
                    ItemText.NewText(item, item.stack, false, false);
                    player.DoCoins(i);
                    if (flag)
                    {
                        Main.PlaySound(38, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f);
                    }
                    else
                    {
                        Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f);
                    }
                    if (player.whoAmI == Main.myPlayer)
                    {
                        Recipe.FindRecipes();
                    }
                    AchievementsHelper.NotifyItemPickup(player, item);
                    return(false);
                }
            }
        }

        //end at 1, eliminating use of first slot for unusable items
        if (!item.favorited)
        {
            for (int i = num1 - 1; i >= 1; --i)
            {
                if (player.inventory[i].type == 0)
                {
                    player.inventory[i] = item;
                    ItemText.NewText(item, item.stack, false, false);
                    player.DoCoins(i);
                    if (flag)
                    {
                        Main.PlaySound(38, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f);
                    }
                    else
                    {
                        Main.PlaySound(7, (int)player.position.X, (int)player.position.Y, 1, 1f, 0.0f);
                    }
                    if (player.whoAmI == Main.myPlayer)
                    {
                        Recipe.FindRecipes();
                    }
                    AchievementsHelper.NotifyItemPickup(player, item);
                    return(false);
                }
            }
        }

        return(true);
    }