Пример #1
0
class ProgressBar(object):
    '''        
    '''
    def __init__(self):
        '''        
        '''
        self.__wait_bar = DirectWaitBar( text = "Carregando...",
                                         value = 0,
                                         pos = (0, 0, -.95),
                                         text_scale = 0.05,
                                         text_pos = (0, 0.025),
                                         frameSize = (-1.3, 1.3, 0, 0.08) )
        
        self.hide()
        
    def finish(self):
        self.__wait_bar['barColor'] = (0, 1, 0, 1)
        self.__wait_bar.setBarColor()
        self.__wait_bar.finish()
        self.hide()
    
    def hide(self):
        self.__wait_bar.hide()
        
    def show(self):
        self.__wait_bar.show()
        
    def update(self, value):
        
        if value < 25:
            self.__wait_bar['barColor'] = (1, 0, 0, 1)
        elif value > 25 and value < 75:
            self.__wait_bar['barColor'] = (1, 1, 0, 1)
        elif value > 75:
            self.__wait_bar['barColor'] = (0, 1, 0, 1)
            
            
        self.__wait_bar.setBarColor()
        
        self.__wait_bar.update(value)
        
        
Пример #2
0
class DistributedCogBattle(DistributedObject):
    notify = directNotify.newCategory('DistributedCogBattle')
    DNCData = {0: [[(-50, 98.73, 0.4), (351.31, 0.0, 0.0), 1.25],
         [(-41.07, 97.2, 0.4), (350.34, 0.0, 0.0), 1.25],
         [(-152.73, -0.58, 0.4), (90.0, 0, 0), 1.25],
         [(-152.73, 8.81, 0.4), (85.3, 0, 0), 1.25],
         [(34.34, -157.19, 2.95), (150.75, 0, 0), 1.25],
         [(26.21, -152.66, 2.95), (147.09, 0, 0), 1.25]],
     1: [],
     2: [],
     5: []}

    def __init__(self, cr):
        try:
            self.DistributedCogBattle_initialized
            return
        except:
            self.DistributedCogBattle_initialized = 1

        DistributedObject.__init__(self, cr)
        self.hoodIndex = None
        self.totalCogs = None
        self.cogsRemaining = None
        self.cogProgressBar = None
        self.DNCSigns = []
        self.introMessageSeq = None
        self.victorySeq = None
        self.turretManager = None
        return

    def setTurretManager(self, tmgr):
        self.turretManager = tmgr

    def getTurretManager(self):
        return self.turretManager

    def victory(self):
        self.cr.playGame.getPlace().fsm.request('stop')
        base.localAvatar.b_setAnimState('win')
        self.victorySeq = Sequence(Wait(7.0), Func(self.finishVictory))
        self.victorySeq.start()

    def finishVictory(self):
        hoodId = self.cr.playGame.hood.hoodId
        if hoodId == CIGlobals.BattleTTC:
            hoodId = CIGlobals.ToontownCentral
            zoneId = CIGlobals.ToontownCentralId
        else:
            zoneId = CogBattleGlobals.HoodIndex2HoodId[self.getHoodIndex()]
        requestStatus = {'zoneId': zoneId,
         'hoodId': hoodId,
         'where': 'playground',
         'avId': base.localAvatar.doId,
         'loader': 'safeZoneLoader',
         'shardId': None,
         'how': 'teleportIn'}
        self.cr.playGame.getPlace().fsm.request('teleportOut', [requestStatus])
        return

    def setTotalCogs(self, num):
        self.totalCogs = num

    def getTotalCogs(self):
        return self.totalCogs

    def setCogsRemaining(self, num):
        self.cogsRemaining = num
        if self.cogProgressBar:
            self.__updateProgressBar()

    def getCogsRemaining(self):
        return self.cogsRemaining

    def setHoodIndex(self, index):
        self.hoodIndex = index

    def getHoodIndex(self):
        return self.hoodIndex

    def startPlacePoll(self):
        taskMgr.add(self.__placePoll, 'DistributedCogBattle-placePoll')

    def __placePoll(self, task):
        if self.cr.playGame.getPlace() != None:
            self.sendUpdate('arrived', [])
            self.constructArea()
            self.createInterface()
            self.__doIntroMessages()
            return task.done
        else:
            return task.cont
            return

    def stopPlacePoll(self):
        taskMgr.remove('DistributedCogBattle-placePoll')

    def createInterface(self):
        self.cogProgressBar = DirectWaitBar(pos=(0, 0, -0.9), relief=DGG.RAISED, scale=0.6, frameColor=(1, 0.5, 0.3, 0.75), barColor=(1, 0.25, 0.25, 0.5), value=0, range=self.getTotalCogs(), text='', text_scale=0.08)
        self.__updateProgressBar()

    def __updateProgressBar(self):
        self.cogProgressBar.update(self.getCogsRemaining())
        self.cogProgressBar['text'] = '{0}/{1} {2} Remaining'.format(self.getCogsRemaining(), self.getTotalCogs(), CIGlobals.Suits)

    def destroyInterface(self):
        if self.cogProgressBar:
            self.cogProgressBar.destroy()
            self.cogProgressBar = None
        return

    def createBossGui(self):
        self.destroyInterface()
        backgroundGui = loader.loadModel('phase_5/models/cogdominium/tt_m_gui_csa_flyThru.bam')
        backgroundGui.find('**/chatBubble').removeNode()
        bg = backgroundGui.find('**/background')
        bg.setScale(5.2)
        bg.setPos(0.14, 0, -0.6667)
        bg.reparentTo(aspect2d)
        self.frame = DirectFrame(geom=bg, relief=None, pos=(0.2, 0, -0.6667))
        return

    def constructArea(self):
        for data in self.DNCData[self.hoodIndex]:
            dnc = loader.loadModel('phase_3.5/models/props/do_not_cross.egg')
            dnc.setPos(*data[0])
            dnc.setHpr(*data[1])
            dnc.setScale(data[2])
            dnc.reparentTo(render)
            self.DNCSigns.append(dnc)

    def deconstructArea(self):
        for dnc in self.DNCSigns:
            dnc.removeNode()

    def createWhisper(self, msg):
        whisper = Whisper()
        whisper.createSystemMessage(msg)

    def __doIntroMessages(self):
        self.introMessageSeq = Sequence(name='DistributedCogBattle-introMessageSeq')
        self.introMessageSeq.append(Func(self.createWhisper, 'Welcome, Toons! The Cogs will be here soon, so get prepared!'))
        self.introMessageSeq.append(Wait(7.5))
        self.introMessageSeq.append(Func(self.createWhisper, 'The pink bar at the bottom of the screen shows the amount of Cogs remaining to defeat.'))
        self.introMessageSeq.append(Wait(8.5))
        self.introMessageSeq.append(Func(self.createWhisper, 'Purchase gags from Goofy at the Gag Shop to restock your used gags.'))
        self.introMessageSeq.append(Wait(7.5))
        self.introMessageSeq.append(Func(self.createWhisper, "Purchase battle tools from Coach at Coach's Battle Shop in between invasions."))
        self.introMessageSeq.setDoneEvent(self.introMessageSeq.getName())
        self.acceptOnce(self.introMessageSeq.getDoneEvent(), self.__introMessagesDone)
        self.introMessageSeq.start()

    def __introMessagesDone(self):
        if self.introMessageSeq:
            self.introMessageSeq.finish()
            self.introMessageSeq = None
        return

    def announceGenerate(self):
        DistributedObject.announceGenerate(self)
        base.localAvatar.setMyBattle(self)
        self.startPlacePoll()

    def disable(self):
        self.turretManager = None
        base.localAvatar.setMyBattle(None)
        self.stopPlacePoll()
        self.deconstructArea()
        self.destroyInterface()
        if self.victorySeq:
            self.victorySeq.pause()
            self.victorySeq = None
        self.hoodIndex = None
        self.DNCSigns = None
        self.totalCogs = None
        self.cogsRemaining = None
        if self.introMessageSeq:
            self.introMessageSeq.pause()
            self.introMessageSeq = None
        DistributedObject.disable(self)
        return
