L2SkillDecoy.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.L2World;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2DecoyInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.templates.StatsSet;
  25. import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  26. public class L2SkillDecoy extends L2Skill
  27. {
  28. private final int _npcId;
  29. private final int _summonTotalLifeTime;
  30. public L2SkillDecoy(StatsSet set)
  31. {
  32. super(set);
  33. _npcId = set.getInteger("npcId", 0);
  34. _summonTotalLifeTime= set.getInteger("summonTotalLifeTime", 20000);
  35. }
  36. @Override
  37. public void useSkill(L2Character caster, L2Object[] targets)
  38. {
  39. if (caster.isAlikeDead() || !(caster instanceof L2PcInstance))
  40. return;
  41. if (_npcId == 0)
  42. return;
  43. final L2PcInstance activeChar = (L2PcInstance) caster;
  44. if (activeChar.inObserverMode())
  45. return;
  46. if (activeChar.getPet() != null || activeChar.isMounted())
  47. return;
  48. L2NpcTemplate DecoyTemplate = NpcTable.getInstance().getTemplate(_npcId);
  49. final L2DecoyInstance Decoy = new L2DecoyInstance(IdFactory.getInstance().getNextId(), DecoyTemplate, activeChar, this);
  50. Decoy.setCurrentHp(Decoy.getMaxHp());
  51. Decoy.setCurrentMp(Decoy.getMaxMp());
  52. Decoy.setHeading(activeChar.getHeading());
  53. activeChar.setDecoy(Decoy);
  54. L2World.getInstance().storeObject(Decoy);
  55. Decoy.spawnMe(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  56. }
  57. public final int getTotalLifeTime()
  58. {
  59. return _summonTotalLifeTime;
  60. }
  61. }