123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using CommonLang.IO;
- using CommonLang.XCSV;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace XmdsCommonServer.Plugin.XmdsSkillTemplate
- {
- /// <summary>
- /// FileName: XmdsSkillDataMgr.cs
- /// Author: Alex.Yu
- /// Corporation:...
- /// Description: 技能数值管理类.
- /// DateTime: 2015/5/19 19:50:44
- /// </summary>
- 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<int, Dictionary<int,int>> mSkillData = null;
- private static void InitData(string path)
- {
- mSkillData = InitSkillConfig(Resource.FormatPath(path + FILE_PATH));
- }
- private static Dictionary<int, Dictionary<int, int>> InitSkillConfig(string path)
- {
- string text = Resource.LoadAllText(path);
- List<SkillConfigLine> lines = CsvParser.LoadCSVObjectList<SkillConfigLine>(text);
- Dictionary<int, Dictionary<int, int>> ret = new Dictionary<int, Dictionary<int, int>>();
- 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<int, int> DictoryParserValue(string context)
- {
- Dictionary<int, int> ret = new Dictionary<int, int>();
- 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<int,int> 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;
- }
- }
- }
|