Browse Source

Missing files

DrHouse 16 năm trước cách đây
mục cha
commit
dd23fc8773

+ 46 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiEvent.java

@@ -0,0 +1,46 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import net.sf.l2j.gameserver.model.actor.L2Character;
+
+public class AiEvent
+{
+	private AiEventType _type;
+	private L2Character _source;
+	private L2Character _target;
+	
+	public AiEvent(AiEventType type, L2Character source, L2Character target)
+	{
+		_type = type;
+		_source = source;
+		_target = target;
+	}
+	
+	public AiEventType getType()
+	{
+		return _type;
+	}
+	
+	public L2Character getSource()
+	{
+		return _source;
+	}
+	
+	public L2Character getTarget()
+	{
+		return _target;
+	}
+}

+ 34 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiEventType.java

@@ -0,0 +1,34 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+/**
+ *
+ * @author -Wooden-
+ *
+ */
+public enum AiEventType
+{
+	SEE_CREATURE,
+	SEE_SPELL,
+	SEE_ATTACK,
+	ATTACKED,
+	AGGRESSION,
+	SPAWNED,
+	MINION_DIED,
+	MINION_SPAWNED,
+	ARRIVED, //??
+	ARRIVED_WAYPOINT
+}

+ 152 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiInstance.java

@@ -0,0 +1,152 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import javolution.util.FastMap;
+import net.sf.l2j.gameserver.TaskPriority;
+
+/**
+ *
+ * @author -Wooden-
+ *
+ */
+public class AiInstance
+{
+	private Map<AiEventType, EventHandlerSet> _eventHandlers;
+	private AiPlugingParameters _pluginigParams;
+	
+	public AiInstance(AiPlugingParameters params)
+	{
+		if (params.isConverted())
+			throw new IllegalArgumentException("AiPluginingParameters of an Ai instance must be converted");
+		_pluginigParams = params;
+		//TODO:update the params (bottom-up)
+		_eventHandlers = new FastMap<AiEventType, EventHandlerSet>();
+		AiManager.getInstance().addAiInstance(this);
+	}
+	
+	public AiInstance(AiInstance instance, AiPlugingParameters params)
+	{
+		this(params);
+		this.copyHanlders(instance);
+	}
+	
+	public void copyHanlders(AiInstance instance)
+	{
+		//then copy all the hanlders from 'instance'
+		for (EventHandlerSet set : instance.getEventHandlerSets())
+		{
+			addHandlerSet(set.getEventType(), set);
+		}
+	}
+	
+	/**
+	 * <p>This methode add the handler to the {@link EventHandlerSet} associated with the specified{@link AiEventType}</p>
+	 * @param handler the handler to be added
+	 */
+	public void addHandler(EventHandler handler)
+	{
+		EventHandlerSet set = _eventHandlers.get(handler.getEvenType());
+		if (set == null)
+		{
+			set = new EventHandlerSet(handler, TaskPriority.PR_NORMAL);
+			_eventHandlers.put(handler.getEvenType(), set);
+		}
+		else
+		{
+			set.addHandler(handler);
+		}
+	}
+	
+	public void addHandlerSet(AiEventType event, EventHandlerSet set)
+	{
+		_eventHandlers.put(event, set);
+	}
+	
+	public class QueueEventRunner implements Runnable
+	{
+		
+		private EventHandlerSet _set;
+		private AiParameters _ai;
+		private AiEvent _event;
+		
+		public QueueEventRunner(EventHandlerSet set, AiParameters ai, AiEvent event)
+		{
+			_set = set;
+			_ai = ai;
+			_event = event;
+		}
+		
+		public void run()
+		{
+			for (EventHandler handler : _set.getHandlers())
+				handler.runImpl(_ai, _event);
+			AiInstance.this.launchNextEvent(_ai);
+		}
+	}
+	
+	/**
+	 * @param _aiParams
+	 * 
+	 */
+	public void launchNextEvent(AiParameters aiParams)
+	{
+		if (aiParams.hasEvents())
+		{
+			AiEvent event = aiParams.nextEvent();
+			AiManager.getInstance().executeEventHandler(new QueueEventRunner(_eventHandlers.get(event.getType()), aiParams, event));
+		}
+	}
+	
+	public void triggerEvent(AiEvent event, AiParameters aiParams)
+	{
+		if (aiParams.isEventInhibited(event.getType()))
+			return;
+		boolean restart = false;
+		synchronized (aiParams)
+		{
+			// if there was no events in the queue start processing events after we add them.
+			if (!aiParams.hasEvents())
+			{
+				restart = true;
+			}
+			aiParams.queueEvents(event);
+			if (restart)
+				this.launchNextEvent(aiParams);
+		}
+	}
+	
+	public AiPlugingParameters getPluginingParamaters()
+	{
+		return _pluginigParams;
+	}
+	
+	public Collection<EventHandlerSet> getEventHandlerSets()
+	{
+		return _eventHandlers.values();
+	}
+	
+	/**
+	 * @return
+	 */
+	public Set<Integer> getHandledNPCIds()
+	{
+		return _pluginigParams.getIDs();
+	}
+}

