コード例 #1
0
    def __init__(self, baseChannel, serverId, districtName):
        ToontownInternalRepository.__init__(self,
                                            baseChannel,
                                            serverId,
                                            dcSuffix='AI')

        self.districtName = districtName

        self.zoneAllocator = UniqueIdAllocator(
            ToontownGlobals.DynamicZonesBegin, ToontownGlobals.DynamicZonesEnd)

        NPCToons.generateZone2NpcDict()

        self.use_libpandadna = simbase.config.GetBool('use-libpandadna', False)

        self.hoods = []
        self._dnaStoreMap = {}

        if self.use_libpandadna:
            self.__loader = DNALoader()

        self.zoneDataStore = AIZoneDataStore()

        self.useAllMinigames = self.config.GetBool('want-all-minigames', False)
        self.doLiveUpdates = True

        self.wantCogdominiums = self.config.GetBool('want-cogdo', False)
        self.wantParties = self.config.GetBool('want-parties', False)
        self.wantEmblems = self.config.GetBool('want-emblems', True)

        self.questManager = QuestManagerAI(self)
        self.promotionMgr = PromotionManagerAI(self)
        self.cogPageManager = CogPageManagerAI(self)
        self.cogSuitMgr = CogSuitManagerAI(self)

        self.trophyMgr = DistributedTrophyMgrAI(self)

        self.fishManager = FishManagerAI()

        self.dnaStoreMap = {}

        self.mintMgr = MintManagerAI.MintManagerAI(self)
        self.factoryMgr = FactoryManagerAI.FactoryManagerAI(self)
        self.lawMgr = LawOfficeManagerAI.LawOfficeManagerAI(self)
        self.countryClubMgr = CountryClubManagerAI.CountryClubManagerAI(self)

        self.buildingManagers = {}
        self.suitPlanners = {}

        self.wantMegaInvasions = str(
            self.ourChannel // 1000000) in self.config.GetString(
                'mega-invasion-shards', '402 403').split()