class ExperimentChallengeGUI(NodePath):
    def __init__(self, description, needed, icon):
        NodePath.__init__(self, 'objective-%s' % id(self))

        self.needed = needed
        self.visible = False

        self.fadeInTrack = None
        self.fadeOutTrack = None

        gui = loader.loadModel('phase_5/models/cogdominium/tt_m_gui_csa_flyThru')
        self.background = gui.find('**/*background').copyTo(self)
        self.background.setScale(2.5)
        gui.removeNode()

        self.icon = icon.copyTo(self.background)
        self.icon.setScale(0.08)
        self.icon.setPos(-0.167, 0, -0.002)

        text = TextNode('challenge')
        text.setText('Challenge')
        text.setFont(ToontownGlobals.getSignFont())
        text.setTextColor(0.95, 0.95, 0, 1)
        self.objText = self.background.attachNewNode(text)
        self.objText.setScale(0.03)
        self.objText.setPos(-0.04, 0.0, 0.02)

        text = TextNode('description')
        text.setText(description)
        text.setFont(ToontownGlobals.getSignFont())
        text.setTextColor(0.95, 0.95, 0, 1)
        text.setAlign(TextNode.ACenter)
        self.objText = self.background.attachNewNode(text)
        self.objText.setScale(0.015)
        self.objText.setPos(0.048, 0.0, -0.009)

        self.progressBar = DirectWaitBar(guiId='ChallengeProgressBar', parent=self.background, frameSize=(-0.11, 0.11, -0.007, 0.007), pos=(0.048, 0, -0.0338), text='')
        self.progressBar['range'] = needed

        self.progressText = DirectLabel(guiId='ChallengeProgressText', parent=self.progressBar, relief=None, pos=(0, 0, -0.0048), text='', textMayChange=1, text_scale=0.014, text_fg=(0.03, 0.83, 0, 1), text_align=TextNode.ACenter, text_font=ToontownGlobals.getSignFont())

        self.updateProgress(0)

        self.reparentTo(base.a2dBottomLeft)
        self.stash()

    def updateProgress(self, count):
        self.progressBar.update(count)
        self.progressText['text'] = '%s/%s' % (count, self.needed)

    def fadeIn(self):
        if self.fadeOutTrack:
            self.fadeOutTrack.finish()
            self.fadeOutTrack = None

        self.visible = True
        self.fadeInTrack = Sequence(Func(self.unstash),
                 Func(self.setTransparency, 1),
                 LerpColorScaleInterval(self, 1, Vec4(1, 1, 1, 1), startColorScale=Vec4(1, 1, 1, 0)),
                 Func(self.clearColorScale),
                 Func(self.clearTransparency))
        self.fadeInTrack.start()

    def fadeOut(self):
        if self.fadeInTrack:
            self.fadeInTrack.finish()
            self.fadeInTrack = None

        self.visible = False
        self.fadeOutTrack = Sequence(Func(self.setTransparency, 1),
                 LerpColorScaleInterval(self, 1, Vec4(1, 1, 1, 0), startColorScale=Vec4(1, 1, 1, 1)),
                 Func(self.clearColorScale),
                 Func(self.clearTransparency),
                 Func(self.stash))
        self.fadeOutTrack.start()

    def fadeOutDestroy(self):
        self.visible = False
        Sequence(Func(self.setTransparency, 1),
                 LerpColorScaleInterval(self, 1, Vec4(1, 1, 1, 0), startColorScale=Vec4(1, 1, 1, 1)),
                 Func(self.clearColorScale),
                 Func(self.clearTransparency),
                 Func(self.stash),
                 Func(self.destroy)).start()

    def destroy(self):
        self.removeNode()
class DistributedBRPond(DistributedObject):
    notify = directNotify.newCategory('DistributedBRPond')
    LowerPowerBarTaskName = 'BRWater-lowerPowerBar'
    WatchMouseMovementTaskName = 'BRWater-watchMouseMovement'
    WaterWatchTaskName = 'BRWater-waterWatch'
    InWaterZ = 0.93
    PowerLoss = 1

    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        self.freezeUpSfx = base.audio3d.loadSfx(
            'phase_8/audio/sfx/freeze_up.ogg')
        self.freezeUpSfx.setVolume(12)

        self.frozenSfxArray = [
            base.audio3d.loadSfx('phase_8/audio/sfx/frozen_1.ogg'),
            base.audio3d.loadSfx('phase_8/audio/sfx/frozen_2.ogg'),
            base.audio3d.loadSfx('phase_8/audio/sfx/frozen_3.ogg')
        ]
        self.coolSfxArray = [
            base.audio3d.loadSfx('phase_8/audio/sfx/cool_down_1.ogg'),
            base.audio3d.loadSfx('phase_8/audio/sfx/cool_down_2.ogg')
        ]

        # Fancy code that will iterate through both lists and set their volume to 12.
        for sfx in itertools.chain(self.frozenSfxArray, self.coolSfxArray):
            sfx.setVolume(12)

        # A dictionary of avIds that point to a list of useful data.
        # Example: 0 : [iceCubeNode, interval]
        self.avId2Data = {}

        # Variables that store values for local stuff such as the GUI and the lastMouseX.
        self.frame = None
        self.powerBar = None
        self.label = None
        self.lastMouseX = 0

    def attachSoundToAvatar(self, avatar, sound):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        base.audio3d.attachSoundToObject(sound, avatar)
        base.playSfx(sound, node=avatar)

    def __resetAvatarIvalAndUnloadIceCube(self, avatar):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly 
            This deletes the ice cube node, pauses the current interval, and deletes the data. """
        iceCube, ival = self.__fetchAvatarIntervalAndIceCube(avatar)

        if iceCube:
            iceCube.removeNode()
            iceCube = None

        if ival:
            ival.pause()
            ival = None

        if avatar.doId in self.avId2Data.keys():
            del self.avId2Data[avatar.doId]

    def __setAvatarIntervalAndIceCube(self, avatar, iceCube, ival, ts):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly 
            NOTE: This starts the interval if one is passed! """
        if ival: ival.start(ts)
        self.avId2Data.update({avatar.doId: [iceCube, ival]})

    def __fetchAvatarIntervalAndIceCube(self, avatar):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly 
            This returns the ice cube node and the current interval """

        # Let's default both of the data to None.
        data = [None, None]
        if avatar.doId in self.avId2Data.keys():
            data = self.avId2Data.get(avatar.doId)
        return data[0], data[1]

    def processStateRequest(self, avId, stateId, lastStateId, timestamp):
        """ This is the processing part of the state system that mimics the FSM system """
        avatar = base.cr.doId2do.get(avId, None)
        elapsedTime = globalClockDelta.localElapsedTime(timestamp)

        if not avatar:
            self.notify.warning(
                'SUSPICIOUS! Attempted to change the state of a non-existent avatar!'
            )
            return

        # Let's exit out of the previous state.
        if lastStateId == 0:
            self.exitFreezeUp(avatar)
        elif lastStateId == 1:
            self.exitFrozen(avatar)

        if stateId == 0:
            self.enterFreezeUp(avatar, elapsedTime)
        elif stateId == 1:
            self.enterFrozen(avatar, elapsedTime)
        elif stateId == 2:
            self.enterCooldown(avatar, elapsedTime)
        elif stateId == 3:
            self.enterCooldown(avatar, elapsedTime, fromFrozen=1)
        elif stateId == 4:
            self.handleCooldownFinish(avatar)
        elif stateId == 5:
            # The AI is just clearing the state of the specified avatar.
            self.__resetAvatarIvalAndUnloadIceCube(avatar)
        else:
            self.notify.warning(
                'Attempted to set state with unknown state id: {0}.'.format(
                    stateId))

    def d_requestState(self, stateId):
        """ This is the requesting part of the state system that mimics the FSM system """
        self.sendUpdate('requestState', [stateId])

    def enterFreezeUp(self, avatar, ts):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        def shouldFreeze():
            if avatar == base.localAvatar:
                self.d_requestState(1)

        length = 1.0
        ival = Sequence(Func(self.attachSoundToAvatar, avatar,
                             self.freezeUpSfx),
                        ToonEffects.getToonFreezeInterval(avatar,
                                                          duration=length),
                        Func(shouldFreeze),
                        name='FreezeUp')

        if avatar == base.localAvatar:
            self.__startWaterWatch(0)
        self.__setAvatarIntervalAndIceCube(avatar, None, ival, ts)

    def exitFreezeUp(self, avatar):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        self.__resetAvatarIvalAndUnloadIceCube(avatar)
        if avatar == base.localAvatar: self.__stopWaterWatch()

    def enterFrozen(self, avatar, ts):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        iceCube = ToonEffects.generateIceCube(avatar)

        if avatar == base.localAvatar:
            base.cr.playGame.getPlace().fsm.request('stop', [0])
            base.localAvatar.stop()

            # We need to hide the mouse cursor.
            props = WindowProperties()
            props.setCursorHidden(True)
            base.win.requestProperties(props)

            # Let's setup our GUI elements.
            self.frame = DirectFrame(pos=(0.0, 0.0, 0.7))
            self.powerBar = DirectWaitBar(frameColor=(1.0, 1.0, 1.0, 1.0),
                                          range=100,
                                          value=0,
                                          scale=(0.4, 0.5, 0.25),
                                          parent=self.frame,
                                          barColor=(0.55, 0.7, 1.0, 1.0))
            self.label = OnscreenText(text='SHAKE MOUSE',
                                      shadow=(0.0, 0.0, 0.0, 1.0),
                                      fg=(0.55, 0.7, 1.0, 1.0),
                                      pos=(0.0, -0.1, 0.0),
                                      parent=self.frame)

            # Let's add our tasks
            taskMgr.add(self.__lowerPowerBar, self.LowerPowerBarTaskName)
            taskMgr.add(self.__watchMouseMovement,
                        self.WatchMouseMovementTaskName)

            mw = base.mouseWatcherNode
            if mw.hasMouse():
                self.lastMouseX = mw.getMouseX()
        else:
            avatar.stop()

        ival = Sequence(
            Func(self.attachSoundToAvatar, avatar,
                 choice(self.frozenSfxArray)),
            ToonEffects.getIceCubeFormInterval(iceCube))

        self.__setAvatarIntervalAndIceCube(avatar, iceCube, ival, ts)

    def exitFrozen(self, avatar):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        self.__resetAvatarIvalAndUnloadIceCube(avatar)
        if avatar == base.localAvatar:
            # Let's make our cursor visible again.
            props = WindowProperties()
            props.setCursorHidden(False)
            base.win.requestProperties(props)

            # Let's remove our tasks
            taskMgr.remove(self.LowerPowerBarTaskName)
            taskMgr.remove(self.WatchMouseMovementTaskName)

            # Let's destroy all of our UI elements.
            if self.frame:
                self.label.destroy()
                self.label = None
                self.powerBar.destroy()
                self.powerBar = None
                self.frame.destroy()
                self.frame = None
            self.lastMouseX = 0

            base.cr.playGame.getPlace().fsm.request('walk')
            base.localAvatar.b_setAnimState('neutral')
        else:
            avatar.loop('neutral')

    def enterCooldown(self, avatar, ts, fromFrozen=0):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        ival = Parallel()
        iceCube = None

        def handleComplete():
            if avatar == base.localAvatar:
                self.d_requestState(4)

        if fromFrozen:
            iceCube = ToonEffects.generateIceCube(avatar)
            iceCube.setColorScale(ToonEffects.ICE_CUBE_SOLID_COLOR)
            ival.append(ToonEffects.getIceCubeThawInterval(iceCube))

        # Let's do the color scale interval on the avatar.
        ival.append(
            Sequence(
                Func(self.attachSoundToAvatar, avatar,
                     choice(self.coolSfxArray)),
                ToonEffects.getToonThawInterval(avatar, duration=1.0),
                Wait(4.0), Func(handleComplete)))

        self.__setAvatarIntervalAndIceCube(avatar, iceCube, ival, ts)

    def handleCooldownFinish(self, avatar):
        """ This is expecting a valid avatar object, either fetched from base.cr.doId2do#get() or passed directly """
        self.__resetAvatarIvalAndUnloadIceCube(avatar)

        if avatar == base.localAvatar:
            self.__startWaterWatch()

    def __lowerPowerBar(self, task):
        if self.powerBar['value'] <= 0:
            self.powerBar.update(0)
        self.powerBar.update(
            int(self.powerBar['value'] -
                (self.PowerLoss * globalClock.getDt())))
        return task.cont

    def __watchMouseMovement(self, task):
        if self.powerBar['value'] >= self.powerBar['range']:
            self.d_requestState(3)
            return task.done

        mw = base.mouseWatcherNode
        if mw.hasMouse():
            if not self.lastMouseX or self.lastMouseX != mw.getMouseX():
                value = abs(self.lastMouseX - mw.getMouseX()) / 0.001
                self.lastMouseX = mw.getMouseX()
                self.powerBar.update(self.powerBar['value'] + abs(value))
        return task.cont

    def __startWaterWatch(self, enter=1):
        taskMgr.add(self.__waterWatch,
                    self.WaterWatchTaskName,
                    extraArgs=[enter],
                    appendTask=True)

    def __stopWaterWatch(self):
        taskMgr.remove(self.WaterWatchTaskName)

    def __waterWatch(self, enter, task):
        """ This task is ran locally to control when to switch to certain states """
        z = base.localAvatar.getZ(render)
        if enter and z <= self.InWaterZ:
            self.d_requestState(0)
            return task.done
        elif not enter and z > self.InWaterZ:
            _, ival = self.__fetchAvatarIntervalAndIceCube(base.localAvatar)
            if ival and ival.getName() is 'FreezeUp':
                self.d_requestState(2)
                return task.done
        return task.cont

    def announceGenerate(self):
        DistributedObject.announceGenerate(self)
        self.__startWaterWatch()
        self.sendUpdate('requestAvatarStates', [])

    def disable(self):
        taskMgr.remove(self.LowerPowerBarTaskName)
        taskMgr.remove(self.WatchMouseMovementTaskName)
        self.__stopWaterWatch()
        DistributedObject.disable(self)

    def delete(self):
        DistributedObject.delete(self)
        self.LowerPowerBarTaskName = None
        self.WatchMouseMovementTaskName = None
        self.WaterWatchTaskName = None
        self.InWaterZ = None
        self.freezeUpSfx = None
        self.frozenSfxArray = None
        self.coolSfxArray = None
        self.avId2Data = None

        if self.frame:
            self.label.destroy()
            self.label = None
            self.powerBar.destroy()
            self.powerBar = None
            self.frame.destroy()
            self.frame = None
        del self.LowerPowerBarTaskName
        del self.WatchMouseMovementTaskName
        del self.WaterWatchTaskName
        del self.InWaterZ
        del self.freezeUpSfx
        del self.frozenSfxArray
        del self.coolSfxArray
        del self.avId2Data
        del self.label
        del self.powerBar
        del self.frame
