package handler.bypass;
import l2p.commons.dao.JdbcEntityState;
import l2p.gameserver.data.holder.PetDataHolder;
import l2p.gameserver.enums.PetId;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.instances.NpcInstance;
import l2p.gameserver.model.instances.PetInstance;
import l2p.gameserver.model.items.ItemInstance;
import l2p.gameserver.network.s2c.InventoryUpdate;
import l2p.gameserver.network.s2c.SystemMessage;
/**
* @author Gaikotsu
*/
public class PetEvolve extends ScriptBypassHandler
{
private static final String[] _commandList = new String[] {
"evolveWolf",
"evolveGreatWolf",
"evolveBabyBuffalo",
"evolveBabyKookabura",
"evolveBabyCoguar" };
private static boolean checkPet(Player player, int itemId[], PetId petId, int level)
{
PetInstance pet = player.getSummonList().getPet();
if (player.getInventory().getItemById(itemId) == null)
{
player.sendPopupMessage("Не найден требующийся для улучшения предмет, призывающий питомца.");
return false;
}
if (pet == null || pet.isDead())
{
player.sendPopupMessage("Необходимый для улучшения питомец не вызван или же он мертв.");
return false;
}
if (pet.getId() != petId.getId())
{
player.sendPopupMessage("Вызванный питомец не подходит для улучшения.");
return false;
}
if (pet.getLevel() < level)
{
player.sendPopupMessage("Уровень вызванного питомца не подходит для улучшения.");
return false;
}
return true;
}
private static void evolvePet(Player player, int itemId, int level)
{
if (itemId == 0)
return;
int controlItemId = player.getSummonList().getPet().getControlItemObjId();
player.getSummonList().removePet(false);
ItemInstance item = player.getInventory().getItemByObjectId(controlItemId);
item.setId(itemId);
item.setEnchantLevel(level);
item.setJdbcState(JdbcEntityState.UPDATED);
item.update();
player.sendPacket(new InventoryUpdate().addModifiedItem(item), SystemMessage.obtainItems(itemId, 1, 0));
player.sendPopupMessage("Питомец успешно улучшен.");
}
@Override
public void onBypassFeedback(NpcInstance npc, Player player, String command, String[] params)
{
if (command.equalsIgnoreCase("evolveWolf"))
{
if (checkPet(player, PetDataHolder.getControlItemId(PetId.WOLF), PetId.WOLF, 55))
evolvePet(player, PetDataHolder.getFirstControlItemId(PetId.GREAT_WOLF), 55);
}
else if (command.equalsIgnoreCase("evolveGreatWolf"))
{
if (checkPet(player, PetDataHolder.getControlItemId(PetId.GREAT_WOLF), PetId.GREAT_WOLF, 70))
evolvePet(player, PetDataHolder.getFirstControlItemId(PetId.FENRIR_WOLF), 70);
}
else if (command.equalsIgnoreCase("evolveBabyBuffalo"))
{
if (checkPet(player, PetDataHolder.getControlItemId(PetId.BABY_BUFFALO), PetId.BABY_BUFFALO, 55))
evolvePet(player, PetDataHolder.getFirstControlItemId(PetId.IMPROVED_BABY_BUFFALO), 55);
}
else if (command.equalsIgnoreCase("evolveBabyKookabura"))
{
if (checkPet(player, PetDataHolder.getControlItemId(PetId.BABY_KOOKABURRA), PetId.BABY_KOOKABURRA, 55))
evolvePet(player, PetDataHolder.getFirstControlItemId(PetId.IMPROVED_BABY_KOOKABURRA), 55);
}
else if (command.equalsIgnoreCase("evolveBabyCoguar"))
{
if (checkPet(player, PetDataHolder.getControlItemId(PetId.BABY_COUGAR), PetId.BABY_COUGAR, 55))
evolvePet(player, PetDataHolder.getFirstControlItemId(PetId.IMPROVED_BABY_COUGAR), 55);
}
}
@Override
public String[] getBypasses()
{
return _commandList;
}
}