MercTicket.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2004-2015 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.itemhandlers;
  20. import com.l2jserver.gameserver.SevenSigns;
  21. import com.l2jserver.gameserver.handler.IItemHandler;
  22. import com.l2jserver.gameserver.instancemanager.CastleManager;
  23. import com.l2jserver.gameserver.instancemanager.MercTicketManager;
  24. import com.l2jserver.gameserver.model.actor.L2Playable;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.Castle;
  27. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. public class MercTicket implements IItemHandler
  30. {
  31. /**
  32. * handler for using mercenary tickets. Things to do: 1) Check constraints: 1.a) Tickets may only be used in a castle 1.b) Only specific tickets may be used in each castle (different tickets for each castle) 1.c) only the owner of that castle may use them 1.d) tickets cannot be used during siege
  33. * 1.e) Check if max number of tickets has been reached 1.f) Check if max number of tickets from this ticket's TYPE has been reached 2) If allowed, call the MercTicketManager to add the item and spawn in the world 3) Remove the item from the person's inventory
  34. */
  35. @Override
  36. public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  37. {
  38. if (!playable.isPlayer())
  39. {
  40. playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
  41. return false;
  42. }
  43. int itemId = item.getId();
  44. L2PcInstance activeChar = (L2PcInstance) playable;
  45. Castle castle = CastleManager.getInstance().getCastle(activeChar);
  46. int castleId = -1;
  47. if (castle != null)
  48. {
  49. castleId = castle.getResidenceId();
  50. }
  51. // add check that certain tickets can only be placed in certain castles
  52. if (MercTicketManager.getInstance().getTicketCastleId(itemId) != castleId)
  53. {
  54. activeChar.sendPacket(SystemMessageId.MERCENARIES_CANNOT_BE_POSITIONED_HERE);
  55. return false;
  56. }
  57. else if (!activeChar.isCastleLord(castleId))
  58. {
  59. activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_AUTHORITY_TO_POSITION_MERCENARIES);
  60. return false;
  61. }
  62. else if ((castle != null) && castle.getSiege().isInProgress())
  63. {
  64. activeChar.sendPacket(SystemMessageId.THIS_MERCENARY_CANNOT_BE_POSITIONED_ANYMORE);
  65. return false;
  66. }
  67. // Checking Seven Signs Quest Period
  68. if (SevenSigns.getInstance().getCurrentPeriod() != SevenSigns.PERIOD_SEAL_VALIDATION)
  69. {
  70. // _log.warning("Someone has tried to spawn a guardian during Quest Event Period of The Seven Signs.");
  71. activeChar.sendPacket(SystemMessageId.THIS_MERCENARY_CANNOT_BE_POSITIONED_ANYMORE);
  72. return false;
  73. }
  74. // Checking the Seal of Strife status
  75. switch (SevenSigns.getInstance().getSealOwner(SevenSigns.SEAL_STRIFE))
  76. {
  77. case SevenSigns.CABAL_NULL:
  78. {
  79. if (SevenSigns.getInstance().checkIsDawnPostingTicket(itemId))
  80. {
  81. // _log.warning("Someone has tried to spawn a Dawn Mercenary though the Seal of Strife is not controlled by anyone.");
  82. activeChar.sendPacket(SystemMessageId.THIS_MERCENARY_CANNOT_BE_POSITIONED_ANYMORE);
  83. return false;
  84. }
  85. break;
  86. }
  87. case SevenSigns.CABAL_DUSK:
  88. {
  89. if (!SevenSigns.getInstance().checkIsRookiePostingTicket(itemId))
  90. {
  91. // _log.warning("Someone has tried to spawn a non-Rookie Mercenary though the Seal of Strife is controlled by Revolutionaries of Dusk.");
  92. activeChar.sendPacket(SystemMessageId.THIS_MERCENARY_CANNOT_BE_POSITIONED_ANYMORE);
  93. return false;
  94. }
  95. break;
  96. }
  97. case SevenSigns.CABAL_DAWN:
  98. {
  99. break;
  100. }
  101. }
  102. if (MercTicketManager.getInstance().isAtCasleLimit(item.getId()))
  103. {
  104. activeChar.sendPacket(SystemMessageId.THIS_MERCENARY_CANNOT_BE_POSITIONED_ANYMORE);
  105. return false;
  106. }
  107. else if (MercTicketManager.getInstance().isAtTypeLimit(item.getId()))
  108. {
  109. activeChar.sendPacket(SystemMessageId.THIS_MERCENARY_CANNOT_BE_POSITIONED_ANYMORE);
  110. return false;
  111. }
  112. else if (MercTicketManager.getInstance().isTooCloseToAnotherTicket(activeChar.getX(), activeChar.getY(), activeChar.getZ()))
  113. {
  114. activeChar.sendPacket(SystemMessageId.POSITIONING_CANNOT_BE_DONE_BECAUSE_DISTANCE_BETWEEN_MERCENARIES_TOO_SHORT);
  115. return false;
  116. }
  117. MercTicketManager.getInstance().addTicket(item.getId(), activeChar);
  118. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false); // Remove item from char's inventory
  119. activeChar.sendPacket(SystemMessageId.PLACE_CURRENT_LOCATION_DIRECTION);
  120. return true;
  121. }
  122. }