Advertisement
Guest User

BattleCalculatorAI.py

a guest
Oct 4th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.95 KB | None | 0 0
  1. #function to calculate toon accuracy in toontown
  2. def __calcToonAtkHit(self, attackIndex, atkTargets):
  3.         if len(atkTargets) == 0:
  4.             return (0, 0)
  5.         if self.tutorialFlag:
  6.             return (1, 95)
  7.         if self.toonsAlways5050:
  8.             roll = random.randint(0, 99)
  9.             if roll < 50:
  10.                 return (1, 95)
  11.             else:
  12.                 return (0, 0)
  13.         if self.toonsAlwaysHit:
  14.             return (1, 95)
  15.         elif self.toonsAlwaysMiss:
  16.             return (0, 0)
  17.         debug = self.notify.getDebug()
  18.         attack = self.battle.toonAttacks[attackIndex]
  19.         atkTrack, atkLevel = self.__getActualTrackLevel(attack)
  20.         if atkTrack == NPCSOS:
  21.             return (1, 95)
  22.         if atkTrack == FIRE:
  23.             return (1, 95)
  24.         if atkTrack == TRAP:
  25.             if debug:
  26.                 self.notify.debug('Attack is a trap, so it hits regardless')
  27.             attack[TOON_ACCBONUS_COL] = 0
  28.             return (1, 100)
  29.         elif atkTrack == DROP and attack[TOON_TRACK_COL] == NPCSOS:
  30.             unluredSuits = 0
  31.             for tgt in atkTargets:
  32.                 if not self.__suitIsLured(tgt.getDoId()):
  33.                     unluredSuits = 1
  34.  
  35.             if unluredSuits == 0:
  36.                 attack[TOON_ACCBONUS_COL] = 1
  37.                 return (0, 0)
  38.         elif atkTrack == DROP:
  39.             allLured = True
  40.             for i in xrange(len(atkTargets)):
  41.                 if self.__suitIsLured(atkTargets[i].getDoId()):
  42.                     pass
  43.                 else:
  44.                     allLured = False
  45.  
  46.             if allLured:
  47.                 attack[TOON_ACCBONUS_COL] = 1
  48.                 return (0, 0)
  49.         elif atkTrack == PETSOS:
  50.             return self.__calculatePetTrickSuccess(attack)
  51.         tgtDef = 0
  52.         numLured = 0
  53.         if atkTrack != HEAL:
  54.             for currTarget in atkTargets:
  55.                 thisSuitDef = self.__targetDefense(currTarget, atkTrack)
  56.                 if debug:
  57.                     self.notify.debug('Examining suit def for toon attack: ' + str(thisSuitDef))
  58.                 tgtDef = min(thisSuitDef, tgtDef)
  59.                 if self.__suitIsLured(currTarget.getDoId()):
  60.                     numLured += 1
  61.  
  62.         trackExp = self.__toonTrackExp(attack[TOON_ID_COL], atkTrack)
  63.         for currOtherAtk in self.toonAtkOrder:
  64.             if currOtherAtk != attack[TOON_ID_COL]:
  65.                 nextAttack = self.battle.toonAttacks[currOtherAtk]
  66.                 nextAtkTrack = self.__getActualTrack(nextAttack)
  67.                 if atkTrack == nextAtkTrack and attack[TOON_TGT_COL] == nextAttack[TOON_TGT_COL]:
  68.                     currTrackExp = self.__toonTrackExp(nextAttack[TOON_ID_COL], atkTrack)
  69.                     if debug:
  70.                         self.notify.debug('Examining toon track exp bonus: ' + str(currTrackExp))
  71.                     trackExp = max(currTrackExp, trackExp)
  72.  
  73.         if debug:
  74.             if atkTrack == HEAL:
  75.                 self.notify.debug('Toon attack is a heal, no target def used')
  76.             else:
  77.                 self.notify.debug('Suit defense used for toon attack: ' + str(tgtDef))
  78.             self.notify.debug('Toon track exp bonus used for toon attack: ' + str(trackExp))
  79.         if attack[TOON_TRACK_COL] == NPCSOS:
  80.             randChoice = 0
  81.         else:
  82.             randChoice = random.randint(0, 99)
  83.         propAcc = AvPropAccuracy[atkTrack][atkLevel]
  84.         if atkTrack == LURE:
  85.             treebonus = self.__toonCheckGagBonus(attack[TOON_ID_COL], atkTrack, atkLevel)
  86.             propBonus = self.__checkPropBonus(atkTrack)
  87.             if self.propAndOrganicBonusStack:
  88.                 propAcc = 0
  89.                 if treebonus:
  90.                     self.notify.debug('using organic bonus lure accuracy')
  91.                     propAcc += AvLureBonusAccuracy[atkLevel]
  92.                 if propBonus:
  93.                     self.notify.debug('using prop bonus lure accuracy')
  94.                     propAcc += AvLureBonusAccuracy[atkLevel]
  95.             elif treebonus or propBonus:
  96.                 self.notify.debug('using oragnic OR prop bonus lure accuracy')
  97.                 propAcc = AvLureBonusAccuracy[atkLevel]
  98.         attackAcc = propAcc + trackExp + tgtDef
  99.         currAtk = self.toonAtkOrder.index(attackIndex)
  100.         if currAtk > 0 and atkTrack != HEAL:
  101.             prevAtkId = self.toonAtkOrder[currAtk - 1]
  102.             prevAttack = self.battle.toonAttacks[prevAtkId]
  103.             prevAtkTrack = self.__getActualTrack(prevAttack)
  104.             lure = atkTrack == LURE and (not attackAffectsGroup(atkTrack, atkLevel,
  105.              attack[TOON_TRACK_COL]) and self.successfulLures.has_key(attack[TOON_TGT_COL]) or attackAffectsGroup(atkTrack, atkLevel, attack[TOON_TRACK_COL]))
  106.             if atkTrack == prevAtkTrack and (attack[TOON_TGT_COL] == prevAttack[TOON_TGT_COL] or lure):
  107.                 if prevAttack[TOON_ACCBONUS_COL] == 1:
  108.                     if debug:
  109.                         self.notify.debug('DODGE: Toon attack track dodged')
  110.                 elif prevAttack[TOON_ACCBONUS_COL] == 0:
  111.                     if debug:
  112.                         self.notify.debug('HIT: Toon attack track hit')
  113.                 attack[TOON_ACCBONUS_COL] = prevAttack[TOON_ACCBONUS_COL]
  114.                 return (not attack[TOON_ACCBONUS_COL], attackAcc)
  115.         atkAccResult = attackAcc
  116.         if debug:
  117.             self.notify.debug('setting atkAccResult to %d' % atkAccResult)
  118.         acc = attackAcc + self.__calcToonAccBonus(attackIndex)
  119.         if atkTrack != LURE and atkTrack != HEAL:
  120.             if atkTrack != DROP:
  121.                 if numLured == len(atkTargets):
  122.                     if debug:
  123.                         self.notify.debug('all targets are lured, attack hits')
  124.                     attack[TOON_ACCBONUS_COL] = 0
  125.                     return (1, 100)
  126.                 else:
  127.                     luredRatio = float(numLured) / float(len(atkTargets))
  128.                     accAdjust = 100 * luredRatio
  129.                     if accAdjust > 0 and debug:
  130.                         self.notify.debug(str(numLured) + ' out of ' + str(len(atkTargets)) + ' targets are lured, so adding ' + str(accAdjust) + ' to attack accuracy')
  131.                     acc += accAdjust
  132.             elif numLured == len(atkTargets):
  133.                 if debug:
  134.                     self.notify.debug('all targets are lured, attack misses')
  135.                 attack[TOON_ACCBONUS_COL] = 0
  136.                 return (0, 0)
  137.         if acc > MaxToonAcc:
  138.             acc = MaxToonAcc
  139.         if randChoice < acc:
  140.             if debug:
  141.                 self.notify.debug('HIT: Toon attack rolled' + str(randChoice) + 'to hit with an accuracy of' + str(acc))
  142.             attack[TOON_ACCBONUS_COL] = 0
  143.         else:
  144.             if debug:
  145.                 self.notify.debug('MISS: Toon attack rolled' + str(randChoice) + 'to hit with an accuracy of' + str(acc))
  146.             attack[TOON_ACCBONUS_COL] = 1
  147.         return (not attack[TOON_ACCBONUS_COL], atkAccResult)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement