Beispiel #1
0
class UnitPermissions(IUnitPermissions):

    def __init__(self, roles = 0, state = UNIT_STATE.DEFAULT, isCurrentPlayer = False, isPlayerReady = False):
        super(UnitPermissions, self).__init__()
        self._roles = roles
        self._state = UnitState(state)
        self._isCurrentPlayer = isCurrentPlayer
        self._isPlayerReady = isPlayerReady

    def __repr__(self):
        return '{0:>s}(roles = {1:n}, state = {2!r:s}, isCurrentPlayer = {3!r:s})'.format(self.__class__.__name__, self._roles, self._state, self._isCurrentPlayer)

    def canSendInvite(self):
        return self._roles & UNIT_ROLE.INVITE_KICK_PLAYERS > 0

    def canKick(self):
        return self._roles & UNIT_ROLE.INVITE_KICK_PLAYERS > 0

    def canChangeUnitState(self):
        return self._roles & UNIT_ROLE.CHANGE_ROSTER > 0

    def canChangeRosters(self):
        return self._roles & UNIT_ROLE.CHANGE_ROSTER > 0

    def canSetVehicle(self):
        return self._isCurrentPlayer

    def canSetReady(self):
        return self._isCurrentPlayer

    def canChangeClosedSlots(self):
        return self._roles & UNIT_ROLE.CHANGE_ROSTER > 0

    def canAssignToSlot(self, dbID):
        return self._roles & UNIT_ROLE.ADD_REMOVE_MEMBERS > 0 or dbID == account_helpers.getPlayerDatabaseID()

    def canReassignToSlot(self):
        return self._roles & UNIT_ROLE.ADD_REMOVE_MEMBERS > 0

    def canChangeComment(self):
        return self._roles & UNIT_ROLE.CHANGE_ROSTER > 0 and not self._state.isInIdle()

    def canInvokeAutoSearch(self):
        return self._roles & UNIT_ROLE.START_STOP_BATTLE > 0

    def canStartBattleQueue(self):
        return self._roles & UNIT_ROLE.START_STOP_BATTLE > 0

    def canStopBattleQueue(self):
        return self._roles & UNIT_ROLE.START_STOP_BATTLE > 0

    def canChangeVehicle(self):
        return self._isCurrentPlayer and not self._isPlayerReady

    @classmethod
    def isCreator(cls, roles):
        return roles & UNIT_ROLE.COMMANDER_UPDATES > 0
Beispiel #2
0
 def __init__(self,
              cfdUnitID,
              unitMgrID=0,
              cmdrRating=0,
              peripheryID=0,
              unit=None,
              **kwargs):
     super(UnitsListItem, self).__init__()
     creatorFullName = ''
     vehiclesNames = tuple()
     playersCount = 0
     commandSize = 0
     state = 0
     isRosterSet = False
     if unit:
         creatorDBID, creator = next(
             itertools.ifilter(
                 lambda
                 (dbID, p): p['role'] & UNIT_ROLE.COMMANDER_UPDATES > 0,
                 unit._players.iteritems()), (None, None))
         if creator is not None:
             creatorFullName = g_lobbyContext.getPlayerFullName(
                 creator['nickName'],
                 clanAbbrev=creator.get('clanAbbrev'),
                 pDBID=creatorDBID)
         freeSlots = unit.getFreeSlots()
         playersSlots = unit.getPlayerSlots()
         state = unit.getState()
         vehicles = g_itemsCache.items.getVehicles(REQ_CRITERIA.INVENTORY)
         matches = unit.getRoster().matchVehicleListToSlotList(
             vehicles.keys(), freeSlots)
         vehiclesNames = tuple(
             itertools.imap(lambda x: vehicles[x].shortUserName,
                            set(matches.keys())))
         playersCount = len(playersSlots)
         commandSize = len(playersSlots) + len(freeSlots)
         isRosterSet = unit.isRosterSet(ignored=CREATOR_ROSTER_SLOT_INDEXES)
     self.cfdUnitID = cfdUnitID
     self.unitMgrID = unitMgrID
     self.creator = creatorFullName
     self.rating = cmdrRating
     self.peripheryID = peripheryID
     self.playersCount = playersCount
     self.commandSize = commandSize
     self.vehicles = vehiclesNames
     self.state = UnitState(state)
     self.isRosterSet = isRosterSet
     return
Beispiel #3
0
 def __init__(self, roles = 0, state = UNIT_STATE.DEFAULT, isCurrentPlayer = False, isPlayerReady = False):
     super(UnitPermissions, self).__init__()
     self._roles = roles
     self._state = UnitState(state)
     self._isCurrentPlayer = isCurrentPlayer
     self._isPlayerReady = isPlayerReady