SupportUnitCaptain.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright (C) 2004-2015 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.npc.SupportUnitCaptain;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.model.ClanPrivilege;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.clientpackets.RequestAcquireSkill;
  25. /**
  26. * Support Unit Captain AI.
  27. * @author St3eT
  28. */
  29. public final class SupportUnitCaptain extends AbstractNpcAI
  30. {
  31. // NPCs
  32. private static final int[] UNIT_CAPTAIN =
  33. {
  34. 35662, // Shanty Fortress
  35. 35694, // Southern Fortress
  36. 35731, // Hive Fortress
  37. 35763, // Valley Fortress
  38. 35800, // Ivory Fortress
  39. 35831, // Narsell Fortress
  40. 35863, // Bayou Fortress
  41. 35900, // White Sands Fortress
  42. 35932, // Borderland Fortress
  43. 35970, // Swamp Fortress
  44. 36007, // Archaic Fortress
  45. 36039, // Floran Fortress
  46. 36077, // Cloud Mountain
  47. 36114, // Tanor Fortress
  48. 36145, // Dragonspine Fortress
  49. 36177, // Antharas's Fortress
  50. 36215, // Western Fortress
  51. 36253, // Hunter's Fortress
  52. 36290, // Aaru Fortress
  53. 36322, // Demon Fortress
  54. 36360, // Monastic Fortress
  55. };
  56. // Items
  57. private static final int EPAULETTE = 9912; // Knight's Epaulette
  58. private static final int RED_MEDITATION = 9931; // Red Talisman of Meditation
  59. private static final int BLUE_DIV_PROTECTION = 9932; // Blue Talisman - Divine Protection
  60. private static final int BLUE_EXPLOSION = 10416; // Blue Talisman - Explosion
  61. private static final int BLUE_M_EXPLOSION = 10417; // Blue Talisman - Magic Explosion
  62. private static final int RED_MIN_CLARITY = 9917; // Red Talisman of Minimum Clarity
  63. private static final int RED_MAX_CLARITY = 9918; // Red Talisman of Maximum Clarity
  64. private static final int RED_MENTAL_REG = 9928; // Red Talisman of Mental Regeneration
  65. private static final int BLUE_PROTECTION = 9929; // Blue Talisman of Protection
  66. private static final int BLUE_INVIS = 9920; // Blue Talisman of Invisibility
  67. private static final int BLUE_DEFENSE = 9916; // Blue Talisman of Defense
  68. private static final int BLACK_ESCAPE = 9923; // Black Talisman - Escape
  69. private static final int BLUE_HEALING = 9924; // Blue Talisman of Healing
  70. private static final int RED_RECOVERY = 9925; // Red Talisman of Recovery
  71. private static final int BLUE_DEFENSE2 = 9926; // Blue Talisman of Defense
  72. private static final int BLUE_M_DEFENSE = 9927; // Blue Talisman of Magic Defense
  73. private static final int RED_LIFE_FORCE = 10518; // Red Talisman - Life Force
  74. private static final int BLUE_GREAT_HEALING = 10424; // Blue Talisman - Greater Healing
  75. private static final int WHITE_FIRE = 10421; // White Talisman - Fire
  76. private static final int[] COMMON_TALISMANS =
  77. {
  78. 9914, // Blue Talisman of Power
  79. 9915, // Blue Talisman of Wild Magic
  80. 9920, // Blue Talisman of Invisibility
  81. 9921, // Blue Talisman - Shield Protection
  82. 9922, // Black Talisman - Mending
  83. 9933, // Yellow Talisman of Power
  84. 9934, // Yellow Talisman of Violent Haste
  85. 9935, // Yellow Talisman of Arcane Defense
  86. 9936, // Yellow Talisman of Arcane Power
  87. 9937, // Yellow Talisman of Arcane Haste
  88. 9938, // Yellow Talisman of Accuracy
  89. 9939, // Yellow Talisman of Defense
  90. 9940, // Yellow Talisman of Alacrity
  91. 9941, // Yellow Talisman of Speed
  92. 9942, // Yellow Talisman of Critical Reduction
  93. 9943, // Yellow Talisman of Critical Damage
  94. 9944, // Yellow Talisman of Critical Dodging
  95. 9945, // Yellow Talisman of Evasion
  96. 9946, // Yellow Talisman of Healing
  97. 9947, // Yellow Talisman of CP Regeneration
  98. 9948, // Yellow Talisman of Physical Regeneration
  99. 9949, // Yellow Talisman of Mental Regeneration
  100. 9950, // Grey Talisman of Weight Training
  101. 9952, // Orange Talisman - Hot Springs CP Potion
  102. 9953, // Orange Talisman - Elixir of Life
  103. 9954, // Orange Talisman - Elixir of Mental Strength
  104. 9955, // Black Talisman - Vocalization
  105. 9956, // Black Talisman - Arcane Freedom
  106. 9957, // Black Talisman - Physical Freedom
  107. 9958, // Black Talisman - Rescue
  108. 9959, // Black Talisman - Free Speech
  109. 9960, // White Talisman of Bravery
  110. 9961, // White Talisman of Motion
  111. 9962, // White Talisman of Grounding
  112. 9963, // White Talisman of Attention
  113. 9964, // White Talisman of Bandages
  114. 9965, // White Talisman of Protection
  115. 10418, // White Talisman - Storm
  116. 10420, // White Talisman - Water
  117. 10519, // White Talisman - Earth
  118. 10422, // White Talisman - Light
  119. 10423, // Blue Talisman - Self-Destruction
  120. };
  121. private SupportUnitCaptain()
  122. {
  123. super(SupportUnitCaptain.class.getSimpleName(), "ai/npc");
  124. addStartNpc(UNIT_CAPTAIN);
  125. addTalkId(UNIT_CAPTAIN);
  126. addFirstTalkId(UNIT_CAPTAIN);
  127. }
  128. @Override
  129. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  130. {
  131. final int fortOwner = npc.getFort().getOwnerClan() == null ? 0 : npc.getFort().getOwnerClan().getId();
  132. if ((player.getClan() == null) || (player.getClanId() != fortOwner))
  133. {
  134. return "unitcaptain-04.html";
  135. }
  136. String htmltext = null;
  137. int itemId = 0;
  138. switch (event)
  139. {
  140. case "unitcaptain.html":
  141. case "unitcaptain-01.html":
  142. {
  143. htmltext = event;
  144. break;
  145. }
  146. case "giveTalisman":
  147. {
  148. if (getQuestItemsCount(player, EPAULETTE) < 10)
  149. {
  150. htmltext = "unitcaptain-05.html";
  151. break;
  152. }
  153. final int categoryChance = getRandom(100);
  154. if (categoryChance <= 5)
  155. {
  156. final int chance = getRandom(100);
  157. if (chance <= 25)
  158. {
  159. itemId = RED_MEDITATION;
  160. }
  161. else if (chance <= 50)
  162. {
  163. itemId = BLUE_DIV_PROTECTION;
  164. }
  165. else if (chance <= 75)
  166. {
  167. itemId = BLUE_EXPLOSION;
  168. }
  169. else
  170. {
  171. itemId = BLUE_M_EXPLOSION;
  172. }
  173. }
  174. else if (categoryChance <= 15)
  175. {
  176. final int chance = getRandom(100);
  177. if (chance <= 20)
  178. {
  179. itemId = RED_MIN_CLARITY;
  180. }
  181. else if (chance <= 40)
  182. {
  183. itemId = RED_MAX_CLARITY;
  184. }
  185. else if (chance <= 60)
  186. {
  187. itemId = RED_MENTAL_REG;
  188. }
  189. else if (chance <= 80)
  190. {
  191. itemId = BLUE_PROTECTION;
  192. }
  193. else
  194. {
  195. itemId = BLUE_INVIS;
  196. }
  197. }
  198. else if (categoryChance <= 30)
  199. {
  200. final int chance = getRandom(100);
  201. if (chance <= 12)
  202. {
  203. itemId = BLUE_DEFENSE;
  204. }
  205. else if (chance <= 25)
  206. {
  207. itemId = BLACK_ESCAPE;
  208. }
  209. else if (chance <= 37)
  210. {
  211. itemId = BLUE_HEALING;
  212. }
  213. else if (chance <= 50)
  214. {
  215. itemId = RED_RECOVERY;
  216. }
  217. else if (chance <= 62)
  218. {
  219. itemId = BLUE_DEFENSE2;
  220. }
  221. else if (chance <= 75)
  222. {
  223. itemId = BLUE_M_DEFENSE;
  224. }
  225. else if (chance <= 87)
  226. {
  227. itemId = RED_LIFE_FORCE;
  228. }
  229. else
  230. {
  231. itemId = BLUE_GREAT_HEALING;
  232. }
  233. }
  234. else
  235. {
  236. final int chance = getRandom(46);
  237. if (chance <= 41)
  238. {
  239. itemId = COMMON_TALISMANS[chance];
  240. }
  241. else
  242. {
  243. itemId = WHITE_FIRE;
  244. }
  245. }
  246. takeItems(player, EPAULETTE, 10);
  247. giveItems(player, itemId, 1);
  248. htmltext = "unitcaptain-02.html";
  249. break;
  250. }
  251. case "squadSkill":
  252. {
  253. if (player.isClanLeader() || player.hasClanPrivilege(ClanPrivilege.CL_TROOPS_FAME))
  254. {
  255. RequestAcquireSkill.showSubUnitSkillList(player);
  256. }
  257. else
  258. {
  259. htmltext = "unitcaptain-03.html";
  260. }
  261. break;
  262. }
  263. }
  264. return htmltext;
  265. }
  266. @Override
  267. public String onFirstTalk(L2Npc npc, L2PcInstance player)
  268. {
  269. final int fortOwner = npc.getFort().getOwnerClan() == null ? 0 : npc.getFort().getOwnerClan().getId();
  270. return ((player.getClan() != null) && (player.getClanId() == fortOwner)) ? "unitcaptain.html" : "unitcaptain-04.html";
  271. }
  272. public static void main(String[] args)
  273. {
  274. new SupportUnitCaptain();
  275. }
  276. }