/**
   * this displays PledgeSkillList to the player.
   *
   * @param player
   */
  public void showPledgeSkillList(L2PcInstance player) {
    if (Config.DEBUG) {
      _log.info("PledgeSkillList activated on: " + getObjectId());
    }
    if (player.getClan() == null) return;

    L2PledgeSkillLearn[] skills = SkillTreeTable.getInstance().getAvailablePledgeSkills(player);
    AquireSkillList asl = new AquireSkillList(AquireSkillList.skillType.Clan);
    int counts = 0;

    for (L2PledgeSkillLearn s : skills) {
      int cost = s.getRepCost();
      counts++;

      asl.addSkill(s.getId(), s.getLevel(), s.getLevel(), cost, 0);
    }
    skills = null;

    if (counts == 0) {
      NpcHtmlMessage html = new NpcHtmlMessage(1);

      if (player.getClan().getLevel() < 8) {
        SystemMessage sm = new SystemMessage(SystemMessageId.DO_NOT_HAVE_FURTHER_SKILLS_TO_LEARN);
        sm.addNumber(player.getClan().getLevel() + 1);
        player.sendPacket(sm);
        sm = null;
      } else {
        TextBuilder sb = new TextBuilder();
        sb.append("<html><body>");
        sb.append("You've learned all skills available for your Clan.<br>");
        sb.append("</body></html>");
        html.setHtml(sb.toString());
        player.sendPacket(html);
        html = null;
        sb = null;
      }
    } else {
      player.sendPacket(asl);
    }

    asl = null;
    player.sendPacket(ActionFailed.STATIC_PACKET);
  }
  public void createSubPledge(
      L2PcInstance player, String clanName, String leaderName, int pledgeType, int minClanLvl) {
    if (Config.DEBUG) {
      _log.info(
          player.getObjectId()
              + "("
              + player.getName()
              + ") requested sub clan creation from "
              + getObjectId()
              + "("
              + getName()
              + ")");
    }

    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    L2Clan clan = player.getClan();
    if (clan.getLevel() < minClanLvl) {
      if (pledgeType == L2Clan.SUBUNIT_ACADEMY) {
        player.sendPacket(
            new SystemMessage(
                SystemMessageId.YOU_DO_NOT_MEET_CRITERIA_IN_ORDER_TO_CREATE_A_CLAN_ACADEMY));
      } else {
        player.sendPacket(
            new SystemMessage(
                SystemMessageId.YOU_DO_NOT_MEET_CRITERIA_IN_ORDER_TO_CREATE_A_MILITARY_UNIT));
      }
      return;
    }

    if (!Util.isAlphaNumeric(clanName) || 2 > clanName.length()) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT));
      return;
    }

    if (clanName.length() > 16) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_TOO_LONG));
      return;
    }
    for (L2Clan tempClan : ClanTable.getInstance().getClans()) {
      if (tempClan.getSubPledge(clanName) != null) {
        if (pledgeType == L2Clan.SUBUNIT_ACADEMY) {
          SystemMessage sm = new SystemMessage(SystemMessageId.S1_ALREADY_EXISTS);
          sm.addString(clanName);
          player.sendPacket(sm);
          sm = null;
        } else {
          player.sendPacket(
              new SystemMessage(SystemMessageId.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME));
        }
        return;
      }
    }

    if (pledgeType != L2Clan.SUBUNIT_ACADEMY)
      if (clan.getClanMember(leaderName) == null
          || clan.getClanMember(leaderName).getPledgeType() != 0) {
        if (pledgeType >= L2Clan.SUBUNIT_KNIGHT1) {
          player.sendPacket(
              new SystemMessage(SystemMessageId.CAPTAIN_OF_ORDER_OF_KNIGHTS_CANNOT_BE_APPOINTED));
        } else if (pledgeType >= L2Clan.SUBUNIT_ROYAL1) {
          player.sendPacket(
              new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED));
        }
        return;
      }

    int leaderId =
        clan.getClanMember(leaderName) != null ? clan.getClanMember(leaderName).getObjectId() : 0;

    if (clan.createSubPledge(player, pledgeType, leaderId, clanName) == null) return;

    SystemMessage sm;
    if (pledgeType == L2Clan.SUBUNIT_ACADEMY) {
      sm = new SystemMessage(SystemMessageId.THE_S1S_CLAN_ACADEMY_HAS_BEEN_CREATED);
      sm.addString(player.getClan().getName());
    } else if (pledgeType >= L2Clan.SUBUNIT_KNIGHT1) {
      sm = new SystemMessage(SystemMessageId.THE_KNIGHTS_OF_S1_HAVE_BEEN_CREATED);
      sm.addString(player.getClan().getName());
    } else if (pledgeType >= L2Clan.SUBUNIT_ROYAL1) {
      sm = new SystemMessage(SystemMessageId.THE_ROYAL_GUARD_OF_S1_HAVE_BEEN_CREATED);
      sm.addString(player.getClan().getName());
    } else {
      sm = new SystemMessage(SystemMessageId.CLAN_CREATED);
    }

    player.sendPacket(sm);
    if (pledgeType != L2Clan.SUBUNIT_ACADEMY) {
      L2ClanMember leaderSubPledge = clan.getClanMember(leaderName);
      if (leaderSubPledge.getPlayerInstance() == null) return;

      leaderSubPledge
          .getPlayerInstance()
          .setPledgeClass(
              leaderSubPledge.calculatePledgeClass(leaderSubPledge.getPlayerInstance()));
      leaderSubPledge
          .getPlayerInstance()
          .sendPacket(new UserInfo(leaderSubPledge.getPlayerInstance()));
    }
    clan = null;
    sm = null;
  }
  public void assignSubPledgeLeader(L2PcInstance player, String clanName, String leaderName) {
    if (Config.DEBUG) {
      _log.info(
          player.getObjectId()
              + "("
              + player.getName()
              + ") requested to assign sub clan"
              + clanName
              + "leader "
              + "("
              + leaderName
              + ")");
    }

    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    if (leaderName.length() > 16) {
      player.sendPacket(new SystemMessage(SystemMessageId.NAMING_CHARNAME_UP_TO_16CHARS));
      return;
    }

    if (player.getName().equals(leaderName)) {
      player.sendPacket(
          new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED));
      return;
    }

    L2Clan clan = player.getClan();
    SubPledge subPledge = player.getClan().getSubPledge(clanName);
    if (null == subPledge) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT));
      return;
    }

    if (subPledge.getId() == L2Clan.SUBUNIT_ACADEMY) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT));
      return;
    }

    if (clan.getClanMember(leaderName) == null
        || clan.getClanMember(leaderName).getPledgeType() != 0) {
      if (subPledge.getId() >= L2Clan.SUBUNIT_KNIGHT1) {
        player.sendPacket(
            new SystemMessage(SystemMessageId.CAPTAIN_OF_ORDER_OF_KNIGHTS_CANNOT_BE_APPOINTED));
      } else if (subPledge.getId() >= L2Clan.SUBUNIT_ROYAL1) {
        player.sendPacket(
            new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED));
      }
      return;
    }

    L2ClanMember leaderSubPledge = clan.getClanMember(leaderName);
    subPledge.setLeaderId(leaderSubPledge.getObjectId());
    clan.updateSubPledgeInDB(subPledge.getId());
    L2PcInstance leaderPlayer = leaderSubPledge.getPlayerInstance();
    if (leaderPlayer != null) {
      leaderPlayer.setPledgeClass(leaderSubPledge.calculatePledgeClass(leaderPlayer));
      leaderPlayer.sendPacket(new UserInfo(leaderPlayer));
    }
    clan.broadcastClanStatus();
    SystemMessage sm = new SystemMessage(SystemMessageId.S1_HAS_BEEN_SELECTED_AS_CAPTAIN_OF_S2);
    sm.addString(leaderName);
    sm.addString(clanName);
    clan.broadcastToOnlineMembers(sm);
    sm = null;
    clan = null;
    subPledge = null;
    leaderPlayer = null;
    leaderSubPledge = null;
  }
  public void changeClanLeader(L2PcInstance player, String target) {
    if (Config.DEBUG) {
      _log.info(
          player.getObjectId()
              + "("
              + player.getName()
              + ") requested change a clan leader from "
              + getObjectId()
              + "("
              + getName()
              + ")");
    }

    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    if (player.isFlying()) {
      player.sendMessage("Get off the Wyvern first.");
      return;
    }

    if (player.getName().equalsIgnoreCase(target)) return;

    L2Clan clan = player.getClan();
    L2ClanMember member = clan.getClanMember(target);
    if (member == null) {
      SystemMessage sm = new SystemMessage(SystemMessageId.S1_DOES_NOT_EXIST);
      sm.addString(target);
      player.sendPacket(sm);
      sm = null;
      return;
    }

    if (!member.isOnline()) {
      player.sendPacket(new SystemMessage(SystemMessageId.INVITED_USER_NOT_ONLINE));
      return;
    }

    if (member.getPledgeType() == L2Clan.SUBUNIT_ACADEMY) {
      player.sendMessage("Can`t give to academy member.");
      return;
    }

    for (Siege siege : SiegeManager.getInstance().getSieges()) {
      if (!siege.getIsInProgress()) {
        continue;
      }

      if (siege.checkIsAttacker(clan) || siege.checkIsDefender(clan)) {
        player.sendMessage("You are not authorized to do that during the siege.");
        return;
      }
    }

    clan.setNewLeader(member);

    clan = null;
    member = null;
  }