class CIProgressScreen:

    Color = (118 / 255.0, 121 / 255.0, 127 / 255.0, 1.0)
    BarColor = (152 / 255.0, 129 / 255.0, 64 / 255.0, 1.0)

    def __init__(self):
        self.defaultLogoScale = 1
        self.defaultLogoZ = 0.65
        self.bgm = loader.loadModel(
            "phase_3/models/gui/progress-background.bam")
        self.bgm.find('**/logo').stash()
        self.barShadow = OnscreenImage(image=self.bgm.find("**/bar_shadow"),
                                       parent=hidden)
        self.bgm.find("**/bar_shadow").removeNode()
        self.bg = self.bgm.find('**/bg')
        self.defaultBgTexture = self.bg.findTexture('*')

        self.logoNode, self.logoImg = CIGlobals.getLogoImage(
            hidden, self.defaultLogoScale, (0, 0, self.defaultLogoZ))

        self.bg_img = OnscreenImage(image=self.bg, parent=hidden)
        self.bg_img.setSx(1.35)
        self.bg_img.hide()
        self.progress_bar = DirectWaitBar(value=0,
                                          pos=(0, 0, -0.85),
                                          parent=hidden,
                                          text_pos=(0, 0, 0.2))
        self.progress_bar.setSx(1.064)
        self.progress_bar.setSz(0.38)
        toontipgui = loader.loadModel(
            'phase_3.5/models/gui/stickerbook_gui.bam')
        poster = toontipgui.find('**/questCard')
        self.toontipFrame = DirectFrame(image=poster,
                                        image_scale=(1.4, 1, 1),
                                        parent=hidden,
                                        relief=None,
                                        pos=(0, 0, -0.1),
                                        scale=0.85)
        self.toontipLbl = OnscreenText(text="",
                                       parent=self.toontipFrame,
                                       fg=(89.0 / 255, 95.0 / 255, 98.0 / 255,
                                           1),
                                       font=CIGlobals.getToonFont(),
                                       wordwrap=13,
                                       pos=(-0.59, 0.25),
                                       align=TextNode.ALeft,
                                       scale=0.08)
        self.loading_lbl = DirectLabel(text="",
                                       relief=None,
                                       scale=0.08,
                                       pos=(-1.0725, 0, -0.79),
                                       text_align=TextNode.ALeft,
                                       sortOrder=100,
                                       text_fg=(1, 1, 1, 1),
                                       text_font=CIGlobals.getMinnieLogoFont(),
                                       parent=hidden,
                                       text_shadow=(0, 0, 0, 0))

        # This is useful when the user has chosen to hide aspect2d before the loading screen.
        # However, we want to show the loading screen all the time, so we need to restore the
        # previous state after the loading screen ends.
        self.mustRestoreHiddenAspect2d = False

    def begin(self, hood, range, wantGui):
        render.hide()
        NametagGlobals.setWant2dNametags(False)

        if base.aspect2d.isHidden():
            base.aspect2d.show()
            self.mustRestoreHiddenAspect2d = True

        self.renderFrames()
        base.setBackgroundColor(0, 0, 0)
        if hood == "localAvatarEnterGame":
            self.loading_lbl['text'] = "Entering..."
        elif hood == "init":
            self.loading_lbl['text'] = "Loading..."
        else:
            self.loading_lbl['text'] = "Heading to %s..." % hood
        self.progress_bar['barColor'] = self.BarColor
        self.progress_bar['range'] = range
        self.bgm.reparentTo(aspect2d)

        ZoneUtil.Hood2ZoneId.keys()

        # We only want to show special loading screens for actual in-game locations.
        if hood in ZoneUtil.Hood2ZoneId.keys():
            abbr = ZoneUtil.ZoneId2HoodAbbr.get(
                ZoneUtil.Hood2ZoneId.get(hood)).lower()
            bgTexture = loader.loadTexture(
                'phase_14/maps/{0}_loading.png'.format(abbr), okMissing=True)

            if bgTexture:
                self.bg.setTexture(bgTexture, 1)

        self.barShadow.reparentTo(aspect2d)
        self.bg.reparentTo(render2d)
        self.bg_img.reparentTo(hidden)
        self.loading_lbl.reparentTo(aspect2d)
        self.logoNode.reparentTo(aspect2d)
        self.progress_bar.reparentTo(aspect2d)
        tip = random.choice(CIGlobals.ToonTips)
        self.toontipLbl.setText("TOON TIP:\n" + tip)
        self.toontipFrame.reparentTo(aspect2d)
        self.__count = 0
        self.__expectedCount = range
        self.progress_bar.update(self.__count)

    def renderFramesTask(self, task):
        self.renderFrames()
        return task.cont

    def end(self):
        base.setBackgroundColor(CIGlobals.DefaultBackgroundColor)
        taskMgr.remove("renderFrames")
        render.show()

        if self.mustRestoreHiddenAspect2d:
            base.aspect2d.hide()
            self.mustRestoreHiddenAspect2d = False

        self.progress_bar.finish()
        self.bg_img.reparentTo(hidden)
        self.logoNode.reparentTo(hidden)
        self.barShadow.reparentTo(hidden)
        self.bg.reparentTo(hidden)

        # Let's get rid of the extra texture stage.
        self.bg.setTexture(self.defaultBgTexture, 1)

        self.bgm.reparentTo(hidden)
        self.loading_lbl.reparentTo(hidden)
        self.progress_bar.reparentTo(hidden)
        self.toontipFrame.reparentTo(hidden)
        base.transitions.fadeScreen(1.0)
        NametagGlobals.setWant2dNametags(True)
        self.renderFrames()

    def destroy(self):
        self.bg.removeNode()
        del self.bg
        self.bgm.removeNode()
        del self.bgm
        self.bg_img.destroy()
        self.barShadow.destroy()
        del self.barShadow
        self.loading_lbl.destroy()
        self.progress_bar.destroy()
        self.bgm.destroy()
        self.mustRestoreHiddenAspect2d = False
        del self.bg_img
        del self.loading_lbl
        del self.progress_bar
        del self.bgm
        del self.defaultBgTexture
        del self.mustRestoreHiddenAspect2d

    def renderFrames(self):
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()

    def tick(self):
        self.__count += 1
        self.progress_bar.update(self.__count)
