from direct.directnotify import DirectNotifyGlobal
import DistributedBoardOfficeAI
from toontown.toonbase import ToontownGlobals
from toontown.coghq.boardbothq import BoardOfficeLayout
from direct.showbase import DirectObject
import random

class BoardOfficeManagerAI(DirectObject.DirectObject):
    notify = DirectNotifyGlobal.directNotify.newCategory('BoardOfficeManagerAI')
    boardofficeId = None

    def __init__(self, air):
        DirectObject.DirectObject.__init__(self)
        self.air = air

    def getDoId(self):
        return 0

    def createBoardOffice(self, boardofficeId, players):
        for avId in players:
            if bboard.has('boardofficeId-%s' % avId):
                boardofficeId = bboard.get('boardofficeId-%s' % avId)
                break

        numFloors = ToontownGlobals.BoardOfficeNumFloors[boardofficeId]
        floor = random.randrange(numFloors)
        for avId in players:
            if bboard.has('mintFloor-%s' % avId):
                floor = bboard.get('mintFloor-%s' % avId)
                floor = max(0, floor)
                floor = min(floor, numFloors - 1)
                break

        for avId in players:
            if bboard.has('mintRoom-%s' % avId):
                roomId = bboard.get('mintRoom-%s' % avId)
                for i in xrange(numFloors):
                    layout = BoardOfficeLayout.BoardOfficeLayout(boardofficeId, i)
                    if roomId in layout.getRoomIds():
                        floor = i
                else:
                    from toontown.coghq.boardbothq import BoardOfficeRoomSpecs
                    roomName = BoardOfficeRoomSpecs.BoardOfficeRoomId2RoomName[roomId]
                    BoardOfficeManagerAI.notify.warning('room %s (%s) not found in any floor of mint %s' % (roomId, roomName, boardofficeId))

        mintZone = self.air.allocateZone()
        mint = DistributedBoardOfficeAI.DistributedBoardOfficeAI(self.air, boardofficeId, mintZone, floor, players)
        mint.generateWithRequired(mintZone)
        return mintZone

[((9, 13, 9, 80), 'direct.directnotify.DirectNotifyGlobal.directNotify.newCategory', 'DirectNotifyGlobal.directNotify.newCategory', ({(9, 57, 9, 79): '"""BoardOfficeManagerAI"""'}, {}), "('BoardOfficeManagerAI')", False, 'from direct.directnotify import DirectNotifyGlobal\n'), ((13, 8, 13, 48), 'direct.showbase.DirectObject.DirectObject.__init__', 'DirectObject.DirectObject.__init__', ({(13, 43, 13, 47): 'self'}, {}), '(self)', False, 'from direct.showbase import DirectObject\n'), ((26, 16, 26, 43), 'random.randrange', 'random.randrange', ({(26, 33, 26, 42): 'numFloors'}, {}), '(numFloors)', False, 'import random\n'), ((47, 15, 47, 115), 'DistributedBoardOfficeAI.DistributedBoardOfficeAI', 'DistributedBoardOfficeAI.DistributedBoardOfficeAI', ({(47, 65, 47, 73): 'self.air', (47, 75, 47, 88): 'boardofficeId', (47, 90, 47, 98): 'mintZone', (47, 100, 47, 105): 'floor', (47, 107, 47, 114): 'players'}, {}), '(self.air, boardofficeId,\n    mintZone, floor, players)', False, 'import DistributedBoardOfficeAI\n'), ((38, 29, 38, 82), 'toontown.coghq.boardbothq.BoardOfficeLayout.BoardOfficeLayout', 'BoardOfficeLayout.BoardOfficeLayout', ({(38, 65, 38, 78): 'boardofficeId', (38, 80, 38, 81): 'i'}, {}), '(boardofficeId, i)', False, 'from toontown.coghq.boardbothq import BoardOfficeLayout\n')]