class Quest(ServerEventAbstract): def __init__(self, qID, data, progress = None): import copy tmpData = copy.deepcopy(data) super(Quest, self).__init__(qID, data) self._progress = progress self._children, self._parents = {}, {} conds = dict(tmpData['conditions']) preBattle = dict(conds['preBattle']) self.accountReqs = AccountRequirements(self.getType(), preBattle['account']) self.vehicleReqs = VehicleRequirements(preBattle['vehicle']) self.preBattleCond = PreBattleConditions(preBattle['battle']) self.bonusCond = BonusConditions(conds['bonus'], self.getProgressData(), self.preBattleCond) self.postBattleCond = PostBattleConditions(conds['postBattle'], self.preBattleCond) self._groupID = DEFAULTS_GROUPS.UNGROUPED_QUESTS def getUserType(self): if self.getType() == constants.EVENT_TYPE.FORT_QUEST: return i18n.makeString(QUESTS.ITEM_TYPE_SPECIALMISSION) return i18n.makeString(QUESTS.ITEM_TYPE_QUEST) def getProgressExpiryTime(self): return self._data.get('progressExpiryTime', time.time()) def isCompletedByGroup(self, groupByKey): bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: if self.bonusCond.getGroupByValue() is None: return self.isCompleted() if self._progress is not None: return bonusLimit <= self.getBonusCount(groupByKey) return False def isCompleted(self, progress = None): progress = progress or self._progress bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return self.getBonusCount(progress=progress) >= bonusLimit if progress is not None: if groupBy == 'nation': return self.__checkGroupedCompletion(nations.AVAILABLE_NAMES, progress, bonusLimit) if groupBy == 'level': return self.__checkGroupedCompletion(xrange(1, constants.MAX_VEHICLE_LEVEL + 1), progress, bonusLimit, keyMaker=lambda lvl: 'level %d' % lvl) if groupBy == 'class': return self.__checkGroupedCompletion(constants.VEHICLE_CLASSES, progress, bonusLimit) if groupBy == 'vehicle': pass return super(Quest, self).isCompleted() def setChildren(self, children): self._children = children def getChildren(self): return self._children def setParents(self, parents): self._parents = parents def getParents(self): return self._parents def getBonusCount(self, groupByKey = None, progress = None): progress = progress or self._progress if progress is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return progress.get(None, {}).get('bonusCount', 0) if groupByKey is not None: return progress.get(groupByKey, {}).get('bonusCount', 0) return sum((p.get('bonusCount', 0) for p in progress.itervalues())) else: return 0 def getProgressData(self): return self._progress or {} def getBonuses(self, bonusName = None): result = [] for n, v in self._data.get('bonus', {}).iteritems(): if bonusName is not None and n != bonusName: continue b = getBonusObj(self, n, v) if b is not None: result.append(b) return result def hasPremIGRVehBonus(self): vehBonuses = self.getBonuses('vehicles') for vehBonus in vehBonuses: vehicles = vehBonus.getValue() for intCD, data in vehicles.iteritems(): item = g_itemsCache.items.getItemByCD(intCD) if item.isPremiumIGR and data.get('rent', None) is not None: return True return False def __checkGroupedCompletion(self, values, progress, bonusLimit = None, keyMaker = lambda v: v): bonusLimit = bonusLimit or self.bonusCond.getBonusLimit() for value in values: if bonusLimit > self.getBonusCount(groupByKey=keyMaker(value), progress=progress): return False return True def _checkConditions(self): isAccAvailable = self.accountReqs.isAvailable() isVehAvailable = self.vehicleReqs.isAnyVehicleAcceptable() or len(self.vehicleReqs.getSuitableVehicles()) > 0 return isAccAvailable and isVehAvailable
class Quest(ServerEventAbstract): itemsCache = dependency.descriptor(IItemsCache) eventsCache = dependency.descriptor(IEventsCache) lobbyContext = dependency.descriptor(ILobbyContext) __slots__ = ServerEventAbstract.__slots__ + ( '_progress', '_children', '_parents', '_parentsName', 'accountReqs', 'vehicleReqs', 'preBattleCond', 'bonusCond', 'postBattleCond', '__linkedActions', '_meta') def __init__(self, qID, data, progress=None): super(Quest, self).__init__(qID, data) self._progress = progress self._children, self._parents, self._parentsName = {}, {}, {} self._meta = data.get('meta', {}) conds = dict(data['conditions']) preBattle = dict(conds['preBattle']) self.accountReqs = AccountRequirements(preBattle['account']) self.vehicleReqs = VehicleRequirements(preBattle['vehicle']) self.preBattleCond = PreBattleConditions(preBattle['battle']) self.bonusCond = BonusConditions(conds['common'], self.getProgressData(), self.preBattleCond) self.postBattleCond = PostBattleConditions(conds['postBattle'], self.preBattleCond) self._groupID = DEFAULTS_GROUPS.UNGROUPED_QUESTS self.__linkedActions = [] def isCompensationPossible(self): return events_helpers.isMarathon(self.getGroupID()) and bool( self.getBonuses('tokens')) def shouldBeShown(self): return self.isAvailable( ).isValid and self.lobbyContext.getServerSettings( ).isMapsTrainingEnabled() if events_helpers.isMapsTraining( self.getGroupID()) else True def getGroupType(self): return getGroupTypeByID(self.getGroupID()) def isAvailable(self): return ValidationResult( False, 'dailyComplete') if self.bonusCond.getBonusLimit( ) is not None and self.bonusCond.isDaily() and self.isCompleted( ) else super(Quest, self).isAvailable() @property def linkedActions(self): return self.__linkedActions @linkedActions.setter def linkedActions(self, value): self.__linkedActions = value def getUserType(self): return i18n.makeString(QUESTS.ITEM_TYPE_QUEST) def getProgressExpiryTime(self): return self._data.get('progressExpiryTime', time.time()) def isCompletedByGroup(self, groupByKey): bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: if self.bonusCond.getGroupByValue() is None: return self.isCompleted() if self._progress is not None: return bonusLimit <= self.getBonusCount(groupByKey) return False def isCompleted(self, progress=None): progress = progress or self._progress bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return self.getBonusCount(progress=progress) >= bonusLimit if progress is not None: if groupBy == 'nation': return self.__checkGroupedCompletion( nations.AVAILABLE_NAMES, progress, bonusLimit) if groupBy == 'level': return self.__checkGroupedCompletion( xrange(1, constants.MAX_VEHICLE_LEVEL + 1), progress, bonusLimit, keyMaker=lambda lvl: 'level %d' % lvl) if groupBy == 'class': return self.__checkGroupedCompletion( constants.VEHICLE_CLASSES, progress, bonusLimit) if groupBy == 'vehicle': pass return super(Quest, self).isCompleted() def setChildren(self, children): self._children = children def getChildren(self): return self._children def setParents(self, parents): self._parents = parents def getParents(self): return self._parents def setParentsName(self, parentsName): self._parentsName = parentsName def getParentsName(self): return self._parentsName def getBonusCount(self, groupByKey=None, progress=None): progress = progress or self._progress if progress is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return progress.get(None, {}).get('bonusCount', 0) if groupByKey is not None: return progress.get(groupByKey, {}).get('bonusCount', 0) return sum((p.get('bonusCount', 0) for p in progress.itervalues())) else: return 0 def getProgressData(self): return self._progress or {} def getBonuses(self, bonusName=None, isCompensation=False, bonusData=None, ctx=None): result = [] bonusData = bonusData or self._data.get('bonus', {}) if bonusName is None: for name, value in bonusData.iteritems(): for bonus in getBonuses(self, name, value, isCompensation, ctx=ctx): result.append(self._bonusDecorator(bonus)) if name == 'vehicles': stylesData = self.__getVehicleStyleBonuses(value) for bonus in getBonuses(self, 'customizations', stylesData, isCompensation, ctx=ctx): result.append(self._bonusDecorator(bonus)) elif bonusName in bonusData: for bonus in getBonuses(self, bonusName, bonusData[bonusName], isCompensation, ctx=ctx): result.append(self._bonusDecorator(bonus)) return sorted(result, cmp=compareBonuses, key=operator.methodcaller('getName')) def __getVehicleStyleBonuses(self, vehiclesData): stylesData = [] for vehData in vehiclesData.itervalues(): customization = vehData.get('customization', None) if customization is not None: styleData = { 'value': 1, 'custType': 'style', 'id': customization.get('styleId', -1), 'customCompensation': customization.get('customCompensation', None) } stylesData.append(styleData) return stylesData def getCompensation(self): compensatedToken = findFirst(lambda t: t.isDisplayable(), self.accountReqs.getTokens()) return { compensatedToken.getID(): self.getBonuses(isCompensation=True) } if compensatedToken else {} def hasPremIGRVehBonus(self): vehBonuses = self.getBonuses('vehicles') for vehBonus in vehBonuses: vehicles = vehBonus.getValue() for intCD, data in vehicles.iteritems(): item = self.itemsCache.items.getItemByCD(intCD) if item.isPremiumIGR and data.get('rent', None) is not None: return True return False def getSuitableVehicles(self): return self.vehicleReqs.getSuitableVehicles() def _bonusDecorator(self, bonus): return bonus def __checkGroupedCompletion(self, values, progress, bonusLimit=None, keyMaker=lambda v: v): bonusLimit = bonusLimit or self.bonusCond.getBonusLimit() for value in values: if bonusLimit > self.getBonusCount(groupByKey=keyMaker(value), progress=progress): return False return True def _checkConditions(self): return self.accountReqs.isAvailable() and ( self.vehicleReqs.isAnyVehicleAcceptable() or self.vehicleReqs.getSuitableVehicles()) def _checkVehicleConditions(self, vehicle): return self.vehicleReqs.isAnyVehicleAcceptable( ) or vehicle in self.vehicleReqs.getSuitableVehicles()
class Quest(ServerEventAbstract): itemsCache = dependency.descriptor(IItemsCache) def __init__(self, qID, data, progress=None): super(Quest, self).__init__(qID, data) self._progress = progress self._children, self._parents, self._parentsName = {}, {}, {} conds = dict(data['conditions']) preBattle = dict(conds['preBattle']) self.accountReqs = AccountRequirements(preBattle['account']) self.vehicleReqs = VehicleRequirements(preBattle['vehicle']) self.preBattleCond = PreBattleConditions(preBattle['battle']) self.bonusCond = BonusConditions(conds['common'], self.getProgressData(), self.preBattleCond) self.postBattleCond = PostBattleConditions(conds['postBattle'], self.preBattleCond) self._groupID = DEFAULTS_GROUPS.UNGROUPED_QUESTS self.__linkedActions = [] def isCompensationPossible(self): return isMarathon(self.getGroupID()) and bool( self.getBonuses('tokens')) def isAvailable(self): return ValidationResult( False, 'dailyComplete') if self.bonusCond.getBonusLimit( ) is not None and self.bonusCond.isDaily() and self.isCompleted( ) else super(Quest, self).isAvailable() @property def linkedActions(self): return self.__linkedActions @linkedActions.setter def linkedActions(self, value): self.__linkedActions = value def getUserType(self): return i18n.makeString(QUESTS.ITEM_TYPE_QUEST) def getProgressExpiryTime(self): return self._data.get('progressExpiryTime', time.time()) def isCompletedByGroup(self, groupByKey): bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: if self.bonusCond.getGroupByValue() is None: return self.isCompleted() if self._progress is not None: return bonusLimit <= self.getBonusCount(groupByKey) return False def isCompleted(self, progress=None): progress = progress or self._progress bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return self.getBonusCount(progress=progress) >= bonusLimit if progress is not None: if groupBy == 'nation': return self.__checkGroupedCompletion( nations.AVAILABLE_NAMES, progress, bonusLimit) if groupBy == 'level': return self.__checkGroupedCompletion( xrange(1, constants.MAX_VEHICLE_LEVEL + 1), progress, bonusLimit, keyMaker=lambda lvl: 'level %d' % lvl) if groupBy == 'class': return self.__checkGroupedCompletion( constants.VEHICLE_CLASSES, progress, bonusLimit) if groupBy == 'vehicle': pass return super(Quest, self).isCompleted() def setChildren(self, children): self._children = children def getChildren(self): return self._children def setParents(self, parents): self._parents = parents def getParents(self): return self._parents def setParentsName(self, parentsName): self._parentsName = parentsName def getParentsName(self): return self._parentsName def getBonusCount(self, groupByKey=None, progress=None): progress = progress or self._progress if progress is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return progress.get(None, {}).get('bonusCount', 0) if groupByKey is not None: return progress.get(groupByKey, {}).get('bonusCount', 0) return sum((p.get('bonusCount', 0) for p in progress.itervalues())) else: return 0 def getProgressData(self): return self._progress or {} def getBonuses(self, bonusName=None, isCompensation=False, bonusData=None): result = [] bonusData = bonusData or self._data.get('bonus', {}) if bonusName is None: for name, value in bonusData.iteritems(): for bonus in getBonuses(self, name, value, isCompensation): result.append(self._bonusDecorator(bonus)) elif bonusName in bonusData: for bonus in getBonuses(self, bonusName, bonusData[bonusName], isCompensation): result.append(self._bonusDecorator(bonus)) return sorted(result, cmp=compareBonuses, key=operator.methodcaller('getName')) def getCompensation(self): compensatedToken = findFirst(lambda t: t.isDisplayable(), self.accountReqs.getTokens()) return { compensatedToken.getID(): self.getBonuses(isCompensation=True) } if compensatedToken else {} def hasPremIGRVehBonus(self): vehBonuses = self.getBonuses('vehicles') for vehBonus in vehBonuses: vehicles = vehBonus.getValue() for intCD, data in vehicles.iteritems(): item = self.itemsCache.items.getItemByCD(intCD) if item.isPremiumIGR and data.get('rent', None) is not None: return True return False def getSuitableVehicles(self): return self.vehicleReqs.getSuitableVehicles() def _bonusDecorator(self, bonus): if self.getType( ) == constants.EVENT_TYPE.TOKEN_QUEST and bonus.getName() == 'oneof': if ranked_helpers.isRankedQuestID(self.getID()): _, cohort, _ = ranked_helpers.getRankedDataFromTokenQuestID( self.getID()) bonus.setupIconHandler(BoxBonus.HANDLER_NAMES.RANKED, ('metal', cohort)) bonus.setTooltipType('rankedSeason') return bonus def __checkGroupedCompletion(self, values, progress, bonusLimit=None, keyMaker=lambda v: v): bonusLimit = bonusLimit or self.bonusCond.getBonusLimit() for value in values: if bonusLimit > self.getBonusCount(groupByKey=keyMaker(value), progress=progress): return False return True def _checkConditions(self): return False if not self.accountReqs.isAvailable( ) else self.vehicleReqs.isAnyVehicleAcceptable( ) or self.vehicleReqs.getSuitableVehicles() def _checkVehicleConditions(self, vehicle): return self.vehicleReqs.isAnyVehicleAcceptable( ) or vehicle in self.vehicleReqs.getSuitableVehicles()
class Quest(ServerEventAbstract): def __init__(self, qID, data, progress=None): import copy tmpData = copy.deepcopy(data) super(Quest, self).__init__(qID, data) self._progress = progress self._children, self._parents = {}, {} conds = dict(tmpData['conditions']) preBattle = dict(conds['preBattle']) self.accountReqs = AccountRequirements(self.getType(), preBattle['account']) self.vehicleReqs = VehicleRequirements(preBattle['vehicle']) self.preBattleCond = PreBattleConditions(preBattle['battle']) self.bonusCond = BonusConditions(conds['bonus'], self.getProgressData(), self.preBattleCond) self.postBattleCond = PostBattleConditions(conds['postBattle'], self.preBattleCond) self._groupID = DEFAULTS_GROUPS.UNGROUPED_QUESTS def getUserType(self): if self.getType() == constants.EVENT_TYPE.FORT_QUEST: return i18n.makeString(QUESTS.ITEM_TYPE_SPECIALMISSION) return i18n.makeString(QUESTS.ITEM_TYPE_QUEST) def getProgressExpiryTime(self): return self._data.get('progressExpiryTime', time.time()) def isCompletedByGroup(self, groupByKey): bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: if self.bonusCond.getGroupByValue() is None: return self.isCompleted() if self._progress is not None: return bonusLimit <= self.getBonusCount(groupByKey) return False def isCompleted(self, progress=None): progress = progress or self._progress bonusLimit = self.bonusCond.getBonusLimit() if bonusLimit is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return self.getBonusCount(progress=progress) >= bonusLimit if progress is not None: if groupBy == 'nation': return self.__checkGroupedCompletion( nations.AVAILABLE_NAMES, progress, bonusLimit) if groupBy == 'level': return self.__checkGroupedCompletion( xrange(1, constants.MAX_VEHICLE_LEVEL + 1), progress, bonusLimit, keyMaker=lambda lvl: 'level %d' % lvl) if groupBy == 'class': return self.__checkGroupedCompletion( constants.VEHICLE_CLASSES, progress, bonusLimit) if groupBy == 'vehicle': pass return super(Quest, self).isCompleted() def setChildren(self, children): self._children = children def getChildren(self): return self._children def setParents(self, parents): self._parents = parents def getParents(self): return self._parents def getBonusCount(self, groupByKey=None, progress=None): progress = progress or self._progress if progress is not None: groupBy = self.bonusCond.getGroupByValue() if groupBy is None: return progress.get(None, {}).get('bonusCount', 0) if groupByKey is not None: return progress.get(groupByKey, {}).get('bonusCount', 0) return sum((p.get('bonusCount', 0) for p in progress.itervalues())) else: return 0 def getProgressData(self): return self._progress or {} def getBonuses(self, bonusName=None): result = [] for n, v in self._data.get('bonus', {}).iteritems(): if bonusName is not None and n != bonusName: continue b = getBonusObj(self, n, v) if b is not None: result.append(b) return sorted(result, cmp=compareBonuses, key=operator.methodcaller('getName')) def hasPremIGRVehBonus(self): vehBonuses = self.getBonuses('vehicles') for vehBonus in vehBonuses: vehicles = vehBonus.getValue() for intCD, data in vehicles.iteritems(): item = g_itemsCache.items.getItemByCD(intCD) if item.isPremiumIGR and data.get('rent', None) is not None: return True return False def __checkGroupedCompletion(self, values, progress, bonusLimit=None, keyMaker=lambda v: v): bonusLimit = bonusLimit or self.bonusCond.getBonusLimit() for value in values: if bonusLimit > self.getBonusCount(groupByKey=keyMaker(value), progress=progress): return False return True def _checkConditions(self): isAccAvailable = self.accountReqs.isAvailable() isVehAvailable = self.vehicleReqs.isAnyVehicleAcceptable() or len( self.vehicleReqs.getSuitableVehicles()) > 0 return isAccAvailable and isVehAvailable def _checkVehicleConditions(self, vehicle): return self.vehicleReqs.isAnyVehicleAcceptable( ) or vehicle in self.vehicleReqs.getSuitableVehicles()