if(function.isActive() && function.getLevel() == level)
{
return true;
}
int lease = level == 0 ? 0 : getFunction(type).getLease(level);
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
if(!function.isActive())
{
if(count >= lease)
{
clan.getWarehouse().destroyItem(57, lease);
}
else
{
return false;
}
long time = Calendar.getInstance().getTimeInMillis() + 86400000;
statement = con.prepareStatement("REPLACE residence_functions SET id=?, type=?, lvl=?, endTime=?");
statement.setInt(1, getId());
statement.setInt(2, type);
statement.setInt(3, level);
statement.setInt(4, (int) (time / 1000));
statement.execute();
function.setLvl(level);
function.setEndTimeInMillis(time);
function.setActive(true);
StartAutoTaskForFunction(function);
}
else
{
if(count >= lease - getFunction(type).getLease())
{
if(lease > getFunction(type).getLease())
{
clan.getWarehouse().destroyItem(57, lease - getFunction(type).getLease());
}
}
else
{
return false;
}
statement = con.prepareStatement("REPLACE residence_functions SET id=?, type=?, lvl=?");
statement.setInt(1, getId());
statement.setInt(2, type);
statement.setInt(3, level);
statement.execute();
function.setLvl(level);