SummonFriend.java 3.9 KB

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