def create(self, estateMgr): self.estateMgr = estateMgr if self.avId not in estateMgr.toons: estateMgr.notify.warning('Garden associated to unknown avatar %d, deleting...' % self.avId) return False houseIndex = estateMgr.toons.index(self.avId) houseType = estateMgr.houses[houseIndex].houseType if self.WANT_FLOWERS: boxIndex = 0 boxes = [] boxDefs = GardenGlobals.estateBoxes[houseType] for x, y, h, boxType in boxDefs: box = DistributedGardenBoxAI(self) box.setTypeIndex(boxType) box.setPos(x, y, 0) box.setH(h) box.setOwnerIndex(houseIndex) box.generateWithRequired(estateMgr.zoneId) self.objects.add(box) boxes.append(box) boxIndex += 1 self._boxes = boxes plots = GardenGlobals.estatePlots[houseIndex] treeIndex = 0 flowerIndex = 0 for plot, (x, y, h, type) in enumerate(plots): if type == GardenGlobals.GAG_TREE_TYPE and self.WANT_TREES: data = self.data['trees'][treeIndex] planted, waterLevel, lastCheck, growthLevel, lastHarvested = data if planted != -1: obj = self.plantTree(treeIndex, planted, waterLevel=waterLevel, lastCheck=lastCheck, growthLevel=growthLevel, lastHarvested=lastHarvested, generate=False) self.trees.add(obj) else: obj = self.placePlot(treeIndex) obj.setPos(x, y, 0) obj.setH(h) obj.setPlot(plot) obj.setOwnerIndex(houseIndex) obj.generateWithRequired(estateMgr.zoneId) treeIndex += 1 elif type == GardenGlobals.FLOWER_TYPE and self.WANT_FLOWERS: data = self.data['flowers'][flowerIndex] planted, waterLevel, lastCheck, growthLevel, variety = data if planted != -1: obj = self.plantFlower(flowerIndex, planted, variety, waterLevel=waterLevel, lastCheck=lastCheck, growthLevel=growthLevel, generate=False) else: obj = self.placePlot(flowerIndex) obj.flowerIndex = flowerIndex obj.setPlot(plot) obj.setOwnerIndex(houseIndex) obj.generateWithRequired(estateMgr.zoneId) index = (0, 1, 2, 2, 2, 3, 3, 3, 4, 4)[flowerIndex] idx = (0, 0, 0, 1, 2, 0, 1, 2, 0, 1)[flowerIndex] obj.sendUpdate('setBoxDoId', [boxes[index].doId, idx]) flowerIndex += 1 elif type == GardenGlobals.STATUARY_TYPE and self.WANT_STATUARY: data = self.data['statuary'] if data == 0: obj = self.placePlot(-1) else: obj = self.placeStatuary(data, generate=False) obj.setPos(x, y, 0) obj.setH(h) obj.setPlot(plot) obj.setOwnerIndex(houseIndex) obj.generateWithRequired(estateMgr.zoneId) for tree in self.trees: tree.calcDependencies() self.reconsiderAvatarOrganicBonus() return True
def load(self, estate): self.estate = estate if self.avId not in estate.activeToons: self.notify.warning( 'Garden associated with unknown avatar %d, deleting...' % self.avId) return False houseIndex = estate.activeToons.index(self.avId) if self.WANT_FLOWERS: estateBoxIndex = 0 estateBoxes = [] estateBoxData = GardenGlobals.estateBoxes[houseIndex] for x, y, h, estateBoxType in estateBoxData: gardenBox = DistributedGardenBoxAI(self) gardenBox.setTypeIndex(estateBoxType) gardenBox.setPos(x, y, 0) gardenBox.setH(h) gardenBox.setOwnerIndex(houseIndex) gardenBox.generateWithRequired(estate.zoneId) self.objects.add(gardenBox) estateBoxes.append(gardenBox) estateBoxIndex += 1 self._estateBoxes = estateBoxes estatePlots = GardenGlobals.estatePlots[houseIndex] treeIndex = 0 flowerIndex = 0 for estatePlot, (x, y, h, estatePlotType) in enumerate(estatePlots): if estatePlotType == GardenGlobals.GAG_TREE_TYPE and self.WANT_TREES: data = self.data['trees'][treeIndex] planted, waterLevel, lastCheck, growthLevel, lastHarvested = data if planted != -1: obj = self.plantTree(treeIndex, planted, waterLevel=waterLevel, lastCheck=lastCheck, growthLevel=growthLevel, lastHarvested=lastHarvested, generate=False) self.trees.add(obj) else: obj = self.placePlot(treeIndex) obj.setPos(x, y, 0) obj.setH(h) obj.setPlot(estatePlot) obj.setOwnerIndex(houseIndex) obj.generateWithRequired(estate.zoneId) treeIndex += 1 elif estatePlotType == GardenGlobals.FLOWER_TYPE and self.WANT_FLOWERS: data = self.data['flowers'][flowerIndex] planted, waterLevel, lastCheck, growthLevel, variety = data if planted != -1: obj = self.plantFlower(flowerIndex, planted, variety, waterLevel=waterLevel, lastCheck=lastCheck, growthLevel=growthLevel, generate=False) zOffset = 1.5 else: obj = self.placePlot(flowerIndex) obj.setFlowerIndex(flowerIndex) zOffset = 1.2 obj.setPlot(estatePlot) obj.setOwnerIndex(houseIndex) # <hack> index = (0, 1, 2, 2, 2, 3, 3, 3, 4, 4)[flowerIndex] idx = (0, 0, 0, 1, 2, 0, 1, 2, 0, 1)[flowerIndex] gardenBox = self._estateBoxes[index] xOffset = FLOWER_X_OFFSETS[gardenBox.getTypeIndex()][idx] obj.setPos(gardenBox, 0, 0, 0) obj.setZ(gardenBox, zOffset) obj.setX(gardenBox, xOffset) obj.setH(gardenBox, 0) # </hack> obj.generateWithRequired(estate.zoneId) flowerIndex += 1 elif estatePlotType == GardenGlobals.STATUARY_TYPE and self.WANT_STATUARY: data = self.data['statuary'] if data == 0: obj = self.placePlot(-1) else: obj = self.placeStatuary(data, generate=False) obj.setPos(x, y, 0) obj.setH(h) obj.setPlot(estatePlot) obj.setOwnerIndex(houseIndex) obj.generateWithRequired(estate.zoneId) for tree in self.trees: tree.calcDependencies() self.reconsiderAvatarOrganicBonus() return True