using LitJson; using System.Collections.Generic; using System.Linq; using TowerDefense.Level; using UnityEngine; namespace KTGMGemClient { public class MonsterSpeedUp { /// /// 加速的时间,秒为单位 /// public float speedTime; /// /// 场景内出怪的时间速度值 /// public float spawnTimeScale; /// /// 怪物移动的速度缩放值 /// public float moveSpeedScale; } public class JsonDataCenter { public static Dictionary> allData; /// /// 怪物加速相关的数据结构 /// public static List monSpeedUp; public static Dictionary gemInfoDic = new Dictionary(); public static Dictionary monsterDic = new Dictionary(); // 金币相关 public static float GOLD_TIME = 0; public static int GOLD_ADD = 0; // 购买塔位后开启倒计时. public static float GRIDOPEN_CDTIME = 10.0f; // 购塔升级开启倒计时时间 public static float TOWERLVLUP_CDTIME = 10.0f; // 技能塔的随机概率. public static double SKILLTOWER_RATE = 0.2f; // Svn版本信息. public static string SVNVERSION_INFO = ""; public static float DOUBLE_GEM_TIME = 10f; /// /// 根据id和Level获取skillLevelInfo数据 /// /// /// /// public static skilllevelinfo GetSkillLevelInfo(int sid, int slevel) { List allSkillLevelInfo = GetList(); for (int ti = 0; ti < allSkillLevelInfo.Count; ti++) { skilllevelinfo tinfo = allSkillLevelInfo[ti]; if ((tinfo.skill == sid) && (tinfo.level == slevel)) return tinfo; } return null; } public static T GetById(int id) where T : class { string tablename = typeof(T).Name; List datas = allData[tablename]; if (datas == null) { return null; } for (int i = 0; i < datas.Count; i++) { if (datas[i].getid() == id) { return datas[i] as T; } } return null; } public static List GetList() where T : class { string tablename = typeof(T).Name; return allData[tablename].Cast().ToList(); } /// /// 根据ID获取Buff相关的数据。 /// /// /// public static buffinfo GetBuffFromId(int id) { List allBuffinfo = GetList(); for (int ti = 0; ti < allBuffinfo.Count; ti++) { buffinfo tbuf = allBuffinfo[ti]; if (tbuf.id == id) return tbuf; } return null; } /// /// 根据传入的MonsterID和Level数据来获取monsterdata. /// /// /// /// public static monster GetMonsterData(int id, int lvl) { List alllMonster = GetList(); for (int ti = 0; ti < alllMonster.Count; ti++) { monster mon = alllMonster[ti]; if (mon.id == id && lvl == mon.level) return mon; } return null; } /// /// 根据索引返回召唤需要的金币数目. /// /// /// public static int GetGemCostFromIdx(int idx) { List allGemCostInfo = GetList(); if (idx >= allGemCostInfo.Count) idx = allGemCostInfo.Count - 1; return allGemCostInfo[idx].cost; } /// /// 数据调入完成后,初始化相关的数据。 /// public static void ProcessInitDataLoad() { monSpeedUp = new List(); List allBattleInfo = JsonDataCenter.GetList(); for (int ti = 0; ti < allBattleInfo.Count; ti++) { battle tbat = allBattleInfo[ti]; switch (tbat.key) { case "initialgold": // 设置初始化金币. int currency = tbat.value; if (LevelManager.instanceExists) LevelManager.instance.ResetCurrency(currency); if (OpponentMgr.instanceExists) OpponentMgr.instance.ResetCurrency(currency); if (EndlessLevelManager.instanceExists) EndlessLevelManager.instance.ResetCurrency(currency); break; case "skilltime": // 设置技能塔出现时间 if (RandomTower.instanceExists) RandomTower.SKILL_TOWER_TIME = tbat.value; else if (EndlessRandomTower.instanceExists) EndlessRandomTower.SKILL_TOWER_TIME = tbat.value; break; case "doublegem": // 购买宝石直接获取2级宝石的时间 DOUBLE_GEM_TIME = tbat.value; break; case "buildtime": GRIDOPEN_CDTIME = tbat.value; break; case "gemcountdown": TOWERLVLUP_CDTIME = tbat.value; break; case "skillchance": SKILLTOWER_RATE = tbat.value / 100.0f; break; case "SpeedUpFrist": MonsterSpeedUp tms = new MonsterSpeedUp(); string[] tsarr = tbat.strvarr[0].Split(':'); if (tsarr.Length != 3) Debug.Log("SpeedUpFrist 数据格式出错了."); else { tms.speedTime = int.Parse(tsarr[0]); tms.spawnTimeScale = float.Parse(tsarr[1]); tms.moveSpeedScale = float.Parse(tsarr[2]); monSpeedUp.Add(tms); //Debug.Log("第一次加速:" + tms.speedTime.ToString() + "," + tms.spawnTimeScale.ToString() + "," + tms.moveSpeedScale.ToString()); } break; case "SpeedUpSecond": MonsterSpeedUp tms1 = new MonsterSpeedUp(); string[] tsarr1 = tbat.strvarr[0].Split(':'); if (tsarr1.Length != 3) Debug.Log("SpeedUpSecond 数据格式出错了."); else { tms1.speedTime = int.Parse(tsarr1[0]); tms1.spawnTimeScale = float.Parse(tsarr1[1]); tms1.moveSpeedScale = float.Parse(tsarr1[2]); monSpeedUp.Add(tms1); } break; } } List allGeminfo = GetList(); foreach (geminfo item in allGeminfo) { if (!JsonDataCenter.gemInfoDic.ContainsKey(item.id)) JsonDataCenter.gemInfoDic.Add(item.id, item); } List alllMonster = GetList(); foreach (monster item in alllMonster) { if (!JsonDataCenter.monsterDic.ContainsKey(item.id)) JsonDataCenter.monsterDic.Add(item.id, item); } List alllgoldInfo = GetList(); foreach (goldInfo item in alllgoldInfo) { JsonDataCenter.GOLD_ADD = item.gold; JsonDataCenter.GOLD_TIME = item.time; } InitData(); } /// /// 表数据处理类初始化 /// private static void InitData() { EndlessEnemyData.Init(); EndlessBuffData.Init(); EndlessBossData.Init(); EndlessBossSkillData.Init(); ElfInfoData.Init(); ElfUpgradeData.Init(); GameConfig.JsonReadDone = true; } } }