SummonPc.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package ai.group_template;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.model.actor.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.holders.SkillHolder;
  25. import com.l2jserver.gameserver.model.skills.Skill;
  26. /**
  27. * Summon Pc AI.<br>
  28. * Summon the player to the NPC on attack.
  29. * @author Zoey76
  30. */
  31. public final class SummonPc extends AbstractNpcAI
  32. {
  33. // NPCs
  34. private static final int PORTA = 20213;
  35. private static final int PERUM = 20221;
  36. // Skill
  37. private static final SkillHolder SUMMON_PC = new SkillHolder(4161, 1);
  38. private SummonPc()
  39. {
  40. super(SummonPc.class.getSimpleName(), "ai/group_template");
  41. addAttackId(PORTA, PERUM);
  42. addSpellFinishedId(PORTA, PERUM);
  43. }
  44. @Override
  45. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  46. {
  47. final int chance = getRandom(100);
  48. final boolean attacked = npc.getVariables().getBoolean("attacked", false);
  49. if ((npc.calculateDistance(attacker, true, false) > 300) && !attacked)
  50. {
  51. if (chance < 50)
  52. {
  53. if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill()))
  54. {
  55. npc.setTarget(attacker);
  56. npc.doCast(SUMMON_PC.getSkill());
  57. }
  58. if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill()))
  59. {
  60. npc.setTarget(attacker);
  61. npc.doCast(SUMMON_PC.getSkill());
  62. npc.getVariables().set("attacked", true);
  63. }
  64. }
  65. }
  66. else if ((npc.calculateDistance(attacker, true, false) > 100) && !attacked)
  67. {
  68. final L2Attackable monster = (L2Attackable) npc;
  69. if (monster.getMostHated() != null)
  70. {
  71. if (((monster.getMostHated() == attacker) && (chance < 50)) || (chance < 10))
  72. {
  73. if ((SUMMON_PC.getSkill().getMpConsume() < npc.getCurrentMp()) && (SUMMON_PC.getSkill().getHpConsume() < npc.getCurrentHp()) && !npc.isSkillDisabled(SUMMON_PC.getSkill()))
  74. {
  75. npc.setTarget(attacker);
  76. npc.doCast(SUMMON_PC.getSkill());
  77. npc.getVariables().set("attacked", true);
  78. }
  79. }
  80. }
  81. }
  82. return super.onAttack(npc, attacker, damage, isSummon);
  83. }
  84. @Override
  85. public String onSpellFinished(L2Npc npc, L2PcInstance player, Skill skill)
  86. {
  87. if ((skill.getId() == SUMMON_PC.getSkillId()) && !npc.isDead() && npc.getVariables().getBoolean("attacked", false))
  88. {
  89. player.teleToLocation(npc);
  90. npc.getVariables().set("attacked", false);
  91. }
  92. return super.onSpellFinished(npc, player, skill);
  93. }
  94. public static void main(String[] args)
  95. {
  96. new SummonPc();
  97. }
  98. }