+ 235 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiManager.java

@@ -0,0 +1,235 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarFile;
+import java.util.logging.Logger;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+import javolution.util.FastSet;
+import net.sf.l2j.gameserver.ThreadPoolManager;
+import net.sf.l2j.gameserver.ai2.AiInstance.QueueEventRunner;
+
+/**
+ * This class will load all the AI's and retain all of them.
+ * It is a singleton
+ * @author -Wooden-
+ *
+ */
+public class AiManager
+{
+	protected static final Logger _log = Logger.getLogger(AiManager.class.getName());
+	private static AiManager _instance;
+	private List<AiInstance> _aiList;
+	private Map<Integer, AiInstance> _aiMap;
+	private ThreadPoolManager _tpm;
+	private Map<String, String> _paramcache;
+	
+	public static AiManager getInstance()
+	{
+		if (_instance == null)
+		{
+			_instance = new AiManager();
+		}
+		return _instance;
+	}
+	
+	private AiManager()
+	{
+		_aiList = new FastList<AiInstance>();
+		_aiMap = new FastMap<Integer, AiInstance>();
+		_tpm = ThreadPoolManager.getInstance();
+		_paramcache = new FastMap<String, String>();
+		load();
+	}
+	
+	public void load()
+	{
+		try
+		{
+			//TODO redo all the SpecificAiManger loading it's completely messed up:
+			@SuppressWarnings("unused")
+			JarFile jar = new JarFile("./l2jserver.jar");
+			URL url = Class.class.getResource("/net/sf/l2j/gameserver/ai/managers");
+			//jar.getJarEntry("/net/sf/l2j/gameserver/ai/managers").get;
+			if (url == null)
+			{
+				_log.severe("Could not open the ai managers folder. No ai will be loaded!");
+				return;
+			}
+			File directory = new File(url.getFile());
+			for (String file : directory.list())
+			{
+				if (file.endsWith(".class"))
+				{
+					try
+					{
+						Class<?> managerClass = Class.forName("net.sf.l2j.gameserver.ai.managers." + file.substring(0, file.length() - 6));
+						Object managerObject = managerClass.newInstance();
+						if (!(managerObject instanceof ISpecificAiManager))
+						{
+							_log.info("A class that was not a ISpecificAiManager was found in the ai managers folder.");
+							continue;
+						}
+						ISpecificAiManager managerInstance = (ISpecificAiManager) managerObject;
+						for (EventHandler handler : managerInstance.getEventHandlers())
+						{
+							AiPlugingParameters pparams = handler.getPlugingParameters();
+							pparams.convertToIDs();
+							boolean perfectMatch = false;
+							// let's check if any previously created AiInstance is allready used for the NPC concerned by this handler
+							List<Intersection> intersections = new FastList<Intersection>();
+							for (AiInstance ai : _aiList)
+							{
+								if (ai.getPluginingParamaters().equals(pparams))
+								{
+									ai.addHandler(handler);
+									perfectMatch = true;
+									break;
+								}
+								Intersection intersection = new Intersection(ai);
+								for (int id : pparams.getIDs())
+								{
+									if (ai.getPluginingParamaters().contains(id))
+									{
+										//intersection with this AI
+										intersection.ids.add(id);
+									}
+								}
+								if (!intersection.isEmpty())
+									intersections.add(intersection);
+							}
+							if (perfectMatch)
+								continue;
+							for (Intersection i : intersections)
+							{
+								//remove secant ids on both AiInstances
+								pparams.removeIDs(i.ids);
+								i.ai.getPluginingParamaters().removeIDs(i.ids); //TODO if this is extracted to a more general purpose method, dont forget to update linkages to AiIntances
+								//create a new instance with the secant ids that will inherit all the handlers from the secant Ai
+								AiPlugingParameters newAiPparams = new AiPlugingParameters(null, null, null, i.ids, null);
+								AiInstance newAi = new AiInstance(i.ai, newAiPparams);
+								newAi.addHandler(handler);
+								_aiList.add(newAi);
+							}
+							if (pparams.isEmpty())
+								continue;
+							// create a new instance with the remaining ids
+							AiInstance newAi = new AiInstance(pparams);
+							newAi.addHandler(handler);
+							_aiList.add(newAi);
+						}
+						
+					}
+					catch (ClassCastException e)
+					{
+						e.printStackTrace();
+					}
+					catch (ClassNotFoundException e)
+					{
+						e.printStackTrace();
+					}
+					catch (IllegalArgumentException e)
+					{
+						e.printStackTrace();
+					}
+					catch (SecurityException e)
+					{
+						e.printStackTrace();
+					}
+					catch (InstantiationException e)
+					{
+						e.printStackTrace();
+					}
+					catch (IllegalAccessException e)
+					{
+						e.printStackTrace();
+					}
+				}
+			}
+		}
+		catch (IOException e1)
+		{
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+		// build a mighty map
+		for (AiInstance ai : _aiList)
+		{
+			for (Integer i : ai.getHandledNPCIds())
+			{
+				_aiMap.put(i, ai);
+			}
+		}
+	}
+	
+	public void executeEventHandler(QueueEventRunner runner)
+	{
+		_tpm.executeAi(runner);
+	}
+	
+	/**
+	 * @param instance
+	 */
+	public void addAiInstance(AiInstance instance)
+	{
+		_aiList.add(instance);
+	}
+	
+	/**
+	 * @param npcId
+	 * @return
+	 */
+	public AiInstance getAiForNPCId(int npcId)
+	{
+		return _aiMap.get(npcId);
+	}
+	
+	public String getParameter(String who, String paramsType, String param1, String param2)
+	{
+		String key = who + ":" + paramsType + ":" + param1 + ":" + param2;
+		String cacheResult = _paramcache.get(key);
+		if (cacheResult != null)
+			return cacheResult;
+		String result = null;
+		// get from SQL
+		_paramcache.put(key, result);
+		return null;
+	}
+	
+	private class Intersection
+	{
+		public AiInstance ai;
+		public Set<Integer> ids;
+		
+		public Intersection(AiInstance instance)
+		{
+			ai = instance;
+			ids = new FastSet<Integer>();
+		}
+		
+		public boolean isEmpty()
+		{
+			return ids.isEmpty();
+		}
+	}
+}

+ 152 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiParameters.java

@@ -0,0 +1,152 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.PriorityBlockingQueue;
+
+import javolution.util.FastList;
+import net.sf.l2j.gameserver.model.actor.L2Character;
+import net.sf.l2j.gameserver.model.actor.L2Npc;
+
+/**
+ *
+ * @author -Wooden-
+ *
+ */
+public class AiParameters
+{
+	private Queue<AiEvent> _eventQueue;
+	private EnumSet<AiEventType> _inhibitions;
+	private L2Npc _actor;
+	private List<Hated> _hated;
+	private List<Liked> _liked;
+	
+	public class Hated
+	{
+		public L2Character character;
+		public HateReason reason;
+		public int degree;
+		
+	}
+	
+	public class Liked
+	{
+		public L2Character character;
+		public LikeReason reason;
+		public int degree;
+	}
+	
+	public enum HateReason
+	{
+		GAVE_DAMMAGE,
+		HEALS_ENNEMY,
+		GAVE_DAMMAGE_TO_FRIEND,
+		IS_ENNEMY
+	}
+	
+	public enum LikeReason
+	{
+		FRIEND,
+		HEALED,
+		HEALED_FRIEND,
+		GAVE_DAMMAGE_TO_ENNEMY
+	}
+	
+	public AiParameters(L2Npc actor)
+	{
+		_eventQueue = new PriorityBlockingQueue<AiEvent>();
+		_hated = new FastList<Hated>();
+		_liked = new FastList<Liked>();
+		_actor = actor;
+		_inhibitions = EnumSet.noneOf(AiEventType.class);
+	}
+	
+	/**
+	 * @return
+	 */
+	public boolean hasEvents()
+	{
+		return _eventQueue.isEmpty();
+	}
+	
+	/**
+	 * @return
+	 */
+	public AiEvent nextEvent()
+	{
+		return _eventQueue.poll();
+	}
+	
+	public void queueEvents(AiEvent set)
+	{
+		_eventQueue.offer(set);
+	}
+	
+	public L2Npc getActor()
+	{
+		return _actor;
+	}
+	
+	public List<Hated> getHated()
+	{
+		return _hated;
+	}
+	
+	public List<Liked> getLiked()
+	{
+		return _liked;
+	}
+	
+	public void addLiked(Liked cha)
+	{
+		_liked.add(cha);
+	}
+	
+	public void addHated(Hated cha)
+	{
+		_hated.add(cha);
+	}
+	
+	public void clear()
+	{
+		_hated.clear();
+		_liked.clear();
+		_eventQueue.clear();
+		_inhibitions.clear();
+	}
+	
+	public void inhibit(AiEventType type)
+	{
+		_inhibitions.add(type);
+	}
+	
+	public void deInhibit(AiEventType type)
+	{
+		_inhibitions.remove(type);
+	}
+	
+	/**
+	 * @param type
+	 * @return
+	 */
+	public boolean isEventInhibited(AiEventType type)
+	{
+		return _inhibitions.contains(type);
+	}
+	
+}

+ 118 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiPlugingParameters.java

@@ -0,0 +1,118 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.util.Set;
+
+import javolution.util.FastSet;
+import net.sf.l2j.gameserver.datatables.NpcTable;
+
+/**
+ *
+ * @author  -Wooden-
+ */
+public class AiPlugingParameters
+{
+	//here is order of priority
+	private Set<String> _npcClassTypes;
+	private Set<Class<?>> _npcL2jClasses;
+	private Set<String> _aiTypes;
+	private Set<Integer> _npcIDs;
+	private boolean _converted;
+	private AiPlugingParameters _but;
+	
+	public AiPlugingParameters(Set<String> npcClassTypes, Set<Class<?>> npcL2jClasses, Set<String> aiTypes, Set<Integer> npcIDs, AiPlugingParameters but)
+	{
+		_npcClassTypes = npcClassTypes;
+		_npcL2jClasses = npcL2jClasses;
+		_aiTypes = aiTypes;
+		_npcIDs = npcIDs;
+		_but = but;
+		if (_npcIDs == null)
+			_npcIDs = new FastSet<Integer>();
+	}
+	
+	public void convertToIDs()
+	{
+		if (_but != null && !_but.isEmpty())
+			_but.convertToIDs();
+		
+		if (_npcClassTypes != null)
+			for (String classType : _npcClassTypes)
+			{
+				_npcIDs.addAll(NpcTable.getInstance().getAllNpcOfClassType(classType));
+			}
+		if (_npcL2jClasses != null)
+			for (Class<?> l2jClass : _npcL2jClasses)
+			{
+				_npcIDs.addAll(NpcTable.getInstance().getAllNpcOfL2jClass(l2jClass));
+			}
+		
+		if (_aiTypes != null)
+			for (String aiType : _aiTypes)
+			{
+				_npcIDs.addAll(NpcTable.getInstance().getAllNpcOfAiType(aiType));
+			}
+		
+		if (_but != null && !_but.isEmpty())
+			removeIDs(_but.getIDs());
+		
+		_converted = true;
+	}
+	
+	public boolean isEmpty()
+	{
+		return (_npcIDs.isEmpty() && _aiTypes.isEmpty() && _npcL2jClasses.isEmpty() && _npcClassTypes.isEmpty());
+	}
+	
+	/**
+	 * If a AiPlugingParameters was converted to IDs its other parameter sets might not be accurate
+	 * @return true if AiPlugingParameters where converted to IDs
+	 */
+	public boolean isConverted()
+	{
+		return _converted;
+	}
+	
+	public void removeIDs(Set<Integer> ids)
+	{
+		_npcIDs.removeAll(ids);
+	}
+	
+	public Set<Integer> getIDs()
+	{
+		return _npcIDs;
+	}
+	
+	/**
+	 * @param id
+	 * @return
+	 */
+	public boolean contains(int id)
+	{
+		if (!_converted)
+			throw new IllegalStateException("Can not call 'contain' method on a non-converted AiPluginParameters");
+		if (_but == null)
+			return _npcIDs.contains(id);
+		return _npcIDs.contains(id) && !_but.contains(id);
+	}
+	
+	public boolean equals(AiPlugingParameters pparams)
+	{
+		if (!_converted)
+			throw new IllegalStateException("Can not call 'equals' method on a non-converted AiPluginParameters");
+		return (_npcIDs.containsAll(pparams.getIDs()) && pparams.getIDs().containsAll(_npcIDs));
+	}
+}

+ 33 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/AiUtil.java

@@ -0,0 +1,33 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import net.sf.l2j.gameserver.model.actor.L2Character;
+
+public class AiUtil
+{
+	
+	public static L2Character getMostHated(AiParameters aiParams)
+	{
+		//TODO
+		return null;
+	}
+	
+	public static L2Character getLikedNeedingHelp(AiParameters aiParams)
+	{
+		//TODO
+		return null;
+	}
+}

+ 44 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/EventHandler.java

@@ -0,0 +1,44 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author -Wooden-
+ *
+ */
+public abstract class EventHandler
+{
+	protected static final Logger _log = Logger.getLogger(EventHandler.class.getName());
+	
+	abstract AiEventType getEvenType();
+	
+	/**
+	 * @return the priority of this EventHandler INSIDE the EventHandlerSet
+	 */
+	abstract int getPriority();
+	
+	abstract void runImpl(AiParameters aiParams, AiEvent event);
+	
+	abstract AiPlugingParameters getPlugingParameters();
+	
+	@Override
+	public String toString()
+	{
+		return "EventHandler: " + getEvenType().name() + " Priority:" + getPriority();
+	}
+}

+ 119 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/EventHandlerSet.java

@@ -0,0 +1,119 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.util.List;
+
+import javolution.util.FastList;
+import net.sf.l2j.gameserver.TaskPriority;
+
+/**
+ *
+ * @author -Wooden-
+ *
+ */
+public class EventHandlerSet implements Comparable<EventHandlerSet>
+{
+	private int _comparatorPrio;
+	private long _insertionTime;
+	private List<EventHandler> _handlers;
+	private AiEventType _eventType;
+	
+	public EventHandlerSet(AiEventType event, List<EventHandler> handlers, TaskPriority prio)
+	{
+		_comparatorPrio = (prio.ordinal() + 1) * 3;
+		_handlers = new FastList<EventHandler>();
+		_eventType = event;
+		for (EventHandler handler : handlers)
+			addHandler(handler);
+	}
+	
+	public EventHandlerSet(EventHandler handler, TaskPriority prio)
+	{
+		_comparatorPrio = (prio.ordinal() + 1) * 3;
+		_handlers = new FastList<EventHandler>();
+		_eventType = handler.getEvenType();
+		addHandler(handler);
+	}
+	
+	public void addHandler(EventHandler handler)
+	{
+		if (handler == null)
+			return;
+		int prio = handler.getPriority();
+		int index = -1;
+		for (EventHandler eventHandler : _handlers)
+		{
+			if (eventHandler.getPriority() <= prio)
+			{
+				index = eventHandler.getPriority();
+				break;
+			}
+		}
+		if (index != -1)
+		{
+			_handlers.add(index, handler);
+		}
+		else
+		{
+			_handlers.add(handler);
+		}
+	}
+	
+	public void setPrio(TaskPriority prio)
+	{
+		_comparatorPrio = (prio.ordinal() + 1) * 3;
+	}
+	
+	public void stampInsertionTime()
+	{
+		_insertionTime = System.currentTimeMillis();
+	}
+	
+	public int getComparatorPriority()
+	{
+		return _comparatorPrio;
+	}
+	
+	public List<EventHandler> getHandlers()
+	{
+		return _handlers;
+	}
+	
+	public AiEventType getEventType()
+	{
+		return _eventType;
+	}
+	
+	/* (non-Javadoc)
+	 * @see java.lang.Comparable#compareTo(T)
+	 */
+	public int compareTo(EventHandlerSet es)
+	{
+		return (int) ((System.currentTimeMillis() - _insertionTime) / 1000) + _comparatorPrio - es.getComparatorPriority();
+	}
+	
+	@Override
+	public String toString()
+	{
+		String str = "EventHandlerSet: size:" + _handlers.size() + " Priority:" + _comparatorPrio + (_insertionTime != 0 ? " TimePoints: " + (int) ((System.currentTimeMillis() - _insertionTime) / 1000) : "");
+		for (EventHandler handler : _handlers)
+		{
+			str = str.concat(" - " + handler.toString());
+		}
+		return str;
+	}
+	
+}

+ 29 - 0
L2_GameServer/java/net/sf/l2j/gameserver/ai2/ISpecificAiManager.java

@@ -0,0 +1,29 @@
+/*
+ * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.gameserver.ai2;
+
+import java.util.List;
+
+/**
+ *
+ * @author -Wooden-
+ *
+ */
+public interface ISpecificAiManager
+{
+	List<EventHandler> getEventHandlers();
+	
+	void load();
+}