SupportMagic.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 handlers.bypasshandlers;
  16. import com.l2jserver.gameserver.datatables.HelperBuffTable;
  17. import com.l2jserver.gameserver.datatables.SkillTable;
  18. import com.l2jserver.gameserver.handler.IBypassHandler;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  24. import com.l2jserver.gameserver.templates.L2HelperBuff;
  25. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  26. public class SupportMagic implements IBypassHandler
  27. {
  28. private static final String[] COMMANDS =
  29. {
  30. "supportmagicservitor",
  31. "supportmagic"
  32. };
  33. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  34. {
  35. if (!(target instanceof L2Npc))
  36. return false;
  37. boolean result = false;
  38. if (command.toLowerCase().startsWith(COMMANDS[0]))
  39. result = makeSupportMagic(activeChar, (L2Npc)target, true);
  40. else if (command.toLowerCase().startsWith(COMMANDS[1]))
  41. result = makeSupportMagic(activeChar, (L2Npc)target, false);
  42. return result;
  43. }
  44. /**
  45. * Add Newbie helper buffs to L2Player according to its level.<BR><BR>
  46. *
  47. * <B><U> Actions</U> :</B><BR><BR>
  48. * <li>Get the range level in wich player must be to obtain buff </li>
  49. * <li>If player level is out of range, display a message and return </li>
  50. * <li>According to player level cast buff </li><BR><BR>
  51. *
  52. * <FONT COLOR=#FF0000><B> Newbie Helper Buff list is define in sql table helper_buff_list</B></FONT><BR><BR>
  53. *
  54. * @param player The L2PcInstance that talk with the L2NpcInstance
  55. *
  56. */
  57. public static boolean makeSupportMagic(L2PcInstance player, L2Npc npc, boolean isSummon)
  58. {
  59. if (player == null)
  60. return false;
  61. // Prevent a cursed weapon weilder of being buffed
  62. if (player.isCursedWeaponEquipped())
  63. return false;
  64. int player_level = player.getLevel();
  65. int lowestLevel = 0;
  66. int highestLevel = 0;
  67. if (isSummon)
  68. {
  69. if (player.getPet() == null || !(player.getPet() instanceof L2SummonInstance))
  70. {
  71. String content = "<html><body>Only servitors can receive this Support Magic. If you do not have a servitor, you cannot access these spells.</body></html>";
  72. npc.insertObjectIdAndShowChatWindow(player, content);
  73. return true;
  74. }
  75. npc.setTarget(player.getPet());
  76. }
  77. else
  78. // Select the player
  79. npc.setTarget(player);
  80. if (isSummon)
  81. {
  82. lowestLevel = HelperBuffTable.getInstance().getServitorLowestLevel();
  83. highestLevel = HelperBuffTable.getInstance().getServitorHighestLevel();
  84. }
  85. else
  86. {
  87. // Calculate the min and max level between which the player must be to obtain buff
  88. if (player.isMageClass())
  89. {
  90. lowestLevel = HelperBuffTable.getInstance().getMagicClassLowestLevel();
  91. highestLevel = HelperBuffTable.getInstance().getMagicClassHighestLevel();
  92. }
  93. else
  94. {
  95. lowestLevel = HelperBuffTable.getInstance().getPhysicClassLowestLevel();
  96. highestLevel = HelperBuffTable.getInstance().getPhysicClassHighestLevel();
  97. }
  98. }
  99. // If the player is too high level, display a message and return
  100. if (player_level > highestLevel)
  101. {
  102. String content = "<html><body>Newbie Guide:<br>Only a <font color=\"LEVEL\">novice character of level " + highestLevel
  103. + " or less</font> can receive my support magic.<br>Your novice character is the first one that you created and raised in this world.</body></html>";
  104. npc.insertObjectIdAndShowChatWindow(player, content);
  105. return true;
  106. }
  107. // If the player is too low level, display a message and return
  108. if (player_level < lowestLevel)
  109. {
  110. String content = "<html><body>Come back here when you have reached level " + lowestLevel + ". I will give you support magic then.</body></html>";
  111. npc.insertObjectIdAndShowChatWindow(player, content);
  112. return true;
  113. }
  114. L2Skill skill = null;
  115. if (isSummon)
  116. {
  117. for (L2HelperBuff helperBuffItem : HelperBuffTable.getInstance().getHelperBuffTable())
  118. {
  119. if (helperBuffItem.isForSummon())
  120. {
  121. skill = SkillTable.getInstance().getInfo(helperBuffItem.getSkillID(), helperBuffItem.getSkillLevel());
  122. if (skill != null)
  123. npc.doCast(skill);
  124. }
  125. }
  126. }
  127. else
  128. {
  129. // Go through the Helper Buff list define in sql table helper_buff_list and cast skill
  130. for (L2HelperBuff helperBuffItem : HelperBuffTable.getInstance().getHelperBuffTable())
  131. {
  132. if (helperBuffItem.isMagicClassBuff() == player.isMageClass())
  133. {
  134. if (player_level >= helperBuffItem.getLowerLevel() && player_level <= helperBuffItem.getUpperLevel())
  135. {
  136. skill = SkillTable.getInstance().getInfo(helperBuffItem.getSkillID(), helperBuffItem.getSkillLevel());
  137. if (skill.getSkillType() == L2SkillType.SUMMON)
  138. player.doSimultaneousCast(skill);
  139. else
  140. npc.doCast(skill);
  141. }
  142. }
  143. }
  144. }
  145. return true;
  146. }
  147. public String[] getBypassList()
  148. {
  149. return COMMANDS;
  150. }
  151. }