Example #1
0
		public static IList<Item> SetupStartInventory(Player player)
		{
			IList<Item> items = new List<Item>();
			Item item = new Item();
			item.SetDefaults("Copper Shortsword");
			item.Prefix(-1);
			items.Add(item);
			item = new Item();
			item.SetDefaults("Copper Pickaxe");
			item.Prefix(-1);
			items.Add(item);
			item = new Item();
			item.SetDefaults("Copper Axe");
			item.Prefix(-1);
			items.Add(item);
			foreach (ModPlayer modPlayer in player.modPlayers)
			{
				modPlayer.SetupStartInventory(items);
			}
			IDictionary<int, int> counts = new Dictionary<int, int>();
			foreach (Item item0 in items)
			{
				if (item0.maxStack > 1)
				{
					if (!counts.ContainsKey(item0.netID))
					{
						counts[item0.netID] = 0;
					}
					counts[item0.netID] += item0.stack;
				}
			}
			int k = 0;
			while (k < items.Count)
			{
				bool flag = true;
				int id = items[k].netID;
				if (counts.ContainsKey(id))
				{
					items[k].stack = counts[id];
					if (items[k].stack > items[k].maxStack)
					{
						items[k].stack = items[k].maxStack;
					}
					counts[id] -= items[k].stack;
					if (items[k].stack <= 0)
					{
						items.RemoveAt(k);
						flag = false;
					}
				}
				if (flag)
				{
					k++;
				}
			}
			return items;
		}
Example #2
0
        public static void Load(Item item, TagCompound tag)
        {
            if (tag.Count == 0)
            {
                item.netDefaults(0);
                return;
            }

            string modName = tag.GetString("mod");
            if (modName == "Terraria")
            {
                item.netDefaults(tag.GetInt("id"));
                if (tag.HasTag("legacyData"))
                    LoadLegacyModData(item, tag.GetByteArray("legacyData"), tag.GetBool("hasGlobalSaving"));
            }
            else
            {
                int type = ModLoader.GetMod(modName)?.ItemType(tag.GetString("name")) ?? 0;
                if (type > 0)
                {
                    item.netDefaults(type);
                    if (tag.HasTag("legacyData"))
                        LoadLegacyModData(item, tag.GetByteArray("legacyData"), tag.GetBool("hasGlobalSaving"));
                    else
                        item.modItem.Load(tag.GetCompound("data"));
                }
                else
                {
                    item.netDefaults(ModLoader.GetMod("ModLoader").ItemType("MysteryItem"));
                    ((MysteryItem)item.modItem).Setup(tag);
                }
            }

            item.Prefix(tag.GetByte("prefix"));
            item.stack = tag.GetTag<int?>("stack") ?? 1;
            item.favorited = tag.GetBool("fav");

            if (!(item.modItem is MysteryItem))
                LoadGlobals(item, tag.GetList<TagCompound>("globalData"));
        }
Example #3
0
		public static void ReadItem(Item item, BinaryReader reader, bool readStack = false, bool readFavorite = false)
		{
			string modName = reader.ReadString();
			bool hasGlobalSaving = false;
			if (modName.Length == 0)
			{
				hasGlobalSaving = true;
				modName = reader.ReadString();
			}
			if (modName == "Terraria")
			{
				item.netDefaults(reader.ReadInt32());
				ReadCustomData(item, GetCustomData(item.type, reader, hasGlobalSaving), hasGlobalSaving);
			}
			else
			{
				string itemName = reader.ReadString();
				int type = ModLoader.GetMod(modName)?.ItemType(itemName) ?? 0;
				byte[] data = GetCustomData(type == 0 ? Int32.MaxValue : type, reader, hasGlobalSaving);
				if (type != 0)
				{
					item.netDefaults(type);
					ReadCustomData(item, data, hasGlobalSaving);
				}
				else
				{
					item.netDefaults(ModLoader.GetMod("ModLoader").ItemType("MysteryItem"));
					((MysteryItem)item.modItem).Setup(modName, itemName, data, hasGlobalSaving);
				}
			}
			
			item.Prefix(reader.ReadByte());

			if (readStack)
				item.stack = reader.ReadInt32();

			if (readFavorite)
				item.favorited = reader.ReadBoolean();
		}
