123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
-
- 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<int, int> mMapMountainKing = new HashMap<int, int>();
- //山大王列表
- private static HashSet<int> mKings = new HashSet<int>();
- 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<MountainKingConfig>(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<int> GetMountainKings()
- {
- return mKings;
- }
- public int GetMapKing(int mapId)
- {
- return mMapMountainKing.Get(mapId);
- }
- }
- }
|