def enterNoShards(self): self.noShardDialog = GlobalDialog(message=CIGlobals.NoShardsMsg + " " + CIGlobals.TryAgain, style=2, doneEvent='noShardsDone') self.noShardDialog.show() self.acceptOnce('noShardsDone', self.handleNoShardsDone)
def enterDistrictReset(self): self.districtResetDialog = GlobalDialog( message=CIGlobals.DistrictResetMsg, style=3, doneEvent='distresetdone') self.districtResetDialog.show() self.acceptOnce('distresetdone', sys.exit)
def enterBetaInform(self): msg = "There may be some features that are present in the game, but are neither finished nor fully functional yet.\n\nAre you sure you want to enter?" self.dialog = GlobalDialog(message=msg, style=1, doneEvent="gameEnterChoice") self.dialog.show() self.acceptOnce("gameEnterChoice", self.handleGameEnterChoice)
def enterServerUnavailable(self): self.notify.info(CIGlobals.ServerUnavailable) self.serverNA = GlobalDialog(message=CIGlobals.ServerUnavailable, style=4, doneEvent="serverNAEvent") self.serverNA.show() self.acceptOnce("serverNAEvent", sys.exit) self.startServerNAPoll()
def __showUnzippingGui(self): self.unzippingDialog = GlobalDialog(message=self.MSG_UNZIPPING, style=0) self.unzippingDialog.show() self.soundUnzipping = base.loadSfx( 'phase_3.5/audio/sfx/ci_s_bpunzip.ogg') SoundInterval(self.soundUnzipping).start() base.taskMgr.doMethodLater(self.UNZIP_TIME, self.__unzipWaitDone, 'DDCBackpack-unzipWaitDone')
def enterAcknowledgeDeath(self, foo=0): base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() message = "You were defeated by the Cogs! Collect treasures in the Playground to refill your Laff meter." self.dialog = GlobalDialog(message=message, style=3, doneEvent='ackDeathDone') self.dialog.show() self.acceptOnce('ackDeathDone', self.handleAckDeathDone)
def handleConnectFail(self, foo1, foo2): self.notify.info("Could not connect to gameserver, notifying user.") self.connectingDialog.cleanup() self.connectingDialog = GlobalDialog( message=CIGlobals.NoConnectionMsg % self.serverAddress + " " + CIGlobals.TryAgain, style=2, doneEvent="connectFail") self.connectingDialog.show() self.acceptOnce("connectFail", self.handleConnectFailButton)
def __showPickUpGui(self): gagNameArray = [] gagString = "%s, %s, %s, %s" for gagId in self.getBP(): gagNameArray.append(GagGlobals.gagIds.get(gagId)) self.pickUpDialog = GlobalDialog( message = self.MSG_CONFIRM % (gagString % (gagNameArray[0], gagNameArray[1], gagNameArray[2], gagNameArray[3])), doneEvent = 'pickUpGui-Done', style = 1 ) self.pickUpDialog.show() self.acceptOnce('pickUpGui-Done', self.__handleBackpackChoice)
def displayGameOver(self, scenario, amt = None): if scenario == "winner": msg = self.winnerMsg % self.winnerPrize self.prizeHigh.play() elif scenario == "loser": msg = self.loserMsg % self.loserPrize self.prizeLow.play() elif scenario == 'showPrize': msg = random.choice(self.allWinnerMsgs) % amt self.prizeHigh.play() self.gameOverDialog = GlobalDialog(message = msg, style = 3, doneEvent = 'gameOverAck') self.acceptOnce('gameOverAck', self.__handleGameOverAck) self.gameOverDialog.show()
def enterAcknowledgeDeath(self, foo = 0): base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() message = 'You were defeated by the Cogs! Collect treasures in the Playground to refill your Laff meter.' self.dialog = GlobalDialog(message=message, style=3, doneEvent='ackDeathDone') self.dialog.show() self.acceptOnce('ackDeathDone', self.handleAckDeathDone)
def enterDisconnect(self, isPlaying, booted=0, bootReason=None): self.notify.info('Disconnect details: isPlaying = %s, booted = %s, bootReason = %s' % ( isPlaying, booted, bootReason)) style = 3 if isPlaying == 1: if not booted: msg = CIGlobals.DisconnectionMsg else: if not booted: msg = CIGlobals.JoinFailureMsg if self.isConnected(): self.sendDisconnect() self.disconnectDialog = GlobalDialog(message=msg, style=style, doneEvent='disconnectDone') self.disconnectDialog.show() if style == 3: self.acceptOnce('disconnectDone', sys.exit) else: self.acceptOnce('disconnectDone', self.handleDisconnectDone)
def __newFriendRequest(self, requester, name, dna): request = GlobalDialog(message=self.MessageFriendRequest % (name, name), style=1, text_wordwrap=12, doneEvent='friendRequestDone-%d' % requester, extraArgs=[requester]) self.friendRequests[requester] = request self.acceptOnce('friendRequestDone-%d' % requester, self.handleFriendRequestChoice)
def __showPickUpGui(self): gagNameArray = [] gagString = '%s, %s, %s, %s' for gagId in self.getBP(): gagNameArray.append(GagGlobals.gagIds.get(gagId)) self.pickUpDialog = GlobalDialog(message=self.MSG_CONFIRM % (gagString % (gagNameArray[0], gagNameArray[1], gagNameArray[2], gagNameArray[3])), doneEvent='pickUpGui-Done', style=1) self.pickUpDialog.show() self.acceptOnce('pickUpGui-Done', self.__handleBackpackChoice)
class Place(StateData): notify = directNotify.newCategory("Place") def __init__(self, loader, doneEvent): StateData.__init__(self, doneEvent) self.loader = loader self.zoneId = None self.track = None self.firstPerson = FirstPerson() self.lastBookPage = 'mapPage' self.useFirstPerson = config.GetBool('want-firstperson-battle') return def maybeUpdateAdminPage(self): if self.fsm: if self.fsm.getCurrentState(): if self.fsm.getCurrentState().getName() == 'shtickerBook': if hasattr(self, 'shtickerBookStateData'): if self.shtickerBookStateData.fsm.getCurrentState( ).getName() == 'adminPage': if base.cr.playGame.suitManager: text2Change2 = 'Turn Suit Spawner ' if base.cr.playGame.suitManager.getSpawner(): text2Change2 += 'Off' else: text2Change2 += 'On' self.shtickerBookStateData.adminPageStateData.suitSpawnerBtn[ 'text'] = text2Change2 def enterStart(self): pass def exitStart(self): pass def enterFinal(self): pass def exitFinal(self): pass def enter(self): StateData.enter(self) base.localAvatar.createChatInput() def exit(self): base.localAvatar.disableChatInput() del self.lastBookPage StateData.exit(self) def enterDoorIn(self, distDoor): base.localAvatar.attachCamera() requestStatus = {} requestStatus['zoneId'] = distDoor.getToZone() requestStatus['hoodId'] = base.cr.playGame.hood.id requestStatus['how'] = 'doorOut' requestStatus['shardId'] = None requestStatus['doorIndex'] = distDoor.getDoorIndex() foundBlock = False for interior in base.cr.doFindAll("DistributedToonInterior"): if interior.zoneId == base.localAvatar.zoneId: foundBlock = True requestStatus['block'] = interior.getBlock() break if not foundBlock: requestStatus['block'] = distDoor.getBlock() requestStatus['where'] = ZoneUtil.getWhereName(requestStatus['zoneId']) requestStatus['loader'] = base.cr.playGame.hood.fsm.getCurrentState( ).getName() requestStatus['avId'] = base.localAvatar.doId self.acceptOnce('DistributedDoor_localAvatarWentInDoor', self.handleDoorInDone, [requestStatus]) self.acceptOnce('DistributedDoor_localAvatarGoingInDoor', base.transitions.irisOut) def exitDoorIn(self): base.localAvatar.detachCamera() self.ignore('DistributedDoor_localAvatarWentInDoor') self.ignore('DistributedDoor_localAvatarGoingInDoor') def handleDoorInDone(self, requestStatus): self.doneStatus = requestStatus messenger.send(self.doneEvent) def __waitOnDoor(self, door, task): if door.ready: self.__doorReady(door) return task.done return task.cont def enterDoorOut(self, requestStatus): base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.d_clearSmoothing() base.localAvatar.stopPosHprBroadcast() base.localAvatar.walkControls.setCollisionsActive(0) block = requestStatus['block'] zoneId = requestStatus['zoneId'] doorIndex = requestStatus['doorIndex'] doorToExitFrom = None for door in base.cr.doFindAll("DistributedDoor"): if door.zoneId == zoneId: if door.getBlock() == block: if door.getDoorIndex() == doorIndex: doorToExitFrom = door break if not doorToExitFrom: self.notify.error('Could not find a DistributedDoor to exit from!') elif not doorToExitFrom.ready: base.taskMgr.add(self.__waitOnDoor, "Place.waitOnDoor", extraArgs=[doorToExitFrom], appendTask=True) return self.__doorReady(doorToExitFrom) def __doorReady(self, door): door.sendUpdate('requestExit', []) self.nextState = 'walk' self.acceptOnce('DistributedDoor_localAvatarCameOutOfDoor', self.handleDoorOutDone) def exitDoorOut(self): base.taskMgr.remove("Place.waitOnDoor") base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() self.ignore('DistributedDoor_localAvatarCameOutOfDoor') def handleDoorOutDone(self): base.transitions.irisIn() base.localAvatar.walkControls.setCollisionsActive(1) self.fsm.request(self.nextState) def enterShtickerBook(self): base.localAvatar.attachCamera() base.localAvatar.createLaffMeter() base.localAvatar.startSmartCamera() base.localAvatar.startPosHprBroadcast() base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setAnimState('openBook', self.enterShtickerBookGui) def enterShtickerBookGui(self): doneEvent = 'shtickerBookDone' self.shtickerBookStateData = ShtickerBook(self.fsm, doneEvent) self.acceptOnce(doneEvent, self.__shtickerBookDone) self.shtickerBookStateData.load() self.shtickerBookStateData.enter(self.lastBookPage) base.localAvatar.showBookButton(1) base.localAvatar.b_setAnimState('readBook') self.acceptOnce('escape-up', base.localAvatar.bookButtonClicked, [0]) def __shtickerBookDone(self): self.ignore('escape-up') doneStatus = self.shtickerBookStateData.getDoneStatus() base.localAvatar.hideBookButton() self.shtickerBookStateData.exit() if doneStatus['mode'] == 'exit': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseExit) elif doneStatus['mode'] == 'teleport': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseTeleport, [doneStatus]) elif doneStatus['mode'] == 'resume': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseResume) elif doneStatus['mode'] == 'switchShard': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseSwitchShard, [doneStatus]) def __handleBookCloseSwitchShard(self, requestStatus): base.localAvatar.b_setAnimState('teleportOut', self.__handleBookSwitchShard, [requestStatus]) def __handleBookSwitchShard(self, requestStatus): params = [] params.append(requestStatus['shardId']) params.append(base.cr.playGame.hood.id) params.append(ZoneUtil.getZoneId(base.cr.playGame.hood.id)) params.append(base.localAvatar.doId) base.cr.gameFSM.request('switchShards', params) def __handleBookCloseResume(self): self.fsm.request('walk') def __handleBookCloseTeleport(self, requestStatus): self.fsm.request('teleportOut', [requestStatus]) def __teleportOutDone(self, requestStatus): if base.localAvatar.getMyBattle() is not None: base.localAvatar.getMyBattle().d_left() self.doneStatus = requestStatus messenger.send(self.doneEvent) def __handleBookCloseExit(self): base.localAvatar.b_setAnimState('teleportOut', self.__handleBookExitTeleport) def __handleBookExitTeleport(self): base.transitions.fadeOut(0.0) base.cr.gameFSM.request('closeShard') def exitShtickerBook(self): base.localAvatar.detachCamera() base.localAvatar.stopSmartCamera() base.localAvatar.stopPosHprBroadcast() base.localAvatar.disableLaffMeter() self.ignore(self.shtickerBookStateData.doneEvent) self.shtickerBookStateData.exit() self.shtickerBookStateData.unload() del self.shtickerBookStateData base.localAvatar.hideBookButton() self.ignore('escape-up') def enterStop(self, doNeutral=1): if doNeutral: base.localAvatar.b_setAnimState('neutral') base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.createLaffMeter() base.localAvatar.createMoney() #base.localAvatar.showBookButton() base.localAvatar.enableGags(0) def exitStop(self): base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() base.localAvatar.disableLaffMeter() base.localAvatar.disableMoney() base.localAvatar.disableGags() #base.localAvatar.hideBookButton() def load(self): StateData.load(self) self.walkDoneEvent = "walkDone" self.walkStateData = PublicWalk(self.fsm, self.walkDoneEvent) self.walkStateData.load() def unload(self): StateData.unload(self) del self.walkDoneEvent self.walkStateData.unload() del self.walkStateData del self.loader def enterTeleportIn(self, requestStatus): base.transitions.irisIn() self.nextState = requestStatus.get('nextState', 'walk') if requestStatus['avId'] != base.localAvatar.doId: av = base.cr.doId2do.get(requestStatus['avId']) if av: base.localAvatar.gotoNode(av) base.localAvatar.b_setChat("Hi, %s." % av.getName()) base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.startPosHprBroadcast() globalClock.tick() base.localAvatar.b_setAnimState('teleportIn', callback=self.teleportInDone) base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setParent(CIGlobals.SPRender) return def exitTeleportIn(self): base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() base.localAvatar.stopPosHprBroadcast() return def teleportInDone(self): if hasattr(self, 'fsm'): self.fsm.request(self.nextState, [1]) def enterAcknowledgeDeath(self, foo=0): base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() message = "You were defeated by the Cogs! Collect treasures in the Playground to refill your Laff meter." self.dialog = GlobalDialog(message=message, style=3, doneEvent='ackDeathDone') self.dialog.show() self.acceptOnce('ackDeathDone', self.handleAckDeathDone) def handleAckDeathDone(self): self.fsm.request('walk', [1]) def exitAcknowledgeDeath(self): self.ignore('ackDeathDone') self.dialog.cleanup() del self.dialog base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() def enterDied(self, requestStatus, callback=None): if callback == None: callback = self.__diedDone base.localAvatar.createLaffMeter() base.localAvatar.attachCamera() base.localAvatar.b_setAnimState('died', callback, [requestStatus]) def __diedDone(self, requestStatus): self.doneStatus = requestStatus messenger.send(self.doneEvent) def exitDied(self): base.localAvatar.disableLaffMeter() base.localAvatar.detachCamera() def enterWalk(self, teleportIn=0): self.walkStateData.enter() if teleportIn == 0: self.walkStateData.fsm.request('walking') self.acceptOnce(self.walkDoneEvent, self.handleWalkDone) self.walkStateData.fsm.request('walking') self.watchTunnelSeq = Sequence(Wait(1.0), Func(LinkTunnel.globalAcceptCollisions)) self.watchTunnelSeq.start() base.localAvatar.setBusy(0) base.localAvatar.enablePicking() base.localAvatar.showFriendButton() NametagGlobals.setWantActiveNametags(True) NametagGlobals.makeTagsReady() if self.useFirstPerson: if base.localAvatar.getMyBattle(): base.localAvatar.stopSmartCamera() camera.setPos(base.localAvatar.smartCamera.firstPersonCamPos) self.firstPerson.start() self.firstPerson.reallyStart() self.firstPerson.disableMouse() base.localAvatar.getGeomNode().show() base.localAvatar.getShadow().hide() base.localAvatar.find('**/torso-top').hide() base.localAvatar.find('**/torso-bot').hide() base.localAvatar.getPart('head').hide() base.localAvatar.chatInput.disableKeyboardShortcuts() def exitWalk(self): self.walkStateData.exit() self.ignore(self.walkDoneEvent) if base.cr.playGame.hood.titleText != None: base.cr.playGame.hood.hideTitleText() self.watchTunnelSeq.pause() del self.watchTunnelSeq NametagGlobals.setWantActiveNametags(False) NametagGlobals.makeTagsInactive() base.localAvatar.setBusy(1) base.localAvatar.disablePicking() base.localAvatar.hideFriendButton() if base.localAvatar.friendsList: base.localAvatar.friendsList.fsm.requestFinalState() if base.localAvatar.panel: base.localAvatar.panel.fsm.requestFinalState() if self.useFirstPerson: if base.localAvatar.getMyBattle(): self.firstPerson.enableMouse() self.firstPerson.end() self.firstPerson.reallyEnd() base.localAvatar.getShadow().show() base.localAvatar.find('**/torso-top').show() base.localAvatar.find('**/torso-bot').show() base.localAvatar.getPart('head').show() return def handleWalkDone(self, doneStatus): pass def enterTeleportOut(self, requestStatus, callback=None): if not callback: callback = self.__teleportOutDone base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.startPosHprBroadcast() base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setAnimState('teleportOut', callback, [requestStatus]) def exitTeleportOut(self): base.localAvatar.disableLaffMeter() base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() base.localAvatar.stopPosHprBroadcast() def enterTunnelIn(self, linkTunnel): zoneId = linkTunnel.data['zoneId'] base.localAvatar.sendUpdate('goThroughTunnel', [zoneId, 0]) base.localAvatar.attachCamera() base.localAvatar.playMovementSfx("run") requestStatus = {} requestStatus['zoneId'] = linkTunnel.data['zoneId'] # Goes from safe zone to street. if linkTunnel.__class__.__name__ == "SafeZoneLinkTunnel": requestStatus['where'] = 'street' requestStatus['loader'] = 'townLoader' requestStatus['hoodId'] = base.cr.playGame.hood.id requestStatus['shardId'] = None requestStatus['avId'] = base.localAvatar.doId requestStatus['how'] = 'tunnelOut' requestStatus['fromZone'] = base.localAvatar.zoneId # Goes from street to safe zone. elif linkTunnel.__class__.__name__ == "StreetLinkTunnel": requestStatus['where'] = 'playground' requestStatus['loader'] = 'safeZoneLoader' requestStatus['hoodId'] = base.cr.playGame.hood.id requestStatus['shardId'] = None requestStatus['avId'] = base.localAvatar.doId requestStatus['how'] = 'tunnelOut' requestStatus['fromZone'] = base.localAvatar.zoneId # Goes from street to street. elif linkTunnel.__class__.__name__ == "NeighborhoodLinkTunnel": requestStatus['where'] = 'street' requestStatus['loader'] = 'townLoader' hoodId = ZoneUtil.getHoodId(linkTunnel.data['zoneId'], 1) requestStatus['hoodId'] = hoodId requestStatus['shardId'] = None requestStatus['avId'] = base.localAvatar.doId requestStatus['how'] = 'tunnelOut' requestStatus['fromZone'] = base.localAvatar.zoneId base.localAvatar.goThroughTunnel(zoneId, 0, requestStatus) def exitTunnelIn(self): base.localAvatar.playMovementSfx(None) base.localAvatar.reparentTo(render) base.localAvatar.detachCamera() base.localAvatar.walkControls.setCollisionsActive(1) def enterTunnelOut(self, requestStatus): zone = requestStatus['fromZone'] base.localAvatar.sendUpdate('goThroughTunnel', [zone, 1]) base.localAvatar.playMovementSfx("run") base.transitions.irisIn() self.nextState = requestStatus.get('nextState', 'walk') base.localAvatar.goThroughTunnel(zone, 1) def exitTunnelOut(self): base.localAvatar.playMovementSfx(None) base.localAvatar.walkControls.setCollisionsActive(1) base.localAvatar.detachCamera() del self.nextState
def enterEjected(self, errorMsg): self.ejectDialog = GlobalDialog(message=errorMsg, style=3, doneEvent='ejectDone') self.ejectDialog.show() self.acceptOnce('ejectDone', sys.exit)
def enterSubmitNewToon(self, dnaStrand, slot, name, skipTutorial=0): self.submittingDialog = GlobalDialog(message=CIGlobals.Submitting) self.submittingDialog.show() self.acceptOnce(self.csm.getToonCreatedEvent(), self.__handleSubmitNewToonResp) self.csm.sendSubmitNewToon(dnaStrand, slot, name, skipTutorial)
def enterConnect(self): self.connectingDialog = GlobalDialog(message=CIGlobals.ConnectingMsg) self.connectingDialog.show() self.connect([self.serverURL], successCallback=self.handleConnected, failureCallback=self.handleConnectFail)
class CogInvasionClientRepository(AstronClientRepository): notify = directNotify.newCategory('CIClientRepository') GameGlobalsId = DO_ID_COGINVASION SetZoneDoneEvent = 'CICRSetZoneDone' EmuSetZoneDoneEvent = 'CICREmuSetZoneDone' SetInterest = 'Set' ClearInterest = 'Clear' ClearInterestDoneEvent = 'CICRClearInterestDone' ITAG_PERM = 'perm' ITAG_AVATAR = 'avatar' ITAG_SHARD = 'shard' ITAG_WORLD = 'world' ITAG_GAME = 'game' def __init__(self, music, serverVersion): self.music = music self.serverVersion = serverVersion AstronClientRepository.__init__(self, ['phase_3/etc/direct.dc', 'phase_3/etc/toon.dc']) self.loginFSM = ClassicFSM('login', [State('off', self.enterOff, self.exitOff), State('connect', self.enterConnect, self.exitConnect), State('disconnect', self.enterDisconnect, self.exitDisconnect), State('avChoose', self.enterAvChoose, self.exitAvChoose), State('playingGame', self.enterPlayingGame, self.exitPlayingGame), State('serverUnavailable', self.enterServerUnavailable, self.exitServerUnavailable), State('makeAToon', self.enterMakeAToon, self.exitMakeAToon), State('submitNewToon', self.enterSubmitNewToon, self.exitSubmitNewToon), State('noShards', self.enterNoShards, self.exitNoShards), State('waitForSetAvatarResponse', self.enterWaitForSetAvatarResponse, self.exitWaitForSetAvatarResponse), State('waitForShardList', self.enterWaitForShardList, self.exitWaitForShardList), State('ejected', self.enterEjected, self.exitEjected), State('districtReset', self.enterDistrictReset, self.exitDistrictReset), State('died', self.enterDied, self.exitDied), State('betaInform', self.enterBetaInform, self.exitBetaInform)], 'off', 'off') self.loginFSM.enterInitialState() self.gameFSM = ClassicFSM('game', [State('off', self.enterGameOff, self.exitGameOff), State('waitForGameEnterResponse', self.enterWaitForGameEnterResponse, self.exitWaitForGameEnterResponse), State('playGame', self.enterPlayGame, self.exitPlayGame), State('closeShard', self.enterCloseShard, self.exitCloseShard), State('switchShards', self.enterSwitchShards, self.exitSwitchShards)], 'off', 'off') self.gameFSM.enterInitialState() self.avChooser = AvChooser(self.loginFSM) self.playGame = PlayGame(self.gameFSM, 'playGameDone') self.hoodMgr = HoodMgr() self.makeAToon = MakeAToon() self.loginToken = os.environ.get('LOGIN_TOKEN') self.serverAddress = os.environ.get('GAME_SERVER') self.serverURL = URLSpec('http://%s' % self.serverAddress) self.parentMgr.registerParent(CIGlobals.SPRender, render) self.parentMgr.registerParent(CIGlobals.SPHidden, hidden) self.adminAccess = False self.localAvChoice = None self.SuitsActive = 0 self.BossActive = 0 self.accServerTimesNA = 0 self.maxAccServerTimesNA = 10 self.setZonesEmulated = 0 self.old_setzone_interest_handle = None self.setZoneQueue = Queue() self.accept(self.SetZoneDoneEvent, self._handleEmuSetZoneDone) self.handler = None self.__currentAvId = 0 self.myDistrict = None self.activeDistricts = {} self.shardListHandle = None self.uberZoneInterest = None self.isShowingPlayerIds = False self.doBetaInform = True self.dTutorial = None self.requestedName = None self.whisperNoise = base.loadSfx('phase_3.5/audio/sfx/GUI_whisper_3.ogg') self.checkHttp() base.audio3d = Audio3DManager(base.sfxManagerList[0], camera) base.audio3d.setDropOffFactor(0) base.audio3d.setDopplerFactor(3.0) base.lifter = CollisionHandlerFloor() base.pusher = CollisionHandlerPusher() base.queue = CollisionHandlerQueue() base.minigame = None base.finalExitCallbacks.insert(0, self.__handleExit) self.csm = self.generateGlobalObject(DO_ID_CLIENT_SERVICES_MANAGER, 'ClientServicesManager') self.friendsManager = self.generateGlobalObject(DO_ID_FRIENDS_MANAGER, 'FriendsManager') SpeedHackChecker.startChecking() self.loginFSM.request('connect') return def __handleExit(self): try: base.localAvatar.b_setAnimState('teleportOut') except: pass self.gameFSM.request('closeShard', ['off']) def showPlayerIds(self): print 'Showing player ids...' self.isShowingPlayerIds = True for av in self.doId2do.values(): if av.__class__.__name__ in ('DistributedToon', 'LocalToon', 'DistributedSuit'): av.showAvId() def hidePlayerIds(self): print 'Hiding player ids...' self.isShowingPlayerIds = False for av in self.doId2do.values(): if av.__class__.__name__ in ('DistributedToon', 'LocalToon', 'DistributedSuit'): av.showName() def sendSetLocation(self, doId, parentId, zoneId): dg = PyDatagram() dg.addUint16(CLIENT_OBJECT_LOCATION) dg.addUint32(doId) dg.addUint32(parentId) dg.addUint32(zoneId) self.send(dg) def getNextSetZoneDoneEvent(self): return '%s-%s' % (self.EmuSetZoneDoneEvent, self.setZonesEmulated + 1) def getLastSetZoneDoneEvent(self): return '%s-%s' % (self.EmuSetZoneDoneEvent, self.setZonesEmulated) def getQuietZoneLeftEvent(self): return 'leftQuietZone-%s' % (id(self),) def sendSetZoneMsg(self, zoneId, visibleZoneList=None): event = self.getNextSetZoneDoneEvent() self.setZonesEmulated += 1 parentId = base.localAvatar.defaultShard self.sendSetLocation(base.localAvatar.doId, parentId, zoneId) localAvatar.setLocation(parentId, zoneId) interestZones = zoneId if visibleZoneList is not None: interestZones = visibleZoneList self._addInterestOpToQueue(self.SetInterest, [parentId, interestZones, 'OldSetZoneEmulator'], event) return def resetInterestStateForConnectionLoss(self): self.old_setzone_interest_handle = None self.setZoneQueue.clear() return def _removeEmulatedSetZone(self, doneEvent): self._addInterestOpToQueue(self.ClearInterest, None, doneEvent) return def _addInterestOpToQueue(self, op, args, event): self.setZoneQueue.push([op, args, event]) if len(self.setZoneQueue) == 1: self._sendNextSetZone() def _sendNextSetZone(self): op, args, event = self.setZoneQueue.top() if op == self.SetInterest: parentId, interestZones, name = args if self.old_setzone_interest_handle == None: self.old_setzone_interest_handle = self.addInterest(parentId, interestZones, name, self.SetZoneDoneEvent) else: self.alterInterest(self.old_setzone_interest_handle, parentId, interestZones, name, self.SetZoneDoneEvent) else: if op == self.ClearInterest: self.removeInterest(self.old_setzone_interest_handle, self.SetZoneDoneEvent) self.old_setzone_interest_handle = None else: self.notify.error('unknown setZone op: %s' % op) return def _handleEmuSetZoneDone(self): op, args, event = self.setZoneQueue.pop() queueIsEmpty = self.setZoneQueue.isEmpty() if event is not None: messenger.send(event) if not queueIsEmpty: self._sendNextSetZone() return def enterSwitchShards(self, shardId, hoodId, zoneId, avId): self._switchShardParams = [ shardId, hoodId, zoneId, avId] self.removeShardInterest(self._handleOldShardGone) def _handleOldShardGone(self): status = {} status['hoodId'] = self._switchShardParams[1] status['zoneId'] = self._switchShardParams[2] status['avId'] = self._switchShardParams[3] print status['avId'] self.gameFSM.request('waitForGameEnterResponse', [status, self._switchShardParams[0]]) def exitSwitchShards(self): del self._switchShardParams def enterBetaInform(self): msg = 'There may be some features that are present in the game, but are neither finished nor fully functional yet.\n\nAre you sure you want to enter?' self.dialog = GlobalDialog(message=msg, style=1, doneEvent='gameEnterChoice') self.dialog.show() self.acceptOnce('gameEnterChoice', self.handleGameEnterChoice) def handleGameEnterChoice(self): value = self.dialog.getValue() if value: self.loginFSM.request('avChoose') else: sys.exit() def exitBetaInform(self): self.ignore('gameEnterChoice') self.dialog.cleanup() del self.dialog def enterCloseShard(self, nextState='avChoose'): self.setNoNewInterests(True) self._removeLocalAvFromStateServer(nextState) def exitCloseShard(self): self.setNoNewInterests(False) self.ignore(self.ClearInterestDoneEvent) def _removeLocalAvFromStateServer(self, nextState): self.sendSetAvatarIdMsg(0) self._removeAllOV() callback = Functor(self.loginFSM.request, nextState) self.removeShardInterest(callback) def removeShardInterest(self, callback): self._removeCurrentShardInterest(Functor(self._removeShardInterestComplete, callback)) def _removeShardInterestComplete(self, callback): self.cache.flush() self.doDataCache.flush() callback() def _removeCurrentShardInterest(self, callback): if self.old_setzone_interest_handle is None: callback() return self.acceptOnce(self.ClearInterestDoneEvent, Functor(self._removeCurrentUberZoneInterest, callback)) self._removeEmulatedSetZone(self.ClearInterestDoneEvent) return def _removeCurrentUberZoneInterest(self, callback): self.acceptOnce(self.ClearInterestDoneEvent, Functor(self._removeShardInterestDone, callback)) self.removeInterest(self.uberZoneInterest, self.ClearInterestDoneEvent) def _removeShardInterestDone(self, callback): self.uberZoneInterest = None callback() return def _removeAllOV(self): owners = self.doId2ownerView.keys() for doId in owners: self.disableDoId(doId, ownerView=True) def enterDied(self): self.deathDialog = GlobalDialog(message=CIGlobals.SuitDefeatMsg, style=2, doneEvent='deathChoice') self.deathDialog.show() self.acceptOnce('deathChoice', self.handleDeathChoice) def handleDeathChoice(self): value = self.deathDialog.getValue() if value: self.loginFSM.request('avChoose') else: sys.exit() def exitDied(self): self.deathDialog.cleanup() del self.deathDialog self.ignore('deathChoice') def enterConnect(self): self.connectingDialog = GlobalDialog(message=CIGlobals.ConnectingMsg) self.connectingDialog.show() self.connect([self.serverURL], successCallback=self.handleConnected, failureCallback=self.handleConnectFail) def handleConnected(self): self.notify.info('Sending CLIENT_HELLO...') self.acceptOnce('CLIENT_HELLO_RESP', self.handleClientHelloResp) self.acceptOnce('CLIENT_EJECT', self.handleEjected) self.acceptOnce('LOST_CONNECTION', self.handleLostConnection) AstronClientRepository.sendHello(self, self.serverVersion) def handleLostConnection(self): self.deleteAllObjects() self.loginFSM.request('disconnect', [1]) def deleteAllObjects(self): for doId in self.doId2do.keys(): obj = self.doId2do[doId] if hasattr(base, 'localAvatar'): if doId != base.localAvatar.doId: if obj.__class__.__name__ not in ('ClientServicesManager', 'DistributedDistrict', 'FriendsManager', 'HolidayManager', 'NameServicesManager'): self.deleteObject(doId) else: self.deleteObject(doId) def handleEjected(self, errorCode, reason): self.notify.info('OMG I WAS EJECTED!') self.ignore('LOST_CONNECTION') errorMsg = ErrorCode2ErrorMsg.get(errorCode, None) or UnknownErrorMsg % errorCode self.loginFSM.request('ejected', [errorMsg]) return def handleClientHelloResp(self): self.notify.info('Got CLIENT_HELLO_RESP!') self.acceptOnce(self.csm.getLoginAcceptedEvent(), self.handleLoginAccepted) self.csm.d_requestLogin(self.loginToken) def handleLoginAccepted(self): self.notify.info('Woo-hoo, I am authenticated!') base.cr.holidayManager = self.generateGlobalObject(DO_ID_HOLIDAY_MANAGER, 'HolidayManager') base.cr.nameServicesManager = self.generateGlobalObject(DO_ID_NAME_SERVICES_MANAGER, 'NameServicesManager') self.loginFSM.request('waitForShardList') def handleConnectFail(self, foo1, foo2): self.notify.info('Could not connect to gameserver, notifying user.') self.connectingDialog.cleanup() self.connectingDialog = GlobalDialog(message=CIGlobals.NoConnectionMsg % self.serverAddress + ' ' + CIGlobals.TryAgain, style=2, doneEvent='connectFail') self.connectingDialog.show() self.acceptOnce('connectFail', self.handleConnectFailButton) def handleConnectFailButton(self): value = self.connectingDialog.getValue() if value: self.loginFSM.request('connect') else: sys.exit() def exitConnect(self): self.ignore('connectFail') self.ignore('CLIENT_HELLO_RESP') self.ignore(self.csm.getLoginAcceptedEvent()) self.connectingDialog.cleanup() del self.connectingDialog def enterEjected(self, errorMsg): self.ejectDialog = GlobalDialog(message=errorMsg, style=3, doneEvent='ejectDone') self.ejectDialog.show() self.acceptOnce('ejectDone', sys.exit) def exitEjected(self): self.ignore('ejectDone') self.ejectDialog.cleanup() del self.ejectDialog def enterServerUnavailable(self): self.notify.info(CIGlobals.ServerUnavailable) self.serverNA = GlobalDialog(message=CIGlobals.ServerUnavailable, style=4, doneEvent='serverNAEvent') self.serverNA.show() self.acceptOnce('serverNAEvent', sys.exit) self.startServerNAPoll() def startServerNAPoll(self): self.notify.info('Starting server poll...') self.accServerTimesNA = 1 taskMgr.add(self.serverNAPoll, 'serverNAPoll') def serverNAPoll(self, task): dg = PyDatagram() dg.addUint16(ACC_IS_SERVER_UP) self.send(dg) task.delayTime = 3.0 return Task.again def __handleServerNAResp(self, resp): if resp == ACC_SERVER_UP: taskMgr.remove('serverNAPoll') self.loginFSM.request(self.loginFSM.getLastState().getName()) else: self.accServerTimesNA += 1 if self.accServerTimesNA >= self.maxAccServerTimesNA: taskMgr.remove('serverNAPoll') self.notify.info('Giving up on polling account server after %s times.' % self.accServerTimesNA) self.loginFSM.request('disconnect', enterArgList=[1]) self.accServerTimesNA = 0 def exitServerUnavailable(self): self.ignore('serverNAEvent') self.serverNA.cleanup() del self.serverNA def enterOff(self): pass def exitOff(self): pass def enterAvChoose(self): ModelPool.garbageCollect() TexturePool.garbageCollect() self.avChooser.load() self.avChooser.enter() if not self.music: self.music = base.loadMusic(CIGlobals.getThemeSong()) base.playMusic(self.music, volume=0.75, looping=1) self.accept('enterMakeAToon', self.__handleMakeAToonReq) self.accept('avChooseDone', self.__handleAvChooseDone) def __handleMakeAToonReq(self, slot): self.loginFSM.request('makeAToon', [slot]) def __handleAvChooseDone(self, avChoice): print '------- AvChooseDone -------' print 'Toon name: %s' % avChoice.getName() print 'Slot: %s' % avChoice.getSlot() print 'DNA: %s' % avChoice.getDNA() self.loginFSM.request('waitForSetAvatarResponse', [avChoice]) def exitAvChoose(self): self.avChooser.exit() self.avChooser.unload() self.ignore('enterMakeAToon') self.ignore('avChooseDone') def handlePlayGame(self, msgType, di): if msgType == CLIENT_ENTER_OBJECT_REQUIRED_OTHER_OWNER: self.handleGenerateWithRequiredOtherOwner(msgType, di) else: AstronClientRepository.handleDatagram(self, di) def enterPlayingGame(self): zoneId = localAvatar.getLastHood() hoodId = ZoneUtil.getHoodId(zoneId) status = {'hoodId': hoodId, 'zoneId': zoneId, 'avId': self.localAvId} shardId = self.myDistrict.doId self.gameFSM.request('waitForGameEnterResponse', [status, shardId]) def exitPlayingGame(self): self.deleteAllObjects() self.handler = None self.gameFSM.request('off') if hasattr(base, 'localAvatar'): camera.reparentTo(render) camera.setPos(0, 0, 0) camera.setHpr(0, 0, 0) del base.localAvatar del __builtins__['localAvatar'] self.localAvChoice = None if loader.inBulkBlock: loader.endBulkLoad(loader.blockName) return def enterNoShards(self): self.noShardDialog = GlobalDialog(message=CIGlobals.NoShardsMsg + ' ' + CIGlobals.TryAgain, style=2, doneEvent='noShardsDone') self.noShardDialog.show() self.acceptOnce('noShardsDone', self.handleNoShardsDone) def handleNoShardsDone(self): value = self.noShardDialog.getValue() if value: self.loginFSM.request('waitForShardList') else: sys.exit() def exitNoShards(self): self.noShardDialog.cleanup() del self.noShardDialog self.ignore('noShardsDone') def enterWaitForShardList(self): self.shardListHandle = self.addTaggedInterest(self.GameGlobalsId, CIGlobals.DistrictZone, self.ITAG_PERM, 'localShardList', event='shardList_complete') self.acceptOnce('shardList_complete', self._handleShardListComplete) def _handleShardListComplete(self): if self._shardsAreAvailable(): self.myDistrict = self._chooseAShard() if self.doBetaInform: self.loginFSM.request('betaInform') else: self.loginFSM.request('avChoose') taskMgr.add(self.monitorDistrict, 'monitorMyDistrict') else: self.loginFSM.request('noShards') def monitorDistrict(self, task): if self.myDistrict is None and self.isConnected(): self.loginFSM.request('districtReset') return task.done return task.cont def _shardsAreAvailable(self): for shard in self.activeDistricts.values(): if shard.available: return True return False def _chooseAShard(self): choices = [] for shard in self.activeDistricts.values(): choices.append(shard) return random.choice(choices) def exitWaitForShardList(self): self.ignore('shardList_complete') def enterDistrictReset(self): self.districtResetDialog = GlobalDialog(message=CIGlobals.DistrictResetMsg, style=3, doneEvent='distresetdone') self.districtResetDialog.show() self.acceptOnce('distresetdone', sys.exit) def exitDistrictReset(self): self.districtResetDialog.cleanup() del self.districtResetDialog def enterWaitForSetAvatarResponse(self, choice): self.sendSetAvatarMsg(choice) def enterLoadDone(self): self.loginFSM.request('playingGame') def __handleSetAvatarResponse(self, avId, di): print 'Entering game...' enterLoad = EnterLoad(self.enterLoadDone) dclass = self.dclassesByName['DistributedToon'] localAvatar = LocalToon.LocalToon(base.cr) localAvatar.dclass = dclass base.localAvatar = localAvatar __builtins__['localAvatar'] = base.localAvatar localAvatar.doId = avId self.localAvId = avId parentId = None zoneId = None localAvatar.setLocation(parentId, zoneId) localAvatar.generateInit() localAvatar.generate() dclass.receiveUpdateBroadcastRequiredOwner(localAvatar, di) localAvatar.announceGenerate() localAvatar.postGenerateMessage() self.doId2do[avId] = localAvatar localAvatar.hoodsDiscovered = [ 1000, 2000, 3000, 4000, 5000, 9000] localAvatar.teleportAccess = [1000, 2000, 3000, 4000, 5000, 9000] enterLoad.load() del enterLoad return def exitWaitForSetAvatarResponse(self): self.ignore(self.csm.getSetAvatarEvent()) def enterWaitForGameEnterResponse(self, status, shardId): if shardId is not None: district = self.activeDistricts[shardId] else: district = None if not district: self.loginFSM.request('noShards') return self.myDistrict = district self.notify.info('Entering shard %s' % shardId) localAvatar.setLocation(shardId, status['zoneId']) localAvatar.defaultShard = shardId self.handleEnteredShard(status) return def handleEnteredShard(self, status): self.uberZoneInterest = self.addInterest(localAvatar.defaultShard, CIGlobals.UberZone, 'uberZone', 'uberZoneInterestComplete') self.acceptOnce('uberZoneInterestComplete', self.uberZoneInterestComplete, [status]) def uberZoneInterestComplete(self, status): self.__gotTimeSync = 0 if self.timeManager == None: print 'No time manager' DistributedSmoothNode.globalActivateSmoothing(0, 0) self.gotTimeSync(status) else: print 'Time manager found' DistributedSmoothNode.globalActivateSmoothing(1, 0) if self.timeManager.synchronize('startup'): self.accept('gotTimeSync', self.gotTimeSync, [status]) else: self.gotTimeSync(status) return def exitWaitForGameEnterResponse(self): self.ignore('uberZoneInterestComplete') def gotTimeSync(self, status): self.notify.info('gotTimeSync') self.ignore('gotTimeSync') self.__gotTimeSync = 1 self.prepareToEnter(status) def prepareToEnter(self, status): if not self.__gotTimeSync: self.notify.info('still waiting for time sync') return self.gameFSM.request('playGame', [status]) def enterMakeAToon(self, slot): if self.music: self.music.stop() self.music = None self.makeAToon.setSlot(slot) self.makeAToon.loadEnviron() self.makeAToon.load() self.makeAToon.matFSM.request('genderShop') self.acceptOnce('quitCreateAToon', self.__handleMakeAToonQuit) self.acceptOnce('createAToonFinished', self.__handleMakeAToonDone) return def __handleMakeAToonQuit(self): self.loginFSM.request('avChoose') def __handleMakeAToonDone(self, dnaStrand, slot, name): self.loginFSM.request('submitNewToon', enterArgList=[dnaStrand, slot, name]) def exitMakeAToon(self): self.makeAToon.setSlot(-1) self.makeAToon.enterExit(None) self.ignore('quitCreateAToon') self.ignore('createAToonFinished') return def enterSubmitNewToon(self, dnaStrand, slot, name, skipTutorial=0): self.submittingDialog = GlobalDialog(message=CIGlobals.Submitting) self.submittingDialog.show() self.acceptOnce(self.csm.getToonCreatedEvent(), self.__handleSubmitNewToonResp) self.csm.sendSubmitNewToon(dnaStrand, slot, name, skipTutorial) def __handleSubmitNewToonResp(self, avId): if self.requestedName is not None: self.nameServicesManager.d_requestName(self.requestedName, avId) self.requestedName = None self.loginFSM.request('avChoose') return def exitSubmitNewToon(self): self.ignore(self.csm.getToonCreatedEvent()) self.submittingDialog.cleanup() del self.submittingDialog def enterGameOff(self): pass def exitGameOff(self): pass def enterPlayGame(self, status): if self.music: self.music.stop() self.music = None base.transitions.noFade() if self.localAvChoice == None: self.notify.error('called enterPlayGame() without self.localAvChoice being set!') return if localAvatar.getTutorialCompleted() == 1 or True: zoneId = status['zoneId'] hoodId = status['hoodId'] avId = status['avId'] self.playGame.load() self.playGame.enter(hoodId, zoneId, avId) else: self.sendQuietZoneRequest() localAvatar.sendUpdate('createTutorial') self.myDistrict.d_joining() return def tutorialCreated(self, zoneId): requestStatus = {'zoneId': zoneId} self.tutQuietZoneState = QuietZoneState('tutQuietZoneDone') self.tutQuietZoneState.load() self.tutQuietZoneState.enter(requestStatus) self.acceptOnce('tutQuietZoneDone', self.__handleTutQuietZoneDone) def __handleTutQuietZoneDone(self): self.tutQuietZoneState.exit() self.tutQuietZoneState.unload() del self.tutQuietZoneState def exitPlayGame(self): self.ignore('tutQuietZoneDone') if hasattr(self, 'tutQuietZoneDone'): self.tutQuietZoneState.exit() self.tutQuietZoneState.unload() del self.tutQuietZoneState if self.music: self.music.stop() self.music = None self.playGame.exit() self.playGame.unload() return def enterDisconnect(self, isPlaying, booted=0, bootReason=None): self.notify.info('Disconnect details: isPlaying = %s, booted = %s, bootReason = %s' % ( isPlaying, booted, bootReason)) style = 3 if isPlaying == 1: if not booted: msg = CIGlobals.DisconnectionMsg else: if not booted: msg = CIGlobals.JoinFailureMsg if self.isConnected(): self.sendDisconnect() self.disconnectDialog = GlobalDialog(message=msg, style=style, doneEvent='disconnectDone') self.disconnectDialog.show() if style == 3: self.acceptOnce('disconnectDone', sys.exit) else: self.acceptOnce('disconnectDone', self.handleDisconnectDone) def handleDisconnectDone(self): value = self.disconnectDialog.getValue() if value: self.loginFSM.request('connect') else: sys.exit() def exitDisconnect(self): self.ignore('disconnectDone') self.disconnectDialog.cleanup() del self.disconnectDialog def renderFrame(self): gsg = base.win.getGsg() if gsg: render2d.prepareScene(gsg) base.graphicsEngine.renderFrame() def handleDatagram(self, di): if self.notify.getDebug(): print 'ClientRepository received datagram:' msgType = self.getMsgType() self.currentSenderId = None if self.handler == None: self.astronHandle(di) else: self.handler(msgType, di) self.considerHeartbeat() return def astronHandle(self, di): AstronClientRepository.handleDatagram(self, di) def handleQuietZoneGenerateWithRequired(self, di): doId = di.getUint32() parentId = di.getUint32() zoneId = di.getUint32() classId = di.getUint16() dclass = self.dclassesByNumber[classId] if dclass.getClassDef().neverDisable: dclass.startGenerate() distObj = self.generateWithRequiredFields(dclass, doId, di, parentId, zoneId) dclass.stopGenerate() def handleQuietZoneGenerateWithRequiredOther(self, di): doId = di.getUint32() parentId = di.getUint32() zoneId = di.getUint32() classId = di.getUint16() dclass = self.dclassesByNumber[classId] if dclass.getClassDef().neverDisable: dclass.startGenerate() distObj = self.generateWithRequiredOtherFields(dclass, doId, di, parentId, zoneId) dclass.stopGenerate() def handleQuietZoneUpdateField(self, di): di2 = DatagramIterator(di) doId = di2.getUint32() if doId in self.deferredDoIds: args, deferrable, dg0, updates = self.deferredDoIds[doId] dclass = args[2] if not dclass.getClassDef().neverDisable: return else: do = self.getDo(doId) if do: if not do.neverDisable: return AstronClientRepository.handleUpdateField(self, di) def handleDelete(self, di): doId = di.getUint32() self.deleteObject(doId) def _abandonShard(self): for doId, obj in self.doId2do.items(): if obj.parentId == localAvatar.defaultShard and obj is not localAvatar: self.deleteObject(doId) def handleEnterObjectRequiredOwner(self, di): if self.loginFSM.getCurrentState().getName() == 'waitForSetAvatarResponse': doId = di.getUint32() parentId = di.getUint32() zoneId = di.getUint32() dclassId = di.getUint16() self.__handleSetAvatarResponse(doId, di) def addTaggedInterest(self, parentId, zoneId, mainTag, desc, otherTags=[], event=None): return self.addInterest(parentId, zoneId, desc, event) def sendSetAvatarMsg(self, choice): avId = choice.getAvId() self.sendSetAvatarIdMsg(avId) self.localAvChoice = choice def sendSetAvatarIdMsg(self, avId): if avId != self.__currentAvId: self.__currentAvId = avId self.csm.sendSetAvatar(avId) def sendQuietZoneRequest(self): self.sendSetZoneMsg(CIGlobals.QuietZone)
class DistributedDroppableCollectableBackpack(DistributedDroppableCollectableObject): notify = directNotify.newCategory('DistributedDroppableCollectableBackpack') MSG_CONFIRM = 'This backpack contains:\n\n%s\n\nAre you sure you want to use this backpack?' MSG_UNZIPPING = 'Unzipping...' UNZIP_TIME = 6.0 def __init__(self, cr): try: self.DistributedDroppableCollectableBackpack_initialized return except: self.DistributedDroppableCollectableBackpack_initialized = 1 DistributedDroppableCollectableObject.__init__(self, cr) self.backpack = None self.dropShadow = None self.bp = None self.pickUpDialog = None self.unzippingDialog = None self.soundUnzipping = None self.rotateTaskName = 'Rotate Pack' self.rotateSpeed = 30 self.backpackScale = 0.35 return def setBP(self, bp): self.bp = bp def getBP(self): return self.bp def removePickUpGui(self): if self.pickUpDialog: self.pickUpDialog.cleanup() self.pickUpDialog = None return def removeUnzipGui(self): if self.unzippingDialog: self.unzippingDialog.cleanup() self.unzippingDialog = None return def __showPickUpGui(self): gagNameArray = [] gagString = '%s, %s, %s, %s' for gagId in self.getBP(): gagNameArray.append(GagGlobals.gagIds.get(gagId)) self.pickUpDialog = GlobalDialog(message=self.MSG_CONFIRM % (gagString % (gagNameArray[0], gagNameArray[1], gagNameArray[2], gagNameArray[3])), doneEvent='pickUpGui-Done', style=1) self.pickUpDialog.show() self.acceptOnce('pickUpGui-Done', self.__handleBackpackChoice) def __handleBackpackChoice(self): value = self.pickUpDialog.getValue() self.removePickUpGui() if value: self.__showUnzippingGui() else: self.cr.playGame.getPlace().fsm.request('walk') self.acceptCollisions() def __showUnzippingGui(self): self.unzippingDialog = GlobalDialog(message=self.MSG_UNZIPPING, style=0) self.unzippingDialog.show() self.soundUnzipping = base.loadSfx('phase_3.5/audio/sfx/ci_s_bpunzip.mp3') SoundInterval(self.soundUnzipping).start() base.taskMgr.doMethodLater(self.UNZIP_TIME, self.__unzipWaitDone, 'DDCBackpack-unzipWaitDone') def __unzipWaitDone(self, task): self.sendUpdate('collectedObject', []) self.removeUnzipGui() self.cr.playGame.getPlace().fsm.request('walk') return Task.done def __rotateBackpack(self, task): if self.backpack: self.backpack.setH(task.time * self.rotateSpeed) return Task.cont return Task.done def loadObject(self): self.removeObject() self.backpack = loader.loadModel('phase_4/models/accessories/tt_m_chr_avt_acc_pac_gags.bam') self.backpack.setScale(self.backpackScale) self.backpack.setZ(1.4) self.backpack.setH(random.uniform(0.0, 360.0)) self.backpack.reparentTo(self) self.dropShadow = loader.loadModel('phase_3/models/props/drop_shadow.bam') self.dropShadow.setColor(0, 0, 0, 0.5) self.dropShadow.setScale(0.25) self.dropShadow.setZ(0.025) self.dropShadow.flattenLight() self.dropShadow.reparentTo(self) base.taskMgr.add(self.__rotateBackpack, self.rotateTaskName) def removeObject(self): if self.backpack: base.taskMgr.remove(self.rotateTaskName) self.dropShadow.removeNode() self.backpack.removeNode() self.dropShadow = None self.backpack = None return def handleCollisions(self, entry): self.cr.playGame.getPlace().fsm.request('stop') self.__showPickUpGui() def disable(self): base.taskMgr.remove('DDCBackpack-unzipWaitDone') self.removeUnzipGui() self.removePickUpGui() if self.cr.playGame.getPlace(): if self.cr.playGame.getPlace().fsm: if self.cr.playGame.getPlace().fsm.getCurrentState(): if self.cr.playGame.getPlace().fsm.getCurrentState().getName() == 'stop': self.cr.playGame.getPlace().fsm.request('walk') self.soundUnzipping = None DistributedDroppableCollectableObject.disable(self) return
def enterDied(self): self.deathDialog = GlobalDialog(message=CIGlobals.SuitDefeatMsg, style=2, doneEvent='deathChoice') self.deathDialog.show() self.acceptOnce('deathChoice', self.handleDeathChoice)
def __showUnzippingGui(self): self.unzippingDialog = GlobalDialog(message=self.MSG_UNZIPPING, style=0) self.unzippingDialog.show() self.soundUnzipping = base.loadSfx('phase_3.5/audio/sfx/ci_s_bpunzip.mp3') SoundInterval(self.soundUnzipping).start() base.taskMgr.doMethodLater(self.UNZIP_TIME, self.__unzipWaitDone, 'DDCBackpack-unzipWaitDone')
def handleMATUnavailable(self): base.transitions.fadeIn(0) self.matNAMsg = GlobalDialog(message=CIGlobals.MatNAMsg, doneEvent="matNAEvent", style=1) self.acceptOnce("matNAEvent", self.removeMatNAMsg)
def enterStart(self): self.descDialog = GlobalDialog(style=3, message=self.getDescription(), doneEvent='gameDescAck') self.acceptOnce('gameDescAck', self.handleDescAck)
class Place(StateData): notify = directNotify.newCategory('Place') def __init__(self, loader, doneEvent): StateData.__init__(self, doneEvent) self.loader = loader self.zoneId = None self.track = None return def maybeUpdateAdminPage(self): if self.fsm: if self.fsm.getCurrentState(): if self.fsm.getCurrentState().getName() == 'shtickerBook': if hasattr(self, 'shtickerBookStateData'): if self.shtickerBookStateData.fsm.getCurrentState().getName() == 'adminPage': if base.cr.playGame.suitManager: text2Change2 = 'Turn Suit Spawner ' if base.cr.playGame.suitManager.getSpawner(): text2Change2 += 'Off' else: text2Change2 += 'On' self.shtickerBookStateData.adminPageStateData.suitSpawnerBtn['text'] = text2Change2 def enterStart(self): pass def exitStart(self): pass def enterFinal(self): pass def exitFinal(self): pass def enter(self): StateData.enter(self) base.localAvatar.createChatInput() def exit(self): base.localAvatar.disableChatInput() StateData.exit(self) def enterDoorIn(self, distDoor): base.localAvatar.attachCamera() requestStatus = {} requestStatus['zoneId'] = distDoor.getToZone() requestStatus['hoodId'] = base.cr.playGame.hood.id requestStatus['how'] = 'doorOut' requestStatus['shardId'] = None requestStatus['doorIndex'] = distDoor.getDoorIndex() foundBlock = False for interior in base.cr.doFindAll('DistributedToonInterior'): if interior.zoneId == base.localAvatar.zoneId: foundBlock = True requestStatus['block'] = interior.getBlock() break if not foundBlock: requestStatus['block'] = distDoor.getBlock() requestStatus['where'] = ZoneUtil.getWhereName(requestStatus['zoneId']) requestStatus['loader'] = base.cr.playGame.hood.fsm.getCurrentState().getName() requestStatus['avId'] = base.localAvatar.doId self.acceptOnce('DistributedDoor_localAvatarWentInDoor', self.handleDoorInDone, [requestStatus]) self.acceptOnce('DistributedDoor_localAvatarGoingInDoor', base.transitions.irisOut) return def exitDoorIn(self): base.localAvatar.detachCamera() self.ignore('DistributedDoor_localAvatarWentInDoor') self.ignore('DistributedDoor_localAvatarGoingInDoor') def handleDoorInDone(self, requestStatus): self.doneStatus = requestStatus messenger.send(self.doneEvent) def __waitOnDoor(self, door, task): if door.ready: self.__doorReady(door) return task.done return task.cont def enterDoorOut(self, requestStatus): base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.d_clearSmoothing() base.localAvatar.stopPosHprBroadcast() base.localAvatar.walkControls.setCollisionsActive(0) block = requestStatus['block'] zoneId = requestStatus['zoneId'] doorIndex = requestStatus['doorIndex'] doorToExitFrom = None for door in base.cr.doFindAll('DistributedDoor'): if door.zoneId == zoneId: if door.getBlock() == block: if door.getDoorIndex() == doorIndex: doorToExitFrom = door break if not doorToExitFrom: self.notify.error('Could not find a DistributedDoor to exit from!') elif not doorToExitFrom.ready: base.taskMgr.add(self.__waitOnDoor, 'Place.waitOnDoor', extraArgs=[doorToExitFrom], appendTask=True) return self.__doorReady(doorToExitFrom) return def __doorReady(self, door): door.sendUpdate('requestExit', []) self.nextState = 'walk' self.acceptOnce('DistributedDoor_localAvatarCameOutOfDoor', self.handleDoorOutDone) def exitDoorOut(self): base.taskMgr.remove('Place.waitOnDoor') base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() self.ignore('DistributedDoor_localAvatarCameOutOfDoor') def handleDoorOutDone(self): base.transitions.irisIn() base.localAvatar.walkControls.setCollisionsActive(1) self.fsm.request(self.nextState) def enterShtickerBook(self): base.localAvatar.attachCamera() base.localAvatar.createLaffMeter() base.localAvatar.startSmartCamera() base.localAvatar.startPosHprBroadcast() base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setAnimState('openBook', self.enterShtickerBookGui) def enterShtickerBookGui(self): doneEvent = 'shtickerBookDone' self.shtickerBookStateData = ShtickerBook(self.fsm, doneEvent) self.acceptOnce(doneEvent, self.__shtickerBookDone) self.shtickerBookStateData.load() self.shtickerBookStateData.enter() base.localAvatar.showBookButton(1) base.localAvatar.b_setAnimState('readBook') def __shtickerBookDone(self): doneStatus = self.shtickerBookStateData.getDoneStatus() base.localAvatar.hideBookButton() self.shtickerBookStateData.exit() if doneStatus['mode'] == 'exit': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseExit) elif doneStatus['mode'] == 'teleport': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseTeleport, [doneStatus]) elif doneStatus['mode'] == 'resume': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseResume) elif doneStatus['mode'] == 'switchShard': base.localAvatar.b_setAnimState('closeBook', self.__handleBookCloseSwitchShard, [doneStatus]) def __handleBookCloseSwitchShard(self, requestStatus): base.localAvatar.b_setAnimState('teleportOut', self.__handleBookSwitchShard, [requestStatus]) def __handleBookSwitchShard(self, requestStatus): params = [] params.append(requestStatus['shardId']) params.append(base.cr.playGame.hood.id) params.append(ZoneUtil.getZoneId(base.cr.playGame.hood.id)) params.append(base.localAvatar.doId) base.cr.gameFSM.request('switchShards', params) def __handleBookCloseResume(self): self.fsm.request('walk') def __handleBookCloseTeleport(self, requestStatus): self.fsm.request('teleportOut', [requestStatus]) def __teleportOutDone(self, requestStatus): self.doneStatus = requestStatus messenger.send(self.doneEvent) def __handleBookCloseExit(self): base.localAvatar.b_setAnimState('teleportOut', self.__handleBookExitTeleport) def __handleBookExitTeleport(self): base.transitions.fadeOut(0.0) base.cr.gameFSM.request('closeShard') def exitShtickerBook(self): base.localAvatar.detachCamera() base.localAvatar.stopSmartCamera() base.localAvatar.stopPosHprBroadcast() base.localAvatar.disableLaffMeter() self.ignore(self.shtickerBookStateData.doneEvent) self.shtickerBookStateData.exit() self.shtickerBookStateData.unload() del self.shtickerBookStateData base.localAvatar.hideBookButton() def enterStop(self, doNeutral = 1): if doNeutral: base.localAvatar.b_setAnimState('neutral') base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.createLaffMeter() base.localAvatar.createMoney() base.localAvatar.enablePies(0) def exitStop(self): base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() base.localAvatar.disableLaffMeter() base.localAvatar.disableMoney() base.localAvatar.disablePies() def load(self): StateData.load(self) self.walkDoneEvent = 'walkDone' self.walkStateData = PublicWalk(self.fsm, self.walkDoneEvent) self.walkStateData.load() def unload(self): StateData.unload(self) del self.walkDoneEvent self.walkStateData.unload() del self.walkStateData del self.loader def enterTeleportIn(self, requestStatus): if requestStatus['avId'] != base.localAvatar.doId: av = base.cr.doId2do.get(requestStatus['avId']) if av: base.localAvatar.gotoNode(av) base.localAvatar.b_setChat('Hi, %s.' % av.getName()) base.transitions.irisIn() self.nextState = requestStatus.get('nextState', 'walk') base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.startPosHprBroadcast() globalClock.tick() base.localAvatar.b_setAnimState('teleportIn', callback=self.teleportInDone) base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setParent(CIGlobals.SPRender) def exitTeleportIn(self): base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() base.localAvatar.stopPosHprBroadcast() def teleportInDone(self): if hasattr(self, 'fsm'): self.fsm.request(self.nextState, [1]) def enterAcknowledgeDeath(self, foo = 0): base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() message = 'You were defeated by the Cogs! Collect treasures in the Playground to refill your Laff meter.' self.dialog = GlobalDialog(message=message, style=3, doneEvent='ackDeathDone') self.dialog.show() self.acceptOnce('ackDeathDone', self.handleAckDeathDone) def handleAckDeathDone(self): self.fsm.request('walk', [1]) def exitAcknowledgeDeath(self): self.ignore('ackDeathDone') self.dialog.cleanup() del self.dialog base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() def enterDied(self, requestStatus, callback = None): if callback == None: callback = self.__diedDone base.localAvatar.createLaffMeter() base.localAvatar.attachCamera() base.localAvatar.b_setAnimState('died', callback, [requestStatus]) return def __diedDone(self, requestStatus): self.doneStatus = requestStatus messenger.send(self.doneEvent) def exitDied(self): base.localAvatar.disableLaffMeter() base.localAvatar.detachCamera() def enterWalk(self, teleportIn = 0): self.walkStateData.enter() if teleportIn == 0: self.walkStateData.fsm.request('walking') self.acceptOnce(self.walkDoneEvent, self.handleWalkDone) self.walkStateData.fsm.request('walking') self.watchTunnelSeq = Sequence(Wait(1.0), Func(LinkTunnel.globalAcceptCollisions)) self.watchTunnelSeq.start() base.localAvatar.setBusy(0) base.localAvatar.enablePicking() base.localAvatar.showFriendButton() def exitWalk(self): self.walkStateData.exit() self.ignore(self.walkDoneEvent) if base.cr.playGame.hood.titleText != None: base.cr.playGame.hood.hideTitleText() self.watchTunnelSeq.pause() del self.watchTunnelSeq base.localAvatar.setBusy(1) base.localAvatar.disablePicking() base.localAvatar.hideFriendButton() base.localAvatar.friendsList.fsm.requestFinalState() base.localAvatar.panel.fsm.requestFinalState() return def handleWalkDone(self, doneStatus): pass def enterTeleportOut(self, requestStatus, callback = None): if not callback: callback = self.__teleportOutDone base.localAvatar.attachCamera() base.localAvatar.startSmartCamera() base.localAvatar.startPosHprBroadcast() base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setAnimState('teleportOut', callback, [requestStatus]) def exitTeleportOut(self): base.localAvatar.disableLaffMeter() base.localAvatar.stopSmartCamera() base.localAvatar.detachCamera() base.localAvatar.stopPosHprBroadcast() def enterTunnelIn(self, linkTunnel): base.localAvatar.attachCamera() base.localAvatar.playMovementSfx('run') pivotPoint = linkTunnel.inPivotPoint self.pivotPointNode = linkTunnel.tunnel.attachNewNode('tunnelPivotPoint') self.pivotPointNode.setPos(pivotPoint) currCamPos = camera.getPos(linkTunnel.tunnel) currCamHpr = camera.getHpr(linkTunnel.tunnel) currPos = base.localAvatar.getPos(self.pivotPointNode) currHpr = base.localAvatar.getHpr(self.pivotPointNode) if linkTunnel.__class__.__name__ == 'SafeZoneLinkTunnel': base.localAvatar.setHpr(180, 0, 0) else: base.localAvatar.setHpr(0, 0, 0) base.localAvatar.setPos(currPos) base.localAvatar.reparentTo(self.pivotPointNode) base.localAvatar.walkControls.setCollisionsActive(0) base.localAvatar.detachCamera() camera.reparentTo(linkTunnel.tunnel) tunnelCamPos = linkTunnel.camPos tunnelCamHpr = linkTunnel.camHpr self.track = Parallel(LerpPosInterval(camera, duration=0.7, pos=tunnelCamPos, startPos=currCamPos, blendType='easeOut'), LerpQuatInterval(camera, duration=0.7, quat=tunnelCamHpr, startHpr=currCamHpr, blendType='easeOut'), Sequence(Func(base.localAvatar.b_setAnimState, 'run'), Wait(2.0), Func(base.transitions.irisOut)), Sequence(LerpHprInterval(self.pivotPointNode, duration=2.0, hpr=linkTunnel.inPivotEndHpr, startHpr=linkTunnel.inPivotStartHpr), LerpPosInterval(self.pivotPointNode, duration=1.0, pos=(linkTunnel.inPivotEndX, self.pivotPointNode.getY(), self.pivotPointNode.getZ()), startPos=(linkTunnel.inPivotStartX, self.pivotPointNode.getY(), self.pivotPointNode.getZ()))), name='Place.enterTunnelIn') requestStatus = {} requestStatus['zoneId'] = linkTunnel.data['zoneId'] if linkTunnel.__class__.__name__ == 'SafeZoneLinkTunnel': requestStatus['where'] = 'street' requestStatus['loader'] = 'townLoader' requestStatus['hoodId'] = base.cr.playGame.hood.id requestStatus['shardId'] = None requestStatus['avId'] = base.localAvatar.doId requestStatus['how'] = 'tunnelOut' requestStatus['fromZone'] = base.localAvatar.zoneId elif linkTunnel.__class__.__name__ == 'StreetLinkTunnel': requestStatus['where'] = 'playground' requestStatus['loader'] = 'safeZoneLoader' requestStatus['hoodId'] = base.cr.playGame.hood.id requestStatus['shardId'] = None requestStatus['avId'] = base.localAvatar.doId requestStatus['how'] = 'tunnelOut' requestStatus['fromZone'] = base.localAvatar.zoneId elif linkTunnel.__class__.__name__ == 'NeighborhoodLinkTunnel': requestStatus['where'] = 'street' requestStatus['loader'] = 'townLoader' hoodId = ZoneUtil.getHoodId(linkTunnel.data['zoneId'], 1) requestStatus['hoodId'] = hoodId requestStatus['shardId'] = None requestStatus['avId'] = base.localAvatar.doId requestStatus['how'] = 'tunnelOut' requestStatus['fromZone'] = base.localAvatar.zoneId self.track.setDoneEvent(self.track.getName()) self.acceptOnce(self.track.getDoneEvent(), self.__handleTunnelInDone, [requestStatus]) self.track.start() return def __handleTunnelInDone(self, requestStatus): self.doneStatus = requestStatus messenger.send(self.doneEvent) def exitTunnelIn(self): base.localAvatar.playMovementSfx(None) if self.track: self.ignore(self.track.getDoneEvent()) self.track.finish() self.track = None base.localAvatar.reparentTo(render) self.pivotPointNode.removeNode() del self.pivotPointNode base.localAvatar.detachCamera() base.localAvatar.walkControls.setCollisionsActive(1) return def enterTunnelOut(self, requestStatus): base.localAvatar.playMovementSfx('run') base.transitions.irisIn() self.nextState = requestStatus.get('nextState', 'walk') linkTunnel = LinkTunnel.getTunnelThatGoesToZone(requestStatus['fromZone']) pivotPoint = linkTunnel.outPivotPoint self.pivotPointNode = linkTunnel.tunnel.attachNewNode('tunnelPivotPoint') self.pivotPointNode.setPos(pivotPoint) self.pivotPointNode.setHpr(linkTunnel.outPivotStartHpr) base.localAvatar.walkControls.setCollisionsActive(0) base.localAvatar.reparentTo(self.pivotPointNode) base.localAvatar.setHpr(linkTunnel.toonOutHpr) base.localAvatar.setPos(linkTunnel.toonOutPos) base.localAvatar.detachCamera() camera.reparentTo(linkTunnel.tunnel) tunnelCamPos = linkTunnel.camPos tunnelCamHpr = linkTunnel.camHpr camera.setPos(tunnelCamPos) camera.setHpr(tunnelCamHpr) self.track = Parallel(Sequence(Func(base.localAvatar.b_setAnimState, 'run'), LerpPosInterval(self.pivotPointNode, duration=1.0, pos=(linkTunnel.outPivotEndX, self.pivotPointNode.getY(), self.pivotPointNode.getZ()), startPos=(linkTunnel.outPivotStartX, self.pivotPointNode.getY(), self.pivotPointNode.getZ())), LerpHprInterval(self.pivotPointNode, duration=2.0, hpr=linkTunnel.outPivotEndHpr, startHpr=linkTunnel.outPivotStartHpr)), name='Place.enterTunnelOut') self.track.setDoneEvent(self.track.getName()) self.acceptOnce(self.track.getDoneEvent(), self.__handleTunnelOutDone) self.track.start() def __handleTunnelOutDone(self): base.localAvatar.walkControls.setCollisionsActive(1) self.fsm.request(self.nextState) def exitTunnelOut(self): base.localAvatar.playMovementSfx(None) base.localAvatar.walkControls.setCollisionsActive(1) if self.track: self.ignore(self.track.getDoneEvent()) self.track.finish() self.track = None base.localAvatar.setPos(base.localAvatar.getPos(render)) base.localAvatar.setHpr(base.localAvatar.getHpr(render)) base.localAvatar.reparentTo(render) self.pivotPointNode.removeNode() del self.pivotPointNode base.localAvatar.detachCamera() del self.nextState return
class DistributedDroppableCollectableBackpack( DistributedDroppableCollectableObject): notify = directNotify.newCategory( 'DistributedDroppableCollectableBackpack') MSG_CONFIRM = 'This backpack contains:\n\n%s\n\nAre you sure you want to use this backpack?' MSG_UNZIPPING = 'Unzipping...' UNZIP_TIME = 6.0 def __init__(self, cr): try: self.DistributedDroppableCollectableBackpack_initialized return except: self.DistributedDroppableCollectableBackpack_initialized = 1 DistributedDroppableCollectableObject.__init__(self, cr) self.backpack = None self.dropShadow = None self.bp = None self.pickUpDialog = None self.unzippingDialog = None self.soundUnzipping = None self.rotateTaskName = 'Rotate Pack' self.rotateSpeed = 30 self.backpackScale = 0.35 return def setBP(self, bp): self.bp = bp def getBP(self): return self.bp def removePickUpGui(self): if self.pickUpDialog: self.pickUpDialog.cleanup() self.pickUpDialog = None return def removeUnzipGui(self): if self.unzippingDialog: self.unzippingDialog.cleanup() self.unzippingDialog = None return def __showPickUpGui(self): gagNameArray = [] gagString = '%s, %s, %s, %s' for gagId in self.getBP(): gagNameArray.append(GagGlobals.gagIds.get(gagId)) self.pickUpDialog = GlobalDialog(message=self.MSG_CONFIRM % (gagString % (gagNameArray[0], gagNameArray[1], gagNameArray[2], gagNameArray[3])), doneEvent='pickUpGui-Done', style=1) self.pickUpDialog.show() self.acceptOnce('pickUpGui-Done', self.__handleBackpackChoice) def __handleBackpackChoice(self): value = self.pickUpDialog.getValue() self.removePickUpGui() if value: self.__showUnzippingGui() else: self.cr.playGame.getPlace().fsm.request('walk') self.acceptCollisions() def __showUnzippingGui(self): self.unzippingDialog = GlobalDialog(message=self.MSG_UNZIPPING, style=0) self.unzippingDialog.show() self.soundUnzipping = base.loadSfx( 'phase_3.5/audio/sfx/ci_s_bpunzip.ogg') SoundInterval(self.soundUnzipping).start() base.taskMgr.doMethodLater(self.UNZIP_TIME, self.__unzipWaitDone, 'DDCBackpack-unzipWaitDone') def __unzipWaitDone(self, task): self.sendUpdate('collectedObject', []) self.removeUnzipGui() self.cr.playGame.getPlace().fsm.request('walk') return Task.done def __rotateBackpack(self, task): if self.backpack: self.backpack.setH(task.time * self.rotateSpeed) return Task.cont return Task.done def loadObject(self): self.removeObject() self.backpack = loader.loadModel( 'phase_4/models/accessories/tt_m_chr_avt_acc_pac_gags.bam') self.backpack.setScale(self.backpackScale) self.backpack.setZ(1.4) self.backpack.setH(random.uniform(0.0, 360.0)) self.backpack.reparentTo(self) self.dropShadow = loader.loadModel( 'phase_3/models/props/drop_shadow.bam') self.dropShadow.setColor(0, 0, 0, 0.5) self.dropShadow.setScale(0.25) self.dropShadow.setZ(0.025) self.dropShadow.flattenLight() self.dropShadow.reparentTo(self) base.taskMgr.add(self.__rotateBackpack, self.rotateTaskName) def removeObject(self): if self.backpack: base.taskMgr.remove(self.rotateTaskName) self.dropShadow.removeNode() self.backpack.removeNode() self.dropShadow = None self.backpack = None return def handleCollisions(self, entry): self.cr.playGame.getPlace().fsm.request('stop') self.__showPickUpGui() def disable(self): base.taskMgr.remove('DDCBackpack-unzipWaitDone') self.removeUnzipGui() self.removePickUpGui() if self.cr.playGame.getPlace(): if self.cr.playGame.getPlace().fsm: if self.cr.playGame.getPlace().fsm.getCurrentState(): if self.cr.playGame.getPlace().fsm.getCurrentState( ).getName() == 'stop': self.cr.playGame.getPlace().fsm.request('walk') self.soundUnzipping = None DistributedDroppableCollectableObject.disable(self) return
class DistributedMinigame(DistributedObject.DistributedObject, Timer.Timer): def __init__(self, cr): try: self.DistributedMinigame_initialized return except: self.DistributedMinigame_initialized = 1 DistributedObject.DistributedObject.__init__(self, cr) Timer.Timer.__init__(self) self.headPanels = HeadPanels() self.finalScoreUI = FinalScoreGUI() self.fsm = ClassicFSM('DistributedMinigame', [ State('start', self.enterStart, self.exitStart, ['waitForOthers']), State('waitForOthers', self.enterWaitForOthers, self.exitWaitForOthers, ['play']), State('play', self.enterPlay, self.exitPlay, ['gameOver']), State('gameOver', self.enterGameOver, self.exitGameOver, ['off']), State('off', self.enterOff, self.exitOff) ], 'off', 'off') self.fsm.enterInitialState() self.cr = cr self.localAv = base.localAvatar self.localAvId = self.localAv.doId self.musicPath = 'phase_4/audio/bgm/trolley_song.mid' self.winSfx = base.loadSfx('phase_4/audio/sfx/MG_win.ogg') self.loseSfx = base.loadSfx('phase_4/audio/sfx/MG_lose.ogg') self.prizeHigh = base.loadSfx('phase_6/audio/sfx/KART_Applause_1.ogg') self.prizeLow = base.loadSfx('phase_6/audio/sfx/KART_Applause_4.ogg') self.music = None self.description = '' self.descDialog = None self.winnerPrize = 0 self.loserPrize = 0 self.winnerMsg = 'Winner!\nYou have earned: %s Jellybeans' self.loserMsg = 'Loser!\nYou have earned: %s Jellybeans' self.allWinnerMsgs = [ 'Nice try!\nYou have earned: %s', 'Good job!\nYou have earned: %s', 'Way to go!\nYou have earned: %s', 'Awesome!\nYou have earned: %s' ] self.timer = None self.timeLbl = None self.alertText = None self.alertPulse = None self.popupSound = None self.gameOverLbl = OnscreenText(text="TIME'S\nUP!", scale=0.25, font=CIGlobals.getMickeyFont(), fg=(1, 0, 0, 1)) self.gameOverLbl.setBin('gui-popup', 60) self.gameOverLbl.hide() return def getTeamDNAColor(self, team): pass def showAlert(self, text): self.stopPulse() base.playSfx(self.popupSound) self.alertText.setText(text) self.alertPulse = getAlertPulse(self.alertText) self.alertPulse.start() def stopPulse(self): if self.alertPulse: self.alertPulse.finish() self.alertPulse = None return def enterFinalScores(self): self.finalScoreUI.load() self.finalScoreUI.showFinalScores() def exitFinalScores(self): self.finalScoreUI.hideFinalScores() self.finalScoreUI.unload() def finalScores(self, avIdList, scoreList): self.finalScoreUI.handleFinalScores(avIdList, scoreList) def generateHeadPanel(self, gender, head, headtype, color, doId, name): self.headPanels.generate(gender, head, headtype, color, doId, name) def updateHeadPanelValue(self, doId, direction): self.headPanels.updateValue(doId, direction) def setTimerTime(self, time): self.setTime(time) def createTimer(self): Timer.Timer.load(self) def deleteTimer(self): Timer.Timer.unload(self) def setDescription(self, desc): self.description = desc def getDescription(self): return self.description def enterStart(self): self.descDialog = GlobalDialog(style=3, message=self.getDescription(), doneEvent='gameDescAck') self.acceptOnce('gameDescAck', self.handleDescAck) def handleDescAck(self): self.d_ready() self.fsm.request('waitForOthers') def exitStart(self): self.ignore('gameDescAck') self.descDialog.cleanup() del self.descDialog def enterWaitForOthers(self): self.waitLbl = DirectLabel(text='Waiting for other players...', relief=None, text_fg=(1, 1, 1, 1), text_scale=0.08, text_shadow=(0, 0, 0, 1)) return def exitWaitForOthers(self): self.waitLbl.destroy() del self.waitLbl def setLoserPrize(self, prize): self.loserPrize = prize def setWinnerPrize(self, prize): self.winnerPrize = prize def getLoserPrize(self): return self.loserPrize def getWinnerPrize(self): return self.winnerPrize def winner(self): self.winSfx.play() self.localAv.b_setAnimState('happy') Sequence(Wait(3.5), Func(self.displayGameOver, 'winner')).start() def showPrize(self, amt): self.winSfx.play() self.localAv.b_setAnimState('happy') Sequence(Wait(3.5), Func(self.displayGameOver, 'showPrize', amt)).start() def loser(self): self.loseSfx.play() self.localAv.b_setAnimState('neutral') Sequence(Wait(3.5), Func(self.displayGameOver, 'loser')).start() def displayGameOver(self, scenario, amt=None): if scenario == 'winner': msg = self.winnerMsg % self.winnerPrize self.prizeHigh.play() else: if scenario == 'loser': msg = self.loserMsg % self.loserPrize self.prizeLow.play() else: if scenario == 'showPrize': msg = random.choice(self.allWinnerMsgs) % amt self.prizeHigh.play() self.gameOverDialog = GlobalDialog(message=msg, style=3, doneEvent='gameOverAck') self.acceptOnce('gameOverAck', self.__handleGameOverAck) self.gameOverDialog.show() def deleteGameOverDialog(self): self.ignore('gameOverAck') if hasattr(self, 'gameOverDialog'): self.gameOverDialog.cleanup() del self.gameOverDialog def __handleGameOverAck(self): self.fsm.requestFinalState() Sequence(Func(base.transitions.irisOut, 1.0), Wait(1.2), Func(self.d_leaving), Func(self.headBackToMinigameArea)).start() def headBackToMinigameArea(self): whereName = ZoneUtil.getWhereName(CIGlobals.MinigameAreaId) loaderName = ZoneUtil.getLoaderName(CIGlobals.MinigameAreaId) requestStatus = { 'zoneId': CIGlobals.MinigameAreaId, 'hoodId': CIGlobals.MinigameArea, 'where': whereName, 'how': 'teleportIn', 'avId': base.localAvatar.doId, 'shardId': None, 'loader': loaderName } self.cr.playGame.hood.fsm.request('quietZone', [requestStatus]) return def abort(self): self.headBackToMinigameArea() def load(self, showDesc=True): if showDesc: self.fsm.request('start') base.transitions.irisIn() def d_leaving(self): self.sendUpdate('leaving', []) def allPlayersReady(self): self.fsm.request('play') def enterPlay(self): self.playMinigameMusic() def exitPlay(self): self.stopMinigameMusic() def enterOff(self): pass def exitOff(self): pass def enterGameOver(self, winner, winnerDoId, allPrize): if winner: if self.localAvId in winnerDoId: self.winner() else: self.loser() else: self.showPrize(allPrize) def exitGameOver(self): self.deleteGameOverDialog() def gameOver(self, winner=0, winnerDoId=[], allPrize=0): self.fsm.request('gameOver', [winner, winnerDoId, allPrize]) def setMinigameMusic(self, path): self.musicPath = path def getMinigameMusic(self): return self.musicPath def playMinigameMusic(self): self.stopMinigameMusic() self.music = base.loadMusic(self.musicPath) self.music.setLoop(True) self.music.setVolume(0.8) self.music.play() def stopMinigameMusic(self): if self.music: self.music.stop() self.music = None return def d_ready(self): self.sendUpdate('ready', []) def announceGenerate(self): DistributedObject.DistributedObject.announceGenerate(self) base.minigame = self self.alertText = getAlertText() self.popupSound = base.loadSfx( 'phase_3/audio/sfx/GUI_balloon_popup.ogg') NametagGlobals.setWant2dNametags(False) def disable(self): base.localAvatar.getGeomNode().setColorScale(VBase4(1, 1, 1, 1)) if hasattr(self, 'gameOverLbl') and self.gameOverLbl: self.gameOverLbl.destroy() self.gameOverLbl = None NametagGlobals.setWant2dNametags(True) base.localAvatar.setPosHpr(0, 0, 0, 0, 0, 0) self.fsm.requestFinalState() del self.fsm self.winSfx = None self.loseSfx = None self.prizeHigh = None self.prizeLow = None self.headPanels.delete() self.headPanels = None self.finalScoreUI.unload() self.finalScoreUI = None base.minigame = None DistributedObject.DistributedObject.disable(self) return
class PickAToon: name_hpr = [ Point3(0, 0, 352), Point3(0, 0, 4), Point3(0, 0, 4), Point3(0, 0, -4), Point3(0, 0, -4), Point3(0, 0, 1) ] name_pos = [ Point3(-0.03, 0, 0.22), Point3(0, 0, 0.235), Point3(0, 0, 0.235), Point3(0, 0, 0.24), Point3(-0.04, 0, 0.235), Point3(0, 0, 0.25) ] trash_pos = [ Point3(0.29, 0, -0.18), Point3(0.22, 0, -0.22), Point3(0.18, 0, -0.24), Point3(0.27, 0, -0.21), Point3(0.30, 0, -0.18), Point3(0.21, 0, -0.23) ] BgColor = (0.1450980392156863, 0.3686274509803922, 0.7803921568627451) def __init__(self, avChooser): self.title = None self.avChooser = avChooser self.dna = ToonDNA() #self.tutorial = Tutorial.Tutorial(self) def createGui(self): base.cr.renderFrame() self.m = loader.loadFont("phase_3/models/fonts/MickeyFont.bam") self.bg = loader.loadModel( "phase_3/models/gui/tt_m_gui_pat_mainGui.bam") self.qtbtn = loader.loadModel("phase_3/models/gui/quit_button.bam") self.trash_gui = loader.loadModel( "phase_3/models/gui/trashcan_gui.bam") self.bg_img = OnscreenImage( image=self.bg.find('**/tt_t_gui_pat_background')) self.setTitle("Pick A Toon To Play") base.setBackgroundColor(self.BgColor) self.btn1 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareGreen'), relief=None, pos=(0.012, 0, 0.306), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn2 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squarePink'), relief=None, pos=(0.01, 0, -0.515), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn3 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareRed'), relief=None, pos=(-0.84, 0, 0.36), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn4 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareYellow'), relief=None, pos=(0.865, 0, -0.45), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn5 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squareBlue'), relief=None, pos=(-0.87, 0, -0.44), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.btn6 = DirectButton( geom=self.bg.find('**/tt_t_gui_pat_squarePurple'), relief=None, pos=(0.873, 0, 0.335), text_wordwrap=6, text_fg=(1, 1, 1, 1)) self.quit_btn = DirectButton(geom=(self.qtbtn.find('**/QuitBtn_RLVR'), self.qtbtn.find('**/QuitBtn_RLVR'), self.qtbtn.find('**/QuitBtn_RLVR')), relief=None, text="Quit", text_font=self.m, text_scale=0.105, text_pos=(0, -0.035), pos=(1.05, 0, -0.9), text_fg=(1, 0.9, 0.1, 1), geom1_scale=(1.02, 1, 1), geom2_scale=(1.02, 1, 1), command=self.quitGame) self.btnList = [] self.btnList.append(self.btn1) self.btnList.append(self.btn2) self.btnList.append(self.btn3) self.btnList.append(self.btn4) self.btnList.append(self.btn5) self.btnList.append(self.btn6) self.headList = [] #datafiler = open("toons/data.txt", "r") #if datafiler.read() == "-": # for btn in self.btnList: # btn['state'] = DGG.DISABLED # self.quit_btn['state'] = DGG.DISABLED # self.tutorial.askTutorial() # datafilew = open("toons/data.txt", "w") # datafilew.write("+") # datafilew.flush() # datafilew.close() #datafiler.close() for slot in range(6): if self.avChooser.hasToonInSlot(slot): notify.info("found existing Toon in slot %s" % (str(slot))) frame = DirectFrame(relief=None, parent=self.btnList[slot], pos=(0, 0, -0.1)) headframe = hidden.attachNewNode('head') headframe.setPosHprScale(0, 5, -0.1, 180, 0, 0, 0.24, 0.24, 0.24) headframe.reparentTo(self.btnList[slot].stateNodePath[0], 20) headframe.instanceTo(self.btnList[slot].stateNodePath[1], 20) headframe.instanceTo(self.btnList[slot].stateNodePath[2], 20) toon = ToonHead(base.cr) self.headList.append(toon) gender, animal, head, headcolor = self.avChooser.getHeadInfo( slot) toon.generateHead(gender, animal, head, 1) toon.getGeomNode().setDepthWrite(1) toon.getGeomNode().setDepthTest(1) toon.startBlink() toon.startLookAround() toon.reparentTo(headframe) toon.setHeadColor(headcolor) toon.flattenLight() name_lbl = DirectLabel(text=self.avChooser.getNameInSlot(slot), text_scale=0.08, text_fg=(1, 1, 1, 1), text_wordwrap=7, relief=None, text_shadow=(0, 0, 0, 1)) name_lbl.reparentTo(self.btnList[slot].stateNodePath[0], 20) name_lbl.instanceTo(self.btnList[slot].stateNodePath[1], 20) name_lbl.instanceTo(self.btnList[slot].stateNodePath[2], 20) name_lbl.setPos(self.name_pos[slot]) name_lbl.setHpr(self.name_hpr[slot]) self.btnList[slot]['text'] = ("", "Play This Toon", "Play This Toon", "") self.btnList[slot]['text_scale'] = 0.1 self.btnList[slot]['text_pos'] = (0, 0) self.btnList[slot]['text_fg'] = (1, 0.9, 0, 1) self.btnList[slot]['text_wordwrap'] = 6 self.btnList[slot]['text_font'] = self.m self.btnList[slot]['command'] = self.fadeMenu self.btnList[slot]['extraArgs'] = ["playGame", slot] delBtn = DirectButton( text=("", "Delete", "Delete", ""), text_scale=0.15, scale=0.5, text_pos=(0, -0.1), text_fg=(1, 1, 1, 1), relief=None, geom=(self.trash_gui.find('**/TrashCan_CLSD'), self.trash_gui.find('**/TrashCan_OPEN'), self.trash_gui.find('**/TrashCan_RLVR')), pos=self.trash_pos[slot], command=self.deleteToon, extraArgs=[ self.avChooser.getAvChoiceBySlot(slot).getAvId() ], text_shadow=(0, 0, 0, 1)) delBtn.reparentTo(self.btnList[slot].stateNodePath[0], 20) delBtn.instanceTo(self.btnList[slot].stateNodePath[1], 20) delBtn.instanceTo(self.btnList[slot].stateNodePath[2], 20) else: self.btnList[slot]['text'] = "Make A Toon" self.btnList[slot]['text_font'] = self.m self.btnList[slot]['text0_scale'] = 0.1 self.btnList[slot]['text1_scale'] = 0.12 self.btnList[slot]['text2_scale'] = 0.12 self.btnList[slot]['text3_scale'] = 0.1 self.btnList[slot]['text0_fg'] = (0, 1, 0.8, 0.5) self.btnList[slot]['text1_fg'] = (0, 1, 0.8, 1) self.btnList[slot]['text2_fg'] = (0.3, 1, 0.9, 1) self.btnList[slot]['text3_fg'] = (0, 1, 0.8, 0.5) self.btnList[slot]['text_font'] = self.m self.btnList[slot]['command'] = self.fadeMenu self.btnList[slot]['extraArgs'] = ["mat", slot] self.btnList[slot]['text_wordwrap'] = 6 def quitGame(self): base.cr.disconnect() base.cr.shutdown() base.shutdown() sys.exit() def deleteToon(self, avId): notify.warning("deleting Toon with avId %s" % (avId)) base.transitions.fadeOut(0.3) Sequence(Wait(0.31), Func(self.callDeleteToon, avId)).start() def callDeleteToon(self, avId): self.avChooser.avChooseFSM.request("waitForToonDelResponse", [avId]) def setTitle(self, title): if self.title: self.title.destroy() self.title = None self.title = DirectLabel(text=title, text_font=self.m, text_fg=(1, 0.9, 0.1, 1), relief=None, text_scale=0.13, pos=(0, 0, 0.82)) def resetMenu(self, task): self.removeGui() self.createGui() return task.done def fadeMenu(self, direction, slot): base.transitions.fadeOut(0.5) self.slot = slot if direction == "mat": notify.info("Toon selected for creation on slot %s" % (self.slot)) taskMgr.doMethodLater(0.51, self.enterMAT, "enterMAT") elif direction == "playGame": notify.info("Playing game as Toon on slot %s" % (self.slot)) taskMgr.doMethodLater(0.51, self.playGame, "playGame") def enterMAT(self, task): messenger.send("enterMakeAToon") return task.done def handleMATUnavailable(self): base.transitions.fadeIn(0) self.matNAMsg = GlobalDialog(message=CIGlobals.MatNAMsg, doneEvent="matNAEvent", style=1) self.acceptOnce("matNAEvent", self.removeMatNAMsg) def removeMatNAMsg(self, value): self.matNAMsg.destroy() if value: random_gender = random.randint(0, 1) if random_gender == 0: gender = "boy" elif random_gender == 1: gender = "girl" MAT = MakeAToon(self.slot, self.cr) MAT.toonGen.generateToon(gender, 1) MAT.exit("finished") return self.createGui(1) def playGame(self, task): self.removeGui() messenger.send("avChooseDone", [self.avChooser.getAvChoiceBySlot(self.slot)]) def removeGui(self): self.bg.removeNode() self.bg_img.destroy() self.quit_btn.destroy() self.title.destroy() for toon in range(len(self.headList) - 1): self.headList[toon].delete() for button in range(6): self.btnList[button].removeNode() base.setBackgroundColor(CIGlobals.DefaultBackgroundColor) base.transitions.fadeIn(0)