Orfen.java 12 KB

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