MercTicket.java 5.1 KB

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