Esempio n. 1
0
 protected void CommonDeSerialize(object data)
 {
     //通用反序列化
     string[] srr = (string[])data;
     if (srr != null)
     {
         var properties = this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
         //无标签的无效
         properties.RemoveAll((info => info.GetCustomAttribute <SlkPropertyAttribute>() == null));
         properties.Sort((p1, p2) =>
         {
             var p1Index = p1.GetCustomAttribute <SlkPropertyAttribute>();
             var p2Index = p2.GetCustomAttribute <SlkPropertyAttribute>();
             var p1i     = p1Index != null ? p1Index.Index : int.MaxValue;
             var p2i     = p2Index != null ? p2Index.Index : int.MaxValue;
             return(p1i - p2i);
         });
         int min = Math.Min(properties.Count, srr.Length);
         for (int i = 0; i < min; i++)
         {
             //全部merge输出
             properties[i].SetValue(this, SlkParseUtil.ParseByType(properties[i].PropertyType, srr[i]));
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 决定转换
        /// </summary>
        /// <param name="info"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string GetPropertyValueConfig(PropertyInfo info, object obj)
        {
            var type  = info.PropertyType;
            var value = info.GetValue(obj);

            if (type.IsClass)
            {
                object infoObj = info.GetValue(obj);
                if (infoObj is IList)
                {
                    Type[] typeArguments = type.GetGenericArguments();
                    var    slkType       = typeArguments[0];
                    if (slkType.IsSubclassOf(typeof(SlkDataObject)))
                    {
                        IList ilist = infoObj as IList;
                        return(SlkParseUtil.SlkList2IdList(ilist));
                    }
                }
                if (type == typeof(List <string>))//ID 表
                {
                    return(SlkParseUtil.IdList2Config((List <string>)value));
                }
                if (type == typeof(RandomWeightPool <string>))//ID 池
                {
                    return(SlkParseUtil.IdPool2Config((RandomWeightPool <string>)value));
                }
                if (type.IsSubclassOf(typeof(SlkDataObject)))
                {
                    //--引用SLKData對象就返回ID--
                    return(((SlkDataObject)value).Id);
                }
            }
            return(value.ToString());
        }
Esempio n. 3
0
        public string GetJassConfig()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < RefRooms.Count; i++)
            {
                sb.AppendLine(string.Format("set dataArr[{0}] = \"{1}\"", i + 1, SlkParseUtil.GetIdRefObjectJass <SLK_Room>(RefRooms[i])));
                //sb.AppendLine(string.Format("set DungeonLevel_dataArr[{0}] = \"{1}\"", i + 1, SlkParseUtil.GetIdRefObjectJass<SLK_Room>(RefRooms[i])));
            }
            sb.AppendLine(string.Format("call RecordConfig({0},{1})", RefRooms.Count, this.IsRandom.ToString().ToLower()));
            return(sb.ToString());
        }
Esempio n. 4
0
        public override void Slk_DeSerialize(object data)
        {
            TryAutoDeSerialize(data);
            return;

            string[] srr = (string[])data;
            if (srr != null)
            {
                Id           = srr[0];
                WeUnitTypeId = srr[1];
                CombatPower  = SlkParseUtil.Parse2Int(srr[2]);
            }
        }
Esempio n. 5
0
        public override void Slk_DeSerialize(object data)
        {
            TryAutoDeSerialize(data);
            return;

            string[] srr = (string[])data;
            if (srr != null)
            {
                Id       = srr[0];
                IsRandom = SlkParseUtil.Parse2Bool(srr[1]);
                RefRooms = SlkParseUtil.Config2IdList(srr[2]);
            }
        }
Esempio n. 6
0
        public override void Slk_DeSerialize(object data)
        {
            TryAutoDeSerialize(data);
            return;

            string[] srr = (string[])data;
            if (srr != null)
            {
                Id          = srr[0];
                Items       = SlkParseUtil.Config2IdList(srr[1]);
                ItemPool    = SlkParseUtil.Config2IdPool(srr[2]);
                RandomCount = SlkParseUtil.Parse2Int(srr[3]);
            }
        }
Esempio n. 7
0
 public override void Slk_LateDeSerialize(object data)
 {
     string[] srr = (string[])data;
     if (srr != null)
     {
         Console.WriteLine("----------------");
         //引用Ins类型没有保存出去的数据
         //存在的意义是什么呢?在代码中修改的时候,能按照引用正确记录?比如改名
         RefRooms_Ins = SlkParseUtil.Config2SlkList <SLK_Room>(srr[2]);
         foreach (var refRoomsIn in RefRooms_Ins)
         {
             Console.WriteLine(refRoomsIn.Id);
         }
         Console.WriteLine("----------------");
     }
 }
Esempio n. 8
0
        public override void Slk_DeSerialize(object data)
        {
            TryAutoDeSerialize(data);
            return;

            string[] srr = (string[])data;
            if (srr != null)
            {
                Id           = srr[0];
                PoolLastTime = SlkParseUtil.Parse2Float(srr[1]);
                PoolInterval = SlkParseUtil.Parse2Float(srr[2]);
                UnitPool     = SlkParseUtil.Config2IdPool(srr[3]);
                ListInterval = SlkParseUtil.Parse2Float(srr[4]);
                UnitList     = SlkParseUtil.Config2IdList(srr[5]);
            }
        }
Esempio n. 9
0
        public void ExportSpawnner2Jass()
        {
            //导出Spawnner 的jass
            StringBuilder sb   = new StringBuilder();
            var           list = SlkManager.Instance.UnitSpawnnerTab.GetAllData();

            for (int i = 0; i < list.Count; i++)
            {
                var spawnner     = list[i];
                var poolName     = "";
                var lastTime     = spawnner.PoolLastTime.ToString("f2");
                var poolInterval = spawnner.PoolInterval.ToString("f2");
                var listName     = "";
                var listInterval = spawnner.ListInterval.ToString("f2");
                sb.AppendLine(string.Format("//--ConfigBegin--{0}--", spawnner.Id));
                if (!spawnner.UnitPool.IsEmpty())
                {
                    poolName = "pool_" + spawnner.Id;
                    foreach (var pair in spawnner.UnitPool.GetMapCopy())
                    {
                        var data   = SlkParseUtil.GetIdRefObjectJass <SLK_Unit>(pair.Key);
                        var weight = pair.Value.ToString("f2");
                        sb.AppendLine(string.Format("call WeightPoolLib_RegistPool_Int(\"{0}\",{1},{2})", poolName, data,
                                                    weight));
                    }
                }
                if (spawnner.UnitList.Count > 0)
                {
                    listName = "list_" + spawnner.Id;
                    foreach (var unit in spawnner.UnitList)
                    {
                        var data   = SlkParseUtil.GetIdRefObjectJass <SLK_Unit>(unit);
                        var weight = 1;
                        sb.AppendLine(string.Format("call WeightPoolLib_RegistPool_Int(\"{0}\",{1},{2})", listName, data,
                                                    weight));
                    }
                }
                sb.AppendLine(string.Format("call RecordSpawnnerCfg(\"{0}\",{1},{2},\"{3}\",{4})", poolName, lastTime, poolInterval, listName, listInterval));
                sb.AppendLine();
            }
            File.WriteAllText(GetPathFileName(SlkManager.Instance.UnitSpawnnerTab.GetExportFileName()), sb.ToString());
        }
Esempio n. 10
0
        public void ExportLoot2Jass()
        {
            //导出Loot
            StringBuilder sb   = new StringBuilder();
            var           list = SlkManager.Instance.LootTab.GetAllData();

            for (int i = 0; i < list.Count; i++)
            {
                //列表存 随机池存
                var data = list[i];
                sb.AppendLine(string.Format("//--ConfigBegin--{0}--", data.Id));
                var listName = "";
                if (data.Items.Count > 0)
                {
                    listName = "list_" + data.Id;
                    foreach (var id in data.Items)
                    {
                        var item   = SlkParseUtil.GetIdRefObjectJass <SLK_LootItem>(id);
                        var weight = 1;
                        sb.AppendLine(string.Format("call WeightPoolLib_RegistPool_Int(\"{0}\",{1},{2})", listName, item, weight));
                    }
                }
                var poolName = "";
                if (!data.ItemPool.IsEmpty())
                {
                    poolName = "pool_" + data.Id;
                    foreach (var pair in data.ItemPool.GetMapCopy())
                    {
                        var item   = SlkParseUtil.GetIdRefObjectJass <SLK_LootItem>(pair.Key);
                        var weight = pair.Value.ToString("f2");
                        sb.AppendLine(string.Format("call WeightPoolLib_RegistPool_Int(\"{0}\",{1},{2})", poolName, item, weight));
                    }
                }
                sb.AppendLine(string.Format("call RecordLoot(\"{0}\",\"{1}\",{2},\"{3}\")", data.Id, poolName, data.RandomCount, listName));
                sb.AppendLine();
            }
            File.WriteAllText(GetPathFileName(SlkManager.Instance.LootTab.GetExportFileName()), sb.ToString());
        }
Esempio n. 11
0
 /// <summary>
 /// 尝试直接自动转换掉
 /// </summary>
 /// <param name="data"></param>
 public void TryAutoDeSerialize(object data)
 {
     string[] srr = (string[])data;
     if (srr != null)
     {
         Id = srr[0];
         StringBuilder sb         = new StringBuilder();
         var           properties = this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();
         //无标签的无效
         properties.RemoveAll((info => info.GetCustomAttribute <SlkPropertyAttribute>() == null));
         properties.Sort((p1, p2) =>
         {
             var p1Index = p1.GetCustomAttribute <SlkPropertyAttribute>();
             var p2Index = p2.GetCustomAttribute <SlkPropertyAttribute>();
             var p1i     = p1Index != null ? p1Index.Index : int.MaxValue;
             var p2i     = p2Index != null ? p2Index.Index : int.MaxValue;
             return(p1i - p2i);
         });
         int lastIndex = 0;
         foreach (var propertyInfo in properties)
         {
             var atb   = propertyInfo.GetCustomAttribute <SlkPropertyAttribute>();
             var index = atb.Index;
             if (index == lastIndex)
             {
                 //保证相同的标签 都为1 也一样能自增
                 index++;
             }
             index     = Math.Max(0, index);
             lastIndex = index;
             if (propertyInfo.PropertyType == typeof(int))
             {
                 propertyInfo.SetValue(this, SlkParseUtil.Parse2Int(srr[index]));
             }
             else if (propertyInfo.PropertyType == typeof(float))
             {
                 propertyInfo.SetValue(this, SlkParseUtil.Parse2Float(srr[index]));
             }
             else if (propertyInfo.PropertyType == typeof(double))
             {
                 propertyInfo.SetValue(this, SlkParseUtil.Parse2Double(srr[index]));
             }
             else if (propertyInfo.PropertyType == typeof(bool))
             {
                 propertyInfo.SetValue(this, SlkParseUtil.Parse2Bool(srr[index]));
             }
             else if (propertyInfo.PropertyType == typeof(string))
             {
                 propertyInfo.SetValue(this, srr[index]);
             }
             else if (propertyInfo.PropertyType == typeof(RandomWeightPool <string>))
             {
                 propertyInfo.SetValue(this, SlkParseUtil.Config2IdPool(srr[index]));
             }
             else if (propertyInfo.PropertyType == typeof(List <string>))
             {
                 propertyInfo.SetValue(this, SlkParseUtil.Config2IdList(srr[index]));
             }
             else if (propertyInfo.PropertyType.IsSubclassOf(typeof(SlkDataObject)))
             {
                 //现在都不直接饮用对象了,都是用ID
                 var obj = SlkManager.Instance.GetSlkData <SlkDataObject>(srr[index]);
                 propertyInfo.SetValue(this, obj);
             }
         }
     }
 }