private void LoadItems(XmlNodeList itemNodes) { Int32 count = -1; if ((itemNodes == null) || (itemNodes.Count == 0)) { errorLog.AppendLine("There are no Item items to load."); return; } foreach (XmlNode itemNode in itemNodes) { String name = String.Empty; String type = String.Empty; String found = String.Empty; String recolor = String.Empty; String droppedBy = String.Empty; Int32 netId = 0; Int32 imageId = -1; Int32 stack = -1; Int32 defaultStack = -1; count++; foreach (XmlAttribute att in itemNode.Attributes) { switch (att.Name) { case "name": name = att.Value; break; case "type": type = att.Value; break; case "netId": if (Int32.TryParse(att.Value, out netId) == false) { errorLog.AppendLine(String.Format("Item #{0} has an invalid netId attribute. Value = \"{1}\"", count, att.Value)); continue; } break; case "itemImage": if (Int32.TryParse(att.Value, out imageId) == false) { errorLog.AppendLine(String.Format("Item #{0} has an invalid itemImage attribute. Value = \"{1}\"", count, att.Value)); continue; } if (imageId < 0) { errorLog.AppendLine(String.Format("Item #{0} had a out of range itemImage attribute. Value=\"{1}\"", count, imageId)); continue; } break; case "foundIn": found = att.Value; break; case "recolor": recolor = att.Value; break; case "maxStack": if (Int32.TryParse(att.Value, out stack) == false) { errorLog.AppendLine(String.Format("Item #{0} has an invalid maxStack attribute. Value=\"{1}\"", count, att.Value)); continue; } if ((stack < 1) || (stack > 255)) { errorLog.AppendLine(String.Format("Item #{0} had a out of range maxStack attribute. Value=\"{1}\"", count, stack)); continue; } break; case "droppedBy": droppedBy = att.Value; break; case "subType": // Not implemented yet. break; case "ammoType": // Not implemented yet. break; case "plantsIn": // Not implemented yet. break; default: errorLog.AppendLine(String.Format("Item #{0} has unknown attribute \"{1}\" has value \"{2}\"", count, att.Name, att.Value)); break; } } if (name == String.Empty) { errorLog.AppendLine(String.Format("Item #{0} had no name attribute.", count)); continue; } if (type == String.Empty) type = "Generic"; if (!itemTypes.ContainsKey(type)) { errorLog.AppendLine(String.Format("Item #{0} has an itemType that does not exist. Value=\"{1}\"", count, type)); continue; } else { defaultStack = itemTypes[type].defaultSize; } if (stack == -1) { stack = defaultStack; } if (imageId == -1) { errorLog.AppendLine(String.Format("Item #{0} had no itemImage attribute.", count)); continue; } if (netId == 0) netId = imageId; if (items.ContainsKey(name)) { errorLog.AppendLine(String.Format("Item #{0} had a duplicate name to {1}.", count, name)); continue; } ItemInfo item = new ItemInfo(); item.name = name; item.type = type; item.droppedBy = droppedBy; item.foundIn = found; item.recolor = recolor; item.netId = netId; item.imageId = imageId; item.stackSize = stack; items.Add(name, item); } }
public void AddCustomItem(String itemName) { ItemInfo ii = new ItemInfo(); ii.name = itemName; ii.isCustom = true; items.Add(itemName, ii); }