示例#1
0
    def createManagers(self):
        self.districtStats = DistributedPopulationTrackerAI(self, populationMin=100, populationMax=700)
        self.districtStats.generateWithRequiredAndId(
            self.allocateChannel(), self.getGameDoId(), 4)
        self.districtStats.b_setShardId(self.distributedDistrict.getDoId())

        self.DistributedTimeOfDayManager = DistributedTimeOfDayManagerAI(self, isPaused=False, isJolly=0)
        self.DistributedTimeOfDayManager.generateWithRequired(3)

        self.DistributedPirateProfileMgr = DistributedPirateProfileMgrAI(self)
        self.DistributedPirateProfileMgr.generateWithRequired(3)

        self.worldManager = WorldManagerAI(self) #TODO: Generate the rest of the islands!
        self.portRoyal = self.worldManager.loadObjectsFromFile(filename="PortRoyalWorld.py")
        self.tortuga = self.worldManager.loadObjectsFromFile(filename="TortugaWorld.py")
        self.islaCangrejos = self.worldManager.loadObjectsFromFile(filename="CangrejosIsland.py")
        self.kingsHead = self.worldManager.loadObjectsFromFile(filename="KingsheadWorld.py")
        self.cuba = self.worldManager.loadObjectsFromFile(filename="CubaWorld.py")
        self.islaRumrunner = self.worldManager.loadObjectsFromFile(filename="RumrunnerWorld.py")
        self.anvilIsland = self.worldManager.loadObjectsFromFile(filename="AnvilIsland.py")
        self.islaTormenta = self.worldManager.loadObjectsFromFile(filename="TormentaIsland.py")

        # Tutorial:
        self.rambleShackIsland = self.worldManager.loadObjectsFromFile(filename="RambleshackWorld.py")

        self.tutorialObject = DistributedPiratesTutorialAI(self)
        self.tutorialObject.generateWithRequired(3)
    def createGlobals(self):
        """
        Create "global" objects, e.g. TimeManager et al.
        """

        self.centralLogger = self.generateGlobalObject(OTP_DO_ID_CENTRAL_LOGGER, 'CentralLogger')

        self.populationTracker = DistributedPopulationTrackerAI(self)
        self.populationTracker.setShardId(self.districtId)
        self.populationTracker.setPopLimits(config.GetInt('shard-pop-limit-low', 100), config.GetInt('shard-pop-limit-high', 300))
        self.populationTracker.generateWithRequiredAndId(self.allocateChannel(), self.getGameDoId(), OTP_ZONE_ID_DISTRICTS_STATS)

        self.timeManager = PiratesTimeManagerAI(self)
        self.timeManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.travelAgent = self.generateGlobalObject(OTP_DO_ID_PIRATES_TRAVEL_AGENT, 'DistributedTravelAgent')

        self.teleportMgr = DistributedTeleportMgrAI(self)
        self.teleportMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.timeOfDayMgr = DistributedTimeOfDayManagerAI(self)
        self.timeOfDayMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

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

        self.holidayMgr = self.generateGlobalObject(OTP_DO_ID_PIRATES_HOLIDAY_MANAGER, 'HolidayManager')

        self.gameStatManager = DistributedGameStatManagerAI(self)
        self.gameStatManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.targetMgr = TargetManagerAI(self)
        self.targetMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.spawner = DistributedEnemySpawnerAI(self)
        self.spawner.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.inventoryManager = self.generateGlobalObject(OTP_DO_ID_PIRATES_INVENTORY_MANAGER, 'DistributedInventoryManager')

        self.magicWords = PiratesMagicWordManagerAI(self)
        self.magicWords.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.tradeMgr = TradeManagerAI(self)
        self.tradeMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.crewMatchManager = self.generateGlobalObject(OTP_DO_ID_PIRATES_CREW_MATCH_MANAGER, 'DistributedCrewMatchManager')

        self.guildManager = self.generateGlobalObject(OTP_DO_ID_PIRATES_GUILD_MANAGER, 'PCGuildManager')
