Advertisement
Guest User

chests.py

a guest
May 19th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.lib import Rnd;
  8. from net.sf.l2j.gameserver.model.quest import QuestState
  9. from net.sf.l2j.gameserver.model.quest.jython import QuestJython as JQuest
  10.  
  11. SKILL_DELUXE_KEY = 2229
  12.  
  13. #Base chance for BOX to be opened
  14. BASE_CHANCE = 100
  15.  
  16. # Percent to decrease base chance when grade of DELUXE key not match
  17. LEVEL_DECREASE = 40
  18.  
  19. # Chance for a chest to actually be a BOX (as opposed to being a mimic).
  20. IS_BOX = 40
  21.  
  22. class chests(JQuest) :
  23.  
  24.     # init function.  Add in here variables that you'd like to be inherited by subclasses (if any)
  25.    def __init__(self,id,name,descr):
  26.        # firstly, don't forget to call the parent constructor to prepare the event triggering
  27.         # mechanisms etc.
  28.         JQuest.__init__(self,id,name,descr)
  29.  
  30.         self.chests = [13100,13101,13102,13103,13104,13105,13106,13107,13108,13109, \
  31.                        13110,13111,13112,13113,13114,13115,13116,13117,13118,13119, \
  32.                        13120,13121,1801,1802,1803,1804,1805,1806,1807,1808,1809,1810, \
  33.                        1811,1812,1813,1814,1815,1816,1817,1818,1819,1820,1821,1822]
  34.  
  35.         for i in self.chests :
  36.             self.addSkillUseId(i)
  37.             self.addAttackId(i)
  38.  
  39.     def onSkillUse (self,npc,player,skill,isPet):
  40.         npcId = npc.getNpcId()
  41.         skillId = skill.getId()
  42.         skillLevel= skill.getLevel()
  43.  
  44.         # check if the npc and skills used are valid for this script.  Exit if invalid.
  45.         if npcId not in self.chests : return
  46.  
  47.         # if this has already been interacted, no further ai decisions are needed
  48.         # if it's the first interaction, check if this is a box or mimic
  49.        if not npc.isInteracted() :
  50.            npc.setInteracted()
  51.            if Rnd.get(100) < IS_BOX :
  52.                # if it's a box, either it will be successfully openned by a proper key, or instantly disappear
  53.                 if skillId == SKILL_DELUXE_KEY :
  54.                     # check the chance to open the box
  55.                     keyLevelNeeded = int(npc.getLevel()/10)
  56.                     levelDiff = keyLevelNeeded - skillLevel
  57.                     if levelDiff < 0 :
  58.                         levelDiff = levelDiff * (-1)
  59.                     chance = BASE_CHANCE - levelDiff * LEVEL_DECREASE
  60.  
  61.                     # success, pretend-death with rewards:  npc.reduceCurrentHp(99999999, player)
  62.                     if Rnd.get(100) < chance :
  63.                         npc.setMustRewardExpSp(False)
  64.                         npc.setSpecialDrop();
  65.                         npc.reduceCurrentHp(99999999, player)
  66.                         return
  67.                 # used a skill other than chest-key, or used a chest-key but failed to open: disappear with no rewards    
  68.                 npc.onDecay()
  69.             else :
  70.                 attacker = player
  71.                 if npc.getAttackByList().contains(player.getPet()):
  72.                     attacker = player.getPet()
  73.                 npc.setRunning()
  74.                 npc.addDamageHate(attacker,0,999)
  75.                 npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker)
  76.         return
  77.  
  78.     def onAttack(self,npc,player,damage,isPet) :
  79.         npcId = npc.getNpcId()
  80.         # check if the npc and skills used are valid for this script.  Exit if invalid.
  81.         if npcId not in self.chests : return
  82.  
  83.         # if this was a mimic, set the target, start the skills and become agro
  84.         if not npc.isInteracted() :
  85.             npc.setInteracted()
  86.             if Rnd.get(100) < IS_BOX :
  87.                 keyLevelNeeded = int(npc.getLevel()/10)
  88.                 levelDiff = keyLevelNeeded - 9
  89.                 if levelDiff < 0 :
  90.                     levelDiff = levelDiff * (-1)
  91.                 chance = BASE_CHANCE - levelDiff * LEVEL_DECREASE
  92.  
  93.                     # success, pretend-death with rewards:  npc.reduceCurrentHp(99999999, player)
  94.                 if Rnd.get(100) < chance :
  95.                     npc.setMustRewardExpSp(False)
  96.                     npc.setSpecialDrop();
  97.                     npc.reduceCurrentHp(99999999, player)
  98.                     return
  99.                 npc.onDecay()
  100.             else :  # if this weren't a box, upon interaction start the mimic behaviors...
  101.                # todo: perhaps a self-buff (skill id 4245) with random chance goes here?
  102.                attacker = player
  103.                if isPet:
  104.                    attacker = player.getPet()
  105.                npc.setRunning()
  106.                npc.addDamageHate(attacker,0,(damage*100)/(npc.getLevel()+7))
  107.                npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker)
  108.        return
  109.  
  110. # now call the constructor (starts up the ai)
  111. QUEST = chests(-1,"chests","ai")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement