Esempio n. 1
0
 def serverTime(self, context, timestamp, timeOfDay):
     end = globalClock.getRealTime()
     now = int(time.time())
     aiTimeDelta = timeOfDay - now
     aiTimeSkew = aiTimeDelta - self.cr.getServerDelta()
     if context != self.thisContext:
         self.notify.info('Ignoring TimeManager response for old context %d' % context)
         return None
     
     elapsed = end - self.start
     self.attemptCount += 1
     self.notify.info('Clock sync roundtrip took %0.3f ms' % elapsed * 1000.0)
     self.notify.info('AI time delta is %s from server delta' % PythonUtil.formatElapsedSeconds(aiTimeSkew))
     if elapsed > self.maxLatency:
         if self.attemptCount < self.maxAttempts:
             self.notify.info('Latency is too high, trying again.')
             self.start = globalClock.getRealTime()
             self.sendUpdate('requestServerTime', [
                 self.thisContext])
             return None
         
         self.notify.info('Giving up on latency requirement.')
     
     average = (self.start + end) / 2.0 - self.extraSkew
     change = globalClockDelta.resynchronize(average, timestamp)
     self.notify.info('Clock delta changed by %.3f s' % change)
     if self.talkResult:
         toonbase.localToon.setChatAbsolute('latency %0.0f ms, clock adjusted %.1f s' % (elapsed * 1000.0, change), CFSpeech | CFTimeout)
     
     self.gotSync = 1
     messenger.send('gotTimeSync')
Esempio n. 2
0
 def serverTime(self, context, timestamp, timeOfDay):
     end = globalClock.getRealTime()
     now = int(time.time())
     aiTimeDelta = timeOfDay - now
     aiTimeSkew = aiTimeDelta - self.cr.getServerDelta()
     if context != self.thisContext:
         self.notify.info('Ignoring TimeManager response for old context %d' % context)
         return
     elapsed = end - self.start
     self.attemptCount += 1
     self.notify.info('Clock sync roundtrip took %0.3f ms' % (elapsed * 1000.0))
     self.notify.info('AI time delta is %s from server delta' % PythonUtil.formatElapsedSeconds(aiTimeSkew))
     if elapsed > self.maxLatency:
         if self.attemptCount < self.maxAttempts:
             self.notify.info('Latency is too high, trying again.')
             self.start = globalClock.getRealTime()
             self.sendUpdate('requestServerTime', [self.thisContext])
             return
         self.notify.info('Giving up on latency requirement.')
     average = (self.start + end) / 2.0 - self.extraSkew
     change = globalClockDelta.resynchronize(average, timestamp)
     self.notify.info('Clock delta changed by %.3f s' % change)
     if self.talkResult:
         toonbase.localToon.setChatAbsolute('latency %0.0f ms, clock adjusted %.1f s' % (elapsed * 1000.0, change), CFSpeech | CFTimeout)
     self.gotSync = 1
     messenger.send('gotTimeSync')
Esempio n. 3
0
 def setServerDelta(self, delta, timezone):
     delta = int(round(delta))
     Notifier.serverDelta = delta + time.timezone - timezone
     import NotifyCategory
     NotifyCategory.NotifyCategory.setServerDelta(self.serverDelta)
     self.info(
         'Notify clock adjusted by %s (and timezone adjusted by %s hours) to synchronize with server.'
         % (PythonUtil.formatElapsedSeconds(delta),
            (time.timezone - timezone) / 3600))
 def setCheesyEffect(self, effect, hoodId, expireTime):
     self.savedCheesyEffect = effect
     self.savedCheesyHoodId = hoodId
     self.savedCheesyExpireTime = expireTime
     if self == toonbase.localToon:
         self.notify.info('setCheesyEffect(%s, %s, %s)' % (effect, hoodId, expireTime))
         if effect != ToontownGlobals.CENormal:
             serverTime = time.time() + self.cr.getServerDelta()
             duration = expireTime * 60 - serverTime
             if duration < 0:
                 self.notify.info('effect should have expired %s ago.' % PythonUtil.formatElapsedSeconds(-duration))
             else:
                 self.notify.info('effect will expire in %s.' % PythonUtil.formatElapsedSeconds(duration))
         
     
     if self.activeState == DistributedObject.ESGenerated:
         self.reconsiderCheesyEffect(lerpTime = 0.5)
     else:
         self.reconsiderCheesyEffect()
