feedable_beasts.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # Growth-capable mobs: Polymorphing upon successful feeding.
  2. # Written by Fulminus
  3. # # # # # # # # # # #
  4. import sys
  5. from net.sf.l2j.gameserver.ai import CtrlIntention
  6. from net.sf.l2j.gameserver.idfactory import IdFactory
  7. from net.sf.l2j.gameserver.datatables import NpcTable
  8. from net.sf.l2j.gameserver.model.actor.instance import L2TamedBeastInstance
  9. from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
  10. from net.sf.l2j.gameserver.serverpackets import NpcSay
  11. from net.sf.l2j.gameserver.serverpackets import SocialAction
  12. from net.sf.l2j.util import Rnd;
  13. GOLDEN_SPICE = 6643
  14. CRYSTAL_SPICE = 6644
  15. SKILL_GOLDEN_SPICE = 2188
  16. SKILL_CRYSTAL_SPICE = 2189
  17. foodSkill = {GOLDEN_SPICE:SKILL_GOLDEN_SPICE, CRYSTAL_SPICE:SKILL_CRYSTAL_SPICE}
  18. class feedable_beasts(JQuest) :
  19. # init function. Add in here variables that you'd like to be inherited by subclasses (if any)
  20. def __init__(self,id,name,descr):
  21. # firstly, don't forget to call the parent constructor to prepare the event triggering
  22. # mechanisms etc.
  23. JQuest.__init__(self,id,name,descr)
  24. # DEFINE MEMBER VARIABLES FOR THIS AI
  25. # all mobs that can eat...
  26. self.tamedBeasts = range(16013,16019)
  27. self.feedableBeasts = range(21451,21508)+range(21824,21830)+ self.tamedBeasts
  28. # all mobs that grow by eating
  29. # mobId: current_growth_level, {food: [list of possible mobs[possible sublist of tamed pets]]}, chance of growth
  30. self.growthCapableMobs = {
  31. # Alpen Kookabura
  32. 21451: [0,{GOLDEN_SPICE:[21452,21453, 21454, 21455],CRYSTAL_SPICE:[21456,21457, 21458, 21459]},100],
  33. 21452: [1,{GOLDEN_SPICE:[21460,21462],CRYSTAL_SPICE:[]},40],
  34. 21453: [1,{GOLDEN_SPICE:[21461,21463],CRYSTAL_SPICE:[]},40],
  35. 21454: [1,{GOLDEN_SPICE:[21460,21462],CRYSTAL_SPICE:[]},40],
  36. 21455: [1,{GOLDEN_SPICE:[21461,21463],CRYSTAL_SPICE:[]},40],
  37. 21456: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21464,21466]},40],
  38. 21457: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21465,21467]},40],
  39. 21458: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21464,21466]},40],
  40. 21459: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21465,21467]},40],
  41. 21460: [2,{GOLDEN_SPICE:[[21468,21824],[16017,16018]],CRYSTAL_SPICE:[]},25],
  42. 21461: [2,{GOLDEN_SPICE:[[21469,21825],[16017,16018]],CRYSTAL_SPICE:[]},25],
  43. 21462: [2,{GOLDEN_SPICE:[[21468,21824],[16017,16018]],CRYSTAL_SPICE:[]},25],
  44. 21463: [2,{GOLDEN_SPICE:[[21469,21825],[16017,16018]],CRYSTAL_SPICE:[]},25],
  45. 21464: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21468,21824],[16017,16018]]},25],
  46. 21465: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21469,21825],[16017,16018]]},25],
  47. 21466: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21468,21824],[16017,16018]]},25],
  48. 21467: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21469,21825],[16017,16018]]},25],
  49. # Alpen Buffalo
  50. 21470: [0,{GOLDEN_SPICE:[21471,21472, 21473, 21474],CRYSTAL_SPICE:[21475,21476, 21477, 21478]},100],
  51. 21471: [1,{GOLDEN_SPICE:[21479,21481],CRYSTAL_SPICE:[]},40],
  52. 21472: [1,{GOLDEN_SPICE:[21481,21482],CRYSTAL_SPICE:[]},40],
  53. 21473: [1,{GOLDEN_SPICE:[21479,21481],CRYSTAL_SPICE:[]},40],
  54. 21474: [1,{GOLDEN_SPICE:[21480,21482],CRYSTAL_SPICE:[]},40],
  55. 21475: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21483,21485]},40],
  56. 21476: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21484,21486]},40],
  57. 21477: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21483,21485]},40],
  58. 21478: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21484,21486]},40],
  59. 21479: [2,{GOLDEN_SPICE:[[21487,21826],[16013,16014]],CRYSTAL_SPICE:[]},25],
  60. 21480: [2,{GOLDEN_SPICE:[[21488,21827],[16013,16014]],CRYSTAL_SPICE:[]},25],
  61. 21481: [2,{GOLDEN_SPICE:[[21487,21826],[16013,16014]],CRYSTAL_SPICE:[]},25],
  62. 21482: [2,{GOLDEN_SPICE:[[21488,21827],[16013,16014]],CRYSTAL_SPICE:[]},25],
  63. 21483: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21487,21826],[16013,16014]]},25],
  64. 21484: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21488,21827],[16013,16014]]},25],
  65. 21485: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21487,21826],[16013,16014]]},25],
  66. 21486: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21488,21827],[16013,16014]]},25],
  67. # Alpen Cougar
  68. 21489: [0,{GOLDEN_SPICE:[21490,21491, 21492, 21493],CRYSTAL_SPICE:[21494,21495, 21496, 21497]},100],
  69. 21490: [1,{GOLDEN_SPICE:[21498,21500],CRYSTAL_SPICE:[]},40],
  70. 21491: [1,{GOLDEN_SPICE:[21499,21501],CRYSTAL_SPICE:[]},40],
  71. 21492: [1,{GOLDEN_SPICE:[21498,21500],CRYSTAL_SPICE:[]},40],
  72. 21493: [1,{GOLDEN_SPICE:[21499,21501],CRYSTAL_SPICE:[]},40],
  73. 21494: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21502,21504]},40],
  74. 21495: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21503,21505]},40],
  75. 21496: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21502,21504]},40],
  76. 21497: [1,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[21503,21505]},40],
  77. 21498: [2,{GOLDEN_SPICE:[[21506,21828],[16015,16016]],CRYSTAL_SPICE:[]},25],
  78. 21499: [2,{GOLDEN_SPICE:[[21507,21829],[16015,16016]],CRYSTAL_SPICE:[]},25],
  79. 21500: [2,{GOLDEN_SPICE:[[21506,21828],[16015,16016]],CRYSTAL_SPICE:[]},25],
  80. 21501: [2,{GOLDEN_SPICE:[[21507,21829],[16015,16016]],CRYSTAL_SPICE:[]},25],
  81. 21502: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21506,21828],[16015,16016]]},25],
  82. 21503: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21507,21829],[16015,16016]]},25],
  83. 21504: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21506,21828],[16015,16016]]},25],
  84. 21505: [2,{GOLDEN_SPICE:[],CRYSTAL_SPICE:[[21507,21829],[16015,16016]]},25]
  85. }
  86. self.madCowPolymorph = {21824:21468,21825:21469,21826:21487,21827:21488,21828:21506,21829:21507}
  87. self.Text = [["What did you just do to me?","You want to tame me, huh?","Do not give me this. Perhaps you will be in danger.","Bah bah. What is this unpalatable thing?","My belly has been complaining. This hit the spot.","What is this? Can I eat it?","You don't need to worry about me.","Delicious food, thanks.","I am starting to like you!","Gulp"],
  88. ["I do not think you have given up on the idea of taming me.","That is just food to me. Perhaps I can eat your hand too.","Will eating this make me fat? Ha ha","Why do you always feed me?","Do not trust me. I may betray you"],
  89. ["Destroy","Look what you have done!","Strange feeling...! Evil intentions grow in my heart...!","It is happenning!","This is sad...Good is sad...!"]]
  90. self.feedInfo = {} # : feedInfo[objectId of mob] = objectId of player feeding it
  91. for i in self.feedableBeasts :
  92. self.addSkillSeeId(i)
  93. self.addKillId(i)
  94. def onAdvEvent(self,event,npc,player) :
  95. if event == "polymorph Mad Cow" and npc and player:
  96. if npc.getNpcId() in self.madCowPolymorph.keys() :
  97. # remove the feed info from the previous mob
  98. if self.feedInfo[npc.getObjectId()] == player.getObjectId() :
  99. self.feedInfo.pop(npc.getObjectId())
  100. # despawn the mad cow
  101. npc.deleteMe()
  102. # spawn the new mob
  103. nextNpc = self.addSpawn(self.madCowPolymorph[npc.getNpcId()],npc)
  104. # register the player in the feedinfo for the mob that just spawned
  105. self.feedInfo[nextNpc.getObjectId()] = player.getObjectId()
  106. nextNpc.setRunning()
  107. nextNpc.addDamageHate(player,0,99999)
  108. nextNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player)
  109. def spawnNext(self, npc, growthLevel,player,food) :
  110. npcId = npc.getNpcId()
  111. nextNpcId = 0
  112. # find the next mob to spawn, based on the current npcId, growthlevel, and food.
  113. if growthLevel == 2:
  114. rand = Rnd.get(2)
  115. # if tamed, the mob that will spawn depends on the class type (fighter/mage) of the player!
  116. if rand == 1 :
  117. if player.getClassId().isMage() :
  118. nextNpcId = self.growthCapableMobs[npcId][1][food][1][1]
  119. else :
  120. nextNpcId = self.growthCapableMobs[npcId][1][food][1][0]
  121. # if not tamed, there is a small chance that have "mad cow" disease.
  122. # that is a stronger-than-normal animal that attacks its feeder
  123. else :
  124. if Rnd.get(5) == 0 :
  125. nextNpcId = self.growthCapableMobs[npcId][1][food][0][1]
  126. else :
  127. nextNpcId = self.growthCapableMobs[npcId][1][food][0][0]
  128. # all other levels of growth are straight-forward
  129. else :
  130. nextNpcId = self.growthCapableMobs[npcId][1][food][Rnd.get(len(self.growthCapableMobs[npcId][1][food]))]
  131. # remove the feedinfo of the mob that got despawned, if any
  132. if self.feedInfo.has_key(npc.getObjectId()) :
  133. if self.feedInfo[npc.getObjectId()] == player.getObjectId() :
  134. self.feedInfo.pop(npc.getObjectId())
  135. # despawn the old mob
  136. if self.growthCapableMobs[npcId][0] == 0 :
  137. npc.onDecay()
  138. else :
  139. npc.deleteMe()
  140. # if this is finally a trained mob, then despawn any other trained mobs that the
  141. # player might have and initialize the Tamed Beast.
  142. if nextNpcId in self.tamedBeasts :
  143. oldTrained = player.getTrainedBeast()
  144. if oldTrained :
  145. oldTrained.doDespawn()
  146. #the following 5 commented lines are not needed, but they provide a plausible alternate implementation...just in case...
  147. #nextNpc = self.addSpawn(nextNpcId,npc)
  148. #nextNpc.setOwner(player)
  149. #nextNpc.setFoodType(foodSkill[food])
  150. #nextNpc.setHome(npc)
  151. template = NpcTable.getInstance().getTemplate(nextNpcId)
  152. nextNpc = L2TamedBeastInstance(IdFactory.getInstance().getNextId(), template, player, foodSkill[food], npc.getX(), npc.getY(), npc.getZ())
  153. nextNpc.setRunning()
  154. objectId = nextNpc.getObjectId()
  155. st = player.getQuestState("20_BringUpWithLove")
  156. if st :
  157. if Rnd.get(100) <= 5 and st.getQuestItemsCount(7185) == 0 :
  158. st.giveItems(7185,1) #if player has quest 20 going, give quest item
  159. st.set("cond","2") #it's easier to hardcode it in here than to try and repeat this stuff in the quest
  160. # also, perform a rare random chat
  161. rand = Rnd.get(20)
  162. if rand > 4 : pass
  163. elif rand == 0 : npc.broadcastPacket(NpcSay(objectId,0,nextNpc.getNpcId(), player.getName()+", will you show me your hideaway?"))
  164. elif rand == 1 : npc.broadcastPacket(NpcSay(objectId,0,nextNpc.getNpcId(), player.getName()+", whenever I look at spice, I think about you."))
  165. elif rand == 2 : npc.broadcastPacket(NpcSay(objectId,0,nextNpc.getNpcId(), player.getName()+", you do not need to return to the village. I will give you strength"))
  166. elif rand == 3 : npc.broadcastPacket(NpcSay(objectId,0,nextNpc.getNpcId(), "Thanks, "+player.getName()+". I hope I can help you"))
  167. elif rand == 4 : npc.broadcastPacket(NpcSay(objectId,0,nextNpc.getNpcId(), player.getName()+", what can I do to help you?"))
  168. # if not trained, the newly spawned mob will automatically be agro against its feeder
  169. # (what happened to "never bite the hand that feeds you" anyway?!)
  170. else :
  171. # spawn the new mob
  172. nextNpc = self.addSpawn(nextNpcId,npc)
  173. if nextNpcId in self.madCowPolymorph :
  174. self.startQuestTimer("polymorph Mad Cow", 10000, nextNpc, player)
  175. # register the player in the feedinfo for the mob that just spawned
  176. self.feedInfo[nextNpc.getObjectId()] = player.getObjectId()
  177. nextNpc.setRunning()
  178. nextNpc.addDamageHate(player,0,99999)
  179. nextNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player)
  180. def onSkillSee (self,npc,player,skill,targets,isPet):
  181. # this behavior is only run when the target of skill is the passed npc (chest)
  182. # i.e. when the player is attempting to open the chest using a skill
  183. if not npc in targets: return
  184. # gather some values on local variables
  185. npcId = npc.getNpcId()
  186. skillId = skill.getId()
  187. # check if the npc and skills used are valid for this script. Exit if invalid.
  188. if npcId not in self.feedableBeasts : return
  189. if skillId not in [SKILL_GOLDEN_SPICE,SKILL_CRYSTAL_SPICE] : return
  190. # first gather some values on local variables
  191. objectId = npc.getObjectId()
  192. growthLevel = 3 # if a mob is in feedableBeasts but not in growthCapableMobs, then it's at max growth (3)
  193. if self.growthCapableMobs.has_key(npcId) :
  194. growthLevel = self.growthCapableMobs[npcId][0]
  195. # prevent exploit which allows 2 players to simultaneously raise the same 0-growth beast
  196. # If the mob is at 0th level (when it still listens to all feeders) lock it to the first feeder!
  197. if (growthLevel==0) and self.feedInfo.has_key(objectId):
  198. return
  199. else :
  200. self.feedInfo[objectId] = player.getObjectId()
  201. food = 0
  202. if skillId == SKILL_GOLDEN_SPICE :
  203. food = GOLDEN_SPICE
  204. elif skillId == SKILL_CRYSTAL_SPICE :
  205. food = CRYSTAL_SPICE
  206. # display the social action of the beast eating the food.
  207. npc.broadcastPacket(SocialAction(objectId,2))
  208. # if this pet can't grow, it's all done.
  209. if npcId in self.growthCapableMobs.keys() :
  210. # do nothing if this mob doesn't eat the specified food (food gets consumed but has no effect).
  211. if len(self.growthCapableMobs[npcId][1][food]) == 0 : return
  212. # rare random talk...
  213. if Rnd.get(20) == 0 :
  214. npc.broadcastPacket(NpcSay(objectId,0,npc.getNpcId(),self.Text[growthLevel][Rnd.get(len(self.Text[growthLevel]))]))
  215. if growthLevel > 0 :
  216. # check if this is the same player as the one who raised it from growth 0.
  217. # if no, then do not allow a chance to raise the pet (food gets consumed but has no effect).
  218. if self.feedInfo[objectId] != player.getObjectId() : return
  219. # Polymorph the mob, with a certain chance, given its current growth level
  220. if Rnd.get(100) < self.growthCapableMobs[npcId][2] :
  221. self.spawnNext(npc, growthLevel,player,food)
  222. elif npcId in self.tamedBeasts :
  223. if skillId == npc.getFoodType() :
  224. npc.onReceiveFood()
  225. mytext = ["Refills! Yeah!","I am such a gluttonous beast, it is embarrassing! Ha ha",
  226. "Your cooperative feeling has been getting better and better.",
  227. "I will help you!",
  228. "The weather is really good. Wanna go for a picnic?",
  229. "I really like you! This is tasty...",
  230. "If you do not have to leave this place, then I can help you.",
  231. "What can I help you with?",
  232. "I am not here only for food!",
  233. "Yam, yam, yam, yam, yam!"]
  234. npc.broadcastPacket(NpcSay(objectId,0,npc.getNpcId(),mytext[Rnd.get(len(mytext))]))
  235. return
  236. def onKill (self,npc,player,isPet):
  237. # remove the feedinfo of the mob that got killed, if any
  238. if self.feedInfo.has_key(npc.getObjectId()) :
  239. self.feedInfo.pop(npc.getObjectId())
  240. # now call the constructor (starts up the ai)
  241. QUEST = feedable_beasts(-1,"feedable_beasts","ai")