2019-11-02 17:27:54 -05:00
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
2019-12-30 00:07:56 -06:00
|
|
|
from . import ZoneUtil
|
2019-11-02 17:27:54 -05:00
|
|
|
from toontown.building import DistributedBuildingMgrAI
|
|
|
|
from toontown.suit import DistributedSuitPlannerAI
|
|
|
|
from toontown.safezone import ButterflyGlobals
|
|
|
|
from toontown.safezone import DistributedButterflyAI
|
|
|
|
from pandac.PandaModules import *
|
2021-07-08 11:52:31 -05:00
|
|
|
from panda3d.toontown import *
|
2019-11-02 17:27:54 -05:00
|
|
|
from toontown.toon import NPCToons
|
|
|
|
|
|
|
|
class HoodDataAI:
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('HoodDataAI')
|
|
|
|
|
|
|
|
def __init__(self, air, zoneId, canonicalHoodId):
|
|
|
|
self.air = air
|
|
|
|
self.zoneId = zoneId
|
|
|
|
self.canonicalHoodId = canonicalHoodId
|
|
|
|
self.treasurePlanner = None
|
|
|
|
self.buildingManagers = []
|
|
|
|
self.suitPlanners = []
|
|
|
|
self.doId2do = {}
|
|
|
|
self.replacementHood = None
|
|
|
|
self.redirectingToMe = []
|
|
|
|
self.hoodPopulation = 0
|
|
|
|
self.pgPopulation = 0
|
|
|
|
return
|
|
|
|
|
|
|
|
def startup(self):
|
|
|
|
self.createFishingPonds()
|
|
|
|
self.createPartyPeople()
|
|
|
|
self.createBuildingManagers()
|
|
|
|
self.createSuitPlanners()
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
self.setRedirect(None)
|
|
|
|
if self.treasurePlanner:
|
|
|
|
self.treasurePlanner.stop()
|
|
|
|
self.treasurePlanner.deleteAllTreasuresNow()
|
|
|
|
self.treasurePlanner = None
|
|
|
|
for suitPlanner in self.suitPlanners:
|
|
|
|
suitPlanner.requestDelete()
|
|
|
|
del self.air.suitPlanners[suitPlanner.zoneId]
|
|
|
|
|
|
|
|
self.suitPlanners = []
|
|
|
|
for buildingManager in self.buildingManagers:
|
|
|
|
buildingManager.cleanup()
|
|
|
|
del self.air.buildingManagers[buildingManager.branchID]
|
|
|
|
|
|
|
|
self.buildingManagers = []
|
|
|
|
ButterflyGlobals.clearIndexes(self.zoneId)
|
|
|
|
del self.fishingPonds
|
2019-12-30 00:07:56 -06:00
|
|
|
for distObj in list(self.doId2do.values()):
|
2019-11-02 17:27:54 -05:00
|
|
|
distObj.requestDelete()
|
|
|
|
|
|
|
|
del self.doId2do
|
|
|
|
del self.air
|
|
|
|
return
|
|
|
|
|
|
|
|
def addDistObj(self, distObj):
|
|
|
|
self.doId2do[distObj.doId] = distObj
|
|
|
|
|
|
|
|
def removeDistObj(self, distObj):
|
|
|
|
del self.doId2do[distObj.doId]
|
|
|
|
|
|
|
|
def createPartyPeople(self):
|
|
|
|
partyHats = []
|
|
|
|
for zone in self.air.zoneTable[self.canonicalHoodId]:
|
|
|
|
zoneId = ZoneUtil.getTrueZoneId(zone[0], self.zoneId)
|
|
|
|
dnaData = self.air.dnaDataMap.get(zone[0], None)
|
|
|
|
if isinstance(dnaData, DNAData):
|
|
|
|
foundPartyHats = self.air.findPartyHats(dnaData, zoneId)
|
|
|
|
partyHats += foundPartyHats
|
|
|
|
|
|
|
|
for distObj in partyHats:
|
|
|
|
self.addDistObj(distObj)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def createFishingPonds(self):
|
|
|
|
self.fishingPonds = []
|
|
|
|
fishingPondGroups = []
|
|
|
|
for zone in self.air.zoneTable[self.canonicalHoodId]:
|
|
|
|
zoneId = ZoneUtil.getTrueZoneId(zone[0], self.zoneId)
|
|
|
|
dnaData = self.air.dnaDataMap.get(zone[0], None)
|
|
|
|
if isinstance(dnaData, DNAData):
|
|
|
|
area = ZoneUtil.getCanonicalZoneId(zoneId)
|
|
|
|
foundFishingPonds, foundFishingPondGroups = self.air.findFishingPonds(dnaData, zoneId, area)
|
|
|
|
self.fishingPonds += foundFishingPonds
|
|
|
|
fishingPondGroups += foundFishingPondGroups
|
|
|
|
|
|
|
|
for distObj in self.fishingPonds:
|
|
|
|
self.addDistObj(distObj)
|
|
|
|
npcs = NPCToons.createNpcsInZone(self.air, distObj.zoneId)
|
|
|
|
for npc in npcs:
|
|
|
|
self.addDistObj(npc)
|
|
|
|
|
|
|
|
fishingSpots = []
|
|
|
|
for dnaGroup, distPond in zip(fishingPondGroups, self.fishingPonds):
|
|
|
|
fishingSpots += self.air.findFishingSpots(dnaGroup, distPond)
|
|
|
|
|
|
|
|
for distObj in fishingSpots:
|
|
|
|
self.addDistObj(distObj)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def createBuildingManagers(self):
|
|
|
|
for zone in self.air.zoneTable[self.canonicalHoodId]:
|
|
|
|
if zone[1]:
|
|
|
|
zoneId = ZoneUtil.getTrueZoneId(zone[0], self.zoneId)
|
|
|
|
dnaStore = self.air.dnaStoreMap[zone[0]]
|
|
|
|
mgr = DistributedBuildingMgrAI.DistributedBuildingMgrAI(self.air, zoneId, dnaStore, self.air.trophyMgr)
|
|
|
|
self.buildingManagers.append(mgr)
|
|
|
|
self.air.buildingManagers[zoneId] = mgr
|
|
|
|
|
|
|
|
def createSuitPlanners(self):
|
|
|
|
for zone in self.air.zoneTable[self.canonicalHoodId]:
|
|
|
|
if zone[2]:
|
|
|
|
zoneId = ZoneUtil.getTrueZoneId(zone[0], self.zoneId)
|
|
|
|
sp = DistributedSuitPlannerAI.DistributedSuitPlannerAI(self.air, zoneId)
|
|
|
|
sp.generateWithRequired(zoneId)
|
|
|
|
sp.d_setZoneId(zoneId)
|
|
|
|
sp.initTasks()
|
|
|
|
self.suitPlanners.append(sp)
|
|
|
|
self.air.suitPlanners[zoneId] = sp
|
|
|
|
|
|
|
|
def createButterflies(self, playground):
|
|
|
|
ButterflyGlobals.generateIndexes(self.zoneId, playground)
|
|
|
|
for i in range(0, ButterflyGlobals.NUM_BUTTERFLY_AREAS[playground]):
|
|
|
|
for j in range(0, ButterflyGlobals.NUM_BUTTERFLIES[playground]):
|
|
|
|
bfly = DistributedButterflyAI.DistributedButterflyAI(self.air, playground, i, self.zoneId)
|
|
|
|
bfly.generateWithRequired(self.zoneId)
|
|
|
|
bfly.start()
|
|
|
|
self.addDistObj(bfly)
|
|
|
|
|
|
|
|
def setRedirect(self, replacementHood):
|
|
|
|
if self.replacementHood:
|
|
|
|
self.replacementHood[0].redirectingToMe.remove(self)
|
|
|
|
self.replacementHood = replacementHood
|
|
|
|
if self.replacementHood:
|
|
|
|
self.replacementHood[0].redirectingToMe.append(self)
|
|
|
|
|
|
|
|
def hasRedirect(self):
|
|
|
|
return self.replacementHood != None
|
|
|
|
|
|
|
|
def getRedirect(self):
|
|
|
|
if self.replacementHood == None:
|
|
|
|
return self
|
|
|
|
else:
|
|
|
|
return self.replacementHood[0].getRedirect()
|
|
|
|
return
|
|
|
|
|
|
|
|
def incrementPopulation(self, zoneId, increment):
|
|
|
|
self.hoodPopulation += increment
|
|
|
|
if ZoneUtil.isPlayground(zoneId):
|
|
|
|
self.pgPopulation += increment
|
|
|
|
|
|
|
|
def getHoodPopulation(self):
|
|
|
|
population = self.hoodPopulation
|
|
|
|
for hood in self.redirectingToMe:
|
|
|
|
population += hood.getHoodPopulation()
|
|
|
|
|
|
|
|
return population
|
|
|
|
|
|
|
|
def getPgPopulation(self):
|
|
|
|
population = self.pgPopulation
|
|
|
|
for pg in self.redirectingToMe:
|
|
|
|
population += pg.getPgPopulation()
|
|
|
|
|
|
|
|
return population
|