Guest User

Untitled

a guest
Jan 31st, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.95 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Xml.Linq;
  6. using Guedez.Database;
  7. using Unity.Entities;
  8. using UnityEngine;
  9. using static EntityProcessor;
  10.  
  11. [LoaderType("equip")]
  12. public class EquipmentProcessor : Processor {
  13.     public EquipmentProcessor(bool isContainer) : base(isContainer) {
  14.     }
  15.  
  16.     public struct BlendMod {
  17.         public string name;
  18.         public int value;
  19.     }
  20.  
  21.     public class EquipmentDefinition {
  22.         //public enum ItemClothSlots {
  23.         //    Hair, Head, Neck, Torso_INNER, Torso_MID, Torso_OUTER, Arms, Legs, Feet, Hand_Left, Hand_Right, Hand_Any, Gloves, Belt
  24.         //}
  25.         //public enum EquipperType {
  26.         //    DEFAULT, ADAM, GIRLS_HUMANOID, GIRLS_HALF
  27.         //}
  28.         public GameObject prefab;
  29.         public bool selfBoned;
  30.         public string attachBone;
  31.         public BlendMod[] blends;
  32.         public string[] types;
  33.         public string[] slots = new string[0];
  34.         public long entity;
  35.         public ItemBehaviour[] behaviours = new ItemBehaviour[0];
  36.  
  37.  
  38.     }
  39.     private static readonly Dictionary<long, EquipmentDefinition> equips = new Dictionary<long, EquipmentDefinition>();
  40.     internal static string[] types;
  41.     internal static string[] slots;
  42.  
  43.     private static HashSet<string> _types;
  44.     private static HashSet<string> _slots;
  45.  
  46.     public override void OnStartDatabaseLoad() {
  47.         equips.Clear();
  48.         _types = new HashSet<string>();
  49.         _slots = new HashSet<string>();
  50.     }
  51.     public override void OnEndDatabaseLoad() {
  52.         types = _types.ToArray();
  53.         slots = _slots.ToArray();
  54.     }
  55.  
  56.     public override object ProcessType(XElement element, List<object> parents) {
  57.         DatabaseEntity entity = DatabaseLoader.GetFirst<DatabaseEntity>(parents);
  58.         if (entity == null) {
  59.             Debug.LogWarning("No entity to add Item to");
  60.             return null;
  61.         }
  62.         EquipmentDefinition item;
  63.         if (!equips.TryGetValue(entity.identifier, out item)) {
  64.             item = new EquipmentDefinition();
  65.         }
  66.         item.prefab = DatabaseLoader.LoadResource<GameObject>(element.Element("prefab"));
  67.         if (item.prefab == null) {
  68.             return null;
  69.         }
  70.         equips[entity.identifier] = item;
  71.         item.selfBoned = element.Element("selfBoned") != null;
  72.         item.attachBone = DatabaseLoader.GetElementValueOrDefault(element.Element("attachBone"));
  73.         item.entity = entity.identifier;
  74.  
  75.         item.slots = DatabaseLoader.GetElementValueAsList<string>(element.Elements("slot"));
  76.         foreach (string s in item.slots) {
  77.             _slots.Add(s.ToLower());
  78.         }
  79.         item.types = DatabaseLoader.GetElementValueAsList<string>(element.Elements("type"));
  80.         item.blends = DatabaseLoader.GetElementValueAsList<BlendMod>(element.Elements("blend"));
  81.         foreach (string t in item.types) {
  82.             _types.Add(t.ToLower());
  83.         }
  84.         item.behaviours = loadBehaviours(element.Elements("behaviour"));
  85.         //public GameObject prefab;
  86.         //public bool selfBoned;
  87.         //public string attachBone;
  88.         //public string type;
  89.         //public string[] slots = new string[0];
  90.         //public long entity;
  91.         //public ItemBehaviour[] behaviours = new ItemBehaviour[0];
  92.  
  93.         //< prefab > Items / Equipment / Seeds / Carrot Seed / Carrot Seed Bag</ prefab >          
  94.         //< !--< selfBoned /> -->          
  95.         //< attachBone > hand_R </ attachBone >          
  96.         //< type > ALL </ type >          
  97.         //< slots >          
  98.         //    < slot > MainHand </ slot >          
  99.         //</ slots >          
  100.         //< behaviour > Items / Equipment / Seeds / Carrot Seed / Carrot Seed Bag Behaiour </ behaviour >
  101.         return item;
  102.     }
  103.  
  104.     private ItemBehaviour[] loadBehaviours(IEnumerable<XElement> enumerable) {
  105.         //
  106.         List<ItemBehaviour> behavs = new List<ItemBehaviour>();
  107.         foreach (XElement els in enumerable) {
  108.             behavs.Add(loadBehaviour(els));
  109.         }
  110.         return behavs.ToArray();
  111.     }
  112.  
  113.     private ItemBehaviour loadBehaviour(XElement els) {
  114.         XElement path = els.Element("path");
  115.         if (path != null) {
  116.             ItemBehaviour itb = GameObject.Instantiate(DatabaseLoader.LoadResource<ItemBehaviour>(path));
  117.             itb.loadProps(els);
  118.             return itb;
  119.         } else {
  120.             return DatabaseLoader.LoadResource<ItemBehaviour>(els);
  121.         }
  122.     }
  123.  
  124.     public IEnumerable<KeyValuePair<long, EquipmentDefinition>> GetEquipmentsAndIndex() {
  125.         return equips;
  126.     }
  127.     public IEnumerable<EquipmentDefinition> GetEquipments() {
  128.         return equips.Values;
  129.     }
  130.  
  131.     public EquipmentDefinition getEquipmentDef(long reference) {
  132.         EquipmentDefinition ret;
  133.         if (equips.TryGetValue(reference, out ret)) {
  134.             return ret;
  135.         }
  136.         return null;
  137.     }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment