FeedableBeasts.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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.group_template;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import java.util.concurrent.ConcurrentHashMap;
  23. import quests.Q00020_BringUpWithLove.Q00020_BringUpWithLove;
  24. import quests.Q00655_AGrandPlanForTamingWildBeasts.Q00655_AGrandPlanForTamingWildBeasts;
  25. import ai.npc.AbstractNpcAI;
  26. import com.l2jserver.gameserver.ai.CtrlIntention;
  27. import com.l2jserver.gameserver.model.L2Object;
  28. import com.l2jserver.gameserver.model.actor.L2Attackable;
  29. import com.l2jserver.gameserver.model.actor.L2Npc;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.actor.instance.L2TamedBeastInstance;
  32. import com.l2jserver.gameserver.model.skills.Skill;
  33. import com.l2jserver.gameserver.network.NpcStringId;
  34. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  35. import com.l2jserver.gameserver.util.Util;
  36. /**
  37. * Growth-capable mobs: Polymorphing upon successful feeding.
  38. * @author Fulminus
  39. */
  40. public final class FeedableBeasts extends AbstractNpcAI
  41. {
  42. private static final int GOLDEN_SPICE = 6643;
  43. private static final int CRYSTAL_SPICE = 6644;
  44. private static final int SKILL_GOLDEN_SPICE = 2188;
  45. private static final int SKILL_CRYSTAL_SPICE = 2189;
  46. private static final int FOODSKILLDIFF = GOLDEN_SPICE - SKILL_GOLDEN_SPICE;
  47. // Tamed Wild Beasts
  48. private static final int TRAINED_BUFFALO1 = 16013;
  49. private static final int TRAINED_BUFFALO2 = 16014;
  50. private static final int TRAINED_COUGAR1 = 16015;
  51. private static final int TRAINED_COUGAR2 = 16016;
  52. private static final int TRAINED_KOOKABURRA1 = 16017;
  53. private static final int TRAINED_KOOKABURRA2 = 16018;
  54. // private static final int TRAINED_TINY_BABY_BUFFALO = 16020; // TODO: Implement.
  55. // private static final int TRAINED_TINY_BABY_COUGAR = 16022; // TODO: Implement.
  56. // private static final int TRAINED_TINY_BABY_KOOKABURRA = 16024; // TODO: Implement.
  57. // @formatter:off
  58. private static final int[] TAMED_BEASTS =
  59. {
  60. TRAINED_BUFFALO1, TRAINED_BUFFALO2, TRAINED_COUGAR1, TRAINED_COUGAR2, TRAINED_KOOKABURRA1, TRAINED_KOOKABURRA2
  61. };
  62. // all mobs that can eat...
  63. private static final int[] FEEDABLE_BEASTS =
  64. {
  65. 21451, 21452, 21453, 21454, 21455, 21456, 21457, 21458, 21459, 21460,
  66. 21461, 21462, 21463, 21464, 21465, 21466, 21467, 21468, 21469, 21470,
  67. 21471, 21472, 21473, 21474, 21475, 21476, 21477, 21478, 21479, 21480,
  68. 21481, 21482, 21483, 21484, 21485, 21486, 21487, 21488, 21489, 21490,
  69. 21491, 21492, 21493, 21494, 21495, 21496, 21497, 21498, 21499, 21500,
  70. 21501, 21502, 21503, 21504, 21505, 21506, 21507, 21824, 21825, 21826,
  71. 21827, 21828, 21829, TRAINED_BUFFALO1, TRAINED_BUFFALO2, TRAINED_COUGAR1, TRAINED_COUGAR2, TRAINED_KOOKABURRA1, TRAINED_KOOKABURRA2
  72. };
  73. // @formatter:on
  74. private static final Map<Integer, Integer> MAD_COW_POLYMORPH = new HashMap<>();
  75. static
  76. {
  77. MAD_COW_POLYMORPH.put(21824, 21468);
  78. MAD_COW_POLYMORPH.put(21825, 21469);
  79. MAD_COW_POLYMORPH.put(21826, 21487);
  80. MAD_COW_POLYMORPH.put(21827, 21488);
  81. MAD_COW_POLYMORPH.put(21828, 21506);
  82. MAD_COW_POLYMORPH.put(21829, 21507);
  83. }
  84. private static final NpcStringId[][] TEXT =
  85. {
  86. {
  87. NpcStringId.WHAT_DID_YOU_JUST_DO_TO_ME,
  88. NpcStringId.ARE_YOU_TRYING_TO_TAME_ME_DONT_DO_THAT,
  89. NpcStringId.DONT_GIVE_SUCH_A_THING_YOU_CAN_ENDANGER_YOURSELF,
  90. NpcStringId.YUCK_WHAT_IS_THIS_IT_TASTES_TERRIBLE,
  91. NpcStringId.IM_HUNGRY_GIVE_ME_A_LITTLE_MORE_PLEASE,
  92. NpcStringId.WHAT_IS_THIS_IS_THIS_EDIBLE,
  93. NpcStringId.DONT_WORRY_ABOUT_ME,
  94. NpcStringId.THANK_YOU_THAT_WAS_DELICIOUS,
  95. NpcStringId.I_THINK_I_AM_STARTING_TO_LIKE_YOU,
  96. NpcStringId.EEEEEK_EEEEEK
  97. },
  98. {
  99. NpcStringId.DONT_KEEP_TRYING_TO_TAME_ME_I_DONT_WANT_TO_BE_TAMED,
  100. NpcStringId.IT_IS_JUST_FOOD_TO_ME_ALTHOUGH_IT_MAY_ALSO_BE_YOUR_HAND,
  101. NpcStringId.IF_I_KEEP_EATING_LIKE_THIS_WONT_I_BECOME_FAT_CHOMP_CHOMP,
  102. NpcStringId.WHY_DO_YOU_KEEP_FEEDING_ME,
  103. NpcStringId.DONT_TRUST_ME_IM_AFRAID_I_MAY_BETRAY_YOU_LATER
  104. },
  105. {
  106. NpcStringId.GRRRRR,
  107. NpcStringId.YOU_BROUGHT_THIS_UPON_YOURSELF,
  108. NpcStringId.I_FEEL_STRANGE_I_KEEP_HAVING_THESE_EVIL_THOUGHTS,
  109. NpcStringId.ALAS_SO_THIS_IS_HOW_IT_ALL_ENDS,
  110. NpcStringId.I_DONT_FEEL_SO_GOOD_OH_MY_MIND_IS_VERY_TROUBLED
  111. }
  112. };
  113. private static final NpcStringId[] TAMED_TEXT =
  114. {
  115. NpcStringId.S1_SO_WHAT_DO_YOU_THINK_IT_IS_LIKE_TO_BE_TAMED,
  116. NpcStringId.S1_WHENEVER_I_SEE_SPICE_I_THINK_I_WILL_MISS_YOUR_HAND_THAT_USED_TO_FEED_IT_TO_ME,
  117. NpcStringId.S1_DONT_GO_TO_THE_VILLAGE_I_DONT_HAVE_THE_STRENGTH_TO_FOLLOW_YOU,
  118. NpcStringId.THANK_YOU_FOR_TRUSTING_ME_S1_I_HOPE_I_WILL_BE_HELPFUL_TO_YOU,
  119. NpcStringId.S1_WILL_I_BE_ABLE_TO_HELP_YOU,
  120. NpcStringId.I_GUESS_ITS_JUST_MY_ANIMAL_MAGNETISM,
  121. NpcStringId.TOO_MUCH_SPICY_FOOD_MAKES_ME_SWEAT_LIKE_A_BEAST,
  122. NpcStringId.ANIMALS_NEED_LOVE_TOO
  123. };
  124. private static final Map<Integer, Integer> FEED_INFO = new ConcurrentHashMap<>();
  125. private static final Map<Integer, GrowthCapableMob> GROWTH_CAPABLE_MONSTERS = new HashMap<>();
  126. // all mobs that grow by eating
  127. private static class GrowthCapableMob
  128. {
  129. private final int _growthLevel;
  130. private final int _chance;
  131. private final Map<Integer, int[][]> _spiceToMob = new HashMap<>();
  132. public GrowthCapableMob(int growthLevel, int chance)
  133. {
  134. _growthLevel = growthLevel;
  135. _chance = chance;
  136. }
  137. public void addMobs(int spice, int[][] Mobs)
  138. {
  139. _spiceToMob.put(spice, Mobs);
  140. }
  141. public Integer getMob(int spice, int mobType, int classType)
  142. {
  143. if (_spiceToMob.containsKey(spice))
  144. {
  145. return _spiceToMob.get(spice)[mobType][classType];
  146. }
  147. return null;
  148. }
  149. public Integer getRandomMob(int spice)
  150. {
  151. int[][] temp;
  152. temp = _spiceToMob.get(spice);
  153. int rand = getRandom(temp[0].length);
  154. return temp[0][rand];
  155. }
  156. public Integer getChance()
  157. {
  158. return _chance;
  159. }
  160. public Integer getGrowthLevel()
  161. {
  162. return _growthLevel;
  163. }
  164. }
  165. private FeedableBeasts()
  166. {
  167. super(FeedableBeasts.class.getSimpleName(), "ai/group_template");
  168. addKillId(FEEDABLE_BEASTS);
  169. addSkillSeeId(FEEDABLE_BEASTS);
  170. // TODO: no grendels?
  171. GrowthCapableMob temp;
  172. //@formatter:off
  173. final int[][] Kookabura_0_Gold = {{ 21452, 21453, 21454, 21455 }};
  174. final int[][] Kookabura_0_Crystal = {{ 21456, 21457, 21458, 21459 }};
  175. final int[][] Kookabura_1_Gold_1= {{ 21460, 21462 }};
  176. final int[][] Kookabura_1_Gold_2 = {{ 21461, 21463 }};
  177. final int[][] Kookabura_1_Crystal_1 = {{ 21464, 21466 }};
  178. final int[][] Kookabura_1_Crystal_2 = {{ 21465, 21467 }};
  179. final int[][] Kookabura_2_1 = {{ 21468, 21824}, { TRAINED_KOOKABURRA1, TRAINED_KOOKABURRA2 }};
  180. final int[][] Kookabura_2_2 = {{ 21469, 21825}, { TRAINED_KOOKABURRA1, TRAINED_KOOKABURRA2 }};
  181. final int[][] Buffalo_0_Gold = {{ 21471, 21472, 21473, 21474 }};
  182. final int[][] Buffalo_0_Crystal = {{ 21475, 21476, 21477, 21478 }};
  183. final int[][] Buffalo_1_Gold_1 = {{ 21479, 21481 }};
  184. final int[][] Buffalo_1_Gold_2 = {{ 21481, 21482 }};
  185. final int[][] Buffalo_1_Crystal_1 = {{ 21483, 21485 }};
  186. final int[][] Buffalo_1_Crystal_2 = {{ 21484, 21486 }};
  187. final int[][] Buffalo_2_1 = {{ 21487, 21826}, {TRAINED_BUFFALO1, TRAINED_BUFFALO2 }};
  188. final int[][] Buffalo_2_2 = {{ 21488, 21827}, {TRAINED_BUFFALO1, TRAINED_BUFFALO2 }};
  189. final int[][] Cougar_0_Gold = {{ 21490, 21491, 21492, 21493 }};
  190. final int[][] Cougar_0_Crystal = {{ 21494, 21495, 21496, 21497 }};
  191. final int[][] Cougar_1_Gold_1 = {{ 21498, 21500 }};
  192. final int[][] Cougar_1_Gold_2 = {{ 21499, 21501 }};
  193. final int[][] Cougar_1_Crystal_1 = {{ 21502, 21504 }};
  194. final int[][] Cougar_1_Crystal_2 = {{ 21503, 21505 }};
  195. final int[][] Cougar_2_1 = {{ 21506, 21828 }, { TRAINED_COUGAR1, TRAINED_COUGAR2 }};
  196. final int[][] Cougar_2_2 = {{ 21507, 21829 }, { TRAINED_COUGAR1, TRAINED_COUGAR2 }};
  197. //@formatter:on
  198. // Alpen Kookabura
  199. temp = new GrowthCapableMob(0, 100);
  200. temp.addMobs(GOLDEN_SPICE, Kookabura_0_Gold);
  201. temp.addMobs(CRYSTAL_SPICE, Kookabura_0_Crystal);
  202. GROWTH_CAPABLE_MONSTERS.put(21451, temp);
  203. temp = new GrowthCapableMob(1, 40);
  204. temp.addMobs(GOLDEN_SPICE, Kookabura_1_Gold_1);
  205. GROWTH_CAPABLE_MONSTERS.put(21452, temp);
  206. GROWTH_CAPABLE_MONSTERS.put(21454, temp);
  207. temp = new GrowthCapableMob(1, 40);
  208. temp.addMobs(GOLDEN_SPICE, Kookabura_1_Gold_2);
  209. GROWTH_CAPABLE_MONSTERS.put(21453, temp);
  210. GROWTH_CAPABLE_MONSTERS.put(21455, temp);
  211. temp = new GrowthCapableMob(1, 40);
  212. temp.addMobs(CRYSTAL_SPICE, Kookabura_1_Crystal_1);
  213. GROWTH_CAPABLE_MONSTERS.put(21456, temp);
  214. GROWTH_CAPABLE_MONSTERS.put(21458, temp);
  215. temp = new GrowthCapableMob(1, 40);
  216. temp.addMobs(CRYSTAL_SPICE, Kookabura_1_Crystal_2);
  217. GROWTH_CAPABLE_MONSTERS.put(21457, temp);
  218. GROWTH_CAPABLE_MONSTERS.put(21459, temp);
  219. temp = new GrowthCapableMob(2, 25);
  220. temp.addMobs(GOLDEN_SPICE, Kookabura_2_1);
  221. GROWTH_CAPABLE_MONSTERS.put(21460, temp);
  222. GROWTH_CAPABLE_MONSTERS.put(21462, temp);
  223. temp = new GrowthCapableMob(2, 25);
  224. temp.addMobs(GOLDEN_SPICE, Kookabura_2_2);
  225. GROWTH_CAPABLE_MONSTERS.put(21461, temp);
  226. GROWTH_CAPABLE_MONSTERS.put(21463, temp);
  227. temp = new GrowthCapableMob(2, 25);
  228. temp.addMobs(CRYSTAL_SPICE, Kookabura_2_1);
  229. GROWTH_CAPABLE_MONSTERS.put(21464, temp);
  230. GROWTH_CAPABLE_MONSTERS.put(21466, temp);
  231. temp = new GrowthCapableMob(2, 25);
  232. temp.addMobs(CRYSTAL_SPICE, Kookabura_2_2);
  233. GROWTH_CAPABLE_MONSTERS.put(21465, temp);
  234. GROWTH_CAPABLE_MONSTERS.put(21467, temp);
  235. // Alpen Buffalo
  236. temp = new GrowthCapableMob(0, 100);
  237. temp.addMobs(GOLDEN_SPICE, Buffalo_0_Gold);
  238. temp.addMobs(CRYSTAL_SPICE, Buffalo_0_Crystal);
  239. GROWTH_CAPABLE_MONSTERS.put(21470, temp);
  240. temp = new GrowthCapableMob(1, 40);
  241. temp.addMobs(GOLDEN_SPICE, Buffalo_1_Gold_1);
  242. GROWTH_CAPABLE_MONSTERS.put(21471, temp);
  243. GROWTH_CAPABLE_MONSTERS.put(21473, temp);
  244. temp = new GrowthCapableMob(1, 40);
  245. temp.addMobs(GOLDEN_SPICE, Buffalo_1_Gold_2);
  246. GROWTH_CAPABLE_MONSTERS.put(21472, temp);
  247. GROWTH_CAPABLE_MONSTERS.put(21474, temp);
  248. temp = new GrowthCapableMob(1, 40);
  249. temp.addMobs(CRYSTAL_SPICE, Buffalo_1_Crystal_1);
  250. GROWTH_CAPABLE_MONSTERS.put(21475, temp);
  251. GROWTH_CAPABLE_MONSTERS.put(21477, temp);
  252. temp = new GrowthCapableMob(1, 40);
  253. temp.addMobs(CRYSTAL_SPICE, Buffalo_1_Crystal_2);
  254. GROWTH_CAPABLE_MONSTERS.put(21476, temp);
  255. GROWTH_CAPABLE_MONSTERS.put(21478, temp);
  256. temp = new GrowthCapableMob(2, 25);
  257. temp.addMobs(GOLDEN_SPICE, Buffalo_2_1);
  258. GROWTH_CAPABLE_MONSTERS.put(21479, temp);
  259. GROWTH_CAPABLE_MONSTERS.put(21481, temp);
  260. temp = new GrowthCapableMob(2, 25);
  261. temp.addMobs(GOLDEN_SPICE, Buffalo_2_2);
  262. GROWTH_CAPABLE_MONSTERS.put(21480, temp);
  263. GROWTH_CAPABLE_MONSTERS.put(21482, temp);
  264. temp = new GrowthCapableMob(2, 25);
  265. temp.addMobs(CRYSTAL_SPICE, Buffalo_2_1);
  266. GROWTH_CAPABLE_MONSTERS.put(21483, temp);
  267. GROWTH_CAPABLE_MONSTERS.put(21485, temp);
  268. temp = new GrowthCapableMob(2, 25);
  269. temp.addMobs(CRYSTAL_SPICE, Buffalo_2_2);
  270. GROWTH_CAPABLE_MONSTERS.put(21484, temp);
  271. GROWTH_CAPABLE_MONSTERS.put(21486, temp);
  272. // Alpen Cougar
  273. temp = new GrowthCapableMob(0, 100);
  274. temp.addMobs(GOLDEN_SPICE, Cougar_0_Gold);
  275. temp.addMobs(CRYSTAL_SPICE, Cougar_0_Crystal);
  276. GROWTH_CAPABLE_MONSTERS.put(21489, temp);
  277. temp = new GrowthCapableMob(1, 40);
  278. temp.addMobs(GOLDEN_SPICE, Cougar_1_Gold_1);
  279. GROWTH_CAPABLE_MONSTERS.put(21490, temp);
  280. GROWTH_CAPABLE_MONSTERS.put(21492, temp);
  281. temp = new GrowthCapableMob(1, 40);
  282. temp.addMobs(GOLDEN_SPICE, Cougar_1_Gold_2);
  283. GROWTH_CAPABLE_MONSTERS.put(21491, temp);
  284. GROWTH_CAPABLE_MONSTERS.put(21493, temp);
  285. temp = new GrowthCapableMob(1, 40);
  286. temp.addMobs(CRYSTAL_SPICE, Cougar_1_Crystal_1);
  287. GROWTH_CAPABLE_MONSTERS.put(21494, temp);
  288. GROWTH_CAPABLE_MONSTERS.put(21496, temp);
  289. temp = new GrowthCapableMob(1, 40);
  290. temp.addMobs(CRYSTAL_SPICE, Cougar_1_Crystal_2);
  291. GROWTH_CAPABLE_MONSTERS.put(21495, temp);
  292. GROWTH_CAPABLE_MONSTERS.put(21497, temp);
  293. temp = new GrowthCapableMob(2, 25);
  294. temp.addMobs(GOLDEN_SPICE, Cougar_2_1);
  295. GROWTH_CAPABLE_MONSTERS.put(21498, temp);
  296. GROWTH_CAPABLE_MONSTERS.put(21500, temp);
  297. temp = new GrowthCapableMob(2, 25);
  298. temp.addMobs(GOLDEN_SPICE, Cougar_2_2);
  299. GROWTH_CAPABLE_MONSTERS.put(21499, temp);
  300. GROWTH_CAPABLE_MONSTERS.put(21501, temp);
  301. temp = new GrowthCapableMob(2, 25);
  302. temp.addMobs(CRYSTAL_SPICE, Cougar_2_1);
  303. GROWTH_CAPABLE_MONSTERS.put(21502, temp);
  304. GROWTH_CAPABLE_MONSTERS.put(21504, temp);
  305. temp = new GrowthCapableMob(2, 25);
  306. temp.addMobs(CRYSTAL_SPICE, Cougar_2_2);
  307. GROWTH_CAPABLE_MONSTERS.put(21503, temp);
  308. GROWTH_CAPABLE_MONSTERS.put(21505, temp);
  309. }
  310. private void spawnNext(L2Npc npc, int growthLevel, L2PcInstance player, int food)
  311. {
  312. int npcId = npc.getId();
  313. int nextNpcId = 0;
  314. // find the next mob to spawn, based on the current npcId, growthlevel, and food.
  315. if (growthLevel == 2)
  316. {
  317. // if tamed, the mob that will spawn depends on the class type (fighter/mage) of the player!
  318. if (getRandom(2) == 0)
  319. {
  320. if (player.getClassId().isMage())
  321. {
  322. nextNpcId = GROWTH_CAPABLE_MONSTERS.get(npcId).getMob(food, 1, 1);
  323. }
  324. else
  325. {
  326. nextNpcId = GROWTH_CAPABLE_MONSTERS.get(npcId).getMob(food, 1, 0);
  327. }
  328. }
  329. else
  330. {
  331. // if not tamed, there is a small chance that have "mad cow" disease.
  332. // that is a stronger-than-normal animal that attacks its feeder
  333. if (getRandom(5) == 0)
  334. {
  335. nextNpcId = GROWTH_CAPABLE_MONSTERS.get(npcId).getMob(food, 0, 1);
  336. }
  337. else
  338. {
  339. nextNpcId = GROWTH_CAPABLE_MONSTERS.get(npcId).getMob(food, 0, 0);
  340. }
  341. }
  342. }
  343. else
  344. {
  345. // all other levels of growth are straight-forward
  346. nextNpcId = GROWTH_CAPABLE_MONSTERS.get(npcId).getRandomMob(food);
  347. }
  348. // remove the feedinfo of the mob that got despawned, if any
  349. if (FEED_INFO.containsKey(npc.getObjectId()))
  350. {
  351. if (FEED_INFO.get(npc.getObjectId()) == player.getObjectId())
  352. {
  353. FEED_INFO.remove(npc.getObjectId());
  354. }
  355. }
  356. // despawn the old mob
  357. // TODO: same code? FIXED?
  358. // @formatter:off
  359. /*
  360. * if (_GrowthCapableMobs.get(npcId).getGrowthLevel() == 0)
  361. {
  362. npc.deleteMe();
  363. }
  364. else
  365. {
  366. */
  367. npc.deleteMe();
  368. // }
  369. // @formatter:on
  370. // if this is finally a trained mob, then despawn any other trained mobs that the
  371. // player might have and initialize the Tamed Beast.
  372. if (Util.contains(TAMED_BEASTS, nextNpcId))
  373. {
  374. if ((player.getTrainedBeasts() != null) && !player.getTrainedBeasts().isEmpty())
  375. {
  376. for (L2TamedBeastInstance oldTrained : player.getTrainedBeasts())
  377. {
  378. oldTrained.deleteMe();
  379. }
  380. }
  381. final L2TamedBeastInstance nextNpc = new L2TamedBeastInstance(nextNpcId, player, food - FOODSKILLDIFF, npc.getX(), npc.getY(), npc.getZ());
  382. nextNpc.setRunning();
  383. Q00020_BringUpWithLove.checkJewelOfInnocence(player);
  384. // Support for A Grand Plan for Taming Wild Beasts (655) quest.
  385. Q00655_AGrandPlanForTamingWildBeasts.reward(player, nextNpc);
  386. // also, perform a rare random chat
  387. if (getRandom(20) == 0)
  388. {
  389. NpcStringId message = NpcStringId.getNpcStringId(getRandom(2024, 2029));
  390. NpcSay packet = new NpcSay(nextNpc, 0, message);
  391. if (message.getParamCount() > 0) // player name, $s1
  392. {
  393. packet.addStringParameter(player.getName());
  394. }
  395. npc.broadcastPacket(packet);
  396. }
  397. // @formatter:off
  398. /*
  399. TODO: The tamed beast consumes one golden/crystal spice
  400. every 60 seconds with an initial delay of 60 seconds
  401. if (tamed beast exists and is alive)
  402. {
  403. if (player has 1+ golden/crystal spice)
  404. {
  405. take one golden/crystal spice;
  406. say random NpcString(getRandom(2029, 2038));
  407. }
  408. }
  409. */
  410. // @formatter:on
  411. }
  412. else
  413. {
  414. // if not trained, the newly spawned mob will automatically be aggro against its feeder
  415. // (what happened to "never bite the hand that feeds you" anyway?!)
  416. L2Attackable nextNpc = (L2Attackable) addSpawn(nextNpcId, npc);
  417. if (MAD_COW_POLYMORPH.containsKey(nextNpcId))
  418. {
  419. this.startQuestTimer("polymorph Mad Cow", 10000, nextNpc, player);
  420. }
  421. // register the player in the feedinfo for the mob that just spawned
  422. FEED_INFO.put(nextNpc.getObjectId(), player.getObjectId());
  423. nextNpc.setRunning();
  424. nextNpc.addDamageHate(player, 0, 99999);
  425. nextNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  426. }
  427. }
  428. @Override
  429. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  430. {
  431. if (event.equalsIgnoreCase("polymorph Mad Cow") && (npc != null) && (player != null))
  432. {
  433. if (MAD_COW_POLYMORPH.containsKey(npc.getId()))
  434. {
  435. // remove the feed info from the previous mob
  436. if (FEED_INFO.get(npc.getObjectId()) == player.getObjectId())
  437. {
  438. FEED_INFO.remove(npc.getObjectId());
  439. }
  440. // despawn the mad cow
  441. npc.deleteMe();
  442. // spawn the new mob
  443. L2Attackable nextNpc = (L2Attackable) addSpawn(MAD_COW_POLYMORPH.get(npc.getId()), npc);
  444. // register the player in the feedinfo for the mob that just spawned
  445. FEED_INFO.put(nextNpc.getObjectId(), player.getObjectId());
  446. nextNpc.setRunning();
  447. nextNpc.addDamageHate(player, 0, 99999);
  448. nextNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  449. }
  450. }
  451. return super.onAdvEvent(event, npc, player);
  452. }
  453. @Override
  454. public String onSkillSee(L2Npc npc, L2PcInstance caster, Skill skill, L2Object[] targets, boolean isSummon)
  455. {
  456. // this behavior is only run when the target of skill is the passed npc (chest)
  457. // i.e. when the player is attempting to open the chest using a skill
  458. if (!Util.contains(targets, npc))
  459. {
  460. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  461. }
  462. // gather some values on local variables
  463. int npcId = npc.getId();
  464. int skillId = skill.getId();
  465. // check if the npc and skills used are valid for this script. Exit if invalid.
  466. if ((skillId != SKILL_GOLDEN_SPICE) && (skillId != SKILL_CRYSTAL_SPICE))
  467. {
  468. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  469. }
  470. // first gather some values on local variables
  471. int objectId = npc.getObjectId();
  472. int growthLevel = 3; // if a mob is in FEEDABLE_BEASTS but not in _GrowthCapableMobs, then it's at max growth (3)
  473. if (GROWTH_CAPABLE_MONSTERS.containsKey(npcId))
  474. {
  475. growthLevel = GROWTH_CAPABLE_MONSTERS.get(npcId).getGrowthLevel();
  476. }
  477. // prevent exploit which allows 2 players to simultaneously raise the same 0-growth beast
  478. // If the mob is at 0th level (when it still listens to all feeders) lock it to the first feeder!
  479. if ((growthLevel == 0) && FEED_INFO.containsKey(objectId))
  480. {
  481. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  482. }
  483. FEED_INFO.put(objectId, caster.getObjectId());
  484. int food = 0;
  485. if (skillId == SKILL_GOLDEN_SPICE)
  486. {
  487. food = GOLDEN_SPICE;
  488. }
  489. else if (skillId == SKILL_CRYSTAL_SPICE)
  490. {
  491. food = CRYSTAL_SPICE;
  492. }
  493. // display the social action of the beast eating the food.
  494. npc.broadcastSocialAction(2);
  495. // if this pet can't grow, it's all done.
  496. if (GROWTH_CAPABLE_MONSTERS.containsKey(npcId))
  497. {
  498. // do nothing if this mob doesn't eat the specified food (food gets consumed but has no effect).
  499. if (GROWTH_CAPABLE_MONSTERS.get(npcId).getMob(food, 0, 0) == null)
  500. {
  501. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  502. }
  503. // rare random talk...
  504. if (getRandom(20) == 0)
  505. {
  506. NpcStringId message = TEXT[growthLevel][getRandom(TEXT[growthLevel].length)];
  507. NpcSay packet = new NpcSay(npc, 0, message);
  508. if (message.getParamCount() > 0) // player name, $s1
  509. {
  510. packet.addStringParameter(caster.getName());
  511. }
  512. npc.broadcastPacket(packet);
  513. }
  514. if ((growthLevel > 0) && (FEED_INFO.get(objectId) != caster.getObjectId()))
  515. {
  516. // check if this is the same player as the one who raised it from growth 0.
  517. // if no, then do not allow a chance to raise the pet (food gets consumed but has no effect).
  518. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  519. }
  520. // Polymorph the mob, with a certain chance, given its current growth level
  521. if (getRandom(100) < GROWTH_CAPABLE_MONSTERS.get(npcId).getChance())
  522. {
  523. spawnNext(npc, growthLevel, caster, food);
  524. }
  525. }
  526. else if (Util.contains(TAMED_BEASTS, npcId) && (npc instanceof L2TamedBeastInstance))
  527. {
  528. L2TamedBeastInstance beast = ((L2TamedBeastInstance) npc);
  529. if (skillId == beast.getFoodType())
  530. {
  531. beast.onReceiveFood();
  532. NpcStringId message = TAMED_TEXT[getRandom(TAMED_TEXT.length)];
  533. NpcSay packet = new NpcSay(npc, 0, message);
  534. if (message.getParamCount() > 0)
  535. {
  536. packet.addStringParameter(caster.getName());
  537. }
  538. beast.broadcastPacket(packet);
  539. }
  540. }
  541. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  542. }
  543. @Override
  544. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  545. {
  546. // remove the feedinfo of the mob that got killed, if any
  547. if (FEED_INFO.containsKey(npc.getObjectId()))
  548. {
  549. FEED_INFO.remove(npc.getObjectId());
  550. }
  551. return super.onKill(npc, killer, isSummon);
  552. }
  553. public static void main(String[] args)
  554. {
  555. new FeedableBeasts();
  556. }
  557. }