class BRWater:
    notify = directNotify.newCategory("BRWater")

    def __init__(self, playground):
        self.playground = playground
        self.fsm = ClassicFSM('BRWater', [
            State('off', self.enterOff, self.exitOff),
            State('freezeUp', self.enterFreezeUp, self.exitFreezeUp),
            State('coolDown', self.enterCoolDown, self.exitCoolDown),
            State('frozen', self.enterFrozen, self.exitFrozen)
        ], 'off', 'off')
        self.fsm.enterInitialState()

        #base.localAvatar.audio3d

        self.freezeUpSfx = base.loadSfx('phase_8/audio/sfx/freeze_up.ogg')
        self.frozenSfxArray = [
            base.loadSfx('phase_8/audio/sfx/frozen_1.ogg'),
            base.loadSfx('phase_8/audio/sfx/frozen_2.ogg'),
            base.loadSfx('phase_8/audio/sfx/frozen_3.ogg')
        ]
        self.coolSfxArray = [
            base.loadSfx('phase_8/audio/sfx/cool_down_1.ogg'),
            base.loadSfx('phase_8/audio/sfx/cool_down_2.ogg')
        ]

        self.iceFormSfx = base.loadSfx("phase_4/audio/sfx/ice_cube_form.ogg")
        self.iceBreakSfx = base.loadSfx("phase_4/audio/sfx/ice_cube_break.ogg")

        self.freezeUpSfx.setVolume(12)
        for sfx in self.frozenSfxArray:
            sfx.setVolume(12)
        for sfx in self.coolSfxArray:
            sfx.setVolume(12)
        #for sfx in self.frozenSfxArray:
        #    self.attachSound(sfx)
        #for sfx in self.coolSfxArray:
        #    self.attachSound(sfx)
        #self.attachSound(self.freezeUpSfx)

    def attachSound(self, sound):
        base.localAvatar.audio3d.attachSoundToObject(sound, base.localAvatar)

    def enterOff(self):
        self.playground.startWaterWatch()

    def exitOff(self):
        self.playground.stopWaterWatch()

    def loadIceCube(self):
        self.iceCube = loader.loadModel('phase_8/models/props/icecube.bam')
        for node in self.iceCube.findAllMatches('**/billboard*'):
            node.removeNode()
        for node in self.iceCube.findAllMatches('**/drop_shadow*'):
            node.removeNode()
        for node in self.iceCube.findAllMatches('**/prop_mailboxcollisions*'):
            node.removeNode()
        self.iceCube.reparentTo(base.localAvatar)
        self.iceCube.setScale(1.2, 1.0, base.localAvatar.getHeight() / 1.7)
        self.iceCube.setTransparency(1)
        self.iceCube.setColorScale(0.76, 0.76, 1.0, 0.0)

    def unloadIceCube(self):
        self.iceCube.removeNode()
        del self.iceCube

    def enterFreezeUp(self):
        length = 1.0
        base.playSfx(self.freezeUpSfx)
        self.fucsIval = Sequence(
            LerpColorScaleInterval(
                base.localAvatar.getGeomNode(),
                duration=length,
                colorScale=VBase4(0.5, 0.5, 1.0, 1.0),
                startColorScale=base.localAvatar.getGeomNode().getColorScale(),
                blendType='easeOut'), Func(self.fsm.request, 'frozen'))
        self.fucsIval.start()
        self.playground.startWaterWatch(0)

    def exitFreezeUp(self):
        self.fucsIval.pause()
        del self.fucsIval
        self.playground.stopWaterWatch()

    def enterFrozen(self):
        self.loadIceCube()
        base.playSfx(self.iceFormSfx)
        base.cr.playGame.getPlace().fsm.request('stop', [0])
        base.localAvatar.stop()
        base.playSfx(choice(self.frozenSfxArray))
        self.iccsIval = LerpColorScaleInterval(
            self.iceCube,
            duration=0.5,
            colorScale=VBase4(0.76, 0.76, 1.0, 1.0),
            startColorScale=self.iceCube.getColorScale(),
            blendType='easeInOut')
        self.iccsIval.start()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)
        self.frame = DirectFrame(pos=(0, 0, 0.7))
        self.powerBar = DirectWaitBar(frameColor=(1, 1, 1, 1),
                                      range=100,
                                      value=0,
                                      scale=(0.4, 0.5, 0.25),
                                      parent=self.frame,
                                      barColor=(0.55, 0.7, 1.0, 1.0))
        self.label = OnscreenText(text="SHAKE MOUSE",
                                  shadow=(0, 0, 0, 1),
                                  fg=(0.55, 0.7, 1.0, 1.0),
                                  pos=(0, -0.1, 0),
                                  parent=self.frame)
        taskMgr.add(self.__watchMouseMovement, 'BRWater-watchMouseMovement')
        taskMgr.add(self.__lowerPowerBar, 'BRWater-lowerPowerBar')
        mw = base.mouseWatcherNode
        if mw.hasMouse():
            self.lastMouseX = mw.getMouseX()

    def __lowerPowerBar(self, task):
        if self.powerBar['value'] <= 0:
            self.powerBar.update(0)
        decrement = 1
        self.powerBar.update(self.powerBar['value'] - decrement)
        task.delayTime = 0.1
        return task.again

    def __watchMouseMovement(self, task):
        if self.powerBar['value'] >= self.powerBar['range']:
            self.fsm.request('coolDown', [1])
            return task.done
        mw = base.mouseWatcherNode
        if mw.hasMouse():
            if not self.lastMouseX or self.lastMouseX != mw.getMouseX():
                value = (abs(self.lastMouseX - mw.getMouseX()) *
                         globalClock.getDt()) / 0.001
                self.lastMouseX = mw.getMouseX()
                self.powerBar.update(self.powerBar['value'] + abs(value))
        return task.cont

    def exitFrozen(self):
        props = WindowProperties()
        props.setCursorHidden(False)
        base.win.requestProperties(props)
        self.iccsIval.pause()
        del self.iccsIval
        self.unloadIceCube()
        taskMgr.remove('BRWater-lowerPowerBar')
        taskMgr.remove('BRWater-watchMouseMovement')
        self.label.destroy()
        del self.label
        self.powerBar.destroy()
        del self.powerBar
        self.frame.destroy()
        del self.frame
        del self.lastMouseX
        base.cr.playGame.getPlace().fsm.request('walk')
        base.localAvatar.b_setAnimState('neutral')

    def enterCoolDown(self, fromFrozen=0):
        if fromFrozen:
            self.loadIceCube()
            base.playSfx(self.iceBreakSfx)
            self.iceCube.setColorScale(0.76, 0.76, 1.0, 1.0)
            self.iccdIval = LerpColorScaleInterval(
                self.iceCube,
                duration=0.5,
                colorScale=VBase4(0.76, 0.76, 1.0, 0.0),
                startColorScale=self.iceCube.getColorScale(),
                blendType='easeInOut')
            self.iccdIval.start()
        length = 1.0
        base.playSfx(choice(self.coolSfxArray))
        self.cdcsIval = Sequence(
            LerpColorScaleInterval(
                base.localAvatar.getGeomNode(),
                duration=length,
                colorScale=VBase4(1.0, 1.0, 1.0, 1.0),
                startColorScale=base.localAvatar.getGeomNode().getColorScale(),
                blendType='easeOut'), Func(self.fsm.request, 'off'))
        self.cdcsIval.start()

    def exitCoolDown(self):
        if hasattr(self, 'iccdIval'):
            self.iccdIval.pause()
            del self.iccdIval
            self.unloadIceCube()
        self.cdcsIval.pause()
        del self.cdcsIval

    def cleanup(self):
        self.fsm.requestFinalState()
        self.playground.stopWaterWatch()
        del self.fsm
        del self.freezeUpSfx
        del self.frozenSfxArray
        del self.coolSfxArray
        del self.playground
