Medson321

AntGuardPolymorphing.java

Apr 3rd, 2023
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | Source Code | 0 0
  1. package net.sf.l2j.gameserver.scripting.script.ai.group;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import net.sf.l2j.commons.random.Rnd;
  7.  
  8. import net.sf.l2j.gameserver.enums.ScriptEventType;
  9. import net.sf.l2j.gameserver.model.actor.Creature;
  10. import net.sf.l2j.gameserver.model.actor.Npc;
  11. import net.sf.l2j.gameserver.scripting.script.ai.AttackableAIScript;
  12. import net.sf.l2j.gameserver.skills.L2Skill;
  13.  
  14. public class AntGuardPolymorphing extends AttackableAIScript
  15. {
  16.     private static final Map<Integer, Integer[]> MOBSPAWNS = new HashMap<>();
  17.    
  18.     static
  19.     {
  20.         MOBSPAWNS.put(40000, new Integer[]
  21.         {
  22.             40001,
  23.             50,
  24.             100,
  25.             0
  26.         });
  27.         MOBSPAWNS.put(40001, new Integer[]
  28.         {
  29.             40002,
  30.             50,
  31.             100,
  32.             1
  33.         });
  34.         MOBSPAWNS.put(40002, new Integer[]
  35.         {
  36.             40003,
  37.             50,
  38.             100,
  39.             2
  40.         });
  41.     }
  42.    
  43.     private static final String[][] MOBTEXTS =
  44.     {
  45.         new String[]
  46.         {
  47.             "Don't think it will be that easy!"
  48.         },
  49.         new String[]
  50.         {
  51.             "Not bad.. but now you don't stand a chance!"
  52.         },
  53.         new String[]
  54.         {
  55.             "You're quite a fighter, but you're done!"
  56.         }
  57.     };
  58.    
  59.     public AntGuardPolymorphing()
  60.     {
  61.         super("ai/group");
  62.     }
  63.    
  64.     @Override
  65.     protected void registerNpcs()
  66.     {
  67.         addEventIds(MOBSPAWNS.keySet(), ScriptEventType.ON_ATTACK);
  68.     }
  69.    
  70.     @Override
  71.     public String onAttack(Npc npc, Creature attacker, int damage, L2Skill skill)
  72.     {
  73.         if (npc.isVisible() && !npc.isDead())
  74.         {
  75.             final Integer[] tmp = MOBSPAWNS.get(npc.getNpcId());
  76.             if (tmp != null)
  77.             {
  78.                 if (npc.getStatus().getHpRatio() * 100 <= tmp[1] && Rnd.get(100) < tmp[2])
  79.                 {
  80.                     if (tmp[3] >= 0)
  81.                         npc.broadcastNpcSay(Rnd.get(MOBTEXTS[tmp[3]]));
  82.                    
  83.                     final Npc newNpc = addSpawn(tmp[0], npc, false, 0, false);
  84.                     newNpc.forceAttack(attacker, 200);
  85.                    
  86.                     npc.deleteMe();
  87.                 }
  88.             }
  89.         }
  90.         return super.onAttack(npc, attacker, damage, skill);
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment