Orfen.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package ai.individual;
  20. import java.util.List;
  21. import javolution.util.FastList;
  22. import ai.npc.AbstractNpcAI;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.ai.CtrlIntention;
  25. import com.l2jserver.gameserver.datatables.SkillData;
  26. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  27. import com.l2jserver.gameserver.model.L2Object;
  28. import com.l2jserver.gameserver.model.L2Spawn;
  29. import com.l2jserver.gameserver.model.Location;
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.gameserver.model.actor.L2Attackable;
  32. import com.l2jserver.gameserver.model.actor.L2Character;
  33. import com.l2jserver.gameserver.model.actor.L2Npc;
  34. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.skills.Skill;
  37. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  38. import com.l2jserver.gameserver.network.NpcStringId;
  39. import com.l2jserver.gameserver.network.clientpackets.Say2;
  40. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  41. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  42. /**
  43. * Orfen's AI
  44. * @author Emperorc
  45. */
  46. public final class Orfen extends AbstractNpcAI
  47. {
  48. private static final Location[] POS =
  49. {
  50. new Location(43728, 17220, -4342),
  51. new Location(55024, 17368, -5412),
  52. new Location(53504, 21248, -5486),
  53. new Location(53248, 24576, -5262)
  54. };
  55. private static final NpcStringId[] TEXT =
  56. {
  57. NpcStringId.S1_STOP_KIDDING_YOURSELF_ABOUT_YOUR_OWN_POWERLESSNESS,
  58. NpcStringId.S1_ILL_MAKE_YOU_FEEL_WHAT_TRUE_FEAR_IS,
  59. NpcStringId.YOURE_REALLY_STUPID_TO_HAVE_CHALLENGED_ME_S1_GET_READY,
  60. NpcStringId.S1_DO_YOU_THINK_THATS_GOING_TO_WORK
  61. };
  62. private static final int ORFEN = 29014;
  63. // private static final int RAIKEL = 29015;
  64. private static final int RAIKEL_LEOS = 29016;
  65. // private static final int RIBA = 29017;
  66. private static final int RIBA_IREN = 29018;
  67. private static boolean _IsTeleported;
  68. private static List<L2Attackable> _Minions = new FastList<>();
  69. private static L2BossZone ZONE;
  70. private static final byte ALIVE = 0;
  71. private static final byte DEAD = 1;
  72. private Orfen()
  73. {
  74. super(Orfen.class.getSimpleName(), "ai/individual");
  75. int[] mobs =
  76. {
  77. ORFEN,
  78. RAIKEL_LEOS,
  79. RIBA_IREN
  80. };
  81. registerMobs(mobs);
  82. _IsTeleported = false;
  83. ZONE = GrandBossManager.getInstance().getZone(POS[0]);
  84. StatsSet info = GrandBossManager.getInstance().getStatsSet(ORFEN);
  85. int status = GrandBossManager.getInstance().getBossStatus(ORFEN);
  86. if (status == DEAD)
  87. {
  88. // load the unlock date and time for Orfen from DB
  89. long temp = info.getLong("respawn_time") - System.currentTimeMillis();
  90. // if Orfen is locked until a certain time, mark it so and start the unlock timer
  91. // the unlock time has not yet expired.
  92. if (temp > 0)
  93. {
  94. startQuestTimer("orfen_unlock", temp, null, null);
  95. }
  96. else
  97. {
  98. // the time has already expired while the server was offline. Immediately spawn Orfen.
  99. int i = getRandom(10);
  100. Location loc;
  101. if (i < 4)
  102. {
  103. loc = POS[1];
  104. }
  105. else if (i < 7)
  106. {
  107. loc = POS[2];
  108. }
  109. else
  110. {
  111. loc = POS[3];
  112. }
  113. L2GrandBossInstance orfen = (L2GrandBossInstance) addSpawn(ORFEN, loc, false, 0);
  114. GrandBossManager.getInstance().setBossStatus(ORFEN, ALIVE);
  115. spawnBoss(orfen);
  116. }
  117. }
  118. else
  119. {
  120. int loc_x = info.getInt("loc_x");
  121. int loc_y = info.getInt("loc_y");
  122. int loc_z = info.getInt("loc_z");
  123. int heading = info.getInt("heading");
  124. int hp = info.getInt("currentHP");
  125. int mp = info.getInt("currentMP");
  126. L2GrandBossInstance orfen = (L2GrandBossInstance) addSpawn(ORFEN, loc_x, loc_y, loc_z, heading, false, 0);
  127. orfen.setCurrentHpMp(hp, mp);
  128. spawnBoss(orfen);
  129. }
  130. }
  131. public void setSpawnPoint(L2Npc npc, int index)
  132. {
  133. ((L2Attackable) npc).clearAggroList();
  134. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  135. L2Spawn spawn = npc.getSpawn();
  136. spawn.setLocation(POS[index]);
  137. npc.teleToLocation(POS[index], false);
  138. }
  139. public void spawnBoss(L2GrandBossInstance npc)
  140. {
  141. GrandBossManager.getInstance().addBoss(npc);
  142. npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  143. startQuestTimer("check_orfen_pos", 10000, npc, null, true);
  144. // Spawn minions
  145. int x = npc.getX();
  146. int y = npc.getY();
  147. L2Attackable mob;
  148. mob = (L2Attackable) addSpawn(RAIKEL_LEOS, x + 100, y + 100, npc.getZ(), 0, false, 0);
  149. mob.setIsRaidMinion(true);
  150. _Minions.add(mob);
  151. mob = (L2Attackable) addSpawn(RAIKEL_LEOS, x + 100, y - 100, npc.getZ(), 0, false, 0);
  152. mob.setIsRaidMinion(true);
  153. _Minions.add(mob);
  154. mob = (L2Attackable) addSpawn(RAIKEL_LEOS, x - 100, y + 100, npc.getZ(), 0, false, 0);
  155. mob.setIsRaidMinion(true);
  156. _Minions.add(mob);
  157. mob = (L2Attackable) addSpawn(RAIKEL_LEOS, x - 100, y - 100, npc.getZ(), 0, false, 0);
  158. mob.setIsRaidMinion(true);
  159. _Minions.add(mob);
  160. startQuestTimer("check_minion_loc", 10000, npc, null, true);
  161. }
  162. @Override
  163. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  164. {
  165. if (event.equalsIgnoreCase("orfen_unlock"))
  166. {
  167. int i = getRandom(10);
  168. Location loc;
  169. if (i < 4)
  170. {
  171. loc = POS[1];
  172. }
  173. else if (i < 7)
  174. {
  175. loc = POS[2];
  176. }
  177. else
  178. {
  179. loc = POS[3];
  180. }
  181. L2GrandBossInstance orfen = (L2GrandBossInstance) addSpawn(ORFEN, loc, false, 0);
  182. GrandBossManager.getInstance().setBossStatus(ORFEN, ALIVE);
  183. spawnBoss(orfen);
  184. }
  185. else if (event.equalsIgnoreCase("check_orfen_pos"))
  186. {
  187. if ((_IsTeleported && (npc.getCurrentHp() > (npc.getMaxHp() * 0.95))) || (!ZONE.isInsideZone(npc) && !_IsTeleported))
  188. {
  189. setSpawnPoint(npc, getRandom(3) + 1);
  190. _IsTeleported = false;
  191. }
  192. else if (_IsTeleported && !ZONE.isInsideZone(npc))
  193. {
  194. setSpawnPoint(npc, 0);
  195. }
  196. }
  197. else if (event.equalsIgnoreCase("check_minion_loc"))
  198. {
  199. for (int i = 0; i < _Minions.size(); i++)
  200. {
  201. L2Attackable mob = _Minions.get(i);
  202. if (!npc.isInsideRadius(mob, 3000, false, false))
  203. {
  204. mob.teleToLocation(npc.getLocation());
  205. ((L2Attackable) npc).clearAggroList();
  206. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  207. }
  208. }
  209. }
  210. else if (event.equalsIgnoreCase("despawn_minions"))
  211. {
  212. for (int i = 0; i < _Minions.size(); i++)
  213. {
  214. L2Attackable mob = _Minions.get(i);
  215. if (mob != null)
  216. {
  217. mob.decayMe();
  218. }
  219. }
  220. _Minions.clear();
  221. }
  222. else if (event.equalsIgnoreCase("spawn_minion"))
  223. {
  224. L2Attackable mob = (L2Attackable) addSpawn(RAIKEL_LEOS, npc.getX(), npc.getY(), npc.getZ(), 0, false, 0);
  225. mob.setIsRaidMinion(true);
  226. _Minions.add(mob);
  227. }
  228. return super.onAdvEvent(event, npc, player);
  229. }
  230. @Override
  231. public String onSkillSee(L2Npc npc, L2PcInstance caster, Skill skill, L2Object[] targets, boolean isSummon)
  232. {
  233. if (npc.getId() == ORFEN)
  234. {
  235. L2Character originalCaster = isSummon ? caster.getSummon() : caster;
  236. if ((skill.getEffectPoint() > 0) && (getRandom(5) == 0) && npc.isInsideRadius(originalCaster, 1000, false, false))
  237. {
  238. NpcSay packet = new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), TEXT[getRandom(4)]);
  239. packet.addStringParameter(caster.getName().toString());
  240. npc.broadcastPacket(packet);
  241. originalCaster.teleToLocation(npc.getLocation());
  242. npc.setTarget(originalCaster);
  243. npc.doCast(SkillData.getInstance().getSkill(4064, 1));
  244. }
  245. }
  246. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  247. }
  248. @Override
  249. public String onFactionCall(L2Npc npc, L2Npc caller, L2PcInstance attacker, boolean isSummon)
  250. {
  251. if ((caller == null) || (npc == null) || npc.isCastingNow())
  252. {
  253. return super.onFactionCall(npc, caller, attacker, isSummon);
  254. }
  255. int npcId = npc.getId();
  256. int callerId = caller.getId();
  257. if ((npcId == RAIKEL_LEOS) && (getRandom(20) == 0))
  258. {
  259. npc.setTarget(attacker);
  260. npc.doCast(SkillData.getInstance().getSkill(4067, 4));
  261. }
  262. else if (npcId == RIBA_IREN)
  263. {
  264. int chance = 1;
  265. if (callerId == ORFEN)
  266. {
  267. chance = 9;
  268. }
  269. if ((callerId != RIBA_IREN) && (caller.getCurrentHp() < (caller.getMaxHp() / 2.0)) && (getRandom(10) < chance))
  270. {
  271. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  272. npc.setTarget(caller);
  273. npc.doCast(SkillData.getInstance().getSkill(4516, 1));
  274. }
  275. }
  276. return super.onFactionCall(npc, caller, attacker, isSummon);
  277. }
  278. @Override
  279. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  280. {
  281. int npcId = npc.getId();
  282. if (npcId == ORFEN)
  283. {
  284. if (!_IsTeleported && ((npc.getCurrentHp() - damage) < (npc.getMaxHp() / 2)))
  285. {
  286. _IsTeleported = true;
  287. setSpawnPoint(npc, 0);
  288. }
  289. else if (npc.isInsideRadius(attacker, 1000, false, false) && !npc.isInsideRadius(attacker, 300, false, false) && (getRandom(10) == 0))
  290. {
  291. NpcSay packet = new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npcId, TEXT[getRandom(3)]);
  292. packet.addStringParameter(attacker.getName().toString());
  293. npc.broadcastPacket(packet);
  294. attacker.teleToLocation(npc.getLocation());
  295. npc.setTarget(attacker);
  296. npc.doCast(SkillData.getInstance().getSkill(4064, 1));
  297. }
  298. }
  299. else if (npcId == RIBA_IREN)
  300. {
  301. if (!npc.isCastingNow() && ((npc.getCurrentHp() - damage) < (npc.getMaxHp() / 2.0)))
  302. {
  303. npc.setTarget(attacker);
  304. npc.doCast(SkillData.getInstance().getSkill(4516, 1));
  305. }
  306. }
  307. return super.onAttack(npc, attacker, damage, isSummon);
  308. }
  309. @Override
  310. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  311. {
  312. if (npc.getId() == ORFEN)
  313. {
  314. npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  315. GrandBossManager.getInstance().setBossStatus(ORFEN, DEAD);
  316. // Calculate Min and Max respawn times randomly.
  317. long respawnTime = Config.ORFEN_SPAWN_INTERVAL + getRandom(-Config.ORFEN_SPAWN_RANDOM, Config.ORFEN_SPAWN_RANDOM);
  318. respawnTime *= 3600000;
  319. startQuestTimer("orfen_unlock", respawnTime, null, null);
  320. // also save the respawn time so that the info is maintained past reboots
  321. StatsSet info = GrandBossManager.getInstance().getStatsSet(ORFEN);
  322. info.set("respawn_time", System.currentTimeMillis() + respawnTime);
  323. GrandBossManager.getInstance().setStatsSet(ORFEN, info);
  324. cancelQuestTimer("check_minion_loc", npc, null);
  325. cancelQuestTimer("check_orfen_pos", npc, null);
  326. startQuestTimer("despawn_minions", 20000, null, null);
  327. cancelQuestTimers("spawn_minion");
  328. }
  329. else if ((GrandBossManager.getInstance().getBossStatus(ORFEN) == ALIVE) && (npc.getId() == RAIKEL_LEOS))
  330. {
  331. _Minions.remove(npc);
  332. startQuestTimer("spawn_minion", 360000, npc, null);
  333. }
  334. return super.onKill(npc, killer, isSummon);
  335. }
  336. public static void main(String[] args)
  337. {
  338. new Orfen();
  339. }
  340. }