oldschool-toontown/toontown/ai/ToontownAIRepository.py

174 lines
6.7 KiB
Python
Raw Normal View History

2019-11-22 19:58:35 -06:00
from libtoontown import *
2019-11-10 18:46:41 -06:00
from direct.directnotify import DirectNotifyGlobal
2019-11-17 15:29:23 -06:00
from otp.ai.AIZoneData import AIZoneDataStore
from otp.distributed.OtpDoGlobals import *
2019-11-10 18:46:41 -06:00
from toontown.distributed.ToontownInternalRepository import ToontownInternalRepository
from toontown.distributed.ToontownDistrictAI import ToontownDistrictAI
2019-11-22 19:18:26 -06:00
from toontown.distributed.ToontownDistrictStatsAI import ToontownDistrictStatsAI
2019-11-17 15:29:23 -06:00
from toontown.ai.HolidayManagerAI import HolidayManagerAI
2019-11-17 15:57:18 -06:00
from toontown.ai.NewsManagerAI import NewsManagerAI
2019-11-22 19:58:35 -06:00
from toontown.building.DistributedTrophyMgrAI import DistributedTrophyMgrAI
2019-11-17 15:29:23 -06:00
from toontown.catalog.CatalogManagerAI import CatalogManagerAI
2019-11-22 19:58:35 -06:00
from toontown.hood.TTHoodDataAI import TTHoodDataAI
from toontown.hood import ZoneUtil
from toontown.pets.PetManagerAI import PetManagerAI
from toontown.suit.SuitInvasionManagerAI import SuitInvasionManagerAI
2019-11-17 15:29:23 -06:00
from toontown.uberdog.DistributedInGameNewsMgrAI import DistributedInGameNewsMgrAI
2019-11-22 19:58:35 -06:00
from toontown.toonbase import ToontownGlobals
2019-11-10 18:46:41 -06:00
class ToontownAIRepository(ToontownInternalRepository):
notify = DirectNotifyGlobal.directNotify.newCategory('ToontownAIRepository')
def __init__(self, baseChannel, serverId, districtName):
ToontownInternalRepository.__init__(self, baseChannel, serverId, dcSuffix='AI')
self.districtName = districtName
2019-11-20 16:05:59 -06:00
self.doLiveUpdates = config.GetBool('want-live-updates', True)
2019-11-22 19:58:35 -06:00
self.wantCogdominiums = config.GetBool('want-cogdominiums', True)
2019-11-10 18:46:41 -06:00
self.districtId = None
self.district = None
2019-11-22 19:18:26 -06:00
self.districtStats = None
2019-11-17 15:29:23 -06:00
self.holidayManager = None
self.zoneDataStore = None
2019-11-22 19:58:35 -06:00
self.petMgr = None
self.suitInvasionManager = None
2019-11-20 16:05:59 -06:00
self.newsManager = None
2019-11-17 15:29:23 -06:00
self.inGameNewsMgr = None
self.catalogManager = None
2019-11-22 19:58:35 -06:00
self.trophyMgr = None
self.zoneTable = {}
self.dnaStoreMap = {}
self.dnaDataMap = {}
self.hoods = []
self.buildingManagers = {}
self.suitPlanners = {}
2019-11-10 18:46:41 -06:00
def handleConnected(self):
ToontownInternalRepository.handleConnected(self)
# Generate our district...
self.districtId = self.allocateChannel()
self.district = ToontownDistrictAI(self)
self.district.setName(self.districtName)
self.district.generateWithRequiredAndId(self.districtId, self.getGameDoId(), OTP_ZONE_ID_DISTRICTS)
2019-11-10 19:50:13 -06:00
# Claim ownership of that district...
self.district.setAI(self.ourChannel)
2019-11-17 15:29:23 -06:00
# Create our local objects.
self.createLocals()
# Create our global objects.
self.createGlobals()
2019-11-22 19:58:35 -06:00
# Create our zones.
self.createZones()
2019-11-10 19:50:13 -06:00
# Make our district available, and we're done.
self.district.b_setAvailable(True)
self.notify.info('Done.')
2019-11-17 15:29:23 -06:00
def createLocals(self):
"""
Creates "local" (non-distributed) objects.
"""
# Create our holiday manager...
self.holidayManager = HolidayManagerAI(self)
# Create our zone data store...
self.zoneDataStore = AIZoneDataStore()
2019-11-22 19:58:35 -06:00
# Create our pet manager...
self.petMgr = PetManagerAI(self)
# Create our suit invasion manager...
self.suitInvasionManager = SuitInvasionManagerAI(self)
2019-11-17 15:29:23 -06:00
def createGlobals(self):
"""
Creates "global" (distributed) objects.
"""
2019-11-22 19:18:26 -06:00
# Generate our district stats...
self.districtStats = ToontownDistrictStatsAI(self)
self.districtStats.settoontownDistrictId(self.districtId)
self.districtStats.generateWithRequiredAndId(self.allocateChannel(), self.district.getDoId(),
OTP_ZONE_ID_DISTRICTS_STATS)
2019-11-17 15:57:18 -06:00
# Generate our news manager...
self.newsManager = NewsManagerAI(self)
self.newsManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)
2019-11-17 15:29:23 -06:00
# Generate our in-game news manager...
self.inGameNewsMgr = DistributedInGameNewsMgrAI(self)
self.inGameNewsMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)
# Generate our catalog manager...
self.catalogManager = CatalogManagerAI(self)
2019-11-20 14:12:05 -06:00
self.catalogManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)
2019-11-17 15:29:23 -06:00
2019-11-22 19:58:35 -06:00
# Generate our trophy manager...
self.trophyMgr = DistributedTrophyMgrAI(self)
self.trophyMgr.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)
def generateHood(self, hoodConstructor, zoneId):
# Bossbot HQ doesn't use DNA, so we skip over that.
if zoneId != ToontownGlobals.BossbotHQ:
self.dnaStoreMap[zoneId] = DNAStorage()
self.dnaDataMap[zoneId] = loadDNAFileAI(self.dnaStoreMap[zoneId], self.genDNAFileName(zoneId))
if zoneId in ToontownGlobals.HoodHierarchy:
for streetId in ToontownGlobals.HoodHierarchy[zoneId]:
self.dnaStoreMap[streetId] = DNAStorage()
self.dnaDataMap[streetId] = loadDNAFileAI(self.dnaStoreMap[streetId], self.genDNAFileName(streetId))
hood = hoodConstructor(self, zoneId)
hood.startup()
self.hoods.append(hood)
def createZones(self):
# Toontown Central
self.zoneTable[ToontownGlobals.ToontownCentral] = (
(ToontownGlobals.ToontownCentral, 1, 0), (ToontownGlobals.SillyStreet, 1, 1),
(ToontownGlobals.LoopyLane, 1, 1), (ToontownGlobals.PunchlinePlace, 1, 1)
)
self.generateHood(TTHoodDataAI, ToontownGlobals.ToontownCentral)
def genDNAFileName(self, zoneId):
canonicalZoneId = ZoneUtil.getCanonicalZoneId(zoneId)
canonicalHoodId = ZoneUtil.getCanonicalHoodId(canonicalZoneId)
hood = ToontownGlobals.dnaMap[canonicalHoodId]
if canonicalHoodId == canonicalZoneId:
canonicalZoneId = 'sz'
phase = ToontownGlobals.phaseMap[canonicalHoodId]
else:
phase = ToontownGlobals.streetPhaseMap[canonicalHoodId]
return 'phase_%s/dna/%s_%s.dna' % (phase, hood, canonicalZoneId)
def loadDNAFileAI(self, dnaStore, dnaFileName):
return loadDNAFileAI(dnaStore, dnaFileName)
def findFishingPonds(self, dnaData, zoneId, area):
return [], [] # TODO
def findPartyHats(self, dnaData, zoneId):
return [] # TODO
2019-11-17 15:29:23 -06:00
def getTrackClsends(self):
return False
def getAvatarExitEvent(self, avId):
return 'distObjDelete-%d' % avId
def getZoneDataStore(self):
return self.zoneDataStore
def incrementPopulation(self):
2019-11-22 19:18:26 -06:00
self.districtStats.b_setAvatarCount(self.districtStats.getAvatarCount() + 1)
2019-11-17 15:29:23 -06:00
def decrementPopulation(self):
2019-11-22 19:18:26 -06:00
self.districtStats.b_setAvatarCount(self.districtStats.getAvatarCount() - 1)
2019-11-17 15:29:23 -06:00
def sendQueryToonMaxHp(self, avId, callback):
pass # TODO?