Shadai.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 hellbound.Shadai;
  16. import com.l2jserver.gameserver.GameTimeController;
  17. import com.l2jserver.gameserver.ThreadPoolManager;
  18. import com.l2jserver.gameserver.model.actor.L2Npc;
  19. import com.l2jserver.gameserver.model.quest.Quest;
  20. /**
  21. * @author GKR
  22. */
  23. public class Shadai extends Quest
  24. {
  25. private static final int SHADAI = 32347;
  26. private static final int[] DAY_COORDS =
  27. {
  28. 16882, 238952, 9776
  29. };
  30. private static final int[] NIGHT_COORDS =
  31. {
  32. 9064, 253037, -1928
  33. };
  34. @Override
  35. public final String onSpawn(L2Npc npc)
  36. {
  37. if (!npc.isTeleporting())
  38. {
  39. ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new ValidatePosition(npc), 60000, 60000);
  40. }
  41. return super.onSpawn(npc);
  42. }
  43. private static void validatePosition(L2Npc npc)
  44. {
  45. int[] coords = DAY_COORDS;
  46. boolean mustRevalidate = false;
  47. if ((npc.getX() != NIGHT_COORDS[0]) && GameTimeController.getInstance().isNowNight())
  48. {
  49. coords = NIGHT_COORDS;
  50. mustRevalidate = true;
  51. }
  52. else if ((npc.getX() != DAY_COORDS[0]) && !GameTimeController.getInstance().isNowNight())
  53. {
  54. mustRevalidate = true;
  55. }
  56. if (mustRevalidate)
  57. {
  58. npc.getSpawn().setLocx(coords[0]);
  59. npc.getSpawn().setLocy(coords[1]);
  60. npc.getSpawn().setLocz(coords[2]);
  61. npc.teleToLocation(coords[0], coords[1], coords[2]);
  62. }
  63. }
  64. private static class ValidatePosition implements Runnable
  65. {
  66. private final L2Npc _npc;
  67. public ValidatePosition(L2Npc npc)
  68. {
  69. _npc = npc;
  70. }
  71. @Override
  72. public void run()
  73. {
  74. validatePosition(_npc);
  75. }
  76. }
  77. public Shadai(int questId, String name, String descr)
  78. {
  79. super(questId, name, descr);
  80. addSpawnId(SHADAI);
  81. }
  82. public static void main(String[] args)
  83. {
  84. new Shadai(-1, "Shadai", "hellbound");
  85. }
  86. }