Package lineage2.gameserver.network.clientpackets

Source Code of lineage2.gameserver.network.clientpackets.RequestJoinParty

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package lineage2.gameserver.network.clientpackets;

import lineage2.gameserver.Config;
import lineage2.gameserver.model.Party;
import lineage2.gameserver.model.Player;
import lineage2.gameserver.model.Request;
import lineage2.gameserver.model.Request.L2RequestType;
import lineage2.gameserver.model.World;
import lineage2.gameserver.network.serverpackets.AskJoinParty;
import lineage2.gameserver.network.serverpackets.SystemMessage2;
import lineage2.gameserver.network.serverpackets.components.IStaticPacket;
import lineage2.gameserver.network.serverpackets.components.SystemMsg;

/**
* @author Mobius
* @version $Revision: 1.0 $
*/
public class RequestJoinParty extends L2GameClientPacket
{
  /**
   * Field _name.
   */
  private String _name;
  /**
   * Field _itemDistribution.
   */
  private int _itemDistribution;
 
  /**
   * Method readImpl.
   */
  @Override
  protected void readImpl()
  {
    _name = readS(Config.CNAME_MAXLEN);
    _itemDistribution = readD();
  }
 
  /**
   * Method runImpl.
   */
  @Override
  protected void runImpl()
  {
    Player activeChar = getClient().getActiveChar();
    if (activeChar == null)
    {
      return;
    }
    if (activeChar.isOutOfControl())
    {
      activeChar.sendActionFailed();
      return;
    }
    if (activeChar.isProcessingRequest())
    {
      activeChar.sendPacket(SystemMsg.WAITING_FOR_ANOTHER_REPLY);
      return;
    }
    Player target = World.getPlayer(_name);
    if (target == null)
    {
      activeChar.sendPacket(SystemMsg.THAT_PLAYER_IS_NOT_ONLINE);
      return;
    }
    if (target == activeChar)
    {
      activeChar.sendPacket(SystemMsg.THAT_IS_AN_INCORRECT_TARGET);
      activeChar.sendActionFailed();
      return;
    }
    if (target.isBusy())
    {
      activeChar.sendPacket(new SystemMessage2(SystemMsg.C1_IS_ON_ANOTHER_TASK).addName(target));
      return;
    }
    IStaticPacket problem = target.canJoinParty(activeChar);
    if (problem != null)
    {
      activeChar.sendPacket(problem);
      return;
    }
    if (activeChar.isInParty())
    {
      if (activeChar.getParty().getMemberCount() >= Party.MAX_SIZE)
      {
        activeChar.sendPacket(SystemMsg.THE_PARTY_IS_FULL);
        return;
      }
      if (Config.PARTY_LEADER_ONLY_CAN_INVITE && !activeChar.getParty().isLeader(activeChar))
      {
        activeChar.sendPacket(SystemMsg.ONLY_THE_LEADER_CAN_GIVE_OUT_INVITATIONS);
        return;
      }
    }
    new Request(L2RequestType.PARTY, activeChar, target).setTimeout(10000L).set("itemDistribution", _itemDistribution);
    target.sendPacket(new AskJoinParty(activeChar.getName(), _itemDistribution));
    activeChar.sendPacket(new SystemMessage2(SystemMsg.C1_HAS_BEEN_INVITED_TO_THE_PARTY).addName(target));
  }
}
TOP

Related Classes of lineage2.gameserver.network.clientpackets.RequestJoinParty

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.