Addition of OnCreatureSee event.
This commit is contained in:
@@ -298,6 +298,7 @@ public abstract class AbstractAI implements Ctrl
|
||||
{
|
||||
case EVT_THINK:
|
||||
{
|
||||
_actor.updateSeenCreatures();
|
||||
onEvtThink();
|
||||
break;
|
||||
}
|
||||
@@ -384,7 +385,9 @@ public abstract class AbstractAI implements Ctrl
|
||||
}
|
||||
case EVT_FORGET_OBJECT:
|
||||
{
|
||||
onEvtForgetObject((WorldObject) args[0]);
|
||||
final WorldObject worldObject = (WorldObject) args[0];
|
||||
_actor.removeSeenCreature(worldObject);
|
||||
onEvtForgetObject(worldObject);
|
||||
break;
|
||||
}
|
||||
case EVT_CANCEL:
|
||||
|
@@ -83,6 +83,7 @@ import org.l2jmobius.gameserver.model.actor.tasks.creature.MagicUseTask;
|
||||
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
|
||||
import org.l2jmobius.gameserver.model.actor.tasks.creature.QueuedMagicUseTask;
|
||||
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.actor.transform.TransformTemplate;
|
||||
import org.l2jmobius.gameserver.model.clan.Clan;
|
||||
@@ -97,6 +98,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureAttacked;
|
||||
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.OnCreatureKill;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSkillUse;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.npc.OnNpcSkillSee;
|
||||
@@ -279,6 +281,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
|
||||
private final Map<Integer, RelationCache> _knownRelations = new ConcurrentHashMap<>();
|
||||
|
||||
private Set<Creature> _seenCreatures = null;
|
||||
private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
|
||||
|
||||
/** A list containing the dropped items of this fake player. */
|
||||
private final List<ItemInstance> _fakePlayerDrops = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -2440,6 +2445,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
{
|
||||
getSkillChannelized().abortChannelization();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2464,6 +2470,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Remove all 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();
|
||||
|
||||
@@ -6746,6 +6758,55 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
return _knownRelations;
|
||||
}
|
||||
|
||||
public void initSeenCreatures()
|
||||
{
|
||||
if (_seenCreatures == null)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (_seenCreatures == null)
|
||||
{
|
||||
if (isNpc())
|
||||
{
|
||||
final NpcTemplate template = ((Npc) this).getTemplate();
|
||||
if ((template != null) && (template.getAggroRange() > 0))
|
||||
{
|
||||
_seenCreatureRange = template.getAggroRange();
|
||||
}
|
||||
}
|
||||
|
||||
_seenCreatures = ConcurrentHashMap.newKeySet(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSeenCreatures()
|
||||
{
|
||||
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 int getKarma()
|
||||
{
|
||||
return _karma;
|
||||
|
@@ -64,6 +64,7 @@ import org.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
|
||||
import org.l2jmobius.gameserver.model.events.annotations.RegisterType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKill;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureZoneEnter;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureZoneExit;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.npc.OnNpcCanBeSeen;
|
||||
@@ -834,6 +835,28 @@ public abstract class AbstractScript extends ManagedScript
|
||||
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides instant callback operation when {@link Creature} sees another creature.
|
||||
* @param callback
|
||||
* @param npcIds
|
||||
* @return
|
||||
*/
|
||||
protected final List<AbstractEventListener> setCreatureSeeId(Consumer<OnCreatureSee> callback, int... npcIds)
|
||||
{
|
||||
return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides instant callback operation when {@link Creature} sees another creature.
|
||||
* @param callback
|
||||
* @param npcIds
|
||||
* @return
|
||||
*/
|
||||
protected final List<AbstractEventListener> setCreatureSeeId(Consumer<OnCreatureSee> callback, Collection<Integer> npcIds)
|
||||
{
|
||||
return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@@ -26,6 +26,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureAttacked;
|
||||
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.OnCreatureKill;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSkillUse;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureZoneEnter;
|
||||
@@ -133,6 +134,7 @@ public enum EventType
|
||||
ON_CREATURE_DAMAGE_RECEIVED(OnCreatureDamageReceived.class, void.class),
|
||||
ON_CREATURE_DAMAGE_DEALT(OnCreatureDamageDealt.class, void.class),
|
||||
ON_CREATURE_KILL(OnCreatureKill.class, void.class, TerminateReturn.class),
|
||||
ON_CREATURE_SEE(OnCreatureSee.class, void.class),
|
||||
ON_CREATURE_SKILL_USE(OnCreatureSkillUse.class, void.class, TerminateReturn.class),
|
||||
ON_CREATURE_TELEPORTED(OnCreatureTeleported.class, void.class),
|
||||
ON_CREATURE_ZONE_ENTER(OnCreatureZoneEnter.class, void.class),
|
||||
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.creature;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnCreatureSee implements IBaseEvent
|
||||
{
|
||||
private final Creature _seer;
|
||||
private final Creature _seen;
|
||||
|
||||
public OnCreatureSee(Creature seer, Creature seen)
|
||||
{
|
||||
_seer = seer;
|
||||
_seen = seen;
|
||||
}
|
||||
|
||||
public Creature getSeer()
|
||||
{
|
||||
return _seer;
|
||||
}
|
||||
|
||||
public Creature getSeen()
|
||||
{
|
||||
return _seen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_CREATURE_SEE;
|
||||
}
|
||||
}
|
@@ -298,6 +298,7 @@ public abstract class AbstractAI implements Ctrl
|
||||
{
|
||||
case EVT_THINK:
|
||||
{
|
||||
_actor.updateSeenCreatures();
|
||||
onEvtThink();
|
||||
break;
|
||||
}
|
||||
@@ -384,7 +385,9 @@ public abstract class AbstractAI implements Ctrl
|
||||
}
|
||||
case EVT_FORGET_OBJECT:
|
||||
{
|
||||
onEvtForgetObject((WorldObject) args[0]);
|
||||
final WorldObject worldObject = (WorldObject) args[0];
|
||||
_actor.removeSeenCreature(worldObject);
|
||||
onEvtForgetObject(worldObject);
|
||||
break;
|
||||
}
|
||||
case EVT_CANCEL:
|
||||
|
@@ -83,6 +83,7 @@ import org.l2jmobius.gameserver.model.actor.tasks.creature.MagicUseTask;
|
||||
import org.l2jmobius.gameserver.model.actor.tasks.creature.NotifyAITask;
|
||||
import org.l2jmobius.gameserver.model.actor.tasks.creature.QueuedMagicUseTask;
|
||||
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.actor.transform.TransformTemplate;
|
||||
import org.l2jmobius.gameserver.model.clan.Clan;
|
||||
@@ -97,6 +98,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureAttacked;
|
||||
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.OnCreatureKill;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSkillUse;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.npc.OnNpcSkillSee;
|
||||
@@ -280,6 +282,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
|
||||
private final Map<Integer, RelationCache> _knownRelations = new ConcurrentHashMap<>();
|
||||
|
||||
private Set<Creature> _seenCreatures = null;
|
||||
private int _seenCreatureRange = Config.ALT_PARTY_RANGE;
|
||||
|
||||
/** A list containing the dropped items of this fake player. */
|
||||
private final List<ItemInstance> _fakePlayerDrops = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -2442,6 +2447,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
{
|
||||
getSkillChannelized().abortChannelization();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2466,6 +2472,12 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
// Remove all 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();
|
||||
|
||||
@@ -6748,6 +6760,55 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
return _knownRelations;
|
||||
}
|
||||
|
||||
public void initSeenCreatures()
|
||||
{
|
||||
if (_seenCreatures == null)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (_seenCreatures == null)
|
||||
{
|
||||
if (isNpc())
|
||||
{
|
||||
final NpcTemplate template = ((Npc) this).getTemplate();
|
||||
if ((template != null) && (template.getAggroRange() > 0))
|
||||
{
|
||||
_seenCreatureRange = template.getAggroRange();
|
||||
}
|
||||
}
|
||||
|
||||
_seenCreatures = ConcurrentHashMap.newKeySet(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSeenCreatures()
|
||||
{
|
||||
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 int getKarma()
|
||||
{
|
||||
return _karma;
|
||||
|
@@ -64,6 +64,7 @@ import org.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
|
||||
import org.l2jmobius.gameserver.model.events.annotations.RegisterType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureKill;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureZoneEnter;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureZoneExit;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.npc.OnNpcCanBeSeen;
|
||||
@@ -834,6 +835,28 @@ public abstract class AbstractScript extends ManagedScript
|
||||
return registerConsumer(callback, EventType.ON_NPC_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides instant callback operation when {@link Creature} sees another creature.
|
||||
* @param callback
|
||||
* @param npcIds
|
||||
* @return
|
||||
*/
|
||||
protected final List<AbstractEventListener> setCreatureSeeId(Consumer<OnCreatureSee> callback, int... npcIds)
|
||||
{
|
||||
return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides instant callback operation when {@link Creature} sees another creature.
|
||||
* @param callback
|
||||
* @param npcIds
|
||||
* @return
|
||||
*/
|
||||
protected final List<AbstractEventListener> setCreatureSeeId(Consumer<OnCreatureSee> callback, Collection<Integer> npcIds)
|
||||
{
|
||||
return registerConsumer(callback, EventType.ON_CREATURE_SEE, ListenerRegisterType.NPC, npcIds);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
@@ -26,6 +26,7 @@ import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureAttacked;
|
||||
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.OnCreatureKill;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSee;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureSkillUse;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureTeleported;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.OnCreatureZoneEnter;
|
||||
@@ -133,6 +134,7 @@ public enum EventType
|
||||
ON_CREATURE_DAMAGE_RECEIVED(OnCreatureDamageReceived.class, void.class),
|
||||
ON_CREATURE_DAMAGE_DEALT(OnCreatureDamageDealt.class, void.class),
|
||||
ON_CREATURE_KILL(OnCreatureKill.class, void.class, TerminateReturn.class),
|
||||
ON_CREATURE_SEE(OnCreatureSee.class, void.class),
|
||||
ON_CREATURE_SKILL_USE(OnCreatureSkillUse.class, void.class, TerminateReturn.class),
|
||||
ON_CREATURE_TELEPORTED(OnCreatureTeleported.class, void.class),
|
||||
ON_CREATURE_ZONE_ENTER(OnCreatureZoneEnter.class, void.class),
|
||||
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.events.impl.creature;
|
||||
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class OnCreatureSee implements IBaseEvent
|
||||
{
|
||||
private final Creature _seer;
|
||||
private final Creature _seen;
|
||||
|
||||
public OnCreatureSee(Creature seer, Creature seen)
|
||||
{
|
||||
_seer = seer;
|
||||
_seen = seen;
|
||||
}
|
||||
|
||||
public Creature getSeer()
|
||||
{
|
||||
return _seer;
|
||||
}
|
||||
|
||||
public Creature getSeen()
|
||||
{
|
||||
return _seen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
return EventType.ON_CREATURE_SEE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user