Example #4
0
 private static void LoadChests(BinaryReader reader)
 {
     int num = (int)reader.ReadInt16();
     int num2 = (int)reader.ReadInt16();
     int num3;
     int num4;
     if (num2 < 40)
     {
         num3 = num2;
         num4 = 0;
     }
     else
     {
         num3 = 40;
         num4 = num2 - 40;
     }
     int i;
     for (i = 0; i < num; i++)
     {
         Chest chest = new Chest(false);
         chest.x = reader.ReadInt32();
         chest.y = reader.ReadInt32();
         chest.name = reader.ReadString();
         for (int j = 0; j < num3; j++)
         {
             short num5 = reader.ReadInt16();
             Item item = new Item();
             if (num5 > 0)
             {
                 item.netDefaults(reader.ReadInt32());
                 item.stack = (int)num5;
                 item.Prefix((int)reader.ReadByte());
             }
             else if (num5 < 0)
             {
                 item.netDefaults(reader.ReadInt32());
                 item.Prefix((int)reader.ReadByte());
                 item.stack = 1;
             }
             chest.item[j] = item;
         }
         for (int j = 0; j < num4; j++)
         {
             short num5 = reader.ReadInt16();
             if (num5 > 0)
             {
                 reader.ReadInt32();
                 reader.ReadByte();
             }
         }
         Main.chest[i] = chest;
     }
     List<Point16> list = new List<Point16>();
     for (int k = 0; k < i; k++)
     {
         if (Main.chest[k] != null)
         {
             Point16 item2 = new Point16(Main.chest[k].x, Main.chest[k].y);
             if (list.Contains(item2))
             {
                 Main.chest[k] = null;
             }
             else
             {
                 list.Add(item2);
             }
         }
     }
     while (i < 1000)
     {
         Main.chest[i] = null;
         i++;
     }
     if (WorldFile.versionNumber < 115)
     {
         WorldFile.FixDresserChests();
     }
 }
Example #5
0
 public static int PickItemMovementAction(Item[] inv, int context, int slot, Item checkItem)
 {
     Player player = Main.player[Main.myPlayer];
     int result = -1;
     if (context == 0)
     {
         result = 0;
     }
     else if (context == 1)
     {
         if (checkItem.type == 0 || checkItem.type == 71 || checkItem.type == 72 || checkItem.type == 73 || checkItem.type == 74)
         {
             result = 0;
         }
     }
     else if (context == 2)
     {
         if (((checkItem.type == 0 || checkItem.ammo > 0 || checkItem.bait > 0) && !checkItem.notAmmo) || checkItem.type == 530)
         {
             result = 0;
         }
     }
     else if (context == 3)
     {
         result = 0;
     }
     else if (context == 4)
     {
         result = 0;
     }
     else if (context == 5)
     {
         if (checkItem.Prefix(-3) || checkItem.type == 0)
         {
             result = 0;
         }
     }
     else if (context == 6)
     {
         result = 0;
     }
     else if (context == 7)
     {
         if (checkItem.material || checkItem.type == 0)
         {
             result = 0;
         }
     }
     else if (context == 8)
     {
         if (checkItem.type == 0 || (checkItem.headSlot > -1 && slot == 0) || (checkItem.bodySlot > -1 && slot == 1) || (checkItem.legSlot > -1 && slot == 2))
         {
             result = 1;
         }
     }
     else if (context == 9)
     {
         if (checkItem.type == 0 || (checkItem.headSlot > -1 && slot == 10) || (checkItem.bodySlot > -1 && slot == 11) || (checkItem.legSlot > -1 && slot == 12))
         {
             result = 1;
         }
     }
     else if (context == 10)
     {
         if (checkItem.type == 0 || (checkItem.accessory && !ItemSlot.AccCheck(checkItem, slot)))
         {
             result = 1;
         }
     }
     else if (context == 11)
     {
         if (checkItem.type == 0 || (checkItem.accessory && !ItemSlot.AccCheck(checkItem, slot)))
         {
             result = 1;
         }
     }
     else if (context == 12)
     {
         result = 2;
     }
     else if (context == 15)
     {
         if (checkItem.type == 0 && inv[slot].type > 0)
         {
             if (player.BuyItem(inv[slot].value))
             {
                 result = 3;
             }
         }
         else if (inv[slot].type == 0 && checkItem.type > 0 && (checkItem.type < 71 || checkItem.type > 74))
         {
             result = 4;
         }
     }
     else if (context == 16)
     {
         if (checkItem.type == 0 || Main.projHook[checkItem.shoot])
         {
             result = 1;
         }
     }
     else if (context == 17)
     {
         if (checkItem.type == 0 || (checkItem.mountType != -1 && !MountID.Sets.Cart[checkItem.mountType]))
         {
             result = 1;
         }
     }
     else if (context == 19)
     {
         if (checkItem.type == 0 || (checkItem.buffType > 0 && Main.vanityPet[checkItem.buffType] && !Main.lightPet[checkItem.buffType]))
         {
             result = 1;
         }
     }
     else if (context == 18)
     {
         if (checkItem.type == 0 || (checkItem.mountType != -1 && MountID.Sets.Cart[checkItem.mountType]))
         {
             result = 1;
         }
     }
     else if (context == 20 && (checkItem.type == 0 || (checkItem.buffType > 0 && Main.lightPet[checkItem.buffType])))
     {
         result = 1;
     }
     return result;
 }
