using CommonLang.IO; using CommonLang.XCSV; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace XmdsCommonServer.Plugin.XmdsSkillTemplate { /// /// FileName: XmdsSkillDataMgr.cs /// Author: Alex.Yu /// Corporation:... /// Description: 技能数值管理类. /// DateTime: 2015/5/19 19:50:44 /// public class XmdsSkillDataMgr { private const string FILE_PATH = "/data_config/skill_config.csv"; private static XmdsSkillDataMgr mInstance = null; public static XmdsSkillDataMgr Instance { get { return mInstance; } } public static void Init(string rootPath) { new XmdsSkillDataMgr(); InitData(rootPath); } private XmdsSkillDataMgr() { mInstance = this; } private static Dictionary> mSkillData = null; private static void InitData(string path) { mSkillData = InitSkillConfig(Resource.FormatPath(path + FILE_PATH)); } private static Dictionary> InitSkillConfig(string path) { string text = Resource.LoadAllText(path); List lines = CsvParser.LoadCSVObjectList(text); Dictionary> ret = new Dictionary>(); foreach(SkillConfigLine line in lines) { if(line.ID != null && line.VALUE != null) { #region Debug. /* int id = 0; if(int.TryParse(line.ID, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out id)) { mSkillData.Add(id, DictoryParserValue(line.VALUE)); } else { XmdsVirtual.FormatLog("XmdsSkillData InitData Error:公式ID = {0}", line.ID); break; } */ #endregion ret.Add(int.Parse(line.ID), DictoryParserValue(line.VALUE)); } } return ret; } private static Dictionary DictoryParserValue(string context) { Dictionary ret = new Dictionary(); context = context.Replace('{', ' '); context = context.Replace('}', ' '); string[] rlt = context.Split(','); if(rlt != null) { int l = rlt.Length; int v = 0; for(int i = 0; i < l; i++) { v = 0; #region Debug. //if(!int.TryParse(rlt[i], System.Globalization.NumberStyles.Integer, // System.Globalization.CultureInfo.InvariantCulture, out v)) //{ // XmdsVirtual.FormatLog("XmdsSkillData Parser Error:公式ID = {0}等级 = {1}", i, rlt[i]); //} #endregion v = int.Parse(rlt[i]); ret.Add(i, v); } } return ret; } //获取技能数据信息. public int GetXmdsSkillData(int formualID, int lv) { Dictionary ret = null; int rlt = 0; if(mSkillData.TryGetValue(formualID, out ret)) { if(ret.TryGetValue(lv - 1, out rlt)) { return rlt; } else { XmdsVirtual.FormatLog("GetXmdsSkillData Error:公式ID = {0}等级 = {1}", formualID, lv); } } else { XmdsVirtual.FormatLog("GetXmdsSkillData Error:公式ID = {0}等级 = {1}", formualID, lv); } return 0; } internal class SkillConfigLine { public string ID = null; public string VALUE = null; } } }