diff --git a/.gitignore b/.gitignore index 0e48a00d..52d61096 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ backups/ contentpacks/ resources/ save.dat -ai-crash.txt \ No newline at end of file +ai-crash.txt +gentokenlr.py \ No newline at end of file diff --git a/astron/dclass/united.dc b/astron/dclass/united.dc index 9cd255fa..28b78efd 100644 --- a/astron/dclass/united.dc +++ b/astron/dclass/united.dc @@ -1548,22 +1548,16 @@ dclass DistributedEstate : DistributedObject { setRentalTimeStamp(uint32 timestamp = 0) required airecv db; setRentalType(uint8 type = 0) required airecv db; setSlot0ToonId(uint32 toonId = 0) required airecv db; - setSlot0Garden(blob g) required airecv db; setSlot0Items(lawnItem items[] = []) required airecv db; setSlot1ToonId(uint32 toonId = 0) required airecv db; - setSlot1Garden(blob g) required airecv db; setSlot1Items(lawnItem items[] = []) required airecv db; setSlot2ToonId(uint32 toonId = 0) required airecv db; - setSlot2Garden(blob g) required airecv db; setSlot2Items(lawnItem items[] = []) required airecv db; setSlot3ToonId(uint32 toonId = 0) required airecv db; - setSlot3Garden(blob g) required airecv db; setSlot3Items(lawnItem items[] = []) required airecv db; setSlot4ToonId(uint32 toonId = 0) required airecv db; - setSlot4Garden(blob g) required airecv db; setSlot4Items(lawnItem items[] = []) required airecv db; setSlot5ToonId(uint32 toonId = 0) required airecv db; - setSlot5Garden(blob g) required airecv db; setSlot5Items(lawnItem items[] = []) required airecv db; setIdList(uint32 []) broadcast ram; completeFlowerSale(uint8) airecv clsend; diff --git a/toontown/estate/DistributedEstateAI.py b/toontown/estate/DistributedEstateAI.py index cf36b456..11b29ac6 100644 --- a/toontown/estate/DistributedEstateAI.py +++ b/toontown/estate/DistributedEstateAI.py @@ -1,239 +1,18 @@ from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectAI import DistributedObjectAI - from toontown.toonbase import ToontownGlobals - import HouseGlobals - import time -import random from toontown.fishing.DistributedFishingPondAI import DistributedFishingPondAI from toontown.fishing.DistributedFishingTargetAI import DistributedFishingTargetAI from toontown.fishing.DistributedPondBingoManagerAI import DistributedPondBingoManagerAI from toontown.fishing import FishingTargetGlobals - from toontown.safezone.DistributedFishingSpotAI import DistributedFishingSpotAI from toontown.safezone.SZTreasurePlannerAI import SZTreasurePlannerAI -from toontown.safezone import DistributedTreasureAI from toontown.safezone import TreasureGlobals -from DistributedGardenBoxAI import * -from DistributedGagTreeAI import * -from DistributedFlowerAI import * -import GardenGlobals -from DistributedCannonAI import * -from DistributedTargetAI import * -import CannonGlobals - -NULL_PLANT = [0, -1, 0, -1, 0] -NULL_TREES = [NULL_PLANT] * 8 -NULL_FLOWERS = [NULL_PLANT] * 10 -NULL_STATUARY = 0 - -from direct.distributed.PyDatagramIterator import * -from direct.distributed.PyDatagram import * - -def unpackGardenSetter(f): - def w(klass, data): - if data: - dg = PyDatagram(data) - dgi = PyDatagramIterator(dg) - def unpackPlant(_): - return dgi.getUint32, dgi.getInt8(), dgi.getUint32(), dgi.getInt8(), dgi.getUint16() - flowers = map(unpackPlant, range(10)) - trees = map(unpackPlant, range(8)) - st = dgi.getUint8() - started = dgi.getBool() - else: - flowers = NULL_FLOWERS - trees = NULL_TREES - st = NULL_STATUARY - started = 0 - return f(klass, started, flowers, trees, st) - return w - -def packGardenData(plants, statuary, started = True): - dg = PyDatagram() - for plant in plants: - a, b, c, d, e = plant - dg.addUint32(a) - dg.addInt8(b) - dg.addUint32(c) - dg.addInt8(d) - dg.addUint16(e) - - dg.addUint8(statuary) - dg.addBool(started) - return dg.getMessage() - -class Garden: - def __init__(self, avId): - self.avId = avId - self.treesData = NULL_TREES - self.flowersData = NULL_FLOWERS - self.statuaryIndex = NULL_STATUARY - self.trees = [] - self.flowers = [] - self.statuary = None - self.objects = [] - - def destroy(self): - del self.treesData - del self.flowersData - del self.statuaryIndex - for tree in self.trees: - tree.requestDelete() - for flower in self.flowers: - flower.requestDelete() - for object in self.objects: - object.requestDelete() - if self.statuary: - self.statuary.requestDelete() - del self.trees - del self.flowers - del self.objects - del self.statuary - - def create(self, estateMgr): - if self.avId not in estateMgr.toons: - estateMgr.notify.warning("Garden associated to unknown avatar %d, deleting..." % self.avId) - print estateMgr.toons - return False - houseIndex = estateMgr.toons.index(self.avId) - - boxDefs = GardenGlobals.estateBoxes[houseIndex] - for x, y, h, boxType in boxDefs: - box = DistributedGardenBoxAI(estateMgr.air) - box.setTypeIndex(boxType) - box.setPos(x, y, 0) - box.setH(h) - box.setOwnerIndex(houseIndex) - box.generateWithRequired(estateMgr.zoneId) - self.objects.append(box) - - plots = GardenGlobals.estatePlots[houseIndex] - treeIndex = 0 - for x, y, h, type in plots: - if type == GardenGlobals.GAG_TREE_TYPE: - planted, waterLevel, nextLevelDecrease, growthLevel, nextGrowth = self.treesData[treeIndex] - if planted: - treeIndex += 1 - tree = DistributedGagTreeAI(estateMgr.air) - tree.setPos(x, y, 0) - tree.setH(h) - tree.setOwnerIndex(houseIndex) - tree.setWaterLevel(waterLevel) - tree.setGrowthLevel(growthLevel) - tree.calculate(nextGrowth, nextLevelDecrease) - tree.generateWithRequired(estateMgr.zoneId) - self.trees.append(tree) - -class GardenManager: - def __init__(self, mgr): - self.mgr = mgr - self.gardens = {} - - def handleSingleGarden(self, avId, data): - g = Garden(avId) - g.flowersData, g.treesData, g.statuaryIndex = data - if not g.create(self.mgr): - return - self.gardens[avId] = g - - def placeGarden(self, avId): - g = Garden(avId) - g.create(self.mgr) - self.gardens[avId] = g - - def destroy(self): - for garden in self.gardens.values(): - garden.destroy() - del self.gardens - - def getData(self, avId): - g = self.gardens.get(avId) - if not g: - return packGardenData(NULL_FLOWERS + NULL_TREES, NULL_STATUARY, False) - return packGardenData(g.flowersData + g.treesData, g.statuaryIndex) - -class Rental: - def __init__(self, estate): - self.estate = estate - self.objects = set() - - def destroy(self): - del self.estate - for object in self.objects: - if not object.isDeleted(): - object.requestDelete() - taskMgr.remove(object.uniqueName('delete')) - self.objects = set() - -class CannonRental(Rental): - def generateObjects(self): - target = DistributedTargetAI(self.estate.air) - target.generateWithRequired(self.estate.zoneId) - - for drop in CannonGlobals.cannonDrops: - cannon = DistributedCannonAI(self.estate.air) - cannon.setEstateId(self.estate.doId) - cannon.setTargetId(target.doId) - cannon.setPosHpr(*drop) - cannon.generateWithRequired(self.estate.zoneId) - self.objects.add(cannon) - - self.generateTreasures() - self.estate.b_setClouds(1) - - def destroy(self): - self.estate.b_setClouds(0) - Rental.destroy(self) - - def generateTreasures(self): - doIds = [] - z = 35 - - for i in xrange(20): - x = random.randint(100, 300) - 200 - y = random.randint(100, 300) - 200 - treasure = DistributedTreasureAI.DistributedTreasureAI(self.estate.air, self, 7, x, y, z) - treasure.generateWithRequired(self.estate.zoneId) - self.objects.add(treasure) - doIds.append(treasure.doId) - - self.estate.sendUpdate("setTreasureIds", [doIds]) - - def grabAttempt(self, avId, treasureId): - av = self.estate.air.doId2do.get(avId) - if av == None: - self.estate.air.writeServerEvent('suspicious', avId, 'TreasurePlannerAI.grabAttempt unknown avatar') - self.estate.notify.warning('avid: %s does not exist' % avId) - return - - treasure = self.estate.air.doId2do.get(treasureId) - if self.validAvatar(av): - treasure.d_setGrab(avId) - self.deleteTreasureSoon(treasure) - - else: - treasure.d_setReject() - - def deleteTreasureSoon(self, treasure): - taskName = treasure.uniqueName('delete') - taskMgr.doMethodLater(5, self.__deleteTreasureNow, taskName, extraArgs=(treasure, taskName)) - - def __deleteTreasureNow(self, treasure, taskName): - treasure.requestDelete() - - def validAvatar(self, av): - if av.getMaxHp() == av.getHp(): - return 0 - - av.toonUp(3) - return 1 - class DistributedEstateAI(DistributedObjectAI): notify = DirectNotifyGlobal.directNotify.newCategory("DistributedEstateAI") def __init__(self, air): @@ -246,16 +25,14 @@ class DistributedEstateAI(DistributedObjectAI): self.dawnTime = 0 self.lastEpochTimestamp = 0 self.rentalTimestamp = 0 - self.houses = [None, None, None, None, None, None] - self.rentalType = 0 - self.rentalHandle = None + self.houses = [None] * 6 + self.pond = None self.spots = [] + self.targets = [] - self.doId2do = {} + self.owner = None - self.gardenManager = GardenManager(self) - self.__pendingGardens = {} def generate(self): DistributedObjectAI.generate(self) @@ -270,6 +47,7 @@ class DistributedEstateAI(DistributedObjectAI): target.generateWithRequired(self.zoneId) self.targets.append(target) + spot = DistributedFishingSpotAI(self.air) spot.setPondDoId(self.pond.getDoId()) spot.setPosHpr(49.1029, -124.805, 0.344704, 90, 0, 0) @@ -296,39 +74,26 @@ class DistributedEstateAI(DistributedObjectAI): self.createTreasurePlanner() - def announceGenerate(self): - DistributedObjectAI.announceGenerate(self) - # Commented out because I had to reach estate to debug doors (Nacib) - #for index, garden in self.__pendingGardens.items(): - # started = garden[0] - # self.gardenManager.handleSingleGarden(self.toons[index], garden[1:]) - # self.placeStarterGarden(self.toons[index]) - self.__pendingGardens = {} def destroy(self): for house in self.houses: if house: house.requestDelete() - self.houses = [] + del self.houses[:] if self.pond: + self.pond.requestDelete() for spot in self.spots: spot.requestDelete() - self.spots = [] for target in self.targets: target.requestDelete() - self.targets = [] - self.pond.requestDelete() - self.pond = None - self.gardenManager.destroy() - if self.rentalHandle: - self.rentalHandle.destroy() - self.rentalHandle = None + if self.treasurePlanner: self.treasurePlanner.stop() + self.requestDelete() - def addDistObj(self, distObj): - self.doId2do[distObj.doId] = distObj + def setEstateReady(self): + pass def setClientReady(self): self.sendUpdate('setEstateReady', []) @@ -345,7 +110,7 @@ class DistributedEstateAI(DistributedObjectAI): def getEstateType(self): return self.estateType - + def setClosestHouse(self, todo0): pass @@ -377,6 +142,9 @@ class DistributedEstateAI(DistributedObjectAI): def getDawnTime(self): return self.dawnTime + def placeOnGround(self, todo0): + pass + def setDecorData(self, decorData): self.decorData = decorData @@ -390,7 +158,7 @@ class DistributedEstateAI(DistributedObjectAI): def getDecorData(self): return self.decorData - def setLastEpochTimeStamp(self, last): + def setLastEpochTimeStamp(self, last): #how do I do this self.lastEpochTimestamp = last def d_setLastEpochTimeStamp(self, last): @@ -410,58 +178,18 @@ class DistributedEstateAI(DistributedObjectAI): self.sendUpdate('setRentalTimeStamp', [rental]) def b_setRentalTimeStamp(self, rental): - self.setRentalTimeStamp(rental) - self.d_setRentalTimeStamp(rental) + self.setRentalTimeStamp(self, rental) + self.b_setRentalTimeStamp(self, rental) def getRentalTimeStamp(self): return self.rentalTimestamp - def b_setRentalType(self, type): - self.d_setRentalType(type) - self.setRentalType(type) - - def d_setRentalType(self, type): - self.sendUpdate("setRentalType", [type]) - - def setRentalType(self, type): - expirestamp = self.getRentalTimeStamp() - if expirestamp == 0: - expire = 0 - - else: - expire = int(expirestamp - time.time()) - - if expire < 0: - self.rentalType = 0 - self.d_setRentalType(0) - self.b_setRentalTimeStamp(0) - - else: - if self.rentalType == type: - return - - self.rentalType = type - if self.rentalHandle: - self.rentalHandle.destroy() - self.rentalHandle = None - - if self.rentalType == ToontownGlobals.RentalCannon: - self.rentalHandle = CannonRental(self) - - else: - self.notify.warning('Unknown rental %s' % self.rentalType) - return - - self.rentalHandle.generateObjects() + def setRentalType(self, todo0): + pass def getRentalType(self): - return self.rentalType - - def rentItem(self, rentType, duration): - self.rentalType = rentType - self.b_setRentalTimeStamp(time.time() + duration * 60) - self.b_setRentalType(rentType) - + return 0 + def setSlot0ToonId(self, id): self.toons[0] = id @@ -579,6 +307,7 @@ class DistributedEstateAI(DistributedObjectAI): def getSlot4ToonId(self): return self.toons[4] + def setSlot4Items(self, items): self.items[4] = items @@ -672,44 +401,3 @@ class DistributedEstateAI(DistributedObjectAI): self.d_setSlot3Items(self.items[3]) self.d_setSlot4Items(self.items[4]) self.d_setSlot5Items(self.items[5]) - - @unpackGardenSetter - def setSlot0Garden(self, started, flowers, trees, si): - self.__pendingGardens[0] = (started, flowers, trees, si) - - @unpackGardenSetter - def setSlot1Garden(self, started, flowers, trees, si): - self.__pendingGardens[1] = (started, flowers, trees, si) - - @unpackGardenSetter - def setSlot2Garden(self, started, flowers, trees, si): - self.__pendingGardens[2] = (started, flowers, trees, si) - - @unpackGardenSetter - def setSlot3Garden(self, started, flowers, trees, si): - self.__pendingGardens[3] = (started, flowers, trees, si) - - @unpackGardenSetter - def setSlot4Garden(self, started, flowers, trees, si): - self.__pendingGardens[4] = (started, flowers, trees, si) - - @unpackGardenSetter - def setSlot5Garden(self, started, flowers, trees, si): - self.__pendingGardens[5] = (started, flowers, trees, si) - - def d_updateGarden(self, slot = None): - self.notify.info('updateGarden %s' % slot) - if slot is None: - for i in xrange(6): - self.d_updateGarden(i) - else: - data = self.gardenManager.getData(self.toons[slot]) - self.sendUpdate('setSlot%dGarden' % slot, [data]) - - def placeStarterGarden(self, avId): - av = self.air.doId2do.get(avId) - if not av: - return - self.notify.info('placeStarterGarden %d' % avId) - self.gardenManager.placeGarden(avId) - self.d_updateGarden()