FeedableBeasts.java 22 KB

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