Fixed and improved and SiegeGuard related behaviors.

Contributed by Sahar.
This commit is contained in:
MobiusDevelopment 2020-07-03 22:49:50 +00:00
parent 4d08c902de
commit e11a5bb916
51 changed files with 680 additions and 542 deletions

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || (target.isPlayer() && target.getActingPlayer().isInvul()))
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -859,7 +859,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -895,9 +895,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != AI_INTENTION_ATTACK))
else if (called.getAI()._intention != AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -190,7 +190,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()) || ((_hall != null) && _hall.getSiegeZone().isActive()))
{
final int activeSiegeId = (_fort != null ? _fort.getResidenceId() : (_castle != null ? _castle.getResidenceId() : (_hall != null ? _hall.getId() : 0)));
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1) && TerritoryWarManager.getInstance().isAllyField(player, activeSiegeId))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
@ -29,7 +28,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -154,44 +153,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || (target.isPlayer() && target.getActingPlayer().isInvul()))
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -859,7 +859,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -895,9 +895,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != AI_INTENTION_ATTACK))
else if (called.getAI()._intention != AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -190,7 +190,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()) || ((_hall != null) && _hall.getSiegeZone().isActive()))
{
final int activeSiegeId = (_fort != null ? _fort.getResidenceId() : (_castle != null ? _castle.getResidenceId() : (_hall != null ? _hall.getId() : 0)));
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1) && TerritoryWarManager.getInstance().isAllyField(player, activeSiegeId))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}

View File

@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.ai.CtrlIntention;
import org.l2jmobius.gameserver.geoengine.GeoEngine;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.model.World;
@ -28,7 +27,7 @@ import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Summon;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.entity.Castle;
import org.l2jmobius.gameserver.model.entity.Fort;
@ -118,44 +117,52 @@ public class SiegeGuards extends AbstractNpcAI
final List<Npc> guards = RESIDENCE_GUARD_MAP[_residenceId];
for (Npc guard : guards)
{
if (guard == null)
// Should never happen.
if ((guard == null) || !guard.isAttackable())
{
continue;
}
// Remove dead guards.
if (guard.isDead())
{
guards.remove(guard);
continue;
}
final WorldObject target = guard.getTarget();
if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul())
{
for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange()))
{
if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
final Summon summon = nearby.isSummon() ? (Summon) nearby : null;
final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner();
if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(guard.getScriptValue())) && ((pl.getSiegeState() != 0) || (guard.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)))
{
// skip invisible players
if (pl.isInvisible() || pl.isInvul())
// Skip if guard is currently attacking.
if (guard.isInCombat())
{
continue;
}
if (guard.isAttackable())
// Skip if guard has an active target (not dead/invis/invul and is within range).
final WorldObject target = guard.getTarget();
final Creature targetCreature = (target != null) && target.isCreature() ? (Creature) target : null;
if ((targetCreature != null) && !targetCreature.isDead() && !targetCreature.isInvisible() && !targetCreature.isInvul() && (guard.calculateDistance2D(targetCreature) < guard.getAggroRange()))
{
continue;
}
// Iterate all players/summons within aggro range...
for (Playable nearby : World.getInstance().getVisibleObjectsInRange(guard, Playable.class, guard.getAggroRange()))
{
// Do not attack players/summons who are dead/invis/invul or cannot be seen.
if (nearby.isDead() || nearby.isInvisible() || nearby.isInvul() || !GeoEngine.getInstance().canSeeTarget(guard, nearby))
{
continue;
}
// Do not attack defenders who are registered to this castle.
final PlayerInstance player = nearby.getActingPlayer();
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(guard.getScriptValue()))
{
continue;
}
// Attack the target and stop searching.
((Attackable) guard).addDamageHate(nearby, 0, 999);
}
guard.setRunning();
guard.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
break; // no need to search more
}
}
}
break;
}
}

View File

@ -40,7 +40,6 @@ import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Attackable;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.DefenderInstance;
import org.l2jmobius.gameserver.model.actor.instance.GrandBossInstance;
@ -711,7 +710,7 @@ public class AttackableAI extends CreatureAI
}
if (targetExistsInAttackByList)
{
World.getInstance().forEachVisibleObjectInRange(npc, Npc.class, factionRange, called ->
World.getInstance().forEachVisibleObjectInRange(npc, Attackable.class, factionRange, called ->
{
// Don't call dead npcs, npcs without ai or npcs which are too far away.
if (called.isDead() || !called.hasAI() || (Math.abs(finalTarget.getZ() - called.getZ()) > 600))
@ -736,9 +735,9 @@ public class AttackableAI extends CreatureAI
called.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, finalTarget, 1);
EventDispatcher.getInstance().notifyEventAsync(new OnAttackableFactionCall(called, getActiveChar(), finalTarget.getActingPlayer(), finalTarget.isSummon()), called);
}
else if (called.isAttackable() && (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK))
else if (called.getAI()._intention != CtrlIntention.AI_INTENTION_ATTACK)
{
((Attackable) called).addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.addDamageHate(finalTarget, 0, npc.getHating(finalTarget));
called.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, finalTarget);
}
});

View File

@ -215,7 +215,9 @@ public class DefenderInstance extends Attackable
if (((_fort != null) && _fort.getZone().isActive()) || ((_castle != null) && _castle.getZone().isActive()))
{
final int activeSiegeId = (_fort != null) ? _fort.getResidenceId() : _castle.getResidenceId();
if ((player != null) && (((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId)) || ((player.getSiegeState() == 1))))
// Do not add hate on defenders.
if ((player.getSiegeState() == 2) && player.isRegisteredOnThisSiegeField(activeSiegeId))
{
return;
}