def validate(self, update=False): """ Validates vehicles selected in unit if player is in slot now Args: update: is this unit update """ items = g_itemsCache.items invVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) vehCDs = invVehicles.keys() pInfo = self.__entity.getPlayerInfo() if pInfo.isInSlot: _, unit = self.__entity.getUnit() roster = unit.getRoster() if not roster.checkVehicleList( vehCDs, pInfo.slotIdx) and not pInfo.isCommander(): self.__entity.request( AssignUnitCtx(pInfo.dbID, UNIT_SLOT.REMOVE, 'prebattle/assign')) elif self.__entity.getEntityType() != PREBATTLE_TYPE.FALLOUT: resultCtx = self.__entity.invalidateSelectedVehicles(vehCDs) if resultCtx is not None: self.__entity.request(resultCtx) elif update: self.__entity.unit_onUnitPlayerVehDictChanged( getAccountDatabaseID()) elif update: self.__entity.unit_onUnitPlayerVehDictChanged( getAccountDatabaseID()) return
def clanRole(self): user = self.usersStorage.getUser(getAccountDatabaseID()) if user: role = user.getClanRole() else: role = 0 return role
def _extractSettings(self, unit): kwargs = super(PublicDynamicRosterSettings, self)._extractSettings(unit) if kwargs and unit.getCommanderDBID( ) == account_helpers.getAccountDatabaseID(): kwargs['maxEmptySlots'] = kwargs['maxSlots'] - 1 return kwargs
def unit_onUnitPlayerRoleChanged(self, playerID, prevRoleFlags, nextRoleFlags): super(EpicSquadEntity, self).unit_onUnitPlayerRoleChanged(playerID, prevRoleFlags, nextRoleFlags) if playerID == account_helpers.getAccountDatabaseID(): self.unit_onUnitRosterChanged()
def __init__(self): StaticFormationStaffViewMeta.__init__(self) UsersInfoHelper.__init__(self) ClubPage.__init__(self) self.__openCloseCallbackID = None self.__viewerDbID = getAccountDatabaseID() self.addListener(events.CoolDownEvent.CLUB, self.__handleClubCooldown, scope=EVENT_BUS_SCOPE.LOBBY)
def unit_onUnitPlayerRoleChanged(self, playerID, prevRoleFlags, nextRoleFlags): super(SortieEntity, self).unit_onUnitPlayerRoleChanged(playerID, prevRoleFlags, nextRoleFlags) if playerID == account_helpers.getAccountDatabaseID(): self.__isLegionary = self.getPlayerInfo().isLegionary()
def _vehicleStateCondition(self, v): result = True if self._isUseSPGValidateRule and v.type == VEHICLE_CLASS_NAME.SPG: isHaveSPG = False accountDbID = account_helpers.getAccountDatabaseID() spgDifferenceCount = self.getMaxSPGCount( ) - self.getCurrentSPGCount() if self.getMaxSPGCount() == 0: return (False, None) elif self.isCommander(accountDbID): return (result, None) elif spgDifferenceCount == 0: _, _ = self.getUnit() vInfos = self.getVehiclesInfo() for vInfo in vInfos: if vInfo.vehClassIdx == VEHICLE_CLASS_INDICES['SPG']: isHaveSPG = True if isHaveSPG: return (result, None) return (False, None) elif spgDifferenceCount > 0: return (result, None) else: return (False, None) return super(EpicSquadEntity, self)._vehicleStateCondition(v)
def _vehicleStateCondition(self, v): result = True if self._isBalancedSquad: result = v.level in self._rosterSettings.getLevelsRange() if not result: return False if self._isUseSPGValidateRule and v.type == VEHICLE_CLASS_NAME.SPG: isHaveSPG = False accountDbID = account_helpers.getAccountDatabaseID() spgDifferenceCount = self.getMaxSPGCount( ) - self.getCurrentSPGCount() if self.getMaxSPGCount() == 0: return False elif self.isCommander(accountDbID): return result elif spgDifferenceCount == 0: _, _ = self.getUnit() vInfos = self.getVehiclesInfo() for vInfo in vInfos: if vInfo.vehClassIdx == VEHICLE_CLASS_INDICES['SPG']: isHaveSPG = True if isHaveSPG: return result return False elif spgDifferenceCount > 0: return result else: return False return super(RandomSquadEntity, self)._vehicleStateCondition(v)
def canLeaveClub(self, profile, club=None): stateID = profile.getState().getStateID() if stateID != _CCB.HAS_CLUB: return error(_CCR.HAS_NO_CLUB) if club is not None: if not club.hasMember(getAccountDatabaseID()): return error(_CCR.NOT_A_CLUB_MEMBER) return self._isClubRequestValid(_CRT.LEAVE_CLUB, club, 'canLeaveClub')
def unit_onUnitPlayerRoleChanged(self, playerID, prevRoleFlags, nextRoleFlags): super(RandomSquadEntity, self).unit_onUnitPlayerRoleChanged(playerID, prevRoleFlags, nextRoleFlags) if self._isBalancedSquad and playerID == account_helpers.getAccountDatabaseID( ): self.unit_onUnitRosterChanged()
def wasInBattle(self, dbID = 0): """Was player in the battle? :param dbID: long containing account database ID or 0. :return: True if player was in the battle, otherwise - False. """ if not dbID: dbID = getAccountDatabaseID() return self.__players.getPlayerInfo(dbID).wasInBattle
def _onUnitMemberVehiclesChanged(self, accoundDbID): """ Routine that holds additional logic related to vehicles list change for player """ self.invalidateVehicleStates() if self._isBalancedSquad and accoundDbID != account_helpers.getAccountDatabaseID(): self.unit_onUnitRosterChanged()
def canLeaveClub(self, profile, club = None): stateID = profile.getState().getStateID() if stateID != _CCB.HAS_CLUB: return error(_CCR.HAS_NO_CLUB) if club is not None: if not club.hasMember(getAccountDatabaseID()): return error(_CCR.NOT_A_CLUB_MEMBER) return self._isClubRequestValid(_CRT.LEAVE_CLUB, club, 'canLeaveClub')
def _makeAchievements(dossier, club): achievements = dossier.getTotalStats().getAchievements() mergedList = list(itertools.chain(*achievements)) isForClubMember = club.hasMember(getAccountDatabaseID()) return AchievementsUtils.packAchievementList(mergedList, dossier.getDossierType(), dumpDossier(dossier), isForClubMember, True)
def _createCache(self): databaseID = getAccountDatabaseID() if databaseID: self._cache = _StorageForSellCache(databaseID) self._cache.read() return self._cache else: return None
def _extractSettings(self, unit): kwargs = super(BalancedSquadDynamicRosterSettings, self)._extractSettings(unit) if kwargs and unit.getCommanderDBID() != getAccountDatabaseID(): vehicles = unit.getMemberVehicles(unit.getCommanderDBID()) if vehicles: levels = [ vehInfo.vehLevel for vehInfo in vehicles ] kwargs['minLevel'] = max(MIN_VEHICLE_LEVEL, min(levels) + self._lowerBound) kwargs['maxLevel'] = min(MAX_VEHICLE_LEVEL, max(levels) + self._upperBound) return kwargs
def assignSlotRequest(self, slotIndex, playerId): if playerId == -1: if self.unitFunctional.getPlayerInfo().isCreator(): LOG_DEBUG('Request to assign is ignored. Creator can not move to another slots') return playerId = account_helpers.getAccountDatabaseID() elif not self.isPlayerInUnit(playerId): return self.requestToAssign(playerId, slotIndex)
def validate(self, update = False): items = g_itemsCache.items invVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) vehCDs = invVehicles.keys() pInfo = self.__functional.getPlayerInfo() if pInfo.isInSlot: _, unit = self.__functional.getUnit() roster = unit.getRoster() if not roster.checkVehicleList(vehCDs, pInfo.slotIdx) and not pInfo.isCreator(): self.__functional.request(unit_ctx.AssignUnitCtx(pInfo.dbID, UNIT_SLOT.REMOVE, 'prebattle/assign')) else: resultCtx = self.__functional.invalidateSelectedVehicles(vehCDs) if resultCtx is not None: self.__functional.request(resultCtx) elif update: self.__functional.unit_onUnitPlayerVehDictChanged(getAccountDatabaseID()) elif update: self.__functional.unit_onUnitPlayerVehDictChanged(getAccountDatabaseID()) return
def goToLobby(self): databaseID = account_helpers.getAccountDatabaseID() raise databaseID or AssertionError('Acoount database ID is not defined') isFirstStart = databaseID not in self.__loggedDBIDs self.__loggedDBIDs.add(databaseID) state = {'isFirstStart': isFirstStart, 'isAfterBattle': self.__afterBattle} self.__setDispatcher(_LOBBY_DISPATCHER) self.__restoreID = _SETTINGS.QUESTS.id self.__doAutoRun((_SETTINGS.OFFBATTLE, _SETTINGS.QUESTS), state) self.__hintsManager = HintsManager() self.__hintsManager.start()
def validate(self, update=False): items = self.itemsCache.items invVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) vehCDs = invVehicles.keys() pInfo = self.__entity.getPlayerInfo() if pInfo.isInSlot: _, unit = self.__entity.getUnit(safe=False) roster = unit.getRoster() if not roster.checkVehicleList(vehCDs, pInfo.slotIdx) and not pInfo.isCommander(): self.__entity.request(AssignUnitCtx(pInfo.dbID, UNIT_SLOT.REMOVE, 'prebattle/assign')) elif update: self.__entity.unit_onUnitPlayerVehDictChanged(getAccountDatabaseID())
def _getRoleByDatabaseID(self, dbID=None, team=None): if dbID is None: dbID = account_helpers.getAccountDatabaseID() rosters = prb_getters.getPrebattleRosters() possibleRosters = PREBATTLE_ROSTER.getRange(self.getEntityType(), team) for roster in possibleRosters: if roster in rosters: for data in rosters[roster].itervalues(): if data['dbID'] == dbID: return data.get('role', 0) return 0
def getConfirmDialogMeta(self, ctx): if self.__errorCount == 0 and self.hasLockedState(): meta = super(StrongholdEntity, self).getConfirmDialogMeta(ctx) else: pDbID = account_helpers.getAccountDatabaseID() members, clanMembers = self._getClanMembers() if ctx.hasFlags(FUNCTIONAL_FLAG.EXIT) or pDbID in members: isFirstBattle = self.__strongholdSettings.isFirstBattle() isLastClanMember = len(clanMembers) == 1 and clanMembers[0] == pDbID subKey = 'Defeat' if isLastClanMember and not isFirstBattle else '' meta = StrongholdConfirmDialogMeta(key='leave', subKey=subKey) else: meta = None return meta
def validate(self, update=False): items = g_itemsCache.items invVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY) vehCDs = invVehicles.keys() pInfo = self.__functional.getPlayerInfo() if pInfo.isInSlot: _, unit = self.__functional.getUnit() roster = unit.getRoster() if not roster.checkVehicleList( vehCDs, pInfo.slotIdx) and not pInfo.isCreator(): self.__functional.request( unit_ctx.AssignUnitCtx(pInfo.dbID, UNIT_SLOT.REMOVE, 'prebattle/assign')) else: vInfo = self.__functional.getVehicleInfo() resultCtx = vInfo.updateInventory(vehCDs) if resultCtx is not None: self.__functional.request(resultCtx) elif update: self.__functional.unit_onUnitPlayerVehDictChanged( getAccountDatabaseID()) elif update: self.__functional.unit_onUnitPlayerVehDictChanged( getAccountDatabaseID())
def _extractSettings(self, unit): kwargs = super(BalancedSquadDynamicRosterSettings, self)._extractSettings(unit) accountDbID = getAccountDatabaseID() if kwargs and unit.getCommanderDBID() != accountDbID: vehicles = unit.getMemberVehicles(unit.getCommanderDBID()) if not vehicles: unitVehicles = unit.getVehicles() for accDbID, vInfos in unitVehicles.iteritems(): if accDbID != accountDbID: vehicles.extend(vInfos) minLevel, maxLevel = self._getVehicleLevels(vehicles) kwargs['minLevel'] = minLevel kwargs['maxLevel'] = maxLevel return kwargs
def getRoles(self, pDatabaseID = None, clanDBID = None, team = None): result = 0 if self._settings is None: return result if pDatabaseID is None: pDatabaseID = account_helpers.getAccountDatabaseID() roles = self._settings['roles'] if pDatabaseID in roles: result = roles[pDatabaseID] if not result and clanDBID: roles = self._settings['clanRoles'] if clanDBID in roles: result = roles[clanDBID] if not result and team: roles = self._settings['teamRoles'] if team in roles: result = roles[team] return result
def isVehcleOfClassAvailable(self): accountDbID = account_helpers.getAccountDatabaseID() availableVehicles = self.getMaxVehiclesOfClass( ) - self.getCurrentVheiclesOfClassCount() if self.getMaxVehiclesOfClass() == 0: return False if self.__unitEntity.isCommander(accountDbID): return True if availableVehicles == 0: _, _ = self.__unitEntity.getUnit() vInfos = self.__unitEntity.getVehiclesInfo() for vInfo in vInfos: if vInfo.vehClassIdx == VEHICLE_CLASS_INDICES[ self._VEHICLE_CLASS_NAME]: return True return False return availableVehicles > 0
def _makeVO(self, memberData): memberDBID = memberData.getDbID() contactEntity = self.userStorage.getUser(memberDBID) if contactEntity: userVO = ContactConverter().makeVO(contactEntity) userVO['userProps']['clanAbbrev'] = '' else: userVO = {'userProps': {'userName': self.__getMemberName(memberData)}} return {'dbID': memberDBID, 'userName': self.__getMemberName(memberData), 'post': items.formatField(getter=memberData.getRoleString), 'postIcon': memberData.getRoleIcon(), 'personalRating': items.formatField(getter=memberData.getGlobalRating, formatter=BigWorld.wg_getIntegralFormat), 'battlesCount': items.formatField(getter=memberData.getBattlesCount, formatter=BigWorld.wg_getIntegralFormat), 'wins': items.formatField(getter=memberData.getBattlesPerformanceAvg, formatter=lambda x: BigWorld.wg_getNiceNumberFormat(x) + '%'), 'awgExp': items.formatField(getter=memberData.getBattleXpAvg, formatter=BigWorld.wg_getIntegralFormat), 'daysInClan': items.formatField(getter=memberData.getDaysInClan, formatter=BigWorld.wg_getIntegralFormat), 'canShowContextMenu': memberDBID != getAccountDatabaseID(), 'contactItem': userVO}
def getRoles(self, pDatabaseID = None, clanDBID = None, team = None): result = 0 if self._settings is None: return result else: if pDatabaseID is None: pDatabaseID = account_helpers.getAccountDatabaseID() roles = self._settings['roles'] if pDatabaseID in roles: result = roles[pDatabaseID] if not result and clanDBID: roles = self._settings['clanRoles'] if clanDBID in roles: result = roles[clanDBID] if not result and team: roles = self._settings['teamRoles'] if team in roles: result = roles[team] return result
def goToLobby(self): databaseID = account_helpers.getAccountDatabaseID() if not databaseID: raise SoftException('Acoount database ID is not defined') isFirstStart = databaseID not in self.__loggedDBIDs self.__loggedDBIDs.add(databaseID) state = {'isFirstStart': isFirstStart, 'isAfterBattle': self.__afterBattle} self.__setDispatcher(_LOBBY_DISPATCHER) self.__restoreID = _SETTINGS.QUESTS.id bootcampController = dependency.instance(IBootcampController) isInBootcampAccount = bootcampController.isInBootcampAccount() if isInBootcampAccount: selectedSettings = self.__doAutoRun((_SETTINGS.OFFBATTLE, _SETTINGS.QUESTS, _SETTINGS.BOOTCAMP_LOBBY), state) else: selectedSettings = None if selectedSettings is None or selectedSettings.hintsEnabled: self.__hintsManager = HintsManager() self.__hintsManager.start() return
def onUnitVehiclesChanged(self, dbID, vInfos): if dbID == account_helpers.getAccountDatabaseID(): self.__updateVehicles() self._proxy.onVehiclesChanged()
def isCurrentPlayer(self): return self.dbID == getAccountDatabaseID()
def isCurrentPlayer(self): if self.dbID > 0: result = self.dbID == getAccountDatabaseID() else: result = self.accID == getPlayerID() return result
def __init__(self, clansCtrl): stats = g_itemsCache.items.stats ClanAccountProfile.__init__(self, clansCtrl, getAccountDatabaseID(), stats.clanDBID, stats.clanInfo)
def onUnitVehiclesChanged(self, dbID, vInfos): if dbID != account_helpers.getAccountDatabaseID(): self._updateRallyData()
def hasSlotForSPG(self): accountDbID = account_helpers.getAccountDatabaseID() return self.getMaxSPGCount() > 0 and ( self.getCurrentSPGCount() < self.getMaxSPGCount() or self.isCommander(accountDbID))
def getAccountDbID(self): return getAccountDatabaseID()
def canAssignToSlot(self, dbID): return self._roles & UNIT_ROLE.ADD_REMOVE_MEMBERS > 0 or dbID == account_helpers.getAccountDatabaseID()
def __getButtonInfo(self, club): dbID = account_helpers.getAccountDatabaseID() if club.hasMember(dbID): return self.__getMemberBtnInfo(club) else: return self.__getNotMemberBtnInfo(club)
def isPromoAutoViewsEnabled(cls): return getAccountDatabaseID() % cls.PROMO_AUTO_VIEWS_TEST_VALUE != 0 and g_lobbyContext.getServerSettings().isPromoAutoViewsEnabled()
def __init__(self, success = None): super(PlayerFortRequester, self).__init__(success) self._databaseID = getAccountDatabaseID() self._individualRqIDs = set()
def getPlayerDatabaseID(): return getAccountDatabaseID() or getAvatarDatabaseID()
def unit_onUnitPlayerRemoved(self, playerID, playerData): super(EpicSquadEntity, self).unit_onUnitPlayerRemoved(playerID, playerData) if playerID == account_helpers.getAccountDatabaseID(): self.unit_onUnitRosterChanged()
def reportBug(self): reportBugOpenConfirm(getAccountDatabaseID() or getAvatarDatabaseID())
def _onUnitMemberVehiclesChanged(self, accoundDbID): self.invalidateVehicleStates() if accoundDbID != account_helpers.getAccountDatabaseID(): self.unit_onUnitRosterChanged()
def _takeLeadership(self): yield self.prbDispatcher.sendUnitRequest(unit_ctx.GiveLeadershipCtx(getAccountDatabaseID(), 'prebattle/takeLeadership'))