public void SellTower(int serialId) { if (!dicTower.ContainsKey(serialId)) { Log.Error("Can not find tower serialId '{0}'.", serialId); return; } DataLevel dataLevel = GameEntry.Data.GetData <DataLevel>(); if (dataLevel.LevelState != EnumLevelState.Prepare && dataLevel.LevelState != EnumLevelState.Normal) { return; } Tower tower = dicTower[serialId]; GameEntry.Event.Fire(this, HideTowerInLevelEventArgs.Create(tower.SerialId)); DataPlayer dataPlayer = GameEntry.Data.GetData <DataPlayer>(); if (dataLevel.LevelState == EnumLevelState.Prepare) { dataPlayer.AddEnergy(tower.TotalCostEnergy); } else if (dataLevel.LevelState == EnumLevelState.Normal) { dataPlayer.AddEnergy(tower.SellEnergy); } }
public void UpgradeTower(int serialId) { if (!dicTower.ContainsKey(serialId)) { Log.Error("Can not find tower serialId '{0}'.", serialId); return; } Tower tower = dicTower[serialId]; if (tower.Level >= tower.MaxLevel) { Log.Error("Tower (id:'{0}') has reached the highest level", serialId); return; } DataPlayer dataPlayer = GameEntry.Data.GetData <DataPlayer>(); int needEnergy = tower.GetBuildEnergy(tower.Level + 1); if (dataPlayer.Energy < needEnergy) { Log.Error("Energy lack,need {0},current is {1}", needEnergy, dataPlayer.Energy); return; } dataPlayer.AddEnergy(-needEnergy); int lastLevel = tower.Level; tower.Upgrade(); GameEntry.Event.Fire(this, UpgradeTowerEventArgs.Create(tower, lastLevel)); }