XmdsSkillDataMgr.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using CommonLang.IO;
  2. using CommonLang.XCSV;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace XmdsCommonServer.Plugin.XmdsSkillTemplate
  8. {
  9. /// <summary>
  10. /// FileName: XmdsSkillDataMgr.cs
  11. /// Author: Alex.Yu
  12. /// Corporation:...
  13. /// Description: 技能数值管理类.
  14. /// DateTime: 2015/5/19 19:50:44
  15. /// </summary>
  16. public class XmdsSkillDataMgr
  17. {
  18. private const string FILE_PATH = "/data_config/skill_config.csv";
  19. private static XmdsSkillDataMgr mInstance = null;
  20. public static XmdsSkillDataMgr Instance { get { return mInstance; } }
  21. public static void Init(string rootPath)
  22. {
  23. new XmdsSkillDataMgr();
  24. InitData(rootPath);
  25. }
  26. private XmdsSkillDataMgr() { mInstance = this; }
  27. private static Dictionary<int, Dictionary<int,int>> mSkillData = null;
  28. private static void InitData(string path)
  29. {
  30. mSkillData = InitSkillConfig(Resource.FormatPath(path + FILE_PATH));
  31. }
  32. private static Dictionary<int, Dictionary<int, int>> InitSkillConfig(string path)
  33. {
  34. string text = Resource.LoadAllText(path);
  35. List<SkillConfigLine> lines = CsvParser.LoadCSVObjectList<SkillConfigLine>(text);
  36. Dictionary<int, Dictionary<int, int>> ret = new Dictionary<int, Dictionary<int, int>>();
  37. foreach(SkillConfigLine line in lines)
  38. {
  39. if(line.ID != null && line.VALUE != null)
  40. {
  41. #region Debug.
  42. /*
  43. int id = 0;
  44. if(int.TryParse(line.ID, System.Globalization.NumberStyles.Integer,
  45. System.Globalization.CultureInfo.InvariantCulture, out id))
  46. {
  47. mSkillData.Add(id, DictoryParserValue(line.VALUE));
  48. }
  49. else
  50. {
  51. XmdsVirtual.FormatLog("XmdsSkillData InitData Error:公式ID = {0}", line.ID);
  52. break;
  53. }
  54. */
  55. #endregion
  56. ret.Add(int.Parse(line.ID), DictoryParserValue(line.VALUE));
  57. }
  58. }
  59. return ret;
  60. }
  61. private static Dictionary<int, int> DictoryParserValue(string context)
  62. {
  63. Dictionary<int, int> ret = new Dictionary<int, int>();
  64. context = context.Replace('{', ' ');
  65. context = context.Replace('}', ' ');
  66. string[] rlt = context.Split(',');
  67. if(rlt != null)
  68. {
  69. int l = rlt.Length;
  70. int v = 0;
  71. for(int i = 0; i < l; i++)
  72. {
  73. v = 0;
  74. #region Debug.
  75. //if(!int.TryParse(rlt[i], System.Globalization.NumberStyles.Integer,
  76. // System.Globalization.CultureInfo.InvariantCulture, out v))
  77. //{
  78. // XmdsVirtual.FormatLog("XmdsSkillData Parser Error:公式ID = {0}等级 = {1}", i, rlt[i]);
  79. //}
  80. #endregion
  81. v = int.Parse(rlt[i]);
  82. ret.Add(i, v);
  83. }
  84. }
  85. return ret;
  86. }
  87. //获取技能数据信息.
  88. public int GetXmdsSkillData(int formualID, int lv)
  89. {
  90. Dictionary<int,int> ret = null;
  91. int rlt = 0;
  92. if(mSkillData.TryGetValue(formualID, out ret))
  93. {
  94. if(ret.TryGetValue(lv - 1, out rlt))
  95. {
  96. return rlt;
  97. }
  98. else
  99. {
  100. XmdsVirtual.FormatLog("GetXmdsSkillData Error:公式ID = {0}等级 = {1}", formualID, lv);
  101. }
  102. }
  103. else
  104. {
  105. XmdsVirtual.FormatLog("GetXmdsSkillData Error:公式ID = {0}等级 = {1}", formualID, lv);
  106. }
  107. return 0;
  108. }
  109. internal class SkillConfigLine
  110. {
  111. public string ID = null;
  112. public string VALUE = null;
  113. }
  114. }
  115. }