L2SkillSpawn.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. final L2NpcTemplate template = NpcTable.getInstance().getTemplate(_npcId);
  57. if (template == null)
  58. {
  59. _log.warning("Spawn of the nonexisting NPC ID:" + _npcId + ", skill ID:" + getId());
  60. return;
  61. }
  62. final int id = IdFactory.getInstance().getNextId();
  63. final L2Npc npc;
  64. if (template.isType("L2XmassTree"))
  65. {
  66. npc = new L2XmassTreeInstance(id, template);
  67. }
  68. else if (template.isType("L2BirthdayCake"))
  69. {
  70. npc = new L2BirthdayCakeInstance(id, template, caster.getObjectId());
  71. }
  72. else if (template.isType("L2Totem"))
  73. {
  74. npc = new L2TotemInstance(id, template, _skillToCast);
  75. }
  76. else if (template.isType("L2WeddingCake"))
  77. {
  78. // TODO: npc = new L2WeddingCakeInstance(id, template);
  79. npc = new L2NpcInstance(id, template);
  80. }
  81. else
  82. {
  83. npc = new L2NpcInstance(id, template);
  84. }
  85. npc.setName(template.getName());
  86. npc.setTitle(caster.getName());
  87. npc.setHeading(-1);
  88. npc.setShowSummonAnimation(_summonSpawn);
  89. if (_randomOffset)
  90. {
  91. x = caster.getX() + (Rnd.nextBoolean() ? Rnd.get(20, 50) : Rnd.get(-50, -20));
  92. y = caster.getY() + (Rnd.nextBoolean() ? Rnd.get(20, 50) : Rnd.get(-50, -20));
  93. }
  94. else
  95. {
  96. x = caster.getX();
  97. y = caster.getY();
  98. }
  99. npc.spawnMe(x, y, caster.getZ() + 20);
  100. if (_despawnDelay > 0)
  101. npc.scheduleDespawn(_despawnDelay);
  102. }
  103. }