RequestEvaluate.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 net.sf.l2j.gameserver.clientpackets;
  16. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  17. import net.sf.l2j.gameserver.network.SystemMessageId;
  18. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  19. import net.sf.l2j.gameserver.serverpackets.UserInfo;
  20. public final class RequestEvaluate extends L2GameClientPacket
  21. {
  22. private static final String _C__B9_REQUESTEVALUATE = "[C] B9 RequestEvaluate";
  23. //private static Logger _log = Logger.getLogger(RequestEvaluate.class.getName());
  24. @SuppressWarnings("unused")
  25. private int _targetId;
  26. @Override
  27. protected void readImpl()
  28. {
  29. _targetId = readD();
  30. }
  31. @Override
  32. protected void runImpl()
  33. {
  34. SystemMessage sm;
  35. L2PcInstance activeChar = getClient().getActiveChar();
  36. if (activeChar == null)
  37. return;
  38. if (!(activeChar.getTarget() instanceof L2PcInstance))
  39. {
  40. sm = new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT);
  41. activeChar.sendPacket(sm);
  42. sm =null;
  43. return;
  44. }
  45. if (activeChar.getLevel() < 10)
  46. {
  47. sm = new SystemMessage(SystemMessageId.ONLY_LEVEL_SUP_10_CAN_RECOMMEND);
  48. activeChar.sendPacket(sm);
  49. sm =null;
  50. return;
  51. }
  52. if (activeChar.getTarget() == activeChar)
  53. {
  54. sm = new SystemMessage(SystemMessageId.YOU_CANNOT_RECOMMEND_YOURSELF);
  55. activeChar.sendPacket(sm);
  56. sm =null;
  57. return;
  58. }
  59. if (activeChar.getRecomLeft() <= 0)
  60. {
  61. sm = new SystemMessage(SystemMessageId.NO_MORE_RECOMMENDATIONS_TO_HAVE);
  62. activeChar.sendPacket(sm);
  63. sm =null;
  64. return;
  65. }
  66. L2PcInstance target = (L2PcInstance)activeChar.getTarget();
  67. if (target.getRecomHave() >= 255)
  68. {
  69. sm = new SystemMessage(SystemMessageId.YOUR_TARGET_NO_LONGER_RECEIVE_A_RECOMMENDATION);
  70. activeChar.sendPacket(sm);
  71. sm =null;
  72. return;
  73. }
  74. if (!activeChar.canRecom(target))
  75. {
  76. sm = new SystemMessage(SystemMessageId.THAT_CHARACTER_IS_RECOMMENDED);
  77. activeChar.sendPacket(sm);
  78. sm =null;
  79. return;
  80. }
  81. activeChar.giveRecom(target);
  82. sm = new SystemMessage(SystemMessageId.YOU_HAVE_RECOMMENDED);
  83. sm.addPcName(target);
  84. sm.addNumber(activeChar.getRecomLeft());
  85. activeChar.sendPacket(sm);
  86. sm = new SystemMessage(SystemMessageId.YOU_HAVE_BEEN_RECOMMENDED);
  87. sm.addPcName(activeChar);
  88. target.sendPacket(sm);
  89. sm =null;
  90. activeChar.sendPacket(new UserInfo(activeChar));
  91. target.broadcastUserInfo();
  92. }
  93. /* (non-Javadoc)
  94. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  95. */
  96. @Override
  97. public String getType() {
  98. return _C__B9_REQUESTEVALUATE;
  99. }
  100. }