Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Linq;
- using System.Xml;
- using System.Xml.Serialization;
- using System.IO;
- using System;
- public static class ServerData
- {
- public static ItemObject[] AllItems;
- public static ItemObject[] HeadGear;
- public static MyColor[] AllColors;
- //public static ItemObject[] Colors { get { return AllItems.ToList().Select(l => l.type.Contains("Color")).ToArray(); } }
- //public static
- public static void ProcessXML(string xml)
- {
- foreach (XmlNode xmlNode in xdoc.DocumentElement.ChildNodes)
- {
- /*if (xmlNode.ChildNodes[2].InnerText.Contains("Color"))
- {
- CustomColour c = new CustomColour();
- c.name = xmlNode.ChildNodes[1].InnerText;
- customcolorlist.Add(c);
- }*/
- ItemObject i = new ItemObject();
- i.ID = Int32.Parse(xmlNode.ChildNodes[0].InnerText);
- i.name = xmlNode.ChildNodes[1].InnerText;
- i.type = xmlNode.ChildNodes[2].InnerText;
- i.customdata = xmlNode.ChildNodes[3].InnerText;
- if (xmlNode.ChildNodes[4].InnerText == "False") i.craftable = false; else i.craftable = true;
- i.equipslot = Int32.Parse(xmlNode.ChildNodes[5].InnerText);
- i.possiblestats = xmlNode.ChildNodes[6].InnerText;
- i.recipe.ParseRecipe(xmlNode.ChildNodes[7].InnerText);
- i.maxstack = Int32.Parse(xmlNode.ChildNodes[8].InnerText);
- i.itempath = xmlNode.ChildNodes[9].InnerText;
- AllItems.ToList().Add(i).ToArray();
- }
- AllColors = AllItems.ToList().Select(l => l.type.Contains("Color")).ConvertAll<MyColor>(a => ItemToColor(a)).ToArray();
- HeadGear = AllItems.ToList().Select(l => l.type.Contains("Equipment") && l.equipslot == 0).ToArray();
- }
- private static MyColor ItemToColor(ItemObject i)
- {
- MyColor c = new MyColor();
- c.ID = i.ID;
- c.name = i.name;
- c.maxstack = i.maxstack;
- c.rarity = SubString(i.customdata, "Rarity': '", "'");
- c.R = Int32.Parse(SubString(i.customdata, "R': '", "'"));
- c.G = Int32.Parse(SubString(i.customdata, "G': '", "'"));
- c.B = Int32.Parse(SubString(i.customdata, "B': '", "'"));
- c.A = Int32.Parse(SubString(i.customdata, "A': '", "'"));
- return c;
- }
- public static string SubString(string data, string firstbit, string secondbit)
- {
- int FirstChr = data.IndexOf(firstbit) + firstbit.Length;
- int SecondChr = data.IndexOf(secondbit, FirstChr);
- string dumdumdum = data.Substring(FirstChr, SecondChr - FirstChr);
- return dumdumdum;
- }
- }
- public class ItemObject
- {
- public int ID = -1;
- public string name = "";
- public string type = "";
- public string customdata = "";
- public string itempath = "";
- public bool craftable = false;
- public int equipslot = -1;
- public string possiblestats = "";
- public MyRecipe recipe = new MyRecipe();
- public int maxstack = -1;
- }
- public class MyColor
- {
- public int ID = -1;
- public string name = "";
- public string rarity = "";
- public int R = 0;
- public int G = 0;
- public int B = 0;
- public int A = 0;
- public int maxstack = 99;
- }
- public class MyRecipe
- {
- public Ingredient[] Ingredients;
- public int Wood { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Wood").First(); if (i != null) return i.amount; else return 0; } }
- public int Stone { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Stone").First(); if (i != null) return i.amount; else return 0; } }
- public int Leather { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Leather").First(); if (i != null) return i.amount; else return 0; } }
- public int Cloth { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Cloth").First(); if (i != null) return i.amount; else return 0; } }
- public int Bone { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Bone").First(); if (i != null) return i.amount; else return 0; } }
- public int Essence { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Essence").First(); if (i != null) return i.amount; else return 0; } }
- public void ParseRecipe(string recipe)
- {
- if (Ingredients == null)
- {
- Ingredients = new Ingredient[0];
- }
- XmlDocument xdoc = new XmlDocument();
- xdoc.LoadXml(recipe);
- foreach (XmlNode xmlNode in xdoc.DocumentElement.ChildNodes)
- {
- Ingredient i = new Ingredient();
- i.ID = Int32.Parse(xmlNode.ChildNodes[0].InnerText);
- i.amount = Int32.Parse(xmlNode.ChildNodes[1].InnerText);
- Ingredients = Ingredients.ToList().Add(i).ToArray();
- }
- }
- }
- public class Ingredient
- {
- public int ID = -1;
- public int amount = -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement