if(player.getSkillLevel(_id) >= _level)
// already knows the skill with this level
return;
L2Skill skill = SkillTable.getInstance().getInfo(_id, _level);
int counts = 0;
int _requiredSp = 10000000;
if(_skillType == 0)
{
L2SkillLearn[] skills = SkillTreeTable.getInstance().getAvailableSkills(player, player.getSkillLearningClassId());
for(L2SkillLearn s : skills)
{
L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
if(sk == null || sk != skill || !sk.getCanLearn(player.getSkillLearningClassId()) || !sk.canTeachBy(npcid))
{
continue;
}
counts++;
_requiredSp = SkillTreeTable.getInstance().getSkillCost(player, skill);
}
if(counts == 0 && !Config.ALT_GAME_SKILL_LEARN)
{
player.sendMessage("You are trying to learn skill that u can't..");
Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to learn skill that he can't!!!", IllegalPlayerAction.PUNISH_KICK);
return;
}
if(player.getSp() >= _requiredSp)
{
int spbId = -1;
// divine inspiration require book for each level
if(Config.DIVINE_SP_BOOK_NEEDED && skill.getId() == L2Skill.SKILL_DIVINE_INSPIRATION)
{
spbId = SkillSpellbookTable.getInstance().getBookForSkill(skill, _level);
}
else if(Config.SP_BOOK_NEEDED && skill.getLevel() == 1)
{
spbId = SkillSpellbookTable.getInstance().getBookForSkill(skill);
}
// spellbook required
if(spbId > -1)
{
L2ItemInstance spb = player.getInventory().getItemByItemId(spbId);
if(spb == null)
{
// Haven't spellbook
player.sendPacket(new SystemMessage(SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
return;
}
// ok
player.destroyItem("Consume", spb, trainer, true);
}
}
else
{
SystemMessage sm = new SystemMessage(SystemMessageId.NOT_ENOUGH_SP_TO_LEARN_SKILL);
player.sendPacket(sm);
return;
}
}
else if(_skillType == 1)
{
int costid = 0;
int costcount = 0;
// Skill Learn bug Fix
L2SkillLearn[] skillsc = SkillTreeTable.getInstance().getAvailableSkills(player);
for(L2SkillLearn s : skillsc)
{
L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
if(sk == null || sk != skill)
{
continue;
}
counts++;
costid = s.getIdCost();
costcount = s.getCostCount();
_requiredSp = s.getSpCost();
}
if(counts == 0)
{
player.sendMessage("You are trying to learn skill that u can't..");
Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " tried to learn skill that he can't!!!", IllegalPlayerAction.PUNISH_KICK);
return;
}
if(player.getSp() >= _requiredSp)
{
if(!player.destroyItemByItemId("Consume", costid, costcount, trainer, false))
{
// Haven't spellbook
player.sendPacket(new SystemMessage(SystemMessageId.ITEM_MISSING_TO_LEARN_SKILL));
return;
}
SystemMessage sm = new SystemMessage(SystemMessageId.DISSAPEARED_ITEM);
sm.addNumber(costcount);
sm.addItemName(costid);
sendPacket(sm);
}
else
{
SystemMessage sm = new SystemMessage(SystemMessageId.NOT_ENOUGH_SP_TO_LEARN_SKILL);
player.sendPacket(sm);
return;
}
}
else if(_skillType == 2) //pledgeskills TODO: Find appropriate system messages.
{
if(!player.isClanLeader())
{
// TODO: Find and add system msg
player.sendMessage("This feature is available only for the clan leader");
return;
}
int itemId = 0;
int repCost = 100000000;
// Skill Learn bug Fix
L2PledgeSkillLearn[] skills = SkillTreeTable.getInstance().getAvailablePledgeSkills(player);
for(L2PledgeSkillLearn s : skills)
{
L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel());
if(sk == null || sk != skill)
{
continue;
}