Пример #7
0
class CIProgressScreen:

    def __init__(self):
        self.bgm = loader.loadModel('phase_3/models/gui/progress-background.bam')
        self.bgm.find('**/logo').stash()
        self.bg = self.bgm.find('**/bg')
        self.logo = loader.loadTexture('phase_3/maps/CogInvasion_Logo.png')
        self.logoImg = OnscreenImage(image=self.logo, scale=(0.5, 0, 0.3), pos=(0, 0, 0), parent=hidden)
        self.logoImg.setTransparency(True)
        self.bg_img = OnscreenImage(image=self.bg, parent=hidden)
        self.bg_img.setSx(1.35)
        self.bg_img.hide()
        self.progress_bar = DirectWaitBar(value=0, pos=(0, 0, -0.85), parent=hidden, text_pos=(0, 0, 0.2))
        self.progress_bar.setSx(1.064)
        self.progress_bar.setSz(0.38)
        self.loading_lbl = DirectLabel(text='', relief=None, scale=0.08, pos=(-1.0725, 0, -0.79), text_align=TextNode.ALeft, sortOrder=100, text_fg=(0.343, 0.343, 0.343, 1.0), text_font=CIGlobals.getMinnieFont(), parent=hidden, text_shadow=(0, 0, 0, 1))
        return

    def begin(self, hood, range, wantGui):
        render.hide()
        self.renderFrames()
        base.setBackgroundColor(0, 0, 0)
        if hood == 'localAvatarEnterGame':
            self.loading_lbl['text'] = 'Entering...'
        elif hood == 'init':
            self.loading_lbl['text'] = 'Loading...'
        else:
            self.loading_lbl['text'] = 'Heading to %s...' % hood
        self.progress_bar['barColor'] = (0.343, 0.343, 0.343, 1.0)
        self.progress_bar['range'] = range
        self.bgm.reparentTo(aspect2d)
        self.bg.reparentTo(render2d)
        self.bg_img.reparentTo(hidden)
        self.loading_lbl.reparentTo(aspect2d)
        self.logoImg.reparentTo(aspect2d)
        self.progress_bar.reparentTo(aspect2d)
        self.__count = 0
        self.__expectedCount = range
        self.progress_bar.update(self.__count)

    def renderFramesTask(self, task):
        self.renderFrames()
        return task.cont

    def end(self):
        base.setBackgroundColor(CIGlobals.DefaultBackgroundColor)
        taskMgr.remove('renderFrames')
        render.show()
        self.progress_bar.finish()
        self.bg_img.reparentTo(hidden)
        self.logoImg.reparentTo(hidden)
        self.bg.reparentTo(hidden)
        self.bgm.reparentTo(hidden)
        self.loading_lbl.reparentTo(hidden)
        self.progress_bar.reparentTo(hidden)
        self.renderFrames()

    def destroy(self):
        self.bg.removeNode()
        del self.bg
        self.bgm.removeNode()
        del self.bgm
        self.bg_img.destroy()
        self.loading_lbl.destroy()
        self.progress_bar.destroy()
        self.bgm.destroy()
        del self.bg_img
        del self.loading_lbl
        del self.progress_bar
        del self.bgm

    def renderFrames(self):
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()

    def tick(self):
        self.__count += 1
        self.progress_bar.update(self.__count)
Пример #8
0
class CIProgressScreen:

    def __init__(self):
        self.defaultLogoScale = 0.85
        self.defaultLogoZ = 0.65
        self.bgm = loader.loadModel('phase_3/models/gui/progress-background.bam')
        self.bgm.find('**/logo').stash()
        self.bg = self.bgm.find('**/bg')
        self.logo = loader.loadTexture('phase_3/maps/CogInvasion_Logo.png')
        self.logoNode = hidden.attachNewNode('logoNode')
        self.logoNode.setScale(self.defaultLogoScale)
        self.logoNode.setPos(0, self.defaultLogoZ, 0)
        self.logoImg = OnscreenImage(image=self.logo, scale=(0.685, 0, 0.3), parent=self.logoNode)
        self.logoImg.setTransparency(True)
        self.bg_img = OnscreenImage(image=self.bg, parent=hidden)
        self.bg_img.setSx(1.35)
        self.bg_img.hide()
        self.progress_bar = DirectWaitBar(value=0, pos=(0, 0, -0.85), parent=hidden, text_pos=(0,
                                                                                               0,
                                                                                               0.2))
        self.progress_bar.setSx(1.064)
        self.progress_bar.setSz(0.38)
        toontipgui = loader.loadModel('phase_3.5/models/gui/stickerbook_gui.bam')
        poster = toontipgui.find('**/questCard')
        self.toontipFrame = DirectFrame(image=poster, image_scale=(1.4, 1, 1), parent=hidden, relief=None, pos=(0,
                                                                                                                0,
                                                                                                                -0.1), scale=0.85)
        self.toontipLbl = OnscreenText(text='', parent=self.toontipFrame, fg=(0.35,
                                                                              0.35,
                                                                              0.35,
                                                                              1), font=CIGlobals.getToonFont(), wordwrap=14.5, pos=(-0.59,
                                                                                                                                    0.25), align=TextNode.ALeft, scale=0.08)
        self.loading_lbl = DirectLabel(text='', relief=None, scale=0.08, pos=(-1.0725,
                                                                              0,
                                                                              -0.79), text_align=TextNode.ALeft, sortOrder=100, text_fg=(0.343,
                                                                                                                                         0.343,
                                                                                                                                         0.343,
                                                                                                                                         1.0), text_font=CIGlobals.getMinnieFont(), parent=hidden, text_shadow=(0,
                                                                                                                                                                                                                0,
                                                                                                                                                                                                                0,
                                                                                                                                                                                                                1))
        return

    def begin(self, hood, range, wantGui):
        render.hide()
        self.renderFrames()
        base.setBackgroundColor(0, 0, 0)
        if hood == 'localAvatarEnterGame':
            self.loading_lbl['text'] = 'Entering...'
        else:
            if hood == 'init':
                self.loading_lbl['text'] = 'Loading...'
            else:
                self.loading_lbl['text'] = 'Heading to %s...' % hood
        self.progress_bar['barColor'] = (0.343, 0.343, 0.343, 1.0)
        self.progress_bar['range'] = range
        self.bgm.reparentTo(aspect2d)
        self.bg.reparentTo(render2d)
        self.bg_img.reparentTo(hidden)
        self.loading_lbl.reparentTo(aspect2d)
        self.logoNode.reparentTo(aspect2d)
        self.progress_bar.reparentTo(aspect2d)
        tip = random.choice(CIGlobals.ToonTips)
        self.toontipLbl.setText('TOON TIP:\n' + tip)
        self.toontipFrame.reparentTo(aspect2d)
        self.__count = 0
        self.__expectedCount = range
        self.progress_bar.update(self.__count)

    def renderFramesTask(self, task):
        self.renderFrames()
        return task.cont

    def end(self):
        base.setBackgroundColor(CIGlobals.DefaultBackgroundColor)
        taskMgr.remove('renderFrames')
        render.show()
        self.progress_bar.finish()
        self.bg_img.reparentTo(hidden)
        self.logoNode.reparentTo(hidden)
        self.bg.reparentTo(hidden)
        self.bgm.reparentTo(hidden)
        self.loading_lbl.reparentTo(hidden)
        self.progress_bar.reparentTo(hidden)
        self.toontipFrame.reparentTo(hidden)
        self.renderFrames()

    def destroy(self):
        self.bg.removeNode()
        del self.bg
        self.bgm.removeNode()
        del self.bgm
        self.bg_img.destroy()
        self.loading_lbl.destroy()
        self.progress_bar.destroy()
        self.bgm.destroy()
        del self.bg_img
        del self.loading_lbl
        del self.progress_bar
        del self.bgm

    def renderFrames(self):
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()

    def tick(self):
        self.__count += 1
        self.progress_bar.update(self.__count)
Пример #9
0
class Enemy(DirectObject):
    def __init__(self, _main):
        self.main = _main
        self.strenght = self.main.enemyStrength
        self.id = id(self)
        self.model = loader.loadModel("Enemy")
        self.model.setP(-90)
        self.model.setH(180)
        self.model.hide()
        cs = CollisionSphere(0, 0, 0, 0.5)
        cnode = CollisionNode('colEnemy' + str(self.id))
        cnode.addSolid(cs)
        self.colNP = self.model.attachNewNode(cnode)
        #self.colNP.show()

        # Game state
        self.health = 100 + (100 * self.strenght)
        self.damageDone = 0.1 + (0.1 * self.strenght)
        self.lastShot = 0.0
        self.attackRate = 10.0


        self.statusHealth = DirectWaitBar(
            text = "",
            value = self.health,
            range = self.health,
            frameSize = (0.12, 0.8, -0.12, 0.0),
            pos = (-0.5, 0, -0.5),
            barColor = (1, 0, 0, 1))
        self.statusHealth.reparentTo(self.model)
        self.statusHealth.setDepthWrite(False)
        self.statusHealth.setBin('fixed', 0)
        self.statusHealth.setBillboardAxis()

    def start(self, startPos, enemyParent):
        self.model.show()
        self.model.reparentTo(enemyParent)
        self.model.setPos(startPos.x,
                          startPos.y,
                          0)
        self.accept("into-" + "colEnemy" + str(self.id), self.hit)
        self.accept("inRange-" + "colEnemy" + str(self.id), self.startAttack)
        self.statusHealth.update(self.health)

    def stop(self):
        self.model.remove_node()
        self.ignore("into-" + "colEnemy" + str(self.id))
        self.ignore("inRange-" + "colEnemy" + str(self.id))

    def hit(self, _dmg):
        if self.health == 0:
            base.messenger.send("killEnemy", [self.id])
        else:
            self.health -= _dmg
            self.statusHealth.update(self.health)

    def makeAi(self):
        # Make some ai character for each
        self.aiChar = AICharacter("Enemy" + str(self.id), self.model, -100, 0.05 + (0.05 * self.strenght), 6 + (1 * self.strenght))
        self.main.AiWorld.addAiChar(self.aiChar)
        self.AIbehaviors = self.aiChar.getAiBehaviors()

        self.AIbehaviors.pursue(self.main.player.model)
        return self.aiChar

    def startAttack(self, _inRange=False):

        if _inRange:
            self.isAttacking = True
            self.simpleAttack()
            #taskMgr.remove("StartAttack")
        #elif _inRange:
        #    pass
        #    taskMgr.add(self.attack, "StartAttack")

    def attack(self, task):
        dt = globalClock.getDt()
        self.lastShot += dt
        if self.lastShot >= self.attackRate:
            self.lastShot -= self.attackRate
            base.messenger.send("doDamageToPlayer", [self.damageDone])
        return task.again

    def simpleAttack(self):
        base.messenger.send("doDamageToPlayer", [self.damageDone])
