Poodletooth-iLand/toontown/estate/DistributedGarden.py

118 lines
3.7 KiB
Python
Raw Normal View History

from panda3d.core import *
2015-03-03 16:10:12 -06:00
from direct.distributed import DistributedObject
2015-05-13 12:02:48 -05:00
from direct.distributed.ClockDelta import *
2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
2015-05-13 12:02:48 -05:00
from direct.gui.DirectGui import *
from toontown.toonbase.ToonBaseGlobal import *
2015-03-03 16:10:12 -06:00
import HouseGlobals
class DistributedGarden(DistributedObject.DistributedObject):
notify = directNotify.newCategory('DistributedGarden')
def __init__(self, cr):
self.notify.debug('init')
DistributedObject.DistributedObject.__init__(self, cr)
self.lt = base.localAvatar
self.props = []
self.pos = None
self.radius = 0
self.gridCells = 20
self.propTable = [None] * self.gridCells
for i in xrange(len(self.propTable)):
self.propTable[i] = [None] * self.gridCells
self.dx = 1.0 / self.gridCells
self.occupied = []
return
def generate(self):
DistributedObject.DistributedObject.generate(self)
def announceGenerate(self):
DistributedObject.DistributedObject.announceGenerate(self)
def disable(self):
DistributedObject.DistributedObject.disable(self)
def unload(self):
pass
def delete(self):
for prop in self.props:
prop[0].removeNode()
del prop[0]
del prop
del self.props
self.props = None
self.unload()
return
def sendNewProp(self, prop, x, y, z):
self.notify.debug('sendNewProp')
print 'new prop (%d) = %s,%s,%s' % (prop,
x,
y,
z)
if prop == HouseGlobals.PROP_ICECUBE:
model = loader.loadModel('phase_8/models/props/icecube.bam')
elif prop == HouseGlobals.PROP_FLOWER:
model = loader.loadModel('phase_8/models/props/flower_treasure.bam')
elif prop == HouseGlobals.PROP_SNOWFLAKE:
model = loader.loadModel('phase_8/models/props/snowflake_treasure.bam')
model.reparentTo(hidden)
model.setPos(x, y, z)
model.setScale(0.2)
model.setBillboardPointEye()
model.reparentTo(render)
self.props.append([model,
x,
y,
z])
def getPropPos(self, i, j):
pos = [self.pos[0] - self.radius + 2 * self.radius * i, self.pos[1] - self.radius + 2 * self.radius * j, self.pos[2]]
return pos
def loadProp(self, prop, i, j):
pos = self.getPropPos(i, j)
if prop == HouseGlobals.PROP_ICECUBE:
model = loader.loadModel('phase_8/models/props/icecube.bam')
elif prop == HouseGlobals.PROP_FLOWER:
model = loader.loadModel('phase_8/models/props/flower_treasure.bam')
elif prop == HouseGlobals.PROP_SNOWFLAKE:
model = loader.loadModel('phase_8/models/props/snowflake_treasure.bam')
else:
self.notify.error('cant find prop: %s' % prop)
model.reparentTo(hidden)
model.setPos(pos[0], pos[1], pos[2])
model.setScale(0.2)
model.setBillboardPointEye()
model.reparentTo(render)
def setAddProp(self, prop, i, j):
self.notify.debug('addProp')
self.props.append([prop, i, j])
self.loadProp(prop, i, j)
self.b_setProps(self, props)
def b_setProps(self, props):
self.notify.debug('b_setProps')
self.setProps(props)
self.d_setProps(props)
def d_setProps(self, props):
self.notify.debug('d_setProps')
aProps = []
for prop in props:
aProps = aProps + prop
self.sendUpdate('setProps', [aProps])
def setProps(self, props):
self.notify.debug('setProps')
self.props = props
for prop in self.props:
pInd, i, j = prop
self.propTable[i, j] = pInd