DragonValley.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 java.util.EnumMap;
  21. import ai.npc.AbstractNpcAI;
  22. import com.l2jserver.gameserver.model.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.L2Playable;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.base.ClassId;
  27. import com.l2jserver.gameserver.model.holders.SkillHolder;
  28. import com.l2jserver.gameserver.model.skills.Skill;
  29. import com.l2jserver.gameserver.util.Util;
  30. /**
  31. * Dragon Valley AI.
  32. * @author St3eT
  33. */
  34. public final class DragonValley extends AbstractNpcAI
  35. {
  36. // NPC
  37. private static final int NECROMANCER_OF_THE_VALLEY = 22858;
  38. private static final int EXPLODING_ORC_GHOST = 22818;
  39. private static final int WRATHFUL_ORC_GHOST = 22819;
  40. private static final int DRAKOS_ASSASSIN = 22823;
  41. private static final int[] SUMMON_NPC =
  42. {
  43. 22822, // Drakos Warrior
  44. 22824, // Drakos Guardian
  45. 22862, // Drakos Hunter
  46. };
  47. private static final int[] SPAWN_ANIMATION =
  48. {
  49. 22826, // Scorpion Bones
  50. 22823, // Drakos Assassin
  51. 22828, // Parasitic Leech
  52. };
  53. private static final int[] SPOIL_REACT_MONSTER =
  54. {
  55. 22822, // Drakos Warrior
  56. 22823, // Drakos Assassin
  57. 22824, // Drakos Guardian
  58. 22825, // Giant Scorpion Bones
  59. 22826, // Scorpion Bones
  60. 22827, // Batwing Drake
  61. 22828, // Parasitic Leech
  62. 22829, // Emerald Drake
  63. 22830, // Gem Dragon
  64. 22831, // Dragon Tracker of the Valley
  65. 22832, // Dragon Scout of the Valley
  66. 22833, // Sand Drake Tracker
  67. 22834, // Dust Dragon Tracker
  68. 22860, // Hungry Parasitic Leech
  69. 22861, // Hard Scorpion Bones
  70. 22862, // Drakos Hunter
  71. };
  72. // Items
  73. private static final int GREATER_HERB_OF_MANA = 8604;
  74. private static final int SUPERIOR_HERB_OF_MANA = 8605;
  75. // Skills
  76. private static final SkillHolder SELF_DESTRUCTION = new SkillHolder(6850, 1);
  77. private static final SkillHolder MORALE_BOOST1 = new SkillHolder(6885, 1);
  78. private static final SkillHolder MORALE_BOOST2 = new SkillHolder(6885, 2);
  79. private static final SkillHolder MORALE_BOOST3 = new SkillHolder(6885, 3);
  80. // Misc
  81. private static final int MIN_DISTANCE = 1500;
  82. private static final int MIN_MEMBERS = 3;
  83. private static final int MIN_LVL = 80;
  84. private static final int CLASS_LVL = 3;
  85. private static final EnumMap<ClassId, Double> CLASS_POINTS = new EnumMap<>(ClassId.class);
  86. {
  87. CLASS_POINTS.put(ClassId.adventurer, 0.2);
  88. CLASS_POINTS.put(ClassId.arcanaLord, 1.5);
  89. CLASS_POINTS.put(ClassId.archmage, 0.3);
  90. CLASS_POINTS.put(ClassId.cardinal, -0.6);
  91. CLASS_POINTS.put(ClassId.dominator, 0.2);
  92. CLASS_POINTS.put(ClassId.doombringer, 0.2);
  93. CLASS_POINTS.put(ClassId.doomcryer, 0.1);
  94. CLASS_POINTS.put(ClassId.dreadnought, 0.7);
  95. CLASS_POINTS.put(ClassId.duelist, 0.2);
  96. CLASS_POINTS.put(ClassId.elementalMaster, 1.4);
  97. CLASS_POINTS.put(ClassId.evaSaint, -0.6);
  98. CLASS_POINTS.put(ClassId.evaTemplar, 0.8);
  99. CLASS_POINTS.put(ClassId.femaleSoulhound, 0.4);
  100. CLASS_POINTS.put(ClassId.fortuneSeeker, 0.9);
  101. CLASS_POINTS.put(ClassId.ghostHunter, 0.2);
  102. CLASS_POINTS.put(ClassId.ghostSentinel, 0.2);
  103. CLASS_POINTS.put(ClassId.grandKhavatari, 0.2);
  104. CLASS_POINTS.put(ClassId.hellKnight, 0.6);
  105. CLASS_POINTS.put(ClassId.hierophant, 0.0);
  106. CLASS_POINTS.put(ClassId.judicator, 0.1);
  107. CLASS_POINTS.put(ClassId.moonlightSentinel, 0.2);
  108. CLASS_POINTS.put(ClassId.maestro, 0.7);
  109. CLASS_POINTS.put(ClassId.maleSoulhound, 0.4);
  110. CLASS_POINTS.put(ClassId.mysticMuse, 0.3);
  111. CLASS_POINTS.put(ClassId.phoenixKnight, 0.6);
  112. CLASS_POINTS.put(ClassId.sagittarius, 0.2);
  113. CLASS_POINTS.put(ClassId.shillienSaint, -0.6);
  114. CLASS_POINTS.put(ClassId.shillienTemplar, 0.8);
  115. CLASS_POINTS.put(ClassId.soultaker, 0.3);
  116. CLASS_POINTS.put(ClassId.spectralDancer, 0.4);
  117. CLASS_POINTS.put(ClassId.spectralMaster, 1.4);
  118. CLASS_POINTS.put(ClassId.stormScreamer, 0.3);
  119. CLASS_POINTS.put(ClassId.swordMuse, 0.4);
  120. CLASS_POINTS.put(ClassId.titan, 0.3);
  121. CLASS_POINTS.put(ClassId.trickster, 0.5);
  122. CLASS_POINTS.put(ClassId.windRider, 0.2);
  123. }
  124. private DragonValley()
  125. {
  126. super(DragonValley.class.getSimpleName(), "ai/group_template");
  127. addAttackId(NECROMANCER_OF_THE_VALLEY);
  128. addAttackId(SUMMON_NPC);
  129. addKillId(NECROMANCER_OF_THE_VALLEY);
  130. addKillId(SPOIL_REACT_MONSTER);
  131. addSpawnId(EXPLODING_ORC_GHOST, NECROMANCER_OF_THE_VALLEY);
  132. addSpawnId(SPOIL_REACT_MONSTER);
  133. addSpellFinishedId(EXPLODING_ORC_GHOST);
  134. }
  135. @Override
  136. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  137. {
  138. if (event.equals("SELF_DESTRUCTION") && (npc != null) && !npc.isDead())
  139. {
  140. final L2Playable playable = npc.getVariables().getObject("playable", L2Playable.class);
  141. if ((playable != null) && (npc.calculateDistance(playable, true, false) < 250))
  142. {
  143. npc.disableCoreAI(true);
  144. npc.doCast(SELF_DESTRUCTION.getSkill());
  145. }
  146. else if (playable != null)
  147. {
  148. startQuestTimer("SELF_DESTRUCTION", 3000, npc, null);
  149. }
  150. }
  151. return super.onAdvEvent(event, npc, player);
  152. }
  153. @Override
  154. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  155. {
  156. if (npc.getId() == NECROMANCER_OF_THE_VALLEY)
  157. {
  158. spawnGhost(npc, attacker, isSummon, 1);
  159. }
  160. else
  161. {
  162. if ((npc.getCurrentHp() < (npc.getMaxHp() / 2)) && (getRandom(100) < 5) && npc.isScriptValue(0))
  163. {
  164. npc.setScriptValue(1);
  165. final int rnd = getRandom(3, 5);
  166. for (int i = 0; i < rnd; i++)
  167. {
  168. final L2Playable playable = isSummon ? attacker.getSummon() : attacker;
  169. final L2Attackable minion = (L2Attackable) addSpawn(DRAKOS_ASSASSIN, npc.getX(), npc.getY(), npc.getZ() + 10, npc.getHeading(), true, 0, true);
  170. attackPlayer(minion, playable);
  171. }
  172. }
  173. }
  174. return super.onAttack(npc, attacker, damage, isSummon);
  175. }
  176. @Override
  177. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  178. {
  179. if (npc.getId() == NECROMANCER_OF_THE_VALLEY)
  180. {
  181. spawnGhost(npc, killer, isSummon, 20);
  182. }
  183. else if (((L2Attackable) npc).isSweepActive())
  184. {
  185. npc.dropItem(killer, getRandom(GREATER_HERB_OF_MANA, SUPERIOR_HERB_OF_MANA), 1);
  186. manageMoraleBoost(killer, npc);
  187. }
  188. return super.onKill(npc, killer, isSummon);
  189. }
  190. @Override
  191. public String onSpawn(L2Npc npc)
  192. {
  193. ((L2Attackable) npc).setOnKillDelay(0);
  194. if (npc.getId() == EXPLODING_ORC_GHOST)
  195. {
  196. startQuestTimer("SELF_DESTRUCTION", 3000, npc, null);
  197. }
  198. else if (Util.contains(SPAWN_ANIMATION, npc.getId()))
  199. {
  200. npc.setShowSummonAnimation(true);
  201. }
  202. return super.onSpawn(npc);
  203. }
  204. @Override
  205. public String onSpellFinished(L2Npc npc, L2PcInstance player, Skill skill)
  206. {
  207. if (skill == SELF_DESTRUCTION.getSkill())
  208. {
  209. npc.doDie(player);
  210. }
  211. return super.onSpellFinished(npc, player, skill);
  212. }
  213. private void manageMoraleBoost(L2PcInstance player, L2Npc npc)
  214. {
  215. double points = 0;
  216. int moraleBoostLv = 0;
  217. if (player.isInParty() && (player.getParty().getMemberCount() >= MIN_MEMBERS) && (npc != null))
  218. {
  219. for (L2PcInstance member : player.getParty().getMembers())
  220. {
  221. if ((member.getLevel() >= MIN_LVL) && (member.getClassId().level() >= CLASS_LVL) && (npc.calculateDistance(member, true, false) < MIN_DISTANCE))
  222. {
  223. points += CLASS_POINTS.get(member.getClassId());
  224. }
  225. }
  226. if (points >= 3)
  227. {
  228. moraleBoostLv = 3;
  229. }
  230. else if (points >= 2)
  231. {
  232. moraleBoostLv = 2;
  233. }
  234. else if (points >= 1)
  235. {
  236. moraleBoostLv = 1;
  237. }
  238. for (L2PcInstance member : player.getParty().getMembers())
  239. {
  240. if (npc.calculateDistance(member, true, false) < MIN_DISTANCE)
  241. {
  242. switch (moraleBoostLv)
  243. {
  244. case 1:
  245. MORALE_BOOST1.getSkill().applyEffects(member, member);
  246. break;
  247. case 2:
  248. MORALE_BOOST2.getSkill().applyEffects(member, member);
  249. break;
  250. case 3:
  251. MORALE_BOOST3.getSkill().applyEffects(member, member);
  252. break;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. private void spawnGhost(L2Npc npc, L2PcInstance player, boolean isSummon, int chance)
  259. {
  260. if ((npc.getScriptValue() < 2) && (getRandom(100) < chance))
  261. {
  262. int val = npc.getScriptValue();
  263. final L2Playable attacker = isSummon ? player.getSummon() : player;
  264. final L2Attackable Ghost1 = (L2Attackable) addSpawn(EXPLODING_ORC_GHOST, npc.getX(), npc.getY(), npc.getZ() + 10, npc.getHeading(), false, 0, true);
  265. Ghost1.getVariables().set("playable", attacker);
  266. attackPlayer(Ghost1, attacker);
  267. val++;
  268. if ((val < 2) && (getRandomBoolean()))
  269. {
  270. final L2Attackable Ghost2 = (L2Attackable) addSpawn(WRATHFUL_ORC_GHOST, npc.getX(), npc.getY(), npc.getZ() + 20, npc.getHeading(), false, 0, false);
  271. attackPlayer(Ghost2, attacker);
  272. val++;
  273. }
  274. npc.setScriptValue(val);
  275. }
  276. }
  277. public static void main(String[] args)
  278. {
  279. new DragonValley();
  280. }
  281. }