RequestVoteNew.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
  24. import com.l2jserver.gameserver.network.serverpackets.ExVoteSystemInfo;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. import com.l2jserver.gameserver.network.serverpackets.UserInfo;
  27. public final class RequestVoteNew extends L2GameClientPacket
  28. {
  29. private static final String _C__D0_7E_REQUESTVOTENEW = "[C] D0:7E RequestVoteNew";
  30. private int _targetId;
  31. @Override
  32. protected void readImpl()
  33. {
  34. _targetId = readD();
  35. }
  36. @Override
  37. protected void runImpl()
  38. {
  39. L2PcInstance activeChar = getClient().getActiveChar();
  40. if (activeChar == null)
  41. {
  42. return;
  43. }
  44. L2Object object = activeChar.getTarget();
  45. if (!(object instanceof L2PcInstance))
  46. {
  47. if (object == null)
  48. {
  49. activeChar.sendPacket(SystemMessageId.SELECT_TARGET);
  50. }
  51. else
  52. {
  53. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  54. }
  55. return;
  56. }
  57. L2PcInstance target = (L2PcInstance) object;
  58. if (target.getObjectId() != _targetId)
  59. {
  60. return;
  61. }
  62. if (target == activeChar)
  63. {
  64. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_RECOMMEND_YOURSELF);
  65. return;
  66. }
  67. if (activeChar.getRecomLeft() <= 0)
  68. {
  69. activeChar.sendPacket(SystemMessageId.YOU_CURRENTLY_DO_NOT_HAVE_ANY_RECOMMENDATIONS);
  70. return;
  71. }
  72. if (target.getRecomHave() >= 255)
  73. {
  74. activeChar.sendPacket(SystemMessageId.YOUR_TARGET_NO_LONGER_RECEIVE_A_RECOMMENDATION);
  75. return;
  76. }
  77. activeChar.giveRecom(target);
  78. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_RECOMMENDED_C1_YOU_HAVE_S2_RECOMMENDATIONS_LEFT);
  79. sm.addPcName(target);
  80. sm.addInt(activeChar.getRecomLeft());
  81. activeChar.sendPacket(sm);
  82. sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_BEEN_RECOMMENDED_BY_C1);
  83. sm.addPcName(activeChar);
  84. target.sendPacket(sm);
  85. activeChar.sendPacket(new UserInfo(activeChar));
  86. sendPacket(new ExBrExtraUserInfo(activeChar));
  87. target.broadcastUserInfo();
  88. activeChar.sendPacket(new ExVoteSystemInfo(activeChar));
  89. target.sendPacket(new ExVoteSystemInfo(target));
  90. }
  91. @Override
  92. public String getType()
  93. {
  94. return _C__D0_7E_REQUESTVOTENEW;
  95. }
  96. }