L2PetData.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. import com.l2jserver.gameserver.datatables.SkillTable;
  21. import com.l2jserver.gameserver.model.holders.SkillHolder;
  22. /**
  23. * Class hold information about basic pet stats which are same on each level.
  24. * @author JIV
  25. */
  26. public class L2PetData
  27. {
  28. private final Map<Integer, L2PetLevelData> _levelStats = new HashMap<>();
  29. private final List<L2PetSkillLearn> _skills = new ArrayList<>();
  30. private int _load = 20000;
  31. private int _hungryLimit = 1;
  32. private int _minlvl = Byte.MAX_VALUE;
  33. private final List<Integer> _food = new ArrayList<>();
  34. /**
  35. * @param level the pet's level.
  36. * @param data the pet's data.
  37. */
  38. public void addNewStat(int level, L2PetLevelData data)
  39. {
  40. if (_minlvl > level)
  41. {
  42. _minlvl = level;
  43. }
  44. _levelStats.put(level, data);
  45. }
  46. /**
  47. * @param petLevel the pet's level.
  48. * @return the pet data associated to that pet level.
  49. */
  50. public L2PetLevelData getPetLevelData(int petLevel)
  51. {
  52. return _levelStats.get(petLevel);
  53. }
  54. /**
  55. * @return the pet's weight load.
  56. */
  57. public int getLoad()
  58. {
  59. return _load;
  60. }
  61. /**
  62. * @return the pet's hunger limit.
  63. */
  64. public int getHungryLimit()
  65. {
  66. return _hungryLimit;
  67. }
  68. /**
  69. * @return the pet's minimum level.
  70. */
  71. public int getMinLevel()
  72. {
  73. return _minlvl;
  74. }
  75. /**
  76. * @return the pet's food list.
  77. */
  78. public List<Integer> getFood()
  79. {
  80. return _food;
  81. }
  82. /**
  83. * @param foodId the pet's food Id to add.
  84. */
  85. public void addFood(Integer foodId)
  86. {
  87. _food.add(foodId);
  88. }
  89. /**
  90. * @param load the weight load to set.
  91. */
  92. public void setLoad(int load)
  93. {
  94. _load = load;
  95. }
  96. /**
  97. * @param limit the hunger limit to set.
  98. */
  99. public void setHungryLimit(int limit)
  100. {
  101. _hungryLimit = limit;
  102. }
  103. // SKILS
  104. /**
  105. * @param skillId the skill Id to add.
  106. * @param skillLvl the skill level.
  107. * @param petLvl the pet's level when this skill is available.
  108. */
  109. public void addNewSkill(int skillId, int skillLvl, int petLvl)
  110. {
  111. _skills.add(new L2PetSkillLearn(skillId, skillLvl, petLvl));
  112. }
  113. /**
  114. * TODO: Simplify this.
  115. * @param skillId the skill Id.
  116. * @param petLvl the pet level.
  117. * @return the level of the skill for the given skill Id and pet level.
  118. */
  119. public int getAvailableLevel(int skillId, int petLvl)
  120. {
  121. int lvl = 0;
  122. for (L2PetSkillLearn temp : _skills)
  123. {
  124. if (temp.getSkillId() != skillId)
  125. {
  126. continue;
  127. }
  128. if (temp.getSkillLvl() == 0)
  129. {
  130. if (petLvl < 70)
  131. {
  132. lvl = (petLvl / 10);
  133. if (lvl <= 0)
  134. {
  135. lvl = 1;
  136. }
  137. }
  138. else
  139. {
  140. lvl = (7 + ((petLvl - 70) / 5));
  141. }
  142. // formula usable for skill that have 10 or more skill levels
  143. int maxLvl = SkillTable.getInstance().getMaxLevel(temp.getSkillId());
  144. if (lvl > maxLvl)
  145. {
  146. lvl = maxLvl;
  147. }
  148. break;
  149. }
  150. else if (temp.getMinLevel() <= petLvl)
  151. {
  152. if (temp.getSkillLvl() > lvl)
  153. {
  154. lvl = temp.getSkillLvl();
  155. }
  156. }
  157. }
  158. return lvl;
  159. }
  160. /**
  161. * @return the list with the pet's skill data.
  162. */
  163. public List<L2PetSkillLearn> getAvailableSkills()
  164. {
  165. return _skills;
  166. }
  167. public static final class L2PetSkillLearn extends SkillHolder
  168. {
  169. private final int _minLevel;
  170. /**
  171. * @param id the skill Id.
  172. * @param lvl the skill level.
  173. * @param minLvl the minimum level when this skill is available.
  174. */
  175. public L2PetSkillLearn(int id, int lvl, int minLvl)
  176. {
  177. super(id, lvl);
  178. _minLevel = minLvl;
  179. }
  180. /**
  181. * @return the minimum level for the pet to get the skill.
  182. */
  183. public int getMinLevel()
  184. {
  185. return _minLevel;
  186. }
  187. }
  188. }