Shadai.java 2.5 KB

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