* @param minClanLvl int
* @param leaderName String
*/
public void createSubPledge(Player player, String clanName, int pledgeType, int minClanLvl, String leaderName)
{
UnitMember subLeader = null;
Clan clan = player.getClan();
if ((clan == null) || !player.isClanLeader())
{
player.sendPacket(Msg.YOU_HAVE_FAILED_TO_CREATE_A_CLAN);
return;
}
if (!Util.isMatchingRegexp(clanName, Config.CLAN_NAME_TEMPLATE))
{
player.sendPacket(Msg.CLAN_NAME_IS_INCORRECT);
return;
}
Collection<SubUnit> subPledge = clan.getAllSubUnits();
for (SubUnit element : subPledge)
{
if (element.getName().equals(clanName))
{
player.sendPacket(Msg.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME_PLEASE_ENTER_A_DIFFERENT_NAME);
return;
}
}
if (ClanTable.getInstance().getClanByName(clanName) != null)
{
player.sendPacket(Msg.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME_PLEASE_ENTER_A_DIFFERENT_NAME);
return;
}
if (clan.getLevel() < minClanLvl)
{
player.sendPacket(Msg.THE_CONDITIONS_NECESSARY_TO_CREATE_A_MILITARY_UNIT_HAVE_NOT_BEEN_MET);
return;
}
SubUnit unit = clan.getSubUnit(Clan.SUBUNIT_MAIN_CLAN);
if (pledgeType != Clan.SUBUNIT_ACADEMY)
{
subLeader = unit.getUnitMember(leaderName);
if (subLeader == null)
{
player.sendMessage(new CustomMessage("lineage2.gameserver.model.instances.L2VillageMasterInstance.PlayerCantBeAssignedAsSubUnitLeader", player));
return;
}
else if (subLeader.getLeaderOf() != Clan.SUBUNIT_NONE)
{
player.sendMessage(new CustomMessage("lineage2.gameserver.model.instances.L2VillageMasterInstance.ItCantBeSubUnitLeader", player));
return;
}
}
pledgeType = clan.createSubPledge(player, pledgeType, subLeader, clanName);
if (pledgeType == Clan.SUBUNIT_NONE)
{
return;
}
clan.broadcastToOnlineMembers(new PledgeReceiveSubPledgeCreated(clan.getSubUnit(pledgeType)));
SystemMessage sm;
if (pledgeType == Clan.SUBUNIT_ACADEMY)
{
sm = new SystemMessage(SystemMessage.CONGRATULATIONS_THE_S1S_CLAN_ACADEMY_HAS_BEEN_CREATED);
sm.addString(player.getClan().getName());
}
else if (pledgeType >= Clan.SUBUNIT_KNIGHT1)
{
sm = new SystemMessage(SystemMessage.THE_KNIGHTS_OF_S1_HAVE_BEEN_CREATED);
sm.addString(player.getClan().getName());
}
else if (pledgeType >= Clan.SUBUNIT_ROYAL1)
{
sm = new SystemMessage(SystemMessage.THE_ROYAL_GUARD_OF_S1_HAVE_BEEN_CREATED);
sm.addString(player.getClan().getName());
}
else
{
sm = Msg.CLAN_HAS_BEEN_CREATED;
}
player.sendPacket(sm);
if (subLeader != null)
{
clan.broadcastToOnlineMembers(new PledgeShowMemberListUpdate(subLeader));
if (subLeader.isOnline())
{
subLeader.getPlayer().updatePledgeClass();
subLeader.getPlayer().broadcastCharInfo();
}
}
}