Menadel

Zaken aCis 382

Jan 19th, 2022 (edited)
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.17 KB | None | 0 0
  1. package net.sf.l2j.gameserver.scripting.scripts.ai.individual;
  2.  
  3. import java.util.Set;
  4. import java.util.concurrent.ConcurrentHashMap;
  5.  
  6. import net.sf.l2j.commons.random.Rnd;
  7. import net.sf.l2j.commons.util.StatsSet;
  8.  
  9. import net.sf.l2j.Config;
  10. import net.sf.l2j.gameserver.data.SkillTable.FrequentSkill;
  11. import net.sf.l2j.gameserver.data.manager.GrandBossManager;
  12. import net.sf.l2j.gameserver.data.manager.ZoneManager;
  13. import net.sf.l2j.gameserver.data.xml.DoorData;
  14. import net.sf.l2j.gameserver.enums.IntentionType;
  15. import net.sf.l2j.gameserver.model.L2Skill;
  16. import net.sf.l2j.gameserver.model.World;
  17. import net.sf.l2j.gameserver.model.WorldObject;
  18. import net.sf.l2j.gameserver.model.actor.Attackable;
  19. import net.sf.l2j.gameserver.model.actor.Creature;
  20. import net.sf.l2j.gameserver.model.actor.Npc;
  21. import net.sf.l2j.gameserver.model.actor.Playable;
  22. import net.sf.l2j.gameserver.model.actor.Player;
  23. import net.sf.l2j.gameserver.model.actor.instance.Door;
  24. import net.sf.l2j.gameserver.model.actor.instance.GrandBoss;
  25. import net.sf.l2j.gameserver.model.location.Location;
  26. import net.sf.l2j.gameserver.model.zone.type.BossZone;
  27. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  28. import net.sf.l2j.gameserver.scripting.scripts.ai.L2AttackableAIScript;
  29. import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
  30.  
  31. public class Zaken extends L2AttackableAIScript
  32. {
  33.     private static final BossZone ZONE = ZoneManager.getInstance().getZoneById(110000, BossZone.class);
  34.     private static final Set<Player> VICTIMS = ConcurrentHashMap.newKeySet();
  35.    
  36.     private static final Location[] LOCS =
  37.     {
  38.         new Location(53950, 219860, -3488),
  39.         new Location(55980, 219820, -3488),
  40.         new Location(54950, 218790, -3488),
  41.         new Location(55970, 217770, -3488),
  42.         new Location(53930, 217760, -3488),
  43.        
  44.         new Location(55970, 217770, -3216),
  45.         new Location(55980, 219920, -3216),
  46.         new Location(54960, 218790, -3216),
  47.         new Location(53950, 219860, -3216),
  48.         new Location(53930, 217760, -3216),
  49.        
  50.         new Location(55970, 217770, -2944),
  51.         new Location(55980, 219920, -2944),
  52.         new Location(54960, 218790, -2944),
  53.         new Location(53950, 219860, -2944),
  54.         new Location(53930, 217760, -2944)
  55.     };
  56.    
  57.     private static final int ZAKEN = 29022;
  58.     private static final int DOLL_BLADER = 29023;
  59.     private static final int VALE_MASTER = 29024;
  60.     private static final int PIRATE_CAPTAIN = 29026;
  61.     private static final int PIRATE_ZOMBIE = 29027;
  62.    
  63.     private static final byte ALIVE = 0;
  64.     private static final byte DEAD = 1;
  65.    
  66.     private final Location _zakenLocation = new Location(0, 0, 0);
  67.    
  68.     private int _teleportCheck;
  69.     private int _minionStatus;
  70.     private int _hate;
  71.    
  72.     private boolean _hasTeleported;
  73.    
  74.     private Creature _mostHated;
  75.    
  76.     public Zaken()
  77.     {
  78.         super("ai/individual");
  79.        
  80.         final StatsSet info = GrandBossManager.getInstance().getStatsSet(ZAKEN);
  81.        
  82.         // Zaken is dead, calculate the respawn time. If passed, we spawn it directly, otherwise we set a task to spawn it lately.
  83.         if (GrandBossManager.getInstance().getBossStatus(ZAKEN) == DEAD)
  84.         {
  85.             final long temp = info.getLong("respawn_time") - System.currentTimeMillis();
  86.             if (temp > 0)
  87.                 startQuestTimer("zaken_unlock", temp, null, null, false);
  88.             else
  89.                 spawnBoss(true);
  90.         }
  91.         // Zaken is alive, spawn it using stored data.
  92.         else
  93.             spawnBoss(false);
  94.     }
  95.    
  96.     @Override
  97.     protected void registerNpcs()
  98.     {
  99.         addAggroRangeEnterId(ZAKEN, DOLL_BLADER, VALE_MASTER, PIRATE_CAPTAIN, PIRATE_ZOMBIE);
  100.         addAttackId(ZAKEN);
  101.         addFactionCallId(DOLL_BLADER, VALE_MASTER, PIRATE_CAPTAIN, PIRATE_ZOMBIE);
  102.         addKillId(ZAKEN, DOLL_BLADER, VALE_MASTER, PIRATE_CAPTAIN, PIRATE_ZOMBIE);
  103.         addSkillSeeId(ZAKEN);
  104.         addSpellFinishedId(ZAKEN);
  105.        
  106.         addGameTimeNotify();
  107.     }
  108.    
  109.     @Override
  110.     public String onAdvEvent(String event, Npc npc, Player player)
  111.     {
  112.         if (GrandBossManager.getInstance().getBossStatus(ZAKEN) == DEAD && !event.equalsIgnoreCase("zaken_unlock"))
  113.             return super.onAdvEvent(event, npc, player);
  114.        
  115.         if (event.equalsIgnoreCase("1001"))
  116.         {
  117.             if (GameTimeTaskManager.getInstance().isNight())
  118.             {
  119.                 L2Skill skill = FrequentSkill.ZAKEN_DAY_TO_NIGHT.getSkill();
  120.                 if (npc.getFirstEffect(skill) == null)
  121.                 {
  122.                     // Add effect "Day to Night" if not found.
  123.                     skill.getEffects(npc, npc);
  124.                    
  125.                     // Refresh stored Zaken location.
  126.                     _zakenLocation.set(npc.getPosition());
  127.                 }
  128.                
  129.                 // Add Night regen if not found.
  130.                 skill = FrequentSkill.ZAKEN_REGEN_NIGHT.getSkill();
  131.                 if (npc.getFirstEffect(skill) == null)
  132.                     skill.getEffects(npc, npc);
  133.                
  134.                 final Creature mostHated = ((Attackable) npc).getMostHated();
  135.                
  136.                 // Under attack stance, but didn't yet teleported. Check most hated and current victims distance.
  137.                 if (npc.getAI().getDesire().getIntention() == IntentionType.ATTACK && !_hasTeleported)
  138.                 {
  139.                     boolean willTeleport = true;
  140.                    
  141.                     // Check most hated distance. If distance is low, Zaken doesn't teleport.
  142.                     if (mostHated != null && mostHated.isInsideRadius(_zakenLocation, 1500, true, false))
  143.                         willTeleport = false;
  144.                    
  145.                     // We're still under willTeleport possibility. Now we check each victim distance. If at least one is near Zaken, we cancel the teleport possibility.
  146.                     if (willTeleport)
  147.                     {
  148.                         for (Player ply : VICTIMS)
  149.                         {
  150.                             if (ply.isInsideRadius(_zakenLocation, 1500, true, false))
  151.                             {
  152.                                 willTeleport = false;
  153.                                 continue;
  154.                             }
  155.                         }
  156.                     }
  157.                    
  158.                     // All targets are far, clear victims list and Zaken teleport.
  159.                     if (willTeleport)
  160.                     {
  161.                         VICTIMS.clear();
  162.                         npc.doCast(FrequentSkill.ZAKEN_SELF_TELE.getSkill());
  163.                     }
  164.                 }
  165.                
  166.                 // Potentially refresh the stored location.
  167.                 if (Rnd.get(20) < 1 && !_hasTeleported)
  168.                     _zakenLocation.set(npc.getPosition());
  169.                
  170.                 // Process to cleanup hate from most hated upon 5 straight AI loops.
  171.                 if (npc.getAI().getDesire().getIntention() == IntentionType.ATTACK && mostHated != null)
  172.                 {
  173.                     if (_hate == 0)
  174.                     {
  175.                         _mostHated = mostHated;
  176.                         _hate = 1;
  177.                     }
  178.                     else
  179.                     {
  180.                         if (_mostHated == mostHated)
  181.                             _hate++;
  182.                         else
  183.                         {
  184.                             _hate = 1;
  185.                             _mostHated = mostHated;
  186.                         }
  187.                     }
  188.                 }
  189.                
  190.                 // Cleanup build hate towards Intention IDLE.
  191.                 if (npc.getAI().getDesire().getIntention() == IntentionType.IDLE)
  192.                     _hate = 0;
  193.                
  194.                 // We built enough hate ; release the current most hated target, reset the hate counter.
  195.                 if (_hate > 5)
  196.                 {
  197.                     ((Attackable) npc).stopHating(_mostHated);
  198.                    
  199.                     _hate = 0;
  200.                 }
  201.             }
  202.             else
  203.             {
  204.                 L2Skill skill = FrequentSkill.ZAKEN_NIGHT_TO_DAY.getSkill();
  205.                 if (npc.getFirstEffect(skill) == null)
  206.                 {
  207.                     // Add effect "Night to Day" if not found.
  208.                     skill.getEffects(npc, npc);
  209.                    
  210.                     _teleportCheck = 3;
  211.                 }
  212.                
  213.                 // Add Day regen if not found.
  214.                 skill = FrequentSkill.ZAKEN_REGEN_DAY.getSkill();
  215.                 if (npc.getFirstEffect(skill) == null)
  216.                     skill.getEffects(npc, npc);
  217.             }
  218.            
  219.             if (Rnd.get(40) < 1)
  220.                 npc.doCast(FrequentSkill.ZAKEN_SELF_TELE.getSkill());
  221.            
  222.             startQuestTimer("1001", 30000, npc, null, false);
  223.         }
  224.         else if (event.equalsIgnoreCase("1002"))
  225.         {
  226.             // Clear victims list.
  227.             VICTIMS.clear();
  228.            
  229.             // Teleport Zaken.
  230.             npc.doCast(FrequentSkill.ZAKEN_SELF_TELE.getSkill());
  231.            
  232.             // Flag the teleport as false.
  233.             _hasTeleported = false;
  234.         }
  235.         else if (event.equalsIgnoreCase("1003"))
  236.         {
  237.             if (_minionStatus == 1)
  238.             {
  239.                 spawnMinionOnEveryLocation(PIRATE_CAPTAIN, 1);
  240.                
  241.                 // Pass to the next spawn cycle.
  242.                 _minionStatus = 2;
  243.             }
  244.             else if (_minionStatus == 2)
  245.             {
  246.                 spawnMinionOnEveryLocation(DOLL_BLADER, 1);
  247.                
  248.                 // Pass to the next spawn cycle.
  249.                 _minionStatus = 3;
  250.             }
  251.             else if (_minionStatus == 3)
  252.             {
  253.                 spawnMinionOnEveryLocation(VALE_MASTER, 2);
  254.                
  255.                 // Pass to the next spawn cycle.
  256.                 _minionStatus = 4;
  257.             }
  258.             else if (_minionStatus == 4)
  259.             {
  260.                 spawnMinionOnEveryLocation(PIRATE_ZOMBIE, 5);
  261.                
  262.                 // Pass to the next spawn cycle.
  263.                 _minionStatus = 5;
  264.             }
  265.             else if (_minionStatus == 5)
  266.             {
  267.                 addSpawn(DOLL_BLADER, 52675, 219371, -3290, Rnd.get(65536), false, 0, true);
  268.                 addSpawn(DOLL_BLADER, 52687, 219596, -3368, Rnd.get(65536), false, 0, true);
  269.                 addSpawn(DOLL_BLADER, 52672, 219740, -3418, Rnd.get(65536), false, 0, true);
  270.                 addSpawn(PIRATE_ZOMBIE, 52857, 219992, -3488, Rnd.get(65536), false, 0, true);
  271.                 addSpawn(PIRATE_CAPTAIN, 52959, 219997, -3488, Rnd.get(65536), false, 0, true);
  272.                 addSpawn(VALE_MASTER, 53381, 220151, -3488, Rnd.get(65536), false, 0, true);
  273.                 addSpawn(PIRATE_CAPTAIN, 54236, 220948, -3488, Rnd.get(65536), false, 0, true);
  274.                 addSpawn(PIRATE_ZOMBIE, 54885, 220144, -3488, Rnd.get(65536), false, 0, true);
  275.                 addSpawn(PIRATE_ZOMBIE, 55264, 219860, -3488, Rnd.get(65536), false, 0, true);
  276.                 addSpawn(PIRATE_CAPTAIN, 55399, 220263, -3488, Rnd.get(65536), false, 0, true);
  277.                 addSpawn(PIRATE_ZOMBIE, 55679, 220129, -3488, Rnd.get(65536), false, 0, true);
  278.                 addSpawn(VALE_MASTER, 56276, 220783, -3488, Rnd.get(65536), false, 0, true);
  279.                 addSpawn(VALE_MASTER, 57173, 220234, -3488, Rnd.get(65536), false, 0, true);
  280.                 addSpawn(PIRATE_ZOMBIE, 56267, 218826, -3488, Rnd.get(65536), false, 0, true);
  281.                 addSpawn(DOLL_BLADER, 56294, 219482, -3488, Rnd.get(65536), false, 0, true);
  282.                 addSpawn(PIRATE_CAPTAIN, 56094, 219113, -3488, Rnd.get(65536), false, 0, true);
  283.                 addSpawn(DOLL_BLADER, 56364, 218967, -3488, Rnd.get(65536), false, 0, true);
  284.                 addSpawn(PIRATE_ZOMBIE, 57113, 218079, -3488, Rnd.get(65536), false, 0, true);
  285.                 addSpawn(DOLL_BLADER, 56186, 217153, -3488, Rnd.get(65536), false, 0, true);
  286.                 addSpawn(PIRATE_ZOMBIE, 55440, 218081, -3488, Rnd.get(65536), false, 0, true);
  287.                 addSpawn(PIRATE_CAPTAIN, 55202, 217940, -3488, Rnd.get(65536), false, 0, true);
  288.                 addSpawn(PIRATE_ZOMBIE, 55225, 218236, -3488, Rnd.get(65536), false, 0, true);
  289.                 addSpawn(PIRATE_ZOMBIE, 54973, 218075, -3488, Rnd.get(65536), false, 0, true);
  290.                 addSpawn(PIRATE_CAPTAIN, 53412, 218077, -3488, Rnd.get(65536), false, 0, true);
  291.                 addSpawn(VALE_MASTER, 54226, 218797, -3488, Rnd.get(65536), false, 0, true);
  292.                 addSpawn(VALE_MASTER, 54394, 219067, -3488, Rnd.get(65536), false, 0, true);
  293.                 addSpawn(PIRATE_ZOMBIE, 54139, 219253, -3488, Rnd.get(65536), false, 0, true);
  294.                 addSpawn(DOLL_BLADER, 54262, 219480, -3488, Rnd.get(65536), false, 0, true);
  295.                
  296.                 // Pass to the next spawn cycle.
  297.                 _minionStatus = 6;
  298.             }
  299.             else if (_minionStatus == 6)
  300.             {
  301.                 addSpawn(PIRATE_ZOMBIE, 53412, 218077, -3488, Rnd.get(65536), false, 0, true);
  302.                 addSpawn(VALE_MASTER, 54413, 217132, -3488, Rnd.get(65536), false, 0, true);
  303.                 addSpawn(DOLL_BLADER, 54841, 217132, -3488, Rnd.get(65536), false, 0, true);
  304.                 addSpawn(DOLL_BLADER, 55372, 217128, -3343, Rnd.get(65536), false, 0, true);
  305.                 addSpawn(DOLL_BLADER, 55893, 217122, -3488, Rnd.get(65536), false, 0, true);
  306.                 addSpawn(PIRATE_CAPTAIN, 56282, 217237, -3216, Rnd.get(65536), false, 0, true);
  307.                 addSpawn(VALE_MASTER, 56963, 218080, -3216, Rnd.get(65536), false, 0, true);
  308.                 addSpawn(PIRATE_ZOMBIE, 56267, 218826, -3216, Rnd.get(65536), false, 0, true);
  309.                 addSpawn(DOLL_BLADER, 56294, 219482, -3216, Rnd.get(65536), false, 0, true);
  310.                 addSpawn(PIRATE_CAPTAIN, 56094, 219113, -3216, Rnd.get(65536), false, 0, true);
  311.                 addSpawn(DOLL_BLADER, 56364, 218967, -3216, Rnd.get(65536), false, 0, true);
  312.                 addSpawn(VALE_MASTER, 56276, 220783, -3216, Rnd.get(65536), false, 0, true);
  313.                 addSpawn(VALE_MASTER, 57173, 220234, -3216, Rnd.get(65536), false, 0, true);
  314.                 addSpawn(PIRATE_ZOMBIE, 54885, 220144, -3216, Rnd.get(65536), false, 0, true);
  315.                 addSpawn(PIRATE_ZOMBIE, 55264, 219860, -3216, Rnd.get(65536), false, 0, true);
  316.                 addSpawn(PIRATE_CAPTAIN, 55399, 220263, -3216, Rnd.get(65536), false, 0, true);
  317.                 addSpawn(PIRATE_ZOMBIE, 55679, 220129, -3216, Rnd.get(65536), false, 0, true);
  318.                 addSpawn(PIRATE_CAPTAIN, 54236, 220948, -3216, Rnd.get(65536), false, 0, true);
  319.                 addSpawn(PIRATE_CAPTAIN, 54464, 219095, -3216, Rnd.get(65536), false, 0, true);
  320.                 addSpawn(VALE_MASTER, 54226, 218797, -3216, Rnd.get(65536), false, 0, true);
  321.                 addSpawn(VALE_MASTER, 54394, 219067, -3216, Rnd.get(65536), false, 0, true);
  322.                 addSpawn(PIRATE_ZOMBIE, 54139, 219253, -3216, Rnd.get(65536), false, 0, true);
  323.                 addSpawn(DOLL_BLADER, 54262, 219480, -3216, Rnd.get(65536), false, 0, true);
  324.                 addSpawn(PIRATE_CAPTAIN, 53412, 218077, -3216, Rnd.get(65536), false, 0, true);
  325.                 addSpawn(PIRATE_ZOMBIE, 55440, 218081, -3216, Rnd.get(65536), false, 0, true);
  326.                 addSpawn(PIRATE_CAPTAIN, 55202, 217940, -3216, Rnd.get(65536), false, 0, true);
  327.                 addSpawn(PIRATE_ZOMBIE, 55225, 218236, -3216, Rnd.get(65536), false, 0, true);
  328.                 addSpawn(PIRATE_ZOMBIE, 54973, 218075, -3216, Rnd.get(65536), false, 0, true);
  329.                
  330.                 // Pass to the next spawn cycle.
  331.                 _minionStatus = 7;
  332.             }
  333.             else if (_minionStatus == 7)
  334.             {
  335.                 addSpawn(PIRATE_ZOMBIE, 54228, 217504, -3216, Rnd.get(65536), false, 0, true);
  336.                 addSpawn(VALE_MASTER, 54181, 217168, -3216, Rnd.get(65536), false, 0, true);
  337.                 addSpawn(DOLL_BLADER, 54714, 217123, -3168, Rnd.get(65536), false, 0, true);
  338.                 addSpawn(DOLL_BLADER, 55298, 217127, -3073, Rnd.get(65536), false, 0, true);
  339.                 addSpawn(DOLL_BLADER, 55787, 217130, -2993, Rnd.get(65536), false, 0, true);
  340.                 addSpawn(PIRATE_CAPTAIN, 56284, 217216, -2944, Rnd.get(65536), false, 0, true);
  341.                 addSpawn(VALE_MASTER, 56963, 218080, -2944, Rnd.get(65536), false, 0, true);
  342.                 addSpawn(PIRATE_ZOMBIE, 56267, 218826, -2944, Rnd.get(65536), false, 0, true);
  343.                 addSpawn(DOLL_BLADER, 56294, 219482, -2944, Rnd.get(65536), false, 0, true);
  344.                 addSpawn(PIRATE_CAPTAIN, 56094, 219113, -2944, Rnd.get(65536), false, 0, true);
  345.                 addSpawn(DOLL_BLADER, 56364, 218967, -2944, Rnd.get(65536), false, 0, true);
  346.                 addSpawn(VALE_MASTER, 56276, 220783, -2944, Rnd.get(65536), false, 0, true);
  347.                 addSpawn(VALE_MASTER, 57173, 220234, -2944, Rnd.get(65536), false, 0, true);
  348.                 addSpawn(PIRATE_ZOMBIE, 54885, 220144, -2944, Rnd.get(65536), false, 0, true);
  349.                 addSpawn(PIRATE_ZOMBIE, 55264, 219860, -2944, Rnd.get(65536), false, 0, true);
  350.                 addSpawn(PIRATE_CAPTAIN, 55399, 220263, -2944, Rnd.get(65536), false, 0, true);
  351.                 addSpawn(PIRATE_ZOMBIE, 55679, 220129, -2944, Rnd.get(65536), false, 0, true);
  352.                 addSpawn(PIRATE_CAPTAIN, 54236, 220948, -2944, Rnd.get(65536), false, 0, true);
  353.                 addSpawn(PIRATE_CAPTAIN, 54464, 219095, -2944, Rnd.get(65536), false, 0, true);
  354.                 addSpawn(VALE_MASTER, 54226, 218797, -2944, Rnd.get(65536), false, 0, true);
  355.                 addSpawn(VALE_MASTER, 54394, 219067, -2944, Rnd.get(65536), false, 0, true);
  356.                 addSpawn(PIRATE_ZOMBIE, 54139, 219253, -2944, Rnd.get(65536), false, 0, true);
  357.                 addSpawn(DOLL_BLADER, 54262, 219480, -2944, Rnd.get(65536), false, 0, true);
  358.                 addSpawn(PIRATE_CAPTAIN, 53412, 218077, -2944, Rnd.get(65536), false, 0, true);
  359.                 addSpawn(PIRATE_CAPTAIN, 54280, 217200, -2944, Rnd.get(65536), false, 0, true);
  360.                 addSpawn(PIRATE_ZOMBIE, 55440, 218081, -2944, Rnd.get(65536), false, 0, true);
  361.                 addSpawn(PIRATE_CAPTAIN, 55202, 217940, -2944, Rnd.get(65536), false, 0, true);
  362.                 addSpawn(PIRATE_ZOMBIE, 55225, 218236, -2944, Rnd.get(65536), false, 0, true);
  363.                 addSpawn(PIRATE_ZOMBIE, 54973, 218075, -2944, Rnd.get(65536), false, 0, true);
  364.                
  365.                 cancelQuestTimer("1003", null, null);
  366.             }
  367.         }
  368.         else if (event.equalsIgnoreCase("zaken_unlock"))
  369.         {
  370.             // Spawn the boss.
  371.             spawnBoss(true);
  372.         }
  373.         else if (event.equalsIgnoreCase("CreateOnePrivateEx"))
  374.             addSpawn(npc.getNpcId(), npc.getX(), npc.getY(), npc.getZ(), Rnd.get(65535), false, 0, true);
  375.        
  376.         return super.onAdvEvent(event, npc, player);
  377.     }
  378.    
  379.     @Override
  380.     public String onAggro(Npc npc, Player player, boolean isPet)
  381.     {
  382.         final Playable realBypasser = (isPet && player.getSummon() != null) ? player.getSummon() : player;
  383.        
  384.         if (ZONE.isInsideZone(npc))
  385.             ((Attackable) npc).addDamageHate(realBypasser, 1, 200);
  386.        
  387.         if (npc.getNpcId() == ZAKEN)
  388.         {
  389.             // Feed victims list, but only if not already full.
  390.             if (Rnd.get(3) < 1 && VICTIMS.size() < 5)
  391.                 VICTIMS.add(player);
  392.            
  393.             // Cast a skill.
  394.             if (Rnd.get(15) < 1)
  395.                 callSkills(npc, realBypasser);
  396.         }
  397.         else if (testCursesOnAggro(npc, realBypasser))
  398.             return null;
  399.        
  400.         return super.onAggro(npc, player, isPet);
  401.     }
  402.    
  403.     @Override
  404.     public String onAttack(Npc npc, Creature attacker, int damage, L2Skill skill)
  405.     {
  406.         // Curses
  407.         if (attacker instanceof Playable && testCursesOnAttack(npc, attacker))
  408.             return null;
  409.        
  410.         if (Rnd.get(10) < 1)
  411.             callSkills(npc, attacker);
  412.        
  413.         if (!GameTimeTaskManager.getInstance().isNight() && (npc.getCurrentHp() < (npc.getMaxHp() * _teleportCheck) / 4))
  414.         {
  415.             _teleportCheck -= 1;
  416.             npc.doCast(FrequentSkill.ZAKEN_SELF_TELE.getSkill());
  417.         }
  418.         return super.onAttack(npc, attacker, damage, skill);
  419.     }
  420.    
  421.     @Override
  422.     public String onFactionCall(Npc npc, Npc caller, Player attacker, boolean isPet)
  423.     {
  424.         if (caller.getNpcId() == ZAKEN && GameTimeTaskManager.getInstance().isNight())
  425.         {
  426.             if (npc.getAI().getDesire().getIntention() == IntentionType.IDLE && !_hasTeleported && caller.getCurrentHp() < (0.9 * caller.getMaxHp()) && Rnd.get(450) < 1)
  427.             {
  428.                 // Set the teleport flag as true.
  429.                 _hasTeleported = true;
  430.                
  431.                 // Edit Zaken stored location.
  432.                 _zakenLocation.set(npc.getPosition());
  433.                
  434.                 // Run the 1002 timer.
  435.                 startQuestTimer("1002", 300, caller, null, false);
  436.             }
  437.         }
  438.         return super.onFactionCall(npc, caller, attacker, isPet);
  439.     }
  440.    
  441.     @Override
  442.     public String onKill(Npc npc, Creature killer)
  443.     {
  444.         if (npc.getNpcId() == ZAKEN)
  445.         {
  446.             // Broadcast death sound.
  447.             npc.broadcastPacket(new PlaySound(1, "BS02_D", npc));
  448.            
  449.             // Flag Zaken as dead.
  450.             GrandBossManager.getInstance().setBossStatus(ZAKEN, DEAD);
  451.            
  452.             // Calculate the next respawn time.
  453.             final long respawnTime = (long) (Config.SPAWN_INTERVAL_ZAKEN + Rnd.get(-Config.RANDOM_SPAWN_TIME_ZAKEN, Config.RANDOM_SPAWN_TIME_ZAKEN)) * 3600000;
  454.            
  455.             // Cancel tasks.
  456.             cancelQuestTimer("1001", npc, null);
  457.             cancelQuestTimer("1003", null, null);
  458.            
  459.             // Start respawn timer.
  460.             startQuestTimer("zaken_unlock", respawnTime, null, null, false);
  461.            
  462.             // Save the respawn time so that the info is maintained past reboots
  463.             final StatsSet info = GrandBossManager.getInstance().getStatsSet(ZAKEN);
  464.             info.set("respawn_time", System.currentTimeMillis() + respawnTime);
  465.             GrandBossManager.getInstance().setStatsSet(ZAKEN, info);
  466.         }
  467.         else if (GrandBossManager.getInstance().getBossStatus(ZAKEN) == ALIVE)
  468.             startQuestTimer("CreateOnePrivateEx", ((30 + Rnd.get(60)) * 1000), npc, null, false);
  469.        
  470.         return super.onKill(npc, killer);
  471.     }
  472.    
  473.     @Override
  474.     public String onSkillSee(Npc npc, Player caster, L2Skill skill, WorldObject[] targets, boolean isPet)
  475.     {
  476.         if (Rnd.get(12) < 1)
  477.             callSkills(npc, caster);
  478.        
  479.         return super.onSkillSee(npc, caster, skill, targets, isPet);
  480.     }
  481.    
  482.     @Override
  483.     public String onSpellFinished(Npc npc, Player player, L2Skill skill)
  484.     {
  485.         switch (skill.getId())
  486.         {
  487.             case 4222: // Instant Move; a self teleport skill Zaken uses to move from one point to another. Location is computed on the fly, depending conditions/checks.
  488.                 ((Attackable) npc).cleanAllHate();
  489.                 npc.teleportTo(_zakenLocation, 0);
  490.                 break;
  491.            
  492.             case 4216: // Scatter Enemy ; a target teleport skill, which teleports the targeted Player to a defined, random Location.
  493.                 ((Attackable) npc).stopHating(player);
  494.                 player.teleportTo(Rnd.get(LOCS), 0);
  495.                 break;
  496.            
  497.             case 4217: // Mass Teleport ; teleport victims and targeted Player, each on a defined, random Location.
  498.                 for (Player ply : VICTIMS)
  499.                 {
  500.                     if (ply.isInsideRadius(player, 250, true, false))
  501.                     {
  502.                         ((Attackable) npc).stopHating(ply);
  503.                         ply.teleportTo(Rnd.get(LOCS), 0);
  504.                     }
  505.                 }
  506.                 ((Attackable) npc).stopHating(player);
  507.                 player.teleportTo(Rnd.get(LOCS), 0);
  508.                 break;
  509.         }
  510.         return super.onSpellFinished(npc, player, skill);
  511.     }
  512.    
  513.     @Override
  514.     public void onGameTime()
  515.     {
  516.         if (GameTimeTaskManager.getInstance().getGameTime() == 0)
  517.         {
  518.             final Door door = DoorData.getInstance().getDoor(21240006);
  519.             if (door != null)
  520.                 door.openMe();
  521.         }
  522.     }
  523.    
  524.     /**
  525.      * Call skills depending of luck and specific events.
  526.      * @param npc : The npc who casts the spell (Zaken).
  527.      * @param target : The target Zaken currently aims at.
  528.      */
  529.     private static void callSkills(Npc npc, WorldObject target)
  530.     {
  531.         if (npc.isCastingNow())
  532.             return;
  533.        
  534.         npc.setTarget(target);
  535.        
  536.         final int chance = Rnd.get(225);
  537.         if (chance < 1)
  538.             npc.doCast(FrequentSkill.ZAKEN_TELE.getSkill());
  539.         else if (chance >= 10 && chance < 35)
  540.             npc.doCast(FrequentSkill.ZAKEN_MASS_TELE.getSkill());
  541.         else if (chance >= 15 && chance < 30)
  542.             npc.doCast(FrequentSkill.ZAKEN_HOLD.getSkill());
  543.         else if (chance >= 15 && chance < 30)
  544.             npc.doCast(FrequentSkill.ZAKEN_DRAIN.getSkill());
  545.         else if (chance >= 10 && chance < 30)
  546.         {
  547.             if (target != ((Attackable) npc).getMostHated() && npc.isInsideRadius(target, 100, false, false))
  548.                 npc.doCast(FrequentSkill.ZAKEN_MASS_DUAL_ATTACK.getSkill());
  549.         }
  550.        
  551.         if (Rnd.nextBoolean() && target == ((Attackable) npc).getMostHated())
  552.             npc.doCast(FrequentSkill.ZAKEN_DUAL_ATTACK.getSkill());
  553.     }
  554.    
  555.     /**
  556.      * Make additional actions on boss spawn : register the NPC as boss, activate tasks.
  557.      * @param freshStart : If true, it uses static data, otherwise it uses stored data.
  558.      */
  559.     private void spawnBoss(boolean freshStart)
  560.     {
  561.         final GrandBoss zaken;
  562.         if (freshStart)
  563.         {
  564.             GrandBossManager.getInstance().setBossStatus(ZAKEN, ALIVE);
  565.            
  566.             final Location loc = Rnd.get(LOCS);
  567.             zaken = (GrandBoss) addSpawn(ZAKEN, loc.getX(), loc.getY(), loc.getZ(), 0, false, 0, false);
  568.         }
  569.         else
  570.         {
  571.             final StatsSet info = GrandBossManager.getInstance().getStatsSet(ZAKEN);
  572.            
  573.             zaken = (GrandBoss) addSpawn(ZAKEN, info.getInteger("loc_x"), info.getInteger("loc_y"), info.getInteger("loc_z"), info.getInteger("heading"), false, 0, false);
  574.             zaken.setCurrentHpMp(info.getInteger("currentHP"), info.getInteger("currentMP"));
  575.         }
  576.        
  577.         GrandBossManager.getInstance().addBoss(zaken);
  578.    
  579.         // Reset variables.
  580.         _teleportCheck = 3;
  581.         _hate = 0;
  582.         _hasTeleported = false;
  583.         _mostHated = null;
  584.        
  585.         // Store current Zaken position.
  586.         _zakenLocation.set(zaken.getPosition());
  587.        
  588.         // Clear victims list.
  589.         VICTIMS.clear();
  590.        
  591.         // If Zaken is on its lair, begin the minions spawn cycle.
  592.         if (ZONE.isInsideZone(zaken))
  593.         {
  594.             _minionStatus = 1;
  595.             startQuestTimer("1003", 1700, null, null, true);
  596.         }
  597.        
  598.         // Generic task is running from now.
  599.         startQuestTimer("1001", 1000, zaken, null, false);
  600.        
  601.         zaken.broadcastPacket(new PlaySound(1, "BS01_A", zaken));
  602.     }
  603.    
  604.     /**
  605.      * Spawn one {@link Npc} on every {@link Location} from the LOCS array. Process it for the roundsNumber amount.
  606.      * @param npcId : The npcId to spawn.
  607.      * @param roundsNumber : The rounds number to process.
  608.      */
  609.     private void spawnMinionOnEveryLocation(int npcId, int roundsNumber)
  610.     {
  611.         for (Location loc : LOCS)
  612.         {
  613.             for (int i = 0; i < roundsNumber; i++)
  614.             {
  615.                 final int x = loc.getX() + Rnd.get(650);
  616.                 final int y = loc.getY() + Rnd.get(650);
  617.                
  618.                 addSpawn(npcId, x, y, loc.getZ(), Rnd.get(65536), false, 0, true);
  619.             }
  620.         }
  621.     }
  622. }
Add Comment
Please, Sign In to add comment