Orfen.java 12 KB

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