当前位置: 首页>>代码示例>>Python>>正文


Python ClassicFSM.getCurrentState方法代码示例

本文整理汇总了Python中direct.fsm.ClassicFSM.ClassicFSM.getCurrentState方法的典型用法代码示例。如果您正苦于以下问题:Python ClassicFSM.getCurrentState方法的具体用法?Python ClassicFSM.getCurrentState怎么用?Python ClassicFSM.getCurrentState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在direct.fsm.ClassicFSM.ClassicFSM的用法示例。


在下文中一共展示了ClassicFSM.getCurrentState方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Toon

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]

#.........这里部分代码省略.........
        self.getNameTag().show()
        self.getGeomNode().show()

    def attachGun(self, gunName):
        self.detachGun()
        if gunName == 'pistol':
            self.gun = loader.loadModel('phase_4/models/props/water-gun.bam')
            self.gun.reparentTo(self.find('**/def_joint_right_hold'))
            self.gun.setPos(Point3(0.28, 0.1, 0.08))
            self.gun.setHpr(VBase3(85.6, -4.44, 94.43))
            self.gunAttached = True
        elif gunName == 'shotgun':
            self.gun = loader.loadModel('phase_4/models/props/shotgun.egg')
            self.gun.setScale(0.75)
            self.gun.reparentTo(self.find('**/def_joint_right_hold'))
            self.gun.setPos(Point3(-0.5, -0.2, 0.19))
            self.gun.setHpr(Vec3(350, 272.05, 0))
            color = random.choice([VBase4(1, 0.25, 0.25, 1), VBase4(0.25, 1, 0.25, 1), VBase4(0.25, 0.25, 1, 1)])
            self.gun.setColorScale(color)
            self.gunAttached = True

    def detachGun(self):
        if self.gun and self.gunAttached:
            self.gun.removeNode()
            self.gun = None
            self.gunAttached = False
        return

    def stopAnimations(self):
        if hasattr(self, 'animFSM'):
            if not self.animFSM.isInternalStateInFlux():
                self.animFSM.request('off')
            else:
                notify.warning('animFSM in flux, state=%s, not requesting off' % self.animFSM.getCurrentState().getName())
        else:
            notify.warning('animFSM has been deleted')
        if self.track != None:
            self.track.finish()
            DelayDelete.cleanupDelayDeletes(self.track)
            self.track = None
        return

    def disable(self):
        try:
            self.Toon_disabled
        except:
            self.Toon_disabled = 1
            self.backpack = None
            self.stopAnimations()
            self.removeAdminToken()
            ToonHead.delete(self)
            self.deleteCurrentToon()
            self.chatSoundDict = {}

        return

    def delete(self):
        try:
            self.Toon_deleted
        except:
            self.Toon_deleted = 1
            del self.animFSM
            self.forwardSpeed = None
            self.chatSoundDict = None
            self.rotateSpeed = None
            self.avatarType = None
开发者ID:coginvasion,项目名称:src,代码行数:70,代码来源:Toon.py

示例2: Human

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]

#.........这里部分代码省略.........
        self.detachNode()
        if gender == "f":
            other = others[1]
        else:
            other = others[0]
        if self.loaded:
            self.cleanupHuman()

        other.useFaceTex = useFaceTex
        self.loadHuman(other)
        if self.isLocal():
            self.renderReflection = True

        self.setRenderReflection()
        self.resetEffectParent()
        self.enableMixing()
        self.reparentTo(parent)

    def getShadowJoint(self):
        return self.nametagNodePath

    def getNametagJoints(self):
        joints = []
        for lodName in self.getLODNames():
            bundle = self.getPartBundle("modelRoot", lodName)
            joint = bundle.findChild("name_tag")
            if joint:
                joints.append(joint)
                continue

        return joints

    def _Human__blinkOpenEyes(self, task):
        if self.eyeFSM.getCurrentState().getName() == "closed":
            self.eyeFSM.request("open")

        r = self.randGen.random()
        if r < 0.10000000000000001:
            t = 0.20000000000000001
        else:
            t = r * 4.0 + 1.0
        taskMgr.doMethodLater(t, self._Human__blinkCloseEyes, self._Human__blinkName)
        return Task.done

    def _Human__blinkCloseEyes(self, task):
        if self.eyeFSM.getCurrentState().getName() != "open":
            taskMgr.doMethodLater(4.0, self._Human__blinkCloseEyes, self._Human__blinkName)
        else:
            self.eyeFSM.request("closed")
            taskMgr.doMethodLater(0.125, self._Human__blinkOpenEyes, self._Human__blinkName)
        return Task.done

    def startBlink(self):
        taskMgr.remove(self._Human__blinkName)
        if self.eyeLids:
            self.openEyes()

        taskMgr.doMethodLater(self.randGen.random() * 4.0 + 1, self._Human__blinkCloseEyes, self._Human__blinkName)

    def stopBlink(self):
        taskMgr.remove(self._Human__blinkName)
        if self.eyeLids:
            self.eyeFSM.request("open")

    def closeEyes(self):
        self.eyeFSM.request("closed")
