PolymorphingOnAttack.java 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package ai.group_template;
  16. import gnu.trove.TIntObjectHashMap;
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.model.actor.L2Attackable;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.clientpackets.Say2;
  23. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  24. import com.l2jserver.util.Rnd;
  25. /**
  26. * @author Slyce
  27. */
  28. public class PolymorphingOnAttack extends L2AttackableAIScript
  29. {
  30. private static final TIntObjectHashMap<Integer[]> MOBSPAWNS = new TIntObjectHashMap<Integer[]>();
  31. static
  32. {
  33. MOBSPAWNS.put(21258,new Integer[]{21259,100,100,-1}); //Fallen Orc Shaman -> Sharp Talon Tiger (always polymorphs)
  34. MOBSPAWNS.put(21261,new Integer[]{21262,100,20 ,0}); //Ol Mahum Transcender 1st stage
  35. MOBSPAWNS.put(21262,new Integer[]{21263,100,10 ,1}); //Ol Mahum Transcender 2nd stage
  36. MOBSPAWNS.put(21263,new Integer[]{21264,100,5 ,2}); //Ol Mahum Transcender 3rd stage
  37. MOBSPAWNS.put(21265,new Integer[]{21271,100,33 ,0}); //Cave Ant Larva -> Cave Ant
  38. MOBSPAWNS.put(21266,new Integer[]{21269,100,100,-1}); //Cave Ant Larva -> Cave Ant (always polymorphs)
  39. MOBSPAWNS.put(21267,new Integer[]{21270,100,100,-1}); //Cave Ant Larva -> Cave Ant Soldier (always polymorphs)
  40. MOBSPAWNS.put(21271,new Integer[]{21272,66,10 ,1}); //Cave Ant -> Cave Ant Soldier
  41. MOBSPAWNS.put(21272,new Integer[]{21273,33 ,5 ,2}); //Cave Ant Soldier -> Cave Noble Ant
  42. MOBSPAWNS.put(21521,new Integer[]{21522,100,30 ,-1}); //Claws of Splendor
  43. MOBSPAWNS.put(21527,new Integer[]{21528,100,30 ,-1}); //Anger of Splendor
  44. MOBSPAWNS.put(21533,new Integer[]{21534,100,30 ,-1}); //Alliance of Splendor
  45. MOBSPAWNS.put(21537,new Integer[]{21538,100,30 ,-1}); //Fang of Splendor
  46. }
  47. protected static final String[][] MOBTEXTS =
  48. {
  49. new String[]{"Enough fooling around. Get ready to die!", "You idiot! I've just been toying with you!", "Now the fun starts!"},
  50. new String[]{"I must admit, no one makes my blood boil quite like you do!", "Now the battle begins!", "Witness my true power!"},
  51. new String[]{"Prepare to die!", "I'll double my strength!", "You have more skill than I thought"}
  52. };
  53. public PolymorphingOnAttack(int questId, String name, String descr)
  54. {
  55. super(questId, name, descr);
  56. for (int id : MOBSPAWNS.keys())
  57. super.addAttackId(id);
  58. }
  59. @Override
  60. public String onAttack (L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  61. {
  62. if (npc.isVisible() && !npc.isDead())
  63. {
  64. final Integer[] tmp = MOBSPAWNS.get(npc.getNpcId());
  65. if (tmp != null)
  66. {
  67. if (npc.getCurrentHp() <= (npc.getMaxHp() * tmp[1]/100.0)&& Rnd.get(100) < tmp[2])
  68. {
  69. if (tmp[3] >= 0)
  70. {
  71. String text = MOBTEXTS[tmp[3]][Rnd.get(MOBTEXTS[tmp[3]].length)];
  72. npc.broadcastPacket(new CreatureSay(npc.getObjectId(),Say2.ALL,npc.getName(),text));
  73. }
  74. npc.deleteMe();
  75. L2Attackable newNpc = (L2Attackable) addSpawn(tmp[0], npc.getX(), npc.getY(), npc.getZ()+10, npc.getHeading(), false, 0, true);
  76. L2Character originalAttacker = isPet? attacker.getPet(): attacker;
  77. newNpc.setRunning();
  78. newNpc.addDamageHate(originalAttacker,0,500);
  79. newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, originalAttacker);
  80. }
  81. }
  82. }
  83. return super.onAttack (npc, attacker, damage, isPet);
  84. }
  85. public static void main(String[] args)
  86. {
  87. new PolymorphingOnAttack(-1,"polymorphing_on_attack","ai");
  88. }
  89. }