Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.95 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Linq;
  4. using System.Xml;
  5. using System.Xml.Serialization;
  6. using System.IO;
  7. using System;
  8.  
  9. public static class ServerData
  10. {
  11.  
  12.     public static ItemObject[] AllItems;
  13.  
  14.     public static ItemObject[] HeadGear;
  15.     public static MyColor[] AllColors;
  16.  
  17.     //public static ItemObject[] Colors { get { return AllItems.ToList().Select(l => l.type.Contains("Color")).ToArray(); } }
  18.     //public static
  19.  
  20.  
  21.     public static void ProcessXML(string xml)
  22.     {
  23.         foreach (XmlNode xmlNode in xdoc.DocumentElement.ChildNodes)
  24.         {
  25.  
  26.             /*if (xmlNode.ChildNodes[2].InnerText.Contains("Color"))
  27.             {
  28.                 CustomColour c = new CustomColour();
  29.                 c.name = xmlNode.ChildNodes[1].InnerText;
  30.                 customcolorlist.Add(c);
  31.  
  32.  
  33.             }*/
  34.             ItemObject i = new ItemObject();
  35.             i.ID = Int32.Parse(xmlNode.ChildNodes[0].InnerText);
  36.             i.name = xmlNode.ChildNodes[1].InnerText;
  37.             i.type = xmlNode.ChildNodes[2].InnerText;
  38.             i.customdata = xmlNode.ChildNodes[3].InnerText;
  39.             if (xmlNode.ChildNodes[4].InnerText == "False") i.craftable = false; else i.craftable = true;
  40.             i.equipslot = Int32.Parse(xmlNode.ChildNodes[5].InnerText);
  41.             i.possiblestats = xmlNode.ChildNodes[6].InnerText;
  42.             i.recipe.ParseRecipe(xmlNode.ChildNodes[7].InnerText);
  43.             i.maxstack = Int32.Parse(xmlNode.ChildNodes[8].InnerText);
  44.             i.itempath = xmlNode.ChildNodes[9].InnerText;
  45.             AllItems.ToList().Add(i).ToArray();
  46.         }
  47.         AllColors = AllItems.ToList().Select(l => l.type.Contains("Color")).ConvertAll<MyColor>(a => ItemToColor(a)).ToArray();
  48.         HeadGear = AllItems.ToList().Select(l => l.type.Contains("Equipment") && l.equipslot == 0).ToArray();
  49.  
  50.  
  51.     }
  52.  
  53.     private static MyColor ItemToColor(ItemObject i)
  54.     {
  55.         MyColor c = new MyColor();
  56.         c.ID = i.ID;
  57.         c.name = i.name;
  58.         c.maxstack = i.maxstack;
  59.         c.rarity = SubString(i.customdata, "Rarity': '", "'");
  60.         c.R = Int32.Parse(SubString(i.customdata, "R': '", "'"));
  61.         c.G = Int32.Parse(SubString(i.customdata, "G': '", "'"));
  62.         c.B = Int32.Parse(SubString(i.customdata, "B': '", "'"));
  63.         c.A = Int32.Parse(SubString(i.customdata, "A': '", "'"));
  64.         return c;
  65.     }
  66.  
  67.     public static string SubString(string data, string firstbit, string secondbit)
  68.     {
  69.         int FirstChr = data.IndexOf(firstbit) + firstbit.Length;
  70.         int SecondChr = data.IndexOf(secondbit, FirstChr);
  71.         string dumdumdum = data.Substring(FirstChr, SecondChr - FirstChr);
  72.         return dumdumdum;
  73.     }
  74.  
  75.  
  76.  
  77. }
  78.  
  79. public class ItemObject
  80. {
  81.     public int ID = -1;
  82.     public string name = "";
  83.     public string type = "";
  84.     public string customdata = "";
  85.     public string itempath = "";
  86.     public bool craftable = false;
  87.     public int equipslot = -1;
  88.     public string possiblestats = "";
  89.     public MyRecipe recipe = new MyRecipe();
  90.     public int maxstack = -1;
  91. }
  92. public class MyColor
  93. {
  94.     public int ID = -1;
  95.     public string name = "";
  96.     public string rarity = "";
  97.     public int R = 0;
  98.     public int G = 0;
  99.     public int B = 0;
  100.     public int A = 0;
  101.     public int maxstack = 99;
  102. }
  103. public class MyRecipe
  104. {
  105.     public Ingredient[] Ingredients;
  106.  
  107.     public int Wood { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Wood").First(); if (i != null) return i.amount; else return 0; } }
  108.     public int Stone { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Stone").First(); if (i != null) return i.amount; else return 0; } }
  109.     public int Leather { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Leather").First(); if (i != null) return i.amount; else return 0; } }
  110.     public int Cloth { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Cloth").First(); if (i != null) return i.amount; else return 0; } }
  111.     public int Bone { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Bone").First(); if (i != null) return i.amount; else return 0; } }
  112.     public int Essence { get { ItemObject i = Ingredients.ToList().Select(x => x.name = "Essence").First(); if (i != null) return i.amount; else return 0; } }
  113.  
  114.     public void ParseRecipe(string recipe)
  115.     {
  116.         if (Ingredients == null)
  117.         {
  118.             Ingredients = new Ingredient[0];
  119.         }
  120.         XmlDocument xdoc = new XmlDocument();
  121.         xdoc.LoadXml(recipe);
  122.         foreach (XmlNode xmlNode in xdoc.DocumentElement.ChildNodes)
  123.         {
  124.             Ingredient i = new Ingredient();
  125.             i.ID = Int32.Parse(xmlNode.ChildNodes[0].InnerText);
  126.             i.amount = Int32.Parse(xmlNode.ChildNodes[1].InnerText);
  127.  
  128.             Ingredients = Ingredients.ToList().Add(i).ToArray();
  129.         }
  130.     }
  131.  
  132. }
  133. public class Ingredient
  134. {
  135.     public int ID = -1;
  136.     public int amount = -1;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement