FourSepulchersChangeAttackTimeTask.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.instancemanager.tasks;
  20. import java.util.Calendar;
  21. import java.util.concurrent.ScheduledFuture;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.ThreadPoolManager;
  24. import com.l2jserver.gameserver.instancemanager.FourSepulchersManager;
  25. /**
  26. * Four Sepulchers change attack time task.
  27. * @author xban1x
  28. */
  29. public final class FourSepulchersChangeAttackTimeTask implements Runnable
  30. {
  31. @Override
  32. public void run()
  33. {
  34. final FourSepulchersManager manager = FourSepulchersManager.getInstance();
  35. manager.setIsEntryTime(false);
  36. manager.setIsWarmUpTime(false);
  37. manager.setIsAttackTime(true);
  38. manager.setIsCoolDownTime(false);
  39. manager.locationShadowSpawns();
  40. manager.spawnMysteriousBox(31921);
  41. manager.spawnMysteriousBox(31922);
  42. manager.spawnMysteriousBox(31923);
  43. manager.spawnMysteriousBox(31924);
  44. if (!manager.isFirstTimeRun())
  45. {
  46. manager.setWarmUpTimeEnd(Calendar.getInstance().getTimeInMillis());
  47. }
  48. long interval = 0;
  49. // say task
  50. if (manager.isFirstTimeRun())
  51. {
  52. for (double min = Calendar.getInstance().get(Calendar.MINUTE); min < manager.getCycleMin(); min++)
  53. {
  54. // looking for next shout time....
  55. if ((min % 5) == 0)// check if min can be divided by 5
  56. {
  57. final Calendar inter = Calendar.getInstance();
  58. inter.set(Calendar.MINUTE, (int) min);
  59. ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersManagerSayTask(), inter.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
  60. break;
  61. }
  62. }
  63. }
  64. else
  65. {
  66. ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersManagerSayTask(), 5 * 60400);
  67. }
  68. // searching time when attack time will be ended:
  69. // counting difference between time when attack time ends and
  70. // current time
  71. // and then launching change time task
  72. if (manager.isFirstTimeRun())
  73. {
  74. interval = manager.getAttackTimeEnd() - Calendar.getInstance().getTimeInMillis();
  75. }
  76. else
  77. {
  78. interval = Config.FS_TIME_ATTACK * 60000L;
  79. }
  80. manager.setChangeCoolDownTimeTask(ThreadPoolManager.getInstance().scheduleGeneral(new FourSepulchersChangeCoolDownTimeTask(), interval));
  81. final ScheduledFuture<?> changeAttackTimeTask = manager.getChangeAttackTimeTask();
  82. if (changeAttackTimeTask != null)
  83. {
  84. changeAttackTimeTask.cancel(true);
  85. manager.setChangeAttackTimeTask(null);
  86. }
  87. }
  88. }