Esempio n. 5
0
 def checkHealTrapLure(self):
     self.notify.debug('numToons: %s, numCogs: %s, lured: %s, trapped: %s' % (self.numToons, self.numCogs, self.luredIndices, self.trappedIndices))
     if len(PythonUtil.union(self.trappedIndices, self.luredIndices)) == self.numCogs:
         canTrap = 0
     else:
         canTrap = 1
     if len(self.luredIndices) == self.numCogs:
         canLure = 0
         canTrap = 0
     else:
         canLure = 1
     if self.numToons == 1:
         canHeal = 0
     else:
         canHeal = 1
     return (canHeal, canTrap, canLure)
Esempio n. 6
0
 def checkHealTrapLure(self):
     self.notify.debug('numToons: %s, numCogs: %s, lured: %s, trapped: %s' % (self.numToons, self.numCogs, self.luredIndices, self.trappedIndices))
     if len(PythonUtil.union(self.trappedIndices, self.luredIndices)) == self.numCogs:
         canTrap = 0
     else:
         canTrap = 1
     if len(self.luredIndices) == self.numCogs:
         canLure = 0
         canTrap = 0
     else:
         canLure = 1
     if self.numToons == 1:
         canHeal = 0
     else:
         canHeal = 1
     return (
      canHeal, canTrap, canLure)
Esempio n. 7
0
def __get_Slots(numRings, rng, vertical = 1):
    tracks = []
    tOffsets = []
    fpTab = []
    for i in range(numRings):
        fpTab.append(PythonUtil.lineupPos(i, numRings, 2.0 / 3))
    
    offset = 1 - fpTab[-1]
    offset = rng.random() * offset * 2 - offset
    fpTab = map(lambda x: x + offset, fpTab)
    for i in range(0, numRings):
        if vertical:
            getActionsFunc = RingTracks.getVerticalSlotActions
        else:
            getActionsFunc = RingTracks.getHorizontalSlotActions
        (actions, durations) = getActionsFunc(fpTab[i])
        track = RingTrack.RingTrack(actions, durations)
        tracks.append(track)
        tOffsets.append((float(i) / numRings) * 0.5)
    
    return (tracks, tOffsets, fullCirclePeriod)
Esempio n. 8
0
def __get_Slots(numRings, rng, vertical=1):
    tracks = []
    tOffsets = []
    fpTab = []
    for i in range(numRings):
        fpTab.append(PythonUtil.lineupPos(i, numRings, 2.0 / 3))

    offset = 1 - fpTab[-1]
    offset = rng.random() * offset * 2 - offset
    fpTab = map(lambda x: x + offset, fpTab)
    for i in range(0, numRings):
        if vertical:
            getActionsFunc = RingTracks.getVerticalSlotActions
        else:
            getActionsFunc = RingTracks.getHorizontalSlotActions
        (actions, durations) = getActionsFunc(fpTab[i])
        track = RingTrack.RingTrack(actions, durations)
        tracks.append(track)
        tOffsets.append((float(i) / numRings) * 0.5)

    return (tracks, tOffsets, fullCirclePeriod)
 def calcTimeOfImpactOnPlane(startHeight, endHeight, startVel, accel):
     return PythonUtil.solveQuadratic(accel * 0.5, startVel,
                                      startHeight - endHeight)
    def enter(self):
        ShtikerPage.ShtikerPage.enter(self)

        try:
            zone = toonbase.tcr.playGame.getPlace().getZoneId()
        except:
            zone = 0

        if zone and ZoneUtil.isPlayground(zone) or self.book.safeMode:
            self.safeZoneButton.hide()
        else:
            self.safeZoneButton.show()
        if toonbase.localToon.estate != None and toonbase.tcr.playGame.estateLoader.atMyEstate(
        ) or self.book.safeMode:
            self.goHomeButton.hide()
        elif toonbase.housingEnabled:
            self.goHomeButton.show()

        if toonbase.tcr.playGame.hood == None and toonbase.tcr.playGame.estateLoader != None:
            if toonbase.tcr.playGame.estateLoader.atMyEstate():
                self.hoodLabel['text'] = Localizer.MapPageYouAreAtHome
                self.hoodLabel.show()
            else:
                avatar = toonbase.tcr.identifyAvatar(
                    toonbase.tcr.playGame.estateLoader.estateOwnerId)
                if avatar:
                    avName = avatar.getName()
                    self.hoodLabel[
                        'text'] = Localizer.MapPageYouAreAtSomeonesHome % Localizer.GetPossesive(
                            avName)
                    self.hoodLabel.show()

        elif zone:
            hoodName = ToontownGlobals.hoodNameMap.get(
                ZoneUtil.getHoodId(zone), ('', ''))[1]
            streetName = ToontownGlobals.StreetNames.get(
                ZoneUtil.getBranchZone(zone), ('', ''))[1]
            if hoodName:
                self.hoodLabel['text'] = Localizer.MapPageYouAreHere % (
                    hoodName, streetName)
                self.hoodLabel.show()
            else:
                self.hoodLabel.hide()
        else:
            self.hoodLabel.hide()
        if toonbase.localToon.teleportCheat:
            safeZonesVisited = ToontownGlobals.Hoods
        else:
            safeZonesVisited = toonbase.localToon.safeZonesVisited
        hoodsAvailable = toonbase.tcr.hoodMgr.getAvailableZones()
        hoodVisibleList = PythonUtil.intersection(safeZonesVisited,
                                                  hoodsAvailable)
        if toonbase.localToon.teleportCheat:
            hoodTeleportList = hoodVisibleList
        else:
            hoodTeleportList = toonbase.localToon.getTeleportAccess()
        for hood in self.allZones:
            label = self.labels[self.allZones.index(hood)]
            clouds = self.clouds[self.allZones.index(hood)]
            if not (self.book.safeMode) and hood in hoodVisibleList:
                label.show()
                for cloud in clouds:
                    cloud.hide()

                fullname = toonbase.tcr.hoodMgr.getFullnameFromId(hood)
                if hood in hoodTeleportList:
                    text = Localizer.MapPageGoTo % fullname
                    label['text'] = ('', text, text)
                else:
                    label['text'] = ('', fullname, fullname)
            else:
                label.hide()
                for cloud in clouds:
                    cloud.show()

        return None
