Advertisement
avogatro

fixed world of tanks mod : reset personal mission for obj 279 early

Mar 31st, 2023
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import BigWorld
  2. from PlayerEvents import g_playerEvents
  3. from gui.ClientUpdateManager import g_clientUpdateManager
  4. from helpers import dependency
  5. from skeletons.gui.shared import IItemsCache
  6. import Account
  7. from personal_missions import g_cache
  8.  
  9. STAT_DIFF_KEY = 'stats'
  10. INVENTORY_DIFF_KEY = 'inventory'
  11. _STAT_DIFF_FORMAT = STAT_DIFF_KEY + '.{0:>s}'
  12. CREDITS_DIFF_KEY = _STAT_DIFF_FORMAT.format('credits')
  13.  
  14. class WBPMAutoReset:
  15.     itemsCache = dependency.descriptor(IItemsCache)
  16.     player = None
  17.     canReset = True
  18.     needTimer = True
  19.  
  20.     def __init__(self):
  21.         self._initListeners()
  22.         self._patchQuestResetter()
  23.  
  24.     def _patchQuestResetter(self):
  25.         old_selectPersonalMissions = Account.PlayerAccount.selectPersonalMissions
  26.  
  27.         def new_selectPersonalMissions(self, personalMissionsIDs, questType, callback):
  28.             old_selectPersonalMissions(self, personalMissionsIDs, questType, callback)
  29.  
  30.         Account.PlayerAccount.selectPersonalMissions = new_selectPersonalMissions
  31.  
  32.     def _initListeners(self):
  33.         self.itemsCache.onSyncCompleted += self._onSyncCompleted
  34.         g_playerEvents.onBattleResultsReceived += self._onBattleResultsReceived
  35.         g_clientUpdateManager.addCallbacks({CREDITS_DIFF_KEY: self._onCreditsUpdate})
  36.  
  37.     def _onCreditsUpdate(self, _):
  38.         self.canReset = True
  39.         self._checkQuestState()
  40.  
  41.     def _onSyncCompleted(self, *args):
  42.         self._checkQuestState()
  43.  
  44.     def _onBattleResultsReceived(self, isPlayerVehicle, results):
  45.         self.canReset = True
  46.  
  47.     def _checkQuestState(self):
  48.         questProgress = Account.g_accountRepository.questProgress
  49.         if questProgress is None:
  50.             return
  51.         else:
  52.             self.needTimer = True
  53.             pmProgress = questProgress._QuestProgress__cache['pm2_progress']
  54.             questsToReset = {}
  55.             for q in pmProgress:
  56.                 quest = pmProgress[q]
  57.                 print '--\t', q, quest
  58.                 questId = g_cache._PQCache__questUniqueIDToPotapovQuestID['%s_main' % q]
  59.                 if 'battlesSeries' in quest.keys():
  60.                     questKeys = quest['battlesSeries'].keys()
  61.                     mainConditionFailed = False
  62.                     advConditionFailed = False
  63.                     if 'battles' in questKeys:
  64.                         if len(quest['battlesSeries']['battles']) > 0:
  65.                             mainConditionFailed = True
  66.                             for battle in quest['battlesSeries']['battles']:
  67.                                 if battle:
  68.                                     mainConditionFailed = False
  69.                                     break
  70.  
  71.                         if mainConditionFailed:
  72.                             questsToReset[questId] = True
  73.                         else:
  74.                             advConditionFailed = False
  75.                             if 'state' in questKeys and quest['battlesSeries']['state'] >= 5:
  76.                                 if len(quest['battlesSeriesAdv']['battles']) > 0:
  77.                                     advConditionFailed = True
  78.                                     for battle in quest['battlesSeriesAdv']['battles']:
  79.                                         if battle:
  80.                                             advConditionFailed = False
  81.                                             break
  82.  
  83.                                 if advConditionFailed and len(quest['battlesSeries']['battles']) == 0:
  84.                                     questsToReset[questId] = True
  85.                        
  86.                     print '>>', questId, 'main cond:', mainConditionFailed, 'adv cond:', advConditionFailed,
  87.  
  88.             needReset = False
  89.             for r in questsToReset:
  90.                 needReset = needReset or questsToReset[r]
  91.  
  92.             if needReset:
  93.                 self._resetQuest(questsToReset)
  94.             else:
  95.                 print 'no need to reset quests:', questsToReset
  96.             return
  97.  
  98.     def _voidCallback(self, *args):
  99.         pass
  100.  
  101.     def _resetQuest(self, questIds):
  102.         if self.canReset:
  103.             self.canReset = False
  104.             print ('>> trying to reset quest:', questIds, questIds.keys())
  105.             BigWorld.player().resetPersonalMissions(list(questIds.keys()), 2, self._voidCallback)
  106.             print ('>> reset seems successful', list(questIds.keys()))
  107.         else:
  108.             print '>> reset quest blocked till next battle'
  109.  
  110.  
  111. wbPMAutoReset = WBPMAutoReset()
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement