Exemple #1
0
 private static Item ArmorSwap(Item item, out bool success)
 {
     success = false;
     if (item.headSlot == -1 && item.bodySlot == -1 && item.legSlot == -1 && !item.accessory)
     {
         return item;
     }
     Player player = Main.player[Main.myPlayer];
     int num = (item.vanity && !item.accessory) ? 10 : 0;
     item.favorited = false;
     Item result = item;
     if (item.headSlot != -1)
     {
         result = player.armor[num].Clone();
         player.armor[num] = item.Clone();
     }
     else if (item.bodySlot != -1)
     {
         result = player.armor[num + 1].Clone();
         player.armor[num + 1] = item.Clone();
     }
     else if (item.legSlot != -1)
     {
         result = player.armor[num + 2].Clone();
         player.armor[num + 2] = item.Clone();
     }
     else if (item.accessory)
     {
         int num2 = 5 + Main.player[Main.myPlayer].extraAccessorySlots;
         for (int i = 3; i < 3 + num2; i++)
         {
             if (player.armor[i].type == 0)
             {
                 ItemSlot.accSlotCount = i - 3;
                 break;
             }
         }
         for (int j = 0; j < player.armor.Length; j++)
         {
             if (item.IsTheSameAs(player.armor[j]))
             {
                 ItemSlot.accSlotCount = j - 3;
             }
             if (j < 10 && item.wingSlot > 0 && player.armor[j].wingSlot > 0)
             {
                 ItemSlot.accSlotCount = j - 3;
             }
         }
         if (ItemSlot.accSlotCount >= num2)
         {
             ItemSlot.accSlotCount = 0;
         }
         if (ItemSlot.accSlotCount < 0)
         {
             ItemSlot.accSlotCount = num2 - 1;
         }
         int num3 = 3 + ItemSlot.accSlotCount;
         for (int k = 0; k < player.armor.Length; k++)
         {
             if (item.IsTheSameAs(player.armor[k]))
             {
                 num3 = k;
             }
         }
         result = player.armor[num3].Clone();
         player.armor[num3] = item.Clone();
         ItemSlot.accSlotCount++;
         if (ItemSlot.accSlotCount >= num2)
         {
             ItemSlot.accSlotCount = 0;
         }
     }
     Main.PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     success = true;
     return result;
 }
        // Modded version of Terraria's Original
        private Item PutItemInNearbyChest(TSPlayer player, Item item, Vector2 position)
        {
            float quickStackRange = this.Config.QuickStackNearbyRange * 16;

              for (int i = 0; i < Main.chest.Length; i++) {
            Chest chest = Main.chest[i];
            if (chest == null || !Main.tile[chest.x, chest.y].active())
              continue;

            bool containsSameItem = false;
            bool hasEmptySlot = false;

            bool isPlayerInChest = false;
            for (int j = 0; j < 255; j++) {
              if (Main.player[j].chest == i) {
            isPlayerInChest = true;
            break;
              }
            }

            if (!isPlayerInChest && !Chest.isLocked(chest.x, chest.y)) {
              Vector2 vector2 = new Vector2((chest.x * 16 + 16), (chest.y * 16 + 16));
              if ((vector2 - position).Length() < quickStackRange) {
            ProtectionEntry protection;
            if (this.ProtectionManager.CheckBlockAccess(player, new DPoint(chest.x, chest.y), false, out protection)) {
              bool isRefillChest = (protection != null && protection.RefillChestData != null);
              if (!isRefillChest) {
                bool isBankChest = (protection != null && protection.BankChestKey != BankChestDataKey.Invalid);

                for (int j = 0; j < chest.item.Length; j++) {
                  Item chestItem = chest.item[j];
                  if (chestItem.type <= 0 || chestItem.stack <= 0)
                    hasEmptySlot = true;
                  else if (item.IsTheSameAs(chestItem)) {
                    containsSameItem = true;
                    int stackLeft = chestItem.maxStack - chestItem.stack;
                    if (stackLeft > 0) {
                      if (stackLeft > item.stack)
                        stackLeft = item.stack;

                      item.stack = item.stack - stackLeft;
                      chestItem.stack = chestItem.stack + stackLeft;
                      if (isBankChest)
                        this.ServerMetadataHandler.EnqueueUpdateBankChestItem(protection.BankChestKey, j, ItemData.FromItem(chestItem));

                      if (item.stack <= 0) {
                        item.SetDefaults();
                        return item;
                      }
                    }
                  }
                }
                if (containsSameItem && hasEmptySlot && item.stack > 0) {
                  for (int k = 0; k < chest.item.Length; k++) {
                    Item chestItem = chest.item[k];
                    if (chestItem.type == 0 || chestItem.stack == 0) {
                      chest.item[k] = item.Clone();

                      if (isBankChest)
                        this.ServerMetadataHandler.EnqueueUpdateBankChestItem(protection.BankChestKey, k, ItemData.FromItem(item));

                      item.SetDefaults();
                      return item;
                    }
                  }
                }
              }
            }
              }
            }
              }
              return item;
        }
