From 242b6fe75684a52e87629172d20a36a2c6bcca23 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sun, 2 Jun 2019 21:11:42 +0000 Subject: [PATCH] Use one quest timer for siege guard aggro. --- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 52 ++++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 51 +++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 51 +++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 51 +++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 51 +++++++++++++----- .../data/scripts/ai/others/SiegeGuards.java | 51 +++++++++++++----- 13 files changed, 502 insertions(+), 169 deletions(-) diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java index 2116100e52..4498c03551 100644 --- a/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java index ca2dcf6698..2daffa416e 100644 --- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -84,6 +87,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -95,34 +99,49 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(FORT_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange())) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange())) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -138,6 +157,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -149,7 +175,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java index 34f8554f8e..aaacd2f8da 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -60,6 +63,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -69,34 +73,48 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(CASTLE_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -112,6 +130,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -123,7 +148,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java index 34f8554f8e..aaacd2f8da 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -60,6 +63,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -69,34 +73,48 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(CASTLE_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -112,6 +130,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -123,7 +148,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java index 34f8554f8e..aaacd2f8da 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -60,6 +63,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -69,34 +73,48 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(CASTLE_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -112,6 +130,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -123,7 +148,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java index 34f8554f8e..aaacd2f8da 100644 --- a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -60,6 +63,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -69,34 +73,48 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(CASTLE_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -112,6 +130,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -123,7 +148,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); } diff --git a/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java b/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java index 34f8554f8e..aaacd2f8da 100644 --- a/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java +++ b/L2J_Mobius_Classic_2.4_SecretOfEmpire/dist/game/data/scripts/ai/others/SiegeGuards.java @@ -16,6 +16,9 @@ */ package ai.others; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + import org.l2jmobius.gameserver.ai.CtrlIntention; import org.l2jmobius.gameserver.geoengine.GeoEngine; import org.l2jmobius.gameserver.model.World; @@ -60,6 +63,7 @@ public class SiegeGuards extends AbstractNpcAI 35134, 35135, 35136, 35176, 35177, 35178, 35218, 35219, 35220, 35261, 35262, 35263, 35264, 35265, 35308, 35309, 35310, 35352, 35353, 35354, 35497, 35498, 35499, 35500, 35501, 35544, 35545, 35546 }; //@formatter:on + private static final List SPAWNED_GUARDS = new CopyOnWriteArrayList<>(); public SiegeGuards() { @@ -69,34 +73,48 @@ public class SiegeGuards extends AbstractNpcAI addSpawnId(CASTLE_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); + addKillId(CASTLE_GUARDS); + addKillId(MERCENARIES); + addKillId(STATIONARY_MERCENARIES); + + startQuestTimer("AGGRO_CHECK", 3000, null, null, true); } @Override public String onAdvEvent(String event, Npc npc, PlayerInstance player) { - if ((npc != null) && !npc.isDead()) + for (Npc guard : SPAWNED_GUARDS) { - final WorldObject target = npc.getTarget(); - if (!npc.isInCombat() || (target == null) || (npc.calculateDistance2D(target) > npc.getAggroRange()) || target.isInvul()) + if (guard != null) { - for (Creature nearby : World.getInstance().getVisibleObjectsInRange(npc, Creature.class, npc.getAggroRange())) + if (guard.isDead()) { - if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + SPAWNED_GUARDS.remove(guard); + } + else + { + final WorldObject target = guard.getTarget(); + if (!guard.isInCombat() || (target == null) || (guard.calculateDistance2D(target) > guard.getAggroRange()) || target.isInvul()) { - final Summon summon = nearby.isSummon() ? (Summon) nearby : null; - final PlayerInstance pl = summon == null ? (PlayerInstance) nearby : summon.getOwner(); - if (((pl.getSiegeState() != 2) || pl.isRegisteredOnThisSiegeField(npc.getScriptValue())) && ((pl.getSiegeState() != 0) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))) + for (Creature nearby : World.getInstance().getVisibleObjectsInRange(guard, Creature.class, guard.getAggroRange())) { - if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + if (nearby.isPlayable() && GeoEngine.getInstance().canSeeTarget(guard, nearby)) { - addAttackPlayerDesire(npc, pl); - break; // no need to search more + 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))) + { + if (!pl.isInvisible() && !pl.isInvul()) // skip invisible players + { + addAttackPlayerDesire(guard, pl); + break; // no need to search more + } + } } } } } } - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), 3000, npc, null); } return super.onAdvEvent(event, npc, player); } @@ -112,6 +130,13 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } + @Override + public String onKill(Npc npc, PlayerInstance killer, boolean isSummon) + { + SPAWNED_GUARDS.remove(npc); + return super.onKill(npc, killer, isSummon); + } + @Override public String onSpawn(Npc npc) { @@ -123,7 +148,7 @@ public class SiegeGuards extends AbstractNpcAI final Castle castle = npc.getCastle(); final Fort fortress = npc.getFort(); npc.setScriptValue(fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - startQuestTimer("AGGRO_CHECK" + npc.getObjectId(), getRandom(1000, 10000), npc, null); + SPAWNED_GUARDS.add(npc); return super.onSpawn(npc); }