public static void SwapEquip(ref Item item) { item = ArmorSwap(item, out bool flag); if (flag) { Main.EquipPageSelected = 0; AchievementsHelper.HandleOnEquip(Main.player[Main.myPlayer], item, item.accessory ? 10 : 8); } Recipe.FindRecipes(); }
public override void OnLeftClick() { if (Main.mouseItem.stack == 1 && Main.mouseItem.dye > 0 && Item.type > 0 && Item.type != Main.mouseItem.type) { Utils.Swap <Item>(ref item, ref Main.mouseItem); Main.PlaySound(7, -1, -1, 1, 1f, 0f); if (Item.stack > 0) { AchievementsHelper.HandleOnEquip(Main.LocalPlayer, Item, 12); } } else if (Main.mouseItem.type == 0 && Item.type > 0) { Utils.Swap <Item>(ref item, ref Main.mouseItem); if (Item.type == 0 || Item.stack < 1) { Item = new Item(); } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || Item.type > 0) { Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } else if (Main.mouseItem.dye > 0 && Item.type == 0) { if (Main.mouseItem.stack == 1) { Utils.Swap <Item>(ref item, ref Main.mouseItem); if (Item.type == 0 || Item.stack < 1) { Item = new Item(); } if (Main.mouseItem.type == 0 || Main.mouseItem.stack < 1) { Main.mouseItem = new Item(); } if (Main.mouseItem.type > 0 || Item.type > 0) { Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } } else { Main.mouseItem.stack--; Item.SetDefaults(Main.mouseItem.type, false); Recipe.FindRecipes(); Main.PlaySound(7, -1, -1, 1, 1f, 0f); } if (Item.stack > 0) { AchievementsHelper.HandleOnEquip(Main.LocalPlayer, Item, 12); } } Item.favorited = false; }
//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; } } } }
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(); } } }
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; } } }