L2GroupSpawn.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.model;
  20. import java.util.logging.Level;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.data.sql.impl.TerritoryTable;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
  25. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  26. import com.l2jserver.util.Rnd;
  27. /**
  28. * @author littlecrow A special spawn implementation to spawn controllable mob
  29. */
  30. public class L2GroupSpawn extends L2Spawn
  31. {
  32. private final L2NpcTemplate _template;
  33. public L2GroupSpawn(L2NpcTemplate mobTemplate) throws SecurityException, ClassNotFoundException, NoSuchMethodException
  34. {
  35. super(mobTemplate);
  36. _template = mobTemplate;
  37. setAmount(1);
  38. }
  39. public L2Npc doGroupSpawn()
  40. {
  41. try
  42. {
  43. if (_template.isType("L2Pet") || _template.isType("L2Minion"))
  44. {
  45. return null;
  46. }
  47. int newlocx = 0;
  48. int newlocy = 0;
  49. int newlocz = 0;
  50. if ((getX() == 0) && (getY() == 0))
  51. {
  52. if (getLocationId() == 0)
  53. {
  54. return null;
  55. }
  56. final Location location = TerritoryTable.getInstance().getRandomPoint(getLocationId());
  57. if (location != null)
  58. {
  59. newlocx = location.getX();
  60. newlocy = location.getY();
  61. newlocz = location.getZ();
  62. }
  63. }
  64. else
  65. {
  66. newlocx = getX();
  67. newlocy = getY();
  68. newlocz = getZ();
  69. }
  70. final L2Npc mob = new L2ControllableMobInstance(_template);
  71. mob.setCurrentHpMp(mob.getMaxHp(), mob.getMaxMp());
  72. if (getHeading() == -1)
  73. {
  74. mob.setHeading(Rnd.nextInt(61794));
  75. }
  76. else
  77. {
  78. mob.setHeading(getHeading());
  79. }
  80. mob.setSpawn(this);
  81. mob.spawnMe(newlocx, newlocy, newlocz);
  82. mob.onSpawn();
  83. if (Config.DEBUG)
  84. {
  85. _log.finest("Spawned Mob Id: " + _template.getId() + " ,at: X: " + mob.getX() + " Y: " + mob.getY() + " Z: " + mob.getZ());
  86. }
  87. return mob;
  88. }
  89. catch (Exception e)
  90. {
  91. _log.log(Level.WARNING, "NPC class not found: " + e.getMessage(), e);
  92. return null;
  93. }
  94. }
  95. }