Guest User

Untitled

a guest
Apr 20th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.63 KB | None | 0 0
  1. package net.sf.l2j.gameserver.scripting.scripts.ai.individual;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import net.sf.l2j.commons.random.Rnd;
  6.  
  7. import net.sf.l2j.gameserver.ai.CtrlIntention;
  8. import net.sf.l2j.gameserver.datatables.SkillTable;
  9. import net.sf.l2j.gameserver.geoengine.GeoEngine;
  10. import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
  11. import net.sf.l2j.gameserver.model.L2Skill;
  12. import net.sf.l2j.gameserver.model.actor.Attackable;
  13. import net.sf.l2j.gameserver.model.actor.Character;
  14. import net.sf.l2j.gameserver.model.actor.Npc;
  15. import net.sf.l2j.gameserver.model.actor.instance.GrandBoss;
  16. import net.sf.l2j.gameserver.model.actor.instance.Monster;
  17. import net.sf.l2j.gameserver.model.actor.instance.Player;
  18. import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
  19. import net.sf.l2j.gameserver.scripting.EventType;
  20. import net.sf.l2j.gameserver.scripting.scripts.ai.L2AttackableAIScript;
  21. import net.sf.l2j.gameserver.templates.StatsSet;
  22. import net.sf.l2j.gameserver.util.Util;
  23.  
  24. public class Fairy extends L2AttackableAIScript
  25. {
  26.  
  27. /**User Configurations */
  28.  
  29. private static final int FAIRY = 25294; //GRANDBOSS ID
  30.  
  31. private static final int RED = 21342; // MINION RED ID
  32. private static final int BLUE = 21688; // MINION BLUE ID
  33. private static final int GREEN = 22146; // MINION GREEN ID
  34.  
  35. private static final int FAIRY_SPAWN_X = 84103;
  36. private static final int FAIRY_SPAWN_Y = 256954;
  37. private static final int FAIRY_SPAWN_Z = -11669;
  38.  
  39. private static final int RESPAWN_HOURS = 6; //Respawn hours needed
  40.  
  41. /**Skill Holder */
  42. private static final int[] skills100 = {7075}; //Add skill ID for 100% hp
  43. private static final int[] skills70 = {7076}; //Add skill ID's for 70%
  44. private static final int[] skills50 = {7077}; //Add skill ID's for 50%
  45. private static final int[] skills30 = {7078}; //Add skill ID's for 30%
  46.  
  47. private static final int FairyBuffId70 = 4099; //This buff will be cast when HP reach 70 or lower
  48. private static final int FairyBuffId50 = 4318; //This buff will be cast when HP reach 50 or lower
  49. private static final int FairyBuffId30 = 4585; //This buff will be cast when HP reach 30 or lower
  50.  
  51.  
  52. //=============================================
  53. //Don't touch these bellow
  54. //=============================================
  55. private static boolean hasAlreadyBuff70 = false;
  56. private static boolean hasAlreadyBuff50 = false;
  57. private static boolean hasAlreadyBuff30 = false;
  58.  
  59. private static final byte ALIVE = 0; // Fairy is spawned.
  60. private static final byte DEAD = 1; // Fairy has been killed.
  61.  
  62. private static Character _actualVictim = null;
  63.  
  64. private final List<Attackable> _minions = new ArrayList<>();
  65.  
  66. public Fairy()
  67. {
  68. super("ai/individual");
  69.  
  70. addAttackId(FAIRY);
  71. addKillId(FAIRY);
  72.  
  73. final StatsSet info = GrandBossManager.getInstance().getStatsSet(FAIRY);
  74. final int status = GrandBossManager.getInstance().getBossStatus(FAIRY);
  75. if (status == DEAD)
  76. {
  77. // load the unlock date and time for Core from DB
  78. final long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
  79. if (temp > 0)
  80. {
  81. // The time has not yet expired. Mark Core as currently locked (dead).
  82. startQuestTimer("fairy_unlock", temp, null, null, false);
  83. }
  84. else
  85. {
  86. final GrandBoss fairy = (GrandBoss) addSpawn(FAIRY, FAIRY_SPAWN_X, FAIRY_SPAWN_Y, FAIRY_SPAWN_Z, 0, false, 0, false); //SPAWN LOCATION of GRANDBOSS <--
  87. GrandBossManager.getInstance().setBossStatus(FAIRY, ALIVE);
  88. spawnBoss(fairy);
  89. }
  90. }
  91. else
  92. {
  93. final int loc_x = info.getInteger("loc_x");
  94. final int loc_y = info.getInteger("loc_y");
  95. final int loc_z = info.getInteger("loc_z");
  96. final int heading = info.getInteger("heading");
  97. final int hp = info.getInteger("currentHP");
  98. final int mp = info.getInteger("currentMP");
  99.  
  100. final GrandBoss fairy = (GrandBoss) addSpawn(FAIRY, loc_x, loc_y, loc_z, heading, false, 0, false);
  101. fairy.setCurrentHpMp(hp, mp);
  102. spawnBoss(fairy);
  103. }
  104. }
  105.  
  106. @Override
  107. public String onSpawn(Npc npc)
  108. {
  109. npc.disableCoreAI(true);
  110. return super.onSpawn(npc);
  111. }
  112.  
  113. @Override
  114. protected void registerNpcs()
  115. {
  116. addEventIds(FAIRY, EventType.ON_ATTACK, EventType.ON_KILL, EventType.ON_SPAWN);
  117. }
  118.  
  119. public void spawnBoss(GrandBoss npc)
  120. {
  121. GrandBossManager.getInstance().addBoss(npc);
  122. npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  123. startQuestTimer("cast_skill", 7500, npc, null, true);
  124.  
  125. hasAlreadyBuff70 = false;
  126. hasAlreadyBuff50 = false;
  127. hasAlreadyBuff30 = false;
  128. }
  129.  
  130. @Override
  131. public String onAdvEvent(String event, Npc npc, Player player)
  132. {
  133. if (event.equalsIgnoreCase("fairy_unlock"))
  134. {
  135. final GrandBoss core = (GrandBoss) addSpawn(FAIRY, FAIRY_SPAWN_X, FAIRY_SPAWN_Y, FAIRY_SPAWN_Z, 0, false, 0, false);
  136. GrandBossManager.getInstance().setBossStatus(FAIRY, ALIVE);
  137. spawnBoss(core);
  138. }
  139. else if (event.equalsIgnoreCase("cast_skill"))
  140. {
  141. callSkillAI(npc);
  142. }
  143. else if (event.equals("SelfBuff70"))
  144. {
  145. npc.setTarget(npc);
  146. npc.doCast(SkillTable.getInstance().getInfo(FairyBuffId70, 1));
  147. }
  148. else if (event.equals("SelfBuff50"))
  149. {
  150. npc.setTarget(npc);
  151. npc.doCast(SkillTable.getInstance().getInfo(FairyBuffId50, 1));
  152. }
  153. else if (event.equals("SelfBuff30"))
  154. {
  155. npc.setTarget(npc);
  156. npc.doCast(SkillTable.getInstance().getInfo(FairyBuffId30, 1));
  157. }
  158. else if (event.equalsIgnoreCase("spawn_minion"))
  159. {
  160. final Attackable mob = (Attackable) addSpawn(npc.getNpcId(), npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0, false);
  161. mob.setIsRaidMinion(true);
  162. _minions.add(mob);
  163. }
  164. else if (event.equalsIgnoreCase("despawn_minions"))
  165. {
  166. for (int i = 0; i < _minions.size(); i++)
  167. {
  168. final Attackable mob = _minions.get(i);
  169. if (mob != null)
  170. mob.decayMe();
  171. }
  172. _minions.clear();
  173. }
  174. return super.onAdvEvent(event, npc, player);
  175. }
  176.  
  177. private static void callSkillAI(Npc npc)
  178. {
  179. if (npc == null || npc.isInvul() || npc.isCastingNow())
  180. return;
  181.  
  182. if (_actualVictim == null || _actualVictim.isDead() || !(npc.getKnownType(Player.class).contains(_actualVictim)) || (_actualVictim instanceof Monster && Rnd.get(10) < 5) || Rnd.get(10) == 0)
  183. _actualVictim = getRandomTarget(npc);
  184.  
  185. if (_actualVictim == null)
  186. return;
  187.  
  188. final L2Skill skill = SkillTable.getInstance().getInfo(getRandomSkill(npc), 1);
  189.  
  190. if (skill == null)
  191. return;
  192.  
  193. if (Util.checkIfInRange((int) (skill.getCastRange() + npc.getCollisionRadius()), npc, _actualVictim, true))
  194. {
  195. npc.getAI().setIntention(CtrlIntention.IDLE);
  196. npc.setTarget(_actualVictim);
  197. npc.doCast(skill);
  198. }
  199. else
  200. npc.getAI().setIntention(CtrlIntention.FOLLOW, _actualVictim, null);
  201. }
  202.  
  203. private static Character getRandomTarget(Npc npc)
  204. {
  205.  
  206. List<Character> result = new ArrayList<>();
  207.  
  208. for (Character obj : npc.getKnownType(Character.class))
  209. {
  210. if (obj instanceof Player)
  211. {
  212. if (obj.isDead() || !(GeoEngine.getInstance().canSeeTarget(npc, obj)))
  213. continue;
  214.  
  215. if (((Player) obj).isGM() && ((Player) obj).getAppearance().getInvisible())
  216. continue;
  217.  
  218. result.add(obj);
  219. }
  220. }
  221.  
  222. return (result.isEmpty()) ? null : Rnd.get(result);
  223. }
  224.  
  225. @Override
  226. public String onAttack(Npc npc, Player attacker, int damage, boolean isPet, L2Skill skill)
  227. {
  228.  
  229. if (npc.getNpcId() == FAIRY)
  230. {
  231.  
  232. double hpPercentage = npc.getCurrentHp() / npc.getMaxHp();
  233.  
  234. int percentage = (int) (hpPercentage * 100);
  235.  
  236. if (percentage <= 70)
  237. {
  238. if (!hasAlreadyBuff70)
  239. {
  240. hasAlreadyBuff70 = true;
  241. startQuestTimer("SelfBuff70", 250, npc, null, false);
  242. }
  243. npc.broadcastNpcSay("You're fucked guys...");
  244. spawnUnits70(npc); //Wave for 70%
  245. }
  246. else if (percentage <= 50)
  247. {
  248. if (!hasAlreadyBuff50)
  249. {
  250. hasAlreadyBuff50 = true;
  251. startQuestTimer("SelfBuff50", 250, npc, null, false);
  252. }
  253. npc.broadcastNpcSay("You're fucked guys...");
  254. spawnUnits50(npc); //Wave for 50%
  255. }
  256. else if (percentage <= 30)
  257. {
  258.  
  259. if (!hasAlreadyBuff30)
  260. {
  261. hasAlreadyBuff30 = true;
  262. startQuestTimer("SelfBuff30", 250, npc, null, false);
  263. }
  264.  
  265. npc.broadcastNpcSay("You're fucked guys...");
  266. spawnUnits30(npc); //Wave for 30%
  267. }
  268. }
  269.  
  270. return super.onAttack(npc, attacker, damage, isPet, skill);
  271. }
  272.  
  273. private void spawnUnits30(Npc npc)
  274. {
  275.  
  276. int redAmount = 5; //Change amount
  277. int greenAmount = 5; //Change amount
  278. int blueAmount = 5;//Change amount
  279.  
  280. Attackable mob;
  281.  
  282. for (int x1 = 0; x1<redAmount; x1++)
  283. {
  284. mob = (Attackable) addSpawn(RED, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  285. mob.setIsRaidMinion(true);
  286. Character target = getRandomTarget(mob);
  287. mob.setTarget(target);
  288. mob.doAttack(target);
  289. _minions.add(mob);
  290. }
  291.  
  292. for (int x1 = 0; x1<greenAmount; x1++)
  293. {
  294. mob = (Attackable) addSpawn(GREEN, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  295. mob.setIsRaidMinion(true);
  296. Character target = getRandomTarget(mob);
  297. mob.setTarget(target);
  298. mob.doAttack(target);
  299. _minions.add(mob);
  300. }
  301.  
  302. for (int x1 = 0; x1<blueAmount; x1++)
  303. {
  304. mob = (Attackable) addSpawn(BLUE, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  305. mob.setIsRaidMinion(true);
  306. Character target = getRandomTarget(mob);
  307. mob.setTarget(target);
  308. mob.doAttack(target);
  309. _minions.add(mob);
  310. }
  311. }
  312.  
  313. private void spawnUnits50(Npc npc)
  314. {
  315.  
  316. int redAmount = 5; //Change amount
  317. int greenAmount = 5; //Change amount
  318. int blueAmount = 5;//Change amount
  319.  
  320. Attackable mob;
  321.  
  322. for (int x1 = 0; x1<redAmount; x1++)
  323. {
  324. mob = (Attackable) addSpawn(RED, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  325. mob.setIsRaidMinion(true);
  326. Character target = getRandomTarget(mob);
  327. mob.setTarget(target);
  328. mob.doAttack(target);
  329. _minions.add(mob);
  330. }
  331.  
  332. for (int x1 = 0; x1<greenAmount; x1++)
  333. {
  334. mob = (Attackable) addSpawn(GREEN, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  335. mob.setIsRaidMinion(true);
  336. Character target = getRandomTarget(mob);
  337. mob.setTarget(target);
  338. mob.doAttack(target);
  339. _minions.add(mob);
  340. }
  341.  
  342. for (int x1 = 0; x1<blueAmount; x1++)
  343. {
  344. mob = (Attackable) addSpawn(BLUE, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  345. mob.setIsRaidMinion(true);
  346. Character target = getRandomTarget(mob);
  347. mob.setTarget(target);
  348. mob.doAttack(target);
  349. _minions.add(mob);
  350. }
  351. }
  352.  
  353. private void spawnUnits70(Npc npc)
  354. {
  355.  
  356. int redAmount = 5; //Change amount
  357. int greenAmount = 5; //Change amount
  358. int blueAmount = 5; //Change amount
  359.  
  360. Attackable mob;
  361.  
  362. for (int x1 = 0; x1<redAmount; x1++)
  363. {
  364. mob = (Attackable) addSpawn(RED, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  365. mob.setIsRaidMinion(true);
  366. Character target = getRandomTarget(mob);
  367. mob.setTarget(target);
  368. mob.doAttack(target);
  369. _minions.add(mob);
  370. }
  371.  
  372. for (int x1 = 0; x1<greenAmount; x1++)
  373. {
  374. mob = (Attackable) addSpawn(GREEN, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  375. mob.setIsRaidMinion(true);
  376. Character target = getRandomTarget(mob);
  377. mob.setTarget(target);
  378. mob.doAttack(target);
  379. _minions.add(mob);
  380. }
  381.  
  382. for (int x1 = 0; x1<blueAmount; x1++)
  383. {
  384. mob = (Attackable) addSpawn(BLUE, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
  385. mob.setIsRaidMinion(true);
  386. Character target = getRandomTarget(mob);
  387. mob.setTarget(target);
  388. mob.doAttack(target);
  389. _minions.add(mob);
  390. }
  391.  
  392. }
  393.  
  394. private static int getRandomSkill(Npc npc)
  395. {
  396. double hpPercentage = npc.getCurrentHp() / npc.getMaxHp();
  397.  
  398. int percentage = (int) (hpPercentage * 100);
  399.  
  400. int[] skills = {};
  401.  
  402. if (percentage <= 70)
  403. skills = skills70;
  404. else if (percentage <= 50)
  405. skills = skills50;
  406. else if (percentage <= 30)
  407. skills = skills30;
  408. else
  409. skills = skills100;
  410.  
  411. return Rnd.get(0, skills.length + 1);
  412.  
  413. }
  414.  
  415. @Override
  416. public String onKill(Npc npc, Player killer, boolean isPet)
  417. {
  418. if (npc.getNpcId() == FAIRY)
  419. {
  420. npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  421. npc.broadcastNpcSay("A fatal error has occurred.");
  422. npc.broadcastNpcSay("System is being shut down...");
  423. npc.broadcastNpcSay("......");
  424.  
  425. GrandBossManager.getInstance().setBossStatus(FAIRY, DEAD);
  426.  
  427. long respawnTime = RESPAWN_HOURS * 1000 * 3600;
  428.  
  429. startQuestTimer("fairy_unlock", respawnTime, null, null, false);
  430.  
  431. final StatsSet info = GrandBossManager.getInstance().getStatsSet(FAIRY);
  432. info.set("respawn_time", System.currentTimeMillis() + respawnTime);
  433. GrandBossManager.getInstance().setStatsSet(FAIRY, info);
  434. startQuestTimer("despawn_minions", 20000, null, null, false);
  435. cancelQuestTimers("spawn_minion");
  436. cancelQuestTimers("cast_skill");
  437. }
  438. else if (GrandBossManager.getInstance().getBossStatus(FAIRY) == ALIVE && _minions != null && _minions.contains(npc))
  439. {
  440. _minions.remove(npc);
  441. startQuestTimer("spawn_minion", 60000, npc, null, false);
  442. }
  443. return super.onKill(npc, killer, isPet);
  444. }
  445.  
  446. }
Add Comment
Please, Sign In to add comment