def _getConditions(self, svrEvents): subBlocks = [] bonus = self.event.bonusCond battlesLeft, battlesCount, inrow = None, None, False battles = bonus.getConditions().find('battles') if battles is not None: battlesCount = battles._getTotalValue() if not self.event.isCompleted() and bonus.getGroupByValue() is None: progress = battles.getProgressPerGroup() if None in progress: curProg, totalProg, _, _ = progress[None] battlesLeft = totalProg - curProg bonusFmtConds = bonus.format(svrEvents, event=self.event) if len(bonusFmtConds): subBlocks.extend(formatters.indexing(bonusFmtConds)) postBattleFmtConds = self.event.postBattleCond.format(svrEvents, event=self.event) if len(postBattleFmtConds): if len(bonusFmtConds): subBlocks.append(formatters.packSeparator(label=i18n.makeString('#quests:details/conditions/postBattle/separator'))) subBlocks.extend(formatters.indexing(postBattleFmtConds)) if bonus.isDaily(): resetHourOffset = (time_utils.ONE_DAY - self._getDailyProgressResetTimeOffset()) / 3600 if resetHourOffset >= 0: subBlocks.append(formatters.packTextBlock(label=formatters.formatYellow('#quests:details/conditions/postBattle/dailyReset') % {'time': time.strftime(i18n.makeString('#quests:details/conditions/postBattle/dailyReset/timeFmt'), time_utils.getTimeStructInLocal(time_utils.getTimeTodayForUTC(hour=resetHourOffset)))})) result = [] if len(subBlocks) or battlesCount: if not self.event.isGuiDisabled(): result.append(formatters.packConditionsBlock(battlesCount, battlesLeft, bonus.isInRow(), conditions=subBlocks)) else: result.append(formatters.packConditionsBlock(conditions=subBlocks)) if bonus.getGroupByValue() is not None and not self.event.isGuiDisabled(): progressesFmt = bonus.formatGroupByProgresses(svrEvents, self.event) if len(progressesFmt): result.append(formatters.packTopLevelContainer(i18n.makeString('#quests:details/conditions/groupBy/%s' % bonus.getGroupByValue()), subBlocks=progressesFmt, isResizable=len(progressesFmt) > 5)) return formatters.todict(result)
def _packConditions(self, svrEvents): subBlocks = [] bonus = self.event.bonusCond battlesLeft, battlesCount, inrow = None, None, False battles = bonus.getConditions().find('battles') if battles is not None: battlesCount = battles._getTotalValue() if not self.event.isCompleted() and bonus.getGroupByValue() is None: progress = battles.getProgressPerGroup() if None in progress: curProg, totalProg, _, _ = progress[None] battlesLeft = totalProg - curProg bonusFmtConds = bonus.format(svrEvents, event=self.event) if len(bonusFmtConds): subBlocks.extend(formatters.indexing(bonusFmtConds)) postBattleFmtConds = self.event.postBattleCond.format(svrEvents, event=self.event) if len(postBattleFmtConds): if len(bonusFmtConds): subBlocks.append(formatters.packSeparator(label=i18n.makeString('#quests:details/conditions/postBattle/separator'))) subBlocks.extend(formatters.indexing(postBattleFmtConds)) if bonus.isDaily(): resetHourOffset = (time_utils.ONE_DAY - self._getDailyProgressResetTimeOffset()) / 3600 if resetHourOffset >= 0: subBlocks.append(formatters.packTextBlock(label=formatters.formatYellow('#quests:details/conditions/postBattle/dailyReset') % {'time': time.strftime(i18n.makeString('#quests:details/conditions/postBattle/dailyReset/timeFmt'), time_utils.getTimeStructInLocal(time_utils.getTimeTodayForUTC(hour=resetHourOffset)))})) result = [] if len(subBlocks) or battlesCount: if not self.event.isGuiDisabled(): result.append(formatters.packConditionsBlock(battlesCount, battlesLeft, bonus.isInRow(), conditions=subBlocks)) else: result.append(formatters.packConditionsBlock(conditions=subBlocks)) if bonus.getGroupByValue() is not None and not self.event.isGuiDisabled(): progressesFmt = bonus.formatGroupByProgresses(svrEvents, self.event) if len(progressesFmt): result.append(formatters.packTopLevelContainer(i18n.makeString('#quests:details/conditions/groupBy/%s' % bonus.getGroupByValue()), subBlocks=progressesFmt, isResizable=len(progressesFmt) > 5)) return result
def _packConditions(self, svrEvents): subBlocks = [] bonus = self.event.bonusCond battlesLeft, battlesCount, inrow = None, None, False battles = bonus.getConditions().find('battles') if battles is not None: battlesCount = battles.getTotalValue() if not self.event.isCompleted( ) and bonus.getGroupByValue() is None: progress = battles.getProgressPerGroup() if None in progress: curProg, totalProg, _, _ = progress[None] battlesLeft = totalProg - curProg bonusFmtConds = bonusCondFormatter.format(bonus, self.event) if len(bonusFmtConds): subBlocks.extend(formatters.indexing(bonusFmtConds)) postBattleFmtConds = postBattleConditionFormatter.format( self.event.postBattleCond, self.event) if len(postBattleFmtConds): if len(bonusFmtConds): subBlocks.append( formatters.packSeparator(label=i18n.makeString( '#quests:details/conditions/postBattle/separator'))) subBlocks.extend(formatters.indexing(postBattleFmtConds)) resetLabel = self._getDailyResetStatus( '#quests:details/conditions/postBattle/dailyReset', formatters.formatYellow) if resetLabel: subBlocks.append(formatters.packTextBlock(label=resetLabel)) result = [] if len(subBlocks) or battlesCount: if not self.event.isGuiDisabled(): result.append( formatters.packConditionsBlock(battlesCount, battlesLeft, bonus.isInRow(), conditions=subBlocks)) else: result.append( formatters.packConditionsBlock(conditions=subBlocks)) if bonus.getGroupByValue( ) is not None and not self.event.isGuiDisabled(): progressesFmt = bonusCondFormatter.formatGroupByProgresses( bonus, self.event) if len(progressesFmt): result.append( formatters.packTopLevelContainer( i18n.makeString( '#quests:details/conditions/groupBy/%s' % bonus.getGroupByValue()), subBlocks=progressesFmt, isResizable=len(progressesFmt) > 5)) return result
def formatGroupByProgresses(self, svrEvents, event=None): battlesLeft = {} groups = defaultdict(list) for c in self.getConditions().items: if isinstance(c, conditions._Cumulativable): for groupByKey, (current, total, _, _) in c.getProgressPerGroup().iteritems(): groups[groupByKey].extend( c.formatByGroup(svrEvents, groupByKey, event)) if c.getName() == 'battles': battlesLeft[groupByKey] = total - current result = [] if event is None or not event.isCompleted(): for groupByKey, groupConds in groups.iteritems(): isGroupCompleted = self.__isGroupProgressCompleted(groupByKey) groupByItem, packedData = self.__packGroupByBlock( self.getGroupByValue(), groupByKey, battlesLeft.get(groupByKey), self.isInRow(), formatters.indexing(groupConds), isGroupCompleted) result.append((groupByItem, packedData, isGroupCompleted)) def _sortFunc(a, b): res = int(a[2]) - int(b[2]) if res: return res return cmp(a, b) return map(lambda v: v[1], sorted(result, cmp=_sortFunc))
def formatGroupByProgresses(self, svrEvents, event=None): battlesLeft = {} groups = defaultdict(list) for c in self.getConditions().items: if isinstance(c, conditions._Cumulativable): for groupByKey, (current, total, _, _) in c.getProgressPerGroup().iteritems(): groups[groupByKey].extend(c.formatByGroup(svrEvents, groupByKey, event)) if c.getName() == "battles": battlesLeft[groupByKey] = total - current result = [] if event is None or not event.isCompleted(): for groupByKey, groupConds in groups.iteritems(): isGroupCompleted = self.__isGroupProgressCompleted(groupByKey) groupByItem, packedData = self.__packGroupByBlock( self.getGroupByValue(), groupByKey, battlesLeft.get(groupByKey), self.isInRow(), formatters.indexing(groupConds), isGroupCompleted, ) result.append((groupByItem, packedData, isGroupCompleted)) def _sortFunc(a, b): res = int(a[2]) - int(b[2]) if res: return res return cmp(a, b) return map(lambda v: v[1], sorted(result, cmp=_sortFunc))
def formatGroupByProgresses(self, conditions, event): battlesLeft = {} groups = defaultdict(list) for c in conditions.getConditions().items: condName = c.getName() for groupByKey, (current, total, _, _) in c.getProgressPerGroup().iteritems(): formatter = self.getConditionFormatter(condName) if formatter: groups[groupByKey].extend(formatter.formatByGroup(c, groupByKey, event)) if condName == 'battles': battlesLeft[groupByKey] = total - current result = [] if not event.isCompleted(): for groupByKey, groupConds in groups.iteritems(): isGroupCompleted = conditions.isGroupProgressCompleted(groupByKey) groupByItem, packedData = self._packGroupByBlock(conditions.getGroupByValue(), groupByKey, battlesLeft.get(groupByKey), conditions.isInRow(), formatters.indexing(groupConds), isGroupCompleted) result.append((groupByItem, packedData, isGroupCompleted)) def _sortFunc(a, b): res = int(a[2]) - int(b[2]) if res: return res return cmp(a, b) return map(lambda v: v[1], sorted(result, cmp=_sortFunc))