Summon.java 4.1 KB

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