コード例 #2
0
    def __init__(self, baseChannel, serverId, districtName):
        ToontownInternalRepository.__init__(self, baseChannel, serverId, dcSuffix='AI')

        self.districtName = districtName

        self.zoneAllocator = UniqueIdAllocator(ToontownGlobals.DynamicZonesBegin,
                                               ToontownGlobals.DynamicZonesEnd)

        NPCToons.generateZone2NpcDict()
        
        self.use_libpandadna = simbase.config.GetBool('use-libpandadna', False)
        
        self.hoods = []
        self._dnaStoreMap = {}
        
        if self.use_libpandadna:
            self.__loader = DNALoader()
        
        self.zoneDataStore = AIZoneDataStore()

        self.useAllMinigames = self.config.GetBool('want-all-minigames', False)
        self.doLiveUpdates = True
        
        self.wantCogdominiums = self.config.GetBool('want-cogdo', False)
        self.wantParties = self.config.GetBool('want-parties', False)
        self.wantEmblems = self.config.GetBool('want-emblems', True)
        
        self.questManager = QuestManagerAI(self)
        self.promotionMgr = PromotionManagerAI(self)
        self.cogPageManager = CogPageManagerAI(self)
        self.cogSuitMgr = CogSuitManagerAI(self)

        self.trophyMgr = DistributedTrophyMgrAI(self)
        
        self.fishManager = FishManagerAI()
		
        self.dnaStoreMap = {}
        
        self.mintMgr = MintManagerAI.MintManagerAI(self)
        self.factoryMgr = FactoryManagerAI.FactoryManagerAI(self)
        self.lawMgr = LawOfficeManagerAI.LawOfficeManagerAI(self)
        self.countryClubMgr = CountryClubManagerAI.CountryClubManagerAI(self)
        
        self.buildingManagers = {}
        self.suitPlanners = {}
        
        self.wantMegaInvasions = str(self.ourChannel // 1000000) in self.config.GetString('mega-invasion-shards', '402 403').split()            
コード例 #3
0
class ToontownAIRepository(ToontownInternalRepository):
    def __init__(self, baseChannel, serverId, districtName):
        ToontownInternalRepository.__init__(self, baseChannel, serverId, dcSuffix='AI')

        self.districtName = districtName

        self.zoneAllocator = UniqueIdAllocator(ToontownGlobals.DynamicZonesBegin,
                                               ToontownGlobals.DynamicZonesEnd)

        NPCToons.generateZone2NpcDict()
        
        self.use_libpandadna = simbase.config.GetBool('use-libpandadna', False)
        
        self.hoods = []
        self._dnaStoreMap = {}
        
        if self.use_libpandadna:
            self.__loader = DNALoader()
        
        self.zoneDataStore = AIZoneDataStore()

        self.useAllMinigames = self.config.GetBool('want-all-minigames', False)
        self.doLiveUpdates = True
        
        self.wantCogdominiums = self.config.GetBool('want-cogdo', False)
        self.wantParties = self.config.GetBool('want-parties', False)
        self.wantEmblems = self.config.GetBool('want-emblems', True)
        
        self.questManager = QuestManagerAI(self)
        self.promotionMgr = PromotionManagerAI(self)
        self.cogPageManager = CogPageManagerAI(self)
        self.cogSuitMgr = CogSuitManagerAI(self)

        self.trophyMgr = DistributedTrophyMgrAI(self)
        
        self.fishManager = FishManagerAI()
		
        self.dnaStoreMap = {}
        
        self.mintMgr = MintManagerAI.MintManagerAI(self)
        self.factoryMgr = FactoryManagerAI.FactoryManagerAI(self)
        self.lawMgr = LawOfficeManagerAI.LawOfficeManagerAI(self)
        self.countryClubMgr = CountryClubManagerAI.CountryClubManagerAI(self)
        
        self.buildingManagers = {}
        self.suitPlanners = {}
        
        self.wantMegaInvasions = str(self.ourChannel // 1000000) in self.config.GetString('mega-invasion-shards', '402 403').split()            

    def getTrackClsends(self):
        return False
        
    def handleConnected(self):
        self.districtId = self.allocateChannel()
        self.distributedDistrict = ToontownDistrictAI(self)
        self.distributedDistrict.setName(self.districtName)
        self.distributedDistrict.generateWithRequiredAndId(simbase.air.districtId, self.getGameDoId(), 2)

        dg = PyDatagram()
        dg.addServerHeader(simbase.air.districtId, simbase.air.ourChannel, STATESERVER_OBJECT_SET_AI)
        dg.addChannel(simbase.air.ourChannel)
        simbase.air.send(dg)

        self.createGlobals()
        self.createZones()

    def __ready(self):
        dg = PyDatagram()
        dg.addServerHeader(self.districtStats.doId, self.ourChannel, STATESERVER_OBJECT_DELETE_RAM)
        dg.addUint32(self.districtStats.doId)
        self.addPostRemove(dg)
        
        self.apiMgr = self.generateGlobalObject(100001, "ShardAPIManager")
        self.apiMgr.start()
        self.apiMgr.d_setShardData()
        
        self.banMgr = self.generateGlobalObject(100002, "BanManager")
        
        self.trophyMgr.updateToonData()
        
    def gotUberdogAPISync(self):
        if not self.distributedDistrict.getAvailable():
            self.notify.info("Got UD API sync, opening shard...")
            messenger.send("startShardActivity")
            self.distributedDistrict.b_setAvailable(1)

    def incrementPopulation(self):
        self.districtStats.b_setAvatarCount(self.districtStats.getAvatarCount() + 1)

    def decrementPopulation(self):
        self.districtStats.b_setAvatarCount(self.districtStats.getAvatarCount() - 1)

    def allocateZone(self):
        return self.zoneAllocator.allocate()

    def deallocateZone(self, zone):
        self.zoneAllocator.free(zone)

    def getZoneDataStore(self):
        return self.zoneDataStore

    def getAvatarExitEvent(self, avId):
        return 'distObjDelete-%d' % avId

    def createGlobals(self):
        self.districtStats = ToontownDistrictStatsAI(self)
        self.districtStats.settoontownDistrictId(self.districtId)
        self.districtStats.generateWithRequiredAndId(self.allocateChannel(), self.getGameDoId(), 2)
		
        self.timeManager = TimeManagerAI(self)
        self.timeManager.generateWithRequired(2)

        self.newsManager = NewsManagerAI(self)
        self.newsManager.generateWithRequired(2)

        self.holidayManager = HolidayManagerAI(self)

        self.magicWordManager = MagicWordManagerAI(self)
        self.magicWordManager.generateWithRequired(2)

        self.safeZoneManager = SafeZoneManagerAI(self)
        self.safeZoneManager.generateWithRequired(2)
		
        self.petMgr = PetManagerAI(self)

        self.friendManager = FriendManagerAI(self)
        self.friendManager.generateWithRequired(2)

        self.partyManager = DistributedPartyManagerAI(self)
        self.partyManager.generateWithRequired(2)
		
        self.tutorialManager = TutorialManagerAI(self)
        self.tutorialManager.generateWithRequired(2)
		
        self.globalPartyMgr = self.generateGlobalObject(OTP_DO_ID_GLOBAL_PARTY_MANAGER, 'GlobalPartyManager')

        self.estateManager = EstateManagerAI(self)
        self.estateManager.generateWithRequired(2)
        
        self.suitInvasionManager = DistributedSuitInvasionManagerAI(self)
        self.suitInvasionManager.generateWithRequired(2)

        self.bankMgr = DistributedBankMgrAI(self)
        self.bankMgr.generateWithRequired(2)
        
        self.catalogManager = CatalogManagerAI(self)
        self.catalogManager.generateWithRequired(2)
        
        self.huntId = 0
        
        if self.holidayManager.isHolidayRunning(ToontownGlobals.TRICK_OR_TREAT):
            import DistributedTrickOrTreatTargetAI
            self.trickOrTreatMgr = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(self)
            self.trickOrTreatMgr.generateWithRequired(2)
            
        self.handleBlackCatMgr()
        self.handleBloodsuckerInvasion()
        self.handleSkelCogWeekInvasion()
        
        if config.GetBool('want-resistance-emote', True):
            self.resistanceMgr = DistributedResistanceEmoteMgrAI.DistributedResistanceEmoteMgrAI(self)
            self.resistanceMgr.generateWithRequired(9720)

        if config.GetBool('want-polar-effect', True):
            self.polarMgr = DistributedPolarPlaceEffectMgrAI.DistributedPolarPlaceEffectMgrAI(self)
            self.polarMgr.generateWithRequired(3821)
            
    def handleBlackCatMgr(self):
        today = datetime.datetime.now()
        start = datetime.datetime(today.year, 10, 31)
        end = datetime.datetime(today.year, 11, 3)
        
        def createBlackCatMgr(task=None):
            import DistributedBlackCatMgrAI
            self.blackCatMgr = DistributedBlackCatMgrAI.DistributedBlackCatMgrAI(self)
            self.blackCatMgr.generateWithRequired(2513)
            if not self.config.GetBool('force-black-cat-mgr', False):
                self.blackCatMgr.expire((end - today).total_seconds())
            return Task.done
        
        if start <= today < end or self.config.GetBool('force-black-cat-mgr', False):
            createBlackCatMgr(None)
            
        elif start >= today:
            taskMgr.doMethodLater((start - today).total_seconds(), createBlackCatMgr, 'air-createBlackCatMgr')
            
    def handleBloodsuckerInvasion(self):
        if not self.wantMegaInvasions:
            return
            
        today = datetime.datetime.now()
        start = datetime.datetime(today.year, 10, 31)
        end = datetime.datetime(today.year, 11, 3)
        
        if start <= today < end:
            self.startMegaInvasion(9, end=end)
            
        elif start > today:
            taskMgr.doMethodLater((start - today).total_seconds(), self.startMegaInvasion, 'air-mega-invasion-9', extraArgs=[9, False, end])
            
    def handleSkelCogWeekInvasion(self):
        if not self.wantMegaInvasions:
            return
            
        today = datetime.datetime.now()
        start = datetime.datetime(2014, 11, 10)
        end = datetime.datetime(2014, 11, 17)
        
        if start <= today < end:
            self.startMegaInvasion(-1, skel=True, end=end)
            
        elif start > today:
            taskMgr.doMethodLater((start - today).total_seconds(), self.startMegaInvasion, 'air-mega-invasion-skel', extraArgs=[-1, True, end])
            
    def startMegaInvasion(self, suitIndex, skel=False, end=None):
        if suitIndex >= 0:
            suitName = SuitDNA.suitHeadTypes[suitIndex]
            
        else:
            suitName = None
            
        if self.suitInvasionManager.hasInvading():
            if self.suitInvasionManager.isMega():
                return Task.done
                
            self.suitInvasionManager.abort()
            
        self.suitInvasionManager.startInvasion(suitName, skel, mega=True)
        if end:
            def doAbort(task):
                self.suitInvasionManager.abort()
                return task.done

            today = datetime.datetime.now()
            taskMgr.doMethodLater((end - today).total_seconds(), doAbort, 'air-abort-mega-invasion')
        
    def getStorage(self, zone):
        s = self._dnaStoreMap.get(zone)
        if not s:
            s = DNAStorage()
            self.loadDNAFileAI(s, self.genDNAFileName(zone))
            self._dnaStoreMap[zone] = s
        
        return s

    def createZones(self):
        self.zoneTable = {
                          1000: ((1000, 1, 0), (1100, 1, 1), (1200, 1, 1), (1300, 1, 1)),
                          2000: ((2000, 1, 0), (2100, 1, 1), (2200, 1, 1), (2300, 1, 1)),
                          3000: ((3000, 1, 0), (3100, 1, 1), (3200, 1, 1), (3300, 1, 1)),
                          4000: ((4000, 1, 0), (4100, 1, 1), (4200, 1, 1), (4300, 1, 1)),
                          5000: ((5000, 1, 0), (5100, 1, 1), (5200, 1, 1), (5300, 1, 1)),
                          9000: ((9000, 1, 0), (9100, 1, 1), (9200, 1, 1)),
                          
                          6000: (),
                          7000: ((7000, 1, 0), (7100, 1, 1)), # XXX to do: planner at 7100
                          8000: ((8000, 1, 0),),
                          10000: (),
                          11000: (),
                          12000: (),
                          13000: (),
                          17000: (),
                         }
        
        self.__nextHood(0)
                         
    def __nextHood(self, hoodIndex):
        if hoodIndex >= len(hoods):
            self.__ready()
            return Task.done
                         
        self.hoods.append(hoods[hoodIndex](self))
        taskMgr.doMethodLater(0, ToontownAIRepository.__nextHood, 'nextHood', [self, hoodIndex + 1])
        return Task.done

    def genDNAFileName(self, zoneId):
        zoneId = ZoneUtil.getCanonicalZoneId(zoneId)
        hoodId = ZoneUtil.getCanonicalHoodId(zoneId)
        hood = ToontownGlobals.dnaMap[hoodId]
        if hoodId == zoneId:
            zoneId = 'sz'
            phase = ToontownGlobals.phaseMap[hoodId]
        else:
            phase = ToontownGlobals.streetPhaseMap[hoodId]

        return 'phase_%s/dna/%s_%s.dna' % (phase, hood, zoneId)

    def loadDNAFileAI(self, dnastore, filename):
        if self.use_libpandadna:
            f = Filename('../resources/' + str(filename))
            f.setExtension('pdna')
            x = self.__loader.loadDNAFileAI(dnastore, f)
            
        else:
            f = Filename(filename)
            f = Filename('etc/dnabkp/' + f.getBasename())
            x = loadDNAFileAI(dnastore, str(f))
        
        return x

    def sendSetZone(self, obj, zoneId):
        obj.b_setLocation(obj.parentId, zoneId)
        
    def getDisconnectReason(self, avId):
        return self.timeManager.disconnectReasonMap.get(avId, 1) # Default: user closed window
        
    def killToon(self, avId, force = True):
        """
        Kills given toon if within this shard.
        If force is False, then checks getDisconnectReason.
        """
        toon = self.doId2do.get(avId)
        
        if not toon:
            self.notify.warning("Tried to kill non-existing toon %s" % avId)
            return False
            
        if not force:
            if self.getDisconnectReason(avId) == 3: # Python Error
                return False
            
        toon.b_setHp(0)
        
        inventory = toon.inventory
        inventory.zeroInv()
        toon.b_setInventory(inventory.makeNetString())
        
        self.notify.info("Killed toon %s, RIP!" % avId)
        return True
        
    def handleObjExit(self, di):
        doId = di.getUint32()

        if doId not in self.doId2do:
            self.notify.warning('Received AI exit for unknown object %d' % (doId))
            return

        do = self.doId2do[doId]
        do.sendDeleteEvent()
        self.removeDOFromTables(do)
        do.delete()
コード例 #4
0
    def createObjects(self):
        # First, load up all of our DNA files for the world.
        self.loadDNA()

        # Create a new district (aka shard) for this AI:
        self.district = ToontownDistrictAI(self, self.districtName)
        self.district.generateOtpObject(OTP_DO_ID_TOONTOWN,
                                        OTP_ZONE_ID_DISTRICTS,
                                        doId=self.districtId)

        # The Time manager.  This negotiates a timestamp exchange for
        # the purposes of synchronizing clocks between client and
        # server with a more accurate handshaking protocol than we
        # would otherwise get.
        #
        # We must create this object first, so clients who happen to
        # come into the world while the AI is still coming up
        # (particularly likely if the AI crashed while players were
        # in) will get a chance to synchronize.
        self.timeManager = TimeManagerAI.TimeManagerAI(self)
        self.timeManager.generateOtpObject(self.district.getDoId(),
                                           OTPGlobals.UberZone)

        self.partyManager = DistributedPartyManagerAI.DistributedPartyManagerAI(
            self)
        self.partyManager.generateOtpObject(self.district.getDoId(),
                                            OTPGlobals.UberZone)

        self.inGameNewsMgr = DistributedInGameNewsMgrAI.DistributedInGameNewsMgrAI(
            self)
        self.inGameNewsMgr.generateOtpObject(self.district.getDoId(),
                                             OTPGlobals.UberZone)

        self.whitelistMgr = DistributedWhitelistMgrAI.DistributedWhitelistMgrAI(
            self)
        self.whitelistMgr.generateOtpObject(self.district.getDoId(),
                                            OTPGlobals.UberZone)

        self.cpuInfoMgr = DistributedCpuInfoMgrAI.DistributedCpuInfoMgrAI(self)
        self.cpuInfoMgr.generateOtpObject(self.district.getDoId(),
                                          OTPGlobals.UberZone)

        #self.securityMgr = DistributedSecurityMgrAI.DistributedSecurityMgrAI(self)
        #self.securityMgr.generateOtpObject(self.district.getDoId(), OTPGlobals.UberZone)

        #if ConfigVariableBool('want-code-redemption', 1).getValue():
        #    self.codeRedemptionManager = TTCodeRedemptionMgrAI(self)
        #    self.codeRedemptionManager.generateOtpObject(self.district.getDoId(), OTPGlobals.UberZone)

        self.randomSourceManager = NonRepeatableRandomSourceAI(self)
        # QuietZone so that the client doesn't get a generate
        self.randomSourceManager.generateOtpObject(self.district.getDoId(),
                                                   OTPGlobals.QuietZone)

        self.welcomeValleyManager = WelcomeValleyManagerAI.WelcomeValleyManagerAI(
            self)
        self.welcomeValleyManager.generateWithRequired(OTPGlobals.UberZone)

        # The trophy manager should be created before the building
        # managers.
        self.trophyMgr = DistributedTrophyMgrAI.DistributedTrophyMgrAI(self)
        self.trophyMgr.generateWithRequired(OTPGlobals.UberZone)

        # The bank manager handles banking transactions
        self.bankMgr = DistributedBankMgrAI.DistributedBankMgrAI(self)
        self.bankMgr.generateWithRequired(OTPGlobals.UberZone)

        # The Friend Manager
        self.friendManager = FriendManagerAI.FriendManagerAI(self)
        self.friendManager.generateWithRequired(OTPGlobals.UberZone)

        # The Delete Manager
        self.deleteManager = DeleteManagerAI.DeleteManagerAI(self)
        self.deleteManager.generateWithRequired(OTPGlobals.UberZone)

        # The Safe Zone manager
        self.safeZoneManager = SafeZoneManagerAI.SafeZoneManagerAI(self)
        self.safeZoneManager.generateWithRequired(OTPGlobals.UberZone)

        # The Magic Word Manager
        magicWordString = ConfigVariableString('want-magic-words',
                                               '1').getValue()
        if magicWordString not in ('', '0', '#f'):
            self.magicWordManager = ToontownMagicWordManagerAI.ToontownMagicWordManagerAI(
                self)
            self.magicWordManager.generateWithRequired(OTPGlobals.UberZone)

        # The Tutorial manager
        self.tutorialManager = TutorialManagerAI.TutorialManagerAI(self)
        self.tutorialManager.generateWithRequired(OTPGlobals.UberZone)

        # The Catalog Manager
        self.catalogManager = CatalogManagerAI.CatalogManagerAI(self)
        self.catalogManager.generateWithRequired(OTPGlobals.UberZone)

        # The Quest manager
        self.questManager = QuestManagerAI.QuestManagerAI(self)

        # The Fish manager
        self.fishManager = FishManagerAI.FishManagerAI(self)

        # The Cog Page manager
        self.cogPageManager = CogPageManagerAI.CogPageManagerAI(self)

        # The Suit Invasion Manager
        self.suitInvasionManager = SuitInvasionManagerAI.SuitInvasionManagerAI(
            self)

        # The Firework Manager: This object really only exists so we can
        # fire off fireworks with magic words. Normally this is a holiday
        # manager driven event and therefore the constructor needs a
        # holidayId. Pass in fourth of july as default.  To do: override
        # holiday ID with a magic word
        self.fireworkManager = FireworkManagerAI.FireworkManagerAI(
            self, NEWYEARS_FIREWORKS)

        # Create an NPC Dialogue manager that manages conversations
        # amongst a set of NPC's
        self.dialogueManager = NPCDialogueManagerAI.NPCDialogueManagerAI()

        # The News manager
        self.newsManager = NewsManagerAI.NewsManagerAI(self)
        self.newsManager.generateWithRequired(OTPGlobals.UberZone)

        # The Factory Manager
        self.factoryMgr = FactoryManagerAI.FactoryManagerAI(self)

        # The Mint Manager
        self.mintMgr = MintManagerAI.MintManagerAI(self)

        #the Law Office Manager
        self.lawMgr = LawOfficeManagerAI.LawOfficeManagerAI(self)

        # The Cog Country Club Manager
        self.countryClubMgr = CountryClubManagerAI.CountryClubManagerAI(self)

        if simbase.wantKarts:
            # The Race Manager
            self.raceMgr = RaceManagerAI.RaceManagerAI(self)

        self.cogSuitMgr = CogSuitManagerAI.CogSuitManagerAI(self)
        self.promotionMgr = PromotionManagerAI.PromotionManagerAI(self)

        # Housing
        self.estateMgr = EstateManagerAI.EstateManagerAI(self)
        self.estateMgr.generateWithRequired(OTPGlobals.UberZone)

        if simbase.wantPets:
            # Pets -- must be created after estateMgr
            self.petMgr = PetManagerAI.PetManagerAI(self)

        # Now create the neighborhood-specific objects.
        self.startupHood(TTHoodDataAI.TTHoodDataAI(self))
        self.startupHood(DDHoodDataAI.DDHoodDataAI(self))
        self.startupHood(MMHoodDataAI.MMHoodDataAI(self))
        self.startupHood(DGHoodDataAI.DGHoodDataAI(self))
        self.startupHood(BRHoodDataAI.BRHoodDataAI(self))
        self.startupHood(DLHoodDataAI.DLHoodDataAI(self))
        self.startupHood(CSHoodDataAI.CSHoodDataAI(self))
        self.startupHood(GSHoodDataAI.GSHoodDataAI(self))
        self.startupHood(OZHoodDataAI.OZHoodDataAI(self))
        self.startupHood(GZHoodDataAI.GZHoodDataAI(self))
        self.startupHood(CashbotHQDataAI.CashbotHQDataAI(self))
        self.startupHood(LawbotHQDataAI.LawbotHQDataAI(self))
        self.startupHood(BossbotHQDataAI.BossbotHQDataAI(self))

        # The Holiday Manager should be instantiated after the each
        # of the hoods and estateMgrAI are generated because Bingo Night
        # needs to reference the HoodDataAI and EstateMgrAI for pond
        # information. (JJT - 7/22/04)
        self.holidayManager = HolidayManagerAI.HolidayManagerAI(self)

        self.banManager = BanManagerAI.BanManagerAI()

        # Now that we've created all the suit planners, any one of
        # them can be used to fill the world with requests for suit
        # buildings.
        if self.suitPlanners:
            list(self.suitPlanners.values())[0].assignInitialSuitBuildings()

        # mark district as avaliable
        self.district.b_setAvailable(1)

        # Now that everything's created, start checking the leader
        # boards for correctness.  We only need to check every 30
        # seconds or so.
        self.__leaderboardFlush(None)
        taskMgr.doMethodLater(30,
                              self.__leaderboardFlush,
                              'leaderboardFlush',
                              appendTask=True)
コード例 #5
0
class ToontownAIRepository(ToontownInternalRepository):
    def __init__(self, baseChannel, serverId, districtName):
        ToontownInternalRepository.__init__(self,
                                            baseChannel,
                                            serverId,
                                            dcSuffix='AI')

        self.districtName = districtName

        self.zoneAllocator = UniqueIdAllocator(
            ToontownGlobals.DynamicZonesBegin, ToontownGlobals.DynamicZonesEnd)

        NPCToons.generateZone2NpcDict()

        self.use_libpandadna = simbase.config.GetBool('use-libpandadna', False)

        self.hoods = []
        self._dnaStoreMap = {}

        if self.use_libpandadna:
            self.__loader = DNALoader()

        self.zoneDataStore = AIZoneDataStore()

        self.useAllMinigames = self.config.GetBool('want-all-minigames', False)
        self.doLiveUpdates = True

        self.wantCogdominiums = self.config.GetBool('want-cogdo', False)
        self.wantParties = self.config.GetBool('want-parties', False)
        self.wantEmblems = self.config.GetBool('want-emblems', True)

        self.questManager = QuestManagerAI(self)
        self.promotionMgr = PromotionManagerAI(self)
        self.cogPageManager = CogPageManagerAI(self)
        self.cogSuitMgr = CogSuitManagerAI(self)

        self.trophyMgr = DistributedTrophyMgrAI(self)

        self.fishManager = FishManagerAI()

        self.dnaStoreMap = {}

        self.mintMgr = MintManagerAI.MintManagerAI(self)
        self.factoryMgr = FactoryManagerAI.FactoryManagerAI(self)
        self.lawMgr = LawOfficeManagerAI.LawOfficeManagerAI(self)
        self.countryClubMgr = CountryClubManagerAI.CountryClubManagerAI(self)

        self.buildingManagers = {}
        self.suitPlanners = {}

        self.wantMegaInvasions = str(
            self.ourChannel // 1000000) in self.config.GetString(
                'mega-invasion-shards', '402 403').split()

    def getTrackClsends(self):
        return False

    def handleConnected(self):
        self.districtId = self.allocateChannel()
        self.distributedDistrict = ToontownDistrictAI(self)
        self.distributedDistrict.setName(self.districtName)
        self.distributedDistrict.generateWithRequiredAndId(
            simbase.air.districtId, self.getGameDoId(), 2)

        dg = PyDatagram()
        dg.addServerHeader(simbase.air.districtId, simbase.air.ourChannel,
                           STATESERVER_OBJECT_SET_AI)
        dg.addChannel(simbase.air.ourChannel)
        simbase.air.send(dg)

        self.createGlobals()
        self.createZones()

    def __ready(self):
        dg = PyDatagram()
        dg.addServerHeader(self.districtStats.doId, self.ourChannel,
                           STATESERVER_OBJECT_DELETE_RAM)
        dg.addUint32(self.districtStats.doId)
        self.addPostRemove(dg)

        self.apiMgr = self.generateGlobalObject(100001, "ShardAPIManager")
        self.apiMgr.start()
        self.apiMgr.d_setShardData()

        self.banMgr = self.generateGlobalObject(100002, "BanManager")

        self.trophyMgr.updateToonData()

    def gotUberdogAPISync(self):
        if not self.distributedDistrict.getAvailable():
            self.notify.info("Got UD API sync, opening shard...")
            messenger.send("startShardActivity")
            self.distributedDistrict.b_setAvailable(1)

    def incrementPopulation(self):
        self.districtStats.b_setAvatarCount(
            self.districtStats.getAvatarCount() + 1)

    def decrementPopulation(self):
        self.districtStats.b_setAvatarCount(
            self.districtStats.getAvatarCount() - 1)

    def allocateZone(self):
        return self.zoneAllocator.allocate()

    def deallocateZone(self, zone):
        self.zoneAllocator.free(zone)

    def getZoneDataStore(self):
        return self.zoneDataStore

    def getAvatarExitEvent(self, avId):
        return 'distObjDelete-%d' % avId

    def createGlobals(self):
        self.districtStats = ToontownDistrictStatsAI(self)
        self.districtStats.settoontownDistrictId(self.districtId)
        self.districtStats.generateWithRequiredAndId(self.allocateChannel(),
                                                     self.getGameDoId(), 2)

        self.timeManager = TimeManagerAI(self)
        self.timeManager.generateWithRequired(2)

        self.newsManager = NewsManagerAI(self)
        self.newsManager.generateWithRequired(2)

        self.holidayManager = HolidayManagerAI(self)

        self.magicWordManager = MagicWordManagerAI(self)
        self.magicWordManager.generateWithRequired(2)

        self.safeZoneManager = SafeZoneManagerAI(self)
        self.safeZoneManager.generateWithRequired(2)

        self.petMgr = PetManagerAI(self)

        self.friendManager = FriendManagerAI(self)
        self.friendManager.generateWithRequired(2)

        self.partyManager = DistributedPartyManagerAI(self)
        self.partyManager.generateWithRequired(2)

        self.tutorialManager = TutorialManagerAI(self)
        self.tutorialManager.generateWithRequired(2)

        self.globalPartyMgr = self.generateGlobalObject(
            OTP_DO_ID_GLOBAL_PARTY_MANAGER, 'GlobalPartyManager')

        self.estateManager = EstateManagerAI(self)
        self.estateManager.generateWithRequired(2)

        self.suitInvasionManager = DistributedSuitInvasionManagerAI(self)
        self.suitInvasionManager.generateWithRequired(2)

        self.bankMgr = DistributedBankMgrAI(self)
        self.bankMgr.generateWithRequired(2)

        self.catalogManager = CatalogManagerAI(self)
        self.catalogManager.generateWithRequired(2)

        self.huntId = 0

        if self.holidayManager.isHolidayRunning(
                ToontownGlobals.TRICK_OR_TREAT):
            import DistributedTrickOrTreatTargetAI
            self.trickOrTreatMgr = DistributedTrickOrTreatTargetAI.DistributedTrickOrTreatTargetAI(
                self)
            self.trickOrTreatMgr.generateWithRequired(2)

        self.handleBlackCatMgr()
        self.handleBloodsuckerInvasion()
        self.handleSkelCogWeekInvasion()

        if config.GetBool('want-resistance-emote', True):
            self.resistanceMgr = DistributedResistanceEmoteMgrAI.DistributedResistanceEmoteMgrAI(
                self)
            self.resistanceMgr.generateWithRequired(9720)

        if config.GetBool('want-top-toons', True):
            self.topToonsMgr = self.generateGlobalObject(
                OTP_DO_ID_TOONTOWN_TOP_TOONS_MGR, 'DistributedTopToonsManager')

        else:
            self.topToonsMgr = None

        if config.GetBool('want-polar-effect', True):
            self.polarMgr = DistributedPolarPlaceEffectMgrAI.DistributedPolarPlaceEffectMgrAI(
                self)
            self.polarMgr.generateWithRequired(3821)

    def handleBlackCatMgr(self):
        today = datetime.datetime.now()
        start = datetime.datetime(today.year, 10, 31)
        end = datetime.datetime(today.year, 11, 3)

        def createBlackCatMgr(task=None):
            import DistributedBlackCatMgrAI
            self.blackCatMgr = DistributedBlackCatMgrAI.DistributedBlackCatMgrAI(
                self)
            self.blackCatMgr.generateWithRequired(2513)
            if not self.config.GetBool('force-black-cat-mgr', False):
                self.blackCatMgr.expire((end - today).total_seconds())
            return Task.done

        if start <= today < end or self.config.GetBool('force-black-cat-mgr',
                                                       False):
            createBlackCatMgr(None)

        elif start >= today:
            taskMgr.doMethodLater((start - today).total_seconds(),
                                  createBlackCatMgr, 'air-createBlackCatMgr')

    def handleBloodsuckerInvasion(self):
        if not self.wantMegaInvasions:
            return

        today = datetime.datetime.now()
        start = datetime.datetime(today.year, 10, 31)
        end = datetime.datetime(today.year, 11, 3)

        if start <= today < end:
            self.startMegaInvasion(9, end=end)

        elif start > today:
            taskMgr.doMethodLater((start - today).total_seconds(),
                                  self.startMegaInvasion,
                                  'air-mega-invasion-9',
                                  extraArgs=[9, False, end])

    def handleSkelCogWeekInvasion(self):
        if not self.wantMegaInvasions:
            return

        today = datetime.datetime.now()
        start = datetime.datetime(2014, 11, 10)
        end = datetime.datetime(2014, 11, 17)

        if start <= today < end:
            self.startMegaInvasion(-1, skel=True, end=end)

        elif start > today:
            taskMgr.doMethodLater((start - today).total_seconds(),
                                  self.startMegaInvasion,
                                  'air-mega-invasion-skel',
                                  extraArgs=[-1, True, end])

    def startMegaInvasion(self, suitIndex, skel=False, end=None):
        if suitIndex >= 0:
            suitName = SuitDNA.suitHeadTypes[suitIndex]

        else:
            suitName = None

        if self.suitInvasionManager.hasInvading():
            if self.suitInvasionManager.isMega():
                return Task.done

            self.suitInvasionManager.abort()

        self.suitInvasionManager.startInvasion(suitName, skel, mega=True)
        if end:

            def doAbort(task):
                self.suitInvasionManager.abort()
                return task.done

            today = datetime.datetime.now()
            taskMgr.doMethodLater((end - today).total_seconds(), doAbort,
                                  'air-abort-mega-invasion')

    def getStorage(self, zone):
        s = self._dnaStoreMap.get(zone)
        if not s:
            s = DNAStorage()
            self.loadDNAFileAI(s, self.genDNAFileName(zone))
            self._dnaStoreMap[zone] = s

        return s

    def createZones(self):
        self.zoneTable = {
            1000: ((1000, 1, 0), (1100, 1, 1), (1200, 1, 1), (1300, 1, 1)),
            2000: ((2000, 1, 0), (2100, 1, 1), (2200, 1, 1), (2300, 1, 1)),
            3000: ((3000, 1, 0), (3100, 1, 1), (3200, 1, 1), (3300, 1, 1)),
            4000: ((4000, 1, 0), (4100, 1, 1), (4200, 1, 1), (4300, 1, 1)),
            5000: ((5000, 1, 0), (5100, 1, 1), (5200, 1, 1), (5300, 1, 1)),
            9000: ((9000, 1, 0), (9100, 1, 1), (9200, 1, 1)),
            6000: (),
            7000: ((7000, 1, 0), (7100, 1, 1)),  # XXX to do: planner at 7100
            8000: ((8000, 1, 0), ),
            10000: (),
            11000: (),
            12000: (),
            13000: (),
            17000: (),
        }

        self.__nextHood(0)

    def __nextHood(self, hoodIndex):
        if hoodIndex >= len(hoods):
            self.__ready()
            return Task.done

        self.hoods.append(hoods[hoodIndex](self))
        taskMgr.doMethodLater(0, ToontownAIRepository.__nextHood, 'nextHood',
                              [self, hoodIndex + 1])
        return Task.done

    def genDNAFileName(self, zoneId):
        zoneId = ZoneUtil.getCanonicalZoneId(zoneId)
        hoodId = ZoneUtil.getCanonicalHoodId(zoneId)
        hood = ToontownGlobals.dnaMap[hoodId]
        if hoodId == zoneId:
            zoneId = 'sz'
            phase = ToontownGlobals.phaseMap[hoodId]
        else:
            phase = ToontownGlobals.streetPhaseMap[hoodId]

        return 'phase_%s/dna/%s_%s.dna' % (phase, hood, zoneId)

    def loadDNAFileAI(self, dnastore, filename):
        if self.use_libpandadna:
            f = Filename('../resources/' + str(filename))
            f.setExtension('pdna')
            x = self.__loader.loadDNAFileAI(dnastore, f)

        else:
            f = Filename(filename)
            f = Filename('etc/dnabkp/' + f.getBasename())
            x = loadDNAFileAI(dnastore, str(f))

        return x

    def sendSetZone(self, obj, zoneId):
        obj.b_setLocation(obj.parentId, zoneId)

    def getDisconnectReason(self, avId):
        return self.timeManager.disconnectReasonMap.get(
            avId, 1)  # Default: user closed window

    def killToon(self, avId, force=True):
        """
        Kills given toon if within this shard.
        If force is False, then checks getDisconnectReason.
        """
        toon = self.doId2do.get(avId)

        if not toon:
            self.notify.warning("Tried to kill non-existing toon %s" % avId)
            return False

        if not force:
            if self.getDisconnectReason(avId) == 3:  # Python Error
                return False

        toon.b_setHp(0)

        inventory = toon.inventory
        inventory.zeroInv()
        toon.b_setInventory(inventory.makeNetString())

        self.notify.info("Killed toon %s, RIP!" % avId)
        return True

    def handleObjExit(self, di):
        doId = di.getUint32()

        if doId not in self.doId2do:
            self.notify.warning('Received AI exit for unknown object %d' %
                                (doId))
            return

        do = self.doId2do[doId]
        do.sendDeleteEvent()
        self.removeDOFromTables(do)
        do.delete()