class DistributedPieTurretManager(DistributedObject):
    notify = directNotify.newCategory('DistributedPieTurretManager')

    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        self.myTurret = None
        self.guiFrame = None
        self.guiLabel = None
        self.guiBar = None
        self.guiBg = None
        self.turretGag = None

    def announceGenerate(self):
        DistributedObject.announceGenerate(self)
        base.taskMgr.add(self.__pollMyBattle, '__pollMyBattle')

    def disable(self):
        base.taskMgr.remove("DPTM.pollTurret")
        base.taskMgr.remove("__pollMyBattle")
        if hasattr(self, 'makeTurretBtn'):
            self.makeTurretBtn.destroy()
            del self.makeTurretBtn
        self.destroyGui()
        self.myTurret = None
        if base.localAvatar.getMyBattle():
            base.localAvatar.getMyBattle().setTurretManager(None)
        DistributedObject.disable(self)

    def clearTurret(self):
        self.turret = None

    def __pollTurret(self, turretId, task):
        turret = self.cr.doId2do.get(turretId)
        if turret != None:
            self.myTurret = turret
            self.myTurret.b_setGag(self.turretGag)
            self.turretGag = None
            self.acceptOnce(turret.getDeathEvent(), self.clearTurret)
            self.makeGui()
            return Task.done
        return Task.cont

    def setGag(self, upgradeId):
        self.turretGag = upgradeId

    def d_requestPlace(self, posHpr):
        self.sendUpdate('requestPlace', [posHpr])

    def turretPlaced(self, turretId):
        base.taskMgr.add(self.__pollTurret,
                         'DPTM.pollTurret',
                         extraArgs=[turretId],
                         appendTask=True)

    def yourTurretIsDead(self):
        base.taskMgr.remove('DPTM.pollTurret')
        self.destroyGui()
        self.myTurret = None
        if base.localAvatar.getPUInventory()[0] > 0:
            self.createTurretButton()

    def makeGui(self):
        self.destroyGui()
        self.guiFrame = DirectFrame(parent=base.a2dBottomRight,
                                    pos=(-0.55, 0, 0.15))
        self.guiBg = OnscreenImage(image="phase_4/maps/turret_gui_bg.png",
                                   scale=(0.15, 0, 0.075),
                                   parent=self.guiFrame)
        self.guiBg.setTransparency(True)
        self.guiLabel = DirectLabel(
            text="Turret",
            text_fg=(1, 0, 0, 1),
            relief=None,
            text_scale=0.05,
            text_font=loader.loadFont("phase_3/models/fonts/ImpressBT.ttf"),
            pos=(0, 0, 0.025),
            parent=self.guiFrame)
        self.guiBar = DirectWaitBar(range=self.myTurret.getMaxHealth(),
                                    value=self.myTurret.getHealth(),
                                    scale=0.125,
                                    parent=self.guiFrame,
                                    pos=(0, 0, -0.01))

    def createTurretButton(self):
        self.makeTurretBtn = DirectButton(relief=None,
                                          geom=CIGlobals.getDefaultBtnGeom(),
                                          text='Turret',
                                          text_scale=0.055,
                                          command=self.handleMakeTurretBtn,
                                          pos=(-0.47, 0, 0.1),
                                          geom_scale=(0.5, 1.0, 1.0),
                                          text_pos=(0, -0.01),
                                          parent=base.a2dBottomRight)

        if base.localAvatar.getPUInventory()[0]:
            self.setGag(base.localAvatar.getPUInventory()[1])

    def handleMakeTurretBtn(self):
        self.makeTurretBtn.destroy()
        del self.makeTurretBtn
        x, y, z = base.localAvatar.getPos()
        h, p, r = base.localAvatar.getHpr()
        self.d_requestPlace([x, y, z, h, p, r])
        base.localAvatar.sendUpdate('usedPU', [0])

    def __pollMyBattle(self, task):
        if base.localAvatar.getMyBattle():
            base.localAvatar.getMyBattle().setTurretManager(self)
            if base.localAvatar.getPUInventory()[0] > 0:
                self.createTurretButton()
            return Task.done
        return Task.cont

    def destroyGui(self):
        if self.guiBar:
            self.guiBar.destroy()
            self.guiBar = None
        if self.guiLabel:
            self.guiLabel.destroy()
            self.guiLabel = None
        if self.guiBg:
            self.guiBg.destroy()
            self.guiBg = None
        if self.guiFrame:
            self.guiFrame.destroy()
            self.guiFrame = None

    def updateTurretGui(self):
        if self.guiBar:
            self.guiBar.update(self.myTurret.getHealth())

    def getTurret(self):
        return self.myTurret
class DistributedCogBattle(DistributedObject):
    notify = directNotify.newCategory("DistributedCogBattle")
    DNCData = {
        0: [[(-50, 98.73, 0.40), (351.31, 0.00, 0.00), 1.25],
            [(-41.07, 97.20, 0.40), (350.34, 0.00, 0.00), 1.25],
            [(-152.73, -0.58, 0.40), (90.00, 0, 0), 1.25],
            [(-152.73, 8.81, 0.40), (85.30, 0, 0), 1.25],
            [(34.34, -157.19, 2.95), (150.75, 0, 0), 1.25],
            [(26.21, -152.66, 2.95), (147.09, 0, 0), 1.25]],
        1: [],
        2: [],
        5: []
    }

    def __init__(self, cr):
        try:
            self.DistributedCogBattle_initialized
            return
        except:
            self.DistributedCogBattle_initialized = 1
        DistributedObject.__init__(self, cr)
        self.hoodIndex = None
        self.totalCogs = None
        self.cogsRemaining = None
        self.cogProgressBar = None
        self.DNCSigns = []
        self.introMessageSeq = None
        self.victorySeq = None
        self.turretManager = None
        self.isGettingBeans = False
        self.getBeansLabel = OnscreenText(
            text="Hurry and pick up all of the jellybeans!",
            fg=(1, 1, 1, 1),
            shadow=(0, 0, 0, 1),
            pos=(0, 0.7),
            font=CIGlobals.getMinnieFont())
        self.getBeansLabel.hide()
        self.timer = Timer()
        self.timer.setZeroCommand(self.getBeansTimeUp)
        # Give toons 30 seconds to get the beans at the end.
        self.timer.setInitialTime(60)
        self.endMusic = base.loadMusic(
            'phase_7/audio/bgm/encntr_toon_winning_indoor.mid')
        self.balloonSound = base.loadSfx(
            'phase_3/audio/sfx/GUI_balloon_popup.ogg')

    def d_left(self):
        self.sendUpdate('iLeft')

    def monitorHP(self, task):
        if base.localAvatar.getHealth() < 1:
            taskMgr.doMethodLater(7.0, self.diedTask,
                                  self.uniqueName('diedTask'))
            return task.done
        return task.cont

    def diedTask(self, task):
        self.d_left()
        return task.done

    def setTurretManager(self, tmgr):
        self.turretManager = tmgr

    def getTurretManager(self):
        return self.turretManager

    def getTurretCount(self):
        avatars = self.cr.doFindAll('DistributedToon')
        turrets = 0

        if self.turretManager:
            if self.turretManager.getTurret():
                turrets += 1

        if base.localAvatar.getPUInventory()[0] > 0:
            turrets += 1

        for avatar in avatars:
            if avatar.zoneId == base.localAvatar.zoneId:
                battle = avatar.getMyBattle()
                if avatar.getPUInventory()[0] > 0:
                    turrets += 1

                if battle:
                    if battle.getTurretManager():
                        if battle.getTurretManager().getTurret():
                            turrets += 1
        return turrets

    def victory(self):
        self.cr.playGame.getPlace().fsm.request('stop')
        base.localAvatar.b_setAnimState('win')
        self.victorySeq = Sequence(Wait(5.0), Func(self.finishVictory))
        self.victorySeq.start()

    def finishVictory(self):
        # Give the players some time to pick up jellybeans before they leave.
        self.cr.playGame.getPlace().fsm.request('walk')
        self.cr.playGame.hood.loader.music.stop()
        base.playMusic(self.endMusic, volume=0.8, looping=1)
        self.timer.load()
        self.timer.startTiming()
        self.getBeansLabel.show()
        base.playSfx(self.balloonSound)

    def getBeansTimeUp(self):
        self.timer.unload()
        self.getBeansLabel.hide()
        hoodId = self.cr.playGame.hood.hoodId
        zoneId = CogBattleGlobals.HoodIndex2HoodId[self.getHoodIndex()]
        requestStatus = {
            'zoneId': zoneId,
            'hoodId': hoodId,
            'where': 'playground',
            'avId': base.localAvatar.doId,
            'loader': 'safeZoneLoader',
            'shardId': None,
            'how': 'teleportIn'
        }
        self.cr.playGame.getPlace().fsm.request('teleportOut', [requestStatus])

    def setTotalCogs(self, num):
        self.totalCogs = num

    def getTotalCogs(self):
        return self.totalCogs

    def setCogsRemaining(self, num):
        self.cogsRemaining = num
        if self.cogProgressBar:
            self.__updateProgressBar()

    def getCogsRemaining(self):
        return self.cogsRemaining

    def setHoodIndex(self, index):
        self.hoodIndex = index

    def getHoodIndex(self):
        return self.hoodIndex

    def startPlacePoll(self):
        taskMgr.add(self.__placePoll, "DistributedCogBattle-placePoll")

    def __placePoll(self, task):
        # Wait for the place to come out of None
        if self.cr.playGame.getPlace() != None:
            self.sendUpdate("arrived", [])
            self.constructArea()
            self.createInterface()
            self.__doIntroMessages()
            return task.done
        else:
            return task.cont

    def stopPlacePoll(self):
        taskMgr.remove("DistributedCogBattle-placePoll")

    def createInterface(self):
        self.cogProgressBar = DirectWaitBar(pos=(0, 0, -0.9),
                                            relief=DGG.RAISED,
                                            scale=0.6,
                                            frameColor=(1, 0.5, 0.3, 0.75),
                                            barColor=(1, 0.25, 0.25, 0.5),
                                            value=0,
                                            range=self.getTotalCogs(),
                                            text="",
                                            text_scale=0.08)
        self.__updateProgressBar()

    def __updateProgressBar(self):
        self.cogProgressBar.update(self.getCogsRemaining())
        self.cogProgressBar['text'] = "{0}/{1} {2} Remaining".format(
            self.getCogsRemaining(), self.getTotalCogs(), CIGlobals.Suits)

    def destroyInterface(self):
        if self.cogProgressBar:
            self.cogProgressBar.destroy()
            self.cogProgressBar = None

    def createBossGui(self):
        self.destroyInterface()
        backgroundGui = loader.loadModel(
            'phase_5/models/cogdominium/tt_m_gui_csa_flyThru.bam')
        backgroundGui.find('**/chatBubble').removeNode()
        bg = backgroundGui.find('**/background')
        bg.setScale(5.2)
        bg.setPos(0.14, 0, -0.6667)
        bg.reparentTo(aspect2d)
        self.frame = DirectFrame(geom=bg, relief=None, pos=(0.2, 0, -0.6667))

    def constructArea(self):
        for data in self.DNCData[self.hoodIndex]:
            dnc = loader.loadModel("phase_3.5/models/props/do_not_cross.egg")
            dnc.setPos(*data[0])
            dnc.setHpr(*data[1])
            dnc.setScale(data[2])
            dnc.reparentTo(render)
            self.DNCSigns.append(dnc)

    def deconstructArea(self):
        for dnc in self.DNCSigns:
            dnc.removeNode()

    def createWhisper(self, msg):
        whisper = WhisperPopup('Toon HQ: ' + msg, CIGlobals.getToonFont(),
                               ChatGlobals.WTSystem)
        whisper.manage(base.marginManager)

    def __doIntroMessages(self):
        self.introMessageSeq = Sequence(
            name="DistributedCogBattle-introMessageSeq")
        self.introMessageSeq.append(
            Func(
                self.createWhisper,
                "Welcome, Toons! The Cogs will be here soon, so get prepared!")
        )
        self.introMessageSeq.append(Wait(7.5))
        self.introMessageSeq.append(
            Func(
                self.createWhisper,
                "The pink bar at the bottom of the screen shows the amount of Cogs remaining to defeat."
            ))
        self.introMessageSeq.append(Wait(8.5))
        self.introMessageSeq.append(
            Func(
                self.createWhisper,
                "Purchase gags from Goofy at the Gag Shop to restock your used gags."
            ))
        self.introMessageSeq.append(Wait(7.5))
        self.introMessageSeq.append(
            Func(
                self.createWhisper,
                "Purchase battle tools from Coach at Coach's Battle Shop in between invasions."
            ))
        self.introMessageSeq.setDoneEvent(self.introMessageSeq.getName())
        self.acceptOnce(self.introMessageSeq.getDoneEvent(),
                        self.__introMessagesDone)
        self.introMessageSeq.start()

    def __introMessagesDone(self):
        if self.introMessageSeq:
            self.introMessageSeq.finish()
            self.introMessageSeq = None

    def announceGenerate(self):
        DistributedObject.announceGenerate(self)
        base.localAvatar.setMyBattle(self)
        self.startPlacePoll()
        taskMgr.add(self.monitorHP, "DCB.monitorHP")

    def disable(self):
        taskMgr.remove("DCB.monitorHP")
        taskMgr.remove(self.uniqueName('diedTask'))
        self.endMusic.stop()
        self.endMusic = None
        self.getBeansLabel.destroy()
        self.getBeansLabel = None
        self.timer.unload()
        self.timer.cleanup()
        self.timer = None
        self.balloonSound = None
        self.turretManager = None
        base.localAvatar.setMyBattle(None)
        self.stopPlacePoll()
        self.deconstructArea()
        self.destroyInterface()
        if self.victorySeq:
            self.victorySeq.pause()
            self.victorySeq = None
        self.hoodIndex = None
        self.DNCSigns = None
        self.totalCogs = None
        self.cogsRemaining = None
        if self.introMessageSeq:
            self.introMessageSeq.pause()
            self.introMessageSeq = None
        DistributedObject.disable(self)
