L2SkillSpawn.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.idfactory.IdFactory;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2BirthdayCakeInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2TotemInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2XmassTreeInstance;
  26. import com.l2jserver.gameserver.templates.StatsSet;
  27. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  28. import com.l2jserver.util.Rnd;
  29. public class L2SkillSpawn extends L2Skill
  30. {
  31. private final int _npcId;
  32. private final int _despawnDelay;
  33. private final boolean _summonSpawn;
  34. private final boolean _randomOffset;
  35. private final int _skillToCast;
  36. public L2SkillSpawn(StatsSet set)
  37. {
  38. super(set);
  39. _npcId = set.getInteger("npcId", 0);
  40. _despawnDelay = set.getInteger("despawnDelay", 0);
  41. _summonSpawn = set.getBool("isSummonSpawn", false);
  42. _randomOffset = set.getBool("randomOffset", true);
  43. _skillToCast = set.getInteger("skillToCast", 0);
  44. }
  45. @Override
  46. public void useSkill(L2Character caster, L2Object[] targets)
  47. {
  48. int x, y;
  49. if (caster.isAlikeDead())
  50. return;
  51. if (_npcId == 0)
  52. {
  53. _log.warning("NPC ID not defined for skill ID:" + getId());
  54. return;
  55. }
  56. L2Npc npc;
  57. final L2NpcTemplate template = NpcTable.getInstance().getTemplate(_npcId);
  58. if (template == null)
  59. {
  60. _log.warning("Spawn of the nonexisting NPC ID:" + _npcId + ", skill ID:" + getId());
  61. return;
  62. }
  63. if (template.type.equalsIgnoreCase("L2XmassTree"))
  64. npc = new L2XmassTreeInstance(IdFactory.getInstance().getNextId(), template);
  65. else if (template.type.equalsIgnoreCase("L2BirthdayCake"))
  66. npc = new L2BirthdayCakeInstance(IdFactory.getInstance().getNextId(), template, caster.getObjectId());
  67. else if (template.type.equalsIgnoreCase("L2Totem"))
  68. npc = new L2TotemInstance(IdFactory.getInstance().getNextId(), template, _skillToCast);
  69. /*
  70. * TODO
  71. * else if (template.type.equalsIgnoreCase("L2WeddingCake"))
  72. * npc = new L2WeddingCakeInstance(IdFactory.getInstance().getNextId(), template);
  73. */
  74. else
  75. npc = new L2NpcInstance(IdFactory.getInstance().getNextId(), template);
  76. npc.setName(template.name);
  77. npc.setTitle(caster.getName());
  78. npc.setHeading(-1);
  79. npc.setShowSummonAnimation(_summonSpawn);
  80. if (_randomOffset)
  81. {
  82. x = caster.getX() + (Rnd.nextBoolean() ? Rnd.get(20, 50) : Rnd.get(-50, -20));
  83. y = caster.getY() + (Rnd.nextBoolean() ? Rnd.get(20, 50) : Rnd.get(-50, -20));
  84. }
  85. else
  86. {
  87. x = caster.getX();
  88. y = caster.getY();
  89. }
  90. npc.spawnMe(x, y, caster.getZ() + 20);
  91. if (_despawnDelay > 0)
  92. npc.scheduleDespawn(_despawnDelay);
  93. }
  94. }