Poodletooth-iLand/toontown/safezone/Walk.py

113 lines
4 KiB
Python
Raw Normal View History

from panda3d.core import *
2015-03-03 16:10:12 -06:00
from direct.task.Task import Task
from direct.directnotify import DirectNotifyGlobal
from direct.fsm import StateData
from direct.fsm import ClassicFSM, State
import colorsys
2015-03-03 16:10:12 -06:00
class Walk(StateData.StateData):
notify = DirectNotifyGlobal.directNotify.newCategory('Walk')
def __init__(self, doneEvent):
StateData.StateData.__init__(self, doneEvent)
self.fsm = ClassicFSM.ClassicFSM('Walk', [State.State('off', self.enterOff, self.exitOff, ['walking', 'swimming', 'slowWalking']),
State.State('walking', self.enterWalking, self.exitWalking, ['swimming', 'slowWalking']),
State.State('swimming', self.enterSwimming, self.exitSwimming, ['walking', 'slowWalking']),
State.State('slowWalking', self.enterSlowWalking, self.exitSlowWalking, ['walking', 'swimming'])], 'off', 'off')
self.fsm.enterInitialState()
self.swimSoundPlaying = 0
def load(self):
pass
def unload(self):
del self.fsm
def enter(self, slowWalk = 0):
base.localAvatar.startPosHprBroadcast()
base.localAvatar.startBlink()
base.localAvatar.attachCamera()
shouldPush = 1
if len(base.localAvatar.cameraPositions) > 0:
shouldPush = not base.localAvatar.cameraPositions[base.localAvatar.cameraIndex][4]
base.localAvatar.startUpdateSmartCamera(shouldPush)
base.localAvatar.showName()
base.localAvatar.collisionsOn()
base.localAvatar.startGlitchKiller()
base.localAvatar.enableAvatarControls()
def exit(self):
self.fsm.request('off')
self.ignore('control')
base.localAvatar.disableAvatarControls()
2015-07-30 17:15:21 -05:00
if not base.localAvatar.preventCameraDisable:
base.localAvatar.stopUpdateSmartCamera()
base.localAvatar.detachCamera()
2015-03-03 16:10:12 -06:00
base.localAvatar.stopPosHprBroadcast()
base.localAvatar.stopBlink()
base.localAvatar.stopGlitchKiller()
base.localAvatar.collisionsOff()
base.localAvatar.controlManager.placeOnFloor()
def enterOff(self):
pass
def exitOff(self):
pass
def enterWalking(self):
if base.localAvatar.hp > 0:
base.localAvatar.startTrackAnimToSpeed()
base.localAvatar.setWalkSpeedNormal()
base.localAvatar.applyBuffs()
else:
self.fsm.request('slowWalking')
def exitWalking(self):
base.localAvatar.stopTrackAnimToSpeed()
def enterSwimming(self, swimSound):
base.localAvatar.setWalkSpeedNormal()
base.localAvatar.applyBuffs()
self.swimSound = swimSound
self.swimSoundPlaying = 0
base.localAvatar.b_setAnimState('swim', base.localAvatar.animMultiplier)
2015-06-27 10:14:04 -05:00
taskMgr.add(self.__swimSoundTest, 'localToonSwimming')
2015-03-03 16:10:12 -06:00
def exitSwimming(self):
taskMgr.remove('localToonSwimming')
self.swimSound.stop()
del self.swimSound
self.swimSoundPlaying = 0
2015-07-05 18:59:25 -05:00
2015-06-27 10:14:04 -05:00
def __swimSoundTest(self, task):
speed, rotSpeed, slideSpeed = base.localAvatar.controlManager.getSpeeds()
if (speed or rotSpeed):
if not self.swimSoundPlaying:
self.swimSoundPlaying = 1
base.playSfx(self.swimSound, looping=1)
elif self.swimSoundPlaying:
2015-03-03 16:10:12 -06:00
self.swimSoundPlaying = 0
self.swimSound.stop()
2015-06-27 10:14:04 -05:00
2015-07-01 06:50:47 -05:00
saturation = min(max((base.localAvatar.getZ() / -12.3), 0.51), 1)
self.getFog().setColor(*colorsys.hsv_to_rgb(0.616, saturation, 0.5))
2015-03-03 16:10:12 -06:00
return Task.cont
2015-07-05 18:59:25 -05:00
2015-07-01 06:50:47 -05:00
def getFog(self):
return base.cr.playGame.hood.fog if hasattr(base.cr.playGame.hood, 'fog') else base.cr.playGame.place.fog
2015-03-03 16:10:12 -06:00
def enterSlowWalking(self):
self.accept(base.localAvatar.uniqueName('positiveHP'), self.__handlePositiveHP)
base.localAvatar.startTrackAnimToSpeed()
base.localAvatar.setWalkSpeedSlow()
def __handlePositiveHP(self):
self.fsm.request('walking')
def exitSlowWalking(self):
base.localAvatar.stopTrackAnimToSpeed()
self.ignore(base.localAvatar.uniqueName('positiveHP'))