public static Tower Create(TowerData towerData, int serialId, int level = 0) { Tower tower = ReferencePool.Acquire <Tower>(); tower.towerData = towerData; tower.Level = level; tower.SerialId = serialId; return(tower); }
protected override void OnLoad() { DataProjectile dataProjectile = GameEntry.Data.GetData <DataProjectile>(); if (dataProjectile == null) { Log.Error("Can't load DataProjectile"); return; } dtTower = GameEntry.DataTable.GetDataTable <DRTower>(); if (dtTower == null) { throw new System.Exception("Can not get data table Tower"); } dtTowerLevel = GameEntry.DataTable.GetDataTable <DRTowerLevel>(); if (dtTowerLevel == null) { throw new System.Exception("Can not get data table TowerLevel"); } dicTowerData = new Dictionary <int, TowerData>(); dicTowerLevelData = new Dictionary <int, TowerLevelData>(); dicTower = new Dictionary <int, Tower>(); DRTowerLevel[] drTowerLevels = dtTowerLevel.GetAllDataRows(); foreach (var drTowerLevel in drTowerLevels) { if (dicTowerLevelData.ContainsKey(drTowerLevel.Id)) { throw new System.Exception(string.Format("Data tower level id '{0}' duplicate.", drTowerLevel.Id)); } ProjectileData projectileData = dataProjectile.GetProjectileData(drTowerLevel.ProjectileData); TowerLevelData towerLevelData = new TowerLevelData(drTowerLevel, projectileData); dicTowerLevelData.Add(drTowerLevel.Id, towerLevelData); } DRTower[] drTowers = dtTower.GetAllDataRows(); foreach (var drTower in drTowers) { TowerLevelData[] towerLevelDatas = new TowerLevelData[drTower.Levels.Length]; for (int i = 0; i < drTower.Levels.Length; i++) { if (!dicTowerLevelData.ContainsKey(drTower.Levels[i])) { throw new System.Exception(string.Format("Can not find tower level id '{0}' in DataTable TowerLevel.", drTower.Levels[i])); } towerLevelDatas[i] = dicTowerLevelData[drTower.Levels[i]]; } TowerData towerData = new TowerData(drTower, towerLevelDatas); dicTowerData.Add(drTower.Id, towerData); } }
public void Clear() { towerData = null; Level = 0; SerialId = 0; }
public Tower() { towerData = null; Level = 0; SerialId = 0; }