Automatic seen creature initialization for registered NPC ids.

This commit is contained in:
MobiusDevelopment
2021-06-22 23:01:45 +00:00
parent ce1873a639
commit 3cc620ba43
44 changed files with 484 additions and 0 deletions

View File

@ -18,6 +18,8 @@ package org.l2jmobius.gameserver.model.actor;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import org.l2jmobius.Config;
@ -116,6 +118,8 @@ public class Npc extends Creature
public static final int INTERACTION_DISTANCE = 250;
/** Maximum distance where the drop may appear given this NPC position. */
public static final int RANDOM_ITEM_DROP_LIMIT = 70;
/** Ids of NPCs that see creatures through the OnCreatureSee event. */
private static final Set<Integer> CREATURE_SEE_IDS = ConcurrentHashMap.newKeySet();
/** The Spawn object that manage this NpcInstance */
private Spawn _spawn;
/** The flag to specify if this NpcInstance is busy */
@ -1070,6 +1074,16 @@ public class Npc extends Creature
{
setClanId(getCastle().getOwnerId());
}
if (CREATURE_SEE_IDS.contains(getId()))
{
initSeenCreatures();
}
}
public static void addCreatureSeeId(int id)
{
CREATURE_SEE_IDS.add(id);
}
/**

View File

@ -981,6 +981,10 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
*/
protected final List<AbstractEventListener> setCreatureSeeId(Consumer<OnCreatureSee> callback, int... npcIds)
{
for (int id : npcIds)
{
Npc.addCreatureSeeId(id);
}
return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
@ -992,6 +996,10 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
*/
protected final List<AbstractEventListener> setCreatureSeeId(Consumer<OnCreatureSee> callback, Collection<Integer> npcIds)
{
for (int id : npcIds)
{
Npc.addCreatureSeeId(id);
}
return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}