PrimevalIsle.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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.group_template;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.GeoData;
  22. import com.l2jserver.gameserver.ai.CtrlIntention;
  23. import com.l2jserver.gameserver.handler.IItemHandler;
  24. import com.l2jserver.gameserver.handler.ItemHandler;
  25. import com.l2jserver.gameserver.model.Location;
  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.L2Playable;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.holders.SkillHolder;
  32. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  33. import com.l2jserver.gameserver.model.skills.Skill;
  34. import com.l2jserver.gameserver.network.NpcStringId;
  35. import com.l2jserver.gameserver.network.clientpackets.Say2;
  36. import com.l2jserver.gameserver.util.Util;
  37. /**
  38. * Primeval Isle AI.
  39. * @author St3eT
  40. */
  41. public final class PrimevalIsle extends AbstractNpcAI
  42. {
  43. // NPC
  44. private static final int EGG = 18344; // Ancient Egg
  45. private static final int SAILREN = 29065; // Sailren
  46. private static final int ORNIT = 22742; // Ornithomimus
  47. private static final int DEINO = 22743; // Deinonychus
  48. private static final int[] SPRIGNANT =
  49. {
  50. 18345, // Sprigant (Anesthesia)
  51. 18346, // Sprigant (Deadly Poison)
  52. };
  53. private static final int[] MONSTERS =
  54. {
  55. 22196, // Velociraptor
  56. 22198, // Velociraptor
  57. 22200, // Ornithomimus
  58. 22202, // Ornithomimus
  59. 22203, // Deinonychus
  60. 22205, // Deinonychus
  61. 22208, // Pachycephalosaurus
  62. 22210, // Pachycephalosaurus
  63. 22211, // Wild Strider
  64. 22213, // Wild Strider
  65. 22223, // Velociraptor
  66. 22224, // Ornithomimus
  67. 22225, // Deinonychus
  68. 22226, // Pachycephalosaurus
  69. 22227, // Wild Strider
  70. 22742, // Ornithomimus
  71. 22743, // Deinonychus
  72. };
  73. private static final int[] TREX =
  74. {
  75. 22215, // Tyrannosaurus
  76. 22216, // Tyrannosaurus
  77. 22217, // Tyrannosaurus
  78. };
  79. private static final int[] VEGETABLE =
  80. {
  81. 22200, // Ornithomimus
  82. 22201, // Ornithomimus
  83. 22202, // Ornithomimus
  84. 22203, // Deinonychus
  85. 22204, // Deinonychus
  86. 22205, // Deinonychus
  87. 22224, // Ornithomimus
  88. 22225, // Deinonychus
  89. };
  90. // Item
  91. private static final int DEINONYCHUS = 14828; // Deinonychus Mesozoic Stone
  92. // Skill
  93. private static final SkillHolder ANESTHESIA = new SkillHolder(5085, 1); // Anesthesia
  94. private static final SkillHolder DEADLY_POISON = new SkillHolder(5086, 1); // Deadly Poison
  95. private static final SkillHolder SELFBUFF1 = new SkillHolder(5087, 1); // Berserk
  96. private static final SkillHolder SELFBUFF2 = new SkillHolder(5087, 2); // Berserk
  97. private static final SkillHolder LONGRANGEDMAGIC1 = new SkillHolder(5120, 1); // Stun
  98. private static final SkillHolder PHYSICALSPECIAL1 = new SkillHolder(5083, 4); // Stun
  99. private static final SkillHolder PHYSICALSPECIAL2 = new SkillHolder(5081, 4); // Silence
  100. private static final SkillHolder PHYSICALSPECIAL3 = new SkillHolder(5082, 4); // NPC Spinning, Slashing Trick
  101. private static final SkillHolder CREW_SKILL = new SkillHolder(6172, 1); // Presentation - Tyranno
  102. private static final SkillHolder INVIN_BUFF_ON = new SkillHolder(5225, 1); // Invincible
  103. private PrimevalIsle()
  104. {
  105. super(PrimevalIsle.class.getSimpleName(), "ai/group_template");
  106. addSpawnId(TREX);
  107. addSpawnId(SPRIGNANT);
  108. addSpawnId(MONSTERS);
  109. addAggroRangeEnterId(TREX);
  110. addSpellFinishedId(TREX);
  111. addAttackId(EGG);
  112. addAttackId(TREX);
  113. addAttackId(MONSTERS);
  114. addKillId(EGG, SAILREN, DEINO, ORNIT);
  115. addSeeCreatureId(TREX);
  116. addSeeCreatureId(MONSTERS);
  117. }
  118. @Override
  119. public String onSpellFinished(L2Npc npc, L2PcInstance player, Skill skill)
  120. {
  121. if (skill.getId() == CREW_SKILL.getSkillId())
  122. {
  123. startQuestTimer("START_INVUL", 4000, npc, null);
  124. final L2Npc target = (L2Npc) npc.getTarget();
  125. if (target != null)
  126. {
  127. target.doDie(npc);
  128. }
  129. }
  130. if (npc.isInCombat())
  131. {
  132. final L2Attackable mob = (L2Attackable) npc;
  133. final L2Character target = mob.getMostHated();
  134. if (((npc.getCurrentHp() / npc.getMaxHp()) * 100) < 60)
  135. {
  136. if (skill.getId() == SELFBUFF1.getSkillId())
  137. {
  138. npc.setScriptValue(3);
  139. if ((target != null))
  140. {
  141. npc.setTarget(target);
  142. mob.setIsRunning(true);
  143. mob.addDamageHate(target, 0, 555);
  144. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  145. }
  146. }
  147. }
  148. else if (((npc.getCurrentHp() / npc.getMaxHp()) * 100) < 30)
  149. {
  150. if (skill.getId() == SELFBUFF1.getSkillId())
  151. {
  152. npc.setScriptValue(1);
  153. if ((target != null))
  154. {
  155. npc.setTarget(target);
  156. mob.setIsRunning(true);
  157. mob.addDamageHate(target, 0, 555);
  158. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  159. }
  160. }
  161. else if (skill.getId() == SELFBUFF2.getSkillId())
  162. {
  163. npc.setScriptValue(5);
  164. if ((target != null))
  165. {
  166. npc.setTarget(target);
  167. mob.setIsRunning(true);
  168. mob.addDamageHate(target, 0, 555);
  169. mob.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  170. }
  171. }
  172. }
  173. }
  174. return super.onSpellFinished(npc, player, skill);
  175. }
  176. @Override
  177. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  178. {
  179. switch (event)
  180. {
  181. case "USE_SKILL":
  182. {
  183. if ((npc != null) && !npc.isDead())
  184. {
  185. npc.doCast((npc.getId() == SPRIGNANT[0] ? ANESTHESIA.getSkill() : DEADLY_POISON.getSkill()));
  186. startQuestTimer("USE_SKILL", 15000, npc, null);
  187. }
  188. break;
  189. }
  190. case "GHOST_DESPAWN":
  191. {
  192. if ((npc != null) && !npc.isDead())
  193. {
  194. if (!npc.isInCombat())
  195. {
  196. npc.deleteMe();
  197. }
  198. else
  199. {
  200. startQuestTimer("GHOST_DESPAWN", 1800000, npc, null);
  201. }
  202. }
  203. break;
  204. }
  205. case "TREX_ATTACK":
  206. {
  207. if ((npc != null) && (player != null))
  208. {
  209. npc.setScriptValue(0);
  210. if (player.isInsideRadius(npc, 800, true, false))
  211. {
  212. npc.setTarget(player);
  213. npc.doCast(LONGRANGEDMAGIC1.getSkill());
  214. attackPlayer((L2Attackable) npc, player);
  215. }
  216. }
  217. break;
  218. }
  219. case "START_INVUL":
  220. {
  221. if ((npc != null) && !npc.isDead())
  222. {
  223. npc.doCast(INVIN_BUFF_ON.getSkill());
  224. startQuestTimer("START_INVUL_2", 30000, npc, null);
  225. }
  226. break;
  227. }
  228. case "START_INVUL_2":
  229. {
  230. if ((npc != null) && !npc.isDead())
  231. {
  232. INVIN_BUFF_ON.getSkill().applyEffects(npc, npc);
  233. }
  234. break;
  235. }
  236. }
  237. return super.onAdvEvent(event, npc, player);
  238. }
  239. @Override
  240. public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon)
  241. {
  242. if (Util.contains(MONSTERS, npc.getId()))
  243. {
  244. if (creature.isPlayer())
  245. {
  246. final L2Attackable mob = (L2Attackable) npc;
  247. final int ag_type = npc.getTemplate().getParameters().getInt("ag_type", 0);
  248. final int probPhysicalSpecial1 = npc.getTemplate().getParameters().getInt("ProbPhysicalSpecial1", 0);
  249. final int probPhysicalSpecial2 = npc.getTemplate().getParameters().getInt("ProbPhysicalSpecial2", 0);
  250. final SkillHolder physicalSpecial1 = npc.getTemplate().getParameters().getObject("PhysicalSpecial1", SkillHolder.class);
  251. final SkillHolder physicalSpecial2 = npc.getTemplate().getParameters().getObject("PhysicalSpecial2", SkillHolder.class);
  252. if (((getRandom(100) < 30) && (npc.getId() == DEINO)) || ((npc.getId() == ORNIT) && npc.isScriptValue(0)))
  253. {
  254. mob.clearAggroList();
  255. npc.setScriptValue(1);
  256. npc.setRunning();
  257. final int distance = 3000;
  258. final int heading = Util.calculateHeadingFrom(creature, npc);
  259. final double angle = Util.convertHeadingToDegree(heading);
  260. final double radian = Math.toRadians(angle);
  261. final double sin = Math.sin(radian);
  262. final double cos = Math.cos(radian);
  263. final int newX = (int) (npc.getX() + (cos * distance));
  264. final int newY = (int) (npc.getY() + (sin * distance));
  265. final Location loc = GeoData.getInstance().moveCheck(npc.getX(), npc.getY(), npc.getZ(), newX, newY, npc.getZ(), npc.getInstanceId());
  266. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, loc, 0);
  267. }
  268. else if (ag_type == 1)
  269. {
  270. if (getRandom(100) <= (probPhysicalSpecial1 * npc.getVariables().getInt("SKILL_MULTIPLER")))
  271. {
  272. if (!npc.isSkillDisabled(physicalSpecial1.getSkillId()))
  273. {
  274. npc.setTarget(creature);
  275. npc.doCast(physicalSpecial1.getSkill());
  276. }
  277. }
  278. else if (getRandom(100) <= (probPhysicalSpecial2 * npc.getVariables().getInt("SKILL_MULTIPLER")))
  279. {
  280. if (!npc.isSkillDisabled(physicalSpecial2.getSkill()))
  281. {
  282. npc.setTarget(creature);
  283. npc.doCast(physicalSpecial2.getSkill());
  284. }
  285. }
  286. }
  287. }
  288. }
  289. else if (Util.contains(VEGETABLE, creature.getId()))
  290. {
  291. npc.setTarget(creature);
  292. npc.doCast(CREW_SKILL.getSkill());
  293. npc.setIsRunning(true);
  294. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, creature);
  295. }
  296. return super.onSeeCreature(npc, creature, isSummon);
  297. }
  298. @Override
  299. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isSummon)
  300. {
  301. if (npc.isScriptValue(0))
  302. {
  303. npc.setScriptValue(1);
  304. broadcastNpcSay(npc, Say2.NPC_ALL, "?");
  305. ((L2Attackable) npc).clearAggroList();
  306. startQuestTimer("TREX_ATTACK", 6000, npc, player);
  307. }
  308. return super.onAggroRangeEnter(npc, player, isSummon);
  309. }
  310. @Override
  311. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  312. {
  313. if (npc.getId() == EGG)
  314. {
  315. if ((getRandom(100) <= 80) && npc.isScriptValue(0))
  316. {
  317. npc.setScriptValue(1);
  318. final L2Playable playable = isSummon ? attacker.getSummon() : attacker;
  319. for (L2Character characters : npc.getKnownList().getKnownCharactersInRadius(500))
  320. {
  321. if ((characters != null) && (characters.isAttackable()) && (getRandomBoolean()))
  322. {
  323. L2Attackable monster = (L2Attackable) characters;
  324. attackPlayer(monster, playable);
  325. }
  326. }
  327. }
  328. }
  329. else if (Util.contains(TREX, npc.getId()))
  330. {
  331. final L2Attackable mob = (L2Attackable) npc;
  332. final L2Character target = mob.getMostHated();
  333. if (((npc.getCurrentHp() / npc.getMaxHp()) * 100) <= 30)
  334. {
  335. if (npc.isScriptValue(3))
  336. {
  337. if (!npc.isSkillDisabled(SELFBUFF1.getSkill()))
  338. {
  339. npc.doCast(SELFBUFF1.getSkill());
  340. }
  341. }
  342. else if (npc.isScriptValue(1))
  343. {
  344. if (!npc.isSkillDisabled(SELFBUFF2.getSkill()))
  345. {
  346. npc.doCast(SELFBUFF2.getSkill());
  347. }
  348. }
  349. }
  350. else if ((((npc.getCurrentHp() / npc.getMaxHp()) * 100) <= 60) && (npc.isScriptValue(3)))
  351. {
  352. if (!npc.isSkillDisabled(SELFBUFF1.getSkill()))
  353. {
  354. npc.doCast(SELFBUFF1.getSkill());
  355. }
  356. }
  357. if (Util.calculateDistance(npc, attacker, true, false) > 100)
  358. {
  359. if (!npc.isSkillDisabled(LONGRANGEDMAGIC1.getSkill()) && (getRandom(100) <= (10 * npc.getScriptValue())))
  360. {
  361. npc.setTarget(attacker);
  362. npc.doCast(LONGRANGEDMAGIC1.getSkill());
  363. }
  364. }
  365. else
  366. {
  367. if (!npc.isSkillDisabled(LONGRANGEDMAGIC1.getSkill()) && (getRandom(100) <= (10 * npc.getScriptValue())))
  368. {
  369. npc.setTarget(target);
  370. npc.doCast(LONGRANGEDMAGIC1.getSkill());
  371. }
  372. if (!npc.isSkillDisabled(PHYSICALSPECIAL1.getSkill()) && (getRandom(100) <= (5 * npc.getScriptValue())))
  373. {
  374. npc.setTarget(target);
  375. npc.doCast(PHYSICALSPECIAL1.getSkill());
  376. }
  377. if (!npc.isSkillDisabled(PHYSICALSPECIAL2.getSkill()) && (getRandom(100) <= (3 * npc.getScriptValue())))
  378. {
  379. npc.setTarget(target);
  380. npc.doCast(PHYSICALSPECIAL2.getSkill());
  381. }
  382. if (!npc.isSkillDisabled(PHYSICALSPECIAL3.getSkill()) && (getRandom(100) <= (5 * npc.getScriptValue())))
  383. {
  384. npc.setTarget(target);
  385. npc.doCast(PHYSICALSPECIAL3.getSkill());
  386. }
  387. }
  388. }
  389. else
  390. {
  391. L2Character target = null;
  392. final int probPhysicalSpecial1 = npc.getTemplate().getParameters().getInt("ProbPhysicalSpecial1", 0);
  393. final int probPhysicalSpecial2 = npc.getTemplate().getParameters().getInt("ProbPhysicalSpecial2", 0);
  394. final SkillHolder selfRangeBuff1 = npc.getTemplate().getParameters().getObject("SelfRangeBuff1", SkillHolder.class);
  395. final SkillHolder physicalSpecial1 = npc.getTemplate().getParameters().getObject("PhysicalSpecial1", SkillHolder.class);
  396. final SkillHolder physicalSpecial2 = npc.getTemplate().getParameters().getObject("PhysicalSpecial2", SkillHolder.class);
  397. if (((npc.getCurrentHp() / npc.getMaxHp()) * 100) <= 50)
  398. {
  399. npc.getVariables().set("SKILL_MULTIPLER", 2);
  400. }
  401. else
  402. {
  403. npc.getVariables().set("SKILL_MULTIPLER", 1);
  404. }
  405. if ((((npc.getCurrentHp() / npc.getMaxHp()) * 100) <= 30) && (npc.getVariables().getInt("SELFBUFF_USED") == 0))
  406. {
  407. final L2Attackable mob = (L2Attackable) npc;
  408. target = mob.getMostHated();
  409. mob.clearAggroList();
  410. if (!npc.isSkillDisabled(selfRangeBuff1.getSkillId()))
  411. {
  412. npc.getVariables().set("SELFBUFF_USED", 1);
  413. npc.doCast(selfRangeBuff1.getSkill());
  414. npc.setIsRunning(true);
  415. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
  416. }
  417. }
  418. if (target != null)
  419. {
  420. if (getRandom(100) <= (probPhysicalSpecial1 * npc.getVariables().getInt("SKILL_MULTIPLER")))
  421. {
  422. if (!npc.isSkillDisabled(physicalSpecial1.getSkill()))
  423. {
  424. npc.setTarget(target);
  425. npc.doCast(physicalSpecial1.getSkill());
  426. }
  427. }
  428. if (getRandom(100) <= (probPhysicalSpecial2 * npc.getVariables().getInt("SKILL_MULTIPLER")))
  429. {
  430. if (!npc.isSkillDisabled(physicalSpecial2.getSkill()))
  431. {
  432. npc.setTarget(target);
  433. npc.doCast(physicalSpecial2.getSkill());
  434. }
  435. }
  436. }
  437. }
  438. return super.onAttack(npc, attacker, damage, isSummon);
  439. }
  440. @Override
  441. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  442. {
  443. if ((npc.getId() == DEINO) || ((npc.getId() == ORNIT) && !npc.isScriptValue(1)))
  444. {
  445. return super.onKill(npc, killer, isSummon);
  446. }
  447. if ((npc.getId() == SAILREN) || (getRandom(100) < 3))
  448. {
  449. final L2PcInstance player = npc.getId() == SAILREN ? getRandomPartyMember(killer) : killer;
  450. if (player.getInventory().getSize(false) <= (player.getInventoryLimit() * 0.8))
  451. {
  452. giveItems(player, DEINONYCHUS, 1);
  453. final L2ItemInstance summonItem = player.getInventory().getItemByItemId(DEINONYCHUS);
  454. final IItemHandler handler = ItemHandler.getInstance().getHandler(summonItem.getEtcItem());
  455. if ((handler != null) && !player.hasPet())
  456. {
  457. handler.useItem(player, summonItem, true);
  458. }
  459. showOnScreenMsg(player, NpcStringId.LIFE_STONE_FROM_THE_BEGINNING_ACQUIRED, 2, 6000);
  460. }
  461. else
  462. {
  463. showOnScreenMsg(player, NpcStringId.WHEN_INVENTORY_WEIGHT_NUMBER_ARE_MORE_THAN_80_THE_LIFE_STONE_FROM_THE_BEGINNING_CANNOT_BE_ACQUIRED, 2, 6000);
  464. }
  465. }
  466. return super.onKill(npc, killer, isSummon);
  467. }
  468. @Override
  469. public String onSpawn(L2Npc npc)
  470. {
  471. if (Util.contains(SPRIGNANT, npc.getId()))
  472. {
  473. startQuestTimer("USE_SKILL", 15000, npc, null);
  474. }
  475. else if (Util.contains(TREX, npc.getId()))
  476. {
  477. final int collectGhost = npc.getTemplate().getParameters().getInt("CollectGhost", 0);
  478. final int collectDespawn = npc.getTemplate().getParameters().getInt("CollectGhostDespawnTime", 30);
  479. if (collectGhost == 1)
  480. {
  481. startQuestTimer("GHOST_DESPAWN", collectDespawn * 60000, npc, null);
  482. }
  483. }
  484. else
  485. {
  486. npc.getVariables().set("SELFBUFF_USED", 0);
  487. npc.getVariables().set("SKILL_MULTIPLER", 1);
  488. }
  489. return super.onSpawn(npc);
  490. }
  491. public static void main(String[] args)
  492. {
  493. new PrimevalIsle();
  494. }
  495. }