package handler.items;
import ai.CargoPet;
import l2ft.gameserver.data.xml.holder.NpcHolder;
import l2ft.gameserver.model.GameObjectsStorage;
import l2ft.gameserver.model.Player;
import l2ft.gameserver.model.SimpleSpawner;
import l2ft.gameserver.model.instances.CargoPetInstance;
import l2ft.gameserver.model.instances.NpcInstance;
import l2ft.gameserver.model.items.CargoWarehouse;
import l2ft.gameserver.model.items.ItemInstance;
import l2ft.gameserver.network.l2.s2c.SystemMessage;
import l2ft.gameserver.scripts.ScriptFile;
import l2ft.gameserver.templates.npc.NpcTemplate;
public class cargoPet extends SimpleItemHandler implements ScriptFile
{
private static final int[] ITEM_IDS = new int[] { 25914, 25915, 25916, 25917, 25918, 25919, 25920, 25921 };
@Override
public int[] getItemIds()
{
return ITEM_IDS;
}
@Override
protected boolean useItemImpl(Player player, ItemInstance item, boolean ctrl)
{
// player.getInventory().writeLock();
// try
// {
// if(player.getInventory().removeItem(item) == null)
// return false;
// }
// finally
// {
// player.getInventory().writeUnlock();
// }
for(NpcInstance n : GameObjectsStorage.getAllNpcsForIterate())
{
if(!n.isDead() && n instanceof CargoPetInstance && ((CargoPetInstance) n).ownerId == player.getObjectId())
{
((CargoPetInstance) n).owner = player;
player.setCargoPet(((CargoPetInstance) n));
}
}
if(player.getCargoPet() != null)
{
player.sendPacket(new SystemMessage(6740));// todo add radar
return false;
}
int npcid = item.getItemId() - 5914 + player.getRace().ordinal() * 8;
NpcTemplate spn = NpcHolder.getInstance().getTemplate(npcid);
SimpleSpawner spawn = new SimpleSpawner(spn);
spawn.setLoc(player.getLoc());
spawn.setAmount(1);
CargoPetInstance npc = (CargoPetInstance) spawn.doSpawn(false);
player.setCargoPet(npc);
//npc.wh.addItem(item);
npc.setAI(new CargoPet(npc, player));
npc.collar = item;
npc.wh = new CargoWarehouse(item.getObjectId());
npc.owner = player;
npc.ownerId = player.getObjectId();
npc.race = player.getRace().ordinal();
return true;
}
}