SubClass.java 3.5 KB

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