Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ArmorSwap()

static Item Terraria.UI.ItemSlot.ArmorSwap ( Item item,
out bool success )
inlinestaticprivate

Definition at line 2730 of file ItemSlot.cs.

2731 {
2732 success = false;
2733 if (item.stack < 1)
2734 {
2735 return item;
2736 }
2737 if (item.headSlot == -1 && item.bodySlot == -1 && item.legSlot == -1 && !item.accessory)
2738 {
2739 return item;
2740 }
2741 Player player = Main.player[Main.myPlayer];
2742 int num = ((item.vanity && !item.accessory) ? 10 : 0);
2743 item.favorited = false;
2744 Item result = item;
2745 if (item.headSlot != -1)
2746 {
2747 result = player.armor[num].Clone();
2748 player.armor[num] = item.Clone();
2749 }
2750 else if (item.bodySlot != -1)
2751 {
2752 result = player.armor[num + 1].Clone();
2753 player.armor[num + 1] = item.Clone();
2754 }
2755 else if (item.legSlot != -1)
2756 {
2757 result = player.armor[num + 2].Clone();
2758 player.armor[num + 2] = item.Clone();
2759 }
2760 else if (item.accessory)
2761 {
2762 int num2 = 3;
2763 for (int i = 3; i < 10; i++)
2764 {
2765 if (player.IsItemSlotUnlockedAndUsable(i))
2766 {
2767 num2 = i;
2768 if (player.armor[i].type == 0)
2769 {
2770 accSlotToSwapTo = i - 3;
2771 break;
2772 }
2773 }
2774 }
2775 for (int j = 0; j < player.armor.Length; j++)
2776 {
2777 if (item.IsTheSameAs(player.armor[j]))
2778 {
2779 accSlotToSwapTo = j - 3;
2780 }
2781 if (j < 10 && item.wingSlot > 0 && player.armor[j].wingSlot > 0)
2782 {
2783 accSlotToSwapTo = j - 3;
2784 }
2785 }
2786 if (accSlotToSwapTo > num2)
2787 {
2788 return item;
2789 }
2790 if (accSlotToSwapTo < 0)
2791 {
2792 accSlotToSwapTo = num2 - 3;
2793 }
2794 int num3 = 3 + accSlotToSwapTo;
2795 if (isEquipLocked(player.armor[num3].type))
2796 {
2797 return item;
2798 }
2799 for (int k = 0; k < player.armor.Length; k++)
2800 {
2801 if (item.IsTheSameAs(player.armor[k]))
2802 {
2803 num3 = k;
2804 }
2805 }
2806 result = player.armor[num3].Clone();
2807 player.armor[num3] = item.Clone();
2808 accSlotToSwapTo = 0;
2809 }
2811 Recipe.FindRecipes();
2812 success = true;
2813 return result;
2814 }
static void PlaySound(int type, Vector2 position, int style=1)
static bool isEquipLocked(int type)
Definition ItemSlot.cs:329
static int accSlotToSwapTo
Definition ItemSlot.cs:155

References Terraria.UI.ItemSlot.accSlotToSwapTo, Terraria.Player.armor, Terraria.Item.Clone(), Terraria.Recipe.FindRecipes(), Terraria.UI.ItemSlot.isEquipLocked(), Terraria.Player.IsItemSlotUnlockedAndUsable(), System.item, Terraria.Main.myPlayer, Terraria.Main.player, Terraria.Audio.SoundEngine.PlaySound(), Terraria.Item.type, and Terraria.Item.wingSlot.

Referenced by Terraria.UI.ItemSlot.SwapEquip().