123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- 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 System.Linq;
- using System.Text;
- using XmdsCommonServer.XLS.Data;
- namespace XmdsCommonServer.XLS
- {
- public class XLSMonsterDynamicLoader : XLSLoader
- {
- private HashMap<String, MonsterProp> SingleMonsterMap = new HashMap<string, MonsterProp>();
- private HashMap<String, MonsterProp> MultipleMonsterMap = new HashMap<string, MonsterProp>();
- private HashMap<int, OrigData> OrigDataMap = new HashMap<int, OrigData>();
- private HashMap<int, UserDefineConfig> UserDefineConfigMap = new HashMap<int, UserDefineConfig>();
- private HashMap<int, DungeonMonsterRatio> DungeonMonsterRatioMap = new HashMap<int, DungeonMonsterRatio>();
- private HashMap<String, float> MonsterDataConfigMap = new HashMap<String, float>();
- private HashMap<int, TowerMonsterRatio> TowerMonsterRatioMap = new HashMap<int, TowerMonsterRatio>();
- //深渊怪物属性加成
- private HashMap<int, TowerMonsterRatio> abyssMonsterRatioMap = new HashMap<int, TowerMonsterRatio>();
- private HashMap<int, GuildBossRatio> GuildBossRatioMap = new HashMap<int, GuildBossRatio>();
- public float Mon_Hp_Ratio;
- public float Mon_Atk_Ratio;
- public float LevelPoint;
- public float DefRatio;
-
- public XLSMonsterDynamicLoader(string path)
- {
- 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
- {
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSMonsterDynamicLoader 初始化怪物配置错误SheetName = {0},Error = {1}",
- sheet.SheetName, error.ToString()));
- }
- if (sheet.SheetName.Equals("single_mon"))
- {
- loadMonsterProp(sheet, SingleMonsterMap);
- }
- else if (sheet.SheetName.Equals("multiple_mon"))
- {
- loadMonsterProp(sheet, MultipleMonsterMap);
- }
- else if (sheet.SheetName.Equals("orig_data"))
- {
- loadOrigData(sheet);
- }
- else if (sheet.SheetName.Equals("user_define_config"))
- {
- loadUserDefineConfig(sheet);
- }
- else if (sheet.SheetName.Equals("dungeon_mon_ratio"))
- {
- loadDungeonMonsterRatio(sheet);
- }
- else if (sheet.SheetName.Equals("tower_mon_ratio"))
- {
- loadTowerMonsterRatio(sheet);
- }
- else if (sheet.SheetName.Equals("guild_boss_ratio"))
- {
- loadGuildBossRatio(sheet);
- }
- else if (sheet.SheetName.Equals("mon_data_config"))
- {
- loadMonsterDataConfig(sheet);
- }
- else if (sheet.SheetName.Equals("abyss_mon_ratio"))
- {
- loadAbyssMonsterRatio(sheet);
- }
- }
- }
- }
- internal MonsterProp GetSingleMonsterProp(int level,int type)
- {
- MonsterProp ret = null;
- string key = string.Format("{0}_{1}", level, type);
- SingleMonsterMap.TryGetValue(key, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetSingleMonsterProp Error:level = {0} type = {1} ", level, type));
- }
- return ret;
- }
- internal MonsterProp GetMultipleMonsterProp(int level, int type)
- {
- MonsterProp ret = null;
- string key = string.Format("{0}_{1}", level, type);
- MultipleMonsterMap.TryGetValue(key, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetMultipleMonsterProp Error:level = {0} type = {1} ", level, type));
- }
- return ret;
- }
- internal OrigData GetOrigData(int level)
- {
- OrigData ret = null;
- OrigDataMap.TryGetValue(level, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetOrigData Error:level = {0} ", level));
- }
- return ret;
- }
- internal TowerMonsterRatio GetTowerMonsterRatio(int floor)
- {
- TowerMonsterRatio ret = null;
- TowerMonsterRatioMap.TryGetValue(floor, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetTowerMonsterRatio Error:floor = {0} ", floor));
- }
- return ret;
- }
- internal TowerMonsterRatio GetAbyssMonsterRatio(int floor)
- {
- TowerMonsterRatio ret = null;
- abyssMonsterRatioMap.TryGetValue(floor, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetAbyssMonsterRatio Error:floor = {0} ", floor));
- }
- return ret;
- }
- internal GuildBossRatio GetGuildBossRatio(int bossLv)
- {
- GuildBossRatio ret = null;
- GuildBossRatioMap.TryGetValue(bossLv, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetGuildBossRatio Error:BossLv = {0} ", bossLv));
- }
- return ret;
- }
- internal UserDefineConfig GetUserDefineConfig(int type)
- {
- UserDefineConfig ret = null;
- UserDefineConfigMap.TryGetValue(type, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetUserDefineConfig Error:type = {0} ", type));
- }
- return ret;
- }
- internal DungeonMonsterRatio GetDungeonMonsterRatio(int type)
- {
- DungeonMonsterRatio ret = null;
- DungeonMonsterRatioMap.TryGetValue(type, out ret);
- if (ret == null)
- {
- log.Error(string.Format("XLSLoader GetDungeonMonsterRatio Error:type = {0} ", type));
- }
- return ret;
- }
-
- private void loadMonsterProp(ISheet sheet, HashMap<String, MonsterProp> map)
- {
- int index = 0;
- string key = null;
- try
- {
- foreach (MonsterProp m in LoadSheet<MonsterProp>(sheet))
- {
- key = string.Format("{0}_{1}", m.Mon_Level, m.Mon_Type);
- map.Add(key, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSMonsterProp Error : index = {0} name = {1} Error = {2}", index, key, error.ToString()));
- }
- }
- private void loadOrigData(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (OrigData m in LoadSheet<OrigData>(sheet))
- {
- OrigDataMap.Add(m.Level, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSOrigData Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- private void loadUserDefineConfig(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (UserDefineConfig m in LoadSheet<UserDefineConfig>(sheet))
- {
- UserDefineConfigMap.Add(m.Mon_Type, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSUserDefineConfig Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- private void loadDungeonMonsterRatio(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (DungeonMonsterRatio m in LoadSheet<DungeonMonsterRatio>(sheet))
- {
- DungeonMonsterRatioMap.Add(m.Mon_Type, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSDungeonMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- private void loadTowerMonsterRatio(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (TowerMonsterRatio m in LoadSheet<TowerMonsterRatio>(sheet))
- {
- TowerMonsterRatioMap.Add(m.Tower_Floor, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSTowerMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- private void loadAbyssMonsterRatio(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (TowerMonsterRatio m in LoadSheet<TowerMonsterRatio>(sheet))
- {
- abyssMonsterRatioMap.Add(m.Tower_Floor, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSTowerMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- private void loadGuildBossRatio(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (GuildBossRatio m in LoadSheet<GuildBossRatio>(sheet))
- {
- GuildBossRatioMap.Add(m.GBoss_Lv, m);
- }
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSGuildBossRatio Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- private void loadMonsterDataConfig(ISheet sheet)
- {
- int index = 0;
- try
- {
- foreach (MonsterDataConfig m in LoadSheet<MonsterDataConfig>(sheet))
- {
- MonsterDataConfigMap.Add(m.ParamName, m.ParamValue);
- }
- MonsterDataConfigMap.TryGetValue("Mon_Hp_Ratio", out Mon_Hp_Ratio);
- MonsterDataConfigMap.TryGetValue("Mon_Atk_Ratio", out Mon_Atk_Ratio);
- MonsterDataConfigMap.TryGetValue("LevelPoint", out LevelPoint);
- MonsterDataConfigMap.TryGetValue("DefRatio", out DefRatio);
- }
- catch (Exception error)
- {
- throw new Exception(string.Format("XLSDungeonMonsterRatio Error : index = {0} Error = {1}", index, error.ToString()));
- }
- }
- }
- }
|