Poodletooth-iLand/toontown/estate/DistributedPlantBaseAI.py

85 lines
3 KiB
Python
Raw Normal View History

2015-03-03 22:10:12 +00:00
from direct.directnotify import DirectNotifyGlobal
from toontown.estate.DistributedLawnDecorAI import DistributedLawnDecorAI
2015-05-24 23:23:54 +00:00
import GardenGlobals
import datetime
2015-03-03 22:10:12 +00:00
class DistributedPlantBaseAI(DistributedLawnDecorAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedPlantBaseAI")
2015-05-10 12:10:32 +00:00
def __init__(self, air):
2015-05-24 23:23:54 +00:00
DistributedLawnDecorAI.__init__(self, air)
2015-05-10 12:10:32 +00:00
self.air = air
2015-05-24 23:23:54 +00:00
self.growthLevel = -1
2015-05-10 12:10:32 +00:00
2015-05-24 23:23:54 +00: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 22:10:12 +00:00
2015-05-10 11:47:03 +00:00
def setWaterLevel(self, water):
2015-05-24 23:23:54 +00:00
self.waterLevel = water
def getWaterLevel(self):
return self.waterLevel
2015-03-03 22:10:12 +00:00
2015-05-10 11:47:03 +00:00
def setGrowthLevel(self, growth):
2015-05-24 23:23:54 +00:00
self.growthLevel = growth
def getGrowthLevel(self):
return self.growthLevel
2015-03-03 22:10:12 +00:00
2015-05-24 23:23:54 +00:00
def waterPlant(self, avId):
2015-06-11 17:48:13 +00:00
# TODO: Proper water threshold for watering can type.
# Not supposed to be 16 for all watering cans.
2015-05-24 23:23:54 +00:00
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 22:10:12 +00:00
def waterPlantDone(self):
2015-05-24 23:23:54 +00: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
2015-06-11 17:48:13 +00:00
# TODO: Possibly store this in mongodb/cPickle instead.
2015-05-24 23:23:54 +00:00
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()