Summon.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.effecthandlers;
  20. import com.l2jserver.gameserver.data.xml.impl.ExperienceData;
  21. import com.l2jserver.gameserver.data.xml.impl.NpcData;
  22. import com.l2jserver.gameserver.enums.Race;
  23. import com.l2jserver.gameserver.model.StatsSet;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2ServitorInstance;
  26. import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
  27. import com.l2jserver.gameserver.model.conditions.Condition;
  28. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  29. import com.l2jserver.gameserver.model.holders.ItemHolder;
  30. import com.l2jserver.gameserver.model.skills.BuffInfo;
  31. /**
  32. * Summon effect implementation.
  33. * @author UnAfraid
  34. */
  35. public final class Summon extends AbstractEffect
  36. {
  37. private final int _npcId;
  38. private final float _expMultiplier;
  39. private final ItemHolder _consumeItem;
  40. private final int _lifeTime;
  41. private final int _consumeItemInterval;
  42. public Summon(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  43. {
  44. super(attachCond, applyCond, set, params);
  45. if (params.isEmpty())
  46. {
  47. throw new IllegalArgumentException("Summon effect without parameters!");
  48. }
  49. _npcId = params.getInt("npcId");
  50. _expMultiplier = params.getFloat("expMultiplier", 1);
  51. _consumeItem = new ItemHolder(params.getInt("consumeItemId", 0), params.getInt("consumeItemCount", 1));
  52. _consumeItemInterval = params.getInt("consumeItemInterval", 0);
  53. _lifeTime = params.getInt("lifeTime", 3600) * 1000;
  54. }
  55. @Override
  56. public boolean isInstant()
  57. {
  58. return true;
  59. }
  60. @Override
  61. public void onStart(BuffInfo info)
  62. {
  63. if (!info.getEffected().isPlayer() || info.getEffected().hasSummon())
  64. {
  65. return;
  66. }
  67. final L2PcInstance player = info.getEffected().getActingPlayer();
  68. final L2NpcTemplate template = NpcData.getInstance().getTemplate(_npcId);
  69. final L2ServitorInstance summon = new L2ServitorInstance(template, player);
  70. final int consumeItemInterval = (_consumeItemInterval > 0 ? _consumeItemInterval : (template.getRace() != Race.SIEGE_WEAPON ? 240 : 60)) * 1000;
  71. summon.setName(template.getName());
  72. summon.setTitle(info.getEffected().getName());
  73. summon.setReferenceSkill(info.getSkill().getId());
  74. summon.setExpMultiplier(_expMultiplier);
  75. summon.setLifeTime(_lifeTime);
  76. summon.setItemConsume(_consumeItem);
  77. summon.setItemConsumeInterval(consumeItemInterval);
  78. if (summon.getLevel() >= ExperienceData.getInstance().getMaxPetLevel())
  79. {
  80. summon.getStat().setExp(ExperienceData.getInstance().getExpForLevel(ExperienceData.getInstance().getMaxPetLevel() - 1));
  81. _log.warning(Summon.class.getSimpleName() + ": (" + summon.getName() + ") NpcID: " + summon.getId() + " has a level above " + ExperienceData.getInstance().getMaxPetLevel() + ". Please rectify.");
  82. }
  83. else
  84. {
  85. summon.getStat().setExp(ExperienceData.getInstance().getExpForLevel(summon.getLevel() % ExperienceData.getInstance().getMaxPetLevel()));
  86. }
  87. summon.setCurrentHp(summon.getMaxHp());
  88. summon.setCurrentMp(summon.getMaxMp());
  89. summon.setHeading(player.getHeading());
  90. player.setPet(summon);
  91. summon.setRunning();
  92. summon.spawnMe();
  93. }
  94. }