def __init__(self, accID, name='', dbID=0, state=PREBATTLE_ACCOUNT_STATE.UNKNOWN, time=0.0, vehCompDescr=0, igrType=0, clanDBID=0, clanAbbrev='', roster=0, entity=None, badges=None, group=0, vehEnhancements=None): self.accID = accID self.name = name self.dbID = dbID self.state = state self.time = time self.vehCompDescr = vehCompDescr self.igrType = igrType self.clanDBID = clanDBID self.clanAbbrev = clanAbbrev self.roster = roster self.badges = BadgesHelper(badges or ()) self.group = group self.vehEnhancements = vehEnhancements or {} if entity is not None: self.isCreator = entity.isCommander(pDatabaseID=self.dbID) else: self.isCreator = False return
def __init__(self, t, prbID, info): super(PrbListItem, self).__init__() self.prbID = prbID self.time = t self.arenaTypeID = 0 if PREBATTLE_CACHE_KEY.ARENA_TYPE_ID in info: self.arenaTypeID = info[PREBATTLE_CACHE_KEY.ARENA_TYPE_ID] self.creator = '' if PREBATTLE_CACHE_KEY.CREATOR in info: self.creator = info[PREBATTLE_CACHE_KEY.CREATOR] self.clanAbbrev = '' if PREBATTLE_CACHE_KEY.CREATOR_CLAN_ABBREV in info: self.clanAbbrev = info[PREBATTLE_CACHE_KEY.CREATOR_CLAN_ABBREV] self.playersCount = 0 if PREBATTLE_CACHE_KEY.PLAYER_COUNT in info: self.playersCount = info[PREBATTLE_CACHE_KEY.PLAYER_COUNT] self.isOpened = True if PREBATTLE_CACHE_KEY.IS_OPENED in info: self.isOpened = info[PREBATTLE_CACHE_KEY.IS_OPENED] self.comment = '' if PREBATTLE_CACHE_KEY.COMMENT in info: self.comment = info[PREBATTLE_CACHE_KEY.COMMENT] self.creatorIgrType = 0 if PREBATTLE_CACHE_KEY.CREATOR_IGR_TYPE in info: self.creatorIgrType = info[PREBATTLE_CACHE_KEY.CREATOR_IGR_TYPE] self.creatorDbId = 0 if PREBATTLE_CACHE_KEY.CREATOR_DB_ID in info: self.creatorDbId = info[PREBATTLE_CACHE_KEY.CREATOR_DB_ID] creatorBadges = [] if PREBATTLE_CACHE_KEY.CREATOR_BADGES in info: creatorBadges = info[PREBATTLE_CACHE_KEY.CREATOR_BADGES] self.badges = BadgesHelper(creatorBadges)
class PrbListItem(object): __slots__ = ('prbID', 'time', 'arenaTypeID', 'creator', 'clanAbbrev', 'playersCount', 'isOpened', 'comment', 'creatorIgrType', 'creatorDbId', 'badges') def __init__(self, t, prbID, info): super(PrbListItem, self).__init__() self.prbID = prbID self.time = t self.arenaTypeID = 0 if PREBATTLE_CACHE_KEY.ARENA_TYPE_ID in info: self.arenaTypeID = info[PREBATTLE_CACHE_KEY.ARENA_TYPE_ID] self.creator = '' if PREBATTLE_CACHE_KEY.CREATOR in info: self.creator = info[PREBATTLE_CACHE_KEY.CREATOR] self.clanAbbrev = '' if PREBATTLE_CACHE_KEY.CREATOR_CLAN_ABBREV in info: self.clanAbbrev = info[PREBATTLE_CACHE_KEY.CREATOR_CLAN_ABBREV] self.playersCount = 0 if PREBATTLE_CACHE_KEY.PLAYER_COUNT in info: self.playersCount = info[PREBATTLE_CACHE_KEY.PLAYER_COUNT] self.isOpened = True if PREBATTLE_CACHE_KEY.IS_OPENED in info: self.isOpened = info[PREBATTLE_CACHE_KEY.IS_OPENED] self.comment = '' if PREBATTLE_CACHE_KEY.COMMENT in info: self.comment = info[PREBATTLE_CACHE_KEY.COMMENT] self.creatorIgrType = 0 if PREBATTLE_CACHE_KEY.CREATOR_IGR_TYPE in info: self.creatorIgrType = info[PREBATTLE_CACHE_KEY.CREATOR_IGR_TYPE] self.creatorDbId = 0 if PREBATTLE_CACHE_KEY.CREATOR_DB_ID in info: self.creatorDbId = info[PREBATTLE_CACHE_KEY.CREATOR_DB_ID] creatorBadges = [] if PREBATTLE_CACHE_KEY.CREATOR_BADGES in info: creatorBadges = info[PREBATTLE_CACHE_KEY.CREATOR_BADGES] self.badges = BadgesHelper(creatorBadges) def __repr__(self): return 'PrbListItem(prbID = {0:n}, arenaTypeID = {1:n}, creator = {2:>s}, playersCount = {3:n}, isOpened = {4!r:s}, time = {5:n}, creatorIgrType = {6:n}, creatorDbId = {7:n})'.format( self.prbID, self.arenaTypeID, self.getCreatorFullName(), self.playersCount, self.isOpened, self.time, self.creatorIgrType, self.creatorDbId) def getCreatorFullName(self): if self.clanAbbrev: fullName = '{0:>s}[{1:>s}]'.format(self.creator, self.clanAbbrev) else: fullName = self.creator return fullName def getCensoredComment(self): return passCensor(self.comment) if self.comment else '' def getBadgeID(self): return self.badges.getBadgeID() def getBadgeImgStr(self, size=24, vspace=-6): return self.badges.getBadgeImgStr(size, vspace)
def __new__(cls, clientID = -1, createTime = None, type = 0, comment = str(), creator = str(), creatorDBID = -1, creatorClanAbbrev = None, creatorBadges = None, receiver = str(), receiverDBID = -1, receiverClanAbbrev = None, state = None, count = 0, peripheryID = 0, prebattleID = 0, extraData = None, alwaysAvailable = None, ownerDBID = -1, expiryTime = None, id = -1, **kwargs): if ownerDBID < 0: ownerDBID = creatorDBID bagdesHelper = BadgesHelper(creatorBadges) result = _PrbInviteData.__new__(cls, clientID, createTime, type, comment, creator, creatorDBID, creatorClanAbbrev, bagdesHelper, receiver, receiverDBID, receiverClanAbbrev, state, count, peripheryID, prebattleID, extraData or {}, alwaysAvailable, ownerDBID, expiryTime, id) result.showAt = 0 return result
def __init__(self, dbID, unitMgrID, unit, nickName = '', rating = 0, role = 0, accountID = 0, vehDict = None, isReady = False, isInSlot = False, slotIdx = -1, clanAbbrev = None, timeJoin = 0, igrType = 0, clanDBID = None, badges = [], **kwargs): self.dbID = dbID self.unitMgrID = unitMgrID if unit is not None: self.unit = weakref.proxy(unit) else: self.unit = None self.name = nickName self.rating = rating self.role = role self.accID = accountID self.vehDict = vehDict or {} self.isReady = isReady self.isInSlot = isInSlot self.slotIdx = slotIdx self.clanDBID = clanDBID self.clanAbbrev = clanAbbrev self.timeJoin = timeJoin self.igrType = igrType self.badges = BadgesHelper(badges) return
class PlayerUnitInfo(object): __slots__ = ('dbID', 'unitMgrID', 'unit', 'name', 'rating', 'role', 'accID', 'vehDict', 'isReady', 'isInSlot', 'slotIdx', 'regionCode', 'clanDBID', 'clanAbbrev', 'timeJoin', 'igrType', 'badges') itemsCache = dependency.descriptor(IItemsCache) lobbyContext = dependency.descriptor(ILobbyContext) def __init__(self, dbID, unitMgrID, unit, nickName = '', rating = 0, role = 0, accountID = 0, vehDict = None, isReady = False, isInSlot = False, slotIdx = -1, clanAbbrev = None, timeJoin = 0, igrType = 0, clanDBID = None, badges = [], **kwargs): self.dbID = dbID self.unitMgrID = unitMgrID if unit is not None: self.unit = weakref.proxy(unit) else: self.unit = None self.name = nickName self.rating = rating self.role = role self.accID = accountID self.vehDict = vehDict or {} self.isReady = isReady self.isInSlot = isInSlot self.slotIdx = slotIdx self.clanDBID = clanDBID self.clanAbbrev = clanAbbrev self.timeJoin = timeJoin self.igrType = igrType self.badges = BadgesHelper(badges) return def __repr__(self): return 'PlayerUnitInfo(dbID = {0:n}, fullName = {1:>s}, unitMgrID = {2:n} rating = {3:n}, isCommander = {4!r:s}, role = {5:n}, accID = {6:n}, isReady={7!r:s}, isInSlot={8!r:s}, igrType = {9:n})'.format(self.dbID, self.getFullName(), self.unitMgrID, self.rating, self.isCommander(), self.role, self.accID, self.isReady, self.isInSlot, self.igrType) def getFullName(self): return self.lobbyContext.getPlayerFullName(self.name, clanAbbrev=self.clanAbbrev, pDBID=self.dbID) def getRegion(self): return self.lobbyContext.getRegionCode(self.dbID) def isCommander(self): return self.role & UNIT_ROLE.CREATOR == UNIT_ROLE.CREATOR and self.slotIdx == CREATOR_SLOT_INDEX def isInvite(self): return self.role & UNIT_ROLE.INVITED > 0 def isInArena(self): return self.role & UNIT_ROLE.IN_ARENA > 0 def isOffline(self): return self.role & UNIT_ROLE.OFFLINE > 0 def isInSearch(self): if self.unit is not None: return self.unit.getFlags() & UNIT_FLAGS.IN_SEARCH > 0 else: return False def isInQueue(self): if self.unit is not None: return self.unit.getFlags() & UNIT_FLAGS.IN_QUEUE > 0 else: return False def isLegionary(self): return self.role & UNIT_ROLE.LEGIONARY > 0 def isCurrentPlayer(self): return self.dbID == getAccountDatabaseID() def getVehiclesCDs(self): requestCriteria = REQ_CRITERIA.INVENTORY requestCriteria |= ~REQ_CRITERIA.VEHICLE.DISABLED_IN_PREM_IGR requestCriteria |= ~REQ_CRITERIA.VEHICLE.EXPIRED_RENT requestCriteria |= ~REQ_CRITERIA.VEHICLE.EVENT_BATTLE if self.isCurrentPlayer(): vehicles = self.itemsCache.items.getVehicles(requestCriteria).keys() else: vehicles = self.vehDict.keys() return vehicles or [] def getVehiclesToSlot(self, slotIdx): if self.unit is not None: checkVehicle = self.unit.getRoster().checkVehicle def validator(vehCD): return checkVehicle(vehCD, slotIdx)[0] return filter(validator, self.getVehiclesCDs()) else: return [] def canAssignToSlot(self, slotIdx): if self.unit is not None and not self.isCommander() and slotIdx != CREATOR_SLOT_INDEX: slots = self.unit.getFreeSlots() if slotIdx in slots: vehicles = self.getVehiclesToSlot(slotIdx) return (bool(vehicles), vehicles) return (False, []) def getVehiclesToSlots(self, allSlots = False): if self.unit is not None: slots = self.unit.getFreeSlots() if allSlots: slots = set(list(slots) + self.unit.getPlayerSlots().values()) return self.unit.getRoster().matchVehicleListToSlotList(self.getVehiclesCDs(), slots) else: return {} def getAvailableSlots(self, allSlots = False): matches = self.getVehiclesToSlots(allSlots) return set(itertools.chain(*matches.values())) def getSlotsToVehicles(self, allSlots = False): matches = self.getVehiclesToSlots(allSlots) slots = set(itertools.chain(*matches.values())) result = {} for slot in slots: result[slot] = list(itertools.ifilter(lambda v, s = slot: s in matches[v], matches.iterkeys())) return result def getBadgeID(self): return self.badges.getBadgeID() def getBadgeImgStr(self, size = 24, vspace = -7): return self.badges.getBadgeImgStr(size, vspace)
class PlayerPrbInfo(object): __slots__ = ('accID', 'name', 'dbID', 'state', 'time', 'vehCompDescr', 'igrType', 'clanDBID', 'clanAbbrev', 'roster', 'isCreator', 'regionCode', 'badges', 'group', 'vehEnhancements') lobbyContext = dependency.descriptor(ILobbyContext) def __init__(self, accID, name='', dbID=0, state=PREBATTLE_ACCOUNT_STATE.UNKNOWN, time=0.0, vehCompDescr=0, igrType=0, clanDBID=0, clanAbbrev='', roster=0, entity=None, badges=None, group=0, vehEnhancements=None): self.accID = accID self.name = name self.dbID = dbID self.state = state self.time = time self.vehCompDescr = vehCompDescr self.igrType = igrType self.clanDBID = clanDBID self.clanAbbrev = clanAbbrev self.roster = roster self.badges = BadgesHelper(badges or ()) self.group = group self.vehEnhancements = vehEnhancements or {} if entity is not None: self.isCreator = entity.isCommander(pDatabaseID=self.dbID) else: self.isCreator = False return def __repr__(self): badge = self.badges.getBadge() return 'PlayerPrbInfo(accID = {0:n}, dbID = {1:n}, fullName = {2:>s}, state = {3:n}, isCreator = {4!r:s}, time = {5:n}, vehCompDescr = {6!r:s}, badgeID = {7}, vehEnhancements = {8})'.format( self.accID, self.dbID, self.getFullName(), self.state, self.isCreator, self.time, self.getVehicle().name if self.isVehicleSpecified() else None, badge.badgeID if badge else None, self.vehEnhancements) def getFullName(self, isClan=True, isRegion=True): if isClan: clanAbbrev = self.clanAbbrev else: clanAbbrev = None if isRegion: pDBID = self.dbID else: pDBID = None return self.lobbyContext.getPlayerFullName(self.name, clanAbbrev=clanAbbrev, pDBID=pDBID) def isVehicleSpecified(self): return self.isReady() or self.inBattle() def getVehicle(self): return Vehicle(self.vehCompDescr) def isCurrentPlayer(self): if self.dbID > 0: result = self.dbID == getAccountDatabaseID() else: result = self.accID == getPlayerID() return result def isReady(self): return self.state & PREBATTLE_ACCOUNT_STATE.READY != 0 def inBattle(self): return self.state & PREBATTLE_ACCOUNT_STATE.IN_BATTLE != 0 def isOffline(self): return self.state & PREBATTLE_ACCOUNT_STATE.OFFLINE != 0 def getBadge(self): return self.badges.getBadge() def getEnhancementVisibility(self): return self.vehEnhancements.get('badge', OVERRIDDEN_BADGE.NONE) def getEnhancementModules(self): return self.vehEnhancements.get('enhancements', [])