Addition of CreatureSeeTaskManager.
This commit is contained in:
		| @@ -254,7 +254,6 @@ public abstract class AbstractAI implements Ctrl | ||||
| 		{ | ||||
| 			case EVT_THINK: | ||||
| 			{ | ||||
| 				_actor.updateSeenCreatures(); | ||||
| 				onEvtThink(); | ||||
| 				break; | ||||
| 			} | ||||
|   | ||||
| @@ -37,8 +37,6 @@ import org.l2jmobius.gameserver.model.actor.Npc; | ||||
| import org.l2jmobius.gameserver.model.actor.Summon; | ||||
| import org.l2jmobius.gameserver.model.actor.instance.PetInstance; | ||||
| import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; | ||||
| import org.l2jmobius.gameserver.model.events.EventDispatcher; | ||||
| import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee; | ||||
| import org.l2jmobius.gameserver.network.Disconnection; | ||||
| import org.l2jmobius.gameserver.network.serverpackets.DeleteObject; | ||||
|  | ||||
| @@ -357,13 +355,6 @@ public class World | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			 | ||||
| 			// Notify OnCreatureSee for creatures that do not trigger EVT_THINK. | ||||
| 			if (!wo.isAttackable() && wo.isCreature() && object.isCreature()) | ||||
| 			{ | ||||
| 				EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee((Creature) wo, (Creature) object), (Creature) wo); | ||||
| 				EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee((Creature) object, (Creature) wo), (Creature) object); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| 	 | ||||
| @@ -577,13 +568,6 @@ public class World | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 				 | ||||
| 				// Notify OnCreatureSee for creatures that do not trigger EVT_THINK. | ||||
| 				if (!wo.isAttackable() && wo.isCreature() && object.isCreature()) | ||||
| 				{ | ||||
| 					EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee((Creature) wo, (Creature) object), (Creature) wo); | ||||
| 					EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee((Creature) object, (Creature) wo), (Creature) object); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -158,6 +158,7 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; | ||||
| import org.l2jmobius.gameserver.network.serverpackets.TeleportToLocation; | ||||
| import org.l2jmobius.gameserver.network.serverpackets.UserInfo; | ||||
| import org.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager; | ||||
| import org.l2jmobius.gameserver.taskmanager.CreatureSeeTaskManager; | ||||
| import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager; | ||||
| import org.l2jmobius.gameserver.util.Util; | ||||
|  | ||||
| @@ -1752,6 +1753,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe | ||||
| 		// Forget all seen creatures. | ||||
| 		if (_seenCreatures != null) | ||||
| 		{ | ||||
| 			CreatureSeeTaskManager.getInstance().remove(this); | ||||
| 			_seenCreatures.clear(); | ||||
| 		} | ||||
| 		 | ||||
| @@ -5478,6 +5480,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		CreatureSeeTaskManager.getInstance().add(this); | ||||
| 	} | ||||
| 	 | ||||
| 	public void updateSeenCreatures() | ||||
|   | ||||
| @@ -1087,8 +1087,7 @@ public class Npc extends Creature | ||||
| 			setClanId(getCastle().getOwnerId()); | ||||
| 		} | ||||
| 		 | ||||
| 		if (isAttackable() // OnCreatureSee for non attackables is triggered at World. | ||||
| 			&& CREATURE_SEE_IDS.contains(getId())) | ||||
| 		if (CREATURE_SEE_IDS.contains(getId())) | ||||
| 		{ | ||||
| 			initSeenCreatures(); | ||||
| 		} | ||||
|   | ||||
| @@ -0,0 +1,71 @@ | ||||
| /* | ||||
|  * This file is part of the L2J Mobius project. | ||||
|  *  | ||||
|  * 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 org.l2jmobius.gameserver.taskmanager; | ||||
|  | ||||
| import java.util.Set; | ||||
| import java.util.concurrent.ConcurrentHashMap; | ||||
|  | ||||
| import org.l2jmobius.commons.concurrent.ThreadPool; | ||||
| import org.l2jmobius.gameserver.model.actor.Creature; | ||||
|  | ||||
| /** | ||||
|  * @author Mobius | ||||
|  */ | ||||
| public class CreatureSeeTaskManager | ||||
| { | ||||
| 	private static final Set<Creature> CREATURES = ConcurrentHashMap.newKeySet(); | ||||
| 	private static boolean _working = false; | ||||
| 	 | ||||
| 	public CreatureSeeTaskManager() | ||||
| 	{ | ||||
| 		ThreadPool.scheduleAtFixedRate(() -> | ||||
| 		{ | ||||
| 			if (_working) | ||||
| 			{ | ||||
| 				return; | ||||
| 			} | ||||
| 			_working = true; | ||||
| 			 | ||||
| 			for (Creature creature : CREATURES) | ||||
| 			{ | ||||
| 				creature.updateSeenCreatures(); | ||||
| 			} | ||||
| 			 | ||||
| 			_working = false; | ||||
| 		}, 1000, 1000); | ||||
| 	} | ||||
| 	 | ||||
| 	public void add(Creature creature) | ||||
| 	{ | ||||
| 		CREATURES.add(creature); | ||||
| 	} | ||||
| 	 | ||||
| 	public void remove(Creature creature) | ||||
| 	{ | ||||
| 		CREATURES.remove(creature); | ||||
| 	} | ||||
| 	 | ||||
| 	public static CreatureSeeTaskManager getInstance() | ||||
| 	{ | ||||
| 		return SingletonHolder.INSTANCE; | ||||
| 	} | ||||
| 	 | ||||
| 	private static class SingletonHolder | ||||
| 	{ | ||||
| 		protected static final CreatureSeeTaskManager INSTANCE = new CreatureSeeTaskManager(); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 MobiusDevelopment
					MobiusDevelopment