class ExperimentChallengeGUI(NodePath):
    def __init__(self, description, needed, icon):
        NodePath.__init__(self, 'objective-%s' % id(self))

        self.needed = needed
        self.visible = False

        self.fadeInTrack = None
        self.fadeOutTrack = None

        gui = loader.loadModel(
            'phase_5/models/cogdominium/tt_m_gui_csa_flyThru')
        self.background = gui.find('**/*background').copyTo(self)
        self.background.setScale(2.5)
        gui.removeNode()

        self.icon = icon.copyTo(self.background)
        self.icon.setScale(0.08)
        self.icon.setPos(-0.167, 0, -0.002)

        text = TextNode('challenge')
        text.setText('Challenge')
        text.setFont(ToontownGlobals.getSignFont())
        text.setTextColor(0.95, 0.95, 0, 1)
        self.objText = self.background.attachNewNode(text)
        self.objText.setScale(0.03)
        self.objText.setPos(-0.04, 0.0, 0.02)

        text = TextNode('description')
        text.setText(description)
        text.setFont(ToontownGlobals.getSignFont())
        text.setTextColor(0.95, 0.95, 0, 1)
        text.setAlign(TextNode.ACenter)
        self.objText = self.background.attachNewNode(text)
        self.objText.setScale(0.015)
        self.objText.setPos(0.048, 0.0, -0.009)

        self.progressBar = DirectWaitBar(guiId='ChallengeProgressBar',
                                         parent=self.background,
                                         frameSize=(-0.11, 0.11, -0.007,
                                                    0.007),
                                         pos=(0.048, 0, -0.0338),
                                         text='')
        self.progressBar['range'] = needed

        self.progressText = DirectLabel(
            guiId='ChallengeProgressText',
            parent=self.progressBar,
            relief=None,
            pos=(0, 0, -0.0048),
            text='',
            textMayChange=1,
            text_scale=0.014,
            text_fg=(0.03, 0.83, 0, 1),
            text_align=TextNode.ACenter,
            text_font=ToontownGlobals.getSignFont())

        self.updateProgress(0)

        self.reparentTo(base.a2dBottomLeft)
        self.stash()

    def updateProgress(self, count):
        self.progressBar.update(count)
        self.progressText['text'] = '%s/%s' % (count, self.needed)

    def fadeIn(self):
        if self.fadeOutTrack:
            self.fadeOutTrack.finish()
            self.fadeOutTrack = None

        self.visible = True
        self.fadeInTrack = Sequence(
            Func(self.unstash), Func(self.setTransparency, 1),
            LerpColorScaleInterval(self,
                                   1,
                                   Vec4(1, 1, 1, 1),
                                   startColorScale=Vec4(1, 1, 1, 0)),
            Func(self.clearColorScale), Func(self.clearTransparency))
        self.fadeInTrack.start()

    def fadeOut(self):
        if self.fadeInTrack:
            self.fadeInTrack.finish()
            self.fadeInTrack = None

        self.visible = False
        self.fadeOutTrack = Sequence(
            Func(self.setTransparency, 1),
            LerpColorScaleInterval(self,
                                   1,
                                   Vec4(1, 1, 1, 0),
                                   startColorScale=Vec4(1, 1, 1, 1)),
            Func(self.clearColorScale), Func(self.clearTransparency),
            Func(self.stash))
        self.fadeOutTrack.start()

    def fadeOutDestroy(self):
        self.visible = False
        Sequence(
            Func(self.setTransparency, 1),
            LerpColorScaleInterval(self,
                                   1,
                                   Vec4(1, 1, 1, 0),
                                   startColorScale=Vec4(1, 1, 1, 1)),
            Func(self.clearColorScale), Func(self.clearTransparency),
            Func(self.stash), Func(self.destroy)).start()

    def destroy(self):
        self.removeNode()
