Package l2p.gameserver.model.instances

Source Code of l2p.gameserver.model.instances.L2ClanTraderInstance

package l2p.gameserver.model.instances;

import l2p.Config;
import l2p.gameserver.model.L2Player;
import l2p.gameserver.model.items.L2ItemInstance;
import l2p.gameserver.serverpackets.NpcHtmlMessage;
import l2p.gameserver.serverpackets.PledgeShowInfoUpdate;
import l2p.gameserver.serverpackets.SystemMessage;
import l2p.gameserver.templates.L2NpcTemplate;

public final class L2ClanTraderInstance extends L2NpcInstance
{
  public L2ClanTraderInstance(int objectId, L2NpcTemplate template)
  {
    super(objectId, template);
  }

  @Override
  public void onBypassFeedback(L2Player player, String command)
  {
    if(!canBypassCheck(player, this))
    {
      return;
    }
    NpcHtmlMessage html = new NpcHtmlMessage(player, this);
    if(command.equalsIgnoreCase("crp"))
    {
      if(player.getClan() != null && player.getClan().getLevel() > 4)
      {
        html.setFile("data/html/default/" + getNpcId() + "-2.htm");
      }
      else
      {
        html.setFile("data/html/default/" + getNpcId() + "-1.htm");
      }
      html.replace("%objectId%", String.valueOf(getObjectId()));
      player.sendPacket(html);
    }
    else if(command.startsWith("exchange"))
    {
      if(!player.isClanLeader())
      {
        html.setFile("data/html/default/" + getNpcId() + "-no.htm");
        html.replace("%objectId%", String.valueOf(getObjectId()));
        player.sendPacket(html);
        return;
      }
      int itemId = Integer.parseInt(command.substring(9).trim());
      int reputation = 0;
      long itemCount = 0;
      L2ItemInstance item = player.getInventory().getItemByItemId(itemId);
      long playerItemCount = item == null ? 0 : item.getCount();
      switch(itemId)
      {
        case 9911: // Blood alliance
          reputation = Config.ClanTraderBloodAllianceReputation;
          itemCount = Config.ClanTraderBloodAllianceItemCount;
          break;
        case 9910: // 10 Blood oath
          reputation = Config.ClanTraderBloodOathReputation;
          itemCount = Config.ClanTraderBloodOathItemCount;
          break;
        case 9912: // 100 Knight's Epaulettes
          reputation = Config.ClanTraderKnightsEpaulettesReputation;
          itemCount = Config.ClanTraderKnightsEpaulettesItemCount;
          break;
      }
      if(playerItemCount >= itemCount)
      {
        player.getInventory().destroyItemByItemId(itemId, itemCount, true);
        player.getClan().incReputation(reputation, false, "ClanTrader " + itemId + " from " + player.getName());
        player.getClan().broadcastToOnlineMembers(new PledgeShowInfoUpdate(player.getClan()));
        player.sendPacket(new SystemMessage(SystemMessage.YOUR_CLAN_HAS_ADDED_1S_POINTS_TO_ITS_CLAN_REPUTATION_SCORE).addNumber(reputation));
        html.setFile("data/html/default/" + getNpcId() + "-ExchangeSuccess.htm");
      }
      else
      {
        html.setFile("data/html/default/" + getNpcId() + "-ExchangeFailed.htm");
      }
      html.replace("%objectId%", String.valueOf(getObjectId()));
      player.sendPacket(html);
    }
    else
    {
      super.onBypassFeedback(player, command);
    }
  }
}
TOP

Related Classes of l2p.gameserver.model.instances.L2ClanTraderInstance

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.