From 5aac275c4a4d91da3e7e7c88db1a9d576e978d9b Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sat, 11 Nov 2017 21:56:22 +0000 Subject: [PATCH] Use a task for siege guard aggro check. --- .../data/scripts/ai/others/SiegeGuards.java | 61 +++++++++++-------- .../data/scripts/ai/others/SiegeGuards.java | 61 +++++++++++-------- .../data/scripts/ai/others/SiegeGuards.java | 61 +++++++++++-------- .../data/scripts/ai/others/SiegeGuards.java | 61 +++++++++++-------- .../data/scripts/ai/others/SiegeGuards.java | 61 +++++++++++-------- 5 files changed, 180 insertions(+), 125 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 fb9007f8c8..b104a1ff86 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 @@ -18,6 +18,7 @@ package ai.others; import com.l2jmobius.gameserver.ai.CtrlIntention; import com.l2jmobius.gameserver.geoengine.GeoEngine; +import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.L2Attackable; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.L2Npc; @@ -88,16 +89,46 @@ public class SiegeGuards extends AbstractNpcAI addAttackId(FORT_GUARDS); addAttackId(MERCENARIES); addAttackId(STATIONARY_MERCENARIES); - addSeeCreatureId(CASTLE_GUARDS); - addSeeCreatureId(FORT_GUARDS); - addSeeCreatureId(MERCENARIES); - addSeeCreatureId(STATIONARY_MERCENARIES); addSpawnId(CASTLE_GUARDS); addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); } + @Override + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) + { + if (event.equals("AGGRO_CHECK")) + { + if ((npc != null) && !npc.isDead()) + { + if (!npc.isInCombat()) + { + for (L2Character nearby : L2World.getInstance().getVisibleObjects(npc, L2Character.class, npc.getAggroRange())) + { + if (nearby.isPlayable() && (npc.calculateDirectionTo(nearby) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + { + final L2Summon summon = nearby.isSummon() ? ((L2Summon) nearby) : null; + final L2PcInstance cha = summon == null ? (L2PcInstance) nearby : summon.getOwner(); + final Castle castle = npc.getCastle(); + final Fort fortress = npc.getFort(); + final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); + if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) + { + if (!cha.isInvisible()) // skip invisible players + { + addAttackPlayerDesire(npc, cha); + } + } + } + } + } + startQuestTimer("AGGRO_CHECK", 2000, npc, null); + } + } + return super.onAdvEvent(event, npc, player); + } + @Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { @@ -112,31 +143,11 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } - @Override - public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon) - { - if (creature.isPlayable() && (npc.calculateDirectionTo(creature) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, creature)) - { - final L2Summon summon = isSummon ? creature.getServitors().values().stream().findFirst().orElse(creature.getPet()) : null; - final L2PcInstance cha = summon == null ? (L2PcInstance) creature : summon.getOwner(); - final Castle castle = npc.getCastle(); - final Fort fortress = npc.getFort(); - final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) - { - if (!cha.isInvisible()) // skip invisible players - { - addAttackPlayerDesire(npc, cha); - } - } - } - return super.onSeeCreature(npc, creature, isSummon); - } - @Override public String onSpawn(L2Npc npc) { npc.setRandomWalking(false); + startQuestTimer("AGGRO_CHECK", 2000, npc, null); 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 fb9007f8c8..b104a1ff86 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 @@ -18,6 +18,7 @@ package ai.others; import com.l2jmobius.gameserver.ai.CtrlIntention; import com.l2jmobius.gameserver.geoengine.GeoEngine; +import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.L2Attackable; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.L2Npc; @@ -88,16 +89,46 @@ public class SiegeGuards extends AbstractNpcAI addAttackId(FORT_GUARDS); addAttackId(MERCENARIES); addAttackId(STATIONARY_MERCENARIES); - addSeeCreatureId(CASTLE_GUARDS); - addSeeCreatureId(FORT_GUARDS); - addSeeCreatureId(MERCENARIES); - addSeeCreatureId(STATIONARY_MERCENARIES); addSpawnId(CASTLE_GUARDS); addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); } + @Override + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) + { + if (event.equals("AGGRO_CHECK")) + { + if ((npc != null) && !npc.isDead()) + { + if (!npc.isInCombat()) + { + for (L2Character nearby : L2World.getInstance().getVisibleObjects(npc, L2Character.class, npc.getAggroRange())) + { + if (nearby.isPlayable() && (npc.calculateDirectionTo(nearby) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + { + final L2Summon summon = nearby.isSummon() ? ((L2Summon) nearby) : null; + final L2PcInstance cha = summon == null ? (L2PcInstance) nearby : summon.getOwner(); + final Castle castle = npc.getCastle(); + final Fort fortress = npc.getFort(); + final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); + if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) + { + if (!cha.isInvisible()) // skip invisible players + { + addAttackPlayerDesire(npc, cha); + } + } + } + } + } + startQuestTimer("AGGRO_CHECK", 2000, npc, null); + } + } + return super.onAdvEvent(event, npc, player); + } + @Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { @@ -112,31 +143,11 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } - @Override - public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon) - { - if (creature.isPlayable() && (npc.calculateDirectionTo(creature) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, creature)) - { - final L2Summon summon = isSummon ? creature.getServitors().values().stream().findFirst().orElse(creature.getPet()) : null; - final L2PcInstance cha = summon == null ? (L2PcInstance) creature : summon.getOwner(); - final Castle castle = npc.getCastle(); - final Fort fortress = npc.getFort(); - final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) - { - if (!cha.isInvisible()) // skip invisible players - { - addAttackPlayerDesire(npc, cha); - } - } - } - return super.onSeeCreature(npc, creature, isSummon); - } - @Override public String onSpawn(L2Npc npc) { npc.setRandomWalking(false); + startQuestTimer("AGGRO_CHECK", 2000, npc, null); 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 fb9007f8c8..b104a1ff86 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 @@ -18,6 +18,7 @@ package ai.others; import com.l2jmobius.gameserver.ai.CtrlIntention; import com.l2jmobius.gameserver.geoengine.GeoEngine; +import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.L2Attackable; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.L2Npc; @@ -88,16 +89,46 @@ public class SiegeGuards extends AbstractNpcAI addAttackId(FORT_GUARDS); addAttackId(MERCENARIES); addAttackId(STATIONARY_MERCENARIES); - addSeeCreatureId(CASTLE_GUARDS); - addSeeCreatureId(FORT_GUARDS); - addSeeCreatureId(MERCENARIES); - addSeeCreatureId(STATIONARY_MERCENARIES); addSpawnId(CASTLE_GUARDS); addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); } + @Override + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) + { + if (event.equals("AGGRO_CHECK")) + { + if ((npc != null) && !npc.isDead()) + { + if (!npc.isInCombat()) + { + for (L2Character nearby : L2World.getInstance().getVisibleObjects(npc, L2Character.class, npc.getAggroRange())) + { + if (nearby.isPlayable() && (npc.calculateDirectionTo(nearby) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + { + final L2Summon summon = nearby.isSummon() ? ((L2Summon) nearby) : null; + final L2PcInstance cha = summon == null ? (L2PcInstance) nearby : summon.getOwner(); + final Castle castle = npc.getCastle(); + final Fort fortress = npc.getFort(); + final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); + if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) + { + if (!cha.isInvisible()) // skip invisible players + { + addAttackPlayerDesire(npc, cha); + } + } + } + } + } + startQuestTimer("AGGRO_CHECK", 2000, npc, null); + } + } + return super.onAdvEvent(event, npc, player); + } + @Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { @@ -112,31 +143,11 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } - @Override - public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon) - { - if (creature.isPlayable() && (npc.calculateDirectionTo(creature) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, creature)) - { - final L2Summon summon = isSummon ? creature.getServitors().values().stream().findFirst().orElse(creature.getPet()) : null; - final L2PcInstance cha = summon == null ? (L2PcInstance) creature : summon.getOwner(); - final Castle castle = npc.getCastle(); - final Fort fortress = npc.getFort(); - final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) - { - if (!cha.isInvisible()) // skip invisible players - { - addAttackPlayerDesire(npc, cha); - } - } - } - return super.onSeeCreature(npc, creature, isSummon); - } - @Override public String onSpawn(L2Npc npc) { npc.setRandomWalking(false); + startQuestTimer("AGGRO_CHECK", 2000, npc, null); 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 fb9007f8c8..b104a1ff86 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 @@ -18,6 +18,7 @@ package ai.others; import com.l2jmobius.gameserver.ai.CtrlIntention; import com.l2jmobius.gameserver.geoengine.GeoEngine; +import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.L2Attackable; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.L2Npc; @@ -88,16 +89,46 @@ public class SiegeGuards extends AbstractNpcAI addAttackId(FORT_GUARDS); addAttackId(MERCENARIES); addAttackId(STATIONARY_MERCENARIES); - addSeeCreatureId(CASTLE_GUARDS); - addSeeCreatureId(FORT_GUARDS); - addSeeCreatureId(MERCENARIES); - addSeeCreatureId(STATIONARY_MERCENARIES); addSpawnId(CASTLE_GUARDS); addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); } + @Override + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) + { + if (event.equals("AGGRO_CHECK")) + { + if ((npc != null) && !npc.isDead()) + { + if (!npc.isInCombat()) + { + for (L2Character nearby : L2World.getInstance().getVisibleObjects(npc, L2Character.class, npc.getAggroRange())) + { + if (nearby.isPlayable() && (npc.calculateDirectionTo(nearby) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + { + final L2Summon summon = nearby.isSummon() ? ((L2Summon) nearby) : null; + final L2PcInstance cha = summon == null ? (L2PcInstance) nearby : summon.getOwner(); + final Castle castle = npc.getCastle(); + final Fort fortress = npc.getFort(); + final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); + if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) + { + if (!cha.isInvisible()) // skip invisible players + { + addAttackPlayerDesire(npc, cha); + } + } + } + } + } + startQuestTimer("AGGRO_CHECK", 2000, npc, null); + } + } + return super.onAdvEvent(event, npc, player); + } + @Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { @@ -112,31 +143,11 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } - @Override - public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon) - { - if (creature.isPlayable() && (npc.calculateDirectionTo(creature) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, creature)) - { - final L2Summon summon = isSummon ? creature.getServitors().values().stream().findFirst().orElse(creature.getPet()) : null; - final L2PcInstance cha = summon == null ? (L2PcInstance) creature : summon.getOwner(); - final Castle castle = npc.getCastle(); - final Fort fortress = npc.getFort(); - final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) - { - if (!cha.isInvisible()) // skip invisible players - { - addAttackPlayerDesire(npc, cha); - } - } - } - return super.onSeeCreature(npc, creature, isSummon); - } - @Override public String onSpawn(L2Npc npc) { npc.setRandomWalking(false); + startQuestTimer("AGGRO_CHECK", 2000, npc, null); 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 fb9007f8c8..b104a1ff86 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 @@ -18,6 +18,7 @@ package ai.others; import com.l2jmobius.gameserver.ai.CtrlIntention; import com.l2jmobius.gameserver.geoengine.GeoEngine; +import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.L2Attackable; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.L2Npc; @@ -88,16 +89,46 @@ public class SiegeGuards extends AbstractNpcAI addAttackId(FORT_GUARDS); addAttackId(MERCENARIES); addAttackId(STATIONARY_MERCENARIES); - addSeeCreatureId(CASTLE_GUARDS); - addSeeCreatureId(FORT_GUARDS); - addSeeCreatureId(MERCENARIES); - addSeeCreatureId(STATIONARY_MERCENARIES); addSpawnId(CASTLE_GUARDS); addSpawnId(FORT_GUARDS); addSpawnId(MERCENARIES); addSpawnId(STATIONARY_MERCENARIES); } + @Override + public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) + { + if (event.equals("AGGRO_CHECK")) + { + if ((npc != null) && !npc.isDead()) + { + if (!npc.isInCombat()) + { + for (L2Character nearby : L2World.getInstance().getVisibleObjects(npc, L2Character.class, npc.getAggroRange())) + { + if (nearby.isPlayable() && (npc.calculateDirectionTo(nearby) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, nearby)) + { + final L2Summon summon = nearby.isSummon() ? ((L2Summon) nearby) : null; + final L2PcInstance cha = summon == null ? (L2PcInstance) nearby : summon.getOwner(); + final Castle castle = npc.getCastle(); + final Fort fortress = npc.getFort(); + final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); + if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) + { + if (!cha.isInvisible()) // skip invisible players + { + addAttackPlayerDesire(npc, cha); + } + } + } + } + } + startQuestTimer("AGGRO_CHECK", 2000, npc, null); + } + } + return super.onAdvEvent(event, npc, player); + } + @Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { @@ -112,31 +143,11 @@ public class SiegeGuards extends AbstractNpcAI return super.onAttack(npc, attacker, damage, isSummon); } - @Override - public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon) - { - if (creature.isPlayable() && (npc.calculateDirectionTo(creature) < npc.getAggroRange()) && GeoEngine.getInstance().canSeeTarget(npc, creature)) - { - final L2Summon summon = isSummon ? creature.getServitors().values().stream().findFirst().orElse(creature.getPet()) : null; - final L2PcInstance cha = summon == null ? (L2PcInstance) creature : summon.getOwner(); - final Castle castle = npc.getCastle(); - final Fort fortress = npc.getFort(); - final int activeSiegeId = (fortress != null ? fortress.getResidenceId() : (castle != null ? castle.getResidenceId() : 0)); - if ((((cha.getSiegeState() != 2) || cha.isRegisteredOnThisSiegeField(activeSiegeId)) && (cha.getSiegeState() != 0)) || (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)) - { - if (!cha.isInvisible()) // skip invisible players - { - addAttackPlayerDesire(npc, cha); - } - } - } - return super.onSeeCreature(npc, creature, isSummon); - } - @Override public String onSpawn(L2Npc npc) { npc.setRandomWalking(false); + startQuestTimer("AGGRO_CHECK", 2000, npc, null); return super.onSpawn(npc); }