Orfen.java 12 KB

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