2
0

L2SkillSpawn.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.skills.l2skills;
  16. import com.l2jserver.gameserver.datatables.NpcTable;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.L2Spawn;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.templates.StatsSet;
  23. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  24. import com.l2jserver.util.Rnd;
  25. public class L2SkillSpawn extends L2Skill
  26. {
  27. private final int _npcId;
  28. private final int _despawnDelay;
  29. private final boolean _summonSpawn;
  30. private final boolean _randomOffset;
  31. public L2SkillSpawn(StatsSet set)
  32. {
  33. super(set);
  34. _npcId = set.getInteger("npcId", 0);
  35. _despawnDelay = set.getInteger("despawnDelay", 0);
  36. _summonSpawn = set.getBool("isSummonSpawn", false);
  37. _randomOffset = set.getBool("randomOffset", true);
  38. }
  39. @Override
  40. public void useSkill(L2Character caster, L2Object[] targets)
  41. {
  42. if (caster.isAlikeDead())
  43. return;
  44. if (_npcId == 0)
  45. {
  46. _log.warning("NPC ID not defined for skill ID:"+this.getId());
  47. return;
  48. }
  49. final L2NpcTemplate template = NpcTable.getInstance().getTemplate(_npcId);
  50. if (template == null)
  51. {
  52. _log.warning("Spawn of the nonexisting NPC ID:"+_npcId+", skill ID:"+this.getId());
  53. return;
  54. }
  55. try
  56. {
  57. final L2Spawn spawn = new L2Spawn(template);
  58. spawn.setInstanceId(caster.getInstanceId());
  59. spawn.setHeading(-1);
  60. if (_randomOffset)
  61. {
  62. spawn.setLocx(caster.getX() + (Rnd.nextBoolean() ? Rnd.get(20, 50) : Rnd.get(-50, -20)));
  63. spawn.setLocy(caster.getY() + (Rnd.nextBoolean() ? Rnd.get(20, 50) : Rnd.get(-50, -20)));
  64. }
  65. else
  66. {
  67. spawn.setLocx(caster.getX());
  68. spawn.setLocy(caster.getY());
  69. }
  70. spawn.setLocz(caster.getZ() + 20);
  71. spawn.stopRespawn();
  72. L2Npc npc = spawn.spawnOne(_summonSpawn);
  73. if (_despawnDelay > 0)
  74. npc.scheduleDespawn(_despawnDelay);
  75. }
  76. catch (Exception e)
  77. {
  78. _log.warning("Exception while spawning NPC ID:"+_npcId+", skill ID:"+this.getId()+","+e);
  79. }
  80. }
  81. }