开发者ID:Puggyblue999,项目名称:PiratesOfTheCarribeanOnline,代码行数:70,代码来源:Human.py

示例3: DynamicHuman

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]

#.........这里部分代码省略.........

        if other and not (other.master) and other.loaded:
            other.cleanupHuman()
        elif self.loaded:
            self.cleanupHuman()

        self.loadHuman(self.style.gender, other)
        if self.isLocal():
            self.renderReflection = True

        self.setRenderReflection()
        self.disableMixing()
        self.enableMixing()

    generateHuman = quickProfile('loadHuman')(generateHuman)

    def getShadowJoint(self):
        return self


    def getNametagJoints(self):
        joints = []
        for lodName in self.getLODNames():
            bundle = self.getPartBundle('legs', lodName)
            joint = bundle.findChild('name_tag')
            if joint:
                joints.append(joint)
                continue

        return joints


    def _DynamicHuman__blinkOpenEyes(self, task):
        if self.eyeFSM.getCurrentState().getName() == 'closed':
            self.eyeFSM.request('open')

        r = self.randGen.random()
        if r < 0.10000000000000001:
            t = 0.20000000000000001
        else:
            t = r * 4.0 + 1.0
        taskMgr.doMethodLater(t, self._DynamicHuman__blinkCloseEyes, self._DynamicHuman__blinkName)
        return Task.done


    def _DynamicHuman__blinkCloseEyes(self, task):
        if self.eyeFSM.getCurrentState().getName() != 'open':
            taskMgr.doMethodLater(4.0, self._DynamicHuman__blinkCloseEyes, self._DynamicHuman__blinkName)
        else:
            self.eyeFSM.request('closed')
            taskMgr.doMethodLater(0.125, self._DynamicHuman__blinkOpenEyes, self._DynamicHuman__blinkName)
        return Task.done


    def startBlink(self):
        taskMgr.remove(self._DynamicHuman__blinkName)
        if self.eyeLids:
            self.openEyes()

        taskMgr.doMethodLater(self.randGen.random() * 4.0 + 1, self._DynamicHuman__blinkCloseEyes, self._DynamicHuman__blinkName)


    def stopBlink(self):
        taskMgr.remove(self._DynamicHuman__blinkName)
        if self.eyeLids:
            self.eyeFSM.request('open')
开发者ID:TTGhost,项目名称:POTCOR-src,代码行数:70,代码来源:DynamicHuman.py

