oldschool-toontown/toontown/ai/ToontownAIRepository.py

292 lines
12 KiB
Python
Raw Normal View History

2019-11-10 18:46:41 -06:00
from direct.directnotify import DirectNotifyGlobal
from panda3d.core import *
from libtoontown import *
2019-11-17 15:29:23 -06:00
from otp.ai.AIZoneData import AIZoneDataStore
from otp.ai.TimeManagerAI import TimeManagerAI
2019-11-17 15:29:23 -06:00
from otp.distributed.OtpDoGlobals import *
from toontown.ai.HolidayManagerAI import HolidayManagerAI
2019-11-17 15:57:18 -06:00
from toontown.ai.NewsManagerAI import NewsManagerAI
2019-12-05 20:38:58 -06:00
from toontown.ai.WelcomeValleyManagerAI import WelcomeValleyManagerAI
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
from toontown.coghq.PromotionManagerAI import PromotionManagerAI
from toontown.distributed.ToontownDistrictAI import ToontownDistrictAI
from toontown.distributed.ToontownDistrictStatsAI import ToontownDistrictStatsAI
from toontown.distributed.ToontownInternalRepository import ToontownInternalRepository
2019-11-22 19:58:35 -06:00
from toontown.hood import ZoneUtil
from toontown.hood.BRHoodDataAI import BRHoodDataAI
from toontown.hood.DDHoodDataAI import DDHoodDataAI
from toontown.hood.DGHoodDataAI import DGHoodDataAI
from toontown.hood.DLHoodDataAI import DLHoodDataAI
from toontown.hood.GSHoodDataAI import GSHoodDataAI
from toontown.hood.MMHoodDataAI import MMHoodDataAI
from toontown.hood.TTHoodDataAI import TTHoodDataAI
2019-11-22 19:58:35 -06:00
from toontown.pets.PetManagerAI import PetManagerAI
from toontown.quest.QuestManagerAI import QuestManagerAI
from toontown.shtiker.CogPageManagerAI import CogPageManagerAI
2019-11-22 19:58:35 -06:00
from toontown.suit.SuitInvasionManagerAI import SuitInvasionManagerAI
from toontown.toon import NPCToons
2019-11-22 19:58:35 -06:00
from toontown.toonbase import ToontownGlobals
from toontown.uberdog.DistributedInGameNewsMgrAI import DistributedInGameNewsMgrAI
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
self.questManager = None
self.promotionMgr = None
self.cogPageManager = None
self.timeManager = None
2019-11-20 16:05:59 -06:00
self.newsManager = None
2019-12-05 20:38:58 -06:00
self.welcomeValleyManager = 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)
# Create our quest manager...
self.questManager = QuestManagerAI(self)
# Create our promotion manager...
self.promotionMgr = PromotionManagerAI(self)
# Create our Cog page manager...
self.cogPageManager = CogPageManagerAI(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)
# Generate our time manager...
self.timeManager = TimeManagerAI(self)
self.timeManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)
2019-11-17 15:57:18 -06:00
# Generate our news manager...
self.newsManager = NewsManagerAI(self)
self.newsManager.generateWithRequired(OTP_ZONE_ID_MANAGEMENT)
2019-12-05 20:38:58 -06:00
# Generate our Welcome Valley manager...
self.welcomeValleyManager = WelcomeValleyManagerAI(self)
self.welcomeValleyManager.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):
# First, generate our zone2NpcDict...
NPCToons.generateZone2NpcDict()
2019-11-22 22:51:24 -06:00
# Donald's Dock
self.zoneTable[ToontownGlobals.DonaldsDock] = (
(ToontownGlobals.DonaldsDock, 1, 0), (ToontownGlobals.BarnacleBoulevard, 1, 1),
(ToontownGlobals.SeaweedStreet, 1, 1), (ToontownGlobals.LighthouseLane, 1, 1)
)
self.generateHood(DDHoodDataAI, ToontownGlobals.DonaldsDock)
2019-11-22 19:58:35 -06:00
# 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)
# The Brrrgh
self.zoneTable[ToontownGlobals.TheBrrrgh] = (
(ToontownGlobals.TheBrrrgh, 1, 0), (ToontownGlobals.WalrusWay, 1, 1),
(ToontownGlobals.SleetStreet, 1, 1), (ToontownGlobals.PolarPlace, 1, 1)
)
self.generateHood(BRHoodDataAI, ToontownGlobals.TheBrrrgh)
# Minnie's Melodyland
self.zoneTable[ToontownGlobals.MinniesMelodyland] = (
(ToontownGlobals.MinniesMelodyland, 1, 0), (ToontownGlobals.AltoAvenue, 1, 1),
(ToontownGlobals.BaritoneBoulevard, 1, 1), (ToontownGlobals.TenorTerrace, 1, 1)
)
self.generateHood(MMHoodDataAI, ToontownGlobals.MinniesMelodyland)
# Daisy Gardens
self.zoneTable[ToontownGlobals.DaisyGardens] = (
(ToontownGlobals.DaisyGardens, 1, 0), (ToontownGlobals.ElmStreet, 1, 1),
(ToontownGlobals.MapleStreet, 1, 1), (ToontownGlobals.OakStreet, 1, 1)
)
self.generateHood(DGHoodDataAI, ToontownGlobals.DaisyGardens)
# Goofy Speedway
self.zoneTable[ToontownGlobals.GoofySpeedway] = (
(ToontownGlobals.GoofySpeedway, 1, 0),
)
self.generateHood(GSHoodDataAI, ToontownGlobals.GoofySpeedway)
# Donald's Dreamland
self.zoneTable[ToontownGlobals.DonaldsDreamland] = (
(ToontownGlobals.DonaldsDreamland, 1, 0), (ToontownGlobals.LullabyLane, 1, 1),
(ToontownGlobals.PajamaPlace, 1, 1)
)
self.generateHood(DLHoodDataAI, ToontownGlobals.DonaldsDreamland)
2019-12-05 20:38:58 -06:00
# Welcome Valley zones
self.welcomeValleyManager.createWelcomeValleyZones()
# Assign the initial suit buildings.
for suitPlanner in self.suitPlanners.values():
suitPlanner.assignInitialSuitBuildings()
2019-11-22 19:58:35 -06:00
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 lookupDNAFileName(self, dnaFileName):
searchPath = DSearchPath()
searchPath.appendDirectory(Filename('resources/phase_3.5/dna'))
searchPath.appendDirectory(Filename('resources/phase_4/dna'))
searchPath.appendDirectory(Filename('resources/phase_5/dna'))
searchPath.appendDirectory(Filename('resources/phase_5.5/dna'))
searchPath.appendDirectory(Filename('resources/phase_6/dna'))
searchPath.appendDirectory(Filename('resources/phase_8/dna'))
searchPath.appendDirectory(Filename('resources/phase_9/dna'))
searchPath.appendDirectory(Filename('resources/phase_10/dna'))
searchPath.appendDirectory(Filename('resources/phase_11/dna'))
searchPath.appendDirectory(Filename('resources/phase_12/dna'))
searchPath.appendDirectory(Filename('resources/phase_13/dna'))
filename = Filename(dnaFileName)
found = vfs.resolveFilename(filename, searchPath)
if not found:
self.notify.warning('lookupDNAFileName - %s not found on:' % dnaFileName)
print searchPath
else:
return filename.getFullpath()
2019-11-22 19:58:35 -06:00
def loadDNAFileAI(self, dnaStore, dnaFileName):
return loadDNAFileAI(dnaStore, dnaFileName)
def findFishingPonds(self, dnaData, zoneId, area):
return [], [] # TODO
def findPartyHats(self, dnaData, zoneId):
return [] # TODO
def findRacingPads(self, dnaData, zoneId, area, type='racing_pad'):
return [], [] # TODO
def findLeaderBoards(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 getAvatarDisconnectReason(self, avId):
return self.timeManager.avId2disconnectcode.get(avId, ToontownGlobals.DisconnectUnknown)
2019-11-17 15:29:23 -06:00
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?