SummonFriend.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 handlers.skillhandlers;
  16. import java.util.logging.Level;
  17. import com.l2jserver.gameserver.handler.ISkillHandler;
  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.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
  24. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  25. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  26. import com.l2jserver.gameserver.util.Util;
  27. /**
  28. * @authors BiTi, Sami
  29. *
  30. */
  31. public class SummonFriend implements ISkillHandler
  32. {
  33. //private static Logger _log = Logger.getLogger(SummonFriend.class.getName());
  34. private static final L2SkillType[] SKILL_IDS =
  35. {
  36. L2SkillType.SUMMON_FRIEND
  37. };
  38. /**
  39. *
  40. * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
  41. */
  42. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  43. {
  44. if (!(activeChar instanceof L2PcInstance))
  45. return; // currently not implemented for others
  46. L2PcInstance activePlayer = (L2PcInstance) activeChar;
  47. if (!L2PcInstance.checkSummonerStatus(activePlayer))
  48. return;
  49. try
  50. {
  51. for (L2Character target: (L2Character[]) targets)
  52. {
  53. if (activeChar == target)
  54. continue;
  55. if (target instanceof L2PcInstance)
  56. {
  57. L2PcInstance targetPlayer = (L2PcInstance) target;
  58. if (!L2PcInstance.checkSummonTargetStatus(targetPlayer, activePlayer))
  59. continue;
  60. if (!Util.checkIfInRange(0, activeChar, target, false))
  61. {
  62. if(!targetPlayer.teleportRequest(activePlayer, skill))
  63. {
  64. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ALREADY_SUMMONED);
  65. sm.addString(target.getName());
  66. activePlayer.sendPacket(sm);
  67. continue;
  68. }
  69. if (skill.getId() == 1403) //summon friend
  70. {
  71. // Send message
  72. ConfirmDlg confirm = new ConfirmDlg(SystemMessageId.C1_WISHES_TO_SUMMON_YOU_FROM_S2_DO_YOU_ACCEPT.getId());
  73. confirm.addCharName(activeChar);
  74. confirm.addZoneName(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  75. confirm.addTime(30000);
  76. confirm.addRequesterId(activePlayer.getObjectId());
  77. target.sendPacket(confirm);
  78. }
  79. else
  80. {
  81. L2PcInstance.teleToTarget(targetPlayer, activePlayer, skill);
  82. targetPlayer.teleportRequest(null, null);
  83. }
  84. }
  85. }
  86. }
  87. }
  88. catch (Exception e)
  89. {
  90. _log.log(Level.SEVERE, "", e);
  91. }
  92. }
  93. /**
  94. *
  95. * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
  96. */
  97. public L2SkillType[] getSkillIds()
  98. {
  99. return SKILL_IDS;
  100. }
  101. }