chests.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # # # # # # # # # # #
  2. # Chest AI implementation.
  3. # Written by Fulminus
  4. # # # # # # # # # # #
  5. import sys
  6. from net.sf.l2j.gameserver.ai import CtrlIntention
  7. from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
  8. from net.sf.l2j.util import Rnd;
  9. SKILL_DELUXE_KEY = 2229
  10. #Base chance for BOX to be opened
  11. BASE_CHANCE = 100
  12. # Percent to decrease base chance when grade of DELUXE key not match
  13. LEVEL_DECREASE = 40
  14. # Chance for a chest to actually be a BOX (as opposed to being a mimic).
  15. IS_BOX = 40
  16. class chests(JQuest) :
  17. # init function. Add in here variables that you'd like to be inherited by subclasses (if any)
  18. def __init__(self,id,name,descr):
  19. # firstly, don't forget to call the parent constructor to prepare the event triggering
  20. # mechanisms etc.
  21. JQuest.__init__(self,id,name,descr)
  22. self.chests = [18265,18266,18267,18268,18269,18270,18271,18272,18273,18274, \
  23. 18275,18276,18277,18278,18279,18280,18281,18282,18283,18284, \
  24. 18285,18286,18287,18288,18289,18290,18291,18292,18293,18294, \
  25. 18295,18296,18297,18298,21671,21694,21717,21740,21763,21786, \
  26. 21801,21802,21803,21804,21805,21806,21807,21808,21809,21810, \
  27. 21811,21812,21813,21814,21815,21816,21817,21818,21819,21820, \
  28. 21821,21822]
  29. for i in self.chests :
  30. self.addSkillSeeId(i)
  31. self.addAttackId(i)
  32. def onSkillSee (self,npc,player,skill,targets,isPet):
  33. # this behavior is only run when the target of skill is the passed npc (chest)
  34. # i.e. when the player is attempting to open the chest using a skill
  35. if not npc in targets: return
  36. npcId = npc.getNpcId()
  37. skillId = skill.getId()
  38. skillLevel= skill.getLevel()
  39. # check if the npc and skills used are valid for this script. Exit if invalid.
  40. if npcId not in self.chests : return
  41. # if this has already been interacted, no further ai decisions are needed
  42. # if it's the first interaction, check if this is a box or mimic
  43. if not npc.isInteracted() :
  44. npc.setInteracted()
  45. if Rnd.get(100) < IS_BOX :
  46. # if it's a box, either it will be successfully openned by a proper key, or instantly disappear
  47. if skillId == SKILL_DELUXE_KEY :
  48. # check the chance to open the box
  49. keyLevelNeeded = int(npc.getLevel()/10)
  50. levelDiff = keyLevelNeeded - skillLevel
  51. if levelDiff < 0 :
  52. levelDiff = levelDiff * (-1)
  53. chance = BASE_CHANCE - levelDiff * LEVEL_DECREASE
  54. # success, pretend-death with rewards: npc.reduceCurrentHp(99999999, player)
  55. if Rnd.get(100) < chance :
  56. npc.setMustRewardExpSp(False)
  57. npc.setSpecialDrop();
  58. npc.reduceCurrentHp(99999999, player)
  59. return
  60. # used a skill other than chest-key, or used a chest-key but failed to open: disappear with no rewards
  61. npc.onDecay()
  62. else :
  63. attacker = player
  64. if npc.getAttackByList().contains(player.getPet()):
  65. attacker = player.getPet()
  66. npc.setRunning()
  67. npc.addDamageHate(attacker,0,999)
  68. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker)
  69. return
  70. def onAttack(self,npc,player,damage,isPet) :
  71. npcId = npc.getNpcId()
  72. # check if the npc and skills used are valid for this script. Exit if invalid.
  73. if npcId not in self.chests : return
  74. # if this was a mimic, set the target, start the skills and become agro
  75. if not npc.isInteracted() :
  76. npc.setInteracted()
  77. if Rnd.get(100) < IS_BOX :
  78. npc.onDecay()
  79. else : # if this weren't a box, upon interaction start the mimic behaviors...
  80. # todo: perhaps a self-buff (skill id 4245) with random chance goes here?
  81. attacker = player
  82. if isPet:
  83. attacker = player.getPet()
  84. npc.setRunning()
  85. npc.addDamageHate(attacker,0,(damage*100)/(npc.getLevel()+7))
  86. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker)
  87. return
  88. # now call the constructor (starts up the ai)
  89. QUEST = chests(-1,"chests","ai")