RentPet.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.bypasshandlers;
  20. import java.util.StringTokenizer;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.handler.IBypassHandler;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  28. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  29. public class RentPet implements IBypassHandler
  30. {
  31. private static final String[] COMMANDS =
  32. {
  33. "RentPet"
  34. };
  35. @Override
  36. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  37. {
  38. if (!(target instanceof L2MerchantInstance))
  39. {
  40. return false;
  41. }
  42. if (!Config.ALLOW_RENTPET)
  43. {
  44. return false;
  45. }
  46. if (!Config.LIST_PET_RENT_NPC.contains(target.getId()))
  47. {
  48. return false;
  49. }
  50. try
  51. {
  52. StringTokenizer st = new StringTokenizer(command, " ");
  53. st.nextToken();
  54. if (st.countTokens() < 1)
  55. {
  56. final NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc) target).getObjectId());
  57. msg.setHtml("<html><body>Pet Manager:<br>" + "You can rent a wyvern or strider for adena.<br>My prices:<br1>" + "<table border=0><tr><td>Ride</td></tr>" + "<tr><td>Wyvern</td><td>Strider</td></tr>" + "<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>" + "<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>" + "<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>" + "<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>" + "</table>" + "</body></html>");
  58. msg.replace("%objectId%", String.valueOf(((L2Npc) target).getObjectId()));
  59. activeChar.sendPacket(msg);
  60. }
  61. else
  62. {
  63. tryRentPet(activeChar, Integer.parseInt(st.nextToken()));
  64. }
  65. return true;
  66. }
  67. catch (Exception e)
  68. {
  69. _log.info("Exception in " + getClass().getSimpleName());
  70. }
  71. return false;
  72. }
  73. public static final void tryRentPet(L2PcInstance player, int val)
  74. {
  75. if ((player == null) || player.hasSummon() || player.isMounted() || player.isRentedPet() || player.isTransformed() || player.isCursedWeaponEquipped())
  76. {
  77. return;
  78. }
  79. if (!player.disarmWeapons())
  80. {
  81. return;
  82. }
  83. int petId;
  84. double price = 1;
  85. int cost[] =
  86. {
  87. 1800,
  88. 7200,
  89. 720000,
  90. 6480000
  91. };
  92. int ridetime[] =
  93. {
  94. 30,
  95. 60,
  96. 600,
  97. 1800
  98. };
  99. if (val > 10)
  100. {
  101. petId = 12526;
  102. val -= 10;
  103. price /= 2;
  104. }
  105. else
  106. {
  107. petId = 12621;
  108. }
  109. if ((val < 1) || (val > 4))
  110. {
  111. return;
  112. }
  113. price *= cost[val - 1];
  114. int time = ridetime[val - 1];
  115. if (!player.reduceAdena("Rent", (long) price, player.getLastFolkNPC(), true))
  116. {
  117. return;
  118. }
  119. player.mount(petId, 0, false);
  120. SetupGauge sg = new SetupGauge(3, time * 1000);
  121. player.sendPacket(sg);
  122. player.startRentPet(time);
  123. }
  124. @Override
  125. public String[] getBypassList()
  126. {
  127. return COMMANDS;
  128. }
  129. }