Example #6
0
        public Item ToItem()
        {
            Item item = new Item();
              item.netDefaults((int)this.Type);
              item.Prefix((int)this.Prefix);
              item.stack = this.StackSize;

              return item;
        }
Example #7
0
        public Item ToItem()
        {
            Item item = new Item();
              if (this.StackSize > 0) {
            item.netDefaults((int)this.Type);
            item.Prefix((int)this.Prefix);
            item.stack = this.StackSize;
              } else {
            item.netDefaults(0);
              }

              return item;
        }
Example #8
0
        public static void LoadLegacy(Item item, BinaryReader reader, bool readStack = false, bool readFavorite = false)
        {
            string modName = reader.ReadString();
            bool hasGlobalSaving = false;
            if (modName.Length == 0)
            {
                hasGlobalSaving = true;
                modName = reader.ReadString();
            }
            if (modName == "Terraria")
            {
                item.netDefaults(reader.ReadInt32());
                LoadLegacyModData(item, LegacyModData(item.type, reader, hasGlobalSaving), hasGlobalSaving);
            }
            else
            {
                string itemName = reader.ReadString();
                int type = ModLoader.GetMod(modName)?.ItemType(itemName) ?? 0;
                byte[] data = LegacyModData(type == 0 ? int.MaxValue : type, reader, hasGlobalSaving);
                if (type != 0)
                {
                    item.netDefaults(type);
                    LoadLegacyModData(item, data, hasGlobalSaving);
                }
                else
                {
                    item.netDefaults(ModLoader.GetMod("ModLoader").ItemType("MysteryItem"));
                    var tag = new TagCompound {
                        ["mod"] = modName,
                        ["name"] = itemName,
                        ["hasGlobalSaving"] = hasGlobalSaving,
                        ["legacyData"] = data
                    };
                    ((MysteryItem)item.modItem).Setup(tag);
                }
            }

            item.Prefix(reader.ReadByte());

            if (readStack)
                item.stack = reader.ReadInt32();

            if (readFavorite)
                item.favorited = reader.ReadBoolean();
        }
Example #9
0
 public static void Receive(Item item, BinaryReader reader, bool readStack = false, bool readFavorite = false)
 {
     item.netDefaults(reader.ReadInt16());
     item.Prefix(reader.ReadByte());
     if (readStack) item.stack = reader.ReadInt16();
     if (readFavorite) item.favorited = reader.ReadBoolean();
     ReceiveModData(item, reader);
 }
		TextSnippet ITagHandler.Parse(string text, Color baseColor, string options)
		{
			Item item = new Item();
			int type;
			if (int.TryParse(text, out type))
			{
				item.netDefaults(type);
			}
			else
			{
				item.SetDefaults(text);
			}
			if (item.type <= 0)
			{
				return new TextSnippet(text);
			}
			item.stack = 1;
			if (options != null)
			{
				string[] array = options.Split(new char[]
				{
					','
				});
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i].Length != 0)
					{
						char c = array[i][0];
						int value2;
						if (c != 'p')
						{
							int value;
							if ((c == 's' || c == 'x') && int.TryParse(array[i].Substring(1), out value))
							{
								item.stack = Utils.Clamp<int>(value, 1, item.maxStack);
							}
						}
						else if (int.TryParse(array[i].Substring(1), out value2))
						{
							item.Prefix((int)((byte)Utils.Clamp<int>(value2, 0, 84)));
						}
					}
				}
			}
			string str = "";
			if (item.stack > 1)
			{
				str = " (" + item.stack + ")";
			}
			return new ItemTagHandler.ItemSnippet(item)
			{
				Text = "[" + item.AffixName() + str + "]",
				CheckForHover = true,
				DeleteWhole = true
			};
		}