From 3d4b16292af015502951b3fefa804bc1812ed02a Mon Sep 17 00:00:00 2001 From: Zoey76 <zoey_76@msn.com> Date: Mon, 18 Jan 2016 02:14:09 -0300 Subject: [PATCH] Porta should keep aggro after teleporting the player, fixes #270 --- .../scripts/ai/group_template/SummonPc.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/dist/game/data/scripts/ai/group_template/SummonPc.java b/dist/game/data/scripts/ai/group_template/SummonPc.java index 57bd5cf21d..e4d893f383 100644 --- a/dist/game/data/scripts/ai/group_template/SummonPc.java +++ b/dist/game/data/scripts/ai/group_template/SummonPc.java @@ -18,14 +18,14 @@ */ package ai.group_template; -import ai.npc.AbstractNpcAI; - import com.l2jserver.gameserver.model.actor.L2Attackable; import com.l2jserver.gameserver.model.actor.L2Npc; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.model.holders.SkillHolder; import com.l2jserver.gameserver.model.skills.Skill; +import ai.npc.AbstractNpcAI; + /** * Summon Pc AI.<br> * Summon the player to the NPC on attack. @@ -38,6 +38,9 @@ public final class SummonPc extends AbstractNpcAI private static final int PERUM = 20221; // Skill private static final SkillHolder SUMMON_PC = new SkillHolder(4161, 1); + // Misc + private static final int MIN_DISTANCE = 300; + private static final int MIN_DISTANCE_MOST_HATED = 100; private SummonPc() { @@ -49,39 +52,29 @@ public final class SummonPc extends AbstractNpcAI @Override public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon) { - final int chance = getRandom(100); final boolean attacked = npc.getVariables().getBoolean("attacked", false); - if ((npc.calculateDistance(attacker, true, false) > 300) && !attacked) + if (attacked) + { + return super.onAttack(npc, attacker, damage, isSummon); + } + + final int chance = getRandom(100); + final double distance = npc.calculateDistance(attacker, true, false); + if (distance > MIN_DISTANCE) { if (chance < 50) { - if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill())) - { - npc.setTarget(attacker); - npc.doCast(SUMMON_PC.getSkill()); - } - - if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill())) - { - npc.setTarget(attacker); - npc.doCast(SUMMON_PC.getSkill()); - npc.getVariables().set("attacked", true); - } + doSummonPc(npc, attacker); } } - else if ((npc.calculateDistance(attacker, true, false) > 100) && !attacked) + else if (distance > MIN_DISTANCE_MOST_HATED) { final L2Attackable monster = (L2Attackable) npc; if (monster.getMostHated() != null) { if (((monster.getMostHated() == attacker) && (chance < 50)) || (chance < 10)) { - if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill())) - { - npc.setTarget(attacker); - npc.doCast(SUMMON_PC.getSkill()); - npc.getVariables().set("attacked", true); - } + doSummonPc(npc, attacker); } } } @@ -95,10 +88,23 @@ public final class SummonPc extends AbstractNpcAI { player.teleToLocation(npc); npc.getVariables().set("attacked", false); + + // TODO(Zoey76): Teleport removes the player from all known lists, affecting aggro lists. + addAttackPlayerDesire(npc, player); } return super.onSpellFinished(npc, player, skill); } + private static void doSummonPc(L2Npc npc, L2PcInstance attacker) + { + if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill())) + { + npc.setTarget(attacker); + npc.doCast(SUMMON_PC.getSkill()); + npc.getVariables().set("attacked", true); + } + } + public static void main(String[] args) { new SummonPc(); -- GitLab