public void ToggleShowExperienceGain(bool showExperienceGain)
        {
            _helper.Events.GameLoop.UpdateTicked -= OnUpdateTicked_DetermineIfExperienceHasBeenGained;
            for (int i = 0; i < _currentExperience.Length; ++i)
            {
                _currentExperience[i] = Game1.player.experiencePoints[i];
            }
            _showExperienceGain = showExperienceGain;

            if (_levelExtenderAPI != null)
            {
                for (int i = 0; i < _currentLevelExtenderExperience.Length; ++i)
                {
                    _currentLevelExtenderExperience[i] = _levelExtenderAPI.currentXP()[i];
                }
            }

            if (showExperienceGain)
            {
                _helper.Events.GameLoop.UpdateTicked += OnUpdateTicked_DetermineIfExperienceHasBeenGained;
            }
        }
Exemple #2
0
        private void DetermineIfExperienceHasBeenGained(object sender, EventArgs e)
        {
            Item currentItem = Game1.player.CurrentItem;

            int currentLevelIndex = -1;

            for (int i = 0; i < _currentExperience.Length; ++i)
            {
                if (_currentExperience[i] != Game1.player.experiencePoints[i])
                {
                    currentLevelIndex = i;
                    break;
                }
            }

            if (currentLevelIndex > -1)
            {
                switch (currentLevelIndex)
                {
                case 0:
                {
                    _experienceFillColor      = new Color(255, 251, 35, 0.38f);
                    _experienceIconPosition.X = 10;
                    _currentSkillLevel        = Game1.player.farmingLevel.Value;
                    break;
                }

                case 1:
                {
                    _experienceFillColor      = new Color(17, 84, 252, 0.63f);
                    _experienceIconPosition.X = 20;
                    _currentSkillLevel        = Game1.player.fishingLevel.Value;
                    break;
                }

                case 2:
                {
                    _experienceFillColor      = new Color(0, 234, 0, 0.63f);
                    _experienceIconPosition.X = 60;
                    _currentSkillLevel        = Game1.player.foragingLevel.Value;
                    break;
                }

                case 3:
                {
                    _experienceFillColor      = new Color(145, 104, 63, 0.63f);
                    _experienceIconPosition.X = 30;
                    _currentSkillLevel        = Game1.player.miningLevel.Value;
                    break;
                }

                case 4:
                {
                    _experienceFillColor      = new Color(204, 0, 3, 0.63f);
                    _experienceIconPosition.X = 120;
                    _currentSkillLevel        = Game1.player.combatLevel.Value;
                    break;
                }
                }

                _experienceRequiredToLevel    = GetExperienceRequiredToLevel(_currentSkillLevel);
                _experienceFromPreviousLevels = GetExperienceRequiredToLevel(_currentSkillLevel - 1);
                _experienceEarnedThisLevel    = Game1.player.experiencePoints[currentLevelIndex] - _experienceFromPreviousLevels;
                int experiencePreviouslyEarnedThisLevel = _currentExperience[currentLevelIndex] - _experienceFromPreviousLevels;

                if (_experienceRequiredToLevel <= 0 &&
                    _levelExtenderAPI != null)
                {
                    _experienceEarnedThisLevel    = _levelExtenderAPI.currentXP()[currentLevelIndex];
                    _experienceFromPreviousLevels = _currentExperience[currentLevelIndex] - _experienceEarnedThisLevel;
                    _experienceRequiredToLevel    = _levelExtenderAPI.requiredXP()[currentLevelIndex] + _experienceFromPreviousLevels;
                }

                ShowExperienceBar();
                if (_showExperienceGain &&
                    _experienceRequiredToLevel > 0)
                {
                    _experiencePointDisplays.Add(
                        new ExperiencePointDisplay(
                            Game1.player.experiencePoints[currentLevelIndex] - _currentExperience[currentLevelIndex],
                            Game1.player.getLocalPosition(Game1.viewport)));
                }

                _currentExperience[currentLevelIndex] = Game1.player.experiencePoints[currentLevelIndex];
            }
            else if (_previousItem != currentItem)
            {
                if (currentItem is FishingRod)
                {
                    _experienceFillColor      = new Color(17, 84, 252, 0.63f);
                    currentLevelIndex         = 1;
                    _experienceIconPosition.X = 20;
                    _currentSkillLevel        = Game1.player.fishingLevel.Value;
                }
                else if (currentItem is Pickaxe)
                {
                    _experienceFillColor      = new Color(145, 104, 63, 0.63f);
                    currentLevelIndex         = 3;
                    _experienceIconPosition.X = 30;
                    _currentSkillLevel        = Game1.player.miningLevel.Value;
                }
                else if (currentItem is MeleeWeapon &&
                         currentItem.Name != "Scythe")
                {
                    _experienceFillColor      = new Color(204, 0, 3, 0.63f);
                    currentLevelIndex         = 4;
                    _experienceIconPosition.X = 120;
                    _currentSkillLevel        = Game1.player.combatLevel.Value;
                }
                else if (Game1.currentLocation is Farm &&
                         !(currentItem is Axe))
                {
                    _experienceFillColor      = new Color(255, 251, 35, 0.38f);
                    currentLevelIndex         = 0;
                    _experienceIconPosition.X = 10;
                    _currentSkillLevel        = Game1.player.farmingLevel.Value;
                }
                else
                {
                    _experienceFillColor      = new Color(0, 234, 0, 0.63f);
                    currentLevelIndex         = 2;
                    _experienceIconPosition.X = 60;
                    _currentSkillLevel        = Game1.player.foragingLevel.Value;
                }

                _experienceRequiredToLevel    = GetExperienceRequiredToLevel(_currentSkillLevel);
                _experienceFromPreviousLevels = GetExperienceRequiredToLevel(_currentSkillLevel - 1);
                _experienceEarnedThisLevel    = Game1.player.experiencePoints[currentLevelIndex] - _experienceFromPreviousLevels;

                if (_experienceRequiredToLevel <= 0 &&
                    _levelExtenderAPI != null)
                {
                    _experienceEarnedThisLevel    = _levelExtenderAPI.currentXP()[currentLevelIndex];
                    _experienceFromPreviousLevels = _currentExperience[currentLevelIndex] - _experienceEarnedThisLevel;
                    _experienceRequiredToLevel    = _levelExtenderAPI.requiredXP()[currentLevelIndex] + _experienceFromPreviousLevels;
                }

                ShowExperienceBar();
                _previousItem = currentItem;
            }
        }