示例4: Char

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]
class Char(Avatar.Avatar):

    def __init__(self):
        try:
            self.Char_initialized
            return
        except:
            self.Char_initialized = 1

        Avatar.Avatar.__init__(self)
        self.avatarType = CIGlobals.CChar
        self.avatarName = None
        self.currentAnim = None
        self.charType = ''
        self.eyes = loader.loadTexture('phase_3/maps/eyes1.jpg', 'phase_3/maps/eyes1_a.rgb')
        self.closedEyes = loader.loadTexture('phase_3/maps/mickey_eyes_closed.jpg', 'phase_3/maps/mickey_eyes_closed_a.rgb')
        self.animFSM = ClassicFSM('Char', [State('off', self.enterOff, self.exitOff),
         State('neutral', self.enterNeutral, self.exitNeutral),
         State('walk', self.enterWalk, self.exitWalk),
         State('run', self.enterRun, self.exitRun)], 'off', 'off')
        animStateList = self.animFSM.getStates()
        self.animFSM.enterInitialState()
        Avatar.Avatar.initializeBodyCollisions(self, self.avatarType, 3.5, 1)
        return

    def stopAnimations(self):
        if hasattr(self, 'animFSM'):
            if not self.animFSM.isInternalStateInFlux():
                self.animFSM.request('off')
            else:
                notify.warning('animFSM in flux, state=%s, not requesting off' % self.animFSM.getCurrentState().getName())
        else:
            notify.warning('animFSM has been deleted')

    def disable(self):
        self.stopBlink()
        self.stopAnimations()
        Avatar.Avatar.disable(self)

    def delete(self):
        try:
            self.Char_deleted
        except:
            self.Char_deleted = 1
            del self.animFSM
            Avatar.Avatar.delete(self)

    def setChat(self, chatString):
        if self.charType == CIGlobals.Mickey:
            self.dial = base.audio3d.loadSfx('phase_3/audio/dial/mickey.wav')
        elif self.charType == CIGlobals.Minnie:
            self.dial = base.audio3d.loadSfx('phase_3/audio/dial/minnie.wav')
        elif self.charType == CIGlobals.Goofy:
            self.dial = base.audio3d.loadSfx('phase_6/audio/dial/goofy.wav')
        base.audio3d.attachSoundToObject(self.dial, self)
        self.dial.play()
        Avatar.Avatar.setChat(self, chatString)

    def setName(self, nameString, charName = None):
        self.avatarName = nameString
        Avatar.Avatar.setName(self, nameString, avatarType=self.avatarType, charName=charName)

    def generateChar(self, charType):
        self.charType = charType
        if charType == CIGlobals.Mickey or charType == CIGlobals.Minnie:
            self.loadModel('phase_3/models/char/' + charType.lower() + '-' + str(CIGlobals.ModelDetail(self.avatarType)) + '.bam')
            self.loadAnims({'neutral': 'phase_3/models/char/' + charType.lower() + '-wait.bam',
             'walk': 'phase_3/models/char/' + charType.lower() + '-walk.bam',
             'run': 'phase_3/models/char/' + charType.lower() + '-run.bam',
             'left-start': 'phase_3.5/models/char/' + charType.lower() + '-left-start.bam',
             'left': 'phase_3.5/models/char/' + charType.lower() + '-left.bam',
             'right-start': 'phase_3.5/models/char/' + charType.lower() + '-right-start.bam',
             'right': 'phase_3.5/models/char/' + charType.lower() + '-right.bam'})
            if charType == CIGlobals.Mickey:
                self.mickeyEye = self.controlJoint(None, 'modelRoot', 'joint_pupilR')
                self.mickeyEye.setY(0.025)
            for bundle in self.getPartBundleDict().values():
                bundle = bundle['modelRoot'].getBundle()
                earNull = bundle.findChild('sphere3')
                if not earNull:
                    earNull = bundle.findChild('*sphere3')
                earNull.clearNetTransforms()

            for bundle in self.getPartBundleDict().values():
                charNodepath = bundle['modelRoot'].partBundleNP
                bundle = bundle['modelRoot'].getBundle()
                earNull = bundle.findChild('sphere3')
                if not earNull:
                    earNull = bundle.findChild('*sphere3')
                ears = charNodepath.find('**/sphere3')
                if ears.isEmpty():
                    ears = charNodepath.find('**/*sphere3')
                ears.clearEffect(CharacterJointEffect.getClassType())
                earRoot = charNodepath.attachNewNode('earRoot')
                earPitch = earRoot.attachNewNode('earPitch')
                earPitch.setP(40.0)
                ears.reparentTo(earPitch)
                earNull.addNetTransform(earRoot.node())
                ears.clearMat()
                ears.node().setPreserveTransform(ModelNode.PTNone)
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:Char.py

