L2GroupSpawn.java 2.8 KB

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