Orfen.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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.group_template.L2AttackableAIScript;
  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.L2Skill;
  25. import com.l2jserver.gameserver.model.L2Spawn;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2GrandBossInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.zone.type.L2BossZone;
  32. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  33. import com.l2jserver.gameserver.network.serverpackets.PlaySound;
  34. import com.l2jserver.gameserver.templates.StatsSet;
  35. import com.l2jserver.util.Rnd;
  36. /**
  37. * Orfen AI
  38. *
  39. * @author Emperorc
  40. *
  41. */
  42. public class Orfen extends L2AttackableAIScript
  43. {
  44. private static final int[][] Pos =
  45. {
  46. {
  47. 43728, 17220, -4342
  48. },
  49. {
  50. 55024, 17368, -5412
  51. },
  52. {
  53. 53504, 21248, -5486
  54. },
  55. {
  56. 53248, 24576, -5262
  57. }
  58. };
  59. private static final int[] Text =
  60. {
  61. 1000028, // $s1. Stop kidding yourself about your own powerlessness!
  62. 1000029, // $s1. I'll make you feel what true fear is!
  63. 1000030, // You're really stupid to have challenged me. $s1! Get ready!
  64. 1000031 //$s1. Do you think that's going to work?!
  65. };
  66. private static final int ORFEN = 29014;
  67. //private static final int RAIKEL = 29015;
  68. private static final int RAIKEL_LEOS = 29016;
  69. //private static final int RIBA = 29017;
  70. private static final int RIBA_IREN = 29018;
  71. private static boolean _IsTeleported;
  72. private static List<L2Attackable> _Minions = new FastList<L2Attackable>();
  73. private static L2BossZone _Zone;
  74. private static final byte ALIVE = 0;
  75. private static final byte DEAD = 1;
  76. public Orfen(int id, String name, String descr)
  77. {
  78. super(id, name, descr);
  79. int[] mobs =
  80. {
  81. ORFEN, RAIKEL_LEOS, RIBA_IREN
  82. };
  83. this.registerMobs(mobs);
  84. _IsTeleported = false;
  85. _Zone = GrandBossManager.getInstance().getZone(Pos[0][0], Pos[0][1], Pos[0][2]);
  86. StatsSet info = GrandBossManager.getInstance().getStatsSet(ORFEN);
  87. int status = GrandBossManager.getInstance().getBossStatus(ORFEN);
  88. if (status == DEAD)
  89. {
  90. // load the unlock date and time for Orfen from DB
  91. long temp = info.getLong("respawn_time") - System.currentTimeMillis();
  92. // if Orfen is locked until a certain time, mark it so and start the unlock timer
  93. // the unlock time has not yet expired.
  94. if (temp > 0)
  95. this.startQuestTimer("orfen_unlock", temp, null, null);
  96. else
  97. {
  98. // the time has already expired while the server was offline. Immediately spawn Orfen.
  99. int i = Rnd.get(10);
  100. int x = 0;
  101. int y = 0;
  102. int z = 0;
  103. if (i < 4)
  104. {
  105. x = Pos[1][0];
  106. y = Pos[1][1];
  107. z = Pos[1][2];
  108. }
  109. else if (i < 7)
  110. {
  111. x = Pos[2][0];
  112. y = Pos[2][1];
  113. z = Pos[2][2];
  114. }
  115. else
  116. {
  117. x = Pos[3][0];
  118. y = Pos[3][1];
  119. z = Pos[3][2];
  120. }
  121. L2GrandBossInstance orfen = (L2GrandBossInstance) addSpawn(ORFEN, x, y, z, 0, false, 0);
  122. GrandBossManager.getInstance().setBossStatus(ORFEN, ALIVE);
  123. this.spawnBoss(orfen);
  124. }
  125. }
  126. else
  127. {
  128. int loc_x = info.getInteger("loc_x");
  129. int loc_y = info.getInteger("loc_y");
  130. int loc_z = info.getInteger("loc_z");
  131. int heading = info.getInteger("heading");
  132. int hp = info.getInteger("currentHP");
  133. int mp = info.getInteger("currentMP");
  134. L2GrandBossInstance orfen = (L2GrandBossInstance) addSpawn(ORFEN, loc_x, loc_y, loc_z, heading, false, 0);
  135. orfen.setCurrentHpMp(hp, mp);
  136. this.spawnBoss(orfen);
  137. }
  138. }
  139. public void setSpawnPoint(L2Npc npc, int index)
  140. {
  141. ((L2Attackable) npc).clearAggroList();
  142. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  143. L2Spawn spawn = npc.getSpawn();
  144. spawn.setLocx(Pos[index][0]);
  145. spawn.setLocy(Pos[index][1]);
  146. spawn.setLocz(Pos[index][2]);
  147. npc.teleToLocation(Pos[index][0], Pos[index][1], Pos[index][2]);
  148. }
  149. public void spawnBoss(L2GrandBossInstance npc)
  150. {
  151. GrandBossManager.getInstance().addBoss(npc);
  152. npc.broadcastPacket(new PlaySound(1, "BS01_A", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  153. this.startQuestTimer("check_orfen_pos", 10000, npc, null, true);
  154. //Spawn minions
  155. int x = npc.getX();
  156. int y = npc.getY();
  157. L2Attackable mob;
  158. mob = (L2Attackable)addSpawn(RAIKEL_LEOS, x + 100, y + 100, npc.getZ(), 0, false, 0);
  159. mob.setIsRaidMinion(true);
  160. _Minions.add(mob);
  161. mob = (L2Attackable)addSpawn(RAIKEL_LEOS, x + 100, y - 100, npc.getZ(), 0, false, 0);
  162. mob.setIsRaidMinion(true);
  163. _Minions.add(mob);
  164. mob = (L2Attackable)addSpawn(RAIKEL_LEOS, x - 100, y + 100, npc.getZ(), 0, false, 0);
  165. mob.setIsRaidMinion(true);
  166. _Minions.add(mob);
  167. mob = (L2Attackable)addSpawn(RAIKEL_LEOS, x - 100, y - 100, npc.getZ(), 0, false, 0);
  168. mob.setIsRaidMinion(true);
  169. _Minions.add(mob);
  170. this.startQuestTimer("check_minion_loc", 10000, npc, null, true);
  171. }
  172. @Override
  173. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  174. {
  175. if (event.equalsIgnoreCase("orfen_unlock"))
  176. {
  177. int i = Rnd.get(10);
  178. int x = 0;
  179. int y = 0;
  180. int z = 0;
  181. if (i < 4)
  182. {
  183. x = Pos[1][0];
  184. y = Pos[1][1];
  185. z = Pos[1][2];
  186. }
  187. else if (i < 7)
  188. {
  189. x = Pos[2][0];
  190. y = Pos[2][1];
  191. z = Pos[2][2];
  192. }
  193. else
  194. {
  195. x = Pos[3][0];
  196. y = Pos[3][1];
  197. z = Pos[3][2];
  198. }
  199. L2GrandBossInstance orfen = (L2GrandBossInstance) addSpawn(ORFEN, x, y, z, 0, false, 0);
  200. GrandBossManager.getInstance().setBossStatus(ORFEN, ALIVE);
  201. this.spawnBoss(orfen);
  202. }
  203. else if (event.equalsIgnoreCase("check_orfen_pos"))
  204. {
  205. if ((_IsTeleported && npc.getCurrentHp() > npc.getMaxHp() * 0.95) || (!_Zone.isInsideZone(npc) && !_IsTeleported))
  206. {
  207. setSpawnPoint(npc, Rnd.get(3) + 1);
  208. _IsTeleported = false;
  209. }
  210. else if (_IsTeleported && !_Zone.isInsideZone(npc))
  211. setSpawnPoint(npc, 0);
  212. }
  213. else if (event.equalsIgnoreCase("check_minion_loc"))
  214. {
  215. for (int i = 0; i < _Minions.size(); i++)
  216. {
  217. L2Attackable mob = _Minions.get(i);
  218. if (!npc.isInsideRadius(mob, 3000, false, false))
  219. {
  220. mob.teleToLocation(npc.getX(), npc.getY(), npc.getZ());
  221. ((L2Attackable) npc).clearAggroList();
  222. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  223. }
  224. }
  225. }
  226. else if (event.equalsIgnoreCase("despawn_minions"))
  227. {
  228. for (int i = 0; i < _Minions.size(); i++)
  229. {
  230. L2Attackable mob = _Minions.get(i);
  231. if (mob != null)
  232. mob.decayMe();
  233. }
  234. _Minions.clear();
  235. }
  236. else if (event.equalsIgnoreCase("spawn_minion"))
  237. {
  238. L2Attackable mob = (L2Attackable)addSpawn(RAIKEL_LEOS, npc.getX(), npc.getY(), npc.getZ(), 0, false, 0);
  239. mob.setIsRaidMinion(true);
  240. _Minions.add(mob);
  241. }
  242. return super.onAdvEvent(event, npc, player);
  243. }
  244. @Override
  245. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  246. {
  247. if (npc.getNpcId() == ORFEN)
  248. {
  249. L2Character originalCaster = isPet ? caster.getPet() : caster;
  250. if (skill.getAggroPoints() > 0 && Rnd.get(5) == 0 && npc.isInsideRadius(originalCaster, 1000, false, false))
  251. {
  252. NpcSay packet = new NpcSay(npc.getObjectId(), 0, npc.getNpcId(), Text[Rnd.get(4)]);
  253. packet.addStringParameter(caster.getName().toString());
  254. npc.broadcastPacket(packet);
  255. originalCaster.teleToLocation(npc.getX(), npc.getY(), npc.getZ());
  256. npc.setTarget(originalCaster);
  257. npc.doCast(SkillTable.getInstance().getInfo(4064, 1));
  258. }
  259. }
  260. return super.onSkillSee(npc, caster, skill, targets, isPet);
  261. }
  262. @Override
  263. public String onFactionCall(L2Npc npc, L2Npc caller, L2PcInstance attacker, boolean isPet)
  264. {
  265. if (caller == null || npc == null || npc.isCastingNow())
  266. return super.onFactionCall(npc, caller, attacker, isPet);
  267. int npcId = npc.getNpcId();
  268. int callerId = caller.getNpcId();
  269. if (npcId == RAIKEL_LEOS && Rnd.get(20) == 0)
  270. {
  271. npc.setTarget(attacker);
  272. npc.doCast(SkillTable.getInstance().getInfo(4067, 4));
  273. }
  274. else if (npcId == RIBA_IREN)
  275. {
  276. int chance = 1;
  277. if (callerId == ORFEN)
  278. chance = 9;
  279. if (callerId != RIBA_IREN && caller.getCurrentHp() < (caller.getMaxHp() / 2.0) && Rnd.get(10) < chance)
  280. {
  281. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null, null);
  282. npc.setTarget(caller);
  283. npc.doCast(SkillTable.getInstance().getInfo(4516, 1));
  284. }
  285. }
  286. return super.onFactionCall(npc, caller, attacker, isPet);
  287. }
  288. @Override
  289. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  290. {
  291. int npcId = npc.getNpcId();
  292. if (npcId == ORFEN)
  293. {
  294. if (!_IsTeleported && (npc.getCurrentHp() - damage) < (npc.getMaxHp() / 2))
  295. {
  296. _IsTeleported = true;
  297. setSpawnPoint(npc, 0);
  298. }
  299. else if (npc.isInsideRadius(attacker, 1000, false, false) && !npc.isInsideRadius(attacker, 300, false, false) && Rnd.get(10) == 0)
  300. {
  301. NpcSay packet = new NpcSay(npc.getObjectId(), 0, npcId, Text[Rnd.get(3)]);
  302. packet.addStringParameter(attacker.getName().toString());
  303. npc.broadcastPacket(packet);
  304. attacker.teleToLocation(npc.getX(), npc.getY(), npc.getZ());
  305. npc.setTarget(attacker);
  306. npc.doCast(SkillTable.getInstance().getInfo(4064, 1));
  307. }
  308. }
  309. else if (npcId == RIBA_IREN)
  310. {
  311. if (!npc.isCastingNow() && (npc.getCurrentHp() - damage) < (npc.getMaxHp() / 2.0))
  312. {
  313. npc.setTarget(attacker);
  314. npc.doCast(SkillTable.getInstance().getInfo(4516, 1));
  315. }
  316. }
  317. return super.onAttack(npc, attacker, damage, isPet);
  318. }
  319. @Override
  320. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  321. {
  322. if (npc.getNpcId() == ORFEN)
  323. {
  324. npc.broadcastPacket(new PlaySound(1, "BS02_D", 1, npc.getObjectId(), npc.getX(), npc.getY(), npc.getZ()));
  325. GrandBossManager.getInstance().setBossStatus(ORFEN, DEAD);
  326. //time is 48hour +/- 20hour
  327. long respawnTime = (long) Config.Interval_Of_Orfen_Spawn + Rnd.get(Config.Random_Of_Orfen_Spawn);
  328. this.startQuestTimer("orfen_unlock", respawnTime, null, null);
  329. // also save the respawn time so that the info is maintained past reboots
  330. StatsSet info = GrandBossManager.getInstance().getStatsSet(ORFEN);
  331. info.set("respawn_time", System.currentTimeMillis() + respawnTime);
  332. GrandBossManager.getInstance().setStatsSet(ORFEN, info);
  333. this.cancelQuestTimer("check_minion_loc", npc, null);
  334. this.cancelQuestTimer("check_orfen_pos", npc, null);
  335. this.startQuestTimer("despawn_minions", 20000, null, null);
  336. this.cancelQuestTimers("spawn_minion");
  337. }
  338. else if (GrandBossManager.getInstance().getBossStatus(ORFEN) == ALIVE && npc.getNpcId() == RAIKEL_LEOS)
  339. {
  340. _Minions.remove(npc);
  341. this.startQuestTimer("spawn_minion", 360000, npc, null);
  342. }
  343. return super.onKill(npc, killer, isPet);
  344. }
  345. public static void main(String[] args)
  346. {
  347. // Quest class and state definition
  348. new Orfen(-1, "orfen", "ai");
  349. }
  350. }