Ejemplo n.º 1
0
 private void PrefixButton_OnClick(UIMouseEvent evt, UIElement listeningElement)
 {
     Main.LocalPlayer.HeldItem.SetDefaults(Main.LocalPlayer.HeldItem.type);
     Main.LocalPlayer.HeldItem.Prefix(-2);
     Main.LocalPlayer.HeldItem.position.X = Main.LocalPlayer.position.X + (float)(Main.LocalPlayer.width / 2) - (float)(Main.LocalPlayer.HeldItem.width / 2);
     Main.LocalPlayer.HeldItem.position.Y = Main.LocalPlayer.position.Y + (float)(Main.LocalPlayer.height / 2) - (float)(Main.LocalPlayer.HeldItem.height / 2);
     PopupText.NewText(PopupTextContext.ItemReforge, Main.LocalPlayer.HeldItem, Main.LocalPlayer.HeldItem.stack, true, false);
 }
Ejemplo n.º 2
0
        public void TryTalkWithCD(TalkType talkType, int CD)
        {
            int talkInt = (int)talkType;

            if (TalkCDs[talkInt] > 0 || universalTalkCD > 0)
            {
                return;
            }

            TalkCounters[talkInt] = (TalkCounters[talkInt] + 1) % MaxThingsToSay[talkInt];
            TalkCDs[talkInt]      = CD;
            universalTalkCD       = 0;

            if (Projectile.owner == Main.myPlayer && ModContent.GetInstance <SoulConfig>().DeviChatter)
            {
                if (!Main.player[Projectile.owner].dead && !Main.player[Projectile.owner].ghost)
                {
                    EmoteBubble.MakeLocalPlayerEmote(EmoteID.EmotionLove);
                }
                SoundEngine.PlaySound(SoundID.LucyTheAxeTalk, Projectile.Center);

                string key       = Enum.GetName(talkType);
                int    actualSay = TalkCounters[talkInt] + 1;
                string text      = Language.GetTextValue($"Mods.FargowiltasSouls.DeviChatter.{key}{actualSay}");

                Vector2 pos = Vector2.Lerp(Main.MouseWorld, Projectile.Center, 0.5f);
                pos = Vector2.Lerp(pos, Main.player[Projectile.owner].Center, 0.5f);

                PopupText.NewText(new AdvancedPopupRequest()
                {
                    Text             = text,
                    DurationInFrames = 420,
                    Velocity         = 7 * -Vector2.UnitY,
                    Color            = Color.HotPink * 1.15f
                }, pos);

                //FargoSoulsUtil.HeartDust(
                //    Projectile.Center,
                //    addedVel: 0.5f * new Vector2(7 * Projectile.direction, -7),
                //    spreadModifier: 0.5f,
                //    scaleModifier: 0.5f
                //);
            }
        }
Ejemplo n.º 3
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)
            {
                const string Message = "Place an item here to Awesomeify";

                ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, FontAssets.MouseText.Value, Message, new Vector2(SlotX + 50, SlotY), new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor), 0f, Vector2.Zero, Vector2.One, -1f, 2f);
                return;
            }

            int    awesomePrice = Item.buyPrice(0, 1, 0, 0);
            string costText     = Language.GetTextValue("LegacyInterface.46") + ": ";

            int[] coins     = Utils.CoinsSplit(awesomePrice);
            var   coinsText = new StringBuilder();

            for (int i = 0; i < 4; i++)
            {
                coinsText.Append($"[c/{Colors.AlphaDarken(Colors.CoinPlatinum).Hex3()}:{coins[3 - i]} {Language.GetTextValue($"LegacyInterface.{15 + i}")}]");
            }

            ItemSlot.DrawSavings(Main.spriteBatch, SlotX + 130, Main.instance.invBottom, true);
            ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, FontAssets.MouseText.Value, 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, FontAssets.MouseText.Value, coinsText.ToString(), new Vector2(SlotX + 50 + FontAssets.MouseText.Value.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 = TextureAssets.Reforge[hoveringOverReforgeButton ? 1 : 0].Value;

            Main.spriteBatch.Draw(reforgeTexture, new Vector2(reforgeX, reforgeY), null, Color.White, 0f, reforgeTexture.Size() / 2f, 0.8f, SpriteEffects.None, 0f);

            if (!hoveringOverReforgeButton)
            {
                tickPlayed = false;
                return;
            }

            Main.hoverItemName = Language.GetTextValue("LegacyInterface.19");

            if (!tickPlayed)
            {
                SoundEngine.PlaySound(SoundID.MenuTick, -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))
            {
                return;
            }

            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(GetInstance <ExampleMod>().PrefixType("ReallyAwesome"));
            }
            else
            {
                reforgeItem.Prefix(GetInstance <ExampleMod>().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);
            PopupText.NewText(PopupTextContext.RegularItemPickup, _vanillaItemSlot.Item, _vanillaItemSlot.Item.stack, true, false);
            SoundEngine.PlaySound(SoundID.Item37, -1, -1);
        }
