public override void Click(UIMouseEvent evt)
        {
            base.Click(evt);

            if (CanInteract?.Invoke(Item, Main.mouseItem) ?? true)
            {
                Item.newAndShiny = false;
                Player player = Main.LocalPlayer;

                if (ItemSlot.ShiftInUse)
                {
                    Main.NewText("move to inventory");
                    return;
                }

                Item temp = Item;
                Utils.Swap(ref temp, ref Main.mouseItem);
                Item = temp;

                if (Item.stack > 0)
                {
                    AchievementsHelper.NotifyItemPickup(player, Item);
                }
                if (Item.type == 0 || Item.stack < 1)
                {
                    Item = new Item();
                }
                if (Main.mouseItem.IsTheSameAs(Item))
                {
                    Utils.Swap(ref Item.favorited, ref Main.mouseItem.favorited);
                    if (Item.stack != Item.maxStack && Main.mouseItem.stack != Main.mouseItem.maxStack)
                    {
                        if (Main.mouseItem.stack + Item.stack <= Main.mouseItem.maxStack)
                        {
                            Item.stack          += Main.mouseItem.stack;
                            Main.mouseItem.stack = 0;
                        }
                        else
                        {
                            int delta = Main.mouseItem.maxStack - Item.stack;
                            Item.stack           += delta;
                            Main.mouseItem.stack -= delta;
                        }
                    }
                }
                if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1)
                {
                    Main.mouseItem = new Item();
                }
                if (Main.mouseItem.type > 0 || Item.type > 0)
                {
                    Terraria.Recipe.FindRecipes();
                    Main.PlaySound(7);
                }

                OnInteract?.Invoke();
            }

            SendUpdate();
        }
Beispiel #2
0
 public void RemoveInteractable(CanInteract canInteract)
 {
     if (_control.CurrentInteractables.Contains(canInteract))
     {
         _control.CurrentInteractables.Remove(canInteract);
     }
 }
Beispiel #3
0
    public void AddInteractable(CanInteract canInteract)
    {
        if (!_control.CurrentInteractables.Contains(canInteract))
        {
            _control.CurrentInteractables.Add(canInteract);
        }

    }
        public void RightMouseDownCont()
        {
            if (CanInteract?.Invoke(Item, Main.mouseItem) ?? true)
            {
                OnInteract?.Invoke();

                Player player = Main.LocalPlayer;
                Item.newAndShiny = false;

                if (player.itemAnimation > 0)
                {
                    return;
                }

                bool specialClick = false;
                if (ItemLoader.CanRightClick(Item))
                {
                    ItemLoader.RightClick(Item, player);
                    specialClick = true;
                    SendUpdate();
                }

                if (specialClick)
                {
                    return;
                }

                if (Item.maxStack == 1 && Main.mouseRight && Main.mouseRightRelease)
                {
                    if (Item.dye > 0)
                    {
                        object[] param = { Item, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("DyeSwap", param);

                        if ((bool)param[1])
                        {
                            Main.EquipPageSelected = 0;
                            AchievementsHelper.HandleOnEquip(player, Item, 12);
                        }
                    }
                    else if (Main.projHook[Item.shoot])
                    {
                        object[] param = { Item, player.miscEquips, 4, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("EquipSwap", param);

                        if ((bool)param[3])
                        {
                            Main.EquipPageSelected = 2;
                            AchievementsHelper.HandleOnEquip(player, Item, 16);
                        }
                    }
                    else if (Item.mountType != -1 && !MountID.Sets.Cart[Item.mountType])
                    {
                        object[] param = { Item, player.miscEquips, 3, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("EquipSwap", param);

                        if ((bool)param[3])
                        {
                            Main.EquipPageSelected = 2;
                            AchievementsHelper.HandleOnEquip(player, Item, 17);
                        }
                    }
                    else if (Item.mountType != -1 && MountID.Sets.Cart[Item.mountType])
                    {
                        object[] param = { Item, player.miscEquips, 2, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("EquipSwap", param);

                        if ((bool)param[3])
                        {
                            Main.EquipPageSelected = 2;
                        }
                    }
                    else if (Item.buffType > 0 && Main.lightPet[Item.buffType])
                    {
                        object[] param = { Item, player.miscEquips, 1, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("EquipSwap", param);

                        if ((bool)param[3])
                        {
                            Main.EquipPageSelected = 2;
                        }
                    }
                    else if (Item.buffType > 0 && Main.vanityPet[Item.buffType])
                    {
                        object[] param = { Item, player.miscEquips, 0, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("EquipSwap", param);

                        if ((bool)param[3])
                        {
                            Main.EquipPageSelected = 2;
                        }
                    }
                    else
                    {
                        Item     item1 = Item;
                        object[] param = { Item, false };
                        Item = typeof(ItemSlot).InvokeMethod <Item>("ArmorSwap", param);

                        if ((bool)param[1])
                        {
                            Main.EquipPageSelected = 0;
                            AchievementsHelper.HandleOnEquip(player, item1, item1.accessory ? 10 : 8);
                        }
                    }
                    Terraria.Recipe.FindRecipes();

                    return;
                }

                if (Main.stackSplit <= 1 && Main.mouseRight)
                {
                    if (Item.maxStack > 1 && (Main.mouseItem.IsTheSameAs(Item) || Main.mouseItem.type == 0) && (Main.mouseItem.stack < Main.mouseItem.maxStack || Main.mouseItem.type == 0))
                    {
                        if (Main.mouseItem.type == 0)
                        {
                            Main.mouseItem       = Item.Clone();
                            Main.mouseItem.stack = 0;
                            if (Item.favorited && Item.maxStack == 1)
                            {
                                Main.mouseItem.favorited = true;
                            }
                            Main.mouseItem.favorited = false;
                        }
                        Main.mouseItem.stack++;
                        Item.stack--;
                        if (Item.stack <= 0)
                        {
                            Item = new Item();
                        }

                        Terraria.Recipe.FindRecipes();

                        Main.soundInstanceMenuTick.Stop();
                        Main.soundInstanceMenuTick = Main.soundMenuTick.CreateInstance();
                        Main.PlaySound(12);

                        Main.stackSplit = Main.stackSplit == 0 ? 15 : Main.stackDelay;
                    }

                    SendUpdate();
                }
            }
        }
Beispiel #5
0
 public void RemoveFromInteractables(CanInteract canInteract)
 {
     _player.RemoveInteractable(canInteract);
 }
Beispiel #6
0
 public void AddToInteractables(CanInteract canInteract)
 {
     _player.AddInteractable(canInteract);
 }