XLSMonsterDynamicLoader.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using CommonLang;
  2. using CommonLang.IO;
  3. using NPOI.HSSF.UserModel;
  4. using NPOI.SS.UserModel;
  5. using NPOI.XSSF.UserModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using XmdsCommonServer.XLS.Data;
  12. namespace XmdsCommonServer.XLS
  13. {
  14. public class XLSMonsterDynamicLoader : XLSLoader
  15. {
  16. private HashMap<String, MonsterProp> SingleMonsterMap = new HashMap<string, MonsterProp>();
  17. private HashMap<String, MonsterProp> MultipleMonsterMap = new HashMap<string, MonsterProp>();
  18. private HashMap<int, OrigData> OrigDataMap = new HashMap<int, OrigData>();
  19. private HashMap<int, UserDefineConfig> UserDefineConfigMap = new HashMap<int, UserDefineConfig>();
  20. private HashMap<int, DungeonMonsterRatio> DungeonMonsterRatioMap = new HashMap<int, DungeonMonsterRatio>();
  21. private HashMap<String, float> MonsterDataConfigMap = new HashMap<String, float>();
  22. private HashMap<int, TowerMonsterRatio> TowerMonsterRatioMap = new HashMap<int, TowerMonsterRatio>();
  23. //深渊怪物属性加成
  24. private HashMap<int, TowerMonsterRatio> abyssMonsterRatioMap = new HashMap<int, TowerMonsterRatio>();
  25. private HashMap<int, GuildBossRatio> GuildBossRatioMap = new HashMap<int, GuildBossRatio>();
  26. public float Mon_Hp_Ratio;
  27. public float Mon_Atk_Ratio;
  28. public float LevelPoint;
  29. public float DefRatio;
  30. public XLSMonsterDynamicLoader(string path)
  31. {
  32. byte[] data = Resource.LoadData(path);
  33. if (data == null)
  34. {
  35. throw new Exception("Can not read xls file : " + path);
  36. }
  37. using (MemoryStream ms = new MemoryStream(data))
  38. {
  39. IWorkbook Workbook = null;
  40. if (path.Contains(".xlsx"))
  41. {
  42. Workbook = new XSSFWorkbook(ms);
  43. }
  44. else if (path.Contains(".xls"))
  45. {
  46. Workbook = new HSSFWorkbook(ms);
  47. }
  48. for (int si = 0; si < Workbook.NumberOfSheets; si++)
  49. {
  50. ISheet sheet = Workbook.GetSheetAt(si) as ISheet;
  51. try
  52. {
  53. }
  54. catch (Exception error)
  55. {
  56. throw new Exception(string.Format("XLSMonsterDynamicLoader 初始化怪物配置错误SheetName = {0},Error = {1}",
  57. sheet.SheetName, error.ToString()));
  58. }
  59. if (sheet.SheetName.Equals("single_mon"))
  60. {
  61. loadMonsterProp(sheet, SingleMonsterMap);
  62. }
  63. else if (sheet.SheetName.Equals("multiple_mon"))
  64. {
  65. loadMonsterProp(sheet, MultipleMonsterMap);
  66. }
  67. else if (sheet.SheetName.Equals("orig_data"))
  68. {
  69. loadOrigData(sheet);
  70. }
  71. else if (sheet.SheetName.Equals("user_define_config"))
  72. {
  73. loadUserDefineConfig(sheet);
  74. }
  75. else if (sheet.SheetName.Equals("dungeon_mon_ratio"))
  76. {
  77. loadDungeonMonsterRatio(sheet);
  78. }
  79. else if (sheet.SheetName.Equals("tower_mon_ratio"))
  80. {
  81. loadTowerMonsterRatio(sheet);
  82. }
  83. else if (sheet.SheetName.Equals("guild_boss_ratio"))
  84. {
  85. loadGuildBossRatio(sheet);
  86. }
  87. else if (sheet.SheetName.Equals("mon_data_config"))
  88. {
  89. loadMonsterDataConfig(sheet);
  90. }
  91. else if (sheet.SheetName.Equals("abyss_mon_ratio"))
  92. {
  93. loadAbyssMonsterRatio(sheet);
  94. }
  95. }
  96. }
  97. }
  98. internal MonsterProp GetSingleMonsterProp(int level,int type)
  99. {
  100. MonsterProp ret = null;
  101. string key = string.Format("{0}_{1}", level, type);
  102. SingleMonsterMap.TryGetValue(key, out ret);
  103. if (ret == null)
  104. {
  105. log.Error(string.Format("XLSLoader GetSingleMonsterProp Error:level = {0} type = {1} ", level, type));
  106. }
  107. return ret;
  108. }
  109. internal MonsterProp GetMultipleMonsterProp(int level, int type)
  110. {
  111. MonsterProp ret = null;
  112. string key = string.Format("{0}_{1}", level, type);
  113. MultipleMonsterMap.TryGetValue(key, out ret);
  114. if (ret == null)
  115. {
  116. log.Error(string.Format("XLSLoader GetMultipleMonsterProp Error:level = {0} type = {1} ", level, type));
  117. }
  118. return ret;
  119. }
  120. internal OrigData GetOrigData(int level)
  121. {
  122. OrigData ret = null;
  123. OrigDataMap.TryGetValue(level, out ret);
  124. if (ret == null)
  125. {
  126. log.Error(string.Format("XLSLoader GetOrigData Error:level = {0} ", level));
  127. }
  128. return ret;
  129. }
  130. internal TowerMonsterRatio GetTowerMonsterRatio(int floor)
  131. {
  132. TowerMonsterRatio ret = null;
  133. TowerMonsterRatioMap.TryGetValue(floor, out ret);
  134. if (ret == null)
  135. {
  136. log.Error(string.Format("XLSLoader GetTowerMonsterRatio Error:floor = {0} ", floor));
  137. }
  138. return ret;
  139. }
  140. internal TowerMonsterRatio GetAbyssMonsterRatio(int floor)
  141. {
  142. TowerMonsterRatio ret = null;
  143. abyssMonsterRatioMap.TryGetValue(floor, out ret);
  144. if (ret == null)
  145. {
  146. log.Error(string.Format("XLSLoader GetAbyssMonsterRatio Error:floor = {0} ", floor));
  147. }
  148. return ret;
  149. }
  150. internal GuildBossRatio GetGuildBossRatio(int bossLv)
  151. {
  152. GuildBossRatio ret = null;
  153. GuildBossRatioMap.TryGetValue(bossLv, out ret);
  154. if (ret == null)
  155. {
  156. log.Error(string.Format("XLSLoader GetGuildBossRatio Error:BossLv = {0} ", bossLv));
  157. }
  158. return ret;
  159. }
  160. internal UserDefineConfig GetUserDefineConfig(int type)
  161. {
  162. UserDefineConfig ret = null;
  163. UserDefineConfigMap.TryGetValue(type, out ret);
  164. if (ret == null)
  165. {
  166. log.Error(string.Format("XLSLoader GetUserDefineConfig Error:type = {0} ", type));
  167. }
  168. return ret;
  169. }
  170. internal DungeonMonsterRatio GetDungeonMonsterRatio(int type)
  171. {
  172. DungeonMonsterRatio ret = null;
  173. DungeonMonsterRatioMap.TryGetValue(type, out ret);
  174. if (ret == null)
  175. {
  176. log.Error(string.Format("XLSLoader GetDungeonMonsterRatio Error:type = {0} ", type));
  177. }
  178. return ret;
  179. }
  180. private void loadMonsterProp(ISheet sheet, HashMap<String, MonsterProp> map)
  181. {
  182. int index = 0;
  183. string key = null;
  184. try
  185. {
  186. foreach (MonsterProp m in LoadSheet<MonsterProp>(sheet))
  187. {
  188. key = string.Format("{0}_{1}", m.Mon_Level, m.Mon_Type);
  189. map.Add(key, m);
  190. }
  191. }
  192. catch (Exception error)
  193. {
  194. throw new Exception(string.Format("XLSMonsterProp Error : index = {0} name = {1} Error = {2}", index, key, error.ToString()));
  195. }
  196. }
  197. private void loadOrigData(ISheet sheet)
  198. {
  199. int index = 0;
  200. try
  201. {
  202. foreach (OrigData m in LoadSheet<OrigData>(sheet))
  203. {
  204. OrigDataMap.Add(m.Level, m);
  205. }
  206. }
  207. catch (Exception error)
  208. {
  209. throw new Exception(string.Format("XLSOrigData Error : index = {0} Error = {1}", index, error.ToString()));
  210. }
  211. }
  212. private void loadUserDefineConfig(ISheet sheet)
  213. {
  214. int index = 0;
  215. try
  216. {
  217. foreach (UserDefineConfig m in LoadSheet<UserDefineConfig>(sheet))
  218. {
  219. UserDefineConfigMap.Add(m.Mon_Type, m);
  220. }
  221. }
  222. catch (Exception error)
  223. {
  224. throw new Exception(string.Format("XLSUserDefineConfig Error : index = {0} Error = {1}", index, error.ToString()));
  225. }
  226. }
  227. private void loadDungeonMonsterRatio(ISheet sheet)
  228. {
  229. int index = 0;
  230. try
  231. {
  232. foreach (DungeonMonsterRatio m in LoadSheet<DungeonMonsterRatio>(sheet))
  233. {
  234. DungeonMonsterRatioMap.Add(m.Mon_Type, m);
  235. }
  236. }
  237. catch (Exception error)
  238. {
  239. throw new Exception(string.Format("XLSDungeonMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
  240. }
  241. }
  242. private void loadTowerMonsterRatio(ISheet sheet)
  243. {
  244. int index = 0;
  245. try
  246. {
  247. foreach (TowerMonsterRatio m in LoadSheet<TowerMonsterRatio>(sheet))
  248. {
  249. TowerMonsterRatioMap.Add(m.Tower_Floor, m);
  250. }
  251. }
  252. catch (Exception error)
  253. {
  254. throw new Exception(string.Format("XLSTowerMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
  255. }
  256. }
  257. private void loadAbyssMonsterRatio(ISheet sheet)
  258. {
  259. int index = 0;
  260. try
  261. {
  262. foreach (TowerMonsterRatio m in LoadSheet<TowerMonsterRatio>(sheet))
  263. {
  264. abyssMonsterRatioMap.Add(m.Tower_Floor, m);
  265. }
  266. }
  267. catch (Exception error)
  268. {
  269. throw new Exception(string.Format("XLSTowerMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
  270. }
  271. }
  272. private void loadGuildBossRatio(ISheet sheet)
  273. {
  274. int index = 0;
  275. try
  276. {
  277. foreach (GuildBossRatio m in LoadSheet<GuildBossRatio>(sheet))
  278. {
  279. GuildBossRatioMap.Add(m.GBoss_Lv, m);
  280. }
  281. }
  282. catch (Exception error)
  283. {
  284. throw new Exception(string.Format("XLSGuildBossRatio Error : index = {0} Error = {1}", index, error.ToString()));
  285. }
  286. }
  287. private void loadMonsterDataConfig(ISheet sheet)
  288. {
  289. int index = 0;
  290. try
  291. {
  292. foreach (MonsterDataConfig m in LoadSheet<MonsterDataConfig>(sheet))
  293. {
  294. MonsterDataConfigMap.Add(m.ParamName, m.ParamValue);
  295. }
  296. MonsterDataConfigMap.TryGetValue("Mon_Hp_Ratio", out Mon_Hp_Ratio);
  297. MonsterDataConfigMap.TryGetValue("Mon_Atk_Ratio", out Mon_Atk_Ratio);
  298. MonsterDataConfigMap.TryGetValue("LevelPoint", out LevelPoint);
  299. MonsterDataConfigMap.TryGetValue("DefRatio", out DefRatio);
  300. }
  301. catch (Exception error)
  302. {
  303. throw new Exception(string.Format("XLSDungeonMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
  304. }
  305. }
  306. }
  307. }