示例#3
0
class PiratesAIRepository(PiratesInternalRepository):
    
    def __init__(self, baseChannel, stateServerChannel, districtName):
        PiratesInternalRepository.__init__(
            self, baseChannel, stateServerChannel, dcSuffix='AI')

        self.notify.setInfo(True)
        self.districtName = districtName
        self.zoneAllocator = UniqueIdAllocator(PiratesGlobals.DynamicZonesBegin,
                                                PiratesGlobals.DynamicZonesEnd)

    def createManagers(self):
        self.districtStats = DistributedPopulationTrackerAI(self, populationMin=100, populationMax=700)
        self.districtStats.generateWithRequiredAndId(
            self.allocateChannel(), self.getGameDoId(), 4)
        self.districtStats.b_setShardId(self.distributedDistrict.getDoId())

        self.DistributedTimeOfDayManager = DistributedTimeOfDayManagerAI(self, isPaused=False, isJolly=0)
        self.DistributedTimeOfDayManager.generateWithRequired(3)

        self.DistributedPirateProfileMgr = DistributedPirateProfileMgrAI(self)
        self.DistributedPirateProfileMgr.generateWithRequired(3)

        self.worldManager = WorldManagerAI(self) #TODO: Generate the rest of the islands!
        self.portRoyal = self.worldManager.loadObjectsFromFile(filename="PortRoyalWorld.py")
        self.tortuga = self.worldManager.loadObjectsFromFile(filename="TortugaWorld.py")
        self.islaCangrejos = self.worldManager.loadObjectsFromFile(filename="CangrejosIsland.py")
        self.kingsHead = self.worldManager.loadObjectsFromFile(filename="KingsheadWorld.py")
        self.cuba = self.worldManager.loadObjectsFromFile(filename="CubaWorld.py")
        self.islaRumrunner = self.worldManager.loadObjectsFromFile(filename="RumrunnerWorld.py")
        self.anvilIsland = self.worldManager.loadObjectsFromFile(filename="AnvilIsland.py")
        self.islaTormenta = self.worldManager.loadObjectsFromFile(filename="TormentaIsland.py")

        # Tutorial:
        self.rambleShackIsland = self.worldManager.loadObjectsFromFile(filename="RambleshackWorld.py")

        self.tutorialObject = DistributedPiratesTutorialAI(self)
        self.tutorialObject.generateWithRequired(3)

    def handleConnected(self):
        self.districtId = self.allocateChannel()
        self.distributedDistrict = PiratesDistrictAI(self, mainWorld="PortRoyalWorld.py", shardType=PiratesGlobals.SHARD_MAIN)
        self.distributedDistrict.setName(self.districtName)
        self.distributedDistrict.generateWithRequiredAndId(
            self.districtId, self.getGameDoId(), 3)
        self.notify.info('Claiming ownership of channel ID: %d...' % self.districtId)
        self.claimOwnership(self.districtId)

        self.notify.info('Creating managers...')
        self.createManagers()

        self.notify.info('Making district available...')
        self.distributedDistrict.b_setAvailable(1)
        self.notify.info('Done.')

    def claimOwnership(self, channelId):
        datagram = PyDatagram()
        datagram.addServerHeader(channelId, self.ourChannel, STATESERVER_OBJECT_SET_AI)
        datagram.addChannel(self.ourChannel)
        self.send(datagram)

    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)
