MercTicket.java 5.2 KB

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