Shadai.java 2.5 KB

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