ArenaBuff.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 java.util.StringTokenizer;
  17. import java.util.logging.Level;
  18. import com.l2jserver.gameserver.datatables.SkillTable;
  19. import com.l2jserver.gameserver.handler.IBypassHandler;
  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.skills.L2Skill;
  24. import com.l2jserver.gameserver.model.zone.ZoneId;
  25. /**
  26. * @author Xaras2
  27. */
  28. public class ArenaBuff implements IBypassHandler
  29. {
  30. private static final String[] COMMANDS =
  31. {
  32. "ArenaBuffs",
  33. "HPRecovery",
  34. "CPRecovery"
  35. };
  36. private final int[][] _Buffs =
  37. {
  38. { // Fighter Buffs
  39. 6803, 6804, 6808, 6809, 6811, 6812
  40. },
  41. { // Mage Buffs
  42. 6804, 6805, 6806, 6807, 6812
  43. }
  44. };
  45. @Override
  46. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  47. {
  48. if (!(target instanceof L2Npc))
  49. {
  50. return false;
  51. }
  52. final L2Npc npc = (L2Npc) target;
  53. final StringTokenizer st = new StringTokenizer(command);
  54. try
  55. {
  56. String cmd = st.nextToken();
  57. if (cmd.equalsIgnoreCase(COMMANDS[0]))
  58. {
  59. if (!activeChar.reduceAdena("ArenaBuffs", 2000, activeChar.getLastFolkNPC(), true))
  60. {
  61. return false;
  62. }
  63. for (int skillId : _Buffs[activeChar.isMageClass() ? 1 : 0])
  64. {
  65. L2Skill skill = SkillTable.getInstance().getInfo(skillId, 1);
  66. if (skill != null)
  67. {
  68. npc.setTarget(activeChar);
  69. npc.doCast(skill);
  70. }
  71. }
  72. return true;
  73. }
  74. else if (cmd.equalsIgnoreCase(COMMANDS[1]))
  75. {
  76. if (activeChar.isInsideZone(ZoneId.PVP)) // Cannot be used while inside the pvp zone
  77. {
  78. return false;
  79. }
  80. else if (!activeChar.reduceAdena("RestoreHP", 1000, activeChar.getLastFolkNPC(), true))
  81. {
  82. return false;
  83. }
  84. L2Skill skill = SkillTable.getInstance().getInfo(6817, 1);
  85. if (skill != null)
  86. {
  87. npc.setTarget(activeChar);
  88. npc.doCast(skill);
  89. }
  90. return true;
  91. }
  92. else if (cmd.equalsIgnoreCase(COMMANDS[2]))
  93. {
  94. if (activeChar.isInsideZone(ZoneId.PVP)) // Cannot be used while inside the pvp zone
  95. {
  96. return false;
  97. }
  98. else if (!activeChar.reduceAdena("RestoreCP", 1000, activeChar.getLastFolkNPC(), true))
  99. {
  100. return false;
  101. }
  102. L2Skill skill = SkillTable.getInstance().getInfo(4380, 1);
  103. if (skill != null)
  104. {
  105. npc.setTarget(activeChar);
  106. npc.doCast(skill);
  107. }
  108. return true;
  109. }
  110. }
  111. catch (Exception e)
  112. {
  113. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  114. }
  115. return false;
  116. }
  117. @Override
  118. public String[] getBypassList()
  119. {
  120. return COMMANDS;
  121. }
  122. }