Exemple #3
0
 private static bool AccCheck(Item item, int slot)
 {
     Player player = Main.player[Main.myPlayer];
     if (slot != -1)
     {
         if (player.armor[slot].IsTheSameAs(item))
         {
             return false;
         }
         if (player.armor[slot].wingSlot > 0 && item.wingSlot > 0)
         {
             return false;
         }
     }
     for (int i = 0; i < player.armor.Length; i++)
     {
         if (slot < 10 && i < 10)
         {
             if (item.wingSlot > 0 && player.armor[i].wingSlot > 0)
             {
                 return true;
             }
             if (slot >= 10 && i >= 10 && item.wingSlot > 0 && player.armor[i].wingSlot > 0)
             {
                 return true;
             }
         }
         if (item.IsTheSameAs(player.armor[i]))
         {
             return true;
         }
     }
     return false;
 }
		public static bool TryPlacingInChest(Item I, bool justCheck)
		{
			bool flag = false;
			Player player = Main.player[Main.myPlayer];
			Item[] item = player.bank.item;
			if (player.chest > -1)
			{
				item = Main.chest[player.chest].item;
				flag = (Main.netMode == 1);
			}
			else if (player.chest == -2)
			{
				item = player.bank.item;
			}
			else if (player.chest == -3)
			{
				item = player.bank2.item;
			}
			bool flag2 = false;
			if (I.maxStack > 1)
			{
				for (int i = 0; i < 40; i++)
				{
					if (item[i].stack < item[i].maxStack && I.IsTheSameAs(item[i]))
					{
						int num = I.stack;
						if (I.stack + item[i].stack > item[i].maxStack)
						{
							num = item[i].maxStack - item[i].stack;
						}
						if (justCheck)
						{
							flag2 = (flag2 || num > 0);
							break;
						}
						I.stack -= num;
						item[i].stack += num;
						Main.PlaySound(7, -1, -1, 1);
						if (I.stack <= 0)
						{
							I.SetDefaults(0, false);
							if (flag)
							{
								NetMessage.SendData(32, -1, -1, "", player.chest, (float)i, 0f, 0f, 0, 0, 0);
								break;
							}
							break;
						}
						else
						{
							if (item[i].type == 0)
							{
								item[i] = I.Clone();
								I.SetDefaults(0, false);
							}
							if (flag)
							{
								NetMessage.SendData(32, -1, -1, "", player.chest, (float)i, 0f, 0f, 0, 0, 0);
							}
						}
					}
				}
			}
			if (I.stack > 0)
			{
				int j = 0;
				while (j < 40)
				{
					if (item[j].stack == 0)
					{
						if (justCheck)
						{
							flag2 = true;
							break;
						}
						Main.PlaySound(7, -1, -1, 1);
						item[j] = I.Clone();
						I.SetDefaults(0, false);
						if (flag)
						{
							NetMessage.SendData(32, -1, -1, "", player.chest, (float)j, 0f, 0f, 0, 0, 0);
							break;
						}
						break;
					}
					else
					{
						j++;
					}
				}
			}
			return flag2;
		}