root/trunk/AE-go_GameServer/src/com/aionemu/gameserver/services/DecayService.java

9621003
1
/*
1
/*
2
 * This file is part of aion-unique <aion-unique.smfnew.com>.
2
 * This file is part of aion-unique <aion-unique.org>.
3
 *
3
 *
4
 *  aion-unique is free software: you can redistribute it and/or modify
4
 *  aion-unique is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
5
 *  it under the terms of the GNU General Public License as published by
...
...
18
18
19
import java.util.concurrent.Future;
19
import java.util.concurrent.Future;
20
20
21
import com.aionemu.gameserver.ai.events.Event;
22
import com.aionemu.gameserver.model.gameobjects.Npc;
21
import com.aionemu.gameserver.model.gameobjects.Npc;
23
import com.aionemu.gameserver.network.aion.serverpackets.SM_DELETE;
24
import com.aionemu.gameserver.utils.PacketSendUtility;
25
import com.aionemu.gameserver.utils.ThreadPoolManager;
22
import com.aionemu.gameserver.utils.ThreadPoolManager;
26
import com.aionemu.gameserver.world.World;
27
23
28
/**
24
/**
29
 * @author ATracer
25
 * @author ATracer
...
...
37
	
33
	
38
	public Future<?> scheduleDecayTask(final Npc npc)
34
	public Future<?> scheduleDecayTask(final Npc npc)
39
	{
35
	{
40
		final World world = npc.getPosition().getWorld();
41
		//TODO separate thread executor for decay/spawns
42
		// or schedule separate decay runnable service with queue 
43
		return ThreadPoolManager.getInstance().schedule(new Runnable()
36
		return ThreadPoolManager.getInstance().schedule(new Runnable()
44
		{
37
		{
45
			@Override
38
			@Override
46
			public void run()
39
			public void run()
47
			{
40
			{
48
				if(!npc.isSpawned())
41
				npc.getController().onDespawn(false);
49
					return;
50
				
51
				npc.getAi().handleEvent(Event.DESPAWN);
52
				PacketSendUtility.broadcastPacket(npc, new SM_DELETE(npc));
53
				world.despawn(npc);	
54
			}
42
			}
55
		}, DECAY_DEFAULT_DELAY);
43
		}, DECAY_DEFAULT_DELAY);
56
57
	}
44
	}
58
	
45
	
59
	public static DecayService getInstance()
46
	public static DecayService getInstance()