SubClass.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. /**
  18. * Character Sub-Class Definition
  19. * <BR>
  20. * Used to store key information about a character's sub-class.
  21. *
  22. * @author Tempy
  23. */
  24. public final class SubClass
  25. {
  26. private static final byte _maxLevel = Config.MAX_SUBCLASS_LEVEL < Experience.MAX_LEVEL ? Config.MAX_SUBCLASS_LEVEL : Experience.MAX_LEVEL - 1;
  27. private PlayerClass _class;
  28. private long _exp = Experience.LEVEL[40];
  29. private int _sp = 0;
  30. private byte _level = 40;
  31. private int _classIndex = 1;
  32. public SubClass(int classId, long exp, int sp, byte level, int classIndex)
  33. {
  34. _class = PlayerClass.values()[classId];
  35. _exp = exp;
  36. _sp = sp;
  37. _level = level;
  38. _classIndex = classIndex;
  39. }
  40. public SubClass(int classId, int classIndex)
  41. {
  42. // Used for defining a sub class using default values for XP, SP and player level.
  43. _class = PlayerClass.values()[classId];
  44. _classIndex = classIndex;
  45. }
  46. public SubClass()
  47. {
  48. // Used for specifying ALL attributes of a sub class directly,
  49. // using the preset default values.
  50. }
  51. public PlayerClass getClassDefinition()
  52. {
  53. return _class;
  54. }
  55. public int getClassId()
  56. {
  57. return _class.ordinal();
  58. }
  59. public long getExp()
  60. {
  61. return _exp;
  62. }
  63. public int getSp()
  64. {
  65. return _sp;
  66. }
  67. public byte getLevel()
  68. {
  69. return _level;
  70. }
  71. /**
  72. * First Sub-Class is index 1.
  73. * @return int _classIndex
  74. */
  75. public int getClassIndex()
  76. {
  77. return _classIndex;
  78. }
  79. public void setClassId(int classId)
  80. {
  81. _class = PlayerClass.values()[classId];
  82. }
  83. public void setExp(long expValue)
  84. {
  85. if (expValue > (Experience.LEVEL[_maxLevel + 1] - 1))
  86. expValue = (Experience.LEVEL[_maxLevel + 1] - 1);
  87. _exp = expValue;
  88. }
  89. public void setSp(int spValue)
  90. {
  91. _sp = spValue;
  92. }
  93. public void setClassIndex(int classIndex)
  94. {
  95. _classIndex = classIndex;
  96. }
  97. public void setLevel(byte levelValue)
  98. {
  99. if (levelValue > _maxLevel)
  100. levelValue = _maxLevel;
  101. else if (levelValue < 40)
  102. levelValue = 40;
  103. _level = levelValue;
  104. }
  105. public void incLevel()
  106. {
  107. if (getLevel() == _maxLevel)
  108. return;
  109. _level++;
  110. setExp(Experience.LEVEL[getLevel()]);
  111. }
  112. public void decLevel()
  113. {
  114. if (getLevel() == 40)
  115. return;
  116. _level--;
  117. setExp(Experience.LEVEL[getLevel()]);
  118. }
  119. }