L2PetData.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 gnu.trove.map.hash.TIntObjectHashMap;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import com.l2jserver.gameserver.datatables.SkillTable;
  20. /**
  21. * Class hold information about basic pet stats which are same on each level
  22. * @author JIV
  23. *
  24. */
  25. public class L2PetData
  26. {
  27. private TIntObjectHashMap<L2PetLevelData> _levelStats = new TIntObjectHashMap<L2PetLevelData>();
  28. private List<L2PetSkillLearn> _skills = new ArrayList<L2PetSkillLearn>();
  29. private int _load = 20000;
  30. private int _hungry_limit = 1;
  31. private int _minlvl = Byte.MAX_VALUE;
  32. private int[] _food = {};
  33. public void addNewStat(L2PetLevelData data, int level)
  34. {
  35. if (_minlvl > level)
  36. _minlvl = level;
  37. _levelStats.put(level, data);
  38. }
  39. public L2PetLevelData getPetLevelData(int petLevel)
  40. {
  41. return _levelStats.get(petLevel);
  42. }
  43. public int getLoad()
  44. {
  45. return _load;
  46. }
  47. public int getHungry_limit()
  48. {
  49. return _hungry_limit;
  50. }
  51. public int getMinLevel()
  52. {
  53. return _minlvl;
  54. }
  55. public int[] getFood()
  56. {
  57. return _food;
  58. }
  59. public void set_load(int _load)
  60. {
  61. this._load = _load;
  62. }
  63. public void set_hungry_limit(int _hungry_limit)
  64. {
  65. this._hungry_limit = _hungry_limit;
  66. }
  67. public void set_food(int[] _food)
  68. {
  69. this._food = _food;
  70. }
  71. //SKILS
  72. public void addNewSkill(int id, int lvl, int petLvl)
  73. {
  74. _skills.add(new L2PetSkillLearn(id, lvl, petLvl));
  75. }
  76. public int getAvailableLevel(int skillId, int petLvl)
  77. {
  78. int lvl = 0;
  79. for (L2PetSkillLearn temp : _skills)
  80. {
  81. if (temp.getId() != skillId)
  82. continue;
  83. if (temp.getLevel() == 0)
  84. {
  85. if (petLvl < 70)
  86. {
  87. lvl = (petLvl / 10);
  88. if (lvl <= 0)
  89. lvl = 1;
  90. }
  91. else
  92. lvl = (7 + ((petLvl - 70) / 5));
  93. // formula usable for skill that have 10 or more skill levels
  94. int maxLvl = SkillTable.getInstance().getMaxLevel(temp.getId());
  95. if (lvl > maxLvl)
  96. lvl = maxLvl;
  97. break;
  98. }
  99. else if (temp.getMinLevel() <= petLvl)
  100. {
  101. if (temp.getLevel() > lvl)
  102. lvl = temp.getLevel();
  103. }
  104. }
  105. return lvl;
  106. }
  107. public List<L2PetSkillLearn> getAvailableSkills()
  108. {
  109. return _skills;
  110. }
  111. public static final class L2PetSkillLearn
  112. {
  113. private final int _id;
  114. private final int _level;
  115. private final int _minLevel;
  116. public L2PetSkillLearn(int id, int lvl, int minLvl)
  117. {
  118. _id = id;
  119. _level = lvl;
  120. _minLevel = minLvl;
  121. }
  122. public int getId()
  123. {
  124. return _id;
  125. }
  126. public int getLevel()
  127. {
  128. return _level;
  129. }
  130. public int getMinLevel()
  131. {
  132. return _minLevel;
  133. }
  134. }
  135. }