SubClass.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.base;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.datatables.ExperienceTable;
  18. /**
  19. * Character Sub-Class Definition
  20. * <BR>
  21. * Used to store key information about a character's sub-class.
  22. *
  23. * @author Tempy
  24. */
  25. public final class SubClass
  26. {
  27. private static final byte _maxLevel = Config.MAX_SUBCLASS_LEVEL < ExperienceTable.getInstance().getMaxLevel() ? Config.MAX_SUBCLASS_LEVEL : (byte)(ExperienceTable.getInstance().getMaxLevel() - 1);
  28. private PlayerClass _class;
  29. private long _exp = ExperienceTable.getInstance().getExpForLevel(Config.BASE_SUBCLASS_LEVEL);
  30. private int _sp = 0;
  31. private byte _level = Config.BASE_SUBCLASS_LEVEL;
  32. private int _classIndex = 1;
  33. public SubClass(int classId, long exp, int sp, byte level, int classIndex)
  34. {
  35. _class = PlayerClass.values()[classId];
  36. _exp = exp;
  37. _sp = sp;
  38. _level = level;
  39. _classIndex = classIndex;
  40. }
  41. public SubClass(int classId, int classIndex)
  42. {
  43. // Used for defining a sub class using default values for XP, SP and player level.
  44. _class = PlayerClass.values()[classId];
  45. _classIndex = classIndex;
  46. }
  47. public SubClass()
  48. {
  49. // Used for specifying ALL attributes of a sub class directly,
  50. // using the preset default values.
  51. }
  52. public PlayerClass getClassDefinition()
  53. {
  54. return _class;
  55. }
  56. public int getClassId()
  57. {
  58. return _class.ordinal();
  59. }
  60. public long getExp()
  61. {
  62. return _exp;
  63. }
  64. public int getSp()
  65. {
  66. return _sp;
  67. }
  68. public byte getLevel()
  69. {
  70. return _level;
  71. }
  72. /**
  73. * First Sub-Class is index 1.
  74. * @return int _classIndex
  75. */
  76. public int getClassIndex()
  77. {
  78. return _classIndex;
  79. }
  80. public void setClassId(int classId)
  81. {
  82. _class = PlayerClass.values()[classId];
  83. }
  84. public void setExp(long expValue)
  85. {
  86. if (expValue > (ExperienceTable.getInstance().getExpForLevel(_maxLevel + 1) - 1))
  87. expValue = ExperienceTable.getInstance().getExpForLevel(_maxLevel + 1) - 1;
  88. _exp = expValue;
  89. }
  90. public void setSp(int spValue)
  91. {
  92. _sp = spValue;
  93. }
  94. public void setClassIndex(int classIndex)
  95. {
  96. _classIndex = classIndex;
  97. }
  98. public void setLevel(byte levelValue)
  99. {
  100. if (levelValue > _maxLevel)
  101. levelValue = _maxLevel;
  102. else if (levelValue < Config.BASE_SUBCLASS_LEVEL)
  103. levelValue = Config.BASE_SUBCLASS_LEVEL;
  104. _level = levelValue;
  105. }
  106. public void incLevel()
  107. {
  108. if (getLevel() == _maxLevel)
  109. return;
  110. _level++;
  111. setExp(ExperienceTable.getInstance().getExpForLevel(getLevel()));
  112. }
  113. public void decLevel()
  114. {
  115. if (getLevel() == Config.BASE_SUBCLASS_LEVEL)
  116. return;
  117. _level--;
  118. setExp(ExperienceTable.getInstance().getExpForLevel(getLevel()));
  119. }
  120. }