Store most popular IBaseEvent to reduce object creation.
This commit is contained in:
@@ -71,6 +71,8 @@ import org.l2jmobius.gameserver.util.Util;
|
||||
*/
|
||||
public class CreatureAI extends AbstractAI
|
||||
{
|
||||
private OnNpcMoveFinished _onNpcMoveFinished = null;
|
||||
|
||||
public static class IntentionCommand
|
||||
{
|
||||
protected final CtrlIntention _crtlIntention;
|
||||
@@ -690,13 +692,17 @@ public class CreatureAI extends AbstractAI
|
||||
}
|
||||
clientStoppedMoving();
|
||||
|
||||
if (_actor instanceof Npc)
|
||||
if (_actor.isNpc())
|
||||
{
|
||||
final Npc npc = (Npc) _actor;
|
||||
WalkingManager.getInstance().onArrived(npc); // Walking Manager support
|
||||
|
||||
// Notify to scripts
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnNpcMoveFinished(npc), npc);
|
||||
if (_onNpcMoveFinished == null)
|
||||
{
|
||||
_onNpcMoveFinished = new OnNpcMoveFinished(npc);
|
||||
}
|
||||
EventDispatcher.getInstance().notifyEventAsync(_onNpcMoveFinished, npc);
|
||||
}
|
||||
|
||||
// If the Intention was AI_INTENTION_MOVE_TO, set the Intention to AI_INTENTION_ACTIVE
|
||||
|
@@ -289,6 +289,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
/** A list containing the dropped items of this fake player. */
|
||||
private final List<ItemInstance> _fakePlayerDrops = new CopyOnWriteArrayList<>();
|
||||
|
||||
private OnCreatureAttack _onCreatureAttack = null;
|
||||
private OnCreatureAttacked _onCreatureAttacked = null;
|
||||
private OnCreatureDamageDealt _onCreatureDamageDealt = null;
|
||||
private OnCreatureDamageReceived _onCreatureDamageReceived = null;
|
||||
private OnCreatureAttackAvoid _onCreatureAttackAvoid = null;
|
||||
private OnCreatureSkillUse _onCreatureSkillUse = null;
|
||||
|
||||
/**
|
||||
* Creates a creature.
|
||||
* @param template the creature template
|
||||
@@ -916,7 +923,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
}
|
||||
|
||||
// Notify to scripts
|
||||
final TerminateReturn attackReturn = EventDispatcher.getInstance().notifyEvent(new OnCreatureAttack(this, target), this, TerminateReturn.class);
|
||||
if (_onCreatureAttack == null)
|
||||
{
|
||||
_onCreatureAttack = new OnCreatureAttack();
|
||||
}
|
||||
_onCreatureAttack.setAttacker(this);
|
||||
_onCreatureAttack.setTarget(target);
|
||||
|
||||
final TerminateReturn attackReturn = EventDispatcher.getInstance().notifyEvent(_onCreatureAttack, this, TerminateReturn.class);
|
||||
if ((attackReturn != null) && attackReturn.terminate())
|
||||
{
|
||||
getAI().setIntention(AI_INTENTION_ACTIVE);
|
||||
@@ -925,7 +939,13 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
}
|
||||
|
||||
// Notify to scripts
|
||||
final TerminateReturn attackedReturn = EventDispatcher.getInstance().notifyEvent(new OnCreatureAttacked(this, target), target, TerminateReturn.class);
|
||||
if (_onCreatureAttacked == null)
|
||||
{
|
||||
_onCreatureAttacked = new OnCreatureAttacked();
|
||||
}
|
||||
_onCreatureAttacked.setAttacker(this);
|
||||
_onCreatureAttacked.setTarget(target);
|
||||
final TerminateReturn attackedReturn = EventDispatcher.getInstance().notifyEvent(_onCreatureAttacked, target, TerminateReturn.class);
|
||||
if ((attackedReturn != null) && attackedReturn.terminate())
|
||||
{
|
||||
getAI().setIntention(AI_INTENTION_ACTIVE);
|
||||
@@ -1694,7 +1714,16 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
return;
|
||||
}
|
||||
|
||||
final TerminateReturn term = EventDispatcher.getInstance().notifyEvent(new OnCreatureSkillUse(this, skill, simultaneously, target, targets), this, TerminateReturn.class);
|
||||
if (_onCreatureSkillUse == null)
|
||||
{
|
||||
_onCreatureSkillUse = new OnCreatureSkillUse();
|
||||
}
|
||||
_onCreatureSkillUse.setCaster(this);
|
||||
_onCreatureSkillUse.setSkill(skill);
|
||||
_onCreatureSkillUse.setSimultaneously(simultaneously);
|
||||
_onCreatureSkillUse.setTarget(target);
|
||||
_onCreatureSkillUse.setTargets(targets);
|
||||
final TerminateReturn term = EventDispatcher.getInstance().notifyEvent(_onCreatureSkillUse, this, TerminateReturn.class);
|
||||
if ((term != null) && term.terminate())
|
||||
{
|
||||
if (simultaneously)
|
||||
@@ -2459,6 +2488,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
{
|
||||
getAI().stopAITask();
|
||||
}
|
||||
|
||||
_onCreatureAttack = null;
|
||||
_onCreatureAttacked = null;
|
||||
_onCreatureDamageDealt = null;
|
||||
_onCreatureDamageReceived = null;
|
||||
_onCreatureAttackAvoid = null;
|
||||
_onCreatureSkillUse = null;
|
||||
|
||||
return super.decayMe();
|
||||
}
|
||||
|
||||
@@ -6546,8 +6583,32 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
*/
|
||||
public void notifyDamageReceived(double damage, Creature attacker, Skill skill, boolean critical, boolean damageOverTime)
|
||||
{
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureDamageReceived(attacker, this, damage, skill, critical, damageOverTime), this);
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureDamageDealt(attacker, this, damage, skill, critical, damageOverTime), attacker);
|
||||
if (attacker != null)
|
||||
{
|
||||
if (_onCreatureDamageDealt == null)
|
||||
{
|
||||
_onCreatureDamageDealt = new OnCreatureDamageDealt();
|
||||
}
|
||||
_onCreatureDamageDealt.setAttacker(attacker);
|
||||
_onCreatureDamageDealt.setTarget(this);
|
||||
_onCreatureDamageDealt.setDamage(damage);
|
||||
_onCreatureDamageDealt.setSkill(skill);
|
||||
_onCreatureDamageDealt.setCritical(critical);
|
||||
_onCreatureDamageDealt.setDamageOverTime(damageOverTime);
|
||||
EventDispatcher.getInstance().notifyEvent(_onCreatureDamageDealt, attacker);
|
||||
}
|
||||
|
||||
if (_onCreatureDamageReceived == null)
|
||||
{
|
||||
_onCreatureDamageReceived = new OnCreatureDamageReceived();
|
||||
}
|
||||
_onCreatureDamageReceived.setAttacker(attacker);
|
||||
_onCreatureDamageReceived.setTarget(this);
|
||||
_onCreatureDamageReceived.setDamage(damage);
|
||||
_onCreatureDamageReceived.setSkill(skill);
|
||||
_onCreatureDamageReceived.setCritical(critical);
|
||||
_onCreatureDamageReceived.setDamageOverTime(damageOverTime);
|
||||
EventDispatcher.getInstance().notifyEventAsync(_onCreatureDamageReceived, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6557,7 +6618,14 @@ public abstract class Creature extends WorldObject implements ISkillsHolder, IDe
|
||||
*/
|
||||
public void notifyAttackAvoid(Creature target, boolean isDot)
|
||||
{
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnCreatureAttackAvoid(this, target, isDot), target);
|
||||
if (_onCreatureAttackAvoid == null)
|
||||
{
|
||||
_onCreatureAttackAvoid = new OnCreatureAttackAvoid();
|
||||
}
|
||||
_onCreatureAttackAvoid.setAttacker(this);
|
||||
_onCreatureAttackAvoid.setTarget(target);
|
||||
_onCreatureAttackAvoid.setDamageOverTime(isDot);
|
||||
EventDispatcher.getInstance().notifyEvent(_onCreatureAttackAvoid, target);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -26,13 +26,11 @@ import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
*/
|
||||
public class OnCreatureAttack implements IBaseEvent
|
||||
{
|
||||
private final Creature _attacker;
|
||||
private final Creature _target;
|
||||
private Creature _attacker;
|
||||
private Creature _target;
|
||||
|
||||
public OnCreatureAttack(Creature attacker, Creature target)
|
||||
public OnCreatureAttack()
|
||||
{
|
||||
_attacker = attacker;
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public Creature getAttacker()
|
||||
@@ -40,11 +38,21 @@ public class OnCreatureAttack implements IBaseEvent
|
||||
return _attacker;
|
||||
}
|
||||
|
||||
public synchronized void setAttacker(Creature attacker)
|
||||
{
|
||||
_attacker = attacker;
|
||||
}
|
||||
|
||||
public Creature getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public synchronized void setTarget(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
|
@@ -26,20 +26,12 @@ import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
*/
|
||||
public class OnCreatureAttackAvoid implements IBaseEvent
|
||||
{
|
||||
private final Creature _attacker;
|
||||
private final Creature _target;
|
||||
private final boolean _damageOverTime;
|
||||
private Creature _attacker;
|
||||
private Creature _target;
|
||||
private boolean _damageOverTime;
|
||||
|
||||
/**
|
||||
* @param attacker who attack
|
||||
* @param target who avoid
|
||||
* @param isDot is dot damage
|
||||
*/
|
||||
public OnCreatureAttackAvoid(Creature attacker, Creature target, boolean isDot)
|
||||
public OnCreatureAttackAvoid()
|
||||
{
|
||||
_attacker = attacker;
|
||||
_target = target;
|
||||
_damageOverTime = isDot;
|
||||
}
|
||||
|
||||
public Creature getAttacker()
|
||||
@@ -47,19 +39,31 @@ public class OnCreatureAttackAvoid implements IBaseEvent
|
||||
return _attacker;
|
||||
}
|
||||
|
||||
public synchronized void setAttacker(Creature attacker)
|
||||
{
|
||||
_attacker = attacker;
|
||||
}
|
||||
|
||||
public Creature getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public synchronized void setTarget(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public boolean isDamageOverTime()
|
||||
{
|
||||
return _damageOverTime;
|
||||
}
|
||||
|
||||
public synchronized void setDamageOverTime(boolean damageOverTime)
|
||||
{
|
||||
_damageOverTime = damageOverTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
|
@@ -26,13 +26,11 @@ import org.l2jmobius.gameserver.model.events.impl.IBaseEvent;
|
||||
*/
|
||||
public class OnCreatureAttacked implements IBaseEvent
|
||||
{
|
||||
private final Creature _attacker;
|
||||
private final Creature _target;
|
||||
private Creature _attacker;
|
||||
private Creature _target;
|
||||
|
||||
public OnCreatureAttacked(Creature attacker, Creature target)
|
||||
public OnCreatureAttacked()
|
||||
{
|
||||
_attacker = attacker;
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public Creature getAttacker()
|
||||
@@ -40,11 +38,21 @@ public class OnCreatureAttacked implements IBaseEvent
|
||||
return _attacker;
|
||||
}
|
||||
|
||||
public synchronized void setAttacker(Creature attacker)
|
||||
{
|
||||
_attacker = attacker;
|
||||
}
|
||||
|
||||
public Creature getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public synchronized void setTarget(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
|
@@ -27,21 +27,15 @@ import org.l2jmobius.gameserver.model.skills.Skill;
|
||||
*/
|
||||
public class OnCreatureDamageDealt implements IBaseEvent
|
||||
{
|
||||
private final Creature _attacker;
|
||||
private final Creature _target;
|
||||
private final double _damage;
|
||||
private final Skill _skill;
|
||||
private final boolean _crit;
|
||||
private final boolean _damageOverTime;
|
||||
private Creature _attacker;
|
||||
private Creature _target;
|
||||
private double _damage;
|
||||
private Skill _skill;
|
||||
private boolean _crit;
|
||||
private boolean _damageOverTime;
|
||||
|
||||
public OnCreatureDamageDealt(Creature attacker, Creature target, double damage, Skill skill, boolean crit, boolean damageOverTime)
|
||||
public OnCreatureDamageDealt()
|
||||
{
|
||||
_attacker = attacker;
|
||||
_target = target;
|
||||
_damage = damage;
|
||||
_skill = skill;
|
||||
_crit = crit;
|
||||
_damageOverTime = damageOverTime;
|
||||
}
|
||||
|
||||
public Creature getAttacker()
|
||||
@@ -49,31 +43,61 @@ public class OnCreatureDamageDealt implements IBaseEvent
|
||||
return _attacker;
|
||||
}
|
||||
|
||||
public synchronized void setAttacker(Creature attacker)
|
||||
{
|
||||
_attacker = attacker;
|
||||
}
|
||||
|
||||
public Creature getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public synchronized void setTarget(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public double getDamage()
|
||||
{
|
||||
return _damage;
|
||||
}
|
||||
|
||||
public synchronized void setDamage(double damage)
|
||||
{
|
||||
_damage = damage;
|
||||
}
|
||||
|
||||
public Skill getSkill()
|
||||
{
|
||||
return _skill;
|
||||
}
|
||||
|
||||
public synchronized void setSkill(Skill skill)
|
||||
{
|
||||
_skill = skill;
|
||||
}
|
||||
|
||||
public boolean isCritical()
|
||||
{
|
||||
return _crit;
|
||||
}
|
||||
|
||||
public synchronized void setCritical(boolean crit)
|
||||
{
|
||||
_crit = crit;
|
||||
}
|
||||
|
||||
public boolean isDamageOverTime()
|
||||
{
|
||||
return _damageOverTime;
|
||||
}
|
||||
|
||||
public synchronized void setDamageOverTime(boolean damageOverTime)
|
||||
{
|
||||
_damageOverTime = damageOverTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
|
@@ -27,21 +27,15 @@ import org.l2jmobius.gameserver.model.skills.Skill;
|
||||
*/
|
||||
public class OnCreatureDamageReceived implements IBaseEvent
|
||||
{
|
||||
private final Creature _attacker;
|
||||
private final Creature _target;
|
||||
private final double _damage;
|
||||
private final Skill _skill;
|
||||
private final boolean _crit;
|
||||
private final boolean _damageOverTime;
|
||||
private Creature _attacker;
|
||||
private Creature _target;
|
||||
private double _damage;
|
||||
private Skill _skill;
|
||||
private boolean _crit;
|
||||
private boolean _damageOverTime;
|
||||
|
||||
public OnCreatureDamageReceived(Creature attacker, Creature target, double damage, Skill skill, boolean crit, boolean damageOverTime)
|
||||
public OnCreatureDamageReceived()
|
||||
{
|
||||
_attacker = attacker;
|
||||
_target = target;
|
||||
_damage = damage;
|
||||
_skill = skill;
|
||||
_crit = crit;
|
||||
_damageOverTime = damageOverTime;
|
||||
}
|
||||
|
||||
public Creature getAttacker()
|
||||
@@ -49,31 +43,61 @@ public class OnCreatureDamageReceived implements IBaseEvent
|
||||
return _attacker;
|
||||
}
|
||||
|
||||
public synchronized void setAttacker(Creature attacker)
|
||||
{
|
||||
_attacker = attacker;
|
||||
}
|
||||
|
||||
public Creature getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public synchronized void setTarget(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public double getDamage()
|
||||
{
|
||||
return _damage;
|
||||
}
|
||||
|
||||
public synchronized void setDamage(double damage)
|
||||
{
|
||||
_damage = damage;
|
||||
}
|
||||
|
||||
public Skill getSkill()
|
||||
{
|
||||
return _skill;
|
||||
}
|
||||
|
||||
public synchronized void setSkill(Skill skill)
|
||||
{
|
||||
_skill = skill;
|
||||
}
|
||||
|
||||
public boolean isCritical()
|
||||
{
|
||||
return _crit;
|
||||
}
|
||||
|
||||
public synchronized void setCritical(boolean crit)
|
||||
{
|
||||
_crit = crit;
|
||||
}
|
||||
|
||||
public boolean isDamageOverTime()
|
||||
{
|
||||
return _damageOverTime;
|
||||
}
|
||||
|
||||
public synchronized void setDamageOverTime(boolean damageOverTime)
|
||||
{
|
||||
_damageOverTime = damageOverTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
|
@@ -28,19 +28,14 @@ import org.l2jmobius.gameserver.model.skills.Skill;
|
||||
*/
|
||||
public class OnCreatureSkillUse implements IBaseEvent
|
||||
{
|
||||
private final Creature _caster;
|
||||
private final Skill _skill;
|
||||
private final boolean _simultaneously;
|
||||
private final Creature _target;
|
||||
private final WorldObject[] _targets;
|
||||
private Creature _caster;
|
||||
private Skill _skill;
|
||||
private boolean _simultaneously;
|
||||
private Creature _target;
|
||||
private WorldObject[] _targets;
|
||||
|
||||
public OnCreatureSkillUse(Creature caster, Skill skill, boolean simultaneously, Creature target, WorldObject[] targets)
|
||||
public OnCreatureSkillUse()
|
||||
{
|
||||
_caster = caster;
|
||||
_skill = skill;
|
||||
_simultaneously = simultaneously;
|
||||
_target = target;
|
||||
_targets = targets;
|
||||
}
|
||||
|
||||
public Creature getCaster()
|
||||
@@ -48,26 +43,51 @@ public class OnCreatureSkillUse implements IBaseEvent
|
||||
return _caster;
|
||||
}
|
||||
|
||||
public synchronized void setCaster(Creature caster)
|
||||
{
|
||||
_caster = caster;
|
||||
}
|
||||
|
||||
public Skill getSkill()
|
||||
{
|
||||
return _skill;
|
||||
}
|
||||
|
||||
public synchronized void setSkill(Skill skill)
|
||||
{
|
||||
_skill = skill;
|
||||
}
|
||||
|
||||
public boolean isSimultaneously()
|
||||
{
|
||||
return _simultaneously;
|
||||
}
|
||||
|
||||
public synchronized void setSimultaneously(boolean simultaneously)
|
||||
{
|
||||
_simultaneously = simultaneously;
|
||||
}
|
||||
|
||||
public Creature getTarget()
|
||||
{
|
||||
return _target;
|
||||
}
|
||||
|
||||
public synchronized void setTarget(Creature target)
|
||||
{
|
||||
_target = target;
|
||||
}
|
||||
|
||||
public WorldObject[] getTargets()
|
||||
{
|
||||
return _targets;
|
||||
}
|
||||
|
||||
public synchronized void setTargets(WorldObject[] targets)
|
||||
{
|
||||
_targets = targets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventType getType()
|
||||
{
|
||||
|
Reference in New Issue
Block a user