All pastes #382643 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-05 20:24 UTC
rendered paste body
/*
 * 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.model.actor.instance;

import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.idfactory.IdFactory;
import net.sf.l2j.gameserver.datatables.NpcTable;
import net.sf.l2j.gameserver.datatables.PolymorphMonstersTable;
import net.sf.l2j.gameserver.datatables.PolyInfo;
import net.sf.l2j.gameserver.datatables.SpawnTable;
import net.sf.l2j.gameserver.model.L2Character;
import net.sf.l2j.gameserver.model.L2Spawn;
import net.sf.l2j.gameserver.templates.L2NpcTemplate;

class L2PolymorphInstance extends L2MonsterInstance
{
	private L2Spawn _baseSpawn = null;
	private int _polyCount = 0;
	
	public class PolySpawnTask implements Runnable
	{
		private PolyInfo _polyInfo = null;
		private L2Spawn _baseSpawn = null;
		private int _polyCount = 0;

		public PolySpawnTask(PolyInfo polyInfo, L2Spawn baseSpawn, int polyCount)
		{
			_polyInfo = polyInfo;
			_baseSpawn = baseSpawn;
			_polyCount = polyCount;
		}
		
		public void run()
		{
			L2NpcTemplate template = NpcTable.getInstance().getTemplate(_polyInfo.getPolyId());
			
			if (template == null)
			{
				_baseSpawn.startRespawn();
				return;
			}

			new L2PolymorphInstance(IdFactory.getInstance().getNextId(), template, _baseSpawn, _polyCount+1);
		}
	}
	
	public L2PolymorphInstance(int objectId, L2NpcTemplate template, L2Spawn baseSpawn, int polyCount)
	{
		super(objectId, template);
		_baseSpawn = baseSpawn;
		_polyCount = polyCount;

		try
		{
			L2Spawn me = new L2Spawn(template); 
			setSpawn(me);
		
			me.setLocx(_baseSpawn.getLocx());
			me.setLocy(_baseSpawn.getLocy());
			me.setLocz(_baseSpawn.getLocz());
			me.setAmount(1);
			me.setHeading(_baseSpawn.getHeading());
			me.setRespawnDelay(60);

			SpawnTable.getInstance().addNewSpawn(me, false);

			me.init();
			me.getLastSpawn().decayMe();
			me.getLastSpawn().spawnMe(_baseSpawn.getLocx(), _baseSpawn.getLocx(), _baseSpawn.getLocx());
		}
		catch (Exception e)
		{}
	}
	
	public void doDie(L2Character killer)
	{
		deleteMe();
		
		PolyInfo polyInfo = PolymorphMonstersTable.getInstance().getPolyInfo(_baseSpawn.getLastSpawn().getNpcId(), _polyCount+1);
		
		if (polyInfo == null)
			_baseSpawn.startRespawn();
		else
			ThreadPoolManager.getInstance().scheduleGeneral(new PolySpawnTask(polyInfo, _baseSpawn, _polyCount), polyInfo.getSpawnDelay());

		super.doDie(killer);
	}
}