/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package lineage2.gameserver.network.clientpackets;
import lineage2.gameserver.cache.Msg;
import lineage2.gameserver.model.Player;
import lineage2.gameserver.model.Skill;
import lineage2.gameserver.model.base.EnchantSkillLearn;
import lineage2.gameserver.network.serverpackets.ExEnchantSkillInfo;
import lineage2.gameserver.network.serverpackets.ExEnchantSkillResult;
import lineage2.gameserver.network.serverpackets.SystemMessage;
import lineage2.gameserver.scripts.Functions;
import lineage2.gameserver.tables.SkillTable;
import lineage2.gameserver.tables.SkillTreeTable;
import lineage2.gameserver.utils.Log;
/**
* @author Mobius
* @version $Revision: 1.0 $
*/
public final class RequestExEnchantSkillUntrain extends L2GameClientPacket
{
/**
* Field _skillId.
*/
private int _skillId;
/**
* Field _skillLvl.
*/
private int _skillLvl;
/**
* Method readImpl.
*/
@Override
protected void readImpl()
{
_skillId = readD();
_skillLvl = readD();
}
/**
* Method runImpl.
*/
@Override
protected void runImpl()
{
Player activeChar = getClient().getActiveChar();
if (activeChar == null)
{
return;
}
if (activeChar.getTransformation() != 0)
{
activeChar.sendMessage("You must leave transformation mode first.");
return;
}
if ((activeChar.getLevel() < 76) || (activeChar.getClassLevel() < 4))
{
activeChar.sendMessage("You must have 3rd class change quest completed.");
return;
}
int oldSkillLevel = activeChar.getSkillDisplayLevel(_skillId);
if (oldSkillLevel == -1)
{
return;
}
if ((_skillLvl != (oldSkillLevel - 1)) || ((_skillLvl / 100) != (oldSkillLevel / 100)))
{
return;
}
EnchantSkillLearn sl = SkillTreeTable.getSkillEnchant(_skillId, oldSkillLevel);
if (sl == null)
{
return;
}
Skill newSkill;
if ((_skillLvl % 100) == 0)
{
_skillLvl = sl.getBaseLevel();
newSkill = SkillTable.getInstance().getInfo(_skillId, _skillLvl);
}
else
{
newSkill = SkillTable.getInstance().getInfo(_skillId, SkillTreeTable.convertEnchantLevel(sl.getBaseLevel(), _skillLvl, sl.getMaxLevel()));
}
if (newSkill == null)
{
return;
}
if (_skillId < 10000)
{
if (Functions.getItemCount(activeChar, SkillTreeTable.UNTRAIN_ENCHANT_BOOK) == 0)
{
activeChar.sendPacket(Msg.ITEMS_REQUIRED_FOR_SKILL_ENCHANT_ARE_INSUFFICIENT);
return;
}
Functions.removeItem(activeChar, SkillTreeTable.UNTRAIN_ENCHANT_BOOK, 1);
}
else if (_skillId >= 10000)
{
if (Functions.getItemCount(activeChar, SkillTreeTable.UNTRAIN_NEW_ENCHANT_BOOK) == 0)
{
activeChar.sendPacket(Msg.ITEMS_REQUIRED_FOR_SKILL_ENCHANT_ARE_INSUFFICIENT);
return;
}
Functions.removeItem(activeChar, SkillTreeTable.UNTRAIN_NEW_ENCHANT_BOOK, 1);
}
activeChar.addExpAndSp(0, sl.getCost()[1] * sl.getCostMult());
activeChar.addSkill(newSkill, true);
if (_skillLvl > 100)
{
SystemMessage sm = new SystemMessage(SystemMessage.Untrain_of_enchant_skill_was_successful_Current_level_of_enchant_skill_S1_has_been_decreased_by_1);
sm.addSkillName(_skillId, _skillLvl);
activeChar.sendPacket(sm);
}
else
{
SystemMessage sm = new SystemMessage(SystemMessage.Untrain_of_enchant_skill_was_successful_Current_level_of_enchant_skill_S1_became_0_and_enchant_skill_will_be_initialized);
sm.addSkillName(_skillId, _skillLvl);
activeChar.sendPacket(sm);
}
Log.add(activeChar.getName() + "|Successfully untranes|" + _skillId + "|to+" + _skillLvl + "|---", "enchant_skills");
activeChar.sendPacket(new ExEnchantSkillInfo(_skillId, newSkill.getDisplayLevel()), ExEnchantSkillResult.SUCCESS);
activeChar.sendSkillList();
RequestExEnchantSkill.updateSkillShortcuts(activeChar, _skillId, _skillLvl);
}
}