// Called when construction has finished.
        private void FinishConstruction(int ctick)
        {
            _timer.Stop();
            Debug.WriteLine($"FinishConstruction: Construction for {Id} finished on tick {ctick} expected {_timer.EndTick}...");

            Village.WorkerManager.DeallotateWorker(this);

            var duration = GetBuildTime(NextUpgrade);
            var player   = Level;

            //TODO: Clean up level and experience calculation.
            var expPointsGained = LogicUtils.CalculateExpPoints(duration);
            var expPoints       = player.Avatar.ExpPoints + expPointsGained;
            var expCurLevel     = player.Avatar.ExpLevels;
            var expLevel        = LogicUtils.CalculateExpLevel(Assets, ref expCurLevel, ref expPoints);

            player.Avatar.ExpPoints = expPoints;
            player.Avatar.ExpLevels = expLevel;

            _upgradeLevel++;
            _data = NextUpgrade;

            // Calling UpdateCanUpgrade will set the IsUpgradable & NextUpgrade property as well.
            UpdateIsUpgradable();
        }
Ejemplo n.º 2
0
        internal void FinishClear(int ctick)
        {
            Debug.WriteLine($"FinishClear: Construction for {Id} finished on tick {ctick} expected {_timer.EndTick}...");

            _timer.Stop();
            Village.WorkerManager.DeallotateWorker(this);

            var duration = _data.ClearTime;
            var player   = Village.Level;

            var gems = s_gemDrops[Village._obstacleClearCount++];

            if (Village._obstacleClearCount >= s_gemDrops.Length)
            {
                Village._obstacleClearCount = 0;
            }

            var expPointsGained = LogicUtils.CalculateExpPoints(duration);
            var expPoints       = player.Avatar.ExpPoints + expPointsGained;
            var expCurLevel     = player.Avatar.ExpLevels;
            var expLevel        = LogicUtils.CalculateExpLevel(Assets, ref expCurLevel, ref expPoints);

            player.Avatar.ExpPoints = expPoints;
            player.Avatar.ExpLevels = expLevel;
            player.Avatar.Gems     += gems;

            Village.VillageObjects.Remove(Id);
        }