RequestAnswerJoinPledge.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 com.l2jserver.gameserver.network.clientpackets;
  16. import com.l2jserver.gameserver.instancemanager.CastleManager;
  17. import com.l2jserver.gameserver.instancemanager.FortManager;
  18. import com.l2jserver.gameserver.model.L2Clan;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.JoinPledge;
  22. import com.l2jserver.gameserver.network.serverpackets.PledgeShowInfoUpdate;
  23. import com.l2jserver.gameserver.network.serverpackets.PledgeShowMemberListAdd;
  24. import com.l2jserver.gameserver.network.serverpackets.PledgeShowMemberListAll;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * This class ...
  28. *
  29. * @version $Revision: 1.4.2.1.2.3 $ $Date: 2005/03/27 15:29:30 $
  30. */
  31. public final class RequestAnswerJoinPledge extends L2GameClientPacket
  32. {
  33. private static final String _C__25_REQUESTANSWERJOINPLEDGE = "[C] 25 RequestAnswerJoinPledge";
  34. private int _answer;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _answer = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2PcInstance activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. return;
  46. L2PcInstance requestor = activeChar.getRequest().getPartner();
  47. if (requestor == null)
  48. return;
  49. if (_answer == 0)
  50. {
  51. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_DID_NOT_RESPOND_TO_S1_CLAN_INVITATION);
  52. sm.addString(requestor.getName());
  53. activeChar.sendPacket(sm);
  54. sm = null;
  55. sm = new SystemMessage(SystemMessageId.S1_DID_NOT_RESPOND_TO_CLAN_INVITATION);
  56. sm.addString(activeChar.getName());
  57. requestor.sendPacket(sm);
  58. sm = null;
  59. }
  60. else
  61. {
  62. if (!(requestor.getRequest().getRequestPacket() instanceof RequestJoinPledge))
  63. return; // hax
  64. RequestJoinPledge requestPacket = (RequestJoinPledge) requestor.getRequest().getRequestPacket();
  65. L2Clan clan = requestor.getClan();
  66. // we must double check this cause during response time conditions can be changed, i.e. another player could join clan
  67. if (clan.checkClanJoinCondition(requestor, activeChar, requestPacket.getPledgeType()))
  68. {
  69. activeChar.sendPacket(new JoinPledge(requestor.getClanId()));
  70. activeChar.setPledgeType(requestPacket.getPledgeType());
  71. if(requestPacket.getPledgeType() == L2Clan.SUBUNIT_ACADEMY)
  72. {
  73. activeChar.setPowerGrade(9); // adademy
  74. activeChar.setLvlJoinedAcademy(activeChar.getLevel());
  75. }
  76. else
  77. activeChar.setPowerGrade(5); // new member starts at 5, not confirmed
  78. clan.addClanMember(activeChar);
  79. activeChar.setClanPrivileges(activeChar.getClan().getRankPrivs(activeChar.getPowerGrade()));
  80. activeChar.sendPacket(new SystemMessage(SystemMessageId.ENTERED_THE_CLAN));
  81. SystemMessage sm = new SystemMessage(SystemMessageId.S1_HAS_JOINED_CLAN);
  82. sm.addString(activeChar.getName());
  83. clan.broadcastToOnlineMembers(sm);
  84. sm = null;
  85. if (activeChar.getClan().getHasCastle() > 0)
  86. CastleManager.getInstance().getCastleByOwner(activeChar.getClan()).giveResidentialSkills(activeChar);
  87. if (activeChar.getClan().getHasFort() > 0)
  88. FortManager.getInstance().getFortByOwner(activeChar.getClan()).giveResidentialSkills(activeChar);
  89. activeChar.sendSkillList();
  90. clan.broadcastToOtherOnlineMembers(new PledgeShowMemberListAdd(activeChar), activeChar);
  91. clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
  92. // this activates the clan tab on the new member
  93. activeChar.sendPacket(new PledgeShowMemberListAll(clan, activeChar));
  94. activeChar.setClanJoinExpiryTime(0);
  95. activeChar.broadcastUserInfo();
  96. }
  97. }
  98. activeChar.getRequest().onRequestResponse();
  99. }
  100. /* (non-Javadoc)
  101. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  102. */
  103. @Override
  104. public String getType()
  105. {
  106. return _C__25_REQUESTANSWERJOINPLEDGE;
  107. }
  108. }