示例5: CogBrain

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]
class CogBrain(DirectObject):
    PANIC_SPEED = 0.15
    PANIC_DELAY = 0.5
    RUNAWAY_SPEED = 0.1
    RUNAWAY_SAFE_DISTANCE = 50
    MAX_BOSS_HELPERS = 5
    PANIC_HP_FACTOR = 0.222
    ATTACK_DISTANCE = 40.0
    MAX_ATTACKERS = 3
    Difficulty2MaxAttackThrows = {}
    for level in range(1, 5):
        Difficulty2MaxAttackThrows[level] = 3

    for level in range(5, 10):
        Difficulty2MaxAttackThrows[level] = 4

    for level in range(9, 13):
        Difficulty2MaxAttackThrows[level] = 5

    def __init__(self, suit):
        self.suit = suit
        self.panicHP = self.suit.getMaxHealth() * self.PANIC_HP_FACTOR
        self.fsm = ClassicFSM('CogBrain', [State('off', self.enterOff, self.exitOff),
         State('neutral', self.enterNeutral, self.exitNeutral),
         State('followBoss', self.enterFollowBoss, self.exitFollowBoss),
         State('panic', self.enterPanic, self.exitPanic),
         State('runAway', self.enterRunAway, self.exitRunAway)], 'off', 'off')
        self.fsm.enterInitialState()

    def start(self):
        taskMgr.add(self.__think, self.suit.uniqueName('think'))

    def end(self, andGoOff = 1):
        taskMgr.remove(self.suit.uniqueName('think'))
        if andGoOff:
            self.fsm.request('off')

    def __think(self, task = None):
        if task:
            task.delayTime = 1
        if self.suit.getAttacking():
            if task:
                return task.again
            else:
                return
        _help_priority = 0
        _panic_priority = 0
        _run_priority = 0
        _helper_suits = 0
        boss = None
        for av in self.suit.getManager().suits.values():
            if av.doId != self.suit.doId:
                if av.head in ('vp',):
                    boss = av
                    for suit in self.suit.getManager().suits.values():
                        if suit.doId != self.suit.doId:
                            if suit.brain:
                                if suit.brain.fsm.getCurrentState().getName() == 'followBoss':
                                    _helper_suits += 1

        if _helper_suits == self.MAX_BOSS_HELPERS - 1:
            _help_priority = 2
        elif _helper_suits == self.MAX_BOSS_HELPERS - 2:
            _help_priority = 2.5
        elif _helper_suits == self.MAX_BOSS_HELPERS - 3:
            _help_priority = 3.5
        elif _helper_suits == self.MAX_BOSS_HELPERS - 4:
            _help_priority = 4
        elif _helper_suits == self.MAX_BOSS_HELPERS - 5:
            _help_priority = 4.5
        if boss == None or _helper_suits == self.MAX_BOSS_HELPERS:
            _help_priority = 0
        if self.fsm.getCurrentState().getName() == 'followBoss':
            if self.bossSpotKey != boss.boss.spot:
                self.fsm.request('followBoss', [boss])
                return task.again
        _toons_in_range = 0
        in_range = 15
        for av in self.suit.air.doId2do.values():
            if av.__class__.__name__ == 'DistributedToonAI':
                if av.zoneId == self.suit.zoneId:
                    if self.suit.getDistance(av) <= in_range:
                        _toons_in_range += 1

        if self.fsm.getCurrentState().getName() == 'followBoss':
            _panic_priority = _toons_in_range / 0.85
        else:
            _panic_priority = _toons_in_range / 0.75
        if self.fsm.getCurrentState().getName() == 'panic' and _toons_in_range > 0:
            _run_priority = 5
        if self.suit.getHealth() <= self.panicHP:
            if _panic_priority < 4:
                _panic_priority = 4
        if _run_priority == 5:
            self.fsm.request('runAway', [av])
            del _help_priority
            del _panic_priority
            del _run_priority
            del _helper_suits
            del boss
#.........这里部分代码省略.........
开发者ID:coginvasion,项目名称:src,代码行数:103,代码来源:CogBrainAI.py

示例6: MasterHuman

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]

