Package l2p.gameserver.clientpackets

Source Code of l2p.gameserver.clientpackets.TradeRequest

package l2p.gameserver.clientpackets;

import l2p.gameserver.cache.Msg;
import l2p.gameserver.model.L2Object;
import l2p.gameserver.model.L2Player;
import l2p.gameserver.model.L2World;
import l2p.gameserver.model.base.Transaction;
import l2p.gameserver.model.base.Transaction.TransactionType;
import l2p.gameserver.serverpackets.SendTradeRequest;
import l2p.gameserver.serverpackets.SystemMessage;
import l2p.util.Util;

public class TradeRequest extends L2GameClientPacket
{
  private int _objectId;
 
  @Override
  public void readImpl()
  {
    _objectId = readD();
  }
 
  @Override
  public void runImpl()
  {
    L2Player activeChar = getClient().getActiveChar();
    if (activeChar == null)
      return;
   
    // hex1r0: temp solution
    if (activeChar.isBlocked())
    {
      activeChar.sendActionFailed();
      return;
    }
   
    if (!activeChar.getPlayerAccess().UseTrade)
    {
      activeChar.sendPacket(Msg.THIS_ACCOUNT_CANOT_TRADE_ITEMS);
      activeChar.sendActionFailed();
      return;
    }
    String tradeBan = activeChar.getVar("tradeBan");
    if (tradeBan != null && (tradeBan.equals("-1") || Long.parseLong(tradeBan) >= System.currentTimeMillis()))
    {
      activeChar.sendMessage("Your trade is banned! Expires: " + (tradeBan.equals("-1") ? "never" : Util.formatTime((Long.parseLong(tradeBan) - System.currentTimeMillis()) / 1000)) + ".");
      return;
    }
    if (activeChar.isDead())
    {
      activeChar.sendActionFailed();
      return;
    }
    L2Object target = L2World.getAroundObjectById(activeChar, _objectId);
    if (target == null || !target.isPlayer() || target.getObjectId() == activeChar.getObjectId())
    {
      activeChar.sendPacket(Msg.THAT_IS_THE_INCORRECT_TARGET);
      return;
    }
    L2Player pcTarget = (L2Player) target;
    if (activeChar.getPrivateStoreType() != L2Player.STORE_PRIVATE_NONE || pcTarget.getPrivateStoreType() != L2Player.STORE_PRIVATE_NONE)
    {
      activeChar.sendPacket(Msg.WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
      return;
    }
    if (!pcTarget.getPlayerAccess().UseTrade)
    {
      activeChar.sendPacket(Msg.THIS_ACCOUNT_CANOT_TRADE_ITEMS);
      activeChar.sendActionFailed();
      return;
    }
    tradeBan = pcTarget.getVar("tradeBan");
    if (tradeBan != null && (tradeBan.equals("-1") || Long.parseLong(tradeBan) >= System.currentTimeMillis()))
    {
      activeChar.sendMessage("Target trade is banned! Expires: " + (tradeBan.equals("-1") ? "never" : Util.formatTime((Long.parseLong(tradeBan) - System.currentTimeMillis()) / 1000)) + ".");
      return;
    }
    if (pcTarget.getTeam() != 0)
    {
      activeChar.sendActionFailed();
      return;
    }
    if (pcTarget.isInOlympiadMode() || activeChar.isInOlympiadMode())
    {
      activeChar.sendPacket(Msg.THAT_IS_THE_INCORRECT_TARGET);
      return;
    }
    if (pcTarget.getTradeRefusal() || pcTarget.isInBlockList(activeChar) || pcTarget.isBlockAll())
    {
      activeChar.sendPacket(Msg.YOU_HAVE_BEEN_BLOCKED_FROM_THE_CONTACT_YOU_SELECTED);
      return;
    }
    if (activeChar.isInTransaction())
    {
      activeChar.sendPacket(Msg.YOU_ARE_ALREADY_TRADING_WITH_SOMEONE);
      return;
    }
    if (pcTarget.isInTransaction())
    {
      activeChar.sendPacket(new SystemMessage(SystemMessage.S1_IS_BUSY_PLEASE_TRY_AGAIN_LATER).addString(pcTarget.getName()));
      return;
    }
    if (activeChar.isFishing())
    {
      activeChar.sendPacket(Msg.YOU_CANNOT_DO_THAT_WHILE_FISHING);
      return;
    }
    new Transaction(TransactionType.TRADE_REQUEST, activeChar, pcTarget, 10000);
    pcTarget.sendPacket(new SendTradeRequest(activeChar.getObjectId()));
    activeChar.sendPacket(new SystemMessage(SystemMessage.YOU_HAVE_REQUESTED_A_TRADE_WITH_C1).addString(pcTarget.getName()));
  }
}
TOP

Related Classes of l2p.gameserver.clientpackets.TradeRequest

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.