SubClass.java 3.4 KB

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