RandomSpawn.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2004-2015 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 ai.group_template;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.gameserver.ThreadPoolManager;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. /**
  27. * Manages spawn of NPCs having several random spawn points.
  28. * @author GKR
  29. */
  30. public final class RandomSpawn extends AbstractNpcAI
  31. {
  32. private static final Map<Integer, Location[]> SPAWN_POINTS = new HashMap<>();
  33. static
  34. {
  35. // Keltas
  36. SPAWN_POINTS.put(22341, new Location[]
  37. {
  38. new Location(-27136, 250938, -3523),
  39. new Location(-29658, 252897, -3523),
  40. new Location(-27237, 251943, -3527),
  41. new Location(-28868, 250113, -3479)
  42. });
  43. // Keymaster
  44. SPAWN_POINTS.put(22361, new Location[]
  45. {
  46. new Location(14091, 250533, -1940),
  47. new Location(15762, 252440, -2015),
  48. new Location(19836, 256212, -2090),
  49. new Location(21940, 254107, -2010),
  50. new Location(17299, 252943, -2015),
  51. });
  52. // Typhoon
  53. SPAWN_POINTS.put(25539, new Location[]
  54. {
  55. new Location(-20641, 255370, -3235),
  56. new Location(-16157, 250993, -3058),
  57. new Location(-18269, 250721, -3151),
  58. new Location(-16532, 254864, -3223),
  59. new Location(-19055, 253489, -3440),
  60. new Location(-9684, 254256, -3148),
  61. new Location(-6209, 251924, -3189),
  62. new Location(-10547, 251359, -2929),
  63. new Location(-7254, 254997, -3261),
  64. new Location(-4883, 253171, -3322)
  65. });
  66. // Mutated Elpy
  67. SPAWN_POINTS.put(25604, new Location[]
  68. {
  69. new Location(-46080, 246368, -14183),
  70. new Location(-44816, 246368, -14183),
  71. new Location(-44224, 247440, -14184),
  72. new Location(-44896, 248464, -14183),
  73. new Location(-46064, 248544, -14183),
  74. new Location(-46720, 247424, -14183)
  75. });
  76. }
  77. public RandomSpawn()
  78. {
  79. super(RandomSpawn.class.getSimpleName(), "ai/group_template");
  80. addSpawnId(SPAWN_POINTS.keySet());
  81. }
  82. @Override
  83. public final String onSpawn(L2Npc npc)
  84. {
  85. final Location[] spawnlist = SPAWN_POINTS.get(npc.getId());
  86. final Location loc = spawnlist[getRandom(spawnlist.length)];
  87. if (!npc.isInsideRadius(loc, 200, false, false))
  88. {
  89. npc.getSpawn().setLocation(loc);
  90. ThreadPoolManager.getInstance().scheduleGeneral(new Teleport(npc, loc), 100);
  91. }
  92. return super.onSpawn(npc);
  93. }
  94. private static class Teleport implements Runnable
  95. {
  96. private final L2Npc _npc;
  97. private final Location _loc;
  98. public Teleport(L2Npc npc, Location loc)
  99. {
  100. _npc = npc;
  101. _loc = loc;
  102. }
  103. @Override
  104. public void run()
  105. {
  106. _npc.teleToLocation(_loc, false);
  107. }
  108. }
  109. public static void main(String[] args)
  110. {
  111. new RandomSpawn();
  112. }
  113. }