Ejemplo n.º 4
0
    public override bool OnPickup(Item item, Player player)
    {
        if (_ignored.Contains(item.type))
        {
            return(true);
        }

        if (item.ModItem?.ItemSpace(player) == true)
        {
            return(true);
        }

        // player.inventory [59]
        // 0-9 hotbar
        // 10-49 are actual inventory
        // 50-53 coins
        // 54-57 ammo
        // 58 mouse ???
        void TextAndSound(int stack)
        {
            PopupText.NewText(PopupTextContext.RegularItemPickup, item, stack);
            SoundEngine.PlaySound(SoundID.Grab, player.position);
        }

        bool Pickup(int from, int to, int emptySlot)
        {
            // check inventory and hotbar for item to stack into
            for (int i = from; i < to; i++)
            {
                Item invItem = player.inventory[i];

                if (invItem.type != item.type)
                {
                    continue;
                }

                if (invItem.stack == invItem.maxStack)
                {
                    continue;
                }

                if (invItem.maxStack == 1)                 // item doesn't stack
                {
                    if (emptySlot == -1)
                    {
                        return(true);
                    }

                    player.inventory[emptySlot] = item;
                    TextAndSound(item.stack);
                }
                else if (invItem.stack + item.stack > invItem.maxStack)
                {
                    // item can stack, but stack + existing.stack > maxStack
                    // add what can be added to existing
                    int origStack = item.stack;
                    item.stack   -= invItem.maxStack - invItem.stack;
                    invItem.stack = invItem.maxStack;
                    // add new item using remainder (if there's a spot for it)
                    if (emptySlot != -1)
                    {
                        player.inventory[emptySlot] = item;
                        TextAndSound(origStack);
                    }
                    else
                    {
                        player.QuickSpawnClonedItem(item, item.stack);
                        TextAndSound(origStack - item.stack);
                    }
                }
                else
                {
                    // item can stack
                    invItem.stack += item.stack;
                    TextAndSound(item.stack);
                }

                // item has been picked up
                return(true);
            }

            // item not in inventory
            return(false);
        }

        if (_ammo.Contains(item.ammo) || item.shoot != ItemID.None)
        {
            int firstEmptyAmmoSlot = -1;

            for (int i = 54; i < 58; i++)
            {
                if (player.inventory[i].type == ItemID.None)
                {
                    firstEmptyAmmoSlot = i;
                    break;
                }
            }

            if (Pickup(54, 58, firstEmptyAmmoSlot))
            {
                return(false);
            }
        }

        // find open slot based on config option 'PickupDirection'
        (int start, int end, int step) = NoHotbarPickupConfig.PickupDirection ? (49, 10, -1) : (10, 49, 1);
        int firstEmptySlot = -1;

        for (int i = start; i != end; i += step)
        {
            if (player.inventory[i].type == ItemID.None)
            {
                firstEmptySlot = i;
                break;
            }
        }

        if (firstEmptySlot == -1 && NoHotbarPickupConfig.HotbarWhenFull)
        {
            for (int i = 0; i < 10; i++)
            {
                if (player.inventory[i].type == ItemID.None)
                {
                    firstEmptySlot = i;
                    break;
                }
            }
        }

        if (Pickup(0, 50, firstEmptySlot))
        {
            return(false);
        }

        if (firstEmptySlot == -1)
        {
            return(false);
        }

        player.inventory[firstEmptySlot] = item;
        TextAndSound(item.stack);

        return(false);
    }