From 9601f3177675a52ff3b92545e09f11386a66cce3 Mon Sep 17 00:00:00 2001
From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Tue, 22 Jun 2021 21:27:08 +0000
Subject: [PATCH] Removal of CreatureContainer class.
---
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
.../l2jmobius/gameserver/ai/AbstractAI.java | 5 +-
.../gameserver/model/CreatureContainer.java | 106 ------------------
.../gameserver/model/actor/Creature.java | 80 +++++++------
.../l2jmobius/gameserver/model/actor/Npc.java | 8 --
.../model/events/AbstractScript.java | 17 ++-
100 files changed, 1280 insertions(+), 3040 deletions(-)
delete mode 100644 L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Classic_Interlude/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/CreatureContainer.java
delete mode 100644 L2J_Mobius_Essence_5.5_FrostLord/java/org/l2jmobius/gameserver/model/CreatureContainer.java
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java
index c0499b01cb..f36f0a1bc6 100644
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5428,22 +5425,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5451,15 +5433,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Npc.java
index 043e357963..998d18643b 100644
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 69643f4a98..f0e51705a0 100644
--- a/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_1.0_Ertheia/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -962,6 +962,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -974,14 +985,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java
index c0499b01cb..f36f0a1bc6 100644
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5428,22 +5425,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5451,15 +5433,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 69643f4a98..f0e51705a0 100644
--- a/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_2.5_Underground/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -962,6 +962,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -974,14 +985,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 62698ddb64..6e33431180 100644
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5428,22 +5425,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5451,15 +5433,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_3.0_Helios/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 62698ddb64..6e33431180 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5428,22 +5425,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5451,15 +5433,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 5ae609289a..c4dc1f46cd 100644
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5437,22 +5434,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5460,15 +5442,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_5.0_Salvation/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 5ae609289a..c4dc1f46cd 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5437,22 +5434,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5460,15 +5442,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 5ae609289a..c4dc1f46cd 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5437,22 +5434,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5460,15 +5442,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java
index a7ed33ff0a..b106afe8f1 100644
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5436,22 +5433,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5459,15 +5441,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc73bc959f..98c4f9f99c 100644
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java
index e0c4b68396..fc94191060 100644
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5436,22 +5433,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5459,15 +5441,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc0a68a851..3947541ddb 100644
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1833,14 +1833,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java
index e0c4b68396..fc94191060 100644
--- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5436,22 +5433,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5459,15 +5441,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Npc.java
index bc0a68a851..3947541ddb 100644
--- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1833,14 +1833,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index aa6174f895..bce4f6845e 100644
--- a/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_9.0_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -963,6 +963,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -975,14 +986,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 4a93e956ae..2f4ec8ef41 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5427,22 +5424,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5450,15 +5432,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Npc.java
index 588693e68a..a3c8d420b2 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 54ba7d9008..8a2109f5b2 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -937,6 +937,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -949,14 +960,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 4a93e956ae..2f4ec8ef41 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5427,22 +5424,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5450,15 +5432,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Npc.java
index 588693e68a..a3c8d420b2 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 54ba7d9008..8a2109f5b2 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -937,6 +937,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -949,14 +960,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 1ae9e5128f..b2fe2a630a 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -69,7 +69,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -88,6 +87,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -101,6 +101,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -271,7 +272,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -563,13 +565,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -577,12 +572,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -591,6 +580,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1727,6 +1717,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1757,6 +1748,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5436,22 +5433,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5459,15 +5441,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Npc.java
index 588693e68a..a3c8d420b2 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1832,14 +1832,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 54ba7d9008..8a2109f5b2 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -937,6 +937,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -949,14 +960,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 8e560b3519..08f890c7eb 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -70,7 +70,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -89,6 +88,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -102,6 +102,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -272,7 +273,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -564,13 +566,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -578,12 +573,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -592,6 +581,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1728,6 +1718,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1758,6 +1749,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5461,22 +5458,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5484,15 +5466,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Npc.java
index 402e0206cb..b6ae6c8945 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1844,14 +1844,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 54ba7d9008..8a2109f5b2 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -937,6 +937,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -949,14 +960,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection npcIds)
{
- return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
// ---------------------------------------------------------------------------------------------------------------------------
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/ai/AbstractAI.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/ai/AbstractAI.java
index 5e37ea5e18..8bc2c7b601 100644
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/ai/AbstractAI.java
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/ai/AbstractAI.java
@@ -254,6 +254,7 @@ public abstract class AbstractAI implements Ctrl
{
case EVT_THINK:
{
+ _actor.updateSeenCreatures();
onEvtThink();
break;
}
@@ -325,7 +326,9 @@ public abstract class AbstractAI implements Ctrl
}
case EVT_FORGET_OBJECT:
{
- onEvtForgetObject((WorldObject) arg0);
+ final WorldObject worldObject = (WorldObject) arg0;
+ _actor.removeSeenCreature(worldObject);
+ onEvtForgetObject(worldObject);
break;
}
case EVT_CANCEL:
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/CreatureContainer.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/CreatureContainer.java
deleted file mode 100644
index b831a14f65..0000000000
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/CreatureContainer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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 .
- */
-package org.l2jmobius.gameserver.model;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-import java.util.function.Predicate;
-
-import org.l2jmobius.commons.concurrent.ThreadPool;
-import org.l2jmobius.gameserver.model.actor.Creature;
-import org.l2jmobius.gameserver.model.events.EventDispatcher;
-import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
-
-/**
- * @author UnAfraid
- */
-public class CreatureContainer
-{
- private final Set _seen = ConcurrentHashMap.newKeySet();
- private final Creature _owner;
- private final int _range;
- private ScheduledFuture> _task;
- private Predicate _condition = null;
-
- public CreatureContainer(Creature owner, int range, Predicate condition)
- {
- _owner = owner;
- _range = range;
- _condition = condition;
- start();
- }
-
- public Creature getOwner()
- {
- return _owner;
- }
-
- public int getRange()
- {
- return _range;
- }
-
- /**
- * Starts the task that scans for new creatures
- */
- public void start()
- {
- if ((_task == null) || _task.isDone())
- {
- _task = ThreadPool.scheduleAtFixedRate(this::update, 1000, 1000);
- }
- }
-
- /**
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; {@code true} otherwise
- */
- public boolean stop()
- {
- return (_task != null) && !_task.isDone() && _task.cancel(false);
- }
-
- /**
- * Resets the creatures container, all previously seen creature will be discarded and next time update method is called will notify for each creature that owner sees!
- */
- public void reset()
- {
- _seen.clear();
- }
-
- /**
- * Scans around the npc and notifies about new creature owner seen
- */
- private void update()
- {
- final Set verified = new HashSet<>();
- World.getInstance().forEachVisibleObjectInRange(_owner, Creature.class, _range, creature ->
- {
- if ((_condition == null) || _condition.test(creature))
- {
- if (_seen.add(creature.getObjectId()))
- {
- EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(_owner, creature), _owner);
- }
- verified.add(creature.getObjectId());
- }
- });
-
- _seen.retainAll(verified);
- }
-}
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java
index 8e560b3519..08f890c7eb 100644
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Creature.java
@@ -70,7 +70,6 @@ import org.l2jmobius.gameserver.instancemanager.MapRegionManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.AccessLevel;
-import org.l2jmobius.gameserver.model.CreatureContainer;
import org.l2jmobius.gameserver.model.EffectList;
import org.l2jmobius.gameserver.model.Hit;
import org.l2jmobius.gameserver.model.Location;
@@ -89,6 +88,7 @@ import org.l2jmobius.gameserver.model.actor.stat.CreatureStat;
import org.l2jmobius.gameserver.model.actor.status.CreatureStatus;
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
import org.l2jmobius.gameserver.model.actor.templates.CreatureTemplate;
+import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
import org.l2jmobius.gameserver.model.actor.transform.Transform;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.effects.EffectFlag;
@@ -102,6 +102,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageDealt
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDamageReceived;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureDeath;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKilled;
+import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleport;
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
import org.l2jmobius.gameserver.model.events.listeners.AbstractEventListener;
@@ -272,7 +273,8 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
private final Map _knownRelations = new ConcurrentHashMap<>();
- private CreatureContainer _seenCreatures;
+ private Set _seenCreatures = null;
+ private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
private final Map _statusUpdates = new ConcurrentHashMap<>();
@@ -564,13 +566,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
_summoner.removeSummonedNpc(getObjectId());
}
-
- // Stop on creature see task and clear the data
- if (_seenCreatures != null)
- {
- _seenCreatures.stop();
- _seenCreatures.reset();
- }
}
@Override
@@ -578,12 +573,6 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
super.onSpawn();
revalidateZone(true);
-
- // restart task
- if (_seenCreatures != null)
- {
- _seenCreatures.start();
- }
}
public synchronized void onTeleported()
@@ -592,6 +581,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
return;
}
+
spawnMe(getX(), getY(), getZ());
setTeleporting(false);
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureTeleported(this), this);
@@ -1728,6 +1718,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
getSkillChannelized().abortChannelization();
}
+
return true;
}
@@ -1758,6 +1749,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
// Remove all active, passive and option effects, do not broadcast changes.
_effectList.stopAllEffectsWithoutExclusions(false, false);
+ // Forget all seen creatures.
+ if (_seenCreatures != null)
+ {
+ _seenCreatures.clear();
+ }
+
// Cancel the BuffFinishTask related to this creature.
cancelBuffFinishTask();
@@ -5461,22 +5458,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
return _blockActionsAllowedSkills.containsKey(skill.getId());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * @param range
- */
- public void initSeenCreatures(int range)
- {
- initSeenCreatures(range, null);
- }
-
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- * The condition can be null
- * @param range
- * @param condition
- */
- public void initSeenCreatures(int range, Predicate condition)
+ public void initSeenCreatures()
{
if (_seenCreatures == null)
{
@@ -5484,15 +5466,45 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
{
if (_seenCreatures == null)
{
- _seenCreatures = new CreatureContainer(this, range, condition);
+ if (isNpc())
+ {
+ final NpcTemplate template = ((Npc) this).getTemplate();
+ if ((template != null) && (template.getAggroRange() > 0))
+ {
+ _seenCreatureRange = template.getAggroRange();
+ }
+ }
+
+ _seenCreatures = ConcurrentHashMap.newKeySet(1);
}
}
}
}
- public CreatureContainer getSeenCreatures()
+ public void updateSeenCreatures()
{
- return _seenCreatures;
+ if ((_seenCreatures == null) || _isDead || !isSpawned())
+ {
+ return;
+ }
+
+ World.getInstance().forEachVisibleObjectInRange(this, Creature.class, _seenCreatureRange, creature ->
+ {
+ if (_seenCreatures.add(creature))
+ {
+ EventDispatcher.getInstance().notifyEventAsync(new OnCreatureSee(this, creature), this);
+ }
+ });
+ }
+
+ public void removeSeenCreature(WorldObject worldObject)
+ {
+ if (_seenCreatures == null)
+ {
+ return;
+ }
+
+ _seenCreatures.remove(worldObject);
}
public MoveType getMoveType()
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Npc.java
index 402e0206cb..b6ae6c8945 100644
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/actor/Npc.java
@@ -1844,14 +1844,6 @@ public class Npc extends Creature
return Rnd.get(100) < Rnd.get(getTemplate().getMinSkillChance(), getTemplate().getMaxSkillChance());
}
- /**
- * Initialize creature container that looks up for creatures around its owner, and notifies with onCreatureSee upon discovery.
- */
- public void initSeenCreatures()
- {
- initSeenCreatures(getTemplate().getAggroRange());
- }
-
/**
* @return the NpcStringId for name
*/
diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/events/AbstractScript.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
index 54ba7d9008..8a2109f5b2 100644
--- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
+++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/java/org/l2jmobius/gameserver/model/events/AbstractScript.java
@@ -937,6 +937,17 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
}
+ /**
+ * Provides instant callback operation when {@link Npc} sees another creature.
+ * @param callback
+ * @param npcIds
+ * @return
+ */
+ protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ {
+ return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
+ }
+
/**
* Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
@@ -949,14 +960,14 @@ public abstract class AbstractScript extends ManagedScript implements IEventTime
}
/**
- * Provides instant callback operation when {@link Npc} sees another creature.
+ * Provides instant callback operation when {@link Creature} sees another creature.
* @param callback
* @param npcIds
* @return
*/
- protected final List setNpcCreatureSeeId(Consumer callback, Collection npcIds)
+ protected final List setCreatureSeeId(Consumer callback, Collection