当前位置: 首页>>代码示例>>C#>>正文


C# Item.Clone方法代码示例

本文整理汇总了C#中Terraria.Item.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Item.Clone方法的具体用法?C# Item.Clone怎么用?C# Item.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Terraria.Item的用法示例。


在下文中一共展示了Item.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetItemsPrefixes

        private static Item[] GetItemsPrefixes(Item item)
        {
            var items = new List<Item>();
            for (int i = 0; i < Lang.prefix.Length; i++)
            {
                var prefixedItem = item.Clone();
                prefixedItem.SetDefaults(item.type);
                prefixedItem.Prefix(i);

                var prefixAlreadyAdded = (from existingItem in items
                                          where existingItem.prefix == prefixedItem.prefix
                                          select existingItem).Count() > 0;
                if (prefixedItem.prefix > 0 && !prefixAlreadyAdded)
                    items.Add(prefixedItem);
            }

            return items.OrderBy(it => -it.rare).ThenBy(it=> Lang.prefix[it.prefix]).ToArray();
        }
开发者ID:chatrat12,项目名称:Prism,代码行数:18,代码来源:PrefixEditor.cs

示例2: AddShop

		public void AddShop(Item newItem)
		{
			int i = 0;
			while (i < 39)
			{
				if (this.item[i] == null || this.item[i].type == 0)
				{
					this.item[i] = newItem.Clone();
					this.item[i].buyOnce = true;
					if (this.item[i].value <= 0)
					{
						break;
					}
					this.item[i].value = this.item[i].value / 5;
					if (this.item[i].value < 1)
					{
						this.item[i].value = 1;
						return;
					}
					break;
				}
				else
				{
					i++;
				}
			}
		}
开发者ID:vito19,项目名称:TerrariaAPI-Server,代码行数:27,代码来源:Chest.cs

