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