Poodletooth-iLand/toontown/estate/DistributedStatuaryAI.py

66 lines
2 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
2015-07-20 14:53:53 -05:00
from DistributedLawnDecorAI import DistributedLawnDecorAI
import GardenGlobals
import time
FOUR_DAYS = 86400 * 4
2015-03-03 16:10:12 -06:00
class DistributedStatuaryAI(DistributedLawnDecorAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedStatuaryAI")
2015-07-20 14:53:53 -05:00
def calculate(self, lastCheck):
self.attributes = GardenGlobals.PlantAttributes[self.index]
self.growthThresholds = self.attributes.get('growthThresholds', (0, 0))
now = int(time.time())
self.lastCheck = lastCheck
if self.lastCheck == 0:
self.lastCheck = now
2015-03-03 16:10:12 -06:00
2015-07-20 14:53:53 -05:00
self.growthLevel = min((now - self.lastCheck) // FOUR_DAYS, self.growthThresholds[-1] + 1)
self.update()
2015-03-03 16:10:12 -06:00
2015-05-24 18:23:54 -05:00
def getTypeIndex(self):
2015-07-20 14:53:53 -05:00
return self.index
2015-05-24 18:23:54 -05:00
def getWaterLevel(self):
2015-07-20 14:53:53 -05:00
return 1
2015-05-24 18:23:54 -05:00
def getGrowthLevel(self):
return self.growthLevel
2015-07-20 14:53:53 -05:00
def getOptional(self):
return self.data
def update(self):
self.mgr.data['statuary'] = self.mgr.S_pack(self.data, self.lastCheck, self.index, self.growthLevel)
self.mgr.update()
def removeItem(self):
avId = self.air.getAvatarIdFromSender()
self.d_setMovie(GardenGlobals.MOVIE_REMOVE)
def _remove(task):
if not self.air:
return
plot = self.mgr.placePlot(-1)
plot.setPlot(self.plot)
plot.setPos(self.getPos())
plot.setH(self.getH())
plot.setOwnerIndex(self.ownerIndex)
plot.generateWithRequired(self.zoneId)
self.air.writeServerEvent('remove-statuary', avId, plot=self.plot)
self.requestDelete()
self.mgr.objects.remove(self)
self.mgr.data['statuary'] = 0
self.mgr.update()
return task.done
taskMgr.doMethodLater(7, _remove, self.uniqueName('do-remove'))