2015-03-16 08:41:50 -05:00
|
|
|
import random
|
2015-06-23 18:11:48 -05:00
|
|
|
from panda3d.core import *
|
2015-03-03 16:10:12 -06:00
|
|
|
from direct.task.Task import Task
|
|
|
|
from direct.distributed.ClockDelta import *
|
|
|
|
from direct.interval.IntervalGlobal import *
|
|
|
|
from direct.distributed import DistributedObject
|
|
|
|
from pandac.PandaModules import NodePath
|
|
|
|
from toontown.toonbase import ToontownGlobals
|
|
|
|
ChangeDirectionDebounce = 1.0
|
|
|
|
ChangeDirectionTime = 1.0
|
|
|
|
|
|
|
|
class DistributedMMPiano(DistributedObject.DistributedObject):
|
2015-03-16 08:41:50 -05:00
|
|
|
whitePartNodeName = 'midkey_floor_1'
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
def __init__(self, cr):
|
|
|
|
DistributedObject.DistributedObject.__init__(self, cr)
|
|
|
|
self.spinStartTime = 0.0
|
|
|
|
self.rpm = 0.0
|
|
|
|
self.degreesPerSecond = self.rpm / 60.0 * 360.0
|
|
|
|
self.offset = 0.0
|
|
|
|
self.speedUpSound = None
|
|
|
|
self.changeDirectionSound = None
|
|
|
|
self.lastChangeDirection = 0.0
|
|
|
|
|
|
|
|
def generate(self):
|
2015-03-16 08:41:50 -05:00
|
|
|
DistributedObject.DistributedObject.generate(self)
|
|
|
|
taskMgr.doMethodLater(4, self.setupGeom, self.uniqueName('setup-geom'))
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-03-16 08:41:50 -05:00
|
|
|
def setupGeom(self, task):
|
2015-07-05 18:59:25 -05:00
|
|
|
geom = self.cr.playGame.getPlace().loader.geom
|
2015-03-16 08:41:50 -05:00
|
|
|
self.piano = geom.find('**/center_icon')
|
|
|
|
if self.piano.isEmpty():
|
|
|
|
loader.notify.error('Piano not found')
|
|
|
|
return
|
|
|
|
|
|
|
|
geom.find('**/center_icon').setPos(0,-20.1,0)
|
|
|
|
geom.find('**/midkey_floor').setPos(0,20.1,0)
|
|
|
|
geom.find('**/pond_floor').setPos(0,20.1,0)
|
|
|
|
geom.find('**/pond_floor').setScale(1.01,1.01,1)
|
|
|
|
geom.find('**/MMsz_water').setPos(0,20.0,0)
|
|
|
|
geom.find('**/midkey_floor').setScale(1.01,1.01,1)
|
|
|
|
geom.find('**/midkey_floor_1').setScale(1.01,1.01,1)
|
2015-03-03 16:10:12 -06:00
|
|
|
base.cr.parentMgr.registerParent(ToontownGlobals.SPMinniesPiano, self.piano)
|
2015-03-16 08:41:50 -05:00
|
|
|
self.accept('enter' + self.whitePartNodeName, self.__handleOnFloor)
|
|
|
|
self.accept('exit' + self.whitePartNodeName, self.__handleOffFloor)
|
|
|
|
self.accept('entermid_fishpond', self.__handleChangeDirectionButton)
|
2015-03-03 16:10:12 -06:00
|
|
|
self.speedUpSound = base.loadSfx('phase_6/audio/sfx/SZ_MM_gliss.ogg')
|
|
|
|
self.changeDirectionSound = base.loadSfx('phase_6/audio/sfx/SZ_MM_cymbal.ogg')
|
|
|
|
self.__setupSpin()
|
2015-03-16 08:41:50 -05:00
|
|
|
return task.done
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def __setupSpin(self):
|
|
|
|
taskMgr.add(self.__updateSpin, self.taskName('pianoSpinTask'))
|
|
|
|
|
|
|
|
def __stopSpin(self):
|
|
|
|
taskMgr.remove(self.taskName('pianoSpinTask'))
|
|
|
|
|
|
|
|
def __updateSpin(self, task):
|
2015-03-16 08:41:50 -05:00
|
|
|
if self.degreesPerSecond == 0:
|
|
|
|
return Task.cont
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-03-16 08:41:50 -05:00
|
|
|
elapsed = globalClock.getRealTime() - self.spinStartTime
|
|
|
|
offset = self.offset
|
|
|
|
heading = ((self.degreesPerSecond * elapsed) + offset) % 360
|
|
|
|
self.piano.setH(heading)
|
2015-03-03 16:10:12 -06:00
|
|
|
return Task.cont
|
|
|
|
|
|
|
|
def disable(self):
|
2015-03-16 08:41:50 -05:00
|
|
|
if hasattr(self, 'piano'):
|
|
|
|
del self.piano
|
|
|
|
base.cr.parentMgr.unregisterParent(ToontownGlobals.SPMinniesPiano)
|
|
|
|
self.ignoreAll()
|
2015-03-03 16:10:12 -06:00
|
|
|
self.speedUpSound = None
|
|
|
|
self.changeDirectionSound = None
|
|
|
|
self.__stopSpin()
|
|
|
|
DistributedObject.DistributedObject.disable(self)
|
|
|
|
|
|
|
|
def setSpeed(self, rpm, offset, timestamp):
|
|
|
|
timestamp = globalClockDelta.networkToLocalTime(timestamp)
|
|
|
|
degreesPerSecond = rpm / 60.0 * 360.0
|
|
|
|
self.rpm = rpm
|
|
|
|
self.degreesPerSecond = degreesPerSecond
|
|
|
|
self.offset = offset
|
|
|
|
self.spinStartTime = timestamp
|
|
|
|
|
|
|
|
def playSpeedUp(self, avId):
|
|
|
|
if avId != base.localAvatar.doId:
|
|
|
|
base.playSfx(self.speedUpSound)
|
|
|
|
|
|
|
|
def playChangeDirection(self, avId):
|
|
|
|
if avId != base.localAvatar.doId:
|
|
|
|
base.playSfx(self.changeDirectionSound)
|
|
|
|
|
|
|
|
def __handleOnFloor(self, collEntry):
|
|
|
|
self.cr.playGame.getPlace().activityFsm.request('OnPiano')
|
|
|
|
self.sendUpdate('requestSpeedUp', [])
|
|
|
|
base.playSfx(self.speedUpSound)
|
|
|
|
|
|
|
|
def __handleOffFloor(self, collEntry):
|
|
|
|
self.cr.playGame.getPlace().activityFsm.request('off')
|
2015-03-16 08:41:50 -05:00
|
|
|
self.sendUpdate('requestSlowDown', [])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def __handleSpeedUpButton(self, collEntry):
|
|
|
|
self.sendUpdate('requestSpeedUp', [])
|
|
|
|
base.playSfx(self.speedUpSound)
|
|
|
|
|
|
|
|
def __handleChangeDirectionButton(self, collEntry):
|
|
|
|
now = globalClock.getFrameTime()
|
|
|
|
if now - self.lastChangeDirection < ChangeDirectionDebounce:
|
2015-03-16 08:41:50 -05:00
|
|
|
loader.notify.debug('Rejecting change direction.')
|
2015-03-03 16:10:12 -06:00
|
|
|
return
|
2015-03-16 08:41:50 -05:00
|
|
|
shouldChange = random.randint(1,10)
|
|
|
|
if int(shouldChange) == 10:
|
|
|
|
self.lastChangeDirection = now
|
|
|
|
self.sendUpdate('requestChangeDirection', [])
|
|
|
|
base.playSfx(self.changeDirectionSound)
|
|
|
|
else:
|
2015-07-05 18:59:25 -05:00
|
|
|
loader.notify.debug('Rejecting change direction.')
|