public static void SellOrTrash(Item[] inv, int context, int slot) { Player player = Main.player[Main.myPlayer]; if (inv[slot].type <= 0) { return; } if (Main.npcShop > 0 && !inv[slot].favorited) { Chest chest = Main.instance.shop[Main.npcShop]; if (inv[slot].type < ItemID.CopperCoin || (inv[slot].type > ItemID.PlatinumCoin && PlayerHooks.CanSellItem(player, Main.npc[player.talkNPC], chest.item, inv[slot]))) { if (player.SellItem(inv[slot].value, inv[slot].stack)) { int num = chest.AddShop(inv[slot]); inv[slot].SetDefaults(0, false); Main.PlaySound(18, -1, -1, 1, 1f, 0f); Recipe.FindRecipes(); PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[num]); return; } if (inv[slot].value == 0) { int num2 = chest.AddShop(inv[slot]); inv[slot].SetDefaults(0, false); Main.PlaySound(7, -1, -1, 1, 1f, 0f); Recipe.FindRecipes(); PlayerHooks.PostSellItem(player, Main.npc[player.talkNPC], chest.item, chest.item[num2]); return; } } } else if (!inv[slot].favorited && !ItemSlot.Options.DisableLeftShiftTrashCan) { Main.PlaySound(7, -1, -1, 1, 1f, 0f); player.trashItem = inv[slot].Clone(); inv[slot].SetDefaults(0, false); if (context == 3 && Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.SyncChestItem, -1, -1, null, player.chest, (float)slot, 0f, 0f, 0, 0, 0); } Recipe.FindRecipes(); } }
//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; } } } }
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; } } }