/* * 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 2, 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */ package net.sf.l2j.gameserver.handler.itemhandlers; import net.sf.l2j.gameserver.datatables.NpcTable; import net.sf.l2j.gameserver.handler.IItemHandler; import net.sf.l2j.gameserver.idfactory.IdFactory; import net.sf.l2j.gameserver.model.L2ItemInstance; import net.sf.l2j.gameserver.model.L2Object; import net.sf.l2j.gameserver.model.L2Spawn; import net.sf.l2j.gameserver.model.L2World; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance; import net.sf.l2j.gameserver.serverpackets.SystemMessage; import net.sf.l2j.gameserver.templates.L2NpcTemplate; public class Pumpkin implements IItemHandler { private static int[] _itemIds = { 6389, // Squash Seed 6390 // Large Squash Seed }; private static int[] _npcIds = { 12774, // Young Squash 12777 // Large Young Squash }; public void useItem(L2PlayableInstance playable, L2ItemInstance item){ L2PcInstance activeChar = (L2PcInstance)playable; L2NpcTemplate template1 = null; int itemId = item.getItemId(); // Busca etre los items del player si tiene el item para spawnear la semilla for(int i = 0 ; i<_itemIds.length ; i++ ){ if( _itemIds[i] == itemId ){ template1 = NpcTable.getInstance().getTemplate(_npcIds[i]); break; } } // Si no lo encuentra se vuelve if(template1==null) return; L2Object target = activeChar.getTarget(); if (target == null) target = activeChar; try{ // Spawneamos el mob L2Spawn spawn = new L2Spawn(template1); spawn.setId(IdFactory.getInstance().getNextId()); spawn.setLocx(target.getX()); spawn.setLocy(target.getY()); spawn.setLocz(target.getZ()); L2World.getInstance().storeObject(spawn.spawnOne()); //TODO: Contar 30 segundos y desespawnear el mob // Quitamos el item al pj activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false ); // Creamos el aviso y se lo mandamos al usuario SystemMessage sm = new SystemMessage(614); sm.addString("Creado un "+template1.name+" en x: "+spawn.getLocx()+" y: "+spawn.getLocy()+" z: "+spawn.getLocz()); activeChar.sendPacket(sm); } catch (Exception e){ // Si algo falla SystemMessage sm = new SystemMessage(614); sm.addString("El objetivo no se encuentra en el juego"); activeChar.sendPacket(sm); } } public int[] getItemIds() { return _itemIds; } }