Пример #13
0
class BRWater:
    notify = directNotify.newCategory('BRWater')

    def __init__(self, playground):
        self.playground = playground
        self.fsm = ClassicFSM('BRWater', [State('off', self.enterOff, self.exitOff),
         State('freezeUp', self.enterFreezeUp, self.exitFreezeUp),
         State('coolDown', self.enterCoolDown, self.exitCoolDown),
         State('frozen', self.enterFrozen, self.exitFrozen)], 'off', 'off')
        self.fsm.enterInitialState()
        self.freezeUpSfx = base.loadSfx('phase_8/audio/sfx/freeze_up.mp3')
        self.frozenSfxArray = [base.loadSfx('phase_8/audio/sfx/frozen_1.mp3'), base.loadSfx('phase_8/audio/sfx/frozen_2.mp3'), base.loadSfx('phase_8/audio/sfx/frozen_3.mp3')]
        self.coolSfxArray = [base.loadSfx('phase_8/audio/sfx/cool_down_1.mp3'), base.loadSfx('phase_8/audio/sfx/cool_down_2.mp3')]
        self.freezeUpSfx.setVolume(12)
        for sfx in self.frozenSfxArray:
            sfx.setVolume(12)

        for sfx in self.coolSfxArray:
            sfx.setVolume(12)

    def attachSound(self, sound):
        base.localAvatar.audio3d.attachSoundToObject(sound, base.localAvatar)

    def enterOff(self):
        self.playground.startWaterWatch()

    def exitOff(self):
        self.playground.stopWaterWatch()

    def loadIceCube(self):
        self.iceCube = loader.loadModel('phase_8/models/props/icecube.bam')
        for node in self.iceCube.findAllMatches('**/billboard*'):
            node.removeNode()

        for node in self.iceCube.findAllMatches('**/drop_shadow*'):
            node.removeNode()

        for node in self.iceCube.findAllMatches('**/prop_mailboxcollisions*'):
            node.removeNode()

        self.iceCube.reparentTo(base.localAvatar)
        self.iceCube.setScale(1.2, 1.0, base.localAvatar.getHeight() / 1.7)
        self.iceCube.setTransparency(1)
        self.iceCube.setColorScale(0.76, 0.76, 1.0, 0.0)

    def unloadIceCube(self):
        self.iceCube.removeNode()
        del self.iceCube

    def enterFreezeUp(self):
        length = 1.0
        base.playSfx(self.freezeUpSfx)
        self.fucsIval = Sequence(LerpColorScaleInterval(base.localAvatar.getGeomNode(), duration=length, colorScale=VBase4(0.5, 0.5, 1.0, 1.0), startColorScale=base.localAvatar.getGeomNode().getColorScale(), blendType='easeOut'), Func(self.fsm.request, 'frozen'))
        self.fucsIval.start()
        self.playground.startWaterWatch(0)

    def exitFreezeUp(self):
        self.fucsIval.pause()
        del self.fucsIval
        self.playground.stopWaterWatch()

    def enterFrozen(self):
        self.loadIceCube()
        base.cr.playGame.getPlace().fsm.request('stop', [0])
        base.localAvatar.stop()
        base.playSfx(choice(self.frozenSfxArray))
        self.iccsIval = LerpColorScaleInterval(self.iceCube, duration=0.5, colorScale=VBase4(0.76, 0.76, 1.0, 1.0), startColorScale=self.iceCube.getColorScale(), blendType='easeInOut')
        self.iccsIval.start()
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)
        self.frame = DirectFrame(pos=(0, 0, 0.7))
        self.powerBar = DirectWaitBar(frameColor=(1, 1, 1, 1), range=100, value=0, scale=(0.4, 0.5, 0.25), parent=self.frame, barColor=(0.55, 0.7, 1.0, 1.0))
        self.label = OnscreenText(text='SHAKE MOUSE', shadow=(0, 0, 0, 1), fg=(0.55, 0.7, 1.0, 1.0), pos=(0, -0.1, 0), parent=self.frame)
        taskMgr.add(self.__watchMouseMovement, 'BRWater-watchMouseMovement')
        taskMgr.add(self.__lowerPowerBar, 'BRWater-lowerPowerBar')
        mw = base.mouseWatcherNode
        if mw.hasMouse():
            self.lastMouseX = mw.getMouseX()

    def __lowerPowerBar(self, task):
        if self.powerBar['value'] <= 0:
            self.powerBar.update(0)
        decrement = 1
        self.powerBar.update(self.powerBar['value'] - decrement)
        task.delayTime = 0.1
        return task.again

    def __watchMouseMovement(self, task):
        if self.powerBar['value'] >= self.powerBar['range']:
            self.fsm.request('coolDown', [1])
            return task.done
        mw = base.mouseWatcherNode
        if mw.hasMouse():
            if not self.lastMouseX or self.lastMouseX != mw.getMouseX():
                value = 3 * self.lastMouseX - mw.getMouseX()
                self.lastMouseX = mw.getMouseX()
                self.powerBar.update(self.powerBar['value'] + abs(value))
        return task.cont

    def exitFrozen(self):
        props = WindowProperties()
        props.setCursorHidden(False)
        base.win.requestProperties(props)
        self.iccsIval.pause()
        del self.iccsIval
        self.unloadIceCube()
        taskMgr.remove('BRWater-lowerPowerBar')
        taskMgr.remove('BRWater-watchMouseMovement')
        self.label.destroy()
        del self.label
        self.powerBar.destroy()
        del self.powerBar
        self.frame.destroy()
        del self.frame
        del self.lastMouseX
        base.cr.playGame.getPlace().fsm.request('walk')
        base.localAvatar.b_setAnimState('neutral')

    def enterCoolDown(self, fromFrozen = 0):
        if fromFrozen:
            self.loadIceCube()
            self.iceCube.setColorScale(0.76, 0.76, 1.0, 1.0)
            self.iccdIval = LerpColorScaleInterval(self.iceCube, duration=0.5, colorScale=VBase4(0.76, 0.76, 1.0, 0.0), startColorScale=self.iceCube.getColorScale(), blendType='easeInOut')
            self.iccdIval.start()
        length = 1.0
        base.playSfx(choice(self.coolSfxArray))
        self.cdcsIval = Sequence(LerpColorScaleInterval(base.localAvatar.getGeomNode(), duration=length, colorScale=VBase4(1.0, 1.0, 1.0, 1.0), startColorScale=base.localAvatar.getGeomNode().getColorScale(), blendType='easeOut'), Func(self.fsm.request, 'off'))
        self.cdcsIval.start()

    def exitCoolDown(self):
        if hasattr(self, 'iccdIval'):
            self.iccdIval.pause()
            del self.iccdIval
            self.unloadIceCube()
        self.cdcsIval.pause()
        del self.cdcsIval

    def cleanup(self):
        self.fsm.requestFinalState()
        self.playground.stopWaterWatch()
        del self.fsm
        del self.freezeUpSfx
        del self.frozenSfxArray
        del self.coolSfxArray
        del self.playground
Пример #14
0
class DistributedPieTurretManager(DistributedObject):
    notify = directNotify.newCategory("DistributedPieTurretManager")

    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        self.myTurret = None
        self.guiFrame = None
        self.guiLabel = None
        self.guiBar = None
        self.guiBg = None
        self.turretGag = None
        return

    def announceGenerate(self):
        DistributedObject.announceGenerate(self)
        base.taskMgr.add(self.__pollMyBattle, "__pollMyBattle")

    def disable(self):
        base.taskMgr.remove("DPTM.pollTurret")
        base.taskMgr.remove("__pollMyBattle")
        if hasattr(self, "makeTurretBtn"):
            self.makeTurretBtn.destroy()
            del self.makeTurretBtn
        self.destroyGui()
        self.myTurret = None
        if base.localAvatar.getMyBattle():
            base.localAvatar.getMyBattle().setTurretManager(None)
        DistributedObject.disable(self)
        return

    def __pollTurret(self, turretId, task):
        turret = self.cr.doId2do.get(turretId)
        if turret != None:
            self.myTurret = turret
            self.turretGag = None
            self.makeGui()
            return Task.done
        else:
            return Task.cont

    def setGag(self, upgradeId):
        self.turretGag = upgradeId

    def d_requestPlace(self, posHpr):
        self.sendUpdate("requestPlace", [posHpr])

    def turretPlaced(self, turretId):
        turret = self.cr.doId2do.get(turretId)
        turret.b_setGag(self.turretGag)
        self.turretGag = None
        base.taskMgr.add(self.__pollTurret, "DPTM.pollTurret", extraArgs=[turretId], appendTask=True)
        return

    def yourTurretIsDead(self):
        base.taskMgr.remove("DPTM.pollTurret")
        self.destroyGui()
        self.myTurret = None
        if base.localAvatar.getPUInventory()[0] > 0:
            self.createTurretButton()
        return

    def makeGui(self):
        self.destroyGui()
        self.guiFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.55, 0, 0.15))
        self.guiBg = OnscreenImage(image="phase_4/maps/turret_gui_bg.png", scale=(0.15, 0, 0.075), parent=self.guiFrame)
        self.guiBg.setTransparency(True)
        self.guiLabel = DirectLabel(
            text="Turret",
            text_fg=(1, 0, 0, 1),
            relief=None,
            text_scale=0.05,
            text_font=loader.loadFont("phase_3/models/fonts/ImpressBT.ttf"),
            pos=(0, 0, 0.025),
            parent=self.guiFrame,
        )
        self.guiBar = DirectWaitBar(
            range=self.myTurret.getMaxHealth(),
            value=self.myTurret.getHealth(),
            scale=0.125,
            parent=self.guiFrame,
            pos=(0, 0, -0.01),
        )
        return

    def createTurretButton(self):
        self.makeTurretBtn = DirectButton(
            relief=None,
            geom=CIGlobals.getDefaultBtnGeom(),
            text="Turret",
            text_scale=0.055,
            command=self.handleMakeTurretBtn,
            pos=(-0.47, 0, 0.1),
            geom_scale=(0.5, 1.0, 1.0),
            text_pos=(0, -0.01),
            parent=base.a2dBottomRight,
        )
        return

    def handleMakeTurretBtn(self):
        self.makeTurretBtn.destroy()
        del self.makeTurretBtn
        x, y, z = base.localAvatar.getPos()
        h, p, r = base.localAvatar.getHpr()
        self.d_requestPlace([x, y, z, h, p, r])
        base.localAvatar.sendUpdate("usedPU", [0])

    def __pollMyBattle(self, task):
        if base.localAvatar.getMyBattle():
            base.localAvatar.getMyBattle().setTurretManager(self)
            if base.localAvatar.getPUInventory()[0] > 0:
                self.createTurretButton()
            return Task.done
        return Task.cont

    def destroyGui(self):
        if self.guiBar:
            self.guiBar.destroy()
            self.guiBar = None
        if self.guiLabel:
            self.guiLabel.destroy()
            self.guiLabel = None
        if self.guiBg:
            self.guiBg.destroy()
            self.guiBg = None
        if self.guiFrame:
            self.guiFrame.destroy()
            self.guiFrame = None
        return

    def updateTurretGui(self):
        if self.guiBar:
            self.guiBar.update(self.myTurret.getHealth())