SummonFriend.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.L2Party;
  20. import com.l2jserver.gameserver.model.L2Skill;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  27. import com.l2jserver.gameserver.util.Util;
  28. /**
  29. * @author BiTi, Sami, Zoey76
  30. */
  31. public class SummonFriend implements ISkillHandler
  32. {
  33. private static final L2SkillType[] SKILL_IDS = { L2SkillType.SUMMON_FRIEND };
  34. @Override
  35. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  36. {
  37. if (!(activeChar instanceof L2PcInstance))
  38. {
  39. return;
  40. }
  41. final boolean isMastersCall = skill.getId() == 23249;
  42. final L2PcInstance activePlayer = activeChar.getActingPlayer();
  43. if (!isMastersCall && !L2PcInstance.checkSummonerStatus(activePlayer))
  44. {
  45. return;
  46. }
  47. try
  48. {
  49. for (L2Character target : (L2Character[]) targets)
  50. {
  51. if ((target == null) || (activeChar == target))
  52. {
  53. continue;
  54. }
  55. if (target instanceof L2PcInstance)
  56. {
  57. if (isMastersCall) //Master's Call
  58. {
  59. final L2Party party = target.getParty();
  60. if (party != null)
  61. {
  62. for (L2PcInstance partyMember : party.getPartyMembers())
  63. {
  64. if (target != partyMember)
  65. {
  66. partyMember.teleToLocation(target.getX(), target.getY(), target.getZ(), true);
  67. }
  68. }
  69. }
  70. else
  71. {
  72. activePlayer.sendMessage(target.getName() + " doesn't have a party.");
  73. }
  74. continue;
  75. }
  76. final L2PcInstance targetPlayer = target.getActingPlayer();
  77. if (!L2PcInstance.checkSummonTargetStatus(targetPlayer, activePlayer))
  78. {
  79. continue;
  80. }
  81. if (!Util.checkIfInRange(0, activeChar, target, false))
  82. {
  83. if (!targetPlayer.teleportRequest(activePlayer, skill))
  84. {
  85. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ALREADY_SUMMONED);
  86. sm.addString(target.getName());
  87. activePlayer.sendPacket(sm);
  88. continue;
  89. }
  90. if (skill.getId() == 1403) //Summon Friend
  91. {
  92. // Send message
  93. final ConfirmDlg confirm = new ConfirmDlg(SystemMessageId.C1_WISHES_TO_SUMMON_YOU_FROM_S2_DO_YOU_ACCEPT.getId());
  94. confirm.addCharName(activeChar);
  95. confirm.addZoneName(activeChar.getX(), activeChar.getY(), activeChar.getZ());
  96. confirm.addTime(30000);
  97. confirm.addRequesterId(activePlayer.getObjectId());
  98. target.sendPacket(confirm);
  99. }
  100. else
  101. {
  102. L2PcInstance.teleToTarget(targetPlayer, activePlayer, skill);
  103. targetPlayer.teleportRequest(null, null);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. catch (Exception e)
  110. {
  111. _log.log(Level.SEVERE, "", e);
  112. }
  113. }
  114. @Override
  115. public L2SkillType[] getSkillIds()
  116. {
  117. return SKILL_IDS;
  118. }
  119. }