Poodletooth-iLand/toontown/estate/DistributedPlantBaseAI.py

82 lines
2.8 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from toontown.estate.DistributedLawnDecorAI import DistributedLawnDecorAI
2015-05-24 18:23:54 -05:00
import GardenGlobals
import datetime
2015-03-03 16:10:12 -06:00
class DistributedPlantBaseAI(DistributedLawnDecorAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedPlantBaseAI")
2015-05-10 07:10:32 -05:00
def __init__(self, air):
2015-05-24 18:23:54 -05:00
DistributedLawnDecorAI.__init__(self, air)
2015-05-10 07:10:32 -05:00
self.air = air
2015-05-24 18:23:54 -05:00
self.growthLevel = -1
2015-05-10 07:10:32 -05:00
2015-05-24 18:23:54 -05:00
def announceGenerate(self):
DistributedLawnDecorAI.announceGenerate(self)
def delete(self):
DistributedLawnDecorAI.delete(self)
def disable(self):
DistributedLawnDecorAI.disable(self)
def setOwnerPlot(self, owner):
self.ownerPlot = owner
def getOwnerPlot(self):
return self.ownerPlot
def setTypeIndex(self, typeIndex):
self.typeIndex = typeIndex
self.attributes = GardenGlobals.PlantAttributes[typeIndex]
self.name = self.attributes['name']
self.plantType = self.attributes['plantType']
self.growthThresholds = self.attributes['growthThresholds']
self.maxWaterLevel = self.attributes['maxWaterLevel']
self.minWaterLevel = self.attributes['minWaterLevel']
def getTypeIndex(self):
return self.typeIndex
2015-03-03 16:10:12 -06:00
2015-05-10 06:47:03 -05:00
def setWaterLevel(self, water):
2015-05-24 18:23:54 -05:00
self.waterLevel = water
def getWaterLevel(self):
return self.waterLevel
2015-03-03 16:10:12 -06:00
2015-05-10 06:47:03 -05:00
def setGrowthLevel(self, growth):
2015-05-24 18:23:54 -05:00
self.growthLevel = growth
def getGrowthLevel(self):
return self.growthLevel
2015-03-03 16:10:12 -06:00
2015-05-24 18:23:54 -05:00
def waterPlant(self, avId):
self.lastWateredBy = avId
newLevel = self.waterLevel + 1
if newLevel > self.maxWaterLevel:
self.setWaterLevel(self.maxWaterLevel)
else:
self.setWaterLevel(newLevel)
self.sendUpdate('setMovie', [GardenGlobals.MOVIE_WATER, avId])
self.sendUpdate('setWaterLevel', [self.getWaterLevel()])
2015-03-03 16:10:12 -06:00
def waterPlantDone(self):
2015-05-24 18:23:54 -05:00
if hasattr(self, 'lastWateredBy'):
av = simbase.air.doId2do.get(self.lastWateredBy)
skill = av.getWateringCanSkill()
skill += GardenGlobals.WateringCanAttributes[av.wateringCan]['skillPts'] / 100
av.b_setWateringCanSkill(skill)
del self.lastWateredBy
estate = simbase.air.doId2do.get(self.getEstate())
dataIndex = -1
for n, item in enumerate(estate.items[self.getOwnerIndex()]):
if item[0] == self.getPlot():
dataIndex = n
if dataIndex >= 0:
dtime = int(datetime.datetime.now().strftime('%Y%m%d%H%M'))
data = list(estate.items[self.getOwnerIndex()][dataIndex])
data[4] = self.getWaterLevel()
data[8] = dtime
estate.items[self.getOwnerIndex()][dataIndex] = tuple(data)
estate.updateItems()