InstanceZone.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.usercommandhandlers;
  16. import java.util.Map;
  17. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  18. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  19. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  23. /**
  24. * @author nille02
  25. */
  26. public class InstanceZone implements IUserCommandHandler
  27. {
  28. private static final int[] COMMAND_IDS =
  29. {
  30. 114
  31. };
  32. /**
  33. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#getUserCommandList()
  34. */
  35. @Override
  36. public int[] getUserCommandList()
  37. {
  38. return COMMAND_IDS;
  39. }
  40. /**
  41. * @see com.l2jserver.gameserver.handler.IUserCommandHandler#useUserCommand(int, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  42. */
  43. @Override
  44. public boolean useUserCommand(int id, L2PcInstance activeChar)
  45. {
  46. if (id != COMMAND_IDS[0])
  47. return false;
  48. final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(activeChar);
  49. if (world != null && world.templateId >= 0)
  50. {
  51. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_CURRENTLY_INUSE_S1);
  52. sm.addInstanceName(world.templateId);
  53. activeChar.sendPacket(sm);
  54. }
  55. Map<Integer, Long> instanceTimes = InstanceManager.getInstance().getAllInstanceTimes(activeChar.getObjectId());
  56. boolean firstMessage = true;
  57. if (instanceTimes != null)
  58. for(int instanceId : instanceTimes.keySet())
  59. {
  60. long remainingTime = (instanceTimes.get(instanceId) - System.currentTimeMillis()) / 1000;
  61. if (remainingTime > 60)
  62. {
  63. if (firstMessage)
  64. {
  65. firstMessage = false;
  66. activeChar.sendPacket(SystemMessageId.INSTANCE_ZONE_TIME_LIMIT);
  67. }
  68. int hours = (int) (remainingTime / 3600);
  69. int minutes = (int) ((remainingTime%3600) / 60);
  70. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AVAILABLE_AFTER_S1_S2_HOURS_S3_MINUTES);
  71. sm.addInstanceName(instanceId);
  72. sm.addNumber(hours);
  73. sm.addNumber(minutes);
  74. activeChar.sendPacket(sm);
  75. }
  76. else
  77. InstanceManager.getInstance().deleteInstanceTime(activeChar.getObjectId(), instanceId);
  78. }
  79. if (firstMessage)
  80. activeChar.sendPacket(SystemMessageId.NO_INSTANCEZONE_TIME_LIMIT);
  81. return true;
  82. }
  83. }