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);
            }
        }
Ejemplo n.º 2
0
        public void Reset()
        {
            int lastHP = HP;

            HP = GameEntry.Config.GetInt(Constant.Config.PlayerHP);
            //HP = 100;
            GameEntry.Event.Fire(this, PlayerHPChangeEventArgs.Create(lastHP, HP));

            float     lastEnergy = Energy;
            DataLevel dataLevel  = GameEntry.Data.GetData <DataLevel>();

            if (!dataLevel.IsInLevel)
            {
                Log.Error("Is invaild to get player energy outsiede level scene");
                Energy = lastEnergy;
            }
            else
            {
                LevelData levelData = dataLevel.GetLevelData(dataLevel.CurrentLevelIndex);
                Energy = levelData.InitEnergy;
            }

            GameEntry.Event.Fire(this, PlayerEnergyChangeEventArgs.Create(lastEnergy, Energy));
        }