예제 #1
0
파일: ItemSlot.cs 프로젝트: MEFBAEA/mefbaea
 private static Item EquipSwap(Item item, Item[] inv, int slot, out bool success)
 {
     success = false;
     Player arg_0E_0 = Main.player[Main.myPlayer];
     item.favorited = false;
     Item result = inv[slot].Clone();
     inv[slot] = item.Clone();
     Main.PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     success = true;
     return result;
 }
예제 #2
0
            /**
             * traverse upwards
             */
            private int Up() {
                Item i = new Item();
                int res = 0;

                if (ns.Count == 0)
                    return -1;

                if (cur != 0 && parent.sc[cur] == 0)
                    return parent.lo[cur];

                bool climb = true;

                while (climb) {
                    i = (Item)ns.Pop();
                    i.child++;
                    switch (i.child) {
                        case (char)1:
                            if (parent.sc[i.parent] != 0) {
                                res = parent.eq[i.parent];
                                ns.Push(i.Clone());
                                ks.Append(parent.sc[i.parent]);
                            } else {
                                i.child++;
                                ns.Push(i.Clone());
                                res = parent.hi[i.parent];
                            }
                            climb = false;
                            break;

                        case (char)2:
                            res = parent.hi[i.parent];
                            ns.Push(i.Clone());
                            if (ks.Length > 0)
                                ks.Length = ks.Length - 1;    // pop
                            climb = false;
                            break;

                        default:
                            if (ns.Count == 0)
                                return -1;
                            climb = true;
                            break;
                    }
                }
                return res;
            }
예제 #3
0
파일: ItemSlot.cs 프로젝트: MEFBAEA/mefbaea
 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;
 }
예제 #4
0
파일: ItemSlot.cs 프로젝트: MEFBAEA/mefbaea
 private static Item DyeSwap(Item item, out bool success)
 {
     success = false;
     if (item.dye <= 0)
     {
         return item;
     }
     Player player = Main.player[Main.myPlayer];
     for (int i = 0; i < 10; i++)
     {
         if (player.dye[i].type == 0)
         {
             ItemSlot.dyeSlotCount = i;
             break;
         }
     }
     if (ItemSlot.dyeSlotCount >= 10)
     {
         ItemSlot.dyeSlotCount = 0;
     }
     if (ItemSlot.dyeSlotCount < 0)
     {
         ItemSlot.dyeSlotCount = 9;
     }
     Item result = player.dye[ItemSlot.dyeSlotCount].Clone();
     player.dye[ItemSlot.dyeSlotCount] = item.Clone();
     ItemSlot.dyeSlotCount++;
     if (ItemSlot.dyeSlotCount >= 10)
     {
         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;
        }
        private Item AdjustWeaponSpeed(Item weapon, float speed)
        {
            Item adjustedWeapon = weapon.Clone();

            adjustedWeapon.MinDamage = (int)Math.Round(weapon.MinDamage / weapon.Speed * speed);
            adjustedWeapon.MaxDamage = (int)Math.Round(weapon.MaxDamage / weapon.Speed * speed);
            adjustedWeapon.Speed = speed;

            return adjustedWeapon;
        }
		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;
		}
예제 #8
0
 /// <summary>
 /// Copies an <paramref name="item"/> to the clipboard.
 /// </summary>
 /// <param name="item">An <see cref="Item"/> to copy.</param>
 /// <remarks>Invoked by the 'Copy' menu item.</remarks>
 protected virtual void OnCopyItem(Item item)
 {
     if (item == null) {
         throw new ArgumentNullException("item");
     }
     IDataObject dataObject = new DataObject(ClipboardFormat.Item, item.Clone());
     Clipboard.SetDataObject(dataObject, false);
 }
예제 #9
0
 /// <summary>
 /// Creates a new instance of the ItemContainer class
 /// </summary>
 /// <param name="i">Sets the ContainedItem field</param>
 public ItemContainer(Item i)
     : this()
 {
     ContainedItem = (Item)i.Clone();
 }