Пример #1
0
        /// <summary>
        /// Current level, XP, XP to next level and modifier buttons.
        /// </summary>
        /// <param name="cc">Instance of the leveling system.</param>
        protected virtual void GUILevelDisplay(ref CharacterBase cc)
        {
            GUILayout.Label("Level", GUILayout.Width(75));

            // decrease level by five
            if (cc.CurrentLevel > (int)CurrentIncrease)
            {
                if (GUILayout.Button("-" + (int)CurrentIncrease, GUILayout.Width(40)))
                {
                    cc.CurrentLevel -= (int)CurrentIncrease;                                                  // reduce the level
                    cc.CurrentXP     = cc.CalcXPToNextLevel(cc.CurrentLevel - 1);                             // update the current XP amount
                    cc.XPToNextLevel = cc.CalcXPToNextLevel(cc.CurrentLevel);                                 // update the level up XP goal

                    cc.UnspentSkillPoints -= (CharacterDefaults.LEVELUP_SKILL_POINTS * (int)CurrentIncrease); // decrease available points

                    if (cc.UnspentSkillPoints < 0)
                    {     // level reduction skill points applied already?
                        for (int j = 0; j < (CharacterDefaults.LEVELUP_SKILL_POINTS * (int)CurrentIncrease); j++)
                        { // reloop for when all points applied to one attribute
                            if (cc.UnspentSkillPoints == 0)
                            {
                                break;                              // work complete when unspent no longer negative
                            }
                            for (int i = 0; i < cc.Skills.Count; i++)
                            {                                   // process all attributes
                                if (cc.Skills[i].Value > 0)
                                {                               // above the min?
                                    cc.Skills[i].Value    -= 1; // remove a skill point
                                    cc.UnspentSkillPoints += 1; // increase the unspent
                                }
                                if (cc.UnspentSkillPoints == 0)
                                {
                                    break;                              // work complete when unspent no longer negative
                                }
                            }
                        }
                    }

                    cc.reCalcCore(true);  // update the core (life, mana, etc) stats
                }
            }
            else
            {
                GUILayout.Space(44);
            }

            // decrease level by one
            if (cc.CurrentLevel > 1)
            {
                if (GUILayout.Button("-", GUILayout.Width(40)))
                {
                    cc.CurrentLevel -= 1;                                            // reduce the level
                    cc.CurrentXP     = cc.CalcXPToNextLevel(cc.CurrentLevel - 1);    // update the current XP amount
                    cc.XPToNextLevel = cc.CalcXPToNextLevel(cc.CurrentLevel);        // update the level up XP goal

                    cc.UnspentSkillPoints -= CharacterDefaults.LEVELUP_SKILL_POINTS; // decrease available points

                    if (cc.UnspentSkillPoints < 0)
                    {     // level reduction skill points applied already?
                        for (int j = 0; j < CharacterDefaults.LEVELUP_SKILL_POINTS; j++)
                        { // reloop for when all points applied to one attribute
                            if (cc.UnspentSkillPoints == 0)
                            {
                                break;                              // work complete when unspent no longer negative
                            }
                            for (int i = 0; i < cc.Skills.Count; i++)
                            {                                   // process all attributes
                                if (cc.Skills[i].Value > 0)
                                {                               // above the min?
                                    cc.Skills[i].Value    -= 1; // remove a skill point
                                    cc.UnspentSkillPoints += 1; // increase the unspent
                                }
                                if (cc.UnspentSkillPoints == 0)
                                {
                                    break;                              // work complete when unspent no longer negative
                                }
                            }
                        }
                    }

                    cc.reCalcCore(true);  // update the core (life, mana, etc) stats
                }
            }
            else
            {
                GUILayout.Space(44);
            }

            // add one level
            if (cc.CurrentLevel < CharacterDefaults.MAXLEVEL)
            {
                if (GUILayout.Button("+", GUILayout.Width(40)))
                {
                    cc.CurrentLevel       += 1;                                         // increase the level
                    cc.CurrentXP           = cc.CalcXPToNextLevel(cc.CurrentLevel - 1); // update the current XP amount
                    cc.XPToNextLevel       = cc.CalcXPToNextLevel(cc.CurrentLevel);     // update the level up XP goal
                    cc.UnspentSkillPoints += CharacterDefaults.LEVELUP_SKILL_POINTS;    // increase available points
                    cc.reCalcCore(true);                                                // update the core (life, mana, etc) stats
                }
            }
            else
            {
                GUILayout.Space(44);
            }

            // add 5 levels
            if (cc.CurrentLevel + (int)CurrentIncrease < CharacterDefaults.MAXLEVEL)
            {
                if (GUILayout.Button("+" + (int)CurrentIncrease, GUILayout.Width(40)))
                {
                    cc.CurrentLevel       += (int)CurrentIncrease;                                            // increase the level
                    cc.CurrentXP           = cc.CalcXPToNextLevel(cc.CurrentLevel - 1);                       // update the current XP amount
                    cc.XPToNextLevel       = cc.CalcXPToNextLevel(cc.CurrentLevel);                           // update the level up XP goal
                    cc.UnspentSkillPoints += (CharacterDefaults.LEVELUP_SKILL_POINTS * (int)CurrentIncrease); // increase available points
                    cc.reCalcCore(true);                                                                      // update the core (life, mana, etc) stats
                }
            }
            else
            {
                GUILayout.Space(44);
            }

            // actual character level
            GUI.skin.label.alignment = TextAnchor.UpperRight;
            GUILayout.Label(cc.CurrentLevel.ToString(), GUILayout.ExpandWidth(true));
            GUI.skin.label.alignment = TextAnchor.UpperLeft;
        }