RentPet.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 com.l2jserver.Config;
  18. import com.l2jserver.gameserver.handler.IBypassHandler;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  24. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  25. public class RentPet implements IBypassHandler
  26. {
  27. private static final String[] COMMANDS =
  28. {
  29. "RentPet"
  30. };
  31. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  32. {
  33. if (!(target instanceof L2MerchantInstance))
  34. return false;
  35. if (!Config.ALLOW_RENTPET)
  36. return false;
  37. if (!Config.LIST_PET_RENT_NPC.contains(((L2Npc)target).getTemplate().getNpcId()))
  38. return false;
  39. try
  40. {
  41. StringTokenizer st = new StringTokenizer(command, " ");
  42. st.nextToken();
  43. if (st.countTokens() < 1)
  44. {
  45. NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc)target).getObjectId());
  46. msg.setHtml("<html><body>Pet Manager:<br>" +
  47. "You can rent a wyvern or strider for adena.<br>My prices:<br1>" +
  48. "<table border=0><tr><td>Ride</td></tr>" +
  49. "<tr><td>Wyvern</td><td>Strider</td></tr>" +
  50. "<tr><td><a action=\"bypass -h npc_%objectId%_RentPet 1\">30 sec/1800 adena</a></td><td><a action=\"bypass -h npc_%objectId%_RentPet 11\">30 sec/900 adena</a></td></tr>" +
  51. "<tr><td><a action=\"bypass -h npc_%objectId%_RentPet 2\">1 min/7200 adena</a></td><td><a action=\"bypass -h npc_%objectId%_RentPet 12\">1 min/3600 adena</a></td></tr>" +
  52. "<tr><td><a action=\"bypass -h npc_%objectId%_RentPet 3\">10 min/720000 adena</a></td><td><a action=\"bypass -h npc_%objectId%_RentPet 13\">10 min/360000 adena</a></td></tr>" +
  53. "<tr><td><a action=\"bypass -h npc_%objectId%_RentPet 4\">30 min/6480000 adena</a></td><td><a action=\"bypass -h npc_%objectId%_RentPet 14\">30 min/3240000 adena</a></td></tr>" +
  54. "</table>" +
  55. "</body></html>");
  56. msg.replace("%objectId%", String.valueOf(((L2Npc)target).getObjectId()));
  57. activeChar.sendPacket(msg);
  58. }
  59. else
  60. tryRentPet(activeChar, Integer.parseInt(st.nextToken()));
  61. return true;
  62. }
  63. catch (Exception e)
  64. {
  65. _log.info("Exception in " + getClass().getSimpleName());
  66. }
  67. return false;
  68. }
  69. public static final void tryRentPet(L2PcInstance player, int val)
  70. {
  71. if (player == null || player.getPet() != null || player.isMounted() || player.isRentedPet() || player.isTransformed() || player.isCursedWeaponEquipped())
  72. return;
  73. if (!player.disarmWeapons())
  74. return;
  75. int petId;
  76. double price = 1;
  77. int cost[] = {1800, 7200, 720000, 6480000};
  78. int ridetime[] = {30, 60, 600, 1800};
  79. if (val > 10)
  80. {
  81. petId = 12526;
  82. val -= 10;
  83. price /= 2;
  84. }
  85. else
  86. petId = 12621;
  87. if (val < 1 || val > 4)
  88. return;
  89. price *= cost[val - 1];
  90. int time = ridetime[val - 1];
  91. if (!player.reduceAdena("Rent", (long) price, player.getLastFolkNPC(), true))
  92. return;
  93. player.mount(petId, 0, false);
  94. SetupGauge sg = new SetupGauge(3, time*1000);
  95. player.sendPacket(sg);
  96. player.startRentPet(time);
  97. }
  98. public String[] getBypassList()
  99. {
  100. return COMMANDS;
  101. }
  102. }