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 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 handleConnected(self): self.districtId = self.allocateChannel() self.notify.info('Creating PiratesDistrictAI(%d)...' % self.districtId) self.distributedDistrict = PiratesDistrictAI(self) self.distributedDistrict.setName(self.districtName) self.distributedDistrict.generateWithRequiredAndId( self.districtId, OTP_DO_ID_PIRATES, OTP_ZONE_ID_DISTRICTS) 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.')
class PiratesAIRepository(PiratesInternalRepository): def __init__(self, baseChannel, stateServerChannel, districtName): PiratesInternalRepository.__init__(self, baseChannel, stateServerChannel, dcSuffix='AI') self.districtName = districtName self.notify.setInfo(True) def createManagers(self): self.timeManager = TimeManagerAI(self) self.timeManager.generateWithRequired(2) def handleConnected(self): self.districtId = self.allocateChannel() self.notify.info('Creating PiratesDistrictAI(%d)...' % self.districtId) self.distributedDistrict = PiratesDistrictAI(self) self.distributedDistrict.setName(self.districtName) self.distributedDistrict.generateWithRequiredAndId( self.districtId, OTP_DO_ID_PIRATES, OTP_ZONE_ID_DISTRICTS) 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)
class PiratesAIRepository(PiratesInternalRepository): def __init__(self, baseChannel, stateServerChannel, districtName): PiratesInternalRepository.__init__( self, baseChannel, stateServerChannel, dcSuffix='AI') self.districtName = districtName self.notify.setInfo(True) def createManagers(self): self.timeManager = TimeManagerAI(self) self.timeManager.generateWithRequired(2) def handleConnected(self): self.districtId = self.allocateChannel() self.notify.info('Creating PiratesDistrictAI(%d)...' % self.districtId) self.distributedDistrict = PiratesDistrictAI(self) self.distributedDistrict.setName(self.districtName) self.distributedDistrict.generateWithRequiredAndId( self.districtId, OTP_DO_ID_PIRATES, OTP_ZONE_ID_DISTRICTS) 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 setupDistrict(self): self.distributedDistrict = PiratesDistrictAI(self) self.distributedDistrict.setName(self.districtName) self.distributedDistrict.generateWithRequiredAndId(self.districtId, OTP_DO_ID_PIRATES, OTP_ZONE_ID_DISTRICTS)
class PiratesAIRepository(PiratesInternalRepository): def __init__(self, baseChannel, stateServerChannel, districtName): PiratesInternalRepository.__init__(self, baseChannel, stateServerChannel, dcSuffix='AI') self.districtName = districtName self.notify.setInfo(True) def createManagers(self): self.timeManager = PiratesTimeManagerAI(self) self.timeManager.generateWithRequired(2) self.magicWordManager = PiratesMagicWordManagerAI(self) self.magicWordManager.generateWithRequired(2) self.holidayManager = HolidayManagerAI(self) self.newsManager = NewsManagerAI(self) self.newsManager.generateWithRequired(2) if self.config.GetBool('want-tutorial', 0): self.tutorialManager = PiratesTutorialManagerAI(self) self.tutorialManager.generateWithRequired(2) self.avatarManager = DistributedAvatarManagerAI(self) self.inventoryManager = DistributedInventoryManagerAI() self.shipLoader = DistributedShipLoaderAI(self) def createMainWorld(self): self.worldCreator = WorldCreatorAI(self) self.mainWorld = DistributedMainWorldAI(self) #self.mainWorld.generateInstance() #self.distributedDistrict.b_setMainWorld(self.mainWorld) #self.worldCreator.makeMainWorld(self.distributedDistrict.getMainWorld) def setupDistrict(self): self.distributedDistrict = PiratesDistrictAI(self) self.distributedDistrict.setName(self.districtName) self.distributedDistrict.generateWithRequiredAndId(self.districtId, OTP_DO_ID_PIRATES, OTP_ZONE_ID_DISTRICTS) def handleConnected(self): self.districtId = self.allocateChannel() self.notify.info('Creating PiratesDistrictAI(%d)...' % self.districtId) self.setupDistrict() 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('Creating main world...') self.createMainWorld() self.notify.info('Making district available...') self.enableShard() 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.distributedDistrict.b_setNewAvatarCount(self.distributedDistrict.getAvatarCount() + 1) def decrementPopulation(self): self.distributedDistrict.b_setNewAvatarCount(self.distributedDistrict.getAvatarCount() - 1) def enableShard(self): self.distributedDistrict.b_setAvailable(1) self.notify.info('Done.') messenger.send('startShardActivity')
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)