#.........这里部分代码省略.........

    def cleanupHuman(self, gender = 'm'):
        self.eyeFSM.request('off')
        self.undoControlJoints()
        self.eyeLids = { }
        self.eyeBalls = { }
        self.eyeIris = { }
        self.flush()
        self.loaded = 0
        self.master = 0


    def generateHuman(self, gender = 'm'):
        self.loadHuman(self.style.gender)


    def getShadowJoint(self):
        return self


    def getNametagJoints(self):
        joints = []
        for lodName in self.getLODNames():
            bundle = self.getPartBundle('legs', lodName)
            joint = bundle.findChild('name_tag')
            if joint:
                joints.append(joint)
                continue

        return joints


    def _MasterHuman__blinkOpenEyes(self, task):
        if self.eyeFSM.getCurrentState().getName() == 'closed':
            self.eyeFSM.request('open')

        r = self.randGen.random()
        if r < 0.10000000000000001:
            t = 0.20000000000000001
        else:
            t = r * 4.0 + 1.0
        taskMgr.doMethodLater(t, self._MasterHuman__blinkCloseEyes, self._MasterHuman__blinkName)
        return Task.done


    def _MasterHuman__blinkCloseEyes(self, task):
        if self.eyeFSM.getCurrentState().getName() != 'open':
            taskMgr.doMethodLater(4.0, self._MasterHuman__blinkCloseEyes, self._MasterHuman__blinkName)
        else:
            self.eyeFSM.request('closed')
            taskMgr.doMethodLater(0.125, self._MasterHuman__blinkOpenEyes, self._MasterHuman__blinkName)
        return Task.done


    def startBlink(self):
        taskMgr.remove(self._MasterHuman__blinkName)
        if self.eyeLids:
            self.openEyes()

        taskMgr.doMethodLater(self.randGen.random() * 4.0 + 1, self._MasterHuman__blinkCloseEyes, self._MasterHuman__blinkName)


    def stopBlink(self):
        taskMgr.remove(self._MasterHuman__blinkName)
        if self.eyeLids:
            self.eyeFSM.request('open')
开发者ID:XamarinDeveloper,项目名称:Pirates-Online-Source,代码行数:70,代码来源:MasterHuman.py

示例7: ToonHead

# 需要导入模块: from direct.fsm.ClassicFSM import ClassicFSM [as 别名]
# 或者: from direct.fsm.ClassicFSM.ClassicFSM import getCurrentState [as 别名]

#.........这里部分代码省略.........
            searchRoot.find('**/head-long').removeNode()
            searchRoot.find('**/head-front-long').removeNode()
        else:
            searchRoot.find('**/head-long').hide()
            searchRoot.find('**/head-front-long').hide()
        if animalType != 'rabbit':
            muzzleParts = searchRoot.findAllMatches('**/muzzle-short*')
            for partNum in range(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()
        else:
            muzzleParts = searchRoot.findAllMatches('**/muzzle-long*')
            for partNum in range(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

    def __fixHeadShortShort(self, style, lodName=None, copy=1):
        if lodName == None:
            searchRoot = self
        else:
            searchRoot = self.find('**/' + str(lodName))
        otherParts = searchRoot.findAllMatches('**/*long*')
        for partNum in range(0, otherParts.getNumPaths()):
            if copy:
                otherParts.getPath(partNum).removeNode()
            else:
                otherParts.getPath(partNum).stash()

    def __blinkOpenEyes(self, task):
        if self.eyelids.getCurrentState().getName() == 'closed':
            self.eyelids.request('open')
        r = self.randGen.random()
        if r < 0.1:
            t = 0.2
        else:
            t = r * 4.0 + 1.0
        taskMgr.doMethodLater(t, self.__blinkCloseEyes, self.__blinkName)
        return Task.done

    def __blinkCloseEyes(self, task):
        if self.eyelids.getCurrentState().getName() != 'open':
            taskMgr.doMethodLater(4.0, self.__blinkCloseEyes, self.__blinkName)
        else:
            self.eyelids.request('closed')
            taskMgr.doMethodLater(0.125, self.__blinkOpenEyes, self.__blinkName)
        return Task.done

    def startBlink(self):
        taskMgr.remove(self.__blinkName)
        if self.__eyes:
            self.openEyes()
        taskMgr.doMethodLater(self.randGen.random() * 4.0 + 1, self.__blinkCloseEyes, self.__blinkName)

    def stopBlink(self):
        taskMgr.remove(self.__blinkName)
        if self.__eyes:
            self.eyelids.request('open')

    def closeEyes(self):
        self.eyelids.request('closed')

    def openEyes(self):
开发者ID:masterbate,项目名称:AIPractive,代码行数:70,代码来源:ToonHead.py


注:本文中的direct.fsm.ClassicFSM.ClassicFSM.getCurrentState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。