class PiratesAIRepository(PiratesInternalRepository):
    notify = directNotify.newCategory('PiratesAIRepository')
    notify.setInfo(True)

    def __init__(self, baseChannel, serverId, districtName):
        PiratesInternalRepository.__init__(self, baseChannel, serverId, dcSuffix='AI')

        self.districtName = districtName
        self.zoneAllocator = UniqueIdAllocator(PiratesGlobals.DynamicZonesBegin, PiratesGlobals.DynamicZonesEnd)
        self.zoneId2owner = {}
        self.uidMgr = UniqueIdManager(self)

    def handleConnected(self):
        PiratesInternalRepository.handleConnected(self)
        self.districtId = self.allocateChannel()
        self.distributedDistrict = PiratesDistrictAI(self)
        self.distributedDistrict.setName(self.districtName)
        self.distributedDistrict.setMainWorld(WorldGlobals.PiratesWorldSceneFile)
        self.distributedDistrict.generateWithRequiredAndId(self.districtId, self.getGameDoId(), 2)
        self.setAI(self.districtId, self.ourChannel)

        self.createGlobals()
        self.createZones()

        self.distributedDistrict.b_setAvailable(1)
        self.notify.info('District (%s) is now ready.' % self.districtName)
        messenger.send('district-ready')

    def incrementPopulation(self):
        self.populationTracker.b_setPopulation(self.populationTracker.getPopulation() + 1)

    def decrementPopulation(self):
        self.populationTracker.b_setPopulation(self.populationTracker.getPopulation() - 1)

    def allocateZone(self, owner=None):
        zoneId = self.zoneAllocator.allocate()
        if owner:
            self.zoneId2owner[zoneId] = owner

        return zoneId

    def deallocateZone(self, zone):
        if self.zoneId2owner.get(zone):
            del self.zoneId2owner[zone]

        self.zoneAllocator.free(zone)

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

    def createGlobals(self):
        """
        Create "global" objects, e.g. TimeManager et al.
        """

        self.centralLogger = self.generateGlobalObject(OTP_DO_ID_CENTRAL_LOGGER, 'CentralLogger')

        self.populationTracker = DistributedPopulationTrackerAI(self)
        self.populationTracker.setShardId(self.districtId)
        self.populationTracker.setPopLimits(config.GetInt('shard-pop-limit-low', 100), config.GetInt('shard-pop-limit-high', 300))
        self.populationTracker.generateWithRequiredAndId(self.allocateChannel(), self.getGameDoId(), OTP_ZONE_ID_DISTRICTS_STATS)

        self.timeManager = PiratesTimeManagerAI(self)
        self.timeManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.travelAgent = self.generateGlobalObject(OTP_DO_ID_PIRATES_TRAVEL_AGENT, 'DistributedTravelAgent')

        self.teleportMgr = DistributedTeleportMgrAI(self)
        self.teleportMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.timeOfDayMgr = DistributedTimeOfDayManagerAI(self)
        self.timeOfDayMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

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

        self.holidayMgr = self.generateGlobalObject(OTP_DO_ID_PIRATES_HOLIDAY_MANAGER, 'HolidayManager')

        self.gameStatManager = DistributedGameStatManagerAI(self)
        self.gameStatManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.targetMgr = TargetManagerAI(self)
        self.targetMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.spawner = DistributedEnemySpawnerAI(self)
        self.spawner.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.inventoryManager = self.generateGlobalObject(OTP_DO_ID_PIRATES_INVENTORY_MANAGER, 'DistributedInventoryManager')

        self.magicWords = PiratesMagicWordManagerAI(self)
        self.magicWords.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.tradeMgr = TradeManagerAI(self)
        self.tradeMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)

        self.crewMatchManager = self.generateGlobalObject(OTP_DO_ID_PIRATES_CREW_MATCH_MANAGER, 'DistributedCrewMatchManager')

        self.guildManager = self.generateGlobalObject(OTP_DO_ID_PIRATES_GUILD_MANAGER, 'PCGuildManager')

    def createZones(self):
        """
        Create "zone" objects, e.g. DistributedOceanGrid et al.
        """

        self.worldCreator = WorldCreatorAI(self)
        self.worldCreator.loadObjectsFromFile(WorldGlobals.PiratesWorldSceneFile)