public void SetItem(ItemData item) { this.tag = item.type.ToString(); this.itemData = item.Copy(); if (this.itemData.amount > 1) { this.text.text = this.itemData.amount.ToString(); } else { this.text.text = ""; } }
/// <summary> /// Deals with the blocks.xml. /// </summary> public static void GetBlocks() { List <ItemData> itemList = ItemData.itemList; XmlDocument document = new XmlDocument(); document.Load(Config.GetSetting("gameRoot") + "\\Data\\Config\\blocks.xml"); XmlNode blocksNode = document.DocumentElement; foreach (XmlNode blockNode in blocksNode.ChildNodes) { if (blockNode.Name.Equals("block")) { XmlNode extendsNode = GetChildNodeByName(blockNode, "Extends"); XmlNode developerNode = GetChildNodeByName(blockNode, "IsDeveloper"); ItemData itemData = new ItemData(); if (extendsNode != null) { string parentItemName = extendsNode.Attributes[1].Value; ItemData parent = ItemData.GetItemDataByName(parentItemName); itemData.Copy(parent); } if (developerNode != null) { itemData.isDeveloper = developerNode.Attributes[1].Value.Equals("true"); } itemData.id = int.Parse(blockNode.Attributes[0].Value); itemData.name = blockNode.Attributes[1].Value; itemData.stackNumber = ItemData.DEFAULT_STACKNUMBER; if ((IconData.itemIconDictionary != null) && (IconData.itemIconDictionary.ContainsKey(itemData.name))) { IconData.itemIconDictionary.TryGetValue(itemData.name, out itemData.iconPixels); } itemList.Add(itemData); } } }
/// <summary> /// Deals with items.xml. /// </summary> public static void GetItems() { List <ItemData> itemList = ItemData.itemList; XmlDocument document = new XmlDocument(); document.Load(Config.GetSetting("gameRoot") + "\\Data\\Config\\items.xml"); XmlNode itemsNode = document.DocumentElement; foreach (XmlNode itemNode in itemsNode.ChildNodes) { if (itemNode.Name.Equals("item")) { XmlNode extendsNode = GetChildNodeByName(itemNode, "Extends"); XmlNode developerNode = GetChildNodeByName(itemNode, "IsDeveloper"); XmlNode stackNumberNode = GetChildNodeByName(itemNode, "Stacknumber"); XmlNode repairToolsNode = GetChildNodeByName(itemNode, "RepairTools"); XmlNode attributesNode = GetChildNodeByName(itemNode, "Attributes"); XmlNode degradationMaxNode = null; if (attributesNode != null) { degradationMaxNode = GetChildNodeByName(attributesNode, "DegradationMax"); } XmlNode partTypeNode = GetChildNodeByName(itemNode, "PartType"); XmlNode attachmentsNode = GetChildNodeByName(itemNode, "Attachments"); XmlNode partsNode = GetChildNodeByName(itemNode, "Parts"); XmlNode action0Node = GetChildNodeByName(itemNode, "Action0"); XmlNode magazineSizeNode = null; if (action0Node != null) { magazineSizeNode = GetChildNodeByName(action0Node, "Magazine_size"); } XmlNode customIconNode = GetChildNodeByName(itemNode, "CustomIcon"); ItemData itemData = new ItemData(); if (extendsNode != null) { string parentItemName = extendsNode.Attributes[1].Value; ItemData parent = ItemData.GetItemDataByName(parentItemName); itemData.Copy(parent); } if (developerNode != null) { itemData.isDeveloper = developerNode.Attributes[1].Value.Equals("true"); } else { itemData.isDeveloper = false; } itemData.id = int.Parse(itemNode.Attributes[0].Value) + 4096; itemData.name = itemNode.Attributes[1].Value; if (stackNumberNode != null) { itemData.stackNumber = int.Parse(stackNumberNode.Attributes[1].Value); } else if (partsNode != null || attributesNode != null) { itemData.stackNumber = 1; } else if (itemData.stackNumber == 0) { itemData.stackNumber = ItemData.DEFAULT_STACKNUMBER; } if (repairToolsNode != null || partTypeNode != null) { string name = itemData.name; itemData.hasQuality = true; if (degradationMaxNode != null) { string degradationS = degradationMaxNode.Attributes[1].Value; itemData.degradationMin = int.Parse(degradationS.Substring(0, degradationS.IndexOf(','))); itemData.degradationMax = int.Parse(degradationS.Substring(degradationS.IndexOf(',') + 1)); } if (partTypeNode != null) { itemData.partType = partTypeNode.Attributes[1].Value; } if (attachmentsNode != null) { itemData.attachmentNames = attachmentsNode.Attributes[1].Value.Split(','); } try { if (partsNode != null) { itemData.partNames = new string[4]; itemData.partNames[0] = GetChildNodeByName(partsNode, "Stock").Attributes[1].Value; itemData.partNames[1] = GetChildNodeByName(partsNode, "Receiver").Attributes[1].Value; itemData.partNames[2] = GetChildNodeByName(partsNode, "Pump").Attributes[1].Value; itemData.partNames[3] = GetChildNodeByName(partsNode, "Barrel").Attributes[1].Value; } if (magazineSizeNode != null) { itemData.magazineSize = int.Parse(magazineSizeNode.Attributes[1].Value); itemData.magazineItems = GetChildNodeByName(action0Node, "Magazine_items").Attributes[1].Value.Split(','); } } catch (System.Exception) { MessageBox.Show("Bad XML Data for item " + itemData.name, "Loading", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } if ((customIconNode != null) && (IconData.itemIconDictionary != null)) { IconData.itemIconDictionary.TryGetValue(customIconNode.Attributes[1].Value, out itemData.iconPixels); } else if ((IconData.itemIconDictionary != null) && (IconData.itemIconDictionary.ContainsKey(itemData.name))) { IconData.itemIconDictionary.TryGetValue(itemData.name, out itemData.iconPixels); } if (!itemData.isDeveloper && extendsNode != null && extendsNode.Attributes[1].Value.Equals("schematicMaster")) { XmlNode action1Node = GetChildNodeByName(itemNode, "Action1"); XmlNode recipesToLearnNode = GetChildNodeByName(action1Node, "Recipes_to_learn"); if (recipesToLearnNode != null) { string recipesToLearn = recipesToLearnNode.Attributes[1].Value; string[] recipes = recipesToLearn.Split(','); foreach (string recipe in recipes) { RecipeData.recipeList.Add(new RecipeData(recipe, true)); } } } itemList.Add(itemData); } } }