示例3: TryPlacingInChest

 public static bool TryPlacingInChest(Item I, bool justCheck)
 {
     bool flag1 = false;
     Player player = Main.player[Main.myPlayer];
     Item[] objArray = player.bank.item;
     if (player.chest > -1)
     {
         objArray = Main.chest[player.chest].item;
         flag1 = Main.netMode == 1;
     }
     else if (player.chest == -2)
         objArray = player.bank.item;
     else if (player.chest == -3)
         objArray = player.bank2.item;
     bool flag2 = false;
     if (I.maxStack > 1)
     {
         for (int index = 0; index < 40; ++index)
         {
             if (objArray[index].stack < objArray[index].maxStack && I.IsTheSameAs(objArray[index]))
             {
                 int num = I.stack;
                 if (I.stack + objArray[index].stack > objArray[index].maxStack)
                     num = objArray[index].maxStack - objArray[index].stack;
                 if (justCheck)
                 {
                     flag2 = flag2 || num > 0;
                     break;
                 }
                 I.stack -= num;
                 objArray[index].stack += num;
                 Main.PlaySound(7, -1, -1, 1);
                 if (I.stack <= 0)
                 {
                     I.SetDefaults(0, false);
                     if (flag1)
                     {
                         NetMessage.SendData(32, -1, -1, "", player.chest, (float)index, 0.0f, 0.0f, 0, 0, 0);
                         break;
                     }
                     break;
                 }
                 if (objArray[index].itemId == 0)
                 {
                     objArray[index] = I.Clone();
                     I.SetDefaults(0, false);
                 }
                 if (flag1)
                     NetMessage.SendData(32, -1, -1, "", player.chest, (float)index, 0.0f, 0.0f, 0, 0, 0);
             }
         }
     }
     if (I.stack > 0)
     {
         for (int index = 0; index < 40; ++index)
         {
             if (objArray[index].stack == 0)
             {
                 if (justCheck)
                 {
                     flag2 = true;
                     break;
                 }
                 Main.PlaySound(7, -1, -1, 1);
                 objArray[index] = I.Clone();
                 I.SetDefaults(0, false);
                 if (flag1)
                 {
                     NetMessage.SendData(32, -1, -1, "", player.chest, (float)index, 0.0f, 0.0f, 0, 0, 0);
                     break;
                 }
                 break;
             }
         }
     }
     return flag2;
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:77,代码来源:ChestUI.cs

示例4: armorSwap

 public static Item armorSwap(Item newItem)
 {
     for (int i = 0; i < Main.player[Main.myPlayer].armor.Length; i++)
     {
         if (newItem.IsTheSameAs(Main.player[Main.myPlayer].armor[i]))
         {
             Main.accSlotCount = i;
         }
     }
     if (newItem.headSlot == -1 && newItem.bodySlot == -1 && newItem.legSlot == -1 && !newItem.accessory)
     {
         return newItem;
     }
     Item result = newItem;
     if (newItem.headSlot != -1)
     {
         result = (Item) Main.player[Main.myPlayer].armor[0].Clone();
         Main.player[Main.myPlayer].armor[0] = (Item) newItem.Clone();
     }
     else
     {
         if (newItem.bodySlot != -1)
         {
             result = (Item) Main.player[Main.myPlayer].armor[1].Clone();
             Main.player[Main.myPlayer].armor[1] = (Item) newItem.Clone();
         }
         else
         {
             if (newItem.legSlot != -1)
             {
                 result = (Item) Main.player[Main.myPlayer].armor[2].Clone();
                 Main.player[Main.myPlayer].armor[2] = (Item) newItem.Clone();
             }
             else
             {
                 if (newItem.accessory)
                 {
                     for (int j = 3; j < 8; j++)
                     {
                         if (Main.player[Main.myPlayer].armor[j].type == 0)
                         {
                             Main.accSlotCount = j - 3;
                             break;
                         }
                     }
                     for (int k = 0; k < Main.player[Main.myPlayer].armor.Length; k++)
                     {
                         if (newItem.IsTheSameAs(Main.player[Main.myPlayer].armor[k]))
                         {
                             Main.accSlotCount = k - 3;
                         }
                     }
                     if (Main.accSlotCount >= 5)
                     {
                         Main.accSlotCount = 0;
                     }
                     if (Main.accSlotCount < 0)
                     {
                         Main.accSlotCount = 4;
                     }
                     result = (Item) Main.player[Main.myPlayer].armor[3 + Main.accSlotCount].Clone();
                     Main.player[Main.myPlayer].armor[3 + Main.accSlotCount] = (Item) newItem.Clone();
                     Main.accSlotCount++;
                     if (Main.accSlotCount >= 5)
                     {
                         Main.accSlotCount = 0;
                     }
                 }
             }
         }
     }
     Main.PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     return result;
 }
开发者ID:RogerPaladin,项目名称:TerrariaAPI-Server,代码行数:75,代码来源:Main.cs

示例5: armorSwap

 public static Item armorSwap(Item newItem)
 {
     for (int i = 0; i < player[myPlayer].armor.Length; i++)
     {
         if (newItem.IsTheSameAs(player[myPlayer].armor[i]))
         {
             accSlotCount = i;
         }
     }
     if (((newItem.headSlot == -1) && (newItem.bodySlot == -1)) && ((newItem.legSlot == -1) && !newItem.accessory))
     {
         return newItem;
     }
     Item item = newItem;
     if (newItem.headSlot != -1)
     {
         item = (Item)player[myPlayer].armor[0].Clone();
         player[myPlayer].armor[0] = (Item)newItem.Clone();
     }
     else if (newItem.bodySlot != -1)
     {
         item = (Item)player[myPlayer].armor[1].Clone();
         player[myPlayer].armor[1] = (Item)newItem.Clone();
     }
     else if (newItem.legSlot != -1)
     {
         item = (Item)player[myPlayer].armor[2].Clone();
         player[myPlayer].armor[2] = (Item)newItem.Clone();
     }
     else if (newItem.accessory)
     {
         for (int j = 3; j < 8; j++)
         {
             if (player[myPlayer].armor[j].type == 0)
             {
                 accSlotCount = j - 3;
                 break;
             }
         }
         for (int k = 0; k < player[myPlayer].armor.Length; k++)
         {
             if (newItem.IsTheSameAs(player[myPlayer].armor[k]))
             {
                 accSlotCount = k - 3;
             }
         }
         if (accSlotCount >= 5)
         {
             accSlotCount = 0;
         }
         if (accSlotCount < 0)
         {
             accSlotCount = 4;
         }
         item = (Item)player[myPlayer].armor[3 + accSlotCount].Clone();
         player[myPlayer].armor[3 + accSlotCount] = (Item)newItem.Clone();
         accSlotCount++;
         if (accSlotCount >= 5)
         {
             accSlotCount = 0;
         }
     }
     PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     return item;
 }
开发者ID:Heloo88,项目名称:ModTerraria_Heloo,代码行数:66,代码来源:Main.cs

示例6: dyeSwap

 public static Item dyeSwap(Item newItem)
 {
     if (newItem.dye <= 0)
     {
         return newItem;
     }
     for (int i = 0; i < 3; i++)
     {
         if (Main.player[Main.myPlayer].dye[i].type == 0)
         {
             Main.dyeSlotCount = i;
             break;
         }
     }
     if (Main.dyeSlotCount >= 3)
     {
         Main.dyeSlotCount = 0;
     }
     if (Main.dyeSlotCount < 0)
     {
         Main.dyeSlotCount = 2;
     }
     Item result = (Item)Main.player[Main.myPlayer].dye[Main.dyeSlotCount].Clone();
     Main.player[Main.myPlayer].dye[Main.dyeSlotCount] = (Item)newItem.Clone();
     Main.dyeSlotCount++;
     if (Main.dyeSlotCount >= 3)
     {
         Main.accSlotCount = 0;
     }
     Main.PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     return result;
 }
开发者ID:brianmcmichael,项目名称:Terraria-Source-Code,代码行数:33,代码来源:Main.cs

示例7: AddShop

 public void AddShop(Item newItem)
 {
     int num = 0;
     while (num < 39)
     {
         if (this.item[num] == null || this.item[num].type == 0)
         {
             this.item[num] = newItem.Clone();
             this.item[num].favorited = false;
             this.item[num].buyOnce = true;
             if (this.item[num][email protected] <= 0)
             {
                 break;
             }
             this.item[num][email protected] = this.item[num][email protected] / 5;
             if (this.item[num][email protected] >= 1)
             {
                 break;
             }
             this.item[num][email protected] = 1;
             return;
         }
         else
         {
             num++;
         }
     }
 }
开发者ID:hastinbe,项目名称:TerrariaAPI-Server,代码行数:28,代码来源:Chest.cs

示例8: PutItemInNearbyChest

 public static Item PutItemInNearbyChest(Item item, Vector2 position)
 {
     if (Main.netMode == 1)
     {
         return item;
     }
     for (int i = 0; i < 1000; i++)
     {
         bool flag = false;
         bool flag1 = false;
         if (Main.chest[i] != null && !Chest.IsPlayerInChest(i) && !Chest.isLocked(Main.chest[i].x, Main.chest[i].y))
         {
             Vector2 vector2 = new Vector2((float)(Main.chest[i].x * 16 + 16), (float)(Main.chest[i].y * 16 + 16));
             if ((vector2 - position).Length() < 200f)
             {
                 for (int j = 0; j < (int)Main.chest[i].item.Length; j++)
                 {
                     if (Main.chest[i].item[j].type <= 0 || Main.chest[i].item[j].stack <= 0)
                     {
                         flag1 = true;
                     }
                     else if (item.IsTheSameAs(Main.chest[i].item[j]))
                     {
                         flag = true;
                         int num = Main.chest[i].item[j].maxStack - Main.chest[i].item[j].stack;
                         if (num > 0)
                         {
                             if (num > item.stack)
                             {
                                 num = item.stack;
                             }
                             Item item1 = item;
                             item1.stack = item1.stack - num;
                             Item item2 = Main.chest[i].item[j];
                             item2.stack = item2.stack + num;
                             if (item.stack <= 0)
                             {
                                 item.SetDefaults(0, false);
                                 return item;
                             }
                         }
                     }
                 }
                 if (flag && flag1 && item.stack > 0)
                 {
                     for (int k = 0; k < (int)Main.chest[i].item.Length; k++)
                     {
                         if (Main.chest[i].item[k].type == 0 || Main.chest[i].item[k].stack == 0)
                         {
                             Main.chest[i].item[k] = item.Clone();
                             item.SetDefaults(0, false);
                             return item;
                         }
                     }
                 }
             }
         }
     }
     return item;
 }
开发者ID:hastinbe,项目名称:TerrariaAPI-Server,代码行数:60,代码来源:Chest.cs

示例9: AddShop

 public void AddShop(Item newItem)
 {
     for (int i = 0; i < 0x13; i++)
     {
         if ((this.item[i] == null) || (this.item[i].type == 0))
         {
             this.item[i] = (Item)newItem.Clone();
             this.item[i].buyOnce = true;
             if (this.item[i].value > 0)
             {
                 this.item[i].value /= 5;
                 if (this.item[i].value < 1)
                 {
                     this.item[i].value = 1;
                     return;
                 }
             }
             break;
         }
     }
 }
开发者ID:Heloo88,项目名称:ModTerraria_Heloo,代码行数:21,代码来源:Chest.cs

示例10: GetItemByName

 /// <summary>
 /// Gets items by name
 /// </summary>
 /// <param name="name">name</param>
 /// <returns>List of Items</returns>
 public static List<Item> GetItemByName(string name)
 {
     var found = new List<Item>();
     Item item = new Item();
     string nameLower = name.ToLower();
     for (int i = -24; i < Main.maxItemTypes; i++)
     {
         item.netDefaults(i);
         if (item.name.ToLower() == nameLower)
             return new List<Item> { item };
         if (item.name.ToLower().StartsWith(nameLower))
             found.Add((Item)item.Clone());
     }
     return found;
 }
开发者ID:jordsti,项目名称:TPulse,代码行数:20,代码来源:GameResources.cs

示例11: EquipSwap

 private static Item EquipSwap(Item item, Item[] inv, int slot, out bool success)
 {
     success = false;
     Player player = Main.player[Main.myPlayer];
     item.favorited = false;
     Item obj = inv[slot].Clone();
     inv[slot] = item.Clone();
     Main.PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     success = true;
     return obj;
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:12,代码来源:ItemSlot.cs

示例12: ArmorSwap

 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 index1 = !item.vanity || item.accessory ? 0 : 10;
     item.favorited = false;
     Item obj = item;
     if (item.headSlot != -1)
     {
         obj = player.armor[index1].Clone();
         player.armor[index1] = item.Clone();
     }
     else if (item.bodySlot != -1)
     {
         obj = player.armor[index1 + 1].Clone();
         player.armor[index1 + 1] = item.Clone();
     }
     else if (item.legSlot != -1)
     {
         obj = player.armor[index1 + 2].Clone();
         player.armor[index1 + 2] = item.Clone();
     }
     else if (item.accessory)
     {
         int num = 5 + Main.player[Main.myPlayer].extraAccessorySlots;
         for (int index2 = 3; index2 < 3 + num; ++index2)
         {
             if (player.armor[index2].itemId == 0)
             {
                 ItemSlot.accSlotCount = index2 - 3;
                 break;
             }
         }
         for (int index2 = 0; index2 < player.armor.Length; ++index2)
         {
             if (item.IsTheSameAs(player.armor[index2]))
                 ItemSlot.accSlotCount = index2 - 3;
             if (index2 < 10 && (int)item.wingSlot > 0 && (int)player.armor[index2].wingSlot > 0)
                 ItemSlot.accSlotCount = index2 - 3;
         }
         if (ItemSlot.accSlotCount >= num)
             ItemSlot.accSlotCount = 0;
         if (ItemSlot.accSlotCount < 0)
             ItemSlot.accSlotCount = num - 1;
         int index3 = 3 + ItemSlot.accSlotCount;
         for (int index2 = 0; index2 < player.armor.Length; ++index2)
         {
             if (item.IsTheSameAs(player.armor[index2]))
                 index3 = index2;
         }
         obj = player.armor[index3].Clone();
         player.armor[index3] = item.Clone();
         ++ItemSlot.accSlotCount;
         if (ItemSlot.accSlotCount >= num)
             ItemSlot.accSlotCount = 0;
     }
     Main.PlaySound(7, -1, -1, 1);
     Recipe.FindRecipes();
     success = true;
     return obj;
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:63,代码来源:ItemSlot.cs

示例13: DyeSwap

 private static Item DyeSwap(Item item, out bool success)
 {
     success = false;
     if ((int)item.dye <= 0)
         return item;
     Player player = Main.player[Main.myPlayer];
     for (int index = 0; index < 10; ++index)
     {
         if (player.dye[index].itemId == 0)
         {
             ItemSlot.dyeSlotCount = index;
             break;
         }
     }
     if (ItemSlot.dyeSlotCount >= 10)
         ItemSlot.dyeSlotCount = 0;
     if (ItemSlot.dyeSlotCount < 0)
         ItemSlot.dyeSlotCount = 9;
     Item obj = 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 obj;
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:28,代码来源:ItemSlot.cs

示例14: AddShop

 public void AddShop(Item newItem)
 {
     for (int index = 0; index < 39; ++index)
     {
         if (item[index] == null || item[index].itemId == 0)
         {
             item[index] = newItem.Clone();
             item[index].favorited = false;
             item[index].buyOnce = true;
             if (item[index].value <= 0)
                 break;
             item[index].value = item[index].value / 5;
             if (item[index].value >= 1)
                 break;
             item[index].value = 1;
             break;
         }
     }
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:19,代码来源:Chest.cs

示例15: PutItemInNearbyChest

 public static Item PutItemInNearbyChest(Item item, Vector2 position)
 {
     if (Main.netMode == 1)
         return item;
     for (int i = 0; i < 1000; ++i)
     {
         bool flag1 = false;
         bool flag2 = false;
         if (Main.chest[i] != null && !IsPlayerInChest(i) && !isLocked(Main.chest[i].x, Main.chest[i].y) && (new Vector2((Main.chest[i].x * 16 + 16), (Main.chest[i].y * 16 + 16)) - position).Length() < 200.0)
         {
             for (int index = 0; index < Main.chest[i].item.Length; ++index)
             {
                 if (Main.chest[i].item[index].itemId > 0 && Main.chest[i].item[index].stack > 0)
                 {
                     if (item.IsTheSameAs(Main.chest[i].item[index]))
                     {
                         flag1 = true;
                         int num = Main.chest[i].item[index].maxStack - Main.chest[i].item[index].stack;
                         if (num > 0)
                         {
                             if (num > item.stack)
                                 num = item.stack;
                             item.stack -= num;
                             Main.chest[i].item[index].stack += num;
                             if (item.stack <= 0)
                             {
                                 item.SetDefaults(0, false);
                                 return item;
                             }
                         }
                     }
                 }
                 else
                     flag2 = true;
             }
             if (flag1 && flag2 && item.stack > 0)
             {
                 for (int index = 0; index < Main.chest[i].item.Length; ++index)
                 {
                     if (Main.chest[i].item[index].itemId == 0 || Main.chest[i].item[index].stack == 0)
                     {
                         Main.chest[i].item[index] = item.Clone();
                         item.SetDefaults(0, false);
                         return item;
                     }
                 }
             }
         }
     }
     return item;
 }
开发者ID:EmuDevs,项目名称:EDTerraria,代码行数:51,代码来源:Chest.cs


注:本文中的Terraria.Item.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。