Esempio n. 11
0
    def enter(self):
        ShtikerPage.ShtikerPage.enter(self)
        
        try:
            zone = toonbase.tcr.playGame.getPlace().getZoneId()
        except:
            zone = 0

        if zone and ZoneUtil.isPlayground(zone) or self.book.safeMode:
            self.safeZoneButton.hide()
        else:
            self.safeZoneButton.show()
        if toonbase.localToon.estate != None and toonbase.tcr.playGame.estateLoader.atMyEstate() or self.book.safeMode:
            self.goHomeButton.hide()
        elif toonbase.housingEnabled:
            self.goHomeButton.show()
        
        if toonbase.tcr.playGame.hood == None and toonbase.tcr.playGame.estateLoader != None:
            if toonbase.tcr.playGame.estateLoader.atMyEstate():
                self.hoodLabel['text'] = Localizer.MapPageYouAreAtHome
                self.hoodLabel.show()
            else:
                avatar = toonbase.tcr.identifyAvatar(toonbase.tcr.playGame.estateLoader.estateOwnerId)
                if avatar:
                    avName = avatar.getName()
                    self.hoodLabel['text'] = Localizer.MapPageYouAreAtSomeonesHome % Localizer.GetPossesive(avName)
                    self.hoodLabel.show()
                
        elif zone:
            hoodName = ToontownGlobals.hoodNameMap.get(ZoneUtil.getHoodId(zone), ('', ''))[1]
            streetName = ToontownGlobals.StreetNames.get(ZoneUtil.getBranchZone(zone), ('', ''))[1]
            if hoodName:
                self.hoodLabel['text'] = Localizer.MapPageYouAreHere % (hoodName, streetName)
                self.hoodLabel.show()
            else:
                self.hoodLabel.hide()
        else:
            self.hoodLabel.hide()
        if toonbase.localToon.teleportCheat:
            safeZonesVisited = ToontownGlobals.Hoods
        else:
            safeZonesVisited = toonbase.localToon.safeZonesVisited
        hoodsAvailable = toonbase.tcr.hoodMgr.getAvailableZones()
        hoodVisibleList = PythonUtil.intersection(safeZonesVisited, hoodsAvailable)
        if toonbase.localToon.teleportCheat:
            hoodTeleportList = hoodVisibleList
        else:
            hoodTeleportList = toonbase.localToon.getTeleportAccess()
        for hood in self.allZones:
            label = self.labels[self.allZones.index(hood)]
            clouds = self.clouds[self.allZones.index(hood)]
            if not (self.book.safeMode) and hood in hoodVisibleList:
                label.show()
                for cloud in clouds:
                    cloud.hide()
                
                fullname = toonbase.tcr.hoodMgr.getFullnameFromId(hood)
                if hood in hoodTeleportList:
                    text = Localizer.MapPageGoTo % fullname
                    label['text'] = ('', text, text)
                else:
                    label['text'] = ('', fullname, fullname)
            else:
                label.hide()
                for cloud in clouds:
                    cloud.show()
                
        
        return None
Esempio n. 12
0
 def calcTimeOfImpactOnPlane(startHeight, endHeight, startVel, accel):
     return PythonUtil.solveQuadratic(accel * 0.5, startVel, startHeight - endHeight)