using CommonLang; using CommonLang.IO; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.IO; using XmdsCommonServer.XLS.Data; namespace XmdsCommonServer.XLS { public class XLSMountainKingConfigLoader : XLSLoader { //场景id,山大王 private static HashMap mMapMountainKing = new HashMap(); //山大王列表 private static HashSet mKings = new HashSet(); public XLSMountainKingConfigLoader(string path) { mMapMountainKing.Clear(); byte[] data = Resource.LoadData(path); if (data == null) { throw new Exception("Can not read xls file : " + path); } using (MemoryStream ms = new MemoryStream(data)) { IWorkbook Workbook = null; if (path.Contains(".xlsx")) { Workbook = new XSSFWorkbook(ms); } else if (path.Contains(".xls")) { Workbook = new HSSFWorkbook(ms); } for (int si = 0; si < Workbook.NumberOfSheets; si++) { ISheet sheet = Workbook.GetSheetAt(si) as ISheet; try { if (sheet.SheetName == "MountainKingConfig") { LoadSheet(sheet); } } catch (Exception error) { throw new Exception(string.Format("XLSRandomMonsterSkillLoader 初始化怪物配置错误SheetName = {0},Error = {1}", sheet.SheetName, error.ToString())); } } } log.Info("XLSMountainKingConfigLoader 初山大王场景配置完成."); } private void LoadSheet(ISheet sheet) { try { foreach (MountainKingConfig m in LoadSheet(sheet)) { if(m.MapId == null || m.MapId.Length <= 0) { continue; } string[] mapIds = m.MapId.Split(';'); foreach(string mapId in mapIds) { mMapMountainKing.Put(int.Parse(mapId), m.ID); } mKings.Add(m.ID); } } catch (Exception error) { throw new Exception(string.Format("XLSRandomMonsterSkillLoader Error : index = {0} Error = {1}", 0, error.ToString())); } log.Info(string.Format("loadSheet【{0}】Complete", sheet.SheetName)); } public HashSet GetMountainKings() { return mKings; } public int GetMapKing(int mapId) { return mMapMountainKing.Get(mapId); } } }