L2PetData.java 5.2 KB

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