Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.sf.l2j.gameserver.scripting.scripts.ai.individual;
- import java.util.ArrayList;
- import java.util.List;
- import net.sf.l2j.commons.random.Rnd;
- import net.sf.l2j.gameserver.ai.CtrlIntention;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.geoengine.GeoEngine;
- import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
- import net.sf.l2j.gameserver.model.L2Skill;
- import net.sf.l2j.gameserver.model.actor.Attackable;
- import net.sf.l2j.gameserver.model.actor.Character;
- import net.sf.l2j.gameserver.model.actor.Npc;
- import net.sf.l2j.gameserver.model.actor.instance.GrandBoss;
- import net.sf.l2j.gameserver.model.actor.instance.Monster;
- import net.sf.l2j.gameserver.model.actor.instance.Player;
- import net.sf.l2j.gameserver.network.serverpackets.PlaySound;
- import net.sf.l2j.gameserver.scripting.EventType;
- import net.sf.l2j.gameserver.scripting.scripts.ai.L2AttackableAIScript;
- import net.sf.l2j.gameserver.templates.StatsSet;
- import net.sf.l2j.gameserver.util.Util;
- public class Fairy extends L2AttackableAIScript
- {
- /**User Configurations */
- private static final int FAIRY = 25294; //GRANDBOSS ID
- private static final int RED = 21342; // MINION RED ID
- private static final int BLUE = 21688; // MINION BLUE ID
- private static final int GREEN = 22146; // MINION GREEN ID
- private static final int FAIRY_SPAWN_X = 84103;
- private static final int FAIRY_SPAWN_Y = 256954;
- private static final int FAIRY_SPAWN_Z = -11669;
- private static final int RESPAWN_HOURS = 6; //Respawn hours needed
- /**Skill Holder */
- private static final int[] skills100 = {7075}; //Add skill ID for 100% hp
- private static final int[] skills70 = {7076}; //Add skill ID's for 70%
- private static final int[] skills50 = {7077}; //Add skill ID's for 50%
- private static final int[] skills30 = {7078}; //Add skill ID's for 30%
- private static final int FairyBuffId70 = 4099; //This buff will be cast when HP reach 70 or lower
- private static final int FairyBuffId50 = 4318; //This buff will be cast when HP reach 50 or lower
- private static final int FairyBuffId30 = 4585; //This buff will be cast when HP reach 30 or lower
- //=============================================
- //Don't touch these bellow
- //=============================================
- private static boolean hasAlreadyBuff70 = false;
- private static boolean hasAlreadyBuff50 = false;
- private static boolean hasAlreadyBuff30 = false;
- private static final byte ALIVE = 0; // Fairy is spawned.
- private static final byte DEAD = 1; // Fairy has been killed.
- private static Character _actualVictim = null;
- private final List<Attackable> _minions = new ArrayList<>();
- public Fairy()
- {
- super("ai/individual");
- addAttackId(FAIRY);
- addKillId(FAIRY);
- final StatsSet info = GrandBossManager.getInstance().getStatsSet(FAIRY);
- final int status = GrandBossManager.getInstance().getBossStatus(FAIRY);
- if (status == DEAD)
- {
- // load the unlock date and time for Core from DB
- final long temp = (info.getLong("respawn_time") - System.currentTimeMillis());
- if (temp > 0)
- {
- // The time has not yet expired. Mark Core as currently locked (dead).
- startQuestTimer("fairy_unlock", temp, null, null, false);
- }
- else
- {
- final GrandBoss fairy = (GrandBoss) addSpawn(FAIRY, FAIRY_SPAWN_X, FAIRY_SPAWN_Y, FAIRY_SPAWN_Z, 0, false, 0, false); //SPAWN LOCATION of GRANDBOSS <--
- GrandBossManager.getInstance().setBossStatus(FAIRY, ALIVE);
- spawnBoss(fairy);
- }
- }
- else
- {
- final int loc_x = info.getInteger("loc_x");
- final int loc_y = info.getInteger("loc_y");
- final int loc_z = info.getInteger("loc_z");
- final int heading = info.getInteger("heading");
- final int hp = info.getInteger("currentHP");
- final int mp = info.getInteger("currentMP");
- final GrandBoss fairy = (GrandBoss) addSpawn(FAIRY, loc_x, loc_y, loc_z, heading, false, 0, false);
- fairy.setCurrentHpMp(hp, mp);
- spawnBoss(fairy);
- }
- }
- @Override
- public String onSpawn(Npc npc)
- {
- npc.disableCoreAI(true);
- return super.onSpawn(npc);
- }
- @Override
- protected void registerNpcs()
- {
- addEventIds(FAIRY, EventType.ON_ATTACK, EventType.ON_KILL, EventType.ON_SPAWN);
- }
- public void spawnBoss(GrandBoss npc)
- {
- GrandBossManager.getInstance().addBoss(npc);
- npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
- startQuestTimer("cast_skill", 7500, npc, null, true);
- hasAlreadyBuff70 = false;
- hasAlreadyBuff50 = false;
- hasAlreadyBuff30 = false;
- }
- @Override
- public String onAdvEvent(String event, Npc npc, Player player)
- {
- if (event.equalsIgnoreCase("fairy_unlock"))
- {
- final GrandBoss core = (GrandBoss) addSpawn(FAIRY, FAIRY_SPAWN_X, FAIRY_SPAWN_Y, FAIRY_SPAWN_Z, 0, false, 0, false);
- GrandBossManager.getInstance().setBossStatus(FAIRY, ALIVE);
- spawnBoss(core);
- }
- else if (event.equalsIgnoreCase("cast_skill"))
- {
- callSkillAI(npc);
- }
- else if (event.equals("SelfBuff70"))
- {
- npc.setTarget(npc);
- npc.doCast(SkillTable.getInstance().getInfo(FairyBuffId70, 1));
- }
- else if (event.equals("SelfBuff50"))
- {
- npc.setTarget(npc);
- npc.doCast(SkillTable.getInstance().getInfo(FairyBuffId50, 1));
- }
- else if (event.equals("SelfBuff30"))
- {
- npc.setTarget(npc);
- npc.doCast(SkillTable.getInstance().getInfo(FairyBuffId30, 1));
- }
- else if (event.equalsIgnoreCase("spawn_minion"))
- {
- final Attackable mob = (Attackable) addSpawn(npc.getNpcId(), npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0, false);
- mob.setIsRaidMinion(true);
- _minions.add(mob);
- }
- else if (event.equalsIgnoreCase("despawn_minions"))
- {
- for (int i = 0; i < _minions.size(); i++)
- {
- final Attackable mob = _minions.get(i);
- if (mob != null)
- mob.decayMe();
- }
- _minions.clear();
- }
- return super.onAdvEvent(event, npc, player);
- }
- private static void callSkillAI(Npc npc)
- {
- if (npc == null || npc.isInvul() || npc.isCastingNow())
- return;
- if (_actualVictim == null || _actualVictim.isDead() || !(npc.getKnownType(Player.class).contains(_actualVictim)) || (_actualVictim instanceof Monster && Rnd.get(10) < 5) || Rnd.get(10) == 0)
- _actualVictim = getRandomTarget(npc);
- if (_actualVictim == null)
- return;
- final L2Skill skill = SkillTable.getInstance().getInfo(getRandomSkill(npc), 1);
- if (skill == null)
- return;
- if (Util.checkIfInRange((int) (skill.getCastRange() + npc.getCollisionRadius()), npc, _actualVictim, true))
- {
- npc.getAI().setIntention(CtrlIntention.IDLE);
- npc.setTarget(_actualVictim);
- npc.doCast(skill);
- }
- else
- npc.getAI().setIntention(CtrlIntention.FOLLOW, _actualVictim, null);
- }
- private static Character getRandomTarget(Npc npc)
- {
- List<Character> result = new ArrayList<>();
- for (Character obj : npc.getKnownType(Character.class))
- {
- if (obj instanceof Player)
- {
- if (obj.isDead() || !(GeoEngine.getInstance().canSeeTarget(npc, obj)))
- continue;
- if (((Player) obj).isGM() && ((Player) obj).getAppearance().getInvisible())
- continue;
- result.add(obj);
- }
- }
- return (result.isEmpty()) ? null : Rnd.get(result);
- }
- @Override
- public String onAttack(Npc npc, Player attacker, int damage, boolean isPet, L2Skill skill)
- {
- if (npc.getNpcId() == FAIRY)
- {
- double hpPercentage = npc.getCurrentHp() / npc.getMaxHp();
- int percentage = (int) (hpPercentage * 100);
- if (percentage <= 70)
- {
- if (!hasAlreadyBuff70)
- {
- hasAlreadyBuff70 = true;
- startQuestTimer("SelfBuff70", 250, npc, null, false);
- }
- npc.broadcastNpcSay("You're fucked guys...");
- spawnUnits70(npc); //Wave for 70%
- }
- else if (percentage <= 50)
- {
- if (!hasAlreadyBuff50)
- {
- hasAlreadyBuff50 = true;
- startQuestTimer("SelfBuff50", 250, npc, null, false);
- }
- npc.broadcastNpcSay("You're fucked guys...");
- spawnUnits50(npc); //Wave for 50%
- }
- else if (percentage <= 30)
- {
- if (!hasAlreadyBuff30)
- {
- hasAlreadyBuff30 = true;
- startQuestTimer("SelfBuff30", 250, npc, null, false);
- }
- npc.broadcastNpcSay("You're fucked guys...");
- spawnUnits30(npc); //Wave for 30%
- }
- }
- return super.onAttack(npc, attacker, damage, isPet, skill);
- }
- private void spawnUnits30(Npc npc)
- {
- int redAmount = 5; //Change amount
- int greenAmount = 5; //Change amount
- int blueAmount = 5;//Change amount
- Attackable mob;
- for (int x1 = 0; x1<redAmount; x1++)
- {
- mob = (Attackable) addSpawn(RED, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- for (int x1 = 0; x1<greenAmount; x1++)
- {
- mob = (Attackable) addSpawn(GREEN, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- for (int x1 = 0; x1<blueAmount; x1++)
- {
- mob = (Attackable) addSpawn(BLUE, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- }
- private void spawnUnits50(Npc npc)
- {
- int redAmount = 5; //Change amount
- int greenAmount = 5; //Change amount
- int blueAmount = 5;//Change amount
- Attackable mob;
- for (int x1 = 0; x1<redAmount; x1++)
- {
- mob = (Attackable) addSpawn(RED, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- for (int x1 = 0; x1<greenAmount; x1++)
- {
- mob = (Attackable) addSpawn(GREEN, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- for (int x1 = 0; x1<blueAmount; x1++)
- {
- mob = (Attackable) addSpawn(BLUE, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- }
- private void spawnUnits70(Npc npc)
- {
- int redAmount = 5; //Change amount
- int greenAmount = 5; //Change amount
- int blueAmount = 5; //Change amount
- Attackable mob;
- for (int x1 = 0; x1<redAmount; x1++)
- {
- mob = (Attackable) addSpawn(RED, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- for (int x1 = 0; x1<greenAmount; x1++)
- {
- mob = (Attackable) addSpawn(GREEN, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- for (int x1 = 0; x1<blueAmount; x1++)
- {
- mob = (Attackable) addSpawn(BLUE, npc.getX() + Rnd.get(100, 1200), npc.getY() + Rnd.get(300, 1200), npc.getZ(), 0, false, 900000, false);
- mob.setIsRaidMinion(true);
- Character target = getRandomTarget(mob);
- mob.setTarget(target);
- mob.doAttack(target);
- _minions.add(mob);
- }
- }
- private static int getRandomSkill(Npc npc)
- {
- double hpPercentage = npc.getCurrentHp() / npc.getMaxHp();
- int percentage = (int) (hpPercentage * 100);
- int[] skills = {};
- if (percentage <= 70)
- skills = skills70;
- else if (percentage <= 50)
- skills = skills50;
- else if (percentage <= 30)
- skills = skills30;
- else
- skills = skills100;
- return Rnd.get(0, skills.length + 1);
- }
- @Override
- public String onKill(Npc npc, Player killer, boolean isPet)
- {
- if (npc.getNpcId() == FAIRY)
- {
- npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
- npc.broadcastNpcSay("A fatal error has occurred.");
- npc.broadcastNpcSay("System is being shut down...");
- npc.broadcastNpcSay("......");
- GrandBossManager.getInstance().setBossStatus(FAIRY, DEAD);
- long respawnTime = RESPAWN_HOURS * 1000 * 3600;
- startQuestTimer("fairy_unlock", respawnTime, null, null, false);
- final StatsSet info = GrandBossManager.getInstance().getStatsSet(FAIRY);
- info.set("respawn_time", System.currentTimeMillis() + respawnTime);
- GrandBossManager.getInstance().setStatsSet(FAIRY, info);
- startQuestTimer("despawn_minions", 20000, null, null, false);
- cancelQuestTimers("spawn_minion");
- cancelQuestTimers("cast_skill");
- }
- else if (GrandBossManager.getInstance().getBossStatus(FAIRY) == ALIVE && _minions != null && _minions.contains(npc))
- {
- _minions.remove(npc);
- startQuestTimer("spawn_minion", 60000, npc, null, false);
- }
- return super.onKill(npc, killer, isPet);
- }
- }
Add Comment
Please, Sign In to add comment