Beispiel #1
0
def loadModel(file, collision=None, animation=None):
    model=None
    if animation:
        model=Actor(file, animation)                   
        #default anim
        if 'default' in animation:
            model.loop('default')
        elif 'idle' in animation:
            model.loop('idle')
        else: #some random anim
             model.loop(animation.items()[0])
    else:
        model=loader.loadModel(file)
    model.setPythonTag('model_file', file)
    #load shaders
    for geom in model.findAllMatches('**/+GeomNode'):
        if geom.hasTag('light'):
            model.setPythonTag('hasLight', True)
        if geom.hasTag('particle'):
            file='particle/'+geom.getTag('particle')
            if os.path.exists(file):
                with open(file) as f:  
                    values=json.load(f)
                p=createEffect(values)                
                model.setPythonTag('particle', p)    
                p.start(parent=model, renderParent=render) 
        if geom.hasTag('cg_shader'):            
            geom.setShader(loader.loadShader("shaders/"+geom.getTag('cg_shader')))
        elif geom.hasTag('glsl_shader'):  
            glsl_shader=geom.getTag('glsl_shader')  
            geom.setShader(Shader.load(Shader.SLGLSL, "shaders/{0}_v.glsl".format(glsl_shader),"shaders/{0}_f.glsl".format(glsl_shader)))
        else:
            #geom.setShader(loader.loadShader("shaders/default.cg"))
            geom.setShader(Shader.load(Shader.SLGLSL, "shaders/default_v.glsl","shaders/default_f.glsl"))
    #collisions        
    model.setCollideMask(BitMask32.allOff())
    if collision:
        coll=loader.loadModel(collision)
        coll.reparentTo(model)
        coll.find('**/collision').setCollideMask(BitMask32.bit(2))        
        coll.find('**/collision').setPythonTag('object', model)
        if animation:
            model.setPythonTag('actor_files', [file,animation,coll]) 
    else:
        try:
            model.find('**/collision').setCollideMask(BitMask32.bit(2))        
            model.find('**/collision').setPythonTag('object', model)        
        except:
            print "WARNING: Model {0} has no collision geometry!\nGenerating collision sphere...".format(file)
            bounds=model.getBounds()
            radi=bounds.getRadius()
            cent=bounds.getCenter()
            coll_sphere=model.attachNewNode(CollisionNode('collision'))
            coll_sphere.node().addSolid(CollisionSphere(cent[0],cent[1],cent[2], radi)) 
            coll_sphere.setCollideMask(BitMask32.bit(2))        
            coll_sphere.setPythonTag('object', model)
            #coll_sphere.show()
            if animation:
                model.setPythonTag('actor_files', [file,animation,None])
    return model    
Beispiel #2
0
    def create_node(self):
        if self.model == "Grenade":
            m = Actor('grenade.egg')
            shell = m.find('**/shell')
            shell.setColor(1,.3,.3,1)
            inner_top = m.find('**/inner_top')
            inner_bottom = m.find('**/inner_bottom')
            inner_top.setColor(.4,.4,.4,1)
            inner_bottom.setColor(.4,.4,.4,1)
            self.spin_bone = m.controlJoint(None, 'modelRoot', 'grenade_bone')
            m.set_scale(GRENADE_SCALE)

        elif self.model == "Missile":
            m = load_model('missile.egg')
            body = m.find('**/bodywings')
            body.set_color(.3,.3,1,1)
            main_engines = m.find('**/mainengines')
            wing_engines = m.find('**/wingengines')
            main_engines.set_color(.1,.1,.1,1)
            wing_engines.set_color(.1,.1,.1,1)
            m.set_scale(MISSILE_SCALE)
        else:
            m = load_model('misc/rgbCube')
            m.set_scale(.5)
            m.set_hpr(45,45,45)
        return m
Beispiel #3
0
    def create_node(self):
        if self.model == "Grenade":
            m = Actor('grenade.egg')
            shell = m.find('**/shell')
            shell.setColor(1, .3, .3, 1)
            inner_top = m.find('**/inner_top')
            inner_bottom = m.find('**/inner_bottom')
            inner_top.setColor(.4, .4, .4, 1)
            inner_bottom.setColor(.4, .4, .4, 1)
            self.spin_bone = m.controlJoint(None, 'modelRoot', 'grenade_bone')
            m.set_scale(GRENADE_SCALE)

        elif self.model == "Missile":
            m = load_model('missile.egg')
            body = m.find('**/bodywings')
            body.set_color(.3, .3, 1, 1)
            main_engines = m.find('**/mainengines')
            wing_engines = m.find('**/wingengines')
            main_engines.set_color(.1, .1, .1, 1)
            wing_engines.set_color(.1, .1, .1, 1)
            m.set_scale(MISSILE_SCALE)
        else:
            m = load_model('misc/rgbCube')
            m.set_scale(.5)
            m.set_hpr(45, 45, 45)
        return m
Beispiel #4
0
    def create_node(self):
        if self.model == "Grenade":
            m = Actor("grenade.egg")
            shell = m.find("**/shell")
            shell.setColor(1, 0.3, 0.3, 1)
            inner_top = m.find("**/inner_top")
            inner_bottom = m.find("**/inner_bottom")
            inner_top.setColor(0.4, 0.4, 0.4, 1)
            inner_bottom.setColor(0.4, 0.4, 0.4, 1)
            self.spin_bone = m.controlJoint(None, "modelRoot", "grenade_bone")
            m.set_scale(GRENADE_SCALE)

        elif self.model == "Missile":
            m = load_model("missile.egg")
            body = m.find("**/bodywings")
            body.set_color(0.3, 0.3, 1, 1)
            main_engines = m.find("**/mainengines")
            wing_engines = m.find("**/wingengines")
            main_engines.set_color(0.1, 0.1, 0.1, 1)
            wing_engines.set_color(0.1, 0.1, 0.1, 1)
            m.set_scale(MISSILE_SCALE)
        else:
            m = load_model("misc/rgbCube")
            m.set_scale(0.5)
            m.set_hpr(45, 45, 45)
        return m
Beispiel #5
0
def loadObject(modid=0, fullanim={}):
    modfile = rushobjlst[modid]
    print("modfile", modfile)
    if modfile['acts'] != {}:
        model = Actor(modfile['filenm'], modfile['action'])
        if isinstance(modfile['joint'], dict) and modfile['joint'] != {}:
            for jname, jparts in modfile['joint'].items():
                model.makeSubpart(jname, jparts['include'], jparts['exclude'])
    elif modfile['file'] not in ['line']:
        model = loader.loadModel(modfile['filenm'])
        if 'movie' in modfile['jjrb']:
            model.find('**/+SequenceNode').node().play()
    else:
        return 1
    model.reparentTo(render)
    if 'posnow' in fullanim and 'pos' in fullanim and fullanim['posnow'] == 1:
        if len(fullanim['pos']) > 2:
            model.setPos(float(fullanim['pos'][0]), float(fullanim['pos'][1]),
                         float(fullanim['pos'][2]))
        if len(fullanim['pos']) > 5:
            model.setHpr(float(fullanim['pos'][3]), float(fullanim['pos'][4]),
                         float(fullanim['pos'][5]))
        if len(fullanim['pos']) > 8:
            model.setScale(float(fullanim['pos'][6]),
                           float(fullanim['pos'][7]),
                           float(fullanim['pos'][8]))
    rushobjlst[modid]['p3dmod'] = model
    return 1
Beispiel #6
0
def loadModel(file, collision=None, animation=None):
    model = None
    if animation:
        model = Actor(file, animation)
        #default anim
        if 'default' in animation:
            model.loop('default')
        elif 'idle' in animation:
            model.loop('idle')
        else:  #some random anim
            model.loop(list(animation.items())[0])
    else:
        model = loader.loadModel(file)
    model.setPythonTag('model_file', file)
    #load shaders
    for geom in model.findAllMatches('**/+GeomNode'):
        if geom.hasTag('cg_shader'):
            geom.setShader(
                loader.loadShader("shaders/" + geom.getTag('cg_shader')))
        elif geom.hasTag('glsl_shader'):
            glsl_shader = geom.getTag('glsl_shader')
            geom.setShader(
                Shader.load(Shader.SLGLSL,
                            "shaders/{0}_v.glsl".format(glsl_shader),
                            "shaders/{0}_f.glsl".format(glsl_shader)))
        else:
            #geom.setShader(loader.loadShader("shaders/default.cg"))
            geom.setShader(
                Shader.load(Shader.SLGLSL, "shaders/default_v.glsl",
                            "shaders/default_f.glsl"))
    #collisions
    model.setCollideMask(BitMask32.allOff())
    if collision:
        coll = loader.loadModel(collision)
        coll.reparentTo(model)
        coll.find('**/collision').setCollideMask(BitMask32.bit(2))
        coll.find('**/collision').setPythonTag('object', model)
        if animation:
            model.setPythonTag('actor_files', [file, animation, coll])
    else:
        try:
            model.find('**/collision').setCollideMask(BitMask32.bit(2))
            model.find('**/collision').setPythonTag('object', model)
        except:
            print(
                "WARNING: Model {0} has no collision geometry!\nGenerating collision sphere..."
                .format(file))
            bounds = model.getBounds()
            radi = bounds.getRadius()
            cent = bounds.getCenter()
            coll_sphere = model.attachNewNode(CollisionNode('collision'))
            coll_sphere.node().addSolid(
                CollisionSphere(cent[0], cent[1], cent[2], radi))
            coll_sphere.setCollideMask(BitMask32.bit(2))
            coll_sphere.setPythonTag('object', model)
            #coll_sphere.show()
            if animation:
                model.setPythonTag('actor_files', [file, animation, None])
    return model
class GameTest(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        self.FlairDirector = Actor(
            'phase_3.5/models/char/suitC-mod.bam', {
                'neutral': 'phase_3.5/models/char/suitC-neutral.bam',
                'victory': 'phase_4/models/char/suitC-victory.bam',
                'walk': 'phase_3.5/models/char/suitC-walk.bam'
            })

        self.FlairDirector.reparentTo(render)
        self.FlairDirector.loop('neutral')
        self.TorsoTex = loader.loadTexture('phase_3.5/maps/t_blazer.jpg')
        self.FlairDirector.find('**/torso').setTexture(self.TorsoTex, 1)
        self.ArmTex = loader.loadTexture('phase_3.5/maps/t_sleeve.jpg')
        self.FlairDirector.find('**/arms').setTexture(self.ArmTex, 1)
        self.LegTex = loader.loadTexture('phase_3.5/maps/t_leg.jpg')
        self.FlairDirector.find('**/legs').setTexture(self.LegTex, 1)
        self.Head = loader.loadModel('phase_3.5/models/char/FlairDirector.egg')
        self.headTexture = loader.loadTexture(
            "phase_3.5/maps/flair-director.jpg")
        self.Head.reparentTo(self.FlairDirector.find('**/joint_head'))
        self.FlairDirector.findAllMatches('**/joint_head').setTexture(
            self.headTexture, 1)
        self.icon = loader.loadModel('phase_3/models/gui/SourcebotIcon.bam')
        self.icon.reparentTo(render)
        self.iconTexture = loader.loadTexture('phase_3/maps/SourcebotIcon.png')
        self.icon.setTexture(self.iconTexture, 1)
        self.icon.setHpr(180, 0, 0)
        self.icon.setPos(0.1, 0, -0.30)
        self.icon.setScale(1.00)
        self.icon.reparentTo(self.FlairDirector.find('**/joint_attachMeter'))
        self.FlairDirector.setScale(1.70)
class JointDemo(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.loadModel()
        #base.oobe()

    def loadModel(self):
        self.character = Actor(
            "../phase_3/models/char/tt_a_chr_dgl_shorts_torso_1000.bam", {
                'neutral':
                "../phase_3/models/char/tt_a_chr_dgl_shorts_torso_neutral.bam"
            })
        self.character.reparentTo(self.render)
        self.character.loop('neutral')

        #character.list_joints()
        #self.character.place()

        def loadProp():
            sword = loader.loadModel("../custom/chr_w_swo01a.egg")
            sword.reparentTo(self.character.find('**/neck'))
            sword.setScale(0.03)
            #sword.place()

        loadProp()
        return self.character
Beispiel #9
0
class DistributedTNT(DistributedPhysicsEntity):
    def __init__(self, cr):
        DistributedPhysicsEntity.__init__(self, cr)
        self.tnt = None
        self.tntSound = None
        self.particle = None

    def explode(self):
        self.tntSound.stop()
        self.hide()
        self.particle.softStop()
        self.cleanupPhysics()
        CIGlobals.makeExplosion(self.getPos(render) + (0, 0, 5.0), 0.7, True)

    def doSetupPhysics(self):
        self.setupPhysics(self.getPhysBody(), True)

    def getPhysBody(self):
        shape = BulletCylinderShape(0.3925, 1.4, ZUp)
        body = BulletRigidBodyNode('tntBody')
        body.addShape(shape)
        body.setKinematic(True)
        body.setCcdMotionThreshold(1e-7)
        body.setCcdSweptSphereRadius(0.3925)
        return body

    def announceGenerate(self):
        self.tnt = Actor('phase_14/models/props/tnt.bam',
                         {'chan': 'phase_5/models/props/tnt-chan.bam'})
        self.tnt.reparentTo(self)
        self.tnt.play('chan')
        self.tnt.setP(97.492)
        self.tnt.setY(0.38)
        self.tntSound = base.audio3d.loadSfx(
            "phase_14/audio/sfx/dynamite_loop.ogg")
        self.tntSound.setLoop(True)
        base.audio3d.attachSoundToObject(self.tntSound, self.tnt)
        self.particle = ParticleLoader.loadParticleEffect(
            "phase_14/etc/tnt_spark.ptf")
        self.particle.start(self.tnt.find('**/joint_attachEmitter'),
                            CIGlobals.getParticleRender())

        DistributedPhysicsEntity.announceGenerate(self)

        self.tntSound.play()

    def disable(self):
        if self.tnt:
            self.tnt.cleanup()
            self.tnt.removeNode()
        self.tnt = None
        if self.tntSound:
            self.tntSound.stop()
        self.tntSound = None
        if self.particle:
            self.particle.softStop()
        self.particle = None
        DistributedPhysicsEntity.disable(self)
Beispiel #10
0
def make_skelecog(suit_style, suit_name, path=""):
    """Return a skelecog version of any traditional cog as an Actor.

    Args:
        suit_style (str): The letter representing the suit style
            ("A", "B" or "C").
        suit_name (str): The name of the boss' suit.
        path (str, optional): The file path to the Toontown phase files.
            Defaults to Panda3D's search path.

    Examples:
        from toontown import make_skelecog

        skelecog = make_skelecog("A", "cash")
        skelecog.loop("neutral")

    Returns:
        An instance of Panda3D's Actor class.
    """
    if path:
        path = pfile.fromOsSpecific("%s/" % path).getFullpath()

    icon_dict = {
        "sell": ("Sales", (0.843, 0.745, 0.745, 1.0)),
        "cash": ("Money", (0.749, 0.769, 0.749, 1.0)),
        "law": ("Legal", (0.749, 0.776, 0.824, 1.0)),
        "boss": ("Corp", (0.863, 0.776, 0.769, 1.0))
    }

    animation_dict = cog_animation(suit_style, path)

    skelecog = Actor(
        "%sphase_5/models/char/cog%s_robot-zero.bam" % (path, suit_style),
        animation_dict
    )

    if icon_dict[suit_name.lower()][0] == "Corp":
        tie = loader.loadTexture(
            "%sphase_5/maps/cog_robot_tie_boss.jpg" % path
        )
    else:
        idict = icon_dict[suit_name][0].lower()
        tie = loader.loadTexture(
            "%sphase_5/maps/cog_robot_tie_%s.jpg" % (path, idict)
        )
    skelecog.findAllMatches("**/tie").setTexture(tie, 1)

    icons = loader.loadModel("%sphase_3/models/gui/cog_icons.bam" % path)
    icon = icons.find(
        "**/%sIcon" % icon_dict[suit_name][0]
    ).copyTo(skelecog.find("**/joint_attachMeter"))
    icon.setPosHprScale(0.02, 0.05, 0.04, 180.0, 0.0, 0.0, 0.51, 0.51, 0.51)
    icon.setColor(icon_dict[suit_name.lower()][1])
    icons.removeNode()

    skelecog.reparentTo(render)
    return skelecog
Beispiel #11
0
    def buildDust(self):
        dust = Actor('phase_5/models/props/dust-mod.bam', {'chan': 'phase_5/models/props/dust-chan.bam'})
        objBin = 110
        for cloudNum in range(1, 12):
            cloudName = '**/cloud' + str(cloudNum)
            cloud = dust.find(cloudName)
            cloud.setBin('fixed', objBin)
            objBin -= 10

        return dust
Beispiel #12
0
 def buildDust(self):
     dust = Actor('phase_5/models/props/dust-mod.bam',
                  {'chan': 'phase_5/models/props/dust-chan.bam'})
     objBin = 110
     for cloudNum in range(1, 12):
         cloudName = '**/cloud' + str(cloudNum)
         cloud = dust.find(cloudName)
         cloud.setBin('fixed', objBin)
         objBin -= 10
     return dust
Beispiel #13
0
 def makeTvMan(self, x, y, z, tex, playrate):
     man = Actor()
     man.loadModel('models/mechman_idle')
     man.setPos(x, y, z)
     man.reparentTo(render)
     faceplate = man.find("**/faceplate")
     faceplate.setTexture(tex, 1)
     man.setPlayRate(playrate, "mechman_anim")
     man.loop("mechman_anim")
     self.tvMen.append(man)
Beispiel #14
0
 def makeTvMan(self,x,y,z,tex,playrate):
     man = Actor()
     man.loadModel('models/mechman_idle')
     man.setPos(x,y,z)
     man.reparentTo(render)
     fp = man.find("**/faceplate")
     fp.setTexture(tex,1)
     man.setPlayRate(playrate, "mechman_anim")
     man.loop("mechman_anim")
     self.tvMen.append(man)
Beispiel #15
0
def make_skelecog(suit_style, suit_name, path=""):
    """Return a skelecog version of any traditional cog as an Actor.

    Args:
        suit_style (str): The letter representing the suit style
            ("A", "B" or "C").
        suit_name (str): The name of the boss' suit.
        path (str, optional): The file path to the Toontown phase files.
            Defaults to Panda3D's search path.

    Examples:
        from toontown import make_skelecog

        skelecog = make_skelecog("A", "cash")
        skelecog.loop("neutral")

    Returns:
        An instance of Panda3D's Actor class.
    """
    if path:
        path = pfile.fromOsSpecific("%s/" % path).getFullpath()

    icon_dict = {
        "sell": ("Sales", (0.843, 0.745, 0.745, 1.0)),
        "cash": ("Money", (0.749, 0.769, 0.749, 1.0)),
        "law": ("Legal", (0.749, 0.776, 0.824, 1.0)),
        "boss": ("Corp", (0.863, 0.776, 0.769, 1.0))
    }

    animation_dict = cog_animation(suit_style, path)

    skelecog = Actor(
        "%sphase_5/models/char/cog%s_robot-zero.bam" % (path, suit_style),
        animation_dict)

    if icon_dict[suit_name.lower()][0] == "Corp":
        tie = loader.loadTexture("%sphase_5/maps/cog_robot_tie_boss.jpg" %
                                 path)
    else:
        idict = icon_dict[suit_name][0].lower()
        tie = loader.loadTexture("%sphase_5/maps/cog_robot_tie_%s.jpg" %
                                 (path, idict))
    skelecog.findAllMatches("**/tie").setTexture(tie, 1)

    icons = loader.loadModel("%sphase_3/models/gui/cog_icons.bam" % path)
    icon = icons.find("**/%sIcon" % icon_dict[suit_name][0]).copyTo(
        skelecog.find("**/joint_attachMeter"))
    icon.setPosHprScale(0.02, 0.05, 0.04, 180.0, 0.0, 0.0, 0.51, 0.51, 0.51)
    icon.setColor(icon_dict[suit_name.lower()][1])
    icons.removeNode()

    skelecog.reparentTo(render)
    return skelecog
Beispiel #16
0
 def stoneCheese(self):
     headPhase = 4
     headJoint = '**/to_head'
     suitAnims = suitAAnims
     shadowScale = 0.5
     suit = Actor('phase_3.5/models/char/suitA-statue.bam', suitAnims)
     head = loader.loadModel('phase_%s/models/char/suitA-heads.bam' %
                             headPhase).find('**/bigcheese')
     head.reparentTo(suit.find(headJoint))
     headT = loader.loadTexture('phase_4/maps/statue-tbc.jpg')
     head.setTexture(headT, 1)
     head.setColor(0.643, 0.643, 0.643, 1)
     shadow = loader.loadModel('phase_3/models/props/drop_shadow.bam')
     shadow.reparentTo(suit.find('**/joint_shadow'))
     shadow.setScale(shadowScale)
     shadow.setAlphaScale(0.89)
     suit.reparentTo(render)
     suit.node().setBounds(OmniBoundingVolume())
     suit.node().setFinal(1)
     suit.setBlend(frameBlend=True)
     self.suit = suit
     return self.suit
Beispiel #17
0
def make_boss(head, torso, path=""):
    """Return any cog boss as an Actor.

    Args:
        head (str): The name of the boss' suit to be used for its head.
        torse (str): The name of the boss' suit to be used for its torso.
        path (str, optional): The file path to the Toontown phase files.
            Defaults to Panda3D's search path.

    Examples:
        from toontown import make_boss

        CFO = make_boss("cash", "cash")
        CFO.loop("Ff_neutral")

    Returns:
        An instance of Panda3D's Actor class.
    """
    if path:
        path = pfile.fromOsSpecific("%s/" % path).getFullpath()

    boss_dict = {
        "sell": "phase_9/models/char/sellbotBoss",
        "cash": "phase_10/models/char/cashbotBoss",
        "law": "phase_11/models/char/lawbotBoss",
        "boss": "phase_12/models/char/bossbotBoss"
    }

    head_dict, torso_dict, legs_dict = cog_animation("Boss", path)

    animation = {
        "head": head_dict,
        "torso": torso_dict,
        "legs": legs_dict
    }

    parts = {
        "head": "%s%s-head-zero.bam" % (path, boss_dict[head]),
        "torso": "%s%s-torso-zero.bam" % (path, boss_dict[torso]),
        "legs": "%sphase_9/models/char/bossCog-legs-zero.bam" % path
    }

    boss = Actor(parts, animation)
    treads = loader.loadModel(
        "%sphase_9/models/char/bossCog-treads.bam" % path
    )
    boss.attach("head", "torso", "joint34")
    boss.attach("torso", "legs", "joint_pelvis")
    treads.reparentTo(boss.find("**/joint_axle"))
    boss.reparentTo(render)
    return boss
Beispiel #18
0
def make_boss(head, torso, path=""):
    """Return any cog boss as an Actor.

    Args:
        head (str): The name of the boss' suit to be used for its head.
        torse (str): The name of the boss' suit to be used for its torso.
        path (str, optional): The file path to the Toontown phase files.
            Defaults to Panda3D's search path.

    Examples:
        from toontown import make_boss

        CFO = make_boss("cash", "cash")
        CFO.loop("Ff_neutral")

    Returns:
        An instance of Panda3D's Actor class.
    """
    if path:
        path = pfile.fromOsSpecific("%s/" % path).getFullpath()

    boss_dict = {
        "sell": "phase_9/models/char/sellbotBoss",
        "cash": "phase_10/models/char/cashbotBoss",
        "law": "phase_11/models/char/lawbotBoss",
        "boss": "phase_12/models/char/bossbotBoss"
    }

    head_dict, torso_dict, legs_dict = cog_animation("Boss", path)

    animation = {"head": head_dict, "torso": torso_dict, "legs": legs_dict}

    parts = {
        "head": "%s%s-head-zero.bam" % (path, boss_dict[head]),
        "torso": "%s%s-torso-zero.bam" % (path, boss_dict[torso]),
        "legs": "%sphase_9/models/char/bossCog-legs-zero.bam" % path
    }

    boss = Actor(parts, animation)
    treads = loader.loadModel("%sphase_9/models/char/bossCog-treads.bam" %
                              path)
    boss.attach("head", "torso", "joint34")
    boss.attach("torso", "legs", "joint_pelvis")
    treads.reparentTo(boss.find("**/joint_axle"))
    boss.reparentTo(render)
    return boss
Beispiel #19
0
def makeDustCloud(pos, scale=(0.1, 0.9, 1), sound=None, color=(1, 1, 1, 1)):
    from direct.actor.Actor import Actor
    dust = Actor('phase_5/models/props/dust-mod.bam',
                 {'chan': 'phase_5/models/props/dust-chan.bam'})
    dust.hide(ShadowCameraBitmask)
    objBin = 110
    for cloudNum in range(1, 12):
        cloudName = '**/cloud' + str(cloudNum)
        cloud = dust.find(cloudName)
        cloud.setBin('fixed', objBin)
        cloud.setLightOff(1)
        cloud.setColorScale(color, 1)
        objBin -= 10
    dust.setBillboardPointEye()
    dust.setScale(scale)
    dust.reparentTo(render)
    dust.setPos(pos)
    if sound:
        base.audio3d.attachSoundToObject(sound, dust)
        sound.play()
    dustTrack = Sequence(ActorInterval(dust, "chan"), Func(dust.cleanup))
    dustTrack.start()
Beispiel #20
0
class MyPanda:
    count = 0
    def __init__(self, tempworld):
        self.isWalk = False
        self.jumpState = False
        self.currentTime = 0
        self.idleTime = 0
        self.pandaPosIntervalX = 0
        self.pandaPaceX = None
        self.pandaPace = None
        self.mySequence = None
        MyPanda.count += 1
        self.myInterval1 = 0
        self.myInterval2 = 0
        self.myInterval3 = 0
        self.myInterval4 = 0
        self.pandaPosInterval1 = 0
        self.id = MyPanda.count
        self.world = tempworld

        self.pandaNode=render.attachNewNode('pandaNode')
        self.actor=Actor("models/panda-model",
                     {"walk": "models/panda-walk4"})
        self.actor.reparentTo(self.pandaNode)
        cPos = int(self.id) * 20
        self.actor.setPos(cPos,0,0)
        self.actor.setScale(0.002, 0.002, 0.002)

        # Create a collsion node for this object.
        self.cNode = CollisionNode('panda')
        # Attach a collision sphere solid to the collision node.
        self.cNode.addSolid(CollisionSphere(2, 0, 400, 500))
        # Attach the collision node to the object's model.
        self.frowneyC = self.actor.attachNewNode(self.cNode)
        #self.frowneyC.show()
        base.cTrav.addCollider(self.frowneyC, self.world.pusher)
        self.world.pusher.addCollider(self.frowneyC, self.actor, base.drive.node())

        self.setJumpSequence()

    def setJumpSequence(self):
        self.myInterval1 = self.actor.posInterval(0.3, Point3(self.actor.getX(), self.actor.getY(), 0))
        self.myInterval2 = self.actor.posInterval(0.3, Point3(self.actor.getX(), self.actor.getY(), 1))
        self.myInterval3 = self.actor.posInterval(0.2, Point3(self.actor.getX(), self.actor.getY(), 1))
        self.myInterval4 = self.actor.posInterval(0.1, Point3(self.actor.getX(), self.actor.getY(), 0))
        self.mySequence = Sequence(self.myInterval1, self.myInterval2, self.myInterval3, self.myInterval4)

    def getActor(self):
        return self.actor

    def timerTask(self, task):
        self.currentTime = int(task.time)
        return Task.cont

    def jumpPanda (self, task):
        if(int(self.currentTime) - int(self.idleTime) > 20 and self.jumpState == False and self.getDist() > 20):
            self.setJumpSequence()
            self.jumpState = True
            print "Jump"
            self.mySequence.start()
            self.mySequence.loop()
        return Task.cont

    def getDist(self):
        distanceVector = self.world.mainChar.getPos()-self.actor.getPos()
        dist = distanceVector.length()

        return dist

    def getId(self):
        return self.id

    def walkSequence(self):
        if self.isWalk == False:
            self.actor.play("walk")
            self.actor.loop("walk")
            self.isWalk = True
        self.actor.setPos(self.actor, 0, 5, 0)
        self.pandaMovement = self.pandaNode.hprInterval(10.0,Point3(0,0,0),startHpr=Point3(self.actor.getX(),self.actor.getY(),0))

    def pandaWalk(self, task):
        if(self.getDist() < 15 and self.getDist() > 3.5):
            self.idleTime = self.currentTime
            #Look at Ralph
            self.actor.find('**/+GeomNode').setH(180)
            self.actor.lookAt(self.world.mainChar)

            if self.jumpState == True:
                print "Stop Jump"
                self.jumpState = False
                #self.idleTime = self.currentTime
                self.mySequence.pause()
                self.actor.setPos(self.actor.getX(), self.actor.getY(), 0)
                print "Start Walk"

            self.walkSequence()
        if self.getDist() < 15 and self.actor.getZ() != 0:
            self.actor.setPos(self.actor.getX(), self.actor.getY(), 0)
        return Task.cont

    def pandaStop(self, task):
        if (self.getDist() > 15 or self.getDist() < 3.5) and self.isWalk:
            print "Stop Walk"
            self.isWalk = False
            self.actor.stop()
        return Task.cont
Beispiel #21
0
class MakeAToon(StateData.StateData):
    """MakeAToon class"""

    notify = DirectNotifyGlobal.directNotify.newCategory('MakeAToon')

    # special methods

    def __init__(self, parentFSM, avList, doneEvent, index, isPaid):
        """
        MakeAToon constructor: create a toon and let the guest customize it
        """
        self.isPaid = isPaid
        StateData.StateData.__init__(self, doneEvent)
        # download phase
        self.phase = 3

        # names is a list of the toon's name, wantName, approvedName, and rejectedName
        #   name is distributed while the other three are specialized for makeatoon process
        self.names = ["", "", "", ""]
        self.dnastring = None
        self.dna = None
        self.progressing = 0

        self.toonPosition = Point3(-1.62, -3.49, 0)
        self.toonScale = Point3(1, 1, 1)
        self.toonHpr = Point3(180, 0, 0)
        self.leftTime = 1.6
        self.rightTime = 1
        self.slide = 0

        # keep a list of already used names so we don't repeat
        self.nameList = []
        # if self.warp gets set to 1, that means we have an avatar already,
        #   and just want to add a name
        self.warp = 0
        for av in avList:
            if av.position == index:
                self.warp = 1
                self.namelessPotAv = av
            self.nameList.append(av.name)

        self.fsm = ClassicFSM.ClassicFSM(
            'MakeAToon',
            [
                State.State('Init', self.enterInit, self.exitInit,
                            ['GenderShop', 'NameShop']),
                State.State('GenderShop', self.enterGenderShop,
                            self.exitGenderShop, ['BodyShop']),
                State.State('BodyShop', self.enterBodyShop, self.exitBodyShop,
                            ['GenderShop', 'ColorShop']),
                State.State('ColorShop', self.enterColorShop,
                            self.exitColorShop, ['BodyShop', 'ClothesShop']),
                State.State('ClothesShop', self.enterClothesShop,
                            self.exitClothesShop, ['ColorShop', 'NameShop']),
                State.State('NameShop', self.enterNameShop, self.exitNameShop,
                            ['ClothesShop']),
                State.State('Done', self.enterDone, self.exitDone, [])
            ],
            # Initial state
            'Init',
            # Final state
            'Done',
        )

        self.parentFSM = parentFSM
        self.parentFSM.getStateNamed('createAvatar').addChild(self.fsm)

        # create the shops
        self.gs = GenderShop.GenderShop(self, "GenderShop-done")
        self.bs = BodyShop.BodyShop("BodyShop-done")
        self.cos = ColorShop.ColorShop("ColorShop-done")
        self.cls = MakeClothesGUI.MakeClothesGUI("ClothesShop-done")
        self.ns = NameShop.NameShop(self, "NameShop-done", avList, index,
                                    self.isPaid)
        self.shop = GENDERSHOP
        self.shopsVisited = []

        if self.warp:
            self.shopsVisited = [GENDERSHOP, BODYSHOP, COLORSHOP, CLOTHESSHOP]

        # sound
        self.music = None
        self.soundBack = None

        self.fsm.enterInitialState()

        if __debug__:
            base.mat = self

        self.hprDelta = -1
        self.dropIval = None
        self.roomSquishIval = None
        self.propSquishIval = None
        self.focusOutIval = None
        self.focusInIval = None
        self.toon = None

    # accessors
    def getToon(self):
        return (self.toon)

    def enter(self):
        self.notify.debug('Starting Make A Toon.')
        base.cr.centralLogger.writeClientEvent('MAT - startingMakeAToon')
        base.camLens.setFov(ToontownGlobals.MakeAToonCameraFov)
        base.playMusic(self.music, looping=1, volume=self.musicVolume)
        camera.setPosHpr(-5.7, -12.3501, 2.15, -24.8499, 2.73, 0)

        if self.warp:
            if (self.toon.style.torso[1] == 's'):
                self.toon.gender = 's'
            else:
                self.toon.gender = 'd'
            self.toon.reparentTo(render)
            self.toon.loop("neutral")
            self.toon.setPosHpr(-4.1, -2, 0, 200, 0, 0)

        self.guiTopBar.show()
        self.guiBottomBar.show()
        self.guiCancelButton.show()

        if self.warp:
            self.progressing = 0
            self.guiLastButton.hide()
            self.fsm.request("NameShop")
        else:
            self.fsm.request("GenderShop")

    def exit(self):
        base.camLens.setFov(ToontownGlobals.DefaultCameraFov)
        self.guiTopBar.hide()
        self.guiBottomBar.hide()
        self.music.stop()
        self.fsm.request("Done")
        self.room.reparentTo(hidden)

    def load(self):
        gui = loader.loadModel("phase_3/models/gui/tt_m_gui_mat_mainGui")
        guiAcceptUp = gui.find("**/tt_t_gui_mat_okUp")
        guiAcceptDown = gui.find("**/tt_t_gui_mat_okDown")
        guiCancelUp = gui.find("**/tt_t_gui_mat_closeUp")
        guiCancelDown = gui.find("**/tt_t_gui_mat_closeDown")
        guiNextUp = gui.find("**/tt_t_gui_mat_nextUp")
        guiNextDown = gui.find("**/tt_t_gui_mat_nextDown")
        guiNextDisabled = gui.find("**/tt_t_gui_mat_nextDisabled")
        skipTutorialUp = gui.find("**/tt_t_gui_mat_skipUp")
        skipTutorialDown = gui.find("**/tt_t_gui_mat_skipDown")
        rotateUp = gui.find("**/tt_t_gui_mat_arrowRotateUp")
        rotateDown = gui.find("**/tt_t_gui_mat_arrowRotateDown")

        self.guiTopBar = DirectFrame(
            relief=None,
            text=TTLocalizer.CreateYourToon,
            text_font=ToontownGlobals.getSignFont(),
            text_fg=(0.0, 0.65, 0.35, 1),
            text_scale=0.18,
            text_pos=(0, -0.03),
            pos=(0, 0, 0.86),
        )
        self.guiTopBar.hide()

        self.guiBottomBar = DirectFrame(
            relief=None,
            image_scale=(1.25, 1, 1),
            pos=(0.01, 0, -0.86),
        )
        self.guiBottomBar.hide()

        self.guiCheckButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiAcceptUp, guiAcceptDown, guiAcceptUp, guiAcceptDown),
            image_scale=halfButtonScale,
            image1_scale=halfButtonHoverScale,
            image2_scale=halfButtonHoverScale,
            pos=(1.165, 0, -0.018),
            command=self.__handleNext,
            text=("", TTLocalizer.MakeAToonDone, TTLocalizer.MakeAToonDone),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=0.08,
            text_align=TextNode.ARight,
            text_pos=(0.13, 0.13),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1),
        )
        self.guiCheckButton.hide()

        self.guiCancelButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiCancelUp, guiCancelDown, guiCancelUp, guiCancelDown),
            image_scale=halfButtonScale,
            image1_scale=halfButtonHoverScale,
            image2_scale=halfButtonHoverScale,
            pos=(-1.179, 0, -0.011),
            command=self.__handleCancel,
            text=("", TTLocalizer.MakeAToonCancel,
                  TTLocalizer.MakeAToonCancel),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=TTLocalizer.MATguiCancelButton,
            text_pos=(0, 0.115),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1),
        )
        self.guiCancelButton.hide()

        self.guiNextButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiNextUp, guiNextDown, guiNextUp, guiNextDisabled),
            image_scale=(0.3, 0.3, 0.3),
            image1_scale=(0.35, 0.35, 0.35),
            image2_scale=(0.35, 0.35, 0.35),
            pos=(1.165, 0, -0.018),
            command=self.__handleNext,
            text=("", TTLocalizer.MakeAToonNext, TTLocalizer.MakeAToonNext,
                  ""),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=TTLocalizer.MATguiNextButton,
            text_pos=(0, 0.115),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1),
        )
        self.guiNextButton.hide()

        self.guiLastButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiNextUp, guiNextDown, guiNextUp, guiNextDown),
            image3_color=Vec4(0.5, 0.5, 0.5, 0.75),
            image_scale=(-0.3, 0.3, 0.3),
            image1_scale=(-0.35, 0.35, 0.35),
            image2_scale=(-0.35, 0.35, 0.35),
            pos=(0.825, 0, -0.018),
            command=self.__handleLast,
            text=("", TTLocalizer.MakeAToonLast, TTLocalizer.MakeAToonLast,
                  ""),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=0.08,
            text_pos=(0, 0.115),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1),
        )
        self.guiLastButton.hide()

        self.rotateLeftButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(rotateUp, rotateDown, rotateUp, rotateDown),
            image_scale=(-0.4, 0.4, 0.4),
            image1_scale=(-0.5, 0.5, 0.5),
            image2_scale=(-0.5, 0.5, 0.5),
            pos=(-0.329249, 0, 0.202961),
        )
        self.rotateLeftButton.hide()
        self.rotateLeftButton.bind(DGG.B1PRESS, self.rotateToonLeft)
        self.rotateLeftButton.bind(DGG.B1RELEASE, self.stopToonRotateLeftTask)

        self.rotateRightButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(rotateUp, rotateDown, rotateUp, rotateDown),
            image_scale=(0.4, 0.4, 0.4),
            image1_scale=(0.5, 0.5, 0.5),
            image2_scale=(0.5, 0.5, 0.5),
            pos=(0.309534, 0, 0.206116),
        )
        self.rotateRightButton.hide()
        self.rotateRightButton.bind(DGG.B1PRESS, self.rotateToonRight)
        self.rotateRightButton.bind(DGG.B1RELEASE,
                                    self.stopToonRotateRightTask)

        gui.removeNode()

        # These are the drop and scale joints that the rooms are going to be parented to during transitions.
        self.roomDropActor = Actor()
        self.roomDropActor.loadModel('phase_3/models/makeatoon/roomAnim_model')
        self.roomDropActor.loadAnims(
            {'drop': 'phase_3/models/makeatoon/roomAnim_roomDrop'})
        self.roomDropActor.reparentTo(render)
        self.dropJoint = self.roomDropActor.find('**/droppingJoint')

        self.roomSquishActor = Actor()
        self.roomSquishActor.loadModel(
            'phase_3/models/makeatoon/roomAnim_model')
        self.roomSquishActor.loadAnims(
            {'squish': 'phase_3/models/makeatoon/roomAnim_roomSquish'})
        self.roomSquishActor.reparentTo(render)
        self.squishJoint = self.roomSquishActor.find('**/scalingJoint')

        self.propSquishActor = Actor()
        self.propSquishActor.loadModel(
            'phase_3/models/makeatoon/roomAnim_model')
        self.propSquishActor.loadAnims(
            {'propSquish': 'phase_3/models/makeatoon/roomAnim_propSquish'})
        self.propSquishActor.reparentTo(render)
        self.propSquishActor.pose('propSquish', 0)
        self.propJoint = self.propSquishActor.find('**/propJoint')

        self.spotlightActor = Actor()
        self.spotlightActor.loadModel(
            'phase_3/models/makeatoon/roomAnim_model')
        self.spotlightActor.loadAnims({
            'spotlightShake':
            'phase_3/models/makeatoon/roomAnim_spotlightShake'
        })
        self.spotlightActor.reparentTo(render)
        self.spotlightJoint = self.spotlightActor.find('**/spotlightJoint')

        ee = DirectFrame(pos=(-1, 1, 1),
                         frameSize=(-.01, .01, -.01, .01),
                         frameColor=(0, 0, 0, .05),
                         state='normal')
        ee.bind(DGG.B1PRESS, lambda x, ee=ee: self.toggleSlide())
        self.eee = ee

        self.room = loader.loadModel(
            "phase_3/models/makeatoon/tt_m_ara_mat_room")
        self.genderWalls = self.room.find('**/genderWalls')
        self.genderProps = self.room.find('**/genderProps')

        self.bodyWalls = self.room.find('**/bodyWalls')
        self.bodyProps = self.room.find('**/bodyProps')

        self.colorWalls = self.room.find('**/colorWalls')
        self.colorProps = self.room.find('**/colorProps')

        self.clothesWalls = self.room.find('**/clothWalls')
        self.clothesProps = self.room.find('**/clothProps')

        self.nameWalls = self.room.find('**/nameWalls')
        self.nameProps = self.room.find('**/nameProps')

        self.background = self.room.find('**/background')
        self.background.reparentTo(render)
        self.floor = self.room.find('**/floor')
        self.floor.reparentTo(render)

        self.spotlight = self.room.find('**/spotlight')
        self.spotlight.reparentTo(self.spotlightJoint)
        self.spotlight.setColor(1, 1, 1, 0.3)
        self.spotlight.setPos(1.18, -1.27, 0.41)
        self.spotlight.setScale(2.6)
        self.spotlight.setHpr(0, 0, 0)

        smokeSeqNode = SequenceNode('smoke')
        smokeModel = loader.loadModel(
            "phase_3/models/makeatoon/tt_m_ara_mat_smoke")
        smokeFrameList = smokeModel.findAllMatches('**/smoke_*').asList()
        smokeFrameList.reverse()
        for smokeFrame in smokeFrameList:
            smokeSeqNode.addChild(smokeFrame.node())
        smokeSeqNode.setFrameRate(12)
        self.smoke = render.attachNewNode(smokeSeqNode)
        self.smoke.setScale(1, 1, 0.75)
        self.smoke.hide()

        # create an initial random, naked, grey toon
        if self.warp:
            self.dna = ToonDNA.ToonDNA()
            self.dna.makeFromNetString(self.namelessPotAv.dna)

            self.toon = Toon.Toon()
            self.toon.setDNA(self.dna)
            # make sure the avatar uses its highest LOD
            self.toon.useLOD(1000)
            # make sure his name doesn't show up
            self.toon.setNameVisible(0)
            self.toon.startBlink()
            self.toon.startLookAround()

        self.gs.load()
        self.bs.load()
        self.cos.load()
        self.cls.load()
        self.ns.load()

        self.music = base.loadMusic("phase_3/audio/bgm/create_a_toon.mid")
        self.musicVolume = base.config.GetFloat("makeatoon-music-volume", 1)
        self.sfxVolume = base.config.GetFloat("makeatoon-sfx-volume", 1)
        self.soundBack = base.loadSfx(
            "phase_3/audio/sfx/GUI_create_toon_back.mp3")

        self.crashSounds = []
        self.crashSounds.append(
            base.loadSfx("phase_3/audio/sfx/tt_s_ara_mat_crash_boing.mp3"))
        self.crashSounds.append(
            base.loadSfx(
                "phase_3/audio/sfx/tt_s_ara_mat_crash_glassBoing.mp3"))
        self.crashSounds.append(
            base.loadSfx("phase_3/audio/sfx/tt_s_ara_mat_crash_wood.mp3"))
        self.crashSounds.append(
            base.loadSfx("phase_3/audio/sfx/tt_s_ara_mat_crash_woodBoing.mp3"))
        self.crashSounds.append(
            base.loadSfx("phase_3/audio/sfx/tt_s_ara_mat_crash_woodGlass.mp3"))

    def unload(self):
        self.exit()
        if self.toon:
            self.toon.stopBlink()
            self.toon.stopLookAroundNow()

        self.gs.unload()
        self.bs.unload()
        self.cos.unload()
        self.cls.unload()
        self.ns.unload()

        del self.gs
        del self.bs
        del self.cos
        del self.cls
        del self.ns

        self.guiTopBar.destroy()
        self.guiBottomBar.destroy()
        self.guiCancelButton.destroy()
        self.guiCheckButton.destroy()
        self.eee.destroy()
        self.guiNextButton.destroy()
        self.guiLastButton.destroy()
        self.rotateLeftButton.destroy()
        self.rotateRightButton.destroy()

        del self.guiTopBar
        del self.guiBottomBar
        del self.guiCancelButton
        del self.guiCheckButton
        del self.eee
        del self.guiNextButton
        del self.guiLastButton
        del self.rotateLeftButton
        del self.rotateRightButton

        del self.names
        del self.dnastring
        del self.nameList

        del self.music
        del self.soundBack

        del self.dna
        if self.toon:
            self.toon.delete()
        del self.toon

        self.cleanupDropIval()
        self.cleanupRoomSquishIval()
        self.cleanupPropSquishIval()
        self.cleanupFocusInIval()
        self.cleanupFocusOutIval()

        self.room.removeNode()
        del self.room

        self.genderWalls.removeNode()
        self.genderProps.removeNode()
        del self.genderWalls
        del self.genderProps

        self.bodyWalls.removeNode()
        self.bodyProps.removeNode()
        del self.bodyWalls
        del self.bodyProps

        self.colorWalls.removeNode()
        self.colorProps.removeNode()
        del self.colorWalls
        del self.colorProps

        self.clothesWalls.removeNode()
        self.clothesProps.removeNode()
        del self.clothesWalls
        del self.clothesProps

        self.nameWalls.removeNode()
        self.nameProps.removeNode()
        del self.nameWalls
        del self.nameProps

        self.background.removeNode()
        del self.background
        self.floor.removeNode()
        del self.floor
        self.spotlight.removeNode()
        del self.spotlight
        self.smoke.removeNode()
        del self.smoke

        while len(self.crashSounds):
            del self.crashSounds[0]

        self.parentFSM.getStateNamed('createAvatar').removeChild(self.fsm)
        del self.parentFSM
        del self.fsm

        self.ignoreAll()

        loader.unloadModel("phase_3/models/gui/create_a_toon_gui")
        loader.unloadModel("phase_3/models/gui/create_a_toon")
        ModelPool.garbageCollect()
        TexturePool.garbageCollect()

    def getDNA(self):
        return self.dnastring

    def __handleBodyShop(self):
        self.fsm.request("BodyShop")

    def __handleClothesShop(self):
        self.fsm.request("ClothesShop")

    def __handleColorShop(self):
        self.fsm.request("ColorShop")

    def __handleNameShop(self):
        self.fsm.request("NameShop")

    def __handleCancel(self):
        self.doneStatus = "cancel"

        #if self.fsm.getCurrentState().getName() == 'NameShop':
        self.shopsVisited = []

        base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))

    def toggleSlide(self):
        self.slide = 1 - self.slide

    def goToNextShop(self):
        self.progressing = 1
        # go to the next shop
        if self.shop == GENDERSHOP:
            self.fsm.request("BodyShop")
        elif self.shop == BODYSHOP:
            self.fsm.request("ColorShop")
        elif self.shop == COLORSHOP:
            self.fsm.request("ClothesShop")
        else:
            self.fsm.request("NameShop")

    def goToLastShop(self):
        self.progressing = 0
        # go to the last shop
        if self.shop == BODYSHOP:
            self.fsm.request("GenderShop")
        elif self.shop == COLORSHOP:
            self.fsm.request("BodyShop")
        elif self.shop == CLOTHESSHOP:
            self.fsm.request("ColorShop")
        else:
            self.fsm.request("ClothesShop")

    def charSez(self, char, statement, dialogue=None):
        import pdb
        pdb.set_trace()
        char.setChatAbsolute(statement, CFSpeech, dialogue)

    # Specific State functions

    def enterInit(self):
        pass

    def exitInit(self):
        pass

    # GenderShop state
    def enterGenderShop(self):
        base.cr.centralLogger.writeClientEvent('MAT - enteringGenderShop')
        self.shop = GENDERSHOP
        if (GENDERSHOP not in self.shopsVisited):
            self.shopsVisited.append(GENDERSHOP)
            self.genderWalls.reparentTo(self.squishJoint)
            self.genderProps.reparentTo(self.propJoint)
            self.roomSquishActor.pose('squish', 0)
            # Start the next button with disabled. It'll be enabled when a gender selection is made.
            self.guiNextButton['state'] = DGG.DISABLED
        else:
            self.dropRoom(self.genderWalls, self.genderProps)

        self.guiTopBar['text'] = TTLocalizer.CreateYourToonTitle
        self.guiTopBar['text_fg'] = (1, 0.92, 0.2, 1)
        ##        self.guiTopBar['text_fg'] = (1, 1, 0, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterGenderShop
        base.transitions.fadeIn()
        self.accept("GenderShop-done", self.__handleGenderShopDone)
        self.gs.enter()

        ##        self.toon.setHpr(self.toonHpr)

        self.guiNextButton.show()
        self.gs.showButtons()
        self.rotateLeftButton.hide()
        self.rotateRightButton.hide()

    def exitGenderShop(self):
        self.squishRoom(self.genderWalls)
        self.squishProp(self.genderProps)
        self.gs.exit()
        self.ignore("GenderShop-done")

    def __handleGenderShopDone(self):
        self.guiNextButton.hide()
        self.gs.hideButtons()
        self.goToNextShop()

    # BodyShop state
    def bodyShopOpening(self):
        self.bs.showButtons()
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterBodyShop(self):
        base.cr.centralLogger.writeClientEvent('MAT - enteringBodyShop')
        self.toon.show()
        # self.roomWalls.setColorScale(0.49, 0.612, 0.380, 1)
        self.shop = BODYSHOP
        self.guiTopBar['text'] = TTLocalizer.ShapeYourToonTitle
        self.guiTopBar['text_fg'] = (0.0, 0.98, 0.5, 1)
        ##        self.guiTopBar['text_fg'] = (0, 1, 0, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterBodyShop

        #base.transitions.fadeIn()
        self.accept("BodyShop-done", self.__handleBodyShopDone)
        self.dropRoom(self.bodyWalls, self.bodyProps)

        # we need to do this first for setup...
        self.bs.enter(self.toon, self.shopsVisited)

        if (BODYSHOP not in self.shopsVisited):
            self.shopsVisited.append(BODYSHOP)

##        self.toon.setHpr(self.toonHpr)
        self.bodyShopOpening()
##        taskMgr.doMethodLater(16.0, self.bodyShopDialogTask, "bodyShopDialogTask")

##    def bodyShopDialogTask(self, task):
##        self.hostSez([TTLocalizer.MakeAToonClickForNextScreen,])
##        return Task.done

    def exitBodyShop(self):
        self.squishRoom(self.bodyWalls)
        self.squishProp(self.bodyProps)
        self.bs.exit()
        self.ignore("BodyShop-done")
##        taskMgr.remove("bodyShopDialogTask")

    def __handleBodyShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.bs.doneStatus == 'next':
            self.bs.hideButtons()
            self.goToNextShop()
        else:
            self.bs.hideButtons()
            self.goToLastShop()

    # ColorShop state
    def colorShopOpening(self):
        self.cos.showButtons()
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterColorShop(self):
        base.cr.centralLogger.writeClientEvent('MAT - enteringColorShop')
        self.shop = COLORSHOP
        self.guiTopBar['text'] = TTLocalizer.PaintYourToonTitle
        self.guiTopBar['text_fg'] = (0, 1, 1, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterColorShop
        #base.transitions.fadeIn()
        self.accept("ColorShop-done", self.__handleColorShopDone)
        self.dropRoom(self.colorWalls, self.colorProps)

        self.toon.setPos(self.toonPosition)
        ##        self.toon.setHpr(self.toonHpr)
        self.colorShopOpening()

        self.cos.enter(self.toon, self.shopsVisited)

        if (COLORSHOP not in self.shopsVisited):
            self.shopsVisited.append(COLORSHOP)

    def exitColorShop(self):
        self.squishRoom(self.colorWalls)
        self.squishProp(self.colorProps)
        self.cos.exit()
        self.ignore("ColorShop-done")

    def __handleColorShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.cos.doneStatus == 'next':
            self.cos.hideButtons()
            self.goToNextShop()
        else:
            self.cos.hideButtons()
            self.goToLastShop()

    # ClothesShop state
    def clothesShopOpening(self):
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.cls.showButtons()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterClothesShop(self):
        base.cr.centralLogger.writeClientEvent('MAT - enteringClothesShop')
        self.shop = CLOTHESSHOP
        self.guiTopBar['text'] = TTLocalizer.PickClothesTitle
        self.guiTopBar['text_fg'] = (1, 0.92, 0.2, 1)
        ##        self.guiTopBar['text_fg'] = (1, 1, 0, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterClothesShop
        self.accept("ClothesShop-done", self.__handleClothesShopDone)
        self.dropRoom(self.clothesWalls, self.clothesProps)
        #Code added to return your toon to normal size
        self.toon.setScale(self.toonScale)

        self.toon.setPos(self.toonPosition)
        if not self.progressing:
            self.toon.setHpr(self.toonHpr)
        self.clothesShopOpening()

        self.cls.enter(self.toon)
        if (CLOTHESSHOP not in self.shopsVisited):
            self.shopsVisited.append(CLOTHESSHOP)

    def exitClothesShop(self):
        self.squishRoom(self.clothesWalls)
        self.squishProp(self.clothesProps)
        self.cls.exit()
        self.ignore("ClothesShop-done")

    def __handleClothesShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.cls.doneStatus == 'next':
            self.cls.hideButtons()
            self.goToNextShop()
        else:
            self.cls.hideButtons()
            self.goToLastShop()

    # NameShop state
    def nameShopOpening(self, task):
        self.guiCheckButton.show()
        self.guiLastButton.show()
        if self.warp:
            self.guiLastButton.hide()
        if (NAMESHOP not in self.shopsVisited):
            self.shopsVisited.append(NAMESHOP)
        return Task.done

    def enterNameShop(self):
        base.cr.centralLogger.writeClientEvent('MAT - enteringNameShop')
        self.shop = NAMESHOP
        self.guiTopBar['text'] = TTLocalizer.NameToonTitle
        self.guiTopBar['text_fg'] = (0.0, 0.98, 0.5, 1)
        ##        self.guiTopBar['text_fg'] = (0, 1, 0, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterNameShop
        self.accept("NameShop-done", self.__handleNameShopDone)
        self.dropRoom(self.nameWalls, self.nameProps)
        self.spotlight.setPos(2, -1.95, 0.41)
        self.spotlight.setScale(2.3)
        self.toon.setPos(Point3(1.5, -4, 0))
        self.toon.setH(120)
        self.rotateLeftButton.hide()
        self.rotateRightButton.hide()

        if self.progressing:
            waittime = self.leftTime
        else:
            waittime = .2
        self.ns.enter(self.toon, self.nameList, self.warp)
        taskMgr.doMethodLater(waittime, self.nameShopOpening,
                              "nameShopOpeningTask")

    def exitNameShop(self):
        self.squishRoom(self.nameWalls)
        self.squishProp(self.nameProps)
        self.spotlight.setPos(1.18, -1.27, 0.41)
        self.spotlight.setScale(2.6)
        self.ns.exit()
        self.ignore("NameShop-done")
        taskMgr.remove("nameShopOpeningTask")

    def rejectName(self):
        self.ns.rejectName(TTLocalizer.RejectNameText)

    def __handleNameShopDone(self):
        self.guiLastButton.hide()
        self.guiCheckButton.hide()
        if self.ns.getDoneStatus() == 'last':
            self.ns.hideAll()
            self.goToLastShop()
        elif self.ns.getDoneStatus() == 'paynow':
            self.doneStatus = "paynow"
            base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))
        else:
            self.doneStatus = "created"
            base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))

    def __handleNext(self):
        messenger.send("next")

    def __handleLast(self):
        messenger.send("last")

    def __handleSkipTutorial(self):
        messenger.send("skipTutorial")

    # Done state
    def enterDone(self):
        pass

    def exitDone(self):
        pass

    def create3DGui(self):
        """
        This is a test function to load the 3D Gui.
        """
        self.proto = loader.loadModel(
            "phase_3/models/makeatoon/tt_m_ara_mat_protoMachine")
        self.proto.setScale(0.2)
        self.proto.reparentTo(render)

    def setup3DPicker(self):
        self.accept('mouse1', self.mouseDown)
        self.accept('mouse1-up', self.mouseUp)

        self.pickerQueue = CollisionHandlerQueue()
        self.pickerTrav = CollisionTraverser('MousePickerTraverser')
        self.pickerTrav.setRespectPrevTransform(True)

        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = camera.attachNewNode(self.pickerNode)
        self.pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.pickerTrav.addCollider(self.pickerNP, self.pickerQueue)

    def mouseDown(self):
        self.notify.debug('Mouse 1 Down')
        # This gives up the screen coordinates of the mouse
        mpos = base.mouseWatcherNode.getMouse()

        # This makes the ray's origin the camera and makes the ray point
        # to the screen coordinates of the mouse.
        self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())

        self.pickerTrav.traverse(render)
        if self.pickerQueue.getNumEntries() > 0:
            self.pickerQueue.sortEntries(
            )  #this is so we get the closest object
            self.pickedObj = self.pickerQueue.getEntry(0).getIntoNodePath()

    def mouseUp(self):
        self.notify.debug('Mouse 1 Up')

    def squishRoom(self, room):
        """
        Plays the squish animation on the given room.
        """
        if self.roomSquishIval and self.roomSquishIval.isPlaying():
            self.roomSquishIval.finish()
        squishDuration = self.roomSquishActor.getDuration('squish')
        self.roomSquishIval = Sequence(
            Func(self.roomSquishActor.play, 'squish'), Wait(squishDuration),
            Func(room.hide))
        self.roomSquishIval.start()

    def squishProp(self, prop):
        """
        Plays the squish animation on the given prop.
        """
        if not prop.isEmpty():
            if self.propSquishIval and self.propSquishIval.isPlaying():
                self.propSquishIval.finish()
            squishDuration = self.propSquishActor.getDuration('propSquish')
            self.propSquishIval = Sequence(
                Func(self.propSquishActor.play, 'propSquish'),
                Wait(squishDuration), Func(prop.hide))
            self.propSquishIval.start()

    def dropRoom(self, walls, props):
        """
        Plays the drop animation on the given room.
        """
        def propReparentTo(props):
            if not props.isEmpty():
                props.reparentTo(self.propJoint)

        if self.dropIval and self.dropIval.isPlaying():
            self.dropIval.finish()
        walls.reparentTo(self.dropJoint)
        walls.show()
        if not props.isEmpty():
            props.reparentTo(self.dropJoint)
            props.show()
        dropDuration = self.roomDropActor.getDuration('drop')

        self.dropIval = Parallel(
            # Drop and Squish Interval.
            Sequence(Func(self.roomDropActor.play, 'drop'), Wait(dropDuration),
                     Func(walls.reparentTo, self.squishJoint),
                     Func(propReparentTo, props),
                     Func(self.propSquishActor.pose, 'propSquish', 0),
                     Func(self.roomSquishActor.pose, 'squish', 0)),

            # Smoke Interval.
            Sequence(
                Wait(0.25), Func(self.smoke.show),
                Func(self.smoke.node().play),
                LerpColorScaleInterval(self.smoke,
                                       0.5,
                                       Vec4(1, 1, 1, 0),
                                       startColorScale=Vec4(1, 1, 1, 1)),
                Func(self.smoke.hide)),

            # Spotlight Interval.
            Func(self.spotlightActor.play, 'spotlightShake'),

            # Play Sound.
            Func(self.playRandomCrashSound),
        )
        self.dropIval.start()

    def startFocusOutIval(self):
        """
        Starts the focusOutIval after making sure that the focusInIval is paused.
        """
        if self.focusInIval.isPlaying():
            self.focusInIval.pause()
        if not self.focusOutIval.isPlaying():
            self.focusOutIval = LerpScaleInterval(self.spotlight, 0.25,
                                                  self.spotlightFinalScale)
            self.focusOutIval.start()

    def startFocusInIval(self):
        """
        Starts the focusInIval after making sure that the focusOutIval is paused.
        """
        if self.focusOutIval.isPlaying():
            self.focusOutIval.pause()
        if not self.focusInIval.isPlaying():
            self.focusInIval = LerpScaleInterval(self.spotlight, 0.25,
                                                 self.spotlightOriginalScale)
            self.focusInIval.start()

    def cleanupFocusOutIval(self):
        """
        Cleans up the focusInIval.
        """
        if self.focusOutIval:
            self.focusOutIval.finish()
            del self.focusOutIval

    def cleanupFocusInIval(self):
        """
        Cleans up the focusOutIval.
        """
        if self.focusInIval:
            self.focusInIval.finish()
            del self.focusInIval

    def cleanupDropIval(self):
        """
        Cleans up the dropIval.
        """
        if self.dropIval:
            self.dropIval.finish()
            del self.dropIval

    def cleanupRoomSquishIval(self):
        """
        Cleans up the roomSquishIval.
        """
        if self.roomSquishIval:
            self.roomSquishIval.finish()
            del self.roomSquishIval

    def cleanupPropSquishIval(self):
        """
        Cleans up the propSquishIval.
        """
        if self.propSquishIval:
            self.propSquishIval.finish()
            del self.propSquishIval

    def setToon(self, toon):
        """
        Public method to set the toon of makeAToon.
        Eg: GenderShop sets the toon of makeAToon.
        """
        self.toon = toon

    def setNextButtonState(self, state):
        """
        Public method to set the state of the next button.
        """
        self.guiNextButton['state'] = state

    def playRandomCrashSound(self):
        """
        Plays a random crash sound from the crash sound list.
        """
        index = random.randint(0, (len(self.crashSounds) - 1))
        base.playSfx(self.crashSounds[index], volume=self.sfxVolume)

    # Rotate Left
    def rotateToonLeft(self, event):
        taskMgr.add(self.rotateToonLeftTask, 'rotateToonLeftTask')

    def rotateToonLeftTask(self, task):
        self.toon.setH(self.toon.getH() + self.hprDelta)
        return task.cont

    def stopToonRotateLeftTask(self, event):
        taskMgr.remove('rotateToonLeftTask')

    # Rotate Right
    def rotateToonRight(self, event):
        taskMgr.add(self.rotateToonRightTask, 'rotateToonRightTask')

    def rotateToonRightTask(self, task):
        self.toon.setH(self.toon.getH() - self.hprDelta)
        return task.cont

    def stopToonRotateRightTask(self, event):
        taskMgr.remove('rotateToonRightTask')
Beispiel #22
0
 environ.setScale(3)
 ceo = Actor({"head":"phase_12/models/char/bossbotBoss-head-zero.bam", \
 "torso":"phase_12/models/char/bossbotBoss-torso-zero.bam", \
 "legs":"phase_9/models/char/bossCog-legs-zero.bam"}, \
 {"head":{"walk":"phase_9/models/char/bossCog-head-Bb_neutral.bam", \
 "run":"phase_9/models/char/bossCog-head-Bb_neutral.bam"}, \
 "torso":{"walk":"phase_9/models/char/bossCog-torso-Bb_neutral.bam", \
 "run":"phase_9/models/char/bossCog-torso-Bb_neutral.bam"}, \
 "legs":{"walk":"phase_9/models/char/bossCog-legs-Bb_neutral.bam", \
 "run":"phase_9/models/char/bossCog-legs-Bb_neutral.bam"} \
 })
 ceo.attach("head", "torso", "joint34")
 ceo.attach("torso", "legs", "joint_legs")
 ceo.reparentTo(render)
 tread3 = loader.loadModel("phase_9/models/char/bossCog-treads.bam")
 rear4 = ceo.find('**/joint_axle')
 tread3.reparentTo(rear4)
 ceo.setPos(-180,21,83.5)
 ceo.loop("walk")
 ceo.setHpr(90,0,0)
 environ = loader.loadModel("phase_4/models/minigames/toonblitz_game_arrow.bam")
 environ.reparentTo(render)
 environ.setPos(-125,21,84)
 environ.setHpr(90,0,0)
 environ.setScale(3)
 environ = loader.loadModel('phase_10/models/cogHQ/CBMetalCrate2.bam')
 environ.reparentTo(render)
 environ.setPos(-267,10,83.5)
 environ.setHpr(0,0,0)
 environ.setScale(3)
 crate1 = loader.loadModel('phase_10/models/cogHQ/CBMetalCrate2.bam')
Beispiel #23
0
class MakeAToon(StateData.StateData):
    notify = DirectNotifyGlobal.directNotify.newCategory('MakeAToon')

    def __init__(self, parentFSM, avList, doneEvent, index):
        StateData.StateData.__init__(self, doneEvent)
        self.phase = 3
        self.names = ['', '', '', '']
        self.dnastring = None
        self.dna = None
        self.progressing = 0
        self.toonPosition = Point3(-1.62, -3.49, 0)
        self.toonScale = Point3(1, 1, 1)
        self.toonHpr = Point3(180, 0, 0)
        self.leftTime = 1.6
        self.rightTime = 1
        self.slide = 0
        self.nameList = []
        self.warp = 0
        for av in avList:
            if av.position == index:
                self.warp = 1
                self.namelessPotAv = av
            self.nameList.append(av.name)

        self.fsm = ClassicFSM.ClassicFSM('MakeAToon', [
            State.State('Init', self.enterInit, self.exitInit,
                        ['GenderShop', 'NameShop']),
            State.State('GenderShop', self.enterGenderShop,
                        self.exitGenderShop, ['BodyShop']),
            State.State('BodyShop', self.enterBodyShop, self.exitBodyShop,
                        ['GenderShop', 'ColorShop']),
            State.State('ColorShop', self.enterColorShop, self.exitColorShop,
                        ['BodyShop', 'ClothesShop']),
            State.State('ClothesShop', self.enterClothesShop,
                        self.exitClothesShop, ['ColorShop', 'NameShop']),
            State.State('NameShop', self.enterNameShop, self.exitNameShop,
                        ['ClothesShop']),
            State.State('Done', self.enterDone, self.exitDone, [])
        ], 'Init', 'Done')
        self.parentFSM = parentFSM
        self.parentFSM.getStateNamed('createAvatar').addChild(self.fsm)
        self.gs = GenderShop.GenderShop(self, 'GenderShop-done')
        self.bs = BodyShop.BodyShop('BodyShop-done')
        self.cos = ColorShop.ColorShop('ColorShop-done')
        self.cls = MakeClothesGUI.MakeClothesGUI('ClothesShop-done')
        self.ns = NameShop.NameShop(self, 'NameShop-done', avList, index)
        self.shop = GENDERSHOP
        self.shopsVisited = []
        if self.warp:
            self.shopsVisited = [
                GENDERSHOP,
                BODYSHOP,
                COLORSHOP,
                CLOTHESSHOP,
            ]
        self.music = None
        self.soundBack = None
        self.fsm.enterInitialState()
        self.hprDelta = -1
        self.dropIval = None
        self.roomSquishIval = None
        self.propSquishIval = None
        self.focusOutIval = None
        self.focusInIval = None
        self.toon = None

    def getToon(self):
        return self.toon

    def enter(self):
        self.notify.debug('Starting Make A Toon.')
        if base.config.GetBool('want-qa-regression', 0):
            self.notify.info('QA-REGRESSION: MAKEATOON: Starting Make A Toon')
        base.camLens.setMinFov(ToontownGlobals.MakeAToonCameraFov / (4. / 3.))
        base.playMusic(self.music, looping=1, volume=self.musicVolume)
        camera.setPosHpr(-5.7, -12.3501, 2.15, -24.8499, 2.73, 0)
        if self.warp:
            if self.toon.style.torso[1] == 's':
                self.toon.gender = 's'
            else:
                self.toon.gender = 'd'
            self.toon.reparentTo(render)
            self.toon.loop('neutral')
            self.toon.setScale(self.toonScale)
            self.spotlight.setPos(2, -1.95, 0.41)
            self.toon.setPos(Point3(1.5, -4, 0))
            self.toon.setH(120)
        self.guiTopBar.show()
        self.guiBottomBar.show()
        self.guiCancelButton.show()
        if self.warp:
            self.progressing = 0
            self.guiLastButton.hide()
            self.fsm.request('NameShop')
        else:
            self.fsm.request('GenderShop')

    def exit(self):
        base.camLens.setMinFov(settings['fov'] / (4. / 3.))
        self.guiTopBar.hide()
        self.guiBottomBar.hide()
        self.music.stop()
        self.fsm.request('Done')
        self.room.reparentTo(hidden)

    def load(self):
        gui = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui')
        gui.flattenMedium()
        guiAcceptUp = gui.find('**/tt_t_gui_mat_okUp')
        guiAcceptUp.flattenStrong()
        guiAcceptDown = gui.find('**/tt_t_gui_mat_okDown')
        guiAcceptDown.flattenStrong()
        guiCancelUp = gui.find('**/tt_t_gui_mat_closeUp')
        guiCancelUp.flattenStrong()
        guiCancelDown = gui.find('**/tt_t_gui_mat_closeDown')
        guiCancelDown.flattenStrong()
        guiNextUp = gui.find('**/tt_t_gui_mat_nextUp')
        guiNextUp.flattenStrong()
        guiNextDown = gui.find('**/tt_t_gui_mat_nextDown')
        guiNextDown.flattenStrong()
        guiNextDisabled = gui.find('**/tt_t_gui_mat_nextDisabled')
        guiNextDisabled.flattenStrong()
        skipTutorialUp = gui.find('**/tt_t_gui_mat_skipUp')
        skipTutorialUp.flattenStrong()
        skipTutorialDown = gui.find('**/tt_t_gui_mat_skipDown')
        skipTutorialDown.flattenStrong()
        rotateUp = gui.find('**/tt_t_gui_mat_arrowRotateUp')
        rotateUp.flattenStrong()
        rotateDown = gui.find('**/tt_t_gui_mat_arrowRotateDown')
        rotateDown.flattenStrong()
        self.guiTopBar = DirectFrame(relief=None,
                                     text=TTLocalizer.CreateYourToon,
                                     text_font=ToontownGlobals.getSignFont(),
                                     text_fg=(0.0, 0.65, 0.35, 1),
                                     text_scale=0.18,
                                     text_pos=(0, -0.03),
                                     pos=(0, 0, 0.86))
        self.guiTopBar.hide()
        self.guiBottomBar = DirectFrame(relief=None,
                                        image_scale=(1.25, 1, 1),
                                        pos=(0.01, 0, -0.86))
        self.guiBottomBar.hide()
        self.guiCheckButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiAcceptUp, guiAcceptDown, guiAcceptUp, guiAcceptDown),
            image_scale=halfButtonScale,
            image1_scale=halfButtonHoverScale,
            image2_scale=halfButtonHoverScale,
            pos=(1.165, 0, -0.018),
            command=self.__handleNext,
            text=('', TTLocalizer.MakeAToonDone, TTLocalizer.MakeAToonDone),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=0.08,
            text_align=TextNode.ARight,
            text_pos=(0.075, 0.13),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1))
        self.guiCheckButton.setPos(-0.13, 0, 0.13)
        self.guiCheckButton.reparentTo(base.a2dBottomRight)
        self.guiCheckButton.hide()
        self.guiCancelButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiCancelUp, guiCancelDown, guiCancelUp, guiCancelDown),
            image_scale=halfButtonScale,
            image1_scale=halfButtonHoverScale,
            image2_scale=halfButtonHoverScale,
            pos=(-1.179, 0, -0.011),
            command=self.__handleCancel,
            text=('', TTLocalizer.MakeAToonCancel,
                  TTLocalizer.MakeAToonCancel),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=TTLocalizer.MATguiCancelButton,
            text_pos=(0, 0.115),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1))
        self.guiCancelButton.setPos(0.13, 0, 0.13)
        self.guiCancelButton.reparentTo(base.a2dBottomLeft)
        self.guiCancelButton.hide()
        self.guiNextButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiNextUp, guiNextDown, guiNextUp, guiNextDisabled),
            image_scale=(0.3, 0.3, 0.3),
            image1_scale=(0.35, 0.35, 0.35),
            image2_scale=(0.35, 0.35, 0.35),
            pos=(1.165, 0, -0.018),
            command=self.__handleNext,
            text=('', TTLocalizer.MakeAToonNext, TTLocalizer.MakeAToonNext,
                  ''),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=TTLocalizer.MATguiNextButton,
            text_pos=(0, 0.115),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1))
        self.guiNextButton.setPos(-0.13, 0, 0.13)
        self.guiNextButton.reparentTo(base.a2dBottomRight)
        self.guiNextButton.hide()
        self.guiLastButton = DirectButton(
            parent=self.guiBottomBar,
            relief=None,
            image=(guiNextUp, guiNextDown, guiNextUp, guiNextDown),
            image3_color=Vec4(0.5, 0.5, 0.5, 0.75),
            image_scale=(-0.3, 0.3, 0.3),
            image1_scale=(-0.35, 0.35, 0.35),
            image2_scale=(-0.35, 0.35, 0.35),
            pos=(0.825, 0, -0.018),
            command=self.__handleLast,
            text=('', TTLocalizer.MakeAToonLast, TTLocalizer.MakeAToonLast,
                  ''),
            text_font=ToontownGlobals.getInterfaceFont(),
            text_scale=0.08,
            text_pos=(0, 0.115),
            text_fg=(1, 1, 1, 1),
            text_shadow=(0, 0, 0, 1))
        self.guiLastButton.setPos(-0.37, 0, 0.13)
        self.guiLastButton.reparentTo(base.a2dBottomRight)
        self.guiLastButton.hide()
        self.rotateLeftButton = DirectButton(parent=self.guiBottomBar,
                                             relief=None,
                                             image=(rotateUp, rotateDown,
                                                    rotateUp, rotateDown),
                                             image_scale=(-0.4, 0.4, 0.4),
                                             image1_scale=(-0.5, 0.5, 0.5),
                                             image2_scale=(-0.5, 0.5, 0.5),
                                             pos=(-0.355, 0, 0.36))
        self.rotateLeftButton.flattenMedium()
        self.rotateLeftButton.reparentTo(base.a2dBottomCenter)
        self.rotateLeftButton.hide()
        self.rotateLeftButton.bind(DGG.B1PRESS, self.rotateToonLeft)
        self.rotateLeftButton.bind(DGG.B1RELEASE, self.stopToonRotateLeftTask)
        self.rotateRightButton = DirectButton(parent=self.guiBottomBar,
                                              relief=None,
                                              image=(rotateUp, rotateDown,
                                                     rotateUp, rotateDown),
                                              image_scale=(0.4, 0.4, 0.4),
                                              image1_scale=(0.5, 0.5, 0.5),
                                              image2_scale=(0.5, 0.5, 0.5),
                                              pos=(0.355, 0, 0.36))
        self.rotateRightButton.flattenStrong()
        self.rotateRightButton.reparentTo(base.a2dBottomCenter)
        self.rotateRightButton.hide()
        self.rotateRightButton.bind(DGG.B1PRESS, self.rotateToonRight)
        self.rotateRightButton.bind(DGG.B1RELEASE,
                                    self.stopToonRotateRightTask)
        gui.removeNode()
        self.roomDropActor = Actor()
        self.roomDropActor.loadModel('phase_3/models/makeatoon/roomAnim_model')
        self.roomDropActor.loadAnims(
            {'drop': 'phase_3/models/makeatoon/roomAnim_roomDrop'})
        self.roomDropActor.reparentTo(render)
        self.dropJoint = self.roomDropActor.find('**/droppingJoint')
        self.roomSquishActor = Actor()
        self.roomSquishActor.loadModel(
            'phase_3/models/makeatoon/roomAnim_model')
        self.roomSquishActor.loadAnims(
            {'squish': 'phase_3/models/makeatoon/roomAnim_roomSquish'})
        self.roomSquishActor.reparentTo(render)
        self.squishJoint = self.roomSquishActor.find('**/scalingJoint')
        self.propSquishActor = Actor()
        self.propSquishActor.loadModel(
            'phase_3/models/makeatoon/roomAnim_model')
        self.propSquishActor.loadAnims(
            {'propSquish': 'phase_3/models/makeatoon/roomAnim_propSquish'})
        self.propSquishActor.reparentTo(render)
        self.propSquishActor.pose('propSquish', 0)
        self.propJoint = self.propSquishActor.find('**/propJoint')
        self.spotlightActor = Actor()
        self.spotlightActor.loadModel(
            'phase_3/models/makeatoon/roomAnim_model')
        self.spotlightActor.loadAnims({
            'spotlightShake':
            'phase_3/models/makeatoon/roomAnim_spotlightShake'
        })
        self.spotlightActor.reparentTo(render)
        self.spotlightJoint = self.spotlightActor.find('**/spotlightJoint')
        ee = DirectFrame(pos=(-1, 1, 1),
                         frameSize=(-.01, 0.01, -.01, 0.01),
                         frameColor=(0, 0, 0, 0.05),
                         state='normal')
        ee.bind(DGG.B1PRESS, lambda x, ee=ee: self.toggleSlide())
        self.eee = ee
        self.room = loader.loadModel(
            'phase_3/models/makeatoon/tt_m_ara_mat_room')
        self.room.flattenMedium()
        self.genderWalls = self.room.find('**/genderWalls')
        self.genderWalls.flattenStrong()
        self.genderProps = self.room.find('**/genderProps')
        self.genderProps.flattenStrong()
        self.bodyWalls = self.room.find('**/bodyWalls')
        self.bodyWalls.flattenStrong()
        self.bodyProps = self.room.find('**/bodyProps')
        self.bodyProps.flattenStrong()
        self.colorWalls = self.room.find('**/colorWalls')
        self.colorWalls.flattenStrong()
        self.colorProps = self.room.find('**/colorProps')
        self.colorProps.flattenStrong()
        self.clothesWalls = self.room.find('**/clothWalls')
        self.clothesWalls.flattenMedium()
        self.clothesProps = self.room.find('**/clothProps')
        self.clothesProps.flattenMedium()
        self.nameWalls = self.room.find('**/nameWalls')
        self.nameWalls.flattenStrong()
        self.nameProps = self.room.find('**/nameProps')
        self.nameProps.flattenStrong()
        self.background = self.room.find('**/background')
        self.background.flattenStrong()
        self.background.reparentTo(render)
        self.floor = self.room.find('**/floor')
        self.floor.flattenStrong()
        self.floor.reparentTo(render)
        self.spotlight = self.room.find('**/spotlight')
        self.spotlight.reparentTo(self.spotlightJoint)
        self.spotlight.setColor(1, 1, 1, 0.3)
        self.spotlight.setPos(1.18, -1.27, 0.41)
        self.spotlight.setScale(2.6)
        self.spotlight.setHpr(0, 0, 0)
        smokeSeqNode = SequenceNode('smoke')
        smokeModel = loader.loadModel(
            'phase_3/models/makeatoon/tt_m_ara_mat_smoke')
        smokeFrameList = list(smokeModel.findAllMatches('**/smoke_*'))
        smokeFrameList.reverse()
        for smokeFrame in smokeFrameList:
            smokeSeqNode.addChild(smokeFrame.node())

        smokeSeqNode.setFrameRate(12)
        self.smoke = render.attachNewNode(smokeSeqNode)
        self.smoke.setScale(1, 1, 0.75)
        self.smoke.hide()
        if self.warp:
            self.dna = ToonDNA.ToonDNA()
            self.dna.makeFromNetString(self.namelessPotAv.dna)
            self.toon = Toon.Toon()
            self.toon.setDNA(self.dna)
            self.toon.useLOD(1000)
            self.toon.setNameVisible(0)
            self.toon.startBlink()
            self.toon.startLookAround()
        self.gs.load()
        self.bs.load()
        self.cos.load()
        self.cls.load()
        self.ns.load()
        self.music = base.loadMusic('phase_3/audio/bgm/create_a_toon.ogg')
        self.musicVolume = base.config.GetFloat('makeatoon-music-volume', 1)
        self.sfxVolume = base.config.GetFloat('makeatoon-sfx-volume', 1)
        self.soundBack = base.loadSfx(
            'phase_3/audio/sfx/GUI_create_toon_back.ogg')
        self.crashSounds = map(base.loadSfx, [
            'phase_3/audio/sfx/tt_s_ara_mat_crash_boing.ogg',
            'phase_3/audio/sfx/tt_s_ara_mat_crash_glassBoing.ogg',
            'phase_3/audio/sfx/tt_s_ara_mat_crash_wood.ogg',
            'phase_3/audio/sfx/tt_s_ara_mat_crash_woodBoing.ogg',
            'phase_3/audio/sfx/tt_s_ara_mat_crash_woodGlass.ogg'
        ])

    def unload(self):
        self.exit()
        if self.toon:
            self.toon.stopBlink()
            self.toon.stopLookAroundNow()
        self.gs.unload()
        self.bs.unload()
        self.cos.unload()
        self.cls.unload()
        self.ns.unload()
        del self.gs
        del self.bs
        del self.cos
        del self.cls
        del self.ns
        self.guiTopBar.destroy()
        self.guiBottomBar.destroy()
        self.guiCancelButton.destroy()
        self.guiCheckButton.destroy()
        self.eee.destroy()
        self.guiNextButton.destroy()
        self.guiLastButton.destroy()
        self.rotateLeftButton.destroy()
        self.rotateRightButton.destroy()
        del self.guiTopBar
        del self.guiBottomBar
        del self.guiCancelButton
        del self.guiCheckButton
        del self.eee
        del self.guiNextButton
        del self.guiLastButton
        del self.rotateLeftButton
        del self.rotateRightButton
        del self.names
        del self.dnastring
        del self.nameList
        del self.music
        del self.soundBack
        del self.dna
        if self.toon:
            self.toon.delete()
        del self.toon
        self.cleanupDropIval()
        self.cleanupRoomSquishIval()
        self.cleanupPropSquishIval()
        self.cleanupFocusInIval()
        self.cleanupFocusOutIval()
        self.room.removeNode()
        del self.room
        self.genderWalls.removeNode()
        self.genderProps.removeNode()
        del self.genderWalls
        del self.genderProps
        self.bodyWalls.removeNode()
        self.bodyProps.removeNode()
        del self.bodyWalls
        del self.bodyProps
        self.colorWalls.removeNode()
        self.colorProps.removeNode()
        del self.colorWalls
        del self.colorProps
        self.clothesWalls.removeNode()
        self.clothesProps.removeNode()
        del self.clothesWalls
        del self.clothesProps
        self.nameWalls.removeNode()
        self.nameProps.removeNode()
        del self.nameWalls
        del self.nameProps
        self.background.removeNode()
        del self.background
        self.floor.removeNode()
        del self.floor
        self.spotlight.removeNode()
        del self.spotlight
        self.smoke.removeNode()
        del self.smoke
        while len(self.crashSounds):
            del self.crashSounds[0]

        self.parentFSM.getStateNamed('createAvatar').removeChild(self.fsm)
        del self.parentFSM
        del self.fsm
        self.ignoreAll()
        loader.unloadModel('phase_3/models/gui/create_a_toon_gui')
        loader.unloadModel('phase_3/models/gui/create_a_toon')
        ModelPool.garbageCollect()
        TexturePool.garbageCollect()

    def getDNA(self):
        return self.dnastring

    def __handleBodyShop(self):
        self.fsm.request('BodyShop')

    def __handleClothesShop(self):
        self.fsm.request('ClothesShop')

    def __handleColorShop(self):
        self.fsm.request('ColorShop')

    def __handleNameShop(self):
        self.fsm.request('NameShop')

    def __handleCancel(self):
        self.doneStatus = 'cancel'
        self.shopsVisited = []
        base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))

    def toggleSlide(self):
        self.slide = 1 - self.slide

    def goToNextShop(self):
        self.progressing = 1
        if self.shop == GENDERSHOP:
            self.fsm.request('BodyShop')
        elif self.shop == BODYSHOP:
            self.fsm.request('ColorShop')
        elif self.shop == COLORSHOP:
            self.fsm.request('ClothesShop')
        else:
            self.fsm.request('NameShop')

    def goToLastShop(self):
        self.progressing = 0
        if self.shop == BODYSHOP:
            self.fsm.request('GenderShop')
        elif self.shop == COLORSHOP:
            self.fsm.request('BodyShop')
        elif self.shop == CLOTHESSHOP:
            self.fsm.request('ColorShop')
        else:
            self.fsm.request('ClothesShop')

    def enterInit(self):
        pass

    def exitInit(self):
        pass

    def enterGenderShop(self):
        self.shop = GENDERSHOP
        if GENDERSHOP not in self.shopsVisited:
            self.shopsVisited.append(GENDERSHOP)
            self.genderWalls.reparentTo(self.squishJoint)
            self.genderProps.reparentTo(self.propJoint)
            self.roomSquishActor.pose('squish', 0)
            self.guiNextButton['state'] = DGG.DISABLED
        else:
            self.dropRoom(self.genderWalls, self.genderProps)
        self.guiTopBar['text'] = TTLocalizer.CreateYourToonTitle
        self.guiTopBar['text_fg'] = (1, 0.92, 0.2, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterGenderShop
        base.transitions.fadeIn()
        self.accept('GenderShop-done', self.__handleGenderShopDone)
        self.gs.enter()
        self.guiNextButton.show()
        self.gs.showButtons()
        self.rotateLeftButton.hide()
        self.rotateRightButton.hide()

    def exitGenderShop(self):
        self.squishRoom(self.genderWalls)
        self.squishProp(self.genderProps)
        self.gs.exit()
        self.ignore('GenderShop-done')

    def __handleGenderShopDone(self):
        self.guiNextButton.hide()
        self.gs.hideButtons()
        self.goToNextShop()

    def bodyShopOpening(self):
        self.bs.showButtons()
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterBodyShop(self):
        self.toon.show()
        self.shop = BODYSHOP
        self.guiTopBar['text'] = TTLocalizer.ShapeYourToonTitle
        self.guiTopBar['text_fg'] = (0.0, 0.98, 0.5, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterBodyShop
        self.accept('BodyShop-done', self.__handleBodyShopDone)
        self.dropRoom(self.bodyWalls, self.bodyProps)
        self.bs.enter(self.toon, self.shopsVisited)
        if BODYSHOP not in self.shopsVisited:
            self.shopsVisited.append(BODYSHOP)
        self.bodyShopOpening()

    def exitBodyShop(self):
        self.squishRoom(self.bodyWalls)
        self.squishProp(self.bodyProps)
        self.bs.exit()
        self.ignore('BodyShop-done')

    def __handleBodyShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.bs.doneStatus == 'next':
            self.bs.hideButtons()
            self.goToNextShop()
        else:
            self.bs.hideButtons()
            self.goToLastShop()

    def colorShopOpening(self):
        self.cos.showButtons()
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterColorShop(self):
        self.shop = COLORSHOP
        self.guiTopBar['text'] = TTLocalizer.PaintYourToonTitle
        self.guiTopBar['text_fg'] = (0, 1, 1, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterColorShop
        self.accept('ColorShop-done', self.__handleColorShopDone)
        self.dropRoom(self.colorWalls, self.colorProps)
        self.toon.setPos(self.toonPosition)
        self.colorShopOpening()
        self.cos.enter(self.toon, self.shopsVisited)
        if COLORSHOP not in self.shopsVisited:
            self.shopsVisited.append(COLORSHOP)

    def exitColorShop(self):
        self.squishRoom(self.colorWalls)
        self.squishProp(self.colorProps)
        self.cos.exit()
        self.ignore('ColorShop-done')

    def __handleColorShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.cos.doneStatus == 'next':
            self.cos.hideButtons()
            self.goToNextShop()
        else:
            self.cos.hideButtons()
            self.goToLastShop()

    def clothesShopOpening(self):
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.cls.showButtons()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterClothesShop(self):
        self.shop = CLOTHESSHOP
        self.guiTopBar['text'] = TTLocalizer.PickClothesTitle
        self.guiTopBar['text_fg'] = (1, 0.92, 0.2, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterClothesShop
        self.accept('ClothesShop-done', self.__handleClothesShopDone)
        self.dropRoom(self.clothesWalls, self.clothesProps)
        self.toon.setScale(self.toonScale)
        self.toon.setPos(self.toonPosition)
        if not self.progressing:
            self.toon.setHpr(self.toonHpr)
        self.clothesShopOpening()
        self.cls.enter(self.toon)
        if CLOTHESSHOP not in self.shopsVisited:
            self.shopsVisited.append(CLOTHESSHOP)

    def exitClothesShop(self):
        self.squishRoom(self.clothesWalls)
        self.squishProp(self.clothesProps)
        self.cls.exit()
        self.ignore('ClothesShop-done')

    def __handleClothesShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.cls.doneStatus == 'next':
            self.cls.hideButtons()
            self.goToNextShop()
        else:
            self.cls.hideButtons()
            self.goToLastShop()

    def nameShopOpening(self, task):
        self.guiCheckButton.show()
        self.guiLastButton.show()
        if self.warp:
            self.guiLastButton.hide()
        if NAMESHOP not in self.shopsVisited:
            self.shopsVisited.append(NAMESHOP)
        return Task.done

    def enterNameShop(self):
        self.shop = NAMESHOP
        self.guiTopBar['text'] = TTLocalizer.NameToonTitle
        self.guiTopBar['text_fg'] = (0.0, 0.98, 0.5, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterNameShop
        self.accept('NameShop-done', self.__handleNameShopDone)
        self.dropRoom(self.nameWalls, self.nameProps)
        self.spotlight.setPos(2, -1.95, 0.41)
        self.toon.setPos(Point3(1.5, -4, 0))
        self.toon.setH(120)
        self.rotateLeftButton.hide()
        self.rotateRightButton.hide()
        if self.progressing:
            waittime = self.leftTime
        else:
            waittime = 0.2
        self.ns.enter(self.toon, self.nameList, self.warp)
        taskMgr.doMethodLater(waittime, self.nameShopOpening,
                              'nameShopOpeningTask')

    def exitNameShop(self):
        self.squishRoom(self.nameWalls)
        self.squishProp(self.nameProps)
        self.spotlight.setPos(1.18, -1.27, 0.41)
        self.ns.exit()
        self.ignore('NameShop-done')
        taskMgr.remove('nameShopOpeningTask')

    def rejectName(self):
        self.ns.rejectName(TTLocalizer.RejectNameText)

    def __handleNameShopDone(self):
        if base.config.GetBool('want-qa-regression', 0):
            self.notify.info('QA-REGRESSION: MAKEATOON: Creating A Toon')
        self.guiLastButton.hide()
        self.guiCheckButton.hide()
        if self.ns.getDoneStatus() == 'last':
            self.ns.hideAll()
            self.goToLastShop()
        else:
            self.doneStatus = 'created'
            base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))

    def __handleNext(self):
        messenger.send('next')

    def __handleLast(self):
        messenger.send('last')

    def __handleSkipTutorial(self):
        messenger.send('skipTutorial')

    def enterDone(self):
        pass

    def exitDone(self):
        pass

    def create3DGui(self):
        self.proto = loader.loadModel(
            'phase_3/models/makeatoon/tt_m_ara_mat_protoMachine')
        self.proto.setScale(0.2)
        self.proto.reparentTo(render)

    def setup3DPicker(self):
        self.accept('mouse1', self.mouseDown)
        self.accept('mouse1-up', self.mouseUp)
        self.pickerQueue = CollisionHandlerQueue()
        self.pickerTrav = CollisionTraverser('MousePickerTraverser')
        self.pickerTrav.setRespectPrevTransform(True)
        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = camera.attachNewNode(self.pickerNode)
        self.pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.pickerTrav.addCollider(self.pickerNP, self.pickerQueue)

    def mouseDown(self):
        self.notify.debug('Mouse 1 Down')
        mpos = base.mouseWatcherNode.getMouse()
        self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
        self.pickerTrav.traverse(render)
        if self.pickerQueue.getNumEntries() > 0:
            self.pickerQueue.sortEntries()
            self.pickedObj = self.pickerQueue.getEntry(0).getIntoNodePath()

    def mouseUp(self):
        self.notify.debug('Mouse 1 Up')

    def squishRoom(self, room):
        if self.roomSquishIval and self.roomSquishIval.isPlaying():
            self.roomSquishIval.finish()
        squishDuration = self.roomSquishActor.getDuration('squish')
        self.roomSquishIval = Sequence(
            Func(self.roomSquishActor.play, 'squish'), Wait(squishDuration),
            Func(room.hide))
        self.roomSquishIval.start()

    def squishProp(self, prop):
        if not prop.isEmpty():
            if self.propSquishIval and self.propSquishIval.isPlaying():
                self.propSquishIval.finish()
            squishDuration = self.propSquishActor.getDuration('propSquish')
            self.propSquishIval = Sequence(
                Func(self.propSquishActor.play, 'propSquish'),
                Wait(squishDuration), Func(prop.hide))
            self.propSquishIval.start()

    def dropRoom(self, walls, props):
        def propReparentTo(props):
            if not props.isEmpty():
                props.reparentTo(self.propJoint)

        if self.dropIval and self.dropIval.isPlaying():
            self.dropIval.finish()
        walls.reparentTo(self.dropJoint)
        walls.show()
        if not props.isEmpty():
            props.reparentTo(self.dropJoint)
            props.show()
        dropDuration = self.roomDropActor.getDuration('drop')
        self.dropIval = Parallel(
            Sequence(Func(self.roomDropActor.play, 'drop'), Wait(dropDuration),
                     Func(walls.reparentTo, self.squishJoint),
                     Func(propReparentTo, props),
                     Func(self.propSquishActor.pose, 'propSquish', 0),
                     Func(self.roomSquishActor.pose, 'squish', 0)),
            Sequence(
                Wait(0.25), Func(self.smoke.show),
                Func(self.smoke.node().play),
                LerpColorScaleInterval(self.smoke,
                                       0.5,
                                       Vec4(1, 1, 1, 0),
                                       startColorScale=Vec4(1, 1, 1, 1)),
                Func(self.smoke.hide)),
            Func(self.spotlightActor.play, 'spotlightShake'),
            Func(self.playRandomCrashSound))
        self.dropIval.start()

    def startFocusOutIval(self):
        if self.focusInIval.isPlaying():
            self.focusInIval.pause()
        if not self.focusOutIval.isPlaying():
            self.focusOutIval = LerpScaleInterval(self.spotlight, 0.25,
                                                  self.spotlightFinalScale)
            self.focusOutIval.start()

    def startFocusInIval(self):
        if self.focusOutIval.isPlaying():
            self.focusOutIval.pause()
        if not self.focusInIval.isPlaying():
            self.focusInIval = LerpScaleInterval(self.spotlight, 0.25,
                                                 self.spotlightOriginalScale)
            self.focusInIval.start()

    def cleanupFocusOutIval(self):
        if self.focusOutIval:
            self.focusOutIval.finish()
            del self.focusOutIval

    def cleanupFocusInIval(self):
        if self.focusInIval:
            self.focusInIval.finish()
            del self.focusInIval

    def cleanupDropIval(self):
        if self.dropIval:
            self.dropIval.finish()
            del self.dropIval

    def cleanupRoomSquishIval(self):
        if self.roomSquishIval:
            self.roomSquishIval.finish()
            del self.roomSquishIval

    def cleanupPropSquishIval(self):
        if self.propSquishIval:
            self.propSquishIval.finish()
            del self.propSquishIval

    def setToon(self, toon):
        self.toon = toon

    def setNextButtonState(self, state):
        self.guiNextButton['state'] = state

    def playRandomCrashSound(self):
        index = random.randint(0, len(self.crashSounds) - 1)
        base.playSfx(self.crashSounds[index], volume=self.sfxVolume)

    def rotateToonLeft(self, event):
        taskMgr.add(self.rotateToonLeftTask, 'rotateToonLeftTask')

    def rotateToonLeftTask(self, task):
        self.toon.setH(self.toon.getH() + self.hprDelta)
        return task.cont

    def stopToonRotateLeftTask(self, event):
        taskMgr.remove('rotateToonLeftTask')

    def rotateToonRight(self, event):
        taskMgr.add(self.rotateToonRightTask, 'rotateToonRightTask')

    def rotateToonRightTask(self, task):
        self.toon.setH(self.toon.getH() - self.hprDelta)
        return task.cont

    def stopToonRotateRightTask(self, event):
        taskMgr.remove('rotateToonRightTask')
Beispiel #24
0
class Cog():
    def __init__(self):
        #Define variables to keep track of the current head, body, and department
        self.currentBody = 0
        self.currentHead = 0
        self.currentDept = 0

        #Define a boolean to determine if the cog is in view
        self.isInView = False

        #Establish current file path location
        self.currentDirectory = os.path.abspath(sys.path[0])
        self.pandaDirectory = Filename.fromOsSpecific(
            self.currentDirectory).getFullpath()

        #Create the cog head and body (mainly to allow it to be
        #destroyed later in replacement of the proper body)
        self.cog = Actor(
            self.pandaDirectory +
            '/resources/cogs/models/tt_a_ene_cga_zero.bam', {
                'neutral':
                (self.pandaDirectory +
                 '/resources/cogs/animations/tt_a_ene_cga_neutral.bam'),
                'walk': (self.pandaDirectory +
                         '/resources/cogs/animations/tt_a_ene_cga_walk.bam')
            })
        self.head = loader.loadModel(self.pandaDirectory +
                                     '/resources/cogs/models/suitA-heads.bam')

        #Determine the body type and set the head
        self.determineBody()

    def determineBody(self):
        #Destroy the current body to unrender it
        self.cog.delete()
        self.cog.removeNode()

        #Determine the new cog body type
        if self.currentBody == 0:
            self.cog = Actor(
                self.pandaDirectory +
                '/resources/cogs/models/tt_a_ene_cga_zero.bam', {
                    'neutral':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cga_neutral.bam'),
                    'walk':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cga_walk.bam'),
                    'victory':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cga_victory.bam')
                })
        elif self.currentBody == 1:
            self.cog = Actor(
                self.pandaDirectory +
                '/resources/cogs/models/tt_a_ene_cgb_zero.bam', {
                    'neutral':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cgb_neutral.bam'),
                    'walk':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cgb_walk.bam'),
                    'victory':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cgb_victory.bam')
                })
        elif self.currentBody == 2:
            self.cog = Actor(
                self.pandaDirectory +
                '/resources/cogs/models/tt_a_ene_cgc_zero.bam', {
                    'neutral':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cgc_neutral.bam'),
                    'walk':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cgc_walk.bam'),
                    'victory':
                    (self.pandaDirectory +
                     '/resources/cogs/animations/tt_a_ene_cgc_victory.bam')
                })
        else:
            raise Exception(
                'UH OH! currentBody is not between 0 and 2! The value of currentBody is {}'
                .format(self.currentBody))

        self.cog.reparentTo(render)

        if self.isInView:
            self.cog.loop('neutral')
            self.cog.setPos(6, 2, 0)
            self.cog.setHpr(180, 0, 0)
        else:
            self.resetCogPos()

        #Define the lerp for the cog's movement and animations
        self.walkIn = self.cog.posInterval(2, pos=(6, 2, 0))
        self.walkOut = self.cog.posInterval(2, pos=(15, 2, 0))
        self.turnToCam = self.cog.hprInterval(1, hpr=(180, 0, 0))
        self.turnAway = self.cog.hprInterval(1, hpr=(270, 0, 0))

        #Define the sequences
        #Note: If you want to loop an animation after a sequence plays,
        #you have to append the Func(self.actor.loop, 'animName') to the end of the function.
        self.enterView = Sequence(self.walkIn, self.turnToCam,
                                  Func(self.cog.loop, 'neutral'))
        self.exitView = Sequence(Func(self.cog.loop, 'walk'), self.turnAway,
                                 self.walkOut)

        #Call the other methods to reattach and reapply the head and department textures
        self.determineHead()
        self.determineDept()

    def determineHead(self):
        #Destroy the current head to unrender it
        self.head.removeNode()

        #Set up a boolean to make sure the cog is or isn't a flunky
        hasGlasses = False

        #Determine the cog head type
        if self.currentHead <= 12:
            self.headList = loader.loadModel(
                self.pandaDirectory + '/resources/cogs/models/suitA-heads.bam')

            if self.currentHead == 0:
                self.head = self.headList.find('**/backstabber')
            elif self.currentHead == 1:
                self.head = self.headList.find('**/bigcheese')
            elif self.currentHead == 2:
                self.head = self.headList.find('**/bigwig')
            elif self.currentHead == 3:
                self.head = self.headList.find('**/headhunter')
            elif self.currentHead == 4:
                self.head = self.headList.find('**/legaleagle')
            elif self.currentHead == 5:
                self.head = self.headList.find('**/numbercruncher')
            elif self.currentHead == 6:
                #name dropper
                self.head = self.headList.find('**/numbercruncher')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/name-dropper.jpg'), 1)
            elif self.currentHead == 7:
                self.head = self.headList.find('**/pennypincher')
            elif self.currentHead == 8:
                self.head = self.headList.find('**/yesman')
            elif self.currentHead == 9:
                #robber baron
                self.head = self.headList.find('**/yesman')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/robber-baron.jpg'), 1)
            elif self.currentHead == 10:
                self.head = self.headList.find('**/twoface')
            elif self.currentHead == 11:
                #mingler
                self.head = self.headList.find('**/twoface')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/mingler.jpg'), 1)
            else:
                #double talker
                self.head = self.headList.find('**/twoface')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/double-talker.jpg'), 1)

        elif self.currentHead <= 20:
            self.headList = loader.loadModel(
                self.pandaDirectory + '/resources/cogs/models/suitB-heads.bam')

            if self.currentHead == 13:
                self.head = self.headList.find('**/ambulancechaser')
            elif self.currentHead == 14:
                self.head = self.headList.find('**/beancounter')
            elif self.currentHead == 15:
                self.head = self.headList.find('**/loanshark')
            elif self.currentHead == 16:
                self.head = self.headList.find('**/movershaker')
            elif self.currentHead == 17:
                #bloodsucker
                self.head = self.headList.find('**/movershaker')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/blood-sucker.jpg'), 1)
            elif self.currentHead == 18:
                self.head = self.headList.find('**/pencilpusher')
            elif self.currentHead == 19:
                self.head = self.headList.find('**/telemarketer')
            else:
                #spin doctor
                self.head = self.headList.find('**/telemarketer')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/spin-doctor.jpg'), 1)

        elif self.currentHead <= 29:
            self.headList = loader.loadModel(
                self.pandaDirectory + '/resources/cogs/models/suitC-heads.bam')

            if self.currentHead == 21:
                #actually a short change
                self.head = self.headList.find('**/coldcaller')
            elif self.currentHead == 22:
                #cold caller needs to be recolored
                self.head = self.headList.find('**/coldcaller')
                self.head.setColor(0, 0, 255, 1)
            elif self.currentHead == 23:
                self.head = self.headList.find('**/flunky')
                hasGlasses = True
            elif self.currentHead == 24:
                #corporate raider
                self.head = self.headList.find('**/flunky')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/corporate-raider.jpg'), 1)
            elif self.currentHead == 25:
                self.head = self.headList.find('**/gladhander')
            elif self.currentHead == 26:
                self.head = self.headList.find('**/micromanager')
            elif self.currentHead == 27:
                self.head = self.headList.find('**/moneybags')
            elif self.currentHead == 28:
                self.head = self.headList.find('**/tightwad')
            else:
                #bottom feeder
                self.head = self.headList.find('**/tightwad')
                self.head.setTexture(loader.loadTexture(self.pandaDirectory + \
                     '/resources/cogs/textures/bottom-feeder.jpg'), 1)
        else:
            raise Exception(
                'UH OH! currentHead is not between 0 and 31! The value of currentBody is {}'
                .format(self.currentHead))

        #Attach the head to the model
        self.head.reparentTo(self.cog.find('**/def_head'))

        if hasGlasses:
            self.glasses = self.headList.find('**/glasses')
            self.glasses.reparentTo(self.head)

    def determineDept(self):
        #Determine the cog department and set the textures of the suit
        if self.currentDept == 0:
            self.cog.findAllMatches('**/torso').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/s_blazer.jpg'), 1)

            self.cog.findAllMatches('**/arms').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/s_sleeve.jpg'), 1)

            self.cog.findAllMatches('**/legs').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/s_leg.jpg'), 1)

        elif self.currentDept == 1:
            self.cog.findAllMatches('**/torso').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/m_blazer.jpg'), 1)

            self.cog.findAllMatches('**/arms').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/m_sleeve.jpg'), 1)

            self.cog.findAllMatches('**/legs').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/m_leg.jpg'), 1)

        elif self.currentDept == 2:
            self.cog.findAllMatches('**/torso').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/l_blazer.jpg'), 1)

            self.cog.findAllMatches('**/arms').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/l_sleeve.jpg'), 1)

            self.cog.findAllMatches('**/legs').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/l_leg.jpg'), 1)

        elif self.currentDept == 3:
            self.cog.findAllMatches('**/torso').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/c_blazer.jpg'), 1)

            self.cog.findAllMatches('**/arms').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/c_sleeve.jpg'), 1)

            self.cog.findAllMatches('**/legs').setTexture(
                loader.loadTexture(self.pandaDirectory +
                                   '/resources/cogs/textures/c_leg.jpg'), 1)

        elif self.currentDept == 4:
            self.cog.findAllMatches('**/torso').setTexture(
                loader.loadTexture(
                    self.pandaDirectory +
                    '/resources/cogs/textures/waiter_m_blazer.jpg'), 1)

            self.cog.findAllMatches('**/arms').setTexture(
                loader.loadTexture(
                    self.pandaDirectory +
                    '/resources/cogs/textures/waiter_m_sleeve.jpg'), 1)

            self.cog.findAllMatches('**/legs').setTexture(
                loader.loadTexture(
                    self.pandaDirectory +
                    '/resources/cogs/textures/waiter_m_leg.jpg'), 1)

        else:
            raise Exception(
                'UH OH! currentDept is not between 0 and 4! The value of currentDept is {}'
                .format(self.currentDept))

    def nextHead(self):
        #Keep the head variable within the range and switch to the next head
        if self.currentHead >= 29:
            self.currentHead = 0
        else:
            self.currentHead += 1

        self.determineHead()

    def previousHead(self):
        #Keep the head variable within the range and switch to the previous head
        if self.currentHead <= 0:
            self.currentHead = 29
        else:
            self.currentHead -= 1

        self.determineHead()

    def nextBody(self):
        #Keep the head variable within the range and switch to the next body
        if self.currentBody >= 2:
            self.currentBody = 0
        else:
            self.currentBody += 1

        self.determineBody()

    def previousBody(self):
        #Keep the head variable within the range and switch to the previous body
        if self.currentBody <= 0:
            self.currentBody = 2
        else:
            self.currentBody -= 1

        self.determineBody()

    def nextDept(self):
        #Keep the head variable within the range and switch to the next department
        if self.currentDept >= 4:
            self.currentDept = 0
        else:
            self.currentDept += 1

        self.determineDept()

    def previousDept(self):
        #Keep the head variable within the range and switch to the previous department
        if self.currentDept <= 0:
            self.currentDept = 4
        else:
            self.currentDept -= 1

        self.determineDept()

    def resetCogPos(self):
        #Sets the cog's position to its starting location outside the scene
        self.cog.loop('walk')
        self.cog.setHpr(90, 0, 0)
        self.cog.setPos(15, 2, 0)

    def enterScene(self):
        #Establish the sequence for the cog to walk in the scene
        self.resetCogPos()
        self.enterView.start()

        self.isInView = True

    def exitScene(self):
        #Establish the sequence for the cog to walk out of the scene
        self.exitView.start()

        self.isInView = False

    def playNeutral(self):
        #Makes the neutral animation available to the GUI class
        self.cog.loop('neutral')

    def playVictory(self):
        #Makes the victory animation available to the GUI class
        self.cog.loop('victory')

    def getAnimPlaying(self):
        #returns the animation playing for the GUI class
        return self.cog.getCurrentAnim()
Beispiel #25
0
class Suit(Avatar.Avatar):
	healthColors = (Vec4(0, 1, 0, 1),
		Vec4(1, 1, 0, 1),
		Vec4(1, 0.5, 0, 1),
		Vec4(1, 0, 0, 1),
		Vec4(0.3, 0.3, 0.3, 1))
	healthGlowColors = (Vec4(0.25, 1, 0.25, 0.5),
		Vec4(1, 1, 0.25, 0.5),
		Vec4(1, 0.5, 0.25, 0.5),
		Vec4(1, 0.25, 0.25, 0.5),
		Vec4(0.3, 0.3, 0.3, 0))
	medallionColors = {'c': Vec4(0.863, 0.776, 0.769, 1.0),
		's': Vec4(0.843, 0.745, 0.745, 1.0),
		'l': Vec4(0.749, 0.776, 0.824, 1.0),
		'm': Vec4(0.749, 0.769, 0.749, 1.0)}
	health2DmgMultiplier = 2.5
	
	def __init__(self):
		try:
			self.Suit_initialized
			return
		except:
			self.Suit_initialized = 1
		
		Avatar.Avatar.__init__(self)
		self.avatarType = CIGlobals.Suit
		self.name = ''
		self.chat = ''
		self.suit = None
		self.suitHeads = None
		self.suitHead = None
		self.loserSuit = None
		self.healthMeterGlow = None
		self.healthMeter = None
		self.weapon = None
		self.weapon_sfx = None
		self.anim = None
		self.suit_dial = None
		self.shadow = None
		self.balloon_sfx = None
		self.add_sfx = None
		self.explosion = None
		self.largeExp = None
		self.smallExp = None
		self.death_sfx = None
		self.attack = None
		self.wtrajectory = None
		self.throwObjectId = None
		self.hasSpawned = False
		self.condition = 0
		self.type = ""
		self.head = ""
		self.team = ""
		self.isSkele = 0
		self.animFSM = ClassicFSM('Suit', [State('off', self.enterOff, self.exitOff),
								State('neutral', self.enterNeutral, self.exitNeutral),
								State('walk', self.enterWalk, self.exitWalk),
								State('die', self.enterDie, self.exitDie),
								State('attack', self.enterAttack, self.exitAttack),
								State('flydown', self.enterFlyDown, self.exitFlyDown),
								State('pie', self.enterPie, self.exitPie),
								State('win', self.enterWin, self.exitWin),
								State('flyaway', self.enterFlyAway, self.exitFlyAway),
								State('rollodex', self.enterRollodex, self.exitRollodex)], 'off', 'off')
		animStateList = self.animFSM.getStates()
		self.animFSM.enterInitialState()
		
		self.initializeBodyCollisions()
		
	def delete(self):
		try:
			self.Suit_deleted
		except:
			self.Suit_deleted = 1
			if self.suit:
				self.cleanupSuit()
			if self.loserSuit:
				self.cleanupLoserSuit()
			if self.suitHeads:
				self.suitHeads.remove()
				self.suitHeads = None
			if self.suitHead:
				self.suitHead.remove()
				self.suitHead = None
			if self.healthMeterGlow:
				self.healthMeterGlow.remove()
				self.healthMeterGlow = None
			if self.healthMeter:
				self.healthMeter.remove()
				self.healthMeter = None
			if self.shadow:
				self.shadow.remove()
				self.shadow = None
			self.weapon = None
			self.weapon_sfx = None
			self.suit_dial = None
			del self.shadowPlacer
			
	def generateSuit(self, suitType, suitHead, suitTeam, suitHealth, skeleton):
		self.health = suitHealth
		self.maxHealth = suitHealth
		self.generateBody(suitType, suitTeam, suitHead, skeleton)
		self.generateHealthMeter()
		self.generateHead(suitType, suitHead)
		self.setupNameTag()
		Avatar.Avatar.initShadow(self)
		
	def generateBody(self, suitType, suitTeam, suitHead, skeleton):
		if self.suit:
			self.cleanupSuit()
			
		self.team = suitTeam
		self.type = suitType
		self.head = suitHead
		self.isSkele = skeleton
		
		if suitType == "A":
			if skeleton:
				self.suit = Actor("phase_5/models/char/cogA_robot-zero.bam")
			else:
				self.suit = Actor("phase_3.5/models/char/suitA-mod.bam")
			self.suit.loadAnims({"neutral": "phase_4/models/char/suitA-neutral.bam",
							"walk": "phase_4/models/char/suitA-walk.bam",
							"pie": "phase_4/models/char/suitA-pie-small.bam",
							"land": "phase_5/models/char/suitA-landing.bam",
							"throw-object": "phase_5/models/char/suitA-throw-object.bam",
							"throw-paper": "phase_5/models/char/suitA-throw-paper.bam",
							"glower": "phase_5/models/char/suitA-glower.bam",
							"win": "phase_4/models/char/suitA-victory.bam",
							"rollodex": "phase_5/models/char/suitA-roll-o-dex.bam"})
		if suitType == "B":
			if skeleton:
				self.suit = Actor("phase_5/models/char/cogB_robot-zero.bam")
			else:
				self.suit = Actor("phase_3.5/models/char/suitB-mod.bam")
			self.suit.loadAnims({"neutral": "phase_4/models/char/suitB-neutral.bam",
							"walk": "phase_4/models/char/suitB-walk.bam",
							"pie": "phase_4/models/char/suitB-pie-small.bam",
							"land": "phase_5/models/char/suitB-landing.bam",
							"throw-object": "phase_5/models/char/suitB-throw-object.bam",
							"throw-paper": "phase_5/models/char/suitB-throw-paper.bam",
							"glower": "phase_5/models/char/suitB-magic1.bam",
							"win": "phase_4/models/char/suitB-victory.bam",
							"rollodex": "phase_5/models/char/suitB-roll-o-dex.bam"})
		if suitType == "C":
			if skeleton:
				self.suit = Actor("phase_5/models/char/cogC_robot-zero.bam")
			else:
				self.suit = Actor("phase_3.5/models/char/suitC-mod.bam")
			self.suit.loadAnims({"neutral": "phase_3.5/models/char/suitC-neutral.bam",
						"walk": "phase_3.5/models/char/suitC-walk.bam",
						"pie": "phase_3.5/models/char/suitC-pie-small.bam",
						"land": "phase_5/models/char/suitC-landing.bam",
						"throw-object": "phase_3.5/models/char/suitC-throw-paper.bam",
						"throw-paper": "phase_3.5/models/char/suitC-throw-paper.bam",
						"glower": "phase_5/models/char/suitC-glower.bam",
						"win": "phase_4/models/char/suitC-victory.bam"})
		if skeleton:
			self.suit.setTwoSided(1)
		self.suit.getGeomNode().setScale(CIGlobals.SuitScales[suitHead] / CIGlobals.SuitScaleFactors[suitType])
		
		if skeleton:
			if suitTeam == "s":
				self.suit_tie = loader.loadTexture("phase_5/maps/cog_robot_tie_sales.jpg")
			elif suitTeam == "m":
				self.suit_tie = loader.loadTexture("phase_5/maps/cog_robot_tie_money.jpg")
			elif suitTeam == "l":
				self.suit_tie = loader.loadTexture("phase_5/maps/cog_robot_tie_legal.jpg")
			elif suitTeam == "c":
				self.suit_tie = loader.loadTexture("phase_5/maps/cog_robot_tie_boss.jpg")
			self.suit.find('**/tie').setTexture(self.suit_tie, 1)
		else:
			self.suit_blazer = loader.loadTexture("phase_3.5/maps/" + suitTeam + "_blazer.jpg")
			self.suit_leg = loader.loadTexture("phase_3.5/maps/" + suitTeam + "_leg.jpg")
			self.suit_sleeve = loader.loadTexture("phase_3.5/maps/" + suitTeam + "_sleeve.jpg")
			
			self.suit.find('**/legs').setTexture(self.suit_leg, 1)
			self.suit.find('**/arms').setTexture(self.suit_sleeve, 1)
			self.suit.find('**/torso').setTexture(self.suit_blazer, 1)
		
			if suitHead == "coldcaller":
				self.suit.find('**/hands').setColor(0.55, 0.65, 1.0, 1.0)
			elif suitHead == "corporateraider":
				self.suit.find('**/hands').setColor(0.85, 0.55, 0.55, 1.0)
			elif suitHead == "bigcheese":
				self.suit.find('**/hands').setColor(0.75, 0.95, 0.75, 1.0)
			elif suitHead == "bloodsucker":
				self.suit.find('**/hands').setColor(0.95, 0.95, 1.0, 1.0)
			elif suitHead == "spindoctor":
				self.suit.find('**/hands').setColor(0.5, 0.8, 0.75, 1.0)
			elif suitHead == "legaleagle":
				self.suit.find('**/hands').setColor(0.25, 0.25, 0.5, 1.0)
			elif suitHead == "pennypincher":
				self.suit.find('**/hands').setColor(1.0, 0.5, 0.6, 1.0)
			elif suitHead == "loanshark":
				self.suit.find('**/hands').setColor(0.5, 0.85, 0.75, 1.0)
			else:
				self.suit.find('**/hands').setColor(CIGlobals.SuitHandColors[suitTeam])
		
		self.suit.reparentTo(self)
		
	def generateHead(self, suitType, suitHead):
		if self.suitHead:
			self.cleanupSuitHead()
			
		self.type = suitType
		self.head = suitHead
		
		if suitHead == "vp":
			self.suitHead = Actor("phase_9/models/char/sellbotBoss-head-zero.bam",
								{"neutral": "phase_9/models/char/bossCog-head-Ff_neutral.bam"})
			self.suitHead.setTwoSided(True)
			self.suitHead.loop("neutral")
			self.suitHead.setScale(0.35)
			self.suitHead.setHpr(270, 0, 270)
			self.suitHead.setZ(-0.10)
		else:
			if suitType == "A" or suitType == "B":
				self.suitHeads = loader.loadModel("phase_4/models/char/suit" + suitType + "-heads.bam")
			else:
				self.suitHeads = loader.loadModel("phase_3.5/models/char/suit" + suitType + "-heads.bam")
			self.suitHead = self.suitHeads.find('**/' + CIGlobals.SuitHeads[suitHead])
			if suitHead == "flunky":
				glasses = self.suitHeads.find('**/glasses')
				glasses.reparentTo(self.suitHead)
				glasses.setTwoSided(True)
			if suitHead in CIGlobals.SuitSharedHeads:
				if suitHead == "coldcaller":
					self.suitHead.setColor(0.25, 0.35, 1.0, 1.0)
				else:
					headTexture = loader.loadTexture("phase_3.5/maps/" + suitHead + ".jpg")
					self.suitHead.setTexture(headTexture, 1)
		if not self.isSkele:
			self.suitHead.reparentTo(self.suit.find('**/joint_head'))
			
	def cleanupSuit(self):
		if self.shadow:
			self.shadow.remove()
			self.shadow = None
		self.removeHealthBar()
		self.suit.cleanup()
		self.suit = None
		
	def cleanupSuitHead(self):
		if self.suitHeads:
			self.suitHeads.remove()
			self.suitHeads = None
		if self.suitHead:
			self.suitHead.remove()
			self.suitHead = None
		
	def cleanupLoserSuit(self):
		if self.explosion:
			self.explosion.remove()
			self.explosion = None
		if self.smallExp:
			self.smallExp = None
		if self.largeExp:
			self.largeExp.cleanup()
			self.largeExp = None
		if self.loserSuit:
			self.loserSuit.cleanup()
			self.loserSuit = None
		
	def setName(self, nameString, charName):
		Avatar.Avatar.setName(self, nameString, avatarType=self.avatarType, charName=charName)
		
	def setChat(self, chatString):
		self.chat = chatString
		if self.isSkele:
			if "?" in chatString:
				self.suit_dial = audio3d.loadSfx("phase_5/audio/sfx/Skel_COG_VO_question.ogg")
			elif "!" in chatString:
				self.suit_dial = audio3d.loadSfx("phase_5/audio/sfx/Skel_COG_VO_grunt.ogg")
			else:
				self.suit_dial = audio3d.loadSfx("phase_5/audio/sfx/Skel_COG_VO_statement.ogg")
		elif self.head == "vp":
			if "?" in chatString:
				self.suit_dial = audio3d.loadSfx("phase_9/audio/sfx/Boss_COG_VO_question.ogg")
			elif "!" in chatString:
				self.suit_dial = audio3d.loadSfx("phase_9/audio/sfx/Boss_COG_VO_grunt.ogg")
			else:
				self.suit_dial = audio3d.loadSfx("phase_9/audio/sfx/Boss_COG_VO_statement.ogg")
		else:
			if "?" in chatString:
				self.suit_dial = audio3d.loadSfx("phase_3.5/audio/dial/COG_VO_question.ogg")
			elif "!" in chatString:
				self.suit_dial = audio3d.loadSfx("phase_3.5/audio/dial/COG_VO_grunt.ogg")
			else:
				self.suit_dial = audio3d.loadSfx("phase_3.5/audio/dial/COG_VO_statement.ogg")
		if self.isSkele:
			audio3d.attachSoundToObject(self.suit_dial, self.suit)
		else:
			audio3d.attachSoundToObject(self.suit_dial, self.suitHead)
		self.suit_dial.play()
		Avatar.Avatar.setChat(self, chatString)
		
	def generateHealthMeter(self):
		self.removeHealthBar()
		model = loader.loadModel("phase_3.5/models/gui/matching_game_gui.bam")
		button = model.find('**/minnieCircle')
		button.setScale(3.0)
		button.setH(180)
		button.setColor(self.healthColors[0])
		chestNull = self.suit.find('**/def_joint_attachMeter')
		if chestNull.isEmpty():
			chestNull = self.suit.find('**/joint_attachMeter')
		button.reparentTo(chestNull)
		self.healthBar = button
		glow = loader.loadModel("phase_3.5/models/props/glow.bam")
		glow.reparentTo(self.healthBar)
		glow.setScale(0.28)
		glow.setPos(-0.005, 0.01, 0.015)
		glow.setColor(self.healthGlowColors[0])
		button.flattenLight()
		self.healthBarGlow = glow
		self.condition = 0
		
	def updateHealthBar(self, hp):
		if hp > self.hp:
			self.hp = hp
		self.hp -= hp
		health = float(self.health) / float(self.maxHP)
		if health > 0.95:
			condition = 0
		elif health > 0.7:
			condition = 1
		elif health > 0.3:
			condition = 2
		elif health > 0.05:
			condition = 3
		elif health > 0.0:
			condition = 4
		else:
			condition = 5
			
		if self.condition != condition:
			if condition == 4:
				blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1))
				taskMgr.add(blinkTask, self.taskName('blink-task'))
			elif condition == 5:
				if self.condition == 4:
					taskMgr.remove(self.taskName('blink-task'))
				blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1))
				taskMgr.add(blinkTask, self.taskName('blink-task'))
			else:
				self.healthBar.setColor(self.healthColors[condition], 1)
				self.healthBarGlow.setColor(self.healthGlowColors[condition], 1)
			self.condition = condition
			
	def __blinkRed(self, task):
		self.healthBar.setColor(self.healthColors[3], 1)
		self.healthBarGlow.setColor(self.healthGlowColors[3], 1)
		if self.condition == 5:
			self.healthBar.setScale(1.17)
		return Task.done
		
	def __blinkGray(self, task):
		if not self.healthBar:
			return
		self.healthBar.setColor(self.healthColors[4], 1)
		self.healthBarGlow.setColor(self.healthGlowColors[4], 1)
		if self.condition == 5:
			self.healthBar.setScale(1.0)
		return Task.done
		
	def removeHealthBar(self):
		if self.healthMeter:
			self.healthBar.removeNode()
			self.healthBar = None
		if self.condition == 4 or self.condition == 5:
			taskMgr.remove(self.taskName('blink-task'))
		self.healthCondition = 0
		return
			
	def enterOff(self):
		self.anim = None
		return
		
	def exitOff(self):
		pass
		
	def exitGeneral(self):
		self.suit.stop()
		
	def enterNeutral(self):
		self.suit.loop("neutral")
		
	def exitNeutral(self):
		self.exitGeneral()
		
	def enterRollodex(self):
		self.suit.play("rollodex")
		
	def exitRollodex(self):
		self.exitGeneral()
		
	def enterWalk(self):
		self.suit.loop("walk")
		
	def exitWalk(self):
		self.exitGeneral()
		
	def generateLoserSuit(self):
		self.cleanupLoserSuit()
		if self.type == "A":
			if self.isSkele:
				self.loserSuit = Actor("phase_5/models/char/cogA_robot-lose-mod.bam")
			else:
				self.loserSuit = Actor("phase_4/models/char/suitA-lose-mod.bam")
			self.loserSuit.loadAnims({"lose": "phase_4/models/char/suitA-lose.bam"})
		if self.type == "B":
			if self.isSkele:
				self.loserSuit = Actor("phase_5/models/char/cogB_robot-lose-mod.bam")
			else:
				self.loserSuit = Actor("phase_4/models/char/suitB-lose-mod.bam")
			self.loserSuit.loadAnims({"lose": "phase_4/models/char/suitB-lose.bam"})
		if self.type == "C":
			if self.isSkele:
				self.loserSuit = Actor("phase_5/models/char/cogC_robot-lose-mod.bam")
			else:
				self.loserSuit = Actor("phase_3.5/models/char/suitC-lose-mod.bam")
			self.loserSuit.loadAnims({"lose": "phase_3.5/models/char/suitC-lose.bam"})
		if self.isSkele:
			self.loserSuit.find('**/tie').setTexture(self.suit_tie, 1)
			self.loserSuit.setTwoSided(1)
		else:
			self.loserSuit.find('**/hands').setColor(self.suit.find('**/hands').getColor())
			self.loserSuit.find('**/legs').setTexture(self.suit_leg, 1)
			self.loserSuit.find('**/arms').setTexture(self.suit_sleeve, 1)
			self.loserSuit.find('**/torso').setTexture(self.suit_blazer, 1)
		self.loserSuit.getGeomNode().setScale(self.suit.getScale())
		self.loserSuit.reparentTo(self)
		if not self.isSkele:
			self.suitHead.reparentTo(self.loserSuit.find('**/joint_head'))
		self.loserSuit.setPos(self.suit.getPos(render))
		self.loserSuit.setHpr(self.suit.getHpr(render))
		self.cleanupSuit()
		Avatar.Avatar.initShadow(self, self.avatarType)
		self.loserSuit.reparentTo(render)
		
	def enterDie(self):
		self.generateLoserSuit()
		self.state = "dead"
		self.loserSuit.play("lose")
		spinningSound = base.loadSfx("phase_3.5/audio/sfx/Cog_Death.ogg")
		deathSound = base.loadSfx("phase_3.5/audio/sfx/ENC_cogfall_apart.ogg")
		#audio3d.attachSoundToObject(spinningSound, self.loserSuit)
		#audio3d.attachSoundToObject(deathSound, self.loserSuit)
		Sequence(Wait(0.8), SoundInterval(spinningSound, duration=1.2, startTime=1.5, volume=0.4, node=self.loserSuit),
			SoundInterval(spinningSound, duration=3.0, startTime=0.6, volume=2.0, node=self.loserSuit),
			SoundInterval(deathSound, volume=0.32, node=self.loserSuit)).start()
		Sequence(Wait(0.8), Func(self.smallDeathParticles), Wait(4.2), Func(self.suitExplode),
				Wait(1.0), Func(self.delSuit)).start()
		
	def smallDeathParticles(self):
		self.smallExp = ParticleLoader.loadParticleEffect("phase_3.5/etc/gearExplosionSmall.ptf")
		self.smallExp.start(self.loserSuit)
		
	def suitExplode(self):
		self.smallExp.cleanup()
		self.largeExp = ParticleLoader.loadParticleEffect("phase_3.5/etc/gearExplosion.ptf")
		self.largeExp.start(self.loserSuit)
		self.explosion = loader.loadModel("phase_3.5/models/props/explosion.bam")
		self.explosion.setScale(0.5)
		self.explosion.reparentTo(render)
		self.explosion.setBillboardPointEye()
		if self.isSkele:
			self.explosion.setPos(self.loserSuit.find('**/joint_head').getPos(render) + (0, 0, 2))
		else:
			self.explosion.setPos(self.suitHead.getPos(render) + (0,0,2))
		
	def delSuit(self):
		self.cleanupLoserSuit()
		self.disableBodyCollisions()
		
	def exitDie(self):
		pass
		
	def enterFlyDown(self):
		self.fd_sfx = audio3d.loadSfx("phase_5/audio/sfx/ENC_propeller_in.ogg")
		self.prop = Actor("phase_4/models/props/propeller-mod.bam",
						{"chan": "phase_4/models/props/propeller-chan.bam"})
		audio3d.attachSoundToObject(self.fd_sfx, self.prop)
		self.fd_sfx.play()
		self.prop.reparentTo(self.suit.find('**/joint_head'))
		propTrack = Sequence(Func(self.prop.loop, 'chan', fromFrame=0, toFrame=3),
							Wait(1.75),
							Func(self.prop.play, 'chan', fromFrame=3))
		propTrack.start()
		if not self.hasSpawned:
			showSuit = Task.sequence(Task(self.hideSuit), Task.pause(0.3), Task(self.showSuit))
			taskMgr.add(showSuit, "showsuit")
			self.hasSpawned = True
		dur = self.suit.getDuration('land')
		suitTrack = Sequence(Func(self.suit.pose, 'land', 0),
							Wait(1.9),
							ActorInterval(self.suit, 'land', duration=dur))
		suitTrack.start()
		
	def hideSuit(self, task):
		self.hide()
		return Task.done
	
	def showSuit(self, task):
		self.show()
		fadeIn = Sequence(Func(self.setTransparency, 1), self.colorScaleInterval(0.6, colorScale=Vec4(1,1,1,1), startColorScale=Vec4(1,1,1,0)), Func(self.clearColorScale), Func(self.clearTransparency), Func(self.reparentTo, render))
		fadeIn.start()
		return Task.done
		
	def initializeLocalCollisions(self, name):
		Avatar.Avatar.initializeLocalCollisions(self, 1, 3, name)
		
	def initializeBodyCollisions(self):
		Avatar.Avatar.initializeBodyCollisions(self, self.avatarType, 2.25, 1, 4, 2)
		self.initializeRay(self.avatarType)
		self.collTube.setTangible(0)
		
	def deleteBean(self):
		if self.bean:
			self.bean.remove_node()
			self.bean = None
			
	def createJellyBean(self):
		self.deleteBean()
		money = int(self.maxHP / CIGlobals.SuitAttackDamageFactors['clipontie'])
		if money == 1:
			self.bean = loader.loadModel("phase_5.5/models/estate/jellyBean.bam")
			self.bean.set_two_sided(True)
			random_r = random.uniform(0, 1)
			random_g = random.uniform(0, 1)
			random_b = random.uniform(0, 1)
			self.bean.set_color(random_r, random_g, random_b, 1)
		else:
			self.bean = loader.loadModel("phase_5.5/models/estate/jellybeanJar.bam")
		self.bean.reparent_to(render)
		self.bean.set_pos(self.get_pos(render) + (0, 0, 1))
		bean_int = self.bean.hprInterval(1,
										Point3(360, 0, 0),
										startHpr=(0, 0, 0))
		bean_int.loop()
		
	def exitFlyDown(self):
		audio3d.detachSound(self.fd_sfx)
		self.prop.cleanup()
		self.prop = None
		
	def enterFlyAway(self):
		self.fa_sfx = audio3d.loadSfx("phase_5/audio/sfx/ENC_propeller_out.ogg")
		self.prop = Actor("phase_4/models/props/propeller-mod.bam",
						{"chan": "phase_4/models/props/propeller-chan.bam"})
		audio3d.attachSoundToObject(self.fa_sfx, self.prop)
		self.fa_sfx.play()
		self.prop.reparentTo(self.suit.find('**/joint_head'))
		self.prop.setPlayRate(-1.0, "chan")
		propTrack = Sequence(Func(self.prop.play, 'chan', fromFrame=3),
							Wait(1.75),
							Func(self.prop.play, 'chan', fromFrame=0, toFrame=3))
		propTrack.start()
		self.suit.setPlayRate(-1.0, 'land')
		self.suit.play('land')
		
	def exitFlyAway(self):
		audio3d.detachSound(self.fa_sfx)
		self.prop.cleanup()
		self.prop = None
		
	def enterAttack(self, attack):
		self.attack = attack
		
		self.weapon_state = 'start'
		
		if attack == "canned":
			self.weapon = loader.loadModel("phase_5/models/props/can.bam")
			self.weapon.setScale(15)
			self.weapon.setR(180)
			self.wss = CollisionSphere(0,0,0,0.05)
		elif attack == "clipontie":
			self.weapon = loader.loadModel("phase_5/models/props/power-tie.bam")
			self.weapon.setScale(4)
			self.weapon.setR(180)
			self.wss = CollisionSphere(0,0,0,0.2)
		elif attack == "sacked":
			self.weapon = loader.loadModel("phase_5/models/props/sandbag-mod.bam")
			self.weapon.setScale(2)
			self.weapon.setR(180)
			self.weapon.setP(90)
			self.weapon.setY(-2.8)
			self.weapon.setZ(-0.3)
			self.wss = CollisionSphere(0,0,0,1)
		elif attack == "playhardball":
			self.weapon = loader.loadModel("phase_5/models/props/baseball.bam")
			self.weapon.setScale(10)
			self.wss = CollisionSphere(0,0,0,0.1)
			self.weapon.setZ(-0.5)
		elif attack == "marketcrash":
			self.weapon = loader.loadModel("phase_5/models/props/newspaper.bam")
			self.weapon.setScale(3)
			self.weapon.setPos(0.41, -0.06, -0.06)
			self.weapon.setHpr(90, 0, 270)
			self.wss = CollisionSphere(0,0,0,0.35)
		elif attack == "glowerpower":
			self.weapon = loader.loadModel("phase_5/models/props/dagger.bam")
			self.wss = CollisionSphere(0,0,0,1)
		else:
			notify.warning("unknown attack!")
			
		self.throwObjectId = random.uniform(0, 101010101010)
		
		if attack == "canned" or attack == "playhardball":
			self.weapon.reparentTo(self.suit.find('**/joint_Rhold'))
			if self.type == "C":
				taskMgr.doMethodLater(2.2, self.throwObject, "throwObject" + str(self.throwObjectId))
			else:
				taskMgr.doMethodLater(3, self.throwObject, "throwObject" + str(self.throwObjectId))
			self.suit.play("throw-object")
		elif attack == "clipontie" or attack == "marketcrash" or attack == "sacked":
			self.weapon.reparentTo(self.suit.find('**/joint_Rhold'))
			if self.type == "C":
				taskMgr.doMethodLater(2.2, self.throwObject, "throwObject" + str(self.throwObjectId))
			else:
				taskMgr.doMethodLater(3, self.throwObject, "throwObject" + str(self.throwObjectId))
			self.suit.play("throw-paper")
		elif attack == "glowerpower":
			taskMgr.doMethodLater(1, self.throwObject, "throwObject" + str(self.throwObjectId))
			self.suit.play("glower")
		self.weaponSensorId = random.uniform(0, 1010101010101001)
		wsnode = CollisionNode('weaponSensor' + str(self.weaponSensorId))
		wsnode.addSolid(self.wss)
		self.wsnp = self.weapon.attachNewNode(wsnode)
		if attack == "sacked":
			self.wsnp.setZ(1)
		elif attack == "marketcrash":
			self.wsnp.setPos(-0.25, 0.3, 0)
			
	def delWeapon(self, task):
		if self.weapon:
			self.weapon.removeNode()
			self.weapon = None
		return task.done
		
	def interruptAttack(self):
		if self.wtrajectory:
			if self.wtrajectory.isStopped():
				if self.weapon:
					self.weapon.removeNode()
					self.weapon = None
		if self.throwObjectId:
			taskMgr.remove("throwObject" + str(self.throwObjectId))
		
	def handleWeaponTouch(self):
		if not self.attack == "glowerpower" or not self.attack == "clipontie":
			if self.weapon_sfx:
				self.weapon_sfx.stop()
		try: self.wtrajectory.pause()
		except: pass
		if self.weapon:
			self.weapon.removeNode()
			self.weapon = None
		
	def weaponCollisions(self):
		self.wsnp.setCollideMask(BitMask32(0))
		self.wsnp.node().setFromCollideMask(CIGlobals.EventBitmask)
			
		event = CollisionHandlerEvent()
		event.setInPattern("%fn-into")
		event.setOutPattern("%fn-out")
		base.cTrav.addCollider(self.wsnp, event)
		
	def throwObject(self, task):
		self.playWeaponSound()
		
		self.weaponNP = NodePath("weaponNP")
		self.weaponNP.setScale(render, 1)
		try: self.weaponNP.reparentTo(self.find('**/joint_nameTag'))
		except: return task.done
		self.weaponNP.setPos(0, 50, 0)
		self.weaponNP.setHpr(0, 0, 0)
		
		if self.weapon:
			self.weapon.setScale(self.weapon.getScale(render))
		try: self.weapon.reparentTo(render)
		except: return task.done
		
		self.weapon.setPos(0,0,0)
		self.weapon.setHpr(0,0,0)
		
		if self.attack == "glowerpower":
			self.weapon.setH(self.weaponNP.getH(render))
			self.wtrajectory = self.weapon.posInterval(0.5,
										Point3(self.weaponNP.getPos(render)),
										startPos=(self.getX(render), self.getY(render) + 3, self.find('**/joint_head').getZ(render)))
			self.wtrajectory.start()
		else:
			self.wtrajectory = ProjectileInterval(self.weapon,
										startPos = (self.suit.find('**/joint_Rhold').getPos(render)),
										endPos = self.weaponNP.getPos(render),
										gravityMult = 0.7, duration = 1)
			self.wtrajectory.start()
		if self.attack == "glowerpower":
			taskMgr.doMethodLater(0.5, self.delWeapon, "delWeapon")
		else:
			taskMgr.doMethodLater(1, self.delWeapon, "delWeapon")
		self.weapon_state = 'released'
		
	def playWeaponSound(self):
		if self.attack == "glowerpower":
			self.weapon_sfx = audio3d.loadSfx("phase_5/audio/sfx/SA_glower_power.ogg")
		elif self.attack == "canned":
			self.weapon_sfx = audio3d.loadSfx("phase_5/audio/sfx/SA_canned_tossup_only.ogg")
		elif self.attack == "clipontie":
			self.weapon_sfx = audio3d.loadSfx("phase_5/audio/sfx/SA_powertie_throw.ogg")
		elif self.attack == "sacked":
			self.weapon_sfx = audio3d.loadSfx("phase_5/audio/sfx/SA_canned_tossup_only.ogg")
		elif self.attack == "playhardball":
			self.weapon_sfx = audio3d.loadSfx("phase_5/audio/sfx/SA_canned_tossup_only.ogg")
		elif self.attack == "marketcrash":
			self.weapon_sfx = audio3d.loadSfx("phase_5/audio/sfx/SA_canned_tossup_only.ogg")
		if self.weapon:
			audio3d.attachSoundToObject(self.weapon_sfx, self.weapon)
			self.weapon_sfx.play()
			
	def exitAttack(self):
		pass
		
	def enterPie(self):
		self.suit.play("pie")
		
	def exitPie(self):
		self.exitGeneral()
		
	def enterWin(self):
		self.suit.play("win")
		
	def exitWin(self):
		self.exitGeneral()
Beispiel #26
0
class Hobot:
    max_speed = 0.25
    acceleration = 0.5
    deceleration = 0.5

    def __init__(self, anim_root):
        self.move_root = base.render.attach_new_node('hobot')
        self.anim_root = anim_root

        self.model = Actor('hobot/hobot.bam')

        self.hand = self.model.expose_joint(None, 'modelRoot', 'hand')
        head = self.model.expose_joint(None, 'modelRoot', 'head')

        self.model.reparent_to(self.anim_root)
        self.model.set_two_sided(True)
        self.model.find("**/+GeomNode").set_transform(
            self.model.get_joint_transform_state('modelRoot',
                                                 'hobot root').get_inverse())
        self.model.set_z(0.1)
        self.facing = 1.0

        self.move_control = self.model.get_anim_control('move_forward')

        self.speed = 0.0
        self.locked = True

        self.model.wrt_reparent_to(self.move_root)
        self.model.hide()

        light_texture = loader.load_texture('hobot/light_on.png')
        light_texture.set_wrap_u(core.SamplerState.WM_clamp)
        light_texture.set_wrap_v(core.SamplerState.WM_clamp)
        cm = core.CardMaker('card')
        cm.set_frame(-0.15, 0.15, 0.15, 0.45)
        self.lightbulb = head.attach_new_node(cm.generate())
        self.lightbulb.set_texture(light_texture)
        self.lightbulb.set_attrib(
            core.ColorBlendAttrib.make(core.ColorBlendAttrib.M_add,
                                       core.ColorBlendAttrib.O_incoming_alpha,
                                       core.ColorBlendAttrib.O_one))
        self.lightbulb.set_depth_test(False)
        self.lightbulb.set_bin('fixed', 0)
        self.lightbulb.set_p(-90)
        self.lightbulb.set_billboard_point_eye()
        self.lightbulb.set_two_sided(True)
        self.lightbulb.hide()

        shadow_texture = loader.load_texture('hobot/drop_shadow.png')
        shadow_texture.set_wrap_u(core.SamplerState.WM_clamp)
        shadow_texture.set_wrap_v(core.SamplerState.WM_clamp)
        cm = core.CardMaker('card')
        cm.set_frame(-0.35, 0.35, -0.45, -0.1)
        self.shadow = self.model.attach_new_node(cm.generate())
        self.shadow.set_texture(shadow_texture)
        self.shadow.set_attrib(
            core.ColorBlendAttrib.make(
                core.ColorBlendAttrib.M_add, core.ColorBlendAttrib.O_zero,
                core.ColorBlendAttrib.O_one_minus_incoming_alpha))
        self.shadow.set_p(-90)
        self.shadow.set_depth_write(False)
        self.shadow.set_x(0.2)
        self.shadow.set_billboard_point_eye()
        self.shadow.set_two_sided(True)
        self.shadow.set_bin('transparent', 0)
        self.shadow.set_alpha_scale(0)
        self.shadow_fade = None

        self.ding_sfx = loader.load_sfx('hobot/sfx/ding.wav')
        self.ding_sfx.set_volume(0.5)
        self.move_sfx = loader.load_sfx('hobot/sfx/move.wav')
        self.move_sfx.set_loop(True)

        self.action_callback = None

    def destroy(self):
        if self.move_control.playing:
            self.move_control.stop()
            self.move_sfx.stop()

        # RIP hobot :-(
        self.model.cleanup()

    def set_action(self, callback):
        self.action_callback = callback
        if self.lightbulb.is_hidden():
            self.ding_sfx.play()
            self.lightbulb.show()

    def clear_action(self):
        self.action_callback = None
        self.lightbulb.hide()

    def do_action(self):
        if self.action_callback:
            self.action_callback()

    def lock(self):
        #self.model.wrt_reparent_to(self.anim_root)
        self.locked = True
        self.speed = 0.0

    def unlock(self):
        self.model.set_pos(self.anim_root.get_pos())
        self.locked = False
        self.model.set_hpr(0, 0, -90)
        self.model.show()

    def face(self, dir):
        if dir:
            self.facing = 1 if dir > 0 else -1
            self.model.set_sz(self.facing * -self.model.get_sx())

    def process_input(self, input, dt, level):
        if self.locked:
            return

        if input.get_action('interact'):
            self.do_action()

        move_x = input.get_axis('move-horizontal')
        move_y = input.get_axis('move-vertical')

        if move_x:
            self.speed += move_x * self.acceleration * dt
            self.face(move_x)
        elif self.speed > 0:
            self.speed = max(0, self.speed - self.deceleration * dt)
        elif self.speed < 0:
            self.speed = min(0, self.speed + self.deceleration * dt)

        delta = core.Vec2(0, 0)

        if move_y:
            delta.y = move_y * dt * MOVE_Y_SPEED

        if self.speed != 0:
            if self.speed > self.max_speed:
                self.speed = self.max_speed
            elif self.speed < -self.max_speed:
                self.speed = -self.max_speed

            delta.x = self.speed * dt
            pos_changed = True

            self.move_control.set_play_rate(self.speed * self.facing * 4.0)

            if not self.move_control.playing:
                self.move_control.loop(False)
                self.move_sfx.play()

        elif self.move_control.playing:
            self.move_control.stop()
            self.move_sfx.stop()

        if delta.length_squared() > 0:
            old_pos = self.model.get_pos()
            new_pos = level.adjust_move(old_pos.xy, delta)
            self.model.set_pos(core.LPoint3(new_pos, old_pos.z))
Beispiel #27
0
class FPSCamera(DirectObject):

    MaxP = 90.0
    MinP = -90.0
    PitchUpdateEpsilon = 0.1
    ViewModelFOV = 70.0

    BobCycleMin = 1.0
    BobCycleMax = 0.45
    Bob = 0.002
    BobUp = 0.5

    PunchDamping = 9.0
    PunchSpring = 65.0

    PrintAnimLengths = False

    def __init__(self):
        DirectObject.__init__(self)

        self.mouseEnabled = False

        self.lastCamRoot2Quat = Quat(Quat.identQuat())

        self.punchAngleVel = Vec3(0)
        self.punchAngle = Vec3(0)

        self.lastFacing = Vec3(0)

        self.lastMousePos = Point2(0)
        self.currMousePos = Point2(0)

        self.bobTime = 0
        self.lastBobTime = 0

        self.lastVMPos = Point3(0)

        self.camRoot = NodePath("camRoot")
        self.camRoot2 = self.camRoot.attachNewNode("camRoot2")
        self.lastPitch = 0

        self.lastEyeHeight = 0.0

        # Updates to the transform of camRoot
        self.vmRender = NodePath(
            BSPRender('vmRender', BSPLoader.getGlobalPtr()))
        self.vmRender.setShaderAuto()
        self.vmRoot = self.vmRender.attachNewNode('vmRoot')
        self.vmRoot2 = self.vmRoot.attachNewNode(ModelRoot('vmRoot2'))
        self.viewModel = Actor(
            "phase_14/models/char/v_toon_arms.bam",
            {
                "zero": "phase_14/models/char/v_toon_arms.egg",

                # Squirt gun viewmodel animations
                "sg_draw": "phase_14/models/char/v_toon_arms-draw.egg",
                "sg_idle": "phase_14/models/char/v_toon_arms-idle.egg",
                "sg_inspect": "phase_14/models/char/v_toon_arms-inspect.egg",
                "sg_shoot_begin":
                "phase_14/models/char/v_toon_arms-shoot_begin.egg",
                "sg_shoot_loop":
                "phase_14/models/char/v_toon_arms-shoot_loop.egg",
                "sg_shoot_end":
                "phase_14/models/char/v_toon_arms-shoot_end.egg",
                "pie_draw": "phase_14/models/char/v_toon_arms-pie_draw.egg",
                "pie_idle": "phase_14/models/char/v_toon_arms-pie_idle.egg",
                "button_draw":
                "phase_14/models/char/v_toon_arms-button_draw.egg",
                "button_idle":
                "phase_14/models/char/v_toon_arms-button_idle.egg",
                "button_press":
                "phase_14/models/char/v_toon_arms-button_press.egg",
                "gumball_draw":
                "phase_14/models/char/v_toon_arms-gumball_draw.egg",
                "gumball_idle":
                "phase_14/models/char/v_toon_arms-gumball_idle.egg",
                "gumball_fire":
                "phase_14/models/char/v_toon_arms-gumball_fire.egg",
                "hose_draw": "phase_14/models/char/v_toon_arms-hose_draw.egg",
                "hose_idle": "phase_14/models/char/v_toon_arms-hose_idle.egg",
                "hose_shoot_begin":
                "phase_14/models/char/v_toon_arms-hose_shoot_begin.egg",
                "hose_shoot_loop":
                "phase_14/models/char/v_toon_arms-hose_shoot_loop.egg",
                "hose_shoot_end":
                "phase_14/models/char/v_toon_arms-hose_shoot_end.egg",
                "tnt_draw": "phase_14/models/char/v_toon_arms-tnt_draw.egg",
                "tnt_idle": "phase_14/models/char/v_toon_arms-tnt_idle.egg",
                "tnt_throw": "phase_14/models/char/v_toon_arms-tnt_throw.egg",
                "slap_idle": "phase_14/models/char/v_toon_arms-slap_idle.egg",
                "slap_hit": "phase_14/models/char/v_toon_arms-slap_hit.egg",
                "sound": "phase_14/models/char/v_toon_arms-sound.egg"
            })
        self.viewModel.setBlend(
            frameBlend=base.config.GetBool("interpolate-frames", False))
        self.viewModel.reparentTo(self.vmRoot2)
        self.viewModel.find("**/hands").setTwoSided(True)
        self.viewModel.hide()

        self.defaultViewModel = self.viewModel
        self.idealFov = self.ViewModelFOV

        precacheActor(self.viewModel)
        #self.viewModel.clearMaterial()
        #self.viewModel.setMaterial(CIGlobals.getCharacterMaterial(specular = (0, 0, 0, 1)), 1)
        self.viewportLens = PerspectiveLens()
        self.viewportLens.setMinFov(self.ViewModelFOV / (4. / 3.))
        self.viewportLens.setNear(0.3)
        # Updates to the transform of base.camera
        self.viewportCam = base.makeCamera(base.win,
                                           clearDepth=True,
                                           camName='fpsViewport',
                                           mask=CIGlobals.ViewModelCamMask,
                                           lens=self.viewportLens)
        # Pretend to be the main camera so the viewmodel gets ambient probes updated
        self.viewportCam.node().setTag("__mainpass__", "1")
        self.viewportCam.reparentTo(self.vmRoot)

        self.vmGag = None
        self.vmAnimTrack = None
        self.dmgFade = OnscreenImage(image="phase_14/maps/damage_effect.png",
                                     parent=render2d)
        self.dmgFade.setBin('gui-popup', 100)
        self.dmgFade.setTransparency(1)
        self.dmgFade.setColorScale(1, 1, 1, 0)
        self.dmgFadeIval = None

        #self.accept('v', self.vmRender.ls)

        #base.bspLoader.addDynamicNode(self.vmRoot)

        if self.PrintAnimLengths:
            print "v_toon_arms animation lengths:"
            for anim in self.viewModel.getAnimNames():
                print "\t{0}\t:\t{1}".format(anim,
                                             self.viewModel.getDuration(anim))

        taskMgr.add(self.__vpDebugTask, "vpdebutask", sort=-100)

    def setViewModelFOV(self, fov):
        self.idealFov = fov

    def restoreViewModelFOV(self):
        self.idealFov = self.ViewModelFOV

    def swapViewModel(self, newViewModel, fov=70.0):
        if newViewModel.isEmpty():
            return

        isHidden = False
        if not self.viewModel.isEmpty():
            self.viewModel.reparentTo(hidden)
            isHidden = self.viewModel.isHidden()

        self.viewModel = newViewModel
        self.viewModel.reparentTo(self.vmRoot2)
        if isHidden:
            self.viewModel.hide()
        else:
            self.viewModel.show()

        self.setViewModelFOV(fov)

    def restoreViewModel(self):
        isHidden = False
        if not self.viewModel.isEmpty():
            self.viewModel.reparentTo(hidden)
            isHidden = self.viewModel.isHidden()

        self.viewModel = self.defaultViewModel
        self.viewModel.reparentTo(self.vmRoot2)
        if isHidden:
            self.viewModel.hide()
        else:
            self.viewModel.show()

        self.restoreViewModelFOV()

    def addViewPunch(self, punch):
        self.punchAngleVel += punch * 20

    def resetViewPunch(self, tolerance=0.0):
        if tolerance != 0.0:
            tolerance *= tolerance
            check = self.punchAngleVel.lengthSquared(
            ) + self.punchAngle.lengthSquared()
            if check > tolerance:
                return

        self.punchAngle = Vec3(0)
        self.punchAngleVel = Vec3(0)

    def decayPunchAngle(self):
        if self.punchAngle.lengthSquared(
        ) > 0.001 or self.punchAngleVel.lengthSquared() > 0.001:
            dt = globalClock.getDt()
            self.punchAngle += self.punchAngleVel * dt
            damping = 1 - (self.PunchDamping * dt)

            if damping < 0:
                damping = 0
            self.punchAngleVel *= damping

            # Torsional spring
            springForceMag = self.PunchSpring * dt
            springForceMag = CIGlobals.clamp(springForceMag, 0.0, 2.0)
            self.punchAngleVel -= self.punchAngle * springForceMag

            # Don't wrap around
            self.punchAngle.set(CIGlobals.clamp(self.punchAngle[0], -179, 179),
                                CIGlobals.clamp(self.punchAngle[1], -89, 89),
                                CIGlobals.clamp(self.punchAngle[2], -89, 89))
        else:
            self.punchAngle = Vec3(0)
            self.punchAngleVel = Vec3(0)

    def hideViewModel(self):
        self.viewModel.hide(BitMask32.allOn())

    def showViewModel(self):
        if not base.localAvatar.isFirstPerson():
            return

        self.viewModel.showThrough(CIGlobals.ViewModelCamMask)

    def __vpDebugTask(self, task):
        if self.vmRender.getState() != render.getState():
            # pretend like the view model is part of the main scene
            self.vmRender.setState(render.getState())

        self.viewportLens.setAspectRatio(base.getAspectRatio())
        self.viewportLens.setMinFov(self.idealFov / (4. / 3.))
        self.vmRoot.setTransform(render, self.camRoot.getTransform(render))
        self.viewportCam.setTransform(render, base.camera.getTransform(render))

        # Since the viewmodel is not underneath BSPRender, it's not going to be automatically
        # influenced by the ambient probes. We need to do this explicitly.
        #base.bspLoader.updateDynamicNode(self.vmRoot)

        #self.viewportDebug.setImage(self.viewportCam.node().getDisplayRegion(0).getScreenshot())

        return task.cont

    def handleSuitAttack(self, attack):
        print "FPSCamera handleSuitAttack:", attack

    def doDamageFade(self, r, g, b, severity=1.0):
        if self.dmgFadeIval:
            self.dmgFadeIval.finish()
            self.dmgFadeIval = None
        severity = min(1.0, severity)
        self.dmgFadeIval = Sequence(
            LerpColorScaleInterval(self.dmgFade,
                                   0.25, (r, g, b, severity), (r, g, b, 0),
                                   blendType='easeOut'), Wait(1.0),
            LerpColorScaleInterval(self.dmgFade,
                                   2.0, (r, g, b, 0), (r, g, b, severity),
                                   blendType='easeInOut'))
        self.dmgFadeIval.start()

    def setVMAnimTrack(self, track, loop=False):
        self.clearVMAnimTrack()

        self.vmAnimTrack = track
        if loop:
            self.vmAnimTrack.loop()
        else:
            self.vmAnimTrack.start()

    def clearVMAnimTrack(self):
        if self.vmAnimTrack:
            self.vmAnimTrack.pause()
            self.vmAnimTrack = None

    def setVMGag(self,
                 gag,
                 pos=(0, 0, 0),
                 hpr=(0, 0, 0),
                 scale=(1, 1, 1),
                 hand=0,
                 animate=True):
        self.clearVMGag()

        handNode = NodePath()
        if hand == ATTACK_HOLD_RIGHT:
            handNode = self.getViewModelRightHand()
        elif hand == ATTACK_HOLD_LEFT:
            handNode = self.getViewModelLeftHand()

        if isinstance(gag, Actor) and animate:
            self.vmGag = Actor(other=gag)
            self.vmGag.reparentTo(handNode)
            self.vmGag.loop('chan')
        else:
            self.vmGag = gag.copyTo(handNode)
        self.vmGag.setPos(pos)
        self.vmGag.setHpr(hpr)
        self.vmGag.setScale(scale)

    def clearVMGag(self):
        if self.vmGag:
            if isinstance(self.vmGag, Actor):
                self.vmGag.cleanup()
            self.vmGag.removeNode()
            self.vmGag = None

    def setup(self):
        try:
            # Match the arm color with the torso color of local avatar
            self.viewModel.find("**/arms").setColorScale(
                base.localAvatar.getTorsoColor(), 1)
            # Same with glove cover
            self.viewModel.find("**/hands").setColorScale(
                base.localAvatar.getGloveColor(), 1)
        except:
            pass

        self.attachCamera()

    def attachCamera(self, reset=True):
        if reset:
            self.camRoot.reparentTo(base.localAvatar)
            if base.localAvatar.isFirstPerson():
                self.camRoot.setPos(base.localAvatar.getEyePoint())
            else:
                self.camRoot.setPos(0, 0, max(base.localAvatar.getHeight(),
                                              3.0))
            self.camRoot.setHpr(0, 0, 0)
            self.camRoot2.setPosHpr(0, 0, 0, 0, 0, 0)

        base.camera.reparentTo(self.camRoot2)

        if base.localAvatar.isFirstPerson():
            base.camera.setPosHpr(0, 0, 0, 0, 0, 0)
        elif base.localAvatar.isThirdPerson():
            pos, lookAt = self.getThirdPersonBattleCam()
            base.localAvatar.smartCamera.setIdealCameraPos(pos)
            base.localAvatar.smartCamera.setLookAtPoint(lookAt)

    def getThirdPersonBattleCam(self):
        camHeight = max(base.localAvatar.getHeight(), 3.0)
        heightScaleFactor = camHeight * 0.3333333333

        return ((1, -5 * heightScaleFactor, 0), (1, 10, 0))

    def getViewModelLeftHand(self):
        return self.viewModel.find("**/def_left_hold")

    def getViewModelRightHand(self):
        return self.viewModel.find("**/def_right_hold")

    def getViewModel(self):
        return self.viewModel

    def acceptEngageKeys(self):
        self.acceptOnce("escape", self.__handleEscapeKey)

    def ignoreEngageKeys(self):
        self.ignore("escape")

    def enableMouseMovement(self):
        props = WindowProperties()
        props.setMouseMode(WindowProperties.MConfined)
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        self.attachCamera(False)
        if base.localAvatar.isFirstPerson():
            base.localAvatar.getGeomNode().hide()

        base.win.movePointer(0,
                             base.win.getXSize() / 2,
                             base.win.getYSize() / 2)

        base.taskMgr.add(self.__updateTask, "mouseUpdateFPSCamera", sort=-40)
        self.acceptEngageKeys()

        self.mouseEnabled = True

        base.localAvatar.enableGagKeys()

    def disableMouseMovement(self, allowEnable=False, showAvatar=True):
        props = WindowProperties()
        props.setMouseMode(WindowProperties.MAbsolute)
        props.setCursorHidden(False)
        base.win.requestProperties(props)

        base.taskMgr.remove("mouseUpdateFPSCamera")

        base.localAvatar.disableGagKeys()

        if allowEnable:
            self.acceptEngageKeys()
        else:
            self.ignoreEngageKeys()
            if showAvatar or base.localAvatar.isThirdPerson():
                base.localAvatar.getGeomNode().show()
            else:
                base.localAvatar.getGeomNode().hide()

        self.mouseEnabled = False

    def __handleEscapeKey(self):
        if self.mouseEnabled:
            self.disableMouseMovement(True)
        else:
            self.enableMouseMovement()

    #def doCameraJolt(self, amplitude, horizRange = [-1, 1], vertRange = [1]):
    #h = random.choice(horizRange) * amplitude
    #p = random.choice(vertRange) * amplitude
    #nquat = Quat(Quat.identQuat())
    #nquat.setHpr((h, p, 0))
    #self.lastCamRoot2Quat = self.lastCamRoot2Quat + nquat

    #Effects.createPBounce(self.camRoot2, 3, self.camRoot2.getHpr(), 1, amplitude).start()
    #Effects.createHBounce(self.camRoot2, 3, self.camRoot2.getHpr(), 1, amplitude).start()

    def handleJumpHardLand(self):
        down = Parallel(
            LerpPosInterval(base.cam,
                            0.1, (-0.1, 0, -0.2), (0, 0, 0),
                            blendType='easeOut'),
            LerpHprInterval(base.cam,
                            0.1, (0, 0, -2.5), (0, 0, 0),
                            blendType='easeOut'))
        up = Parallel(
            LerpPosInterval(base.cam,
                            0.7, (0, 0, 0), (-0.1, 0, -0.2),
                            blendType='easeInOut'),
            LerpHprInterval(base.cam,
                            0.7, (0, 0, 0), (0, 0, -2.5),
                            blendType='easeInOut'))
        Sequence(down, up).start()

    def __updateTask(self, task):
        # TODO -- This function does a lot of math, I measured it to take .5 ms on my laptop
        #         That's a lot of time for something miniscule like sway and bob.

        dt = globalClock.getDt()
        time = globalClock.getFrameTime()

        if base.localAvatar.isFirstPerson():
            eyePoint = base.localAvatar.getEyePoint()
            if base.localAvatar.walkControls.crouching:
                eyePoint[2] = eyePoint[2] / 2.0
            eyePoint[2] = CIGlobals.lerpWithRatio(eyePoint[2],
                                                  self.lastEyeHeight, 0.4)
            self.lastEyeHeight = eyePoint[2]

        camRootAngles = Vec3(0)

        # Mouse look around
        mw = base.mouseWatcherNode
        if mw.hasMouse():
            md = base.win.getPointer(0)
            center = Point2(base.win.getXSize() / 2, base.win.getYSize() / 2)

            xDist = md.getX() - center.getX()
            yDist = md.getY() - center.getY()

            sens = self.__getMouseSensitivity()

            angular = -(xDist * sens) / dt
            base.localAvatar.walkControls.controller.setAngularMovement(
                angular)
            camRootAngles.setY(self.lastPitch - yDist * sens)

            if camRootAngles.getY() > FPSCamera.MaxP:
                camRootAngles.setY(FPSCamera.MaxP)
                yDist = 0
            elif camRootAngles.getY() < FPSCamera.MinP:
                yDist = 0
                camRootAngles.setY(FPSCamera.MinP)

            base.win.movePointer(0, int(center.getX()), int(center.getY()))

        if base.localAvatar.isFirstPerson():
            # Camera / viewmodel bobbing
            vmBob = Point3(0)
            vmAngles = Vec3(0)
            vmRaise = Point3(0)
            camBob = Point3(0)

            maxSpeed = base.localAvatar.walkControls.BattleRunSpeed * 16.0

            speed = base.localAvatar.walkControls.speeds.length() * 16.0
            speed = max(-maxSpeed, min(maxSpeed, speed))

            bobOffset = CIGlobals.remapVal(speed, 0, maxSpeed, 0.0, 1.0)

            self.bobTime += (time - self.lastBobTime) * bobOffset
            self.lastBobTime = time

            # Calculate the vertical bob
            cycle = self.bobTime - int(
                self.bobTime / self.BobCycleMax) * self.BobCycleMax
            cycle /= self.BobCycleMax
            if cycle < self.BobUp:
                cycle = math.pi * cycle / self.BobUp
            else:
                cycle = math.pi + math.pi * (cycle - self.BobUp) / (1.0 -
                                                                    self.BobUp)

            verticalBob = speed * 0.005
            verticalBob = verticalBob * 0.3 + verticalBob * 0.7 * math.sin(
                cycle)
            verticalBob = max(-7.0, min(4.0, verticalBob))
            verticalBob /= 16.0

            # Calculate the lateral bob
            cycle = self.bobTime - int(
                self.bobTime / self.BobCycleMax * 2) * self.BobCycleMax * 2
            cycle /= self.BobCycleMax * 2
            if cycle < self.BobUp:
                cycle = math.pi * cycle / self.BobUp
            else:
                cycle = math.pi + math.pi * (cycle - self.BobUp) / (1.0 -
                                                                    self.BobUp)

            lateralBob = speed * 0.005
            lateralBob = lateralBob * 0.3 + lateralBob * 0.7 * math.sin(cycle)
            lateralBob = max(-7.0, min(4.0, lateralBob))
            lateralBob /= 16.0

            # Apply bob, but scaled down a bit
            vmBob.set(lateralBob * 0.8, 0, verticalBob * 0.1)
            # Z bob a bit more
            vmBob[2] += verticalBob * 0.1
            # Bob the angles
            vmAngles[2] += verticalBob * 0.5
            vmAngles[1] -= verticalBob * 0.4
            vmAngles[0] -= lateralBob * 0.3

            # ================================================================
            # Viewmodel lag/sway

            angles = self.camRoot.getHpr(render)
            quat = Quat()
            quat.setHpr(angles)
            invQuat = Quat()
            invQuat.invertFrom(quat)

            maxVMLag = 1.5
            lagforward = quat.getForward()
            if dt != 0.0:
                lagdifference = lagforward - self.lastFacing
                lagspeed = 5.0
                lagdiff = lagdifference.length()
                if (lagdiff > maxVMLag) and (maxVMLag > 0.0):
                    lagscale = lagdiff / maxVMLag
                    lagspeed *= lagscale

                self.lastFacing = CIGlobals.extrude(self.lastFacing,
                                                    lagspeed * dt,
                                                    lagdifference)
                self.lastFacing.normalize()
                lfLocal = invQuat.xform(lagdifference)
                vmBob = CIGlobals.extrude(vmBob, 5.0 / 16.0, lfLocal * -1.0)

            pitch = angles[1]
            if pitch > 180:
                pitch -= 360
            elif pitch < -180:
                pitch += 360

            vmBob = CIGlobals.extrude(vmBob, pitch * (0.035 / 16),
                                      Vec3.forward())
            vmBob = CIGlobals.extrude(vmBob, pitch * (0.03 / 16), Vec3.right())
            vmBob = CIGlobals.extrude(vmBob, pitch * (0.02 / 16), Vec3.up())

            # ================================================================

            vmRaise.set(
                0, 0, 0
            )  #(0, abs(camRootAngles.getY()) * -0.002, camRootAngles.getY() * 0.002)
            camBob.set(0, 0, 0)

            # Apply bob, raise, and sway to the viewmodel.
            self.viewModel.setPos(vmBob + vmRaise + self.lastVMPos)
            self.vmRoot2.setHpr(vmAngles)
            self.camRoot.setPos(eyePoint + camBob)

        newPitch = camRootAngles.getY()

        if abs(newPitch - self.lastPitch) > self.PitchUpdateEpsilon:
            # Broadcast where our head is looking
            head = base.localAvatar.getPart("head")
            if head and not head.isEmpty():
                # Constrain the head pitch a little bit so it doesn't look like their head snapped
                headPitch = max(-47, newPitch)
                headPitch = min(75, headPitch)
                base.localAvatar.b_setLookPitch(headPitch)

        self.lastPitch = newPitch

        if base.localAvatar.isFirstPerson():
            # Apply punch angle
            self.decayPunchAngle()
            camRootAngles += self.punchAngle

        self.camRoot.setHpr(camRootAngles)

        return task.cont

    def __getMouseSensitivity(self):
        return CIGlobals.getSettingsMgr().getSetting('fpmgms').getValue()

    def cleanup(self):
        taskMgr.remove("vpdebutask")
        self.disableMouseMovement(False, False)
        self.clearVMAnimTrack()
        self.clearVMGag()
        if self.viewModel:
            self.viewModel.cleanup()
            self.viewModel.removeNode()
        self.viewModel = None
        if self.vmRender:
            self.vmRender.removeNode()
        self.vmRender = None
        self.vmRoot = None
        self.vmRoot2 = None
        self.viewportLens = None
        if self.viewportCam:
            self.viewportCam.removeNode()
        self.viewportCam = None
        if self.camRoot:
            self.camRoot.removeNode()
        self.camRoot = None
        self.camRoot2 = None
        self.lastEyeHeight = None
        self.lastPitch = None
        self.bobTime = None
        self.lastBobTime = None
        self.mouseEnabled = None
        self.lastCamRoot2Quat = None
        self.punchAngleVel = None
        self.punchAngle = None
        self.lastFacing = None
        self.lastMousePos = None
        self.currMousePos = None
        self.lastVMPos = None
        self.defaultViewModel = None
        self.idealFov = None
        self.vmGag = None
        self.vmAnimTrack = None
        self.dmgFade = None
        self.dmgFadeIval = None
        self.ignoreAll()
Beispiel #28
0
class DistributedPartyFireworksActivity(DistributedPartyActivity,
                                        FireworkShowMixin):

    notify = directNotify.newCategory("DistributedPartyFireworksActivity")

    def __init__(self, cr):
        """
        cr: instance of ClientRepository
        """
        DistributedPartyFireworksActivity.notify.debug("__init__")
        DistributedPartyActivity.__init__(self,
                                          cr,
                                          ActivityIds.PartyFireworks,
                                          ActivityTypes.HostInitiated,
                                          wantLever=True)
        FireworkShowMixin.__init__(self,
                                   restorePlaygroundMusic=True,
                                   startDelay=FireworksPostLaunchDelay)

    def setEventId(self, eventId):
        DistributedPartyFireworksActivity.notify.debug(
            "setEventId( %s )" % FireworkShows.getString(eventId))
        self.eventId = eventId

    def setShowStyle(self, showStyle):
        DistributedPartyFireworksActivity.notify.debug("setShowStyle( %d )" %
                                                       showStyle)
        self.showStyle = showStyle

    def load(self):
        """
        Load the necessary assets
        """
        DistributedPartyFireworksActivity.notify.debug("load")
        DistributedPartyActivity.load(self)

        self.eventId = PartyGlobals.FireworkShows.Summer

        # load the rocket platform and place it in party space
        self.launchPadModel = loader.loadModel(
            'phase_13/models/parties/launchPad')
        # Compensate for pivot of fireworks model and center it in 2x4 space
        self.launchPadModel.setH(90.0)
        self.launchPadModel.setPos(0.0, -18.0, 0.0)
        # reparent to root
        self.launchPadModel.reparentTo(self.root)
        # special case the depth testing on the railings to prevent
        # transparency oddness
        railingsCollection = self.launchPadModel.findAllMatches(
            "**/launchPad_mesh/*railing*")
        for i in range(railingsCollection.getNumPaths()):
            railingsCollection[i].setAttrib(
                AlphaTestAttrib.make(RenderAttrib.MGreater, 0.75))

        # place the lever on the platform
        leverLocator = self.launchPadModel.find("**/RocketLever_locator")
        self.lever.setPosHpr(Vec3.zero(), Vec3.zero())
        self.lever.reparentTo(leverLocator)
        self.toonPullingLeverInterval = None

        # place the activity sign
        self.sign.reparentTo(
            self.launchPadModel.find("**/launchPad_sign_locator"))

        # load the rocket with animation and place it on the platform
        self.rocketActor = Actor(
            'phase_13/models/parties/rocket_model',
            {'launch': 'phase_13/models/parties/rocket_launch'},
        )

        rocketLocator = self.launchPadModel.find("**/rocket_locator")
        self.rocketActor.reparentTo(rocketLocator)
        # ensure the rocket is never culled
        self.rocketActor.node().setBound(OmniBoundingVolume())
        self.rocketActor.node().setFinal(True)

        effectsLocator = self.rocketActor.find("**/joint1")
        self.rocketExplosionEffect = RocketExplosion(effectsLocator,
                                                     rocketLocator)

        self.rocketParticleSeq = None

        self.launchSound = base.loader.loadSfx(
            "phase_13/audio/sfx/rocket_launch.mp3")

        # create state machine and set initial state
        self.activityFSM = FireworksActivityFSM(self)
        self.activityFSM.request("Idle")

    def unload(self):
        DistributedPartyFireworksActivity.notify.debug("unload")
        taskMgr.remove(self.taskName("delayedStartShow"))
        if self.rocketParticleSeq:
            self.rocketParticleSeq.pause()
            self.rocketParticleSeq = None
        self.launchPadModel.removeNode()
        del self.launchPadModel
        del self.toonPullingLeverInterval
        self.rocketActor.delete()
        self.rocketExplosionEffect.destroy()
        self.activityFSM.request("Disabled")
        del self.rocketActor
        del self.launchSound
        del self.activityFSM
        del self.eventId
        del self.showStyle
        DistributedPartyActivity.unload(self)

    def _leverPulled(self, collEntry):
        DistributedPartyFireworksActivity.notify.debug("_leverPulled")
        hostPulledLever = DistributedPartyActivity._leverPulled(
            self, collEntry)
        if self.activityFSM.getCurrentOrNextState() == "Active":
            self.showMessage(TTLocalizer.PartyFireworksAlreadyActive)
        elif self.activityFSM.getCurrentOrNextState() == "Disabled":
            self.showMessage(TTLocalizer.PartyFireworksAlreadyDone)
        elif self.activityFSM.getCurrentOrNextState() == "Idle":
            if hostPulledLever:
                base.cr.playGame.getPlace().fsm.request(
                    "activity")  # prevent toon from moving
                self.toonPullingLeverInterval = self.getToonPullingLeverInterval(
                    base.localAvatar)
                self.toonPullingLeverInterval.append(
                    Func(self.d_toonJoinRequest))
                self.toonPullingLeverInterval.append(
                    Func(base.cr.playGame.getPlace().fsm.request, 'walk'))
                self.toonPullingLeverInterval.start()
            else:
                self.showMessage(TTLocalizer.PartyOnlyHostLeverPull)

    # FSM utility methods
    def setState(self, newState, timestamp):
        DistributedPartyFireworksActivity.notify.debug(
            "setState( newState=%s, ... )" % newState)
        DistributedPartyActivity.setState(self, newState, timestamp)
        # pass additional parameters only to those states that need it
        if newState == "Active":
            self.activityFSM.request(newState, timestamp)
        else:
            self.activityFSM.request(newState)

    # FSM transition methods
    def startIdle(self):
        DistributedPartyFireworksActivity.notify.debug("startIdle")

    def finishIdle(self):
        DistributedPartyFireworksActivity.notify.debug("finishIdle")

    def startActive(self, showStartTimestamp):
        DistributedPartyFireworksActivity.notify.debug("startActive")
        messenger.send(FireworksStartedEvent)
        # if too much time has passed since the show started, don't bother
        # playing the rocket animation, just hide it
        timeSinceStart = globalClockDelta.localElapsedTime(showStartTimestamp)
        if timeSinceStart > self.rocketActor.getDuration("launch"):
            self.rocketActor.hide()
            self.startShow(self.eventId, self.showStyle, showStartTimestamp)
        else:
            self.rocketActor.play("launch")
            self.rocketParticleSeq = Sequence(Wait(RocketSoundDelay), \
                                                        Func(base.playSfx,self.launchSound), \
                                                        Func(self.rocketExplosionEffect.start), \
                                                        Wait(RocketDirectionDelay), \
                                                        LerpHprInterval(self.rocketActor, 4.0, Vec3(0, 0, -60)), \
                                                        Func(self.rocketExplosionEffect.end), \
                                                        Func(self.rocketActor.hide))
            self.rocketParticleSeq.start()

            # give rocket animation some time to play out before starting the show
            taskMgr.doMethodLater(
                FireworksPostLaunchDelay,
                self.startShow,
                self.taskName("delayedStartShow"),
                extraArgs=[
                    self.eventId, self.showStyle, showStartTimestamp, self.root
                ],
            )

    def finishActive(self):
        self.rocketParticleSeq = None
        DistributedPartyFireworksActivity.notify.debug("finishActive")
        messenger.send(FireworksFinishedEvent)
        taskMgr.remove(self.taskName("delayedStartShow"))
        FireworkShowMixin.disable(self)  # stop the fireworks show

    def startDisabled(self):
        DistributedPartyFireworksActivity.notify.debug("startDisabled")
        if not self.rocketActor.isEmpty():
            self.rocketActor.hide()  # so late comers won't see the rocket

    def finishDisabled(self):
        DistributedPartyFireworksActivity.notify.debug("finishDisabled")

    def handleToonDisabled(self, toonId):
        """
        A toon dropped unexpectedly from the game. Handle it!
        """
        self.notify.warning("handleToonDisabled no implementation yet")
Beispiel #29
0
def loadModel(file, collision=None, animation=None):
    model=None
    if animation:
        collision=file+'/collision'
        anims={}
        dirList=listdir(file+'/animation')
        for fname in dirList:                            
            anims[fname[:-4]]=file+'/animation/'+fname
        #print anims    
        model=Actor(file+'/model', anims)                   
        #default anim
        if 'default' in anims:
            model.loop('default')
        elif 'idle' in animation:
            model.loop('idle')
        else: #some first, random anim
             model.loop(anims.items()[0])
    else:
        model=loader.loadModel(file)
    model.setPythonTag('model_file', file)
    #load shaders
    for geom in model.findAllMatches('**/+GeomNode'):
        if geom.hasTag('light'):
            model.setPythonTag('hasLight', True)
        if geom.hasTag('particle'):
            file='particle/'+geom.getTag('particle')
            if exists(file):
                with open(file) as f:  
                    values=json.load(f)
                p=createEffect(values)                
                model.setPythonTag('particle', p)    
                p.start(parent=model, renderParent=render) 
        if geom.hasTag('cg_shader'):            
            geom.setShader(loader.loadShader("shaders/"+geom.getTag('cg_shader')))
        elif geom.hasTag('glsl_shader'):  
            glsl_shader=geom.getTag('glsl_shader')  
            model.setShader(Shader.load(Shader.SLGLSL, "shaders/{0}_v.glsl".format(glsl_shader),"shaders/{0}_f.glsl".format(glsl_shader)))
        else:
            #geom.setShader(loader.loadShader("shaders/default.cg"))
            model.setShader(Shader.load(Shader.SLGLSL, "shaders/default_v.glsl","shaders/default_f.glsl"), 1)
            print "default shader!"
    #collisions        
    model.setCollideMask(BitMask32.allOff())
    if collision:
        coll=loader.loadModel(collision)
        coll.reparentTo(model)
        coll.find('**/collision').setCollideMask(BitMask32.bit(2))        
        coll.find('**/collision').setPythonTag('object', model)
        if animation:
            model.setPythonTag('actor_files', [file,anims,coll]) 
    else:
        try:
            model.find('**/collision').setCollideMask(BitMask32.bit(2))        
            model.find('**/collision').setPythonTag('object', model)        
        except:
            print "WARNING: Model {0} has no collision geometry!\nGenerating collision sphere...".format(file)
            bounds=model.getBounds()
            radi=bounds.getRadius()
            cent=bounds.getCenter()
            coll_sphere=model.attachNewNode(CollisionNode('collision'))
            coll_sphere.node().addSolid(CollisionSphere(cent[0],cent[1],cent[2], radi)) 
            coll_sphere.setCollideMask(BitMask32.bit(2))        
            coll_sphere.setPythonTag('object', model)
            #coll_sphere.show()
            if animation:
                model.setPythonTag('actor_files', [file,animation,None])
    if ConfigVariableBool('framebuffer-srgb',False).getValue():
        fixSrgbTextures(model)            
    return model
class MakeAToon(StateData.StateData):
    notify = DirectNotifyGlobal.directNotify.newCategory('MakeAToon')

    def __init__(self, parentFSM, avList, doneEvent, index, isPaid):
        self.isPaid = isPaid
        StateData.StateData.__init__(self, doneEvent)
        self.phase = 3
        self.names = ['',
         '',
         '',
         '']
        self.dnastring = None
        self.dna = None
        self.progressing = 0
        self.toonPosition = Point3(-1.62, -3.49, 0)
        self.toonScale = Point3(1, 1, 1)
        self.toonHpr = Point3(180, 0, 0)
        self.leftTime = 1.6
        self.rightTime = 1
        self.slide = 0
        self.nameList = []
        self.warp = 0
        for av in avList:
            if av.position == index:
                self.warp = 1
                self.namelessPotAv = av
            self.nameList.append(av.name)

        self.fsm = ClassicFSM.ClassicFSM('MakeAToon', [State.State('Init', self.enterInit, self.exitInit, ['GenderShop', 'NameShop']),
         State.State('GenderShop', self.enterGenderShop, self.exitGenderShop, ['BodyShop']),
         State.State('BodyShop', self.enterBodyShop, self.exitBodyShop, ['GenderShop', 'ColorShop']),
         State.State('ColorShop', self.enterColorShop, self.exitColorShop, ['BodyShop', 'ClothesShop']),
         State.State('ClothesShop', self.enterClothesShop, self.exitClothesShop, ['ColorShop', 'NameShop']),
         State.State('NameShop', self.enterNameShop, self.exitNameShop, ['ClothesShop']),
         State.State('Done', self.enterDone, self.exitDone, [])], 'Init', 'Done')
        self.parentFSM = parentFSM
        self.parentFSM.getStateNamed('createAvatar').addChild(self.fsm)
        self.gs = GenderShop.GenderShop(self, 'GenderShop-done')
        self.bs = BodyShop.BodyShop('BodyShop-done')
        self.cos = ColorShop.ColorShop('ColorShop-done')
        self.cls = MakeClothesGUI.MakeClothesGUI('ClothesShop-done')
        self.ns = NameShop.NameShop(self, 'NameShop-done', avList, index, self.isPaid)
        self.shop = GENDERSHOP
        self.shopsVisited = []
        if self.warp:
            self.shopsVisited = [GENDERSHOP,
             BODYSHOP,
             COLORSHOP,
             CLOTHESSHOP]
        self.music = None
        self.soundBack = None
        self.fsm.enterInitialState()
        self.hprDelta = -1
        self.dropIval = None
        self.roomSquishIval = None
        self.propSquishIval = None
        self.focusOutIval = None
        self.focusInIval = None
        self.toon = None

    def getToon(self):
        return self.toon

    def enter(self):
        self.notify.debug('Starting Make A Toon.')
        if base.config.GetBool('want-qa-regression', 0):
            self.notify.info('QA-REGRESSION: MAKEATOON: Starting Make A Toon')
        base.camLens.setMinFov(ToontownGlobals.MakeAToonCameraFov/(4./3.))
        base.playMusic(self.music, looping=1, volume=self.musicVolume)
        base.camera.setPosHpr(-5.7, -12.3501, 2.15, -24.8499, 2.73, 0)
        if self.warp:
            if self.toon.style.torso[1] == 's':
                self.toon.gender = 's'
            else:
                self.toon.gender = 'd'
            self.toon.reparentTo(render)
            self.toon.loop('neutral')
            self.toon.setPosHpr(-4.1, -2, 0, 200, 0, 0)
        self.guiTopBar.show()
        self.guiBottomBar.show()
        self.guiCancelButton.show()
        if self.warp:
            self.progressing = 0
            self.guiLastButton.hide()
            self.fsm.request('NameShop')
        else:
            self.fsm.request('GenderShop')

    def exit(self):
        base.camLens.setMinFov(ToontownGlobals.DefaultCameraFov/(4./3.))
        self.guiTopBar.hide()
        self.guiBottomBar.hide()
        self.music.stop()
        self.fsm.request('Done')
        self.room.reparentTo(hidden)

    def load(self):
        gui = loader.loadModel('phase_3/models/gui/tt_m_gui_mat_mainGui')
        gui.flattenMedium()
        guiAcceptUp = gui.find('**/tt_t_gui_mat_okUp')
        guiAcceptUp.flattenStrong()
        guiAcceptDown = gui.find('**/tt_t_gui_mat_okDown')
        guiAcceptDown.flattenStrong()
        guiCancelUp = gui.find('**/tt_t_gui_mat_closeUp')
        guiCancelUp.flattenStrong()
        guiCancelDown = gui.find('**/tt_t_gui_mat_closeDown')
        guiCancelDown.flattenStrong()
        guiNextUp = gui.find('**/tt_t_gui_mat_nextUp')
        guiNextUp.flattenStrong()
        guiNextDown = gui.find('**/tt_t_gui_mat_nextDown')
        guiNextDown.flattenStrong()
        guiNextDisabled = gui.find('**/tt_t_gui_mat_nextDisabled')
        guiNextDisabled.flattenStrong()
        skipTutorialUp = gui.find('**/tt_t_gui_mat_skipUp')
        skipTutorialUp.flattenStrong()
        skipTutorialDown = gui.find('**/tt_t_gui_mat_skipDown')
        skipTutorialDown.flattenStrong()
        rotateUp = gui.find('**/tt_t_gui_mat_arrowRotateUp')
        rotateUp.flattenStrong()
        rotateDown = gui.find('**/tt_t_gui_mat_arrowRotateDown')
        rotateDown.flattenStrong()
        self.guiTopBar = DirectFrame(relief=None, text=TTLocalizer.CreateYourToon, text_font=ToontownGlobals.getSignFont(), text_fg=(0.0, 0.65, 0.35, 1), text_scale=0.18, text_pos=(0, -0.03), pos=(0, 0, 0.86))
        self.guiTopBar.hide()
        self.guiBottomBar = DirectFrame(relief=None, image_scale=(1.25, 1, 1), pos=(0.01, 0, -0.86))
        self.guiBottomBar.hide()
        self.guiCheckButton = DirectButton(parent=self.guiBottomBar, relief=None, image=(guiAcceptUp,
         guiAcceptDown,
         guiAcceptUp,
         guiAcceptDown), image_scale=halfButtonScale, image1_scale=halfButtonHoverScale, image2_scale=halfButtonHoverScale, pos=(1.165, 0, -0.018), command=self.__handleNext, text=('', TTLocalizer.MakeAToonDone, TTLocalizer.MakeAToonDone), text_font=ToontownGlobals.getInterfaceFont(), text_scale=0.08, text_align=TextNode.ARight, text_pos=(0.075, 0.13), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1))
        self.guiCheckButton.setPos(-0.13, 0, 0.13)
        self.guiCheckButton.reparentTo(base.a2dBottomRight)
        self.guiCheckButton.hide()
        self.guiCancelButton = DirectButton(parent=self.guiBottomBar, relief=None, image=(guiCancelUp,
         guiCancelDown,
         guiCancelUp,
         guiCancelDown), image_scale=halfButtonScale, image1_scale=halfButtonHoverScale, image2_scale=halfButtonHoverScale, pos=(-1.179, 0, -0.011), command=self.__handleCancel, text=('', TTLocalizer.MakeAToonCancel, TTLocalizer.MakeAToonCancel), text_font=ToontownGlobals.getInterfaceFont(), text_scale=TTLocalizer.MATguiCancelButton, text_pos=(0, 0.115), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1))
        self.guiCancelButton.setPos(0.13,0,0.13)
        self.guiCancelButton.reparentTo(base.a2dBottomLeft)
        self.guiCancelButton.hide()
        self.guiNextButton = DirectButton(parent=self.guiBottomBar, relief=None, image=(guiNextUp,
         guiNextDown,
         guiNextUp,
         guiNextDisabled), image_scale=(0.3, 0.3, 0.3), image1_scale=(0.35, 0.35, 0.35), image2_scale=(0.35, 0.35, 0.35), pos=(1.165, 0, -0.018), command=self.__handleNext, text=('',
         TTLocalizer.MakeAToonNext,
         TTLocalizer.MakeAToonNext,
         ''), text_font=ToontownGlobals.getInterfaceFont(), text_scale=TTLocalizer.MATguiNextButton, text_pos=(0, 0.115), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1))
        self.guiNextButton.setPos(-0.13, 0, 0.13)
        self.guiNextButton.reparentTo(base.a2dBottomRight)
        self.guiNextButton.hide()
        self.guiLastButton = DirectButton(parent=self.guiBottomBar, relief=None, image=(guiNextUp,
         guiNextDown,
         guiNextUp,
         guiNextDown), image3_color=Vec4(0.5, 0.5, 0.5, 0.75), image_scale=(-0.3, 0.3, 0.3), image1_scale=(-0.35, 0.35, 0.35), image2_scale=(-0.35, 0.35, 0.35), pos=(0.825, 0, -0.018), command=self.__handleLast, text=('',
         TTLocalizer.MakeAToonLast,
         TTLocalizer.MakeAToonLast,
         ''), text_font=ToontownGlobals.getInterfaceFont(), text_scale=0.08, text_pos=(0, 0.115), text_fg=(1, 1, 1, 1), text_shadow=(0, 0, 0, 1))
        self.guiLastButton.setPos(-0.37, 0, 0.13)
        self.guiLastButton.reparentTo(base.a2dBottomRight)
        self.guiLastButton.hide()
        self.rotateLeftButton = DirectButton(parent=self.guiBottomBar, relief=None, image=(rotateUp,
         rotateDown,
         rotateUp,
         rotateDown), image_scale=(-0.4, 0.4, 0.4), image1_scale=(-0.5, 0.5, 0.5), image2_scale=(-0.5, 0.5, 0.5), pos=(-0.355, 0, 0.36))
        self.rotateLeftButton.flattenMedium()
        self.rotateLeftButton.reparentTo(base.a2dBottomCenter)
        self.rotateLeftButton.hide()
        self.rotateLeftButton.bind(DGG.B1PRESS, self.rotateToonLeft)
        self.rotateLeftButton.bind(DGG.B1RELEASE, self.stopToonRotateLeftTask)
        self.rotateRightButton = DirectButton(parent=self.guiBottomBar, relief=None, image=(rotateUp,
         rotateDown,
         rotateUp,
         rotateDown), image_scale=(0.4, 0.4, 0.4), image1_scale=(0.5, 0.5, 0.5), image2_scale=(0.5, 0.5, 0.5), pos=(0.355, 0, 0.36))
        self.rotateRightButton.flattenStrong()
        self.rotateRightButton.reparentTo(base.a2dBottomCenter)
        self.rotateRightButton.hide()
        self.rotateRightButton.bind(DGG.B1PRESS, self.rotateToonRight)
        self.rotateRightButton.bind(DGG.B1RELEASE, self.stopToonRotateRightTask)
        gui.removeNode()
        self.roomDropActor = Actor()
        self.roomDropActor.loadModel('phase_3/models/makeatoon/roomAnim_model')
        self.roomDropActor.loadAnims({'drop': 'phase_3/models/makeatoon/roomAnim_roomDrop'})
        self.roomDropActor.reparentTo(render)
        self.dropJoint = self.roomDropActor.find('**/droppingJoint')
        self.roomSquishActor = Actor()
        self.roomSquishActor.loadModel('phase_3/models/makeatoon/roomAnim_model')
        self.roomSquishActor.loadAnims({'squish': 'phase_3/models/makeatoon/roomAnim_roomSquish'})
        self.roomSquishActor.reparentTo(render)
        self.squishJoint = self.roomSquishActor.find('**/scalingJoint')
        self.propSquishActor = Actor()
        self.propSquishActor.loadModel('phase_3/models/makeatoon/roomAnim_model')
        self.propSquishActor.loadAnims({'propSquish': 'phase_3/models/makeatoon/roomAnim_propSquish'})
        self.propSquishActor.reparentTo(render)
        self.propSquishActor.pose('propSquish', 0)
        self.propJoint = self.propSquishActor.find('**/propJoint')
        self.spotlightActor = Actor()
        self.spotlightActor.loadModel('phase_3/models/makeatoon/roomAnim_model')
        self.spotlightActor.loadAnims({'spotlightShake': 'phase_3/models/makeatoon/roomAnim_spotlightShake'})
        self.spotlightActor.reparentTo(render)
        self.spotlightJoint = self.spotlightActor.find('**/spotlightJoint')
        ee = DirectFrame(pos=(-1, 1, 1), frameSize=(-.01, 0.01, -.01, 0.01), frameColor=(0, 0, 0, 0.05), state='normal')
        ee.bind(DGG.B1PRESS, lambda x, ee = ee: self.toggleSlide())
        self.eee = ee
        self.room = loader.loadModel('phase_3/models/makeatoon/tt_m_ara_mat_room')
        self.room.flattenMedium()
        self.genderWalls = self.room.find('**/genderWalls')
        self.genderWalls.flattenStrong()
        self.genderProps = self.room.find('**/genderProps')
        self.genderProps.flattenStrong()
        self.bodyWalls = self.room.find('**/bodyWalls')
        self.bodyWalls.flattenStrong()
        self.bodyProps = self.room.find('**/bodyProps')
        self.bodyProps.flattenStrong()
        self.colorWalls = self.room.find('**/colorWalls')
        self.colorWalls.flattenStrong()
        self.colorProps = self.room.find('**/colorProps')
        self.colorProps.flattenStrong()
        self.clothesWalls = self.room.find('**/clothWalls')
        self.clothesWalls.flattenMedium()
        self.clothesProps = self.room.find('**/clothProps')
        self.clothesProps.flattenMedium()
        self.nameWalls = self.room.find('**/nameWalls')
        self.nameWalls.flattenStrong()
        self.nameProps = self.room.find('**/nameProps')
        self.nameProps.flattenStrong()
        self.background = self.room.find('**/background')
        self.background.flattenStrong()
        self.background.reparentTo(render)
        self.floor = self.room.find('**/floor')
        self.floor.flattenStrong()
        self.floor.reparentTo(render)
        self.spotlight = self.room.find('**/spotlight')
        self.spotlight.reparentTo(self.spotlightJoint)
        self.spotlight.setColor(1, 1, 1, 0.3)
        self.spotlight.setPos(1.18, -1.27, 0.41)
        self.spotlight.setScale(2.6)
        self.spotlight.setHpr(0, 0, 0)
        smokeSeqNode = SequenceNode('smoke')
        smokeModel = loader.loadModel('phase_3/models/makeatoon/tt_m_ara_mat_smoke')
        smokeFrameList = list(smokeModel.findAllMatches('**/smoke_*'))
        smokeFrameList.reverse()
        for smokeFrame in smokeFrameList:
            smokeSeqNode.addChild(smokeFrame.node())

        smokeSeqNode.setFrameRate(12)
        self.smoke = render.attachNewNode(smokeSeqNode)
        self.smoke.setScale(1, 1, 0.75)
        self.smoke.hide()
        if self.warp:
            self.dna = ToonDNA.ToonDNA()
            self.dna.makeFromNetString(self.namelessPotAv.dna)
            self.toon = Toon.Toon()
            self.toon.setDNA(self.dna)
            self.toon.useLOD(1000)
            self.toon.setNameVisible(0)
            self.toon.startBlink()
            self.toon.startLookAround()
        self.gs.load()
        self.bs.load()
        self.cos.load()
        self.cls.load()
        self.ns.load()
        self.music = base.loadMusic('phase_3/audio/bgm/create_a_toon.ogg')
        self.musicVolume = base.config.GetFloat('makeatoon-music-volume', 1)
        self.sfxVolume = base.config.GetFloat('makeatoon-sfx-volume', 1)
        self.soundBack = base.loadSfx('phase_3/audio/sfx/GUI_create_toon_back.ogg')
        self.crashSounds = map(base.loadSfx, ['phase_3/audio/sfx/tt_s_ara_mat_crash_boing.ogg',
                                              'phase_3/audio/sfx/tt_s_ara_mat_crash_glassBoing.ogg',
                                              'phase_3/audio/sfx/tt_s_ara_mat_crash_wood.ogg',
                                              'phase_3/audio/sfx/tt_s_ara_mat_crash_woodBoing.ogg',
                                              'phase_3/audio/sfx/tt_s_ara_mat_crash_woodGlass.ogg'])

    def unload(self):
        self.exit()
        if self.toon:
            self.toon.stopBlink()
            self.toon.stopLookAroundNow()
        self.gs.unload()
        self.bs.unload()
        self.cos.unload()
        self.cls.unload()
        self.ns.unload()
        del self.gs
        del self.bs
        del self.cos
        del self.cls
        del self.ns
        self.guiTopBar.destroy()
        self.guiBottomBar.destroy()
        self.guiCancelButton.destroy()
        self.guiCheckButton.destroy()
        self.eee.destroy()
        self.guiNextButton.destroy()
        self.guiLastButton.destroy()
        self.rotateLeftButton.destroy()
        self.rotateRightButton.destroy()
        del self.guiTopBar
        del self.guiBottomBar
        del self.guiCancelButton
        del self.guiCheckButton
        del self.eee
        del self.guiNextButton
        del self.guiLastButton
        del self.rotateLeftButton
        del self.rotateRightButton
        del self.names
        del self.dnastring
        del self.nameList
        del self.music
        del self.soundBack
        del self.dna
        if self.toon:
            self.toon.delete()
        del self.toon
        self.cleanupDropIval()
        self.cleanupRoomSquishIval()
        self.cleanupPropSquishIval()
        self.cleanupFocusInIval()
        self.cleanupFocusOutIval()
        self.room.removeNode()
        del self.room
        self.genderWalls.removeNode()
        self.genderProps.removeNode()
        del self.genderWalls
        del self.genderProps
        self.bodyWalls.removeNode()
        self.bodyProps.removeNode()
        del self.bodyWalls
        del self.bodyProps
        self.colorWalls.removeNode()
        self.colorProps.removeNode()
        del self.colorWalls
        del self.colorProps
        self.clothesWalls.removeNode()
        self.clothesProps.removeNode()
        del self.clothesWalls
        del self.clothesProps
        self.nameWalls.removeNode()
        self.nameProps.removeNode()
        del self.nameWalls
        del self.nameProps
        self.background.removeNode()
        del self.background
        self.floor.removeNode()
        del self.floor
        self.spotlight.removeNode()
        del self.spotlight
        self.smoke.removeNode()
        del self.smoke
        while len(self.crashSounds):
            del self.crashSounds[0]

        self.parentFSM.getStateNamed('createAvatar').removeChild(self.fsm)
        del self.parentFSM
        del self.fsm
        self.ignoreAll()
        loader.unloadModel('phase_3/models/gui/create_a_toon_gui')
        loader.unloadModel('phase_3/models/gui/create_a_toon')
        ModelPool.garbageCollect()
        TexturePool.garbageCollect()

    def getDNA(self):
        return self.dnastring

    def __handleBodyShop(self):
        self.fsm.request('BodyShop')

    def __handleClothesShop(self):
        self.fsm.request('ClothesShop')

    def __handleColorShop(self):
        self.fsm.request('ColorShop')

    def __handleNameShop(self):
        self.fsm.request('NameShop')

    def __handleCancel(self):
        self.doneStatus = 'cancel'
        self.shopsVisited = []
        base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))

    def toggleSlide(self):
        self.slide = 1 - self.slide

    def goToNextShop(self):
        self.progressing = 1
        if self.shop == GENDERSHOP:
            self.fsm.request('BodyShop')
        elif self.shop == BODYSHOP:
            self.fsm.request('ColorShop')
        elif self.shop == COLORSHOP:
            self.fsm.request('ClothesShop')
        else:
            self.fsm.request('NameShop')

    def goToLastShop(self):
        self.progressing = 0
        if self.shop == BODYSHOP:
            self.fsm.request('GenderShop')
        elif self.shop == COLORSHOP:
            self.fsm.request('BodyShop')
        elif self.shop == CLOTHESSHOP:
            self.fsm.request('ColorShop')
        else:
            self.fsm.request('ClothesShop')

    def charSez(self, char, statement, dialogue = None):
        import pdb
        pdb.set_trace()
        char.setChatAbsolute(statement, CFSpeech, dialogue)

    def enterInit(self):
        pass

    def exitInit(self):
        pass

    def enterGenderShop(self):
        self.shop = GENDERSHOP
        if GENDERSHOP not in self.shopsVisited:
            self.shopsVisited.append(GENDERSHOP)
            self.genderWalls.reparentTo(self.squishJoint)
            self.genderProps.reparentTo(self.propJoint)
            self.roomSquishActor.pose('squish', 0)
            self.guiNextButton['state'] = DGG.DISABLED
        else:
            self.dropRoom(self.genderWalls, self.genderProps)
        self.guiTopBar['text'] = TTLocalizer.CreateYourToonTitle
        self.guiTopBar['text_fg'] = (1, 0.92, 0.2, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterGenderShop
        base.transitions.fadeIn()
        self.accept('GenderShop-done', self.__handleGenderShopDone)
        self.gs.enter()
        self.guiNextButton.show()
        self.gs.showButtons()
        self.rotateLeftButton.hide()
        self.rotateRightButton.hide()

    def exitGenderShop(self):
        self.squishRoom(self.genderWalls)
        self.squishProp(self.genderProps)
        self.gs.exit()
        self.ignore('GenderShop-done')

    def __handleGenderShopDone(self):
        self.guiNextButton.hide()
        self.gs.hideButtons()
        self.goToNextShop()

    def bodyShopOpening(self):
        self.bs.showButtons()
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterBodyShop(self):
        self.toon.show()
        self.shop = BODYSHOP
        self.guiTopBar['text'] = TTLocalizer.ShapeYourToonTitle
        self.guiTopBar['text_fg'] = (0.0, 0.98, 0.5, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterBodyShop
        self.accept('BodyShop-done', self.__handleBodyShopDone)
        self.dropRoom(self.bodyWalls, self.bodyProps)
        self.bs.enter(self.toon, self.shopsVisited)
        if BODYSHOP not in self.shopsVisited:
            self.shopsVisited.append(BODYSHOP)
        self.bodyShopOpening()

    def exitBodyShop(self):
        self.squishRoom(self.bodyWalls)
        self.squishProp(self.bodyProps)
        self.bs.exit()
        self.ignore('BodyShop-done')

    def __handleBodyShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.bs.doneStatus == 'next':
            self.bs.hideButtons()
            self.goToNextShop()
        else:
            self.bs.hideButtons()
            self.goToLastShop()

    def colorShopOpening(self):
        self.cos.showButtons()
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterColorShop(self):
        self.shop = COLORSHOP
        self.guiTopBar['text'] = TTLocalizer.PaintYourToonTitle
        self.guiTopBar['text_fg'] = (0, 1, 1, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterColorShop
        self.accept('ColorShop-done', self.__handleColorShopDone)
        self.dropRoom(self.colorWalls, self.colorProps)
        self.toon.setPos(self.toonPosition)
        self.colorShopOpening()
        self.cos.enter(self.toon, self.shopsVisited)
        if COLORSHOP not in self.shopsVisited:
            self.shopsVisited.append(COLORSHOP)

    def exitColorShop(self):
        self.squishRoom(self.colorWalls)
        self.squishProp(self.colorProps)
        self.cos.exit()
        self.ignore('ColorShop-done')

    def __handleColorShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.cos.doneStatus == 'next':
            self.cos.hideButtons()
            self.goToNextShop()
        else:
            self.cos.hideButtons()
            self.goToLastShop()

    def clothesShopOpening(self):
        self.guiNextButton.show()
        self.guiLastButton.show()
        self.cls.showButtons()
        self.rotateLeftButton.show()
        self.rotateRightButton.show()

    def enterClothesShop(self):
        self.shop = CLOTHESSHOP
        self.guiTopBar['text'] = TTLocalizer.PickClothesTitle
        self.guiTopBar['text_fg'] = (1, 0.92, 0.2, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterClothesShop
        self.accept('ClothesShop-done', self.__handleClothesShopDone)
        self.dropRoom(self.clothesWalls, self.clothesProps)
        self.toon.setScale(self.toonScale)
        self.toon.setPos(self.toonPosition)
        if not self.progressing:
            self.toon.setHpr(self.toonHpr)
        self.clothesShopOpening()
        self.cls.enter(self.toon)
        if CLOTHESSHOP not in self.shopsVisited:
            self.shopsVisited.append(CLOTHESSHOP)

    def exitClothesShop(self):
        self.squishRoom(self.clothesWalls)
        self.squishProp(self.clothesProps)
        self.cls.exit()
        self.ignore('ClothesShop-done')

    def __handleClothesShopDone(self):
        self.guiNextButton.hide()
        self.guiLastButton.hide()
        if self.cls.doneStatus == 'next':
            self.cls.hideButtons()
            self.goToNextShop()
        else:
            self.cls.hideButtons()
            self.goToLastShop()

    def nameShopOpening(self, task):
        self.guiCheckButton.show()
        self.guiLastButton.show()
        if self.warp:
            self.guiLastButton.hide()
        if NAMESHOP not in self.shopsVisited:
            self.shopsVisited.append(NAMESHOP)
        return Task.done

    def enterNameShop(self):
        self.shop = NAMESHOP
        self.guiTopBar['text'] = TTLocalizer.NameToonTitle
        self.guiTopBar['text_fg'] = (0.0, 0.98, 0.5, 1)
        self.guiTopBar['text_scale'] = TTLocalizer.MATenterNameShop
        self.accept('NameShop-done', self.__handleNameShopDone)
        self.dropRoom(self.nameWalls, self.nameProps)
        self.spotlight.setPos(2, -1.95, 0.41)
        self.toon.setPos(Point3(1.5, -4, 0))
        self.toon.setH(120)
        self.rotateLeftButton.hide()
        self.rotateRightButton.hide()
        if self.progressing:
            waittime = self.leftTime
        else:
            waittime = 0.2
        self.ns.enter(self.toon, self.nameList, self.warp)
        taskMgr.doMethodLater(waittime, self.nameShopOpening, 'nameShopOpeningTask')

    def exitNameShop(self):
        self.squishRoom(self.nameWalls)
        self.squishProp(self.nameProps)
        self.spotlight.setPos(1.18, -1.27, 0.41)
        self.ns.exit()
        self.ignore('NameShop-done')
        taskMgr.remove('nameShopOpeningTask')

    def rejectName(self):
        self.ns.rejectName(TTLocalizer.RejectNameText)

    def __handleNameShopDone(self):
        if base.config.GetBool('want-qa-regression', 0):
            self.notify.info('QA-REGRESSION: MAKEATOON: Creating A Toon')
        self.guiLastButton.hide()
        self.guiCheckButton.hide()
        if self.ns.getDoneStatus() == 'last':
            self.ns.hideAll()
            self.goToLastShop()
        elif self.ns.getDoneStatus() == 'paynow':
            self.doneStatus = 'paynow'
            base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))
        else:
            self.doneStatus = 'created'
            base.transitions.fadeOut(finishIval=EventInterval(self.doneEvent))

    def __handleNext(self):
        messenger.send('next')

    def __handleLast(self):
        messenger.send('last')

    def __handleSkipTutorial(self):
        messenger.send('skipTutorial')

    def enterDone(self):
        pass

    def exitDone(self):
        pass

    def create3DGui(self):
        self.proto = loader.loadModel('phase_3/models/makeatoon/tt_m_ara_mat_protoMachine')
        self.proto.setScale(0.2)
        self.proto.reparentTo(render)

    def setup3DPicker(self):
        self.accept('mouse1', self.mouseDown)
        self.accept('mouse1-up', self.mouseUp)
        self.pickerQueue = CollisionHandlerQueue()
        self.pickerTrav = CollisionTraverser('MousePickerTraverser')
        self.pickerTrav.setRespectPrevTransform(True)
        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = base.camera.attachNewNode(self.pickerNode)
        self.pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.pickerTrav.addCollider(self.pickerNP, self.pickerQueue)

    def mouseDown(self):
        self.notify.debug('Mouse 1 Down')
        mpos = base.mouseWatcherNode.getMouse()
        self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
        self.pickerTrav.traverse(render)
        if self.pickerQueue.getNumEntries() > 0:
            self.pickerQueue.sortEntries()
            self.pickedObj = self.pickerQueue.getEntry(0).getIntoNodePath()

    def mouseUp(self):
        self.notify.debug('Mouse 1 Up')

    def squishRoom(self, room):
        if self.roomSquishIval and self.roomSquishIval.isPlaying():
            self.roomSquishIval.finish()
        squishDuration = self.roomSquishActor.getDuration('squish')
        self.roomSquishIval = Sequence(Func(self.roomSquishActor.play, 'squish'), Wait(squishDuration), Func(room.hide))
        self.roomSquishIval.start()

    def squishProp(self, prop):
        if not prop.isEmpty():
            if self.propSquishIval and self.propSquishIval.isPlaying():
                self.propSquishIval.finish()
            squishDuration = self.propSquishActor.getDuration('propSquish')
            self.propSquishIval = Sequence(Func(self.propSquishActor.play, 'propSquish'), Wait(squishDuration), Func(prop.hide))
            self.propSquishIval.start()

    def dropRoom(self, walls, props):

        def propReparentTo(props):
            if not props.isEmpty():
                props.reparentTo(self.propJoint)

        if self.dropIval and self.dropIval.isPlaying():
            self.dropIval.finish()
        walls.reparentTo(self.dropJoint)
        walls.show()
        if not props.isEmpty():
            props.reparentTo(self.dropJoint)
            props.show()
        dropDuration = self.roomDropActor.getDuration('drop')
        self.dropIval = Parallel(Sequence(Func(self.roomDropActor.play, 'drop'), Wait(dropDuration), Func(walls.reparentTo, self.squishJoint), Func(propReparentTo, props), Func(self.propSquishActor.pose, 'propSquish', 0), Func(self.roomSquishActor.pose, 'squish', 0)), Sequence(Wait(0.25), Func(self.smoke.show), Func(self.smoke.node().play), LerpColorScaleInterval(self.smoke, 0.5, Vec4(1, 1, 1, 0), startColorScale=Vec4(1, 1, 1, 1)), Func(self.smoke.hide)), Func(self.spotlightActor.play, 'spotlightShake'), Func(self.playRandomCrashSound))
        self.dropIval.start()

    def startFocusOutIval(self):
        if self.focusInIval.isPlaying():
            self.focusInIval.pause()
        if not self.focusOutIval.isPlaying():
            self.focusOutIval = LerpScaleInterval(self.spotlight, 0.25, self.spotlightFinalScale)
            self.focusOutIval.start()

    def startFocusInIval(self):
        if self.focusOutIval.isPlaying():
            self.focusOutIval.pause()
        if not self.focusInIval.isPlaying():
            self.focusInIval = LerpScaleInterval(self.spotlight, 0.25, self.spotlightOriginalScale)
            self.focusInIval.start()

    def cleanupFocusOutIval(self):
        if self.focusOutIval:
            self.focusOutIval.finish()
            del self.focusOutIval

    def cleanupFocusInIval(self):
        if self.focusInIval:
            self.focusInIval.finish()
            del self.focusInIval

    def cleanupDropIval(self):
        if self.dropIval:
            self.dropIval.finish()
            del self.dropIval

    def cleanupRoomSquishIval(self):
        if self.roomSquishIval:
            self.roomSquishIval.finish()
            del self.roomSquishIval

    def cleanupPropSquishIval(self):
        if self.propSquishIval:
            self.propSquishIval.finish()
            del self.propSquishIval

    def setToon(self, toon):
        self.toon = toon

    def setNextButtonState(self, state):
        self.guiNextButton['state'] = state

    def playRandomCrashSound(self):
        index = random.randint(0, len(self.crashSounds) - 1)
        base.playSfx(self.crashSounds[index], volume=self.sfxVolume)

    def rotateToonLeft(self, event):
        taskMgr.add(self.rotateToonLeftTask, 'rotateToonLeftTask')

    def rotateToonLeftTask(self, task):
        self.toon.setH(self.toon.getH() + self.hprDelta)
        return task.cont

    def stopToonRotateLeftTask(self, event):
        taskMgr.remove('rotateToonLeftTask')

    def rotateToonRight(self, event):
        taskMgr.add(self.rotateToonRightTask, 'rotateToonRightTask')

    def rotateToonRightTask(self, task):
        self.toon.setH(self.toon.getH() - self.hprDelta)
        return task.cont

    def stopToonRotateRightTask(self, event):
        taskMgr.remove('rotateToonRightTask')
Beispiel #31
0
class Grenade (Projectile):
    def __init__(self, pos, hpr, color, walker_v, name=None):
        super(Grenade, self).__init__(name)
        self.pos = Vec3(*pos)
        self.hpr = hpr
        self.move_divisor = 9
        self.color = color
        self.forward_m = .25
        self.walker_v = walker_v

    def create_node(self):
        self.model = Actor('grenade.egg')
        self.shell = self.model.find('**/shell')
        self.shell.set_color(*self.color)
        self.inner_top = self.model.find('**/inner_top')
        self.inner_bottom = self.model.find('**/inner_bottom')
        self.inner_top.set_color(*random.choice(ENGINE_COLORS))
        self.inner_bottom.set_color(*random.choice(ENGINE_COLORS))
        self.model.set_scale(GRENADE_SCALE)
        self.model.set_hpr(0,0,0)
        self.spin_bone = self.model.controlJoint(None, 'modelRoot', 'grenade_bone')
        return self.model

    def create_solid(self):
        node = BulletRigidBodyNode(self.name)
        node.set_angular_damping(.9)
        node_shape = BulletSphereShape(.08)
        node.add_shape(node_shape)
        node.set_mass(.5)
        return node

    def attached(self):
        self.node.set_pos(self.pos)
        self.node.set_hpr(self.hpr)
        self.world.register_updater(self)
        self.world.register_collider(self)
        self.solid.setIntoCollideMask(NO_COLLISION_BITS)
        self.solid.set_gravity(DEFAULT_GRAVITY*4.5)
        grenade_iv = render.get_relative_vector(self.node, Vec3(0,8.5,13.5))
        grenade_iv += (self.walker_v * 1/2)
        self.solid.apply_impulse(grenade_iv, Point3(*self.pos))

    def decompose(self):
        clist = list(self.color)
        clist.extend([1])
        expl_colors = [clist]
        expl_colors.extend(ENGINE_COLORS)
        expl_pos = self.node.get_pos(self.world.render)
        for c in expl_colors:
            self.world.attach(TriangleExplosion(expl_pos, 1, size=.1, color=c, lifetime=40))
        self.world.garbage.add(self)

    def update(self, dt):
        self.inner_top.set_color(*random.choice(ENGINE_COLORS))
        self.inner_bottom.set_color(*random.choice(ENGINE_COLORS))
        result = self.world.physics.contact_test(self.solid)
        self.spin_bone.set_hpr(self.spin_bone, 0,0,10)
        contacts = result.getContacts()
        if len(contacts) > 0:
            hit_node = contacts[0].get_node1().get_name()
            if hit_node.endswith("_walker_cap"):
                return
            clist = list(self.color)
            clist.extend([1])
            expl_colors = [clist]
            expl_colors.extend(ENGINE_COLORS)
            expl_pos = self.node.get_pos(self.world.render)
            for c in expl_colors:
                self.world.attach(TriangleExplosion(expl_pos, 3, size=.1, color=c, lifetime=80,))
            self.world.do_explosion(self.node, 3, 100)
            self.world.garbage.add(self)
class SnapshotRenderer:
    def __init__(self, dnaString):
        self.dnaString = dnaString
        loadModels()
        compileGlobalAnimList()
        self.makeFromNetString(dnaString)
        self.toon = Actor()
        self.generateToon()
        self.renderSnapshot()

    def makeFromNetString(self, string):
        dg = PyDatagram(string)
        dgi = PyDatagramIterator(dg)
        self.type = dgi.getFixedString(1)
        if self.type == "t":
            headIndex = dgi.getUint8()
            torsoIndex = dgi.getUint8()
            legsIndex = dgi.getUint8()
            self.head = toonHeadTypes[headIndex]
            self.torso = toonTorsoTypes[torsoIndex]
            self.legs = toonLegTypes[legsIndex]
            gender = dgi.getUint8()
            if gender == 1:
                self.gender = "m"
            else:
                self.gender = "f"
            self.topTex = dgi.getUint8()
            self.topTexColor = dgi.getUint8()
            self.sleeveTex = dgi.getUint8()
            self.sleeveTexColor = dgi.getUint8()
            self.botTex = dgi.getUint8()
            self.botTexColor = dgi.getUint8()
            self.armColor = dgi.getUint8()
            self.gloveColor = dgi.getUint8()
            self.legColor = dgi.getUint8()
            self.headColor = dgi.getUint8()
        else:
            notify.error("unknown avatar type: ", self.type)

    def getAnimal(self):
        if self.head[0] == "d":
            return "dog"
        elif self.head[0] == "c":
            return "cat"
        elif self.head[0] == "m":
            return "mouse"
        elif self.head[0] == "h":
            return "horse"
        elif self.head[0] == "r":
            return "rabbit"
        elif self.head[0] == "f":
            return "duck"
        elif self.head[0] == "p":
            return "monkey"
        elif self.head[0] == "b":
            return "bear"
        elif self.head[0] == "s":
            return "pig"
        else:
            notify.error("unknown headStyle: ", self.head[0])

    def getArmColor(self):
        try:
            return allColorsList[self.armColor]
        except:
            return allColorsList[0]

    def getLegColor(self):
        try:
            return allColorsList[self.legColor]
        except:
            return allColorsList[0]

    def getHeadColor(self):
        try:
            return allColorsList[self.headColor]
        except:
            return allColorsList[0]

    def getGloveColor(self):
        try:
            return allColorsList[self.gloveColor]
        except:
            return allColorsList[0]

    def getGender(self):
        return self.gender

    def generateToon(self):
        self.setLODs()
        self.generateToonLegs()
        self.generateToonHead(1, ("1000", "500", "250"))
        self.generateToonTorso()
        self.generateToonColor()
        self.parentToonParts()
        # self.rescaleToon()
        # self.resetHeight()
        # self.setupToonNodes()
        self.toon.reparentTo(render)
        self.toon.setPos(0, 5, -3)
        self.toon.setH(180)
        self.toon.getPart("head", "1000").setR(10)
        self.toon.pose("neutral", 0)

    def generateToonLegs(self, copy=1):
        global Preloaded
        legStyle = self.legs
        filePrefix = LegDict.get(legStyle)
        if filePrefix is None:
            print ("unknown leg style: %s" % legStyle)
        self.toon.loadModel(Preloaded[filePrefix + "-1000"], "legs", "1000", True)
        self.toon.loadModel(Preloaded[filePrefix + "-500"], "legs", "500", True)
        self.toon.loadModel(Preloaded[filePrefix + "-250"], "legs", "250", True)
        if not copy:
            self.toon.showPart("legs", "1000")
            self.toon.showPart("legs", "500")
            self.toon.showPart("legs", "250")
        self.toon.loadAnims(LegsAnimDict[legStyle], "legs", "1000")
        self.toon.loadAnims(LegsAnimDict[legStyle], "legs", "500")
        self.toon.loadAnims(LegsAnimDict[legStyle], "legs", "250")
        self.toon.findAllMatches("**/boots_short").stash()
        self.toon.findAllMatches("**/boots_long").stash()
        self.toon.findAllMatches("**/shoes").stash()
        return

    def generateToonTorso(self, copy=1, genClothes=1):
        global Preloaded
        torsoStyle = self.torso
        filePrefix = TorsoDict.get(torsoStyle)
        if filePrefix is None:
            self.notify.error("unknown torso style: %s" % torsoStyle)
        self.toon.loadModel(Preloaded[filePrefix + "-1000"], "torso", "1000", True)
        if len(torsoStyle) == 1:
            self.toon.loadModel(Preloaded[filePrefix + "-1000"], "torso", "500", True)
            self.toon.loadModel(Preloaded[filePrefix + "-1000"], "torso", "250", True)
        else:
            self.toon.loadModel(Preloaded[filePrefix + "-500"], "torso", "500", True)
            self.toon.loadModel(Preloaded[filePrefix + "-250"], "torso", "250", True)
        if not copy:
            self.toon.showPart("torso", "1000")
            self.toon.showPart("torso", "500")
            self.toon.showPart("torso", "250")
        self.toon.loadAnims(TorsoAnimDict[torsoStyle], "torso", "1000")
        self.toon.loadAnims(TorsoAnimDict[torsoStyle], "torso", "500")
        self.toon.loadAnims(TorsoAnimDict[torsoStyle], "torso", "250")
        if genClothes == 1 and not len(torsoStyle) == 1:
            self.generateToonClothes()
        return

    def generateToonClothes(self, fromNet=0):
        swappedTorso = 0
        if self.toon.hasLOD():
            if self.getGender() == "f" and fromNet == 0:
                try:
                    bottomPair = GirlBottoms[self.botTex]
                except:
                    bottomPair = GirlBottoms[0]
            try:
                texName = Shirts[self.topTex]
            except:
                texName = Shirts[0]

            shirtTex = loader.loadTexture(texName, okMissing=True)
            if shirtTex is None:
                shirtTex = loader.loadTexture(Shirts[0])
            shirtTex.setMinfilter(Texture.FTLinearMipmapLinear)
            shirtTex.setMagfilter(Texture.FTLinear)
            try:
                shirtColor = ClothesColors[self.topTexColor]
            except:
                shirtColor = ClothesColors[0]

            try:
                texName = Sleeves[self.sleeveTex]
            except:
                texName = Sleeves[0]

            sleeveTex = loader.loadTexture(texName, okMissing=True)
            if sleeveTex is None:
                self.sendLogSuspiciousEvent("failed to load texture %s" % texName)
                sleeveTex = loader.loadTexture(Sleeves[0])
            sleeveTex.setMinfilter(Texture.FTLinearMipmapLinear)
            sleeveTex.setMagfilter(Texture.FTLinear)
            try:
                sleeveColor = ClothesColors[self.sleeveTexColor]
            except:
                sleeveColor = ClothesColors[0]

            if self.getGender() == "m":
                try:
                    texName = BoyShorts[self.botTex]
                except:
                    texName = BoyShorts[0]

            else:
                try:
                    texName = GirlBottoms[self.botTex][0]
                except:
                    texName = GirlBottoms[0][0]

            bottomTex = loader.loadTexture(texName, okMissing=True)
            if bottomTex is None:
                self.sendLogSuspiciousEvent("failed to load texture %s" % texName)
                if self.getGender() == "m":
                    bottomTex = loader.loadTexture(BoyShorts[0])
                else:
                    bottomTex = loader.loadTexture(GirlBottoms[0][0])
            bottomTex.setMinfilter(Texture.FTLinearMipmapLinear)
            bottomTex.setMagfilter(Texture.FTLinear)
            try:
                bottomColor = ClothesColors[self.botTexColor]
            except:
                bottomColor = ClothesColors[0]

            darkBottomColor = bottomColor * 0.5
            darkBottomColor.setW(1.0)
            for lodName in self.toon.getLODNames():
                thisPart = self.toon.getPart("torso", lodName)
                top = thisPart.find("**/torso-top")
                top.setTexture(shirtTex, 1)
                top.setColor(shirtColor)
                sleeves = thisPart.find("**/sleeves")
                sleeves.setTexture(sleeveTex, 1)
                sleeves.setColor(sleeveColor)
                bottoms = thisPart.findAllMatches("**/torso-bot")
                for bottomNum in xrange(0, bottoms.getNumPaths()):
                    bottom = bottoms.getPath(bottomNum)
                    bottom.setTexture(bottomTex, 1)
                    bottom.setColor(bottomColor)

                caps = thisPart.findAllMatches("**/torso-bot-cap")
                caps.setColor(darkBottomColor)

        return swappedTorso

    def generateToonColor(self):
        parts = self.toon.findAllMatches("**/head*")
        parts.setColor(self.getHeadColor())
        animalType = self.getAnimal()
        if (
            animalType == "cat"
            or animalType == "rabbit"
            or animalType == "bear"
            or animalType == "mouse"
            or animalType == "pig"
        ):
            parts = self.toon.findAllMatches("**/ear?-*")
            parts.setColor(self.getHeadColor())

        armColor = self.getArmColor()
        gloveColor = self.getGloveColor()
        legColor = self.getLegColor()
        for lodName in self.toon.getLODNames():
            torso = self.toon.getPart("torso", lodName)
            if len(self.torso) == 1:
                parts = torso.findAllMatches("**/torso*")
                parts.setColor(armColor)
            for pieceName in ("arms", "neck"):
                piece = torso.find("**/" + pieceName)
                piece.setColor(armColor)

            hands = torso.find("**/hands")
            hands.setColor(gloveColor)
            legs = self.toon.getPart("legs", lodName)
            for pieceName in ("legs", "feet"):
                piece = legs.find("**/%s;+s" % pieceName)
                piece.setColor(legColor)

    def generateToonHead(self, copy, lods):
        headStyle = self.head
        fix = None
        if headStyle == "dls":
            filePrefix = HeadDict["dls"]
            headHeight = 0.75
        elif headStyle == "dss":
            filePrefix = HeadDict["dss"]
            headHeight = 0.5
        elif headStyle == "dsl":
            filePrefix = HeadDict["dsl"]
            headHeight = 0.5
        elif headStyle == "dll":
            filePrefix = HeadDict["dll"]
            headHeight = 0.75
        elif headStyle == "cls":
            filePrefix = HeadDict["c"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "css":
            filePrefix = HeadDict["c"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "csl":
            filePrefix = HeadDict["c"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "cll":
            filePrefix = HeadDict["c"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == "hls":
            filePrefix = HeadDict["h"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "hss":
            filePrefix = HeadDict["h"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "hsl":
            filePrefix = HeadDict["h"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "hll":
            filePrefix = HeadDict["h"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == "mls":
            filePrefix = HeadDict["m"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "mss":
            filePrefix = HeadDict["m"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "rls":
            filePrefix = HeadDict["r"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "rss":
            filePrefix = HeadDict["r"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "rsl":
            filePrefix = HeadDict["r"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "rll":
            filePrefix = HeadDict["r"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == "fls":
            filePrefix = HeadDict["f"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "fss":
            filePrefix = HeadDict["f"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "fsl":
            filePrefix = HeadDict["f"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "fll":
            filePrefix = HeadDict["f"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == "pls":
            filePrefix = HeadDict["p"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "pss":
            filePrefix = HeadDict["p"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "psl":
            filePrefix = HeadDict["p"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "pll":
            filePrefix = HeadDict["p"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == "bls":
            filePrefix = HeadDict["b"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "bss":
            filePrefix = HeadDict["b"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "bsl":
            filePrefix = HeadDict["b"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "bll":
            filePrefix = HeadDict["b"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == "sls":
            filePrefix = HeadDict["s"]
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == "sss":
            filePrefix = HeadDict["s"]
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == "ssl":
            filePrefix = HeadDict["s"]
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == "sll":
            filePrefix = HeadDict["s"]
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        else:
            ToonHead.notify.error("unknown head style: %s" % headStyle)
        if len(lods) == 1:
            self.toon.loadModel(filePrefix + lods[0], "head", "lodRoot", copy)
            if not copy:
                self.toon.showAllParts("head")
            if fix != None:
                fix(None, copy)
            self.__lods = lods
            self.__headStyle = headStyle
            self.__copy = copy
        else:
            for lod in lods:
                self.toon.loadModel(filePrefix + lod, "head", lod, copy)
                if not copy:
                    self.toon.showAllParts("head", lod)
                if fix != None:
                    fix(lod, copy)
                self.__lods = lods
                self.__headStyle = headStyle
                self.__copy = copy

        # self.setupEyelashes()
        self.setupMuzzles()
        return headHeight

    def setupMuzzles(self):
        self.__muzzles = []
        self.__surpriseMuzzles = []
        self.__angryMuzzles = []
        self.__sadMuzzles = []
        self.__smileMuzzles = []
        self.__laughMuzzles = []

        def hideAddNonEmptyItemToList(item, list):
            if not item.isEmpty():
                item.hide()
                list.append(item)

        def hideNonEmptyItem(item):
            if not item.isEmpty():
                item.hide()

        if self.toon.hasLOD():
            for lodName in self.toon.getLODNames():
                animal = self.getAnimal()
                if animal != "dog":
                    muzzle = self.toon.find("**/" + lodName + "/**/muzzle*neutral")
                else:
                    muzzle = self.toon.find("**/" + lodName + "/**/muzzle*")
                    if lodName == "1000" or lodName == "500":
                        filePrefix = DogMuzzleDict[self.head]
                        muzzles = self.toon.loadModel(filePrefix + lodName)
                        if base.config.GetBool("want-new-anims", 1):
                            if not self.toon.find("**/" + lodName + "/**/__Actor_head/def_head").isEmpty():
                                muzzles.reparentTo(self.toon.find("**/" + lodName + "/**/__Actor_head/def_head"))
                            else:
                                muzzles.reparentTo(self.toon.find("**/" + lodName + "/**/joint_toHead"))
                        elif self.toon.find("**/" + lodName + "/**/joint_toHead"):
                            muzzles.reparentTo(self.toon.find("**/" + lodName + "/**/joint_toHead"))
                surpriseMuzzle = self.toon.find("**/" + lodName + "/**/muzzle*surprise")
                angryMuzzle = self.toon.find("**/" + lodName + "/**/muzzle*angry")
                sadMuzzle = self.toon.find("**/" + lodName + "/**/muzzle*sad")
                smileMuzzle = self.toon.find("**/" + lodName + "/**/muzzle*smile")
                laughMuzzle = self.toon.find("**/" + lodName + "/**/muzzle*laugh")
                self.__muzzles.append(muzzle)
                hideAddNonEmptyItemToList(surpriseMuzzle, self.__surpriseMuzzles)
                hideAddNonEmptyItemToList(angryMuzzle, self.__angryMuzzles)
                hideAddNonEmptyItemToList(sadMuzzle, self.__sadMuzzles)
                hideAddNonEmptyItemToList(smileMuzzle, self.__smileMuzzles)
                hideAddNonEmptyItemToList(laughMuzzle, self.__laughMuzzles)

    def setupEyelashes(self):
        animal = self.head[0]
        model = self.toon.loadModel(EyelashDict[animal])
        if self.toon.hasLOD():
            head = self.toon.getPart("head", "1000")
        else:
            head = self.toon.getPart("head", "lodRoot")
        length = self.head[1]
        if length == "l":
            openString = "open-long"
            closedString = "closed-long"
        else:
            openString = "open-short"
            closedString = "closed-short"
        self.__eyelashOpen = model.find("**/" + openString).copyTo(head)
        self.__eyelashClosed = model.find("**/" + closedString).copyTo(head)
        model.removeNode()
        return

    def parentToonParts(self):
        if self.toon.hasLOD():
            for lodName in self.toon.getLODNames():
                if base.config.GetBool("want-new-anims", 1):
                    if not self.toon.getPart("torso", lodName).find("**/def_head").isEmpty():
                        self.toon.attach("head", "torso", "def_head", lodName)
                    else:
                        self.toon.attach("head", "torso", "joint_head", lodName)
                else:
                    self.toon.attach("head", "torso", "joint_head", lodName)
                self.toon.attach("torso", "legs", "joint_hips", lodName)
        else:
            self.toon.attach("head", "torso", "joint_head")
            self.toon.attach("torso", "legs", "joint_hips")

    def __fixHeadLongLong(self, lodName=None, copy=1):
        if lodName == None:
            searchRoot = self.toon
        else:
            searchRoot = self.toon.find("**/" + str(lodName))
        otherParts = searchRoot.findAllMatches("**/*short*")
        for partNum in xrange(0, otherParts.getNumPaths()):
            if copy:
                otherParts.getPath(partNum).removeNode()
            else:
                otherParts.getPath(partNum).stash()

        return

    def __fixHeadLongShort(self, lodName=None, copy=1):
        animalType = self.getAnimal()
        headStyle = self.head
        if lodName == None:
            searchRoot = self.toon
        else:
            searchRoot = self.toon.find("**/" + str(lodName))
        if animalType != "duck" and animalType != "horse":
            if animalType == "rabbit":
                if copy:
                    searchRoot.find("**/ears-long").removeNode()
                else:
                    searchRoot.find("**/ears-long").hide()
            elif copy:
                searchRoot.find("**/ears-short").removeNode()
            else:
                searchRoot.find("**/ears-short").hide()
        if animalType != "rabbit":
            if copy:
                searchRoot.find("**/eyes-short").removeNode()
            else:
                searchRoot.find("**/eyes-short").hide()
        if animalType != "dog":
            if copy:
                searchRoot.find("**/joint_pupilL_short").removeNode()
                searchRoot.find("**/joint_pupilR_short").removeNode()
            else:
                searchRoot.find("**/joint_pupilL_short").stash()
                searchRoot.find("**/joint_pupilR_short").stash()
        if animalType != "rabbit":
            muzzleParts = searchRoot.findAllMatches("**/muzzle-long*")
            for partNum in xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        else:
            muzzleParts = searchRoot.findAllMatches("**/muzzle-short*")
            for partNum in xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        return

    def __fixHeadShortLong(self, lodName=None, copy=1):
        animalType = self.getAnimal()
        headStyle = self.head
        if lodName == None:
            searchRoot = self.toon
        else:
            searchRoot = self.toon.find("**/" + str(lodName))
        if animalType != "duck" and animalType != "horse":
            if animalType == "rabbit":
                if copy:
                    searchRoot.find("**/ears-short").removeNode()
                else:
                    searchRoot.find("**/ears-short").hide()
            elif copy:
                searchRoot.find("**/ears-long").removeNode()
            else:
                searchRoot.find("**/ears-long").hide()
        if animalType != "rabbit":
            if copy:
                searchRoot.find("**/eyes-long").removeNode()
            else:
                searchRoot.find("**/eyes-long").hide()
        if animalType != "dog":
            if copy:
                searchRoot.find("**/joint_pupilL_long").removeNode()
                searchRoot.find("**/joint_pupilR_long").removeNode()
            else:
                searchRoot.find("**/joint_pupilL_long").stash()
                searchRoot.find("**/joint_pupilR_long").stash()
        if copy:
            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 xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        else:
            muzzleParts = searchRoot.findAllMatches("**/muzzle-long*")
            for partNum in xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        return

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

        return

    def setLODs(self):
        self.toon.setLODNode()
        levelOneIn = base.config.GetInt("lod1-in", 20)
        levelOneOut = base.config.GetInt("lod1-out", 0)
        levelTwoIn = base.config.GetInt("lod2-in", 80)
        levelTwoOut = base.config.GetInt("lod2-out", 20)
        levelThreeIn = base.config.GetInt("lod3-in", 280)
        levelThreeOut = base.config.GetInt("lod3-out", 80)
        self.toon.addLOD(1000, levelOneIn, levelOneOut)
        self.toon.addLOD(500, levelTwoIn, levelTwoOut)
        self.toon.addLOD(250, levelThreeIn, levelThreeOut)

    def loadPhaseAnims(self, phaseStr="phase_3", loadFlag=1):
        if phaseStr == "phase_3":
            animList = Phase3AnimList
        elif phaseStr == "phase_3.5":
            animList = Phase3_5AnimList
        elif phaseStr == "phase_4":
            animList = Phase4AnimList
        elif phaseStr == "phase_5":
            animList = Phase5AnimList
        elif phaseStr == "phase_5.5":
            animList = Phase5_5AnimList
        elif phaseStr == "phase_6":
            animList = Phase6AnimList
        elif phaseStr == "phase_9":
            animList = Phase9AnimList
        elif phaseStr == "phase_10":
            animList = Phase10AnimList
        elif phaseStr == "phase_12":
            animList = Phase12AnimList
        else:
            self.notify.error("Unknown phase string %s" % phaseStr)
        for key in LegDict.keys():
            for anim in animList:
                if loadFlag:
                    pass
                elif anim[0] in LegsAnimDict[key]:
                    if self.legs == key:
                        self.toon.unloadAnims([anim[0]], "legs", None)

        for key in TorsoDict.keys():
            for anim in animList:
                if loadFlag:
                    pass
                elif anim[0] in TorsoAnimDict[key]:
                    if self.torso == key:
                        self.toon.unloadAnims([anim[0]], "torso", None)

        for key in HeadDict.keys():
            if key.find("d") >= 0:
                for anim in animList:
                    if loadFlag:
                        pass
                    elif anim[0] in HeadAnimDict[key]:
                        if self.head == key:
                            self.toon.unloadAnims([anim[0]], "head", None)

    def renderSnapshot(self):
        print "Rendering Snapshot..."
        base.graphicsEngine.renderFrame()
        base.screenshot(namePrefix="snapshot-render", defaultFilename=1, source=None, imageComment="")
Beispiel #33
0
class Base(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        add_device_listener(
            config_file='keybindings.toml',
            assigner=SinglePlayerAssigner(),
        )
        base.disableMouse()
        self.sound = SoundManager()
        self.linefx = LineEffects()
        self.cardmaker = CardMaker("card")
        self.cardmaker.set_frame(-1,1,-1,1)
        self.turn_speed = 0.3 #length of turn animation in seconds
        self.sequence_player = SequencePlayer()
        self.transition = Transitions(loader)
        self.interface = Interface()
        self.bg_color = VBase4(0, 0, 0, 1)
        self.innitialize_fov()

        card, scene, camera, self.buffer = self.make_render_card()
        card.set_x(-0.25)
        self.camera = camera
        self.load_icons()

        self.texts = Texts(camera)
        self.pause = True
        self.instruct = True
        self.gameover = False
        self.won = False

        self.player = Player((0,0,0))
        self.map = Map()
        self.map.new_game()

        camera.reparent_to(self.player.root)
        camera.set_pos(4,-4,8)
        camera.look_at(self.player.root)
        camera.set_compass()
        base.task_mgr.add(self.update)

        card, scene, camera, buffer = self.make_render_card([3,7],[64,256],(0,100))
        self.hudgun = Actor("assets/models/hand.bam")
        self.hudgun.reparent_to(scene)
        self.hudgun.find("**/hand_healthy").show()
        self.hudgun.find("**/hand_hurt").hide()
        self.hudgun.setLODAnimation(1, 0.1, 0.005)
        self.player.weapon.set_hud_bullets()
        camera.look_at(self.hudgun)
        camera.set_pos(0.5,-1.5,10)
        camera.set_p(-90)
        card.set_scale(1/4,1,1)
        card.set_x(1-(1/4))
        self.quad = None
        self.setup_post_effect()

    def game_over(self):
        self.pause = True
        self.gameover = True
        self.texts.make_gameover()

    def win_game(self):
        self.pause = True
        self.won = True
        self.texts.make_end()

    def innitialize_fov(self):
        render.set_shader_auto()
        self.fov_point = PointLight("caster")
        self.fov_point.set_shadow_caster(True, 256*2, 256*2, -1000)
        self.fov_point.set_camera_mask(0b001)
        self.fov_point.set_lens_active(4, False)
        self.fov_point.set_lens_active(5, False)
        for i in range(6):
            self.fov_point.get_lens(i).set_near_far(0.5, 10)
        self.fov_point_np = render.attach_new_node(self.fov_point)
        self.fov_point_np.set_z(0.5)
        self.fov_point.set_color(VBase4(1,1,1,1))


    def make_render_card(self, ortho_size=[8,5], resolution=[256,256], nearfar=(5,40)):
        scene = NodePath("Scene")
        buffer = base.win.make_texture_buffer("Buffer", resolution[0], resolution[1])
        texture = buffer.get_texture()
        texture.set_magfilter(SamplerState.FT_nearest)
        texture.set_minfilter(SamplerState.FT_nearest)
        texture.set_wrap_u(SamplerState.WM_clamp)
        texture.set_wrap_v(SamplerState.WM_clamp)
        buffer.set_sort(-100)
        buffer.set_clear_color_active(True)
        buffer.set_clear_color(self.bg_color)
        camera = base.make_camera(buffer)
        lens = OrthographicLens()
        lens.set_film_size(ortho_size[0], ortho_size[1])
        lens.set_near(nearfar[0])
        lens.set_far(nearfar[1])
        camera.node().set_lens(lens)
        camera.reparent_to(scene)
        card = render2d.attach_new_node(self.cardmaker.generate())
        card.set_texture(texture)
        return card, scene, camera, buffer

    def setup_post_effect(self):
        self.manager = FilterManager(base.win, base.cam2d)
        tex = Texture()
        #tex = loader.load_texture("assets/noise.png")
        self.quad = self.manager.renderSceneInto(colortex=tex)
        self.quad.setShader(Shader.load(Shader.SL_GLSL, "crt.vert","crt.frag"))
        self.quad.setShaderInput("iResolution", (base.win.getXSize(), base.win.getYSize()))
        self.quad.setShaderInput("pattern", base.loader.load_texture("assets/crt.png"))
        self.quad.get_texture().set_wrap_u(SamplerState.WM_clamp)
        self.quad.get_texture().set_wrap_v(SamplerState.WM_clamp)
        base.accept("window-event", self.on_window_event)

    def on_window_event(self, win):
        base.windowEvent(win)
        self.quad.setShaderInput("iResolution", (base.win.getXSize(), base.win.getYSize()))

    def load_icons(self):
        model = loader.load_model("assets/models/icons.bam")
        self.icons = {}
        for child in model.get_children():
            child.clear_transform()
            child.detach_node()
            self.icons[child.name] = child

    def update(self, task):
        self.dt = globalClock.get_dt()
        context = base.device_listener.read_context('ew')
        if context["quit"]:
            sys.exit()
        if not self.pause:
            if self.player.alive:
                base.texts.deactivate()
            if not self.sequence_player.parallel:
                self.interface.update(context)
        elif not self.sequence_player.parallel:
            if self.won:
                return task.cont

            if context["select"]:
                self.texts.deactivate()
                if self.instruct:
                    self.instruct = False
                    self.texts.make_instructions()
                else:
                    self.pause = False
                    if self.gameover:
                        base.sound.stop("die")
                        self.gameover = False
                        self.map.destroy()
                        self.map.new_game()
                    else:
                        base.sound.music["opening"].stop()
                        base.sound.music["background"].play()
        return task.cont
Beispiel #34
0
class Avatar(DirectObject):
    
    def __init__(self):
        self.data = {
        'Animal' : None,
        'Gender' : None,
        'Weight' : None,
        'Height' : None,
        'Color' : None,
        'HeadType' : None,
        'HeadLength' : None,
        'Shirt' : None,
        'Bottoms' : None
        }
        
    def setData(self, key, value):
        self.data[key] = value
        
    def getData(self):
        return self.data
        
    def generateAnims(self, torso = False, legs = False):
        anims = {}
        if(torso):
            for anim in Anims:
                anims[anim] = loader.loadModel('phase_3/models/char/%s-torso-%s-%s.bam' % (self.data['Weight'], self.data['Gender'], anim))
        if(legs):
            for anim in Anims:
                anims[anim] = loader.loadModel('phase_3/models/char/%s-legs-%s.bam' % (self.data['Height'], anim))
        return anims
    
    def removeOtherParts(self, nodepath, impotent):
        if(impotent == None):
            matches = nodepath
            for part in range(0, matches.getNumPaths()):
                name = matches.getPath(part).getName()
                if(name):
                    if(name == 'muzzle-short-neutral' and self.data['Animal'] == 'mouse'):
                        if(self.data['HeadType'] == 500 or self.data['HeadType'] == 1000):
                            return
                    matches.getPath(part).removeNode()
        else:
            matches = nodepath
            for part in range(0, matches.getNumPaths()):
                if(part != impotent):
                    if(matches.getPath(part).getName()):
                        matches.getPath(part).removeNode()
    
    def setColor(self):
        colorEarAnimals = {'dog', 'horse', 'monkey'}
        body = ['**/head-*', '**/neck', '**/arms', '**/legs', '**/feet', '**/head']
        if(self.data['Animal'] not in colorEarAnimals):
            body.append('**/*ears*')
        for part in range(len(body)):
            self.Avatar.findAllMatches(body[part]).setColor(self.data['Color'])
        self.Avatar.findAllMatches("**/hands").setColor(AvatarAttributes().getColor('white'))
        
    def generate(self):
        head = loader.loadModel('phase_3/models/char/%s-heads-%s.bam' % (self.data['Animal'], self.data['HeadType']))
        torso = loader.loadModel('phase_3/models/char/%s-torso-%s.bam' % (self.data['Weight'], self.data['Gender']))
        legs = loader.loadModel('phase_3/models/char/%s-legs.bam' % (self.data['Height']))
        
        if(self.data['HeadLength'] == 'short'):
            self.removeOtherParts(head.findAllMatches('**/*long*'), None)
        else:
            self.removeOtherParts(head.findAllMatches('**/*short*'), None)
        muzzleParts = head.findAllMatches('**/*muzzle*')
        if(self.data['Animal'] != 'dog'):
            for partNum in range(0, muzzleParts.getNumPaths()):
                part = muzzleParts.getPath(partNum)
                if not 'neutral' in part.getName():
                    part.hide()
        self.removeOtherParts(legs.findAllMatches('**/boots*') + legs.findAllMatches('**/shoes'), None)
        torsoAnims = self.generateAnims(torso=True)
        legsAnims = self.generateAnims(legs=True)
        self.Avatar = Actor({'head' : head, 'torso' : torso, 'legs' : legs}, {'torso' : torsoAnims, 'legs' : legsAnims})
        self.Avatar.attach('head', 'torso', 'def_head')
        self.Avatar.attach('torso', 'legs', 'joint_hips')
        if(self.data['Gender'] == 'girl'):
            femaleEyes = loader.loadTexture('phase_3/maps/eyesFemale.jpg', 'phase_3/maps/eyesFemale_a.rgb')
            try:
                self.Avatar.find('**/eyes').setTexture(femaleEyes, 1)
            except: pass
            try:
                self.Avatar.find('**/eyes-%s' % (self.data['HeadLength'])).setTexture(femaleEyes, 1)
            except: pass
        # Reseat pupils of old head models
        pupils = head.findAllMatches('**/*pupil*')
        for pupil in pupils:
            pupil.setY(0.02)
        self.setColor()
        shadow = ShadowCaster(self.Avatar)
        shadow.initializeDropShadow()
        self.Avatar.setPythonTag("AvatarInstance", self)
        
    def getAvatar(self):
        return self.Avatar
        
        
class DistributedPartyFireworksActivity(DistributedPartyActivity, FireworkShowMixin):
    notify = directNotify.newCategory('DistributedPartyFireworksActivity')

    def __init__(self, cr):
        DistributedPartyFireworksActivity.notify.debug('__init__')
        DistributedPartyActivity.__init__(self, cr, ActivityIds.PartyFireworks, ActivityTypes.HostInitiated, wantLever=True)
        FireworkShowMixin.__init__(self, restorePlaygroundMusic=True, startDelay=FireworksPostLaunchDelay)

    def setEventId(self, eventId):
        DistributedPartyFireworksActivity.notify.debug('setEventId( %s )' % FireworkShows.getString(eventId))
        self.eventId = eventId

    def setShowStyle(self, showStyle):
        DistributedPartyFireworksActivity.notify.debug('setShowStyle( %d )' % showStyle)
        self.showStyle = showStyle
    
    def setSongId(self, songId):
        self.songId = songId

    def load(self):
        DistributedPartyFireworksActivity.notify.debug('load')
        DistributedPartyActivity.load(self)
        self.eventId = PartyGlobals.FireworkShows.Summer
        self.launchPadModel = loader.loadModel('phase_13/models/parties/launchPad')
        self.launchPadModel.setH(90.0)
        self.launchPadModel.setPos(0.0, -18.0, 0.0)
        self.launchPadModel.reparentTo(self.root)
        railingsCollection = self.launchPadModel.findAllMatches('**/launchPad_mesh/*railing*')
        for i in xrange(railingsCollection.getNumPaths()):
            railingsCollection[i].setAttrib(AlphaTestAttrib.make(RenderAttrib.MGreater, 0.75))

        leverLocator = self.launchPadModel.find('**/RocketLever_locator')
        self.lever.setPosHpr(Vec3.zero(), Vec3.zero())
        self.lever.reparentTo(leverLocator)
        self.toonPullingLeverInterval = None
        self.sign.reparentTo(self.launchPadModel.find('**/launchPad_sign_locator'))
        self.rocketActor = Actor('phase_13/models/parties/rocket_model', {'launch': 'phase_13/models/parties/rocket_launch'})
        rocketLocator = self.launchPadModel.find('**/rocket_locator')
        self.rocketActor.reparentTo(rocketLocator)
        self.rocketActor.node().setBound(OmniBoundingVolume())
        self.rocketActor.node().setFinal(True)
        effectsLocator = self.rocketActor.find('**/joint1')
        self.rocketExplosionEffect = RocketExplosion(effectsLocator, rocketLocator)
        self.rocketParticleSeq = None
        self.launchSound = base.loadSfx('phase_13/audio/sfx/rocket_launch.ogg')
        self.activityFSM = FireworksActivityFSM(self)
        self.activityFSM.request('Idle')
        return

    def unload(self):
        DistributedPartyFireworksActivity.notify.debug('unload')
        taskMgr.remove(self.taskName('delayedStartShow'))
        if self.rocketParticleSeq:
            self.rocketParticleSeq.pause()
            self.rocketParticleSeq = None
        self.launchPadModel.removeNode()
        del self.launchPadModel
        del self.toonPullingLeverInterval
        self.rocketActor.delete()
        self.rocketExplosionEffect.destroy()
        self.activityFSM.request('Disabled')
        del self.rocketActor
        del self.launchSound
        del self.activityFSM
        del self.eventId
        del self.showStyle
        DistributedPartyActivity.unload(self)
        return

    def _leverPulled(self, collEntry):
        DistributedPartyFireworksActivity.notify.debug('_leverPulled')
        hostPulledLever = DistributedPartyActivity._leverPulled(self, collEntry)
        if self.activityFSM.getCurrentOrNextState() == 'Active':
            self.showMessage(TTLocalizer.PartyFireworksAlreadyActive)
        elif self.activityFSM.getCurrentOrNextState() == 'Disabled':
            self.showMessage(TTLocalizer.PartyFireworksAlreadyDone)
        elif self.activityFSM.getCurrentOrNextState() == 'Idle':
            if hostPulledLever:
                base.cr.playGame.getPlace().fsm.request('activity')
                self.toonPullingLeverInterval = self.getToonPullingLeverInterval(base.localAvatar)
                self.toonPullingLeverInterval.append(Func(self.d_toonJoinRequest))
                self.toonPullingLeverInterval.append(Func(base.cr.playGame.getPlace().fsm.request, 'walk'))
                self.toonPullingLeverInterval.start()
            else:
                self.showMessage(TTLocalizer.PartyOnlyHostLeverPull)

    def setState(self, newState, timestamp):
        DistributedPartyFireworksActivity.notify.debug('setState( newState=%s, ... )' % newState)
        DistributedPartyActivity.setState(self, newState, timestamp)
        if newState == 'Active':
            self.activityFSM.request(newState, timestamp)
        else:
            self.activityFSM.request(newState)

    def startIdle(self):
        DistributedPartyFireworksActivity.notify.debug('startIdle')

    def finishIdle(self):
        DistributedPartyFireworksActivity.notify.debug('finishIdle')

    def startActive(self, showStartTimestamp):
        DistributedPartyFireworksActivity.notify.debug('startActive')
        messenger.send(FireworksStartedEvent)
        timeSinceStart = globalClockDelta.localElapsedTime(showStartTimestamp)
        if timeSinceStart > self.rocketActor.getDuration('launch'):
            self.rocketActor.hide()
            if timeSinceStart < 60:
                self.startShow(self.eventId, self.showStyle, self.songId, showStartTimestamp)
        else:
            self.rocketActor.play('launch')
            self.rocketParticleSeq = Sequence(Wait(RocketSoundDelay), Func(base.playSfx, self.launchSound), Func(self.rocketExplosionEffect.start), Wait(RocketDirectionDelay), LerpHprInterval(self.rocketActor, 4.0, Vec3(0, 0, -60)), Func(self.rocketExplosionEffect.end), Func(self.rocketActor.hide))
            self.rocketParticleSeq.start()
            taskMgr.doMethodLater(FireworksPostLaunchDelay, self.startShow, self.taskName('delayedStartShow'), extraArgs=[self.eventId,
             self.showStyle,
             self.songId,
             showStartTimestamp,
             self.root])

    def finishActive(self):
        self.rocketParticleSeq = None
        DistributedPartyFireworksActivity.notify.debug('finishActive')
        messenger.send(FireworksFinishedEvent)
        taskMgr.remove(self.taskName('delayedStartShow'))
        FireworkShowMixin.disable(self)
        return

    def startDisabled(self):
        DistributedPartyFireworksActivity.notify.debug('startDisabled')
        if not self.rocketActor.isEmpty():
            self.rocketActor.hide()

    def finishDisabled(self):
        DistributedPartyFireworksActivity.notify.debug('finishDisabled')

    def handleToonDisabled(self, toonId):
        self.notify.warning('handleToonDisabled no implementation yet')
class DistributedFountain(DistributedNode.DistributedNode):

    def __init__(self, cr, objectId):
        DistributedNode.DistributedNode.__init__(self, cr)
        NodePath.__init__(self, 'dgaFountain')
        self.persistenceFields = []
        self.bothFields = ['setGeyserAnim']
        self.done = True
        self.geyserTrack = None
        self.geyserModel = loader.loadModel('phase_6/models/golf/golf_geyser_model')
        self.geyserSound = loader.loadSfx('phase_6/audio/sfx/OZ_Geyser_No_Toon.mp3')
        self.fountainModel = loader.loadModel('phase_8/models/props/tt_m_ara_dga_fountain')
        self.fountainModel.reparentTo(self)
        self.fountainModel.find('**/fountainHead_dga').removeNode()
        geyserPlacer = self.attachNewNode('geyserPlacer')
        geyserPlacer.setPos(0, 0, 4)
        self.geyserSoundInterval = SoundInterval(self.geyserSound, node=geyserPlacer,
         listenerNode=base.camera, seamlessLoop=False, volume=0.6, cutOff=120)
        if self.geyserModel:
            self.geyserActor = Actor(self.geyserModel)
            self.geyserActor.loadAnims({'idle':'phase_6/models/golf/golf_geyser'})
            self.geyserActor.reparentTo(geyserPlacer)
            self.geyserActor.setScale(0.01)
            self.geyserActor.setPlayRate(8.6, 'idle')
            self.geyserActor.loop('idle')
            self.geyserActor.setDepthWrite(0)
            self.geyserActor.setTwoSided(True, 11)
            self.geyserActor.setColorScale(1.0, 1.0, 1.0, 1.0)
            self.geyserActor.setBin('fixed', 0)
            mesh = self.geyserActor.find('**/mesh_tide1')
            joint = self.geyserActor.find('**/uvj_WakeWhiteTide1')
            mesh.setTexProjector(mesh.findTextureStage('default'), joint, self.geyserActor)
            self.geyserActor.setZ(geyserPlacer.getZ() - 10.0)
            self.geyserPos = geyserPlacer.getPos()
            self.geyserPlacer = geyserPlacer
        self.objectId = objectId
        self.doId = self.objectId
        self.triggerName = self.uniqueName('trigger')
        self.triggerEvent_enter = 'enter%s' % self.triggerName
        cs = CollisionSphere(0.0, 0.0, -1.4, 4.0)
        cs.setTangible(0)
        cn = CollisionNode(self.triggerName)
        cn.addSolid(cs)
        cn.setIntoCollideMask(OTPGlobals.WallBitmask)
        trigger = self.attachNewNode(cn)
        self.accept(self.triggerEvent_enter, self.b_setGeyserAnim)

    def toggleGeyserDone(self):
        self.done = not self.done

    def b_setGeyserAnim(self, collisionEvent):
        self.sendUpdate('setGeyserAnim', [])

    def setGeyserAnim(self):
        if not self.done:
            return None
        self.toggleGeyserDone()
        maxSize = 0.12
        time = 1.0
        self.geyserTrack = Sequence()
        upPos = Vec3(self.geyserPos[0], self.geyserPos[1], self.geyserPos[2] - 8.0)
        downPos = Vec3(self.geyserPos[0], self.geyserPos[1], (self.geyserPos[2] - 8.0))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, (2.0 * time), 0.1, 0.01),
         LerpPosInterval(self.geyserActor, (2.0 * time), pos=downPos, startPos=downPos)))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, time, maxSize, 0.1),
         LerpPosInterval(self.geyserActor, time, pos=upPos, startPos=downPos)))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, (2.0 * time), 0.1, maxSize),
         LerpPosInterval(self.geyserActor, (2.0 * time), pos=downPos, startPos=upPos)))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, time, maxSize, 0.1),
         LerpPosInterval(self.geyserActor, time, pos=upPos, startPos=downPos)))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, (2.0 * time), 0.1, maxSize),
         LerpPosInterval(self.geyserActor, (2.0 * time), pos=downPos, startPos=upPos)))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, time, maxSize, 0.1),
         LerpPosInterval(self.geyserActor, time, pos=upPos, startPos=downPos)))
        self.geyserTrack.append(Parallel(LerpScaleInterval(self.geyserActor, (4.0 * time), 0.01, maxSize),
         LerpPosInterval(self.geyserActor, (4.0 * time), pos=downPos, startPos=upPos)))
        self.geyserTrack.append(Func(self.toggleGeyserDone))
        self.geyserTrack.start()
        self.geyserSoundInterval.start()

    def handleMessage(self, fieldName, args=[], sendToId=None, reciever=None):
        if fieldName == 'setGeyserAnim':
            self.setGeyserAnim()

    def sendUpdate(self, fieldName, args=[], sendToId=None,
                    recieverId=None, overrideBoth=False, persistenceOverride=False):
        if sendToId == None:
            sendToId = base.localAvatar.doId
        if (fieldName in self.bothFields) and (not overrideBoth):
            self.handleMessage(fieldName, args, sendToId)
        if (fieldName in self.persistenceFields) and (not persistenceOverride):
            TTSendBuffer.TTSendBuffer.sendMessage(self.objectId, fieldName, args, sendToId, True)
        else:
            TTSendBuffer.TTSendBuffer.sendMessage(self.objectId, fieldName, args, sendToId, False)
Beispiel #37
0
tallPumpkin.setTexture(tallPumpkinTex, 1)
tallPumpkin.setX(9.9)
tallPumpkin.setY(-3)
tallPumpkin.setZ(3.9)
tallPumpkin.setHpr(270, 0, 0)
tallPumpkin.place()

# Loanshark

LoanShark = Actor('phase_3.5/models/char/suitB-mod.bam',
                  {'victory': 'phase_4/models/char/suitB-victory.bam'})
LoanShark.reparentTo(render)
LoanShark.loop('victory')
LoanSharkHead = loader.loadModel('phase_4/models/char/suitB-heads.bam').find(
    '**/loanshark')
LoanSharkHead.reparentTo(LoanShark.find('**/joint_head'))
LoanSharkTorsoTex = loader.loadTexture('phase_3.5/maps/m_blazer.jpg')
LoanShark.find('**/torso').setTexture(LoanSharkTorsoTex, 1)
LoanSharkArmTex = loader.loadTexture('phase_3.5/maps/m_sleeve.jpg')
LoanShark.find('**/arms').setTexture(LoanSharkArmTex, 1)
LoanSharkLegTex = loader.loadTexture('phase_3.5/maps/m_leg.jpg')
LoanShark.find('**/legs').setTexture(LoanSharkLegTex, 1)

# Loanshark pos
LoanShark.setX(10)
LoanShark.setZ(4)
LoanShark.setH(90)

LoanShark.place()

bgm = base.loader.loadSfx(
Beispiel #38
0
class DistributedPartyFireworksActivity(DistributedPartyActivity,
                                        FireworkShowMixin):
    notify = directNotify.newCategory('DistributedPartyFireworksActivity')

    def __init__(self, cr):
        DistributedPartyFireworksActivity.notify.debug('__init__')
        DistributedPartyActivity.__init__(self,
                                          cr,
                                          ActivityIds.PartyFireworks,
                                          ActivityTypes.HostInitiated,
                                          wantLever=True)
        FireworkShowMixin.__init__(self,
                                   restorePlaygroundMusic=True,
                                   startDelay=FireworksPostLaunchDelay)

    def setEventId(self, eventId):
        DistributedPartyFireworksActivity.notify.debug(
            'setEventId( %s )' % FireworkShows.getString(eventId))
        self.eventId = eventId

    def setShowStyle(self, showStyle):
        DistributedPartyFireworksActivity.notify.debug('setShowStyle( %d )' %
                                                       showStyle)
        self.showStyle = showStyle

    def setSongId(self, songId):
        self.songId = songId

    def load(self):
        DistributedPartyFireworksActivity.notify.debug('load')
        DistributedPartyActivity.load(self)
        self.eventId = PartyGlobals.FireworkShows.Summer
        self.launchPadModel = loader.loadModel(
            'phase_13/models/parties/launchPad')
        self.launchPadModel.setH(90.0)
        self.launchPadModel.setPos(0.0, -18.0, 0.0)
        self.launchPadModel.reparentTo(self.root)
        railingsCollection = self.launchPadModel.findAllMatches(
            '**/launchPad_mesh/*railing*')
        for i in xrange(railingsCollection.getNumPaths()):
            railingsCollection[i].setAttrib(
                AlphaTestAttrib.make(RenderAttrib.MGreater, 0.75))

        leverLocator = self.launchPadModel.find('**/RocketLever_locator')
        self.lever.setPosHpr(Vec3.zero(), Vec3.zero())
        self.lever.reparentTo(leverLocator)
        self.toonPullingLeverInterval = None
        self.sign.reparentTo(
            self.launchPadModel.find('**/launchPad_sign_locator'))
        self.rocketActor = Actor(
            'phase_13/models/parties/rocket_model',
            {'launch': 'phase_13/models/parties/rocket_launch'})
        rocketLocator = self.launchPadModel.find('**/rocket_locator')
        self.rocketActor.reparentTo(rocketLocator)
        self.rocketActor.node().setBound(OmniBoundingVolume())
        self.rocketActor.node().setFinal(True)
        effectsLocator = self.rocketActor.find('**/joint1')
        self.rocketExplosionEffect = RocketExplosion(effectsLocator,
                                                     rocketLocator)
        self.rocketParticleSeq = None
        self.launchSound = base.loader.loadSfx(
            'phase_13/audio/sfx/rocket_launch.ogg')
        self.activityFSM = FireworksActivityFSM(self)
        self.activityFSM.request('Idle')
        return

    def unload(self):
        DistributedPartyFireworksActivity.notify.debug('unload')
        taskMgr.remove(self.taskName('delayedStartShow'))
        if self.rocketParticleSeq:
            self.rocketParticleSeq.pause()
            self.rocketParticleSeq = None
        self.launchPadModel.removeNode()
        del self.launchPadModel
        del self.toonPullingLeverInterval
        self.rocketActor.delete()
        self.rocketExplosionEffect.destroy()
        self.activityFSM.request('Disabled')
        del self.rocketActor
        del self.launchSound
        del self.activityFSM
        del self.eventId
        del self.showStyle
        DistributedPartyActivity.unload(self)
        return

    def _leverPulled(self, collEntry):
        DistributedPartyFireworksActivity.notify.debug('_leverPulled')
        hostPulledLever = DistributedPartyActivity._leverPulled(
            self, collEntry)
        if self.activityFSM.getCurrentOrNextState() == 'Active':
            self.showMessage(TTLocalizer.PartyFireworksAlreadyActive)
        elif self.activityFSM.getCurrentOrNextState() == 'Disabled':
            self.showMessage(TTLocalizer.PartyFireworksAlreadyDone)
        elif self.activityFSM.getCurrentOrNextState() == 'Idle':
            if hostPulledLever:
                base.cr.playGame.getPlace().fsm.request('activity')
                self.toonPullingLeverInterval = self.getToonPullingLeverInterval(
                    base.localAvatar)
                self.toonPullingLeverInterval.append(
                    Func(self.d_toonJoinRequest))
                self.toonPullingLeverInterval.append(
                    Func(base.cr.playGame.getPlace().fsm.request, 'walk'))
                self.toonPullingLeverInterval.start()
            else:
                self.showMessage(TTLocalizer.PartyOnlyHostLeverPull)

    def setState(self, newState, timestamp):
        DistributedPartyFireworksActivity.notify.debug(
            'setState( newState=%s, ... )' % newState)
        DistributedPartyActivity.setState(self, newState, timestamp)
        if newState == 'Active':
            self.activityFSM.request(newState, timestamp)
        else:
            self.activityFSM.request(newState)

    def startIdle(self):
        DistributedPartyFireworksActivity.notify.debug('startIdle')

    def finishIdle(self):
        DistributedPartyFireworksActivity.notify.debug('finishIdle')

    def startActive(self, showStartTimestamp):
        DistributedPartyFireworksActivity.notify.debug('startActive')
        messenger.send(FireworksStartedEvent)
        timeSinceStart = globalClockDelta.localElapsedTime(showStartTimestamp)
        if timeSinceStart > self.rocketActor.getDuration('launch'):
            self.rocketActor.hide()
            if timeSinceStart < 60:
                self.startShow(self.eventId, self.showStyle, self.songId,
                               showStartTimestamp)
        else:
            self.rocketActor.play('launch')
            self.rocketParticleSeq = Sequence(
                Wait(RocketSoundDelay), Func(base.playSfx, self.launchSound),
                Func(self.rocketExplosionEffect.start),
                Wait(RocketDirectionDelay),
                LerpHprInterval(self.rocketActor, 4.0, Vec3(0, 0, -60)),
                Func(self.rocketExplosionEffect.end),
                Func(self.rocketActor.hide))
            self.rocketParticleSeq.start()
            taskMgr.doMethodLater(FireworksPostLaunchDelay,
                                  self.startShow,
                                  self.taskName('delayedStartShow'),
                                  extraArgs=[
                                      self.eventId, self.showStyle,
                                      self.songId, showStartTimestamp,
                                      self.root
                                  ])

    def finishActive(self):
        self.rocketParticleSeq = None
        DistributedPartyFireworksActivity.notify.debug('finishActive')
        messenger.send(FireworksFinishedEvent)
        taskMgr.remove(self.taskName('delayedStartShow'))
        FireworkShowMixin.disable(self)
        return

    def startDisabled(self):
        DistributedPartyFireworksActivity.notify.debug('startDisabled')
        if not self.rocketActor.isEmpty():
            self.rocketActor.hide()

    def finishDisabled(self):
        DistributedPartyFireworksActivity.notify.debug('finishDisabled')

    def handleToonDisabled(self, toonId):
        self.notify.warning('handleToonDisabled no implementation yet')
Beispiel #39
0
def make_cog(head, head_style, suit_style, suit_name, head_text="", path=""):
    """Return a skelecog version of any traditional cog as an Actor.

    Args:
        head (str): The name of the cog.
        head_style (str): The letter representing the suit style
            ("A", "B" or "C").
        suit_style (str): The letter representing the suit style
            ("A", "B" or "C").
        suit_name (str): The name of the suit.
        head_text (str, optional): The name of a head texture.
        path (str, optional): The file path to the Toontown phase files.
            Defaults to Panda3D's search path.

    Examples:
        from toontown import make_cog

        Hollywood = make_cog("yesman", "A", "A", "sell")
        Hollywood.loop("landing")

        RobberBaron = make_cog("yesman", "A", "A", "cash", "robber-baron")
        RobberBaron.loop("walk")

        SpinDoctor = make_cog("telemarketer", "B", "B", "law", "spin-doctor")
        SpinDoctor.loop("throw-paper")

    Returns:
        An instance of Panda3D's Actor class.
    """

    if path:
        path = pfile.fromOsSpecific("%s/" % path).getFullpath()

    abrv = {
        "sell": (
            "s", (0.95, 0.75, 0.95, 1.0),
            "Sales", (0.843, 0.745, 0.745, 1.0)
        ),
        "cash": (
            "m", (0.65, 0.95, 0.85, 1.0),
            "Money", (0.749, 0.769, 0.749, 1.0)
        ),
        "law": (
            "l", (0.75, 0.75, 0.95, 1.0),
            "Legal", (0.749, 0.776, 0.824, 1.0)
        ),
        "boss": (
            "c", (0.95, 0.75, 0.75, 1.0),
            "Corp", (0.863, 0.776, 0.769, 1.0)
        )
    }

    cog_color = {
        "coldcaller": ((0.75, 0.75, 0.95, 1.0), ""),
        "pennypincher": ((1.0, 0.5, 0.6, 1.0), ""),
        "legaleagle": ((0.25, 0.25, 0.5, 1.0), ""),
        "telemarketer": ((0.5, 0.8, 0.75, 1.0), "spin-doctor"),
        "movershaker": ((0.95, 0.95, 1.0, 1.0), "blood-sucker"),
        "bigcheese": ((0.75, 0.95, 0.75, 1.0), ""),
        "flunky": ((0.85, 0.55, 0.55, 1.0), "corporate-raider")
    }

    blazer = loader.loadTexture(
        "%sphase_3.5/maps/%s_blazer.jpg" % (path, abrv[suit_name][0])
    )
    sleeve = loader.loadTexture(
        "%sphase_3.5/maps/%s_sleeve.jpg" % (path, abrv[suit_name][0])
    )
    leg = loader.loadTexture(
        "%sphase_3.5/maps/%s_leg.jpg" % (path, abrv[suit_name][0])
    )

    animation_dict = cog_animation(suit_style, path)

    if suit_style in ("A", "B"):
        cog = Actor(
            "%sphase_3.5/models/char/suit%s-mod.bam" % (path, suit_style),
            animation_dict
        )
    else:
        cog = Actor(
            "%sphase_3.5/models/char/suitC-mod.bam" % path, animation_dict
        )

    if head_style in ("A", "B"):
        head_model = loader.loadModel(
            "%sphase_4/models/char/suit%s-heads.bam" % (path, head_style)
        )
    else:
        head_model = loader.loadModel(
            "%sphase_3.5/models/char/suitC-heads.bam" % path
        )

    cog_head = head_model.find("**/%s" % head)
    joint_head = cog.find("**/joint_head")
    cog_head.reparentTo(joint_head)

    if head in cog_color.keys() and head_text == cog_color[head][1]:
        cog.find("**/hands").setColor(cog_color[head][0])
    else:
        cog.find("**/hands").setColor(abrv[suit_name][1])

    if head_text and head_text not in ("bottom-feeder", "corporate-raider"):
        head_texture = loader.loadTexture(
            "%sphase_4/maps/%s.jpg" % (path, head_text)
        )
        cog.findAllMatches("**/%s" % head).setTexture(head_texture, 1)
    elif head_text in ("bottom-feeder", "corporate-raider"):
        head_texture = loader.loadTexture(
            "%sphase_3.5/maps/%s.jpg" % (path, head_text)
        )
        cog.findAllMatches("**/%s" % head).setTexture(head_texture, 1)

    if head == "flunky" and not head_text:
        head_model.find("**/glasses").reparentTo(cog_head)

    icons = loader.loadModel("%sphase_3/models/gui/cog_icons.bam" % path)
    icon = icons.find(
        "**/%sIcon" % abrv[suit_name][2]
    ).copyTo(cog.find("**/joint_attachMeter"))
    icon.setPosHprScale(0.02, 0.05, 0.04, 180.0, 0.0, 0.0, 0.51, 0.51, 0.51)
    icon.setColor(abrv[suit_name][3])
    icons.removeNode()

    cog.find("**/legs").setTexture(leg, 1)
    cog.find("**/torso").setTexture(blazer, 1)
    cog.find("**/arms").setTexture(sleeve, 1)
    cog.reparentTo(render)

    return cog
Beispiel #40
0
class ToonMaker:
    def ToonMaker(self, legs, torso, head, shirtText, sleeveText, pantsText,
                  number, gender):
        if gender == 'm':
            gender = 'shorts'
        elif gender == 'f':
            gender = 'skirt'
        self.Toon = Actor(
            {
                'legs':
                'phase_3/models/char/tt_a_chr_dg%s_shorts_legs_1000.bam' %
                (legs),
                'torso':
                'phase_3/models/char/tt_a_chr_dg%s_%s_torso_1000.bam' %
                (torso, gender),
                'head':
                'phase_3/models/char/tt_a_chr_dg%s_shorts_head_1000.bam' %
                (head)
            }, {
                'legs': {
                    'neutral':
                    'phase_3/models/char/tt_a_chr_dg%s_shorts_legs_neutral.bam'
                    % (legs)
                },
                'torso': {
                    'neutral':
                    'phase_3/models/char/tt_a_chr_dg%s_%s_torso_neutral.bam' %
                    (torso, gender)
                },
                'head': {
                    'neutral':
                    'phase_3/models/char/tt_a_chr_dg%s_shorts_head_neutral.bam'
                    % (head)
                }
            })
        self.Toon.reparentTo(render)
        self.Toon.attach("head", "torso", "def_head")
        self.Toon.attach("torso", "legs", "joint_hips")
        self.Toon.loop('neutral')
        self.Toon.setBlend(frameBlend=True)
        self.Toon.find('**/hands').setColor(1, 1, 1, 1)
        self.Toon.find('**/shoes').removeNode()
        self.Toon.find('**/boots_short').removeNode()
        self.Toon.find('**/boots_long').removeNode()

        shirt = loader.loadTexture(shirtText)
        sleeve = loader.loadTexture(sleeveText)
        pants = loader.loadTexture(pantsText)
        self.Toon.find('**/torso-top').setTexture(shirt, 1)
        self.Toon.find('**/sleeves').setTexture(sleeve, 1)
        self.Toon.find('**/torso-bot').setTexture(pants, 1)

        fur = (.75, .25, .25, 1)
        self.Toon.find('**/feet').setColor(fur)
        self.Toon.find('**/legs').setColor(fur)
        self.Toon.find('**/arms').setColor(fur)
        self.Toon.find('**/neck').setColor(fur)
        self.Toon.find('**/head').setColor(fur)
        self.Toon.find('**/head-front').setColor(fur)
        self.Toon.setPos(number, 0, 0)
        self.Toon.setH(180)

        Hat = loader.loadModel(
            'phase_4/models/accessories/tt_m_chr_avt_acc_hat_bowler.bam')
        Hat.setColor(1)
        Hat.reparentTo(self.Toon.find('**/head'))
        Hat.setZ(0.30)
        Hat.setHpr(180.00, 330.00, 0.00)
        Hat.setScale(0.35)
        self.Toon.find('**/head').removeNode()
        self.Toon.find('**/head-front').removeNode()
        self.Toon.find('**/muzzle').removeNode()
        self.Toon.find('**/nose').removeNode()
        self.Toon.find('**/eyes').removeNode()
        self.Toon.find('**/ears').removeNode()
Beispiel #41
0
class HL2Shotgun(Gag):
    name = GagGlobals.HL2Shotgun
    gagType = GagType.TRAP
    multiUse = True
    model = "phase_14/hl2/w_shotgun/w_shotgun.bam"

    sgDir = 'phase_14/hl2/v_shotgun/panda/opt/'
    sgActorDef = [
        sgDir + 'v_shotgun.bam', {
            'draw': sgDir + 'v_shotgun-draw.egg',
            'idle': sgDir + 'v_shotgun-idle01.egg',
            'pump': sgDir + 'v_shotgun-pump.egg',
            'fire': sgDir + 'v_shotgun-fire01.egg',
            'altfire': sgDir + 'v_shotgun-altfire.egg',
            'reload1': sgDir + 'v_shotgun-reload1.egg',
            'reload2': sgDir + 'v_shotgun-reload2.egg',
            'reload3': sgDir + 'v_shotgun-reload3.egg'
        }
    ]
    sgFirePath = 'phase_14/hl2/v_shotgun/shotgun_fire7.wav'
    sgEmptyPath = 'phase_14/hl2/v_shotgun/shotgun_empty.wav'
    sgDblFirePath = 'phase_14/hl2/v_shotgun/shotgun_dbl_fire7.wav'
    sgPumpPath = 'phase_14/hl2/v_shotgun/shotgun_cock.wav'
    sgReloadPaths = [
        'phase_14/hl2/v_shotgun/shotgun_reload1.wav',
        'phase_14/hl2/v_shotgun/shotgun_reload2.wav',
        'phase_14/hl2/v_shotgun/shotgun_reload3.wav'
    ]

    actionIdle = 0
    actionPump = 1
    actionBeginReload = 5
    actionEndReload = 6
    actionReload = 2
    actionFire = 3
    actionDblFire = 4
    actionDraw = 7

    actionLengths = {
        actionIdle: 0,
        actionPump: 0.666666666667,
        actionReload: 0.5,
        actionBeginReload: 0.625,
        actionEndReload: 0.541666666667,
        actionFire: 0.416666666667,
        actionDblFire: 0.625,
        actionDraw: 0.916666666667
    }

    def __init__(self):
        Gag.__init__(self)
        self.sgViewModel = None

        self.fireSound = base.audio3d.loadSfx(self.sgFirePath)
        self.dblFireSound = base.audio3d.loadSfx(self.sgDblFirePath)
        self.pumpSound = base.audio3d.loadSfx(self.sgPumpPath)
        self.emptySound = base.audio3d.loadSfx(self.sgEmptyPath)
        self.reloadSounds = []
        for rl in self.sgReloadPaths:
            self.reloadSounds.append(base.audio3d.loadSfx(rl))

        self.maxClip = 6
        self.clip = 6

        self.action = self.actionIdle
        self.actionStartTime = 0
        self.nextAction = None

        self.needsPump = False

    def _handleShotSomething(self, intoNP, hitPos, distance):
        avNP = intoNP.getParent()

        if base.localAvatarReachable() and self.isLocal():
            for obj in base.avatars:
                if CIGlobals.isAvatar(obj) and obj.getKey() == avNP.getKey():
                    obj.handleHitByToon(self.avatar, self.getID(), distance)

        vm = self.getViewModel()
        fpsCam = self.getFPSCam()
        track = Sequence()

        if action == self.actionIdle:
            track.append(Func(vm.loop, "idle"))
        elif action == self.actionDraw:
            track.append(ActorInterval(vm, "draw"))
        elif action == self.actionPump:
            track.append(Func(self.pumpSound.play))
            track.append(ActorInterval(vm, "pump"))

        elif action == self.actionFire:
            camQuat = camera.getQuat(render)
            pFrom = camera.getPos(render)
            pTo = pFrom + camQuat.xform(Vec3.forward() * 10000)
            hitPos = Point3(pTo)
            result = base.physicsWorld.rayTestClosest(pFrom, pTo,
                                                      CIGlobals.WorldGroup)
            if result.hasHit():
                node = result.getNode()
                hitPos = result.getHitPos()
                distance = (hitPos - pFrom).length()
                self._handleShotSomething(NodePath(node), hitPos, distance)

            self.clip -= 1
            fpsCam = self.getFPSCam()
            if base.localAvatar.isFirstPerson():
                fpsCam.addViewPunch(
                    Vec3(random.uniform(-2, 2), random.uniform(2, 1), 0))

            base.localAvatar.sendUpdate('usedGag', [self.id])

            track.append(Func(self.fireSound.play))
            track.append(ActorInterval(vm, "fire"))

        elif action == self.actionDblFire:
            track.append(Func(self.dblFireSound.play))
            track.append(ActorInterval(vm, "altfire"))
        elif action == self.actionReload:
            sound = random.choice(self.reloadSounds)
            track.append(Func(sound.play))
            track.append(ActorInterval(vm, "reload2"))
        elif action == self.actionBeginReload:
            track.append(ActorInterval(vm, "reload1"))
        elif action == self.actionEndReload:
            track.append(ActorInterval(vm, "reload3"))

        fpsCam.setVMAnimTrack(track)

    def __tick(self, task):
        complete = self.isActionComplete()

        if complete and self.nextAction is None:
            nextAction = self.actionIdle
            if self.action == self.actionFire:
                if self.clip <= 0:
                    self.needsPump = True
                    nextAction = self.actionBeginReload
                else:
                    nextAction = self.actionPump
            elif self.action == self.actionBeginReload:
                nextAction = self.actionReload
            elif self.action == self.actionReload:
                self.clip += 1
                if self.clip < self.maxClip and self.clip < self.avatar.backpack.getSupply(
                        self.getID()):
                    nextAction = self.actionReload
                else:
                    nextAction = self.actionEndReload
            elif self.action == self.actionEndReload:
                if self.needsPump:
                    nextAction = self.actionPump
                    self.needsPump = False
                else:
                    nextAction = self.actionIdle
            elif self.action == self.actionDraw:
                if self.clip <= 0:
                    self.needsPump = True
                    nextAction = self.actionBeginReload
                elif self.needsPump:
                    nextAction = self.actionPump
                    self.needsPump = False
                else:
                    nextAction = self.actionIdle

            if self.action != nextAction or nextAction != self.actionIdle:
                self.setAction(nextAction)

        elif ((complete) or (not complete and self.action == self.actionPump
                             and self.getActionTime() >= 0.5
                             and self.nextAction == self.actionFire)):

            self.setAction(self.nextAction)
            self.nextAction = None

        return task.cont

    def __doReload(self):
        if self.action == self.actionIdle and self.clip < self.maxClip:
            self.setNextAction(self.actionBeginReload)

    @classmethod
    def doPrecache(cls):
        precacheActor(cls.sgActorDef)

        precacheSound(cls.sgFirePath)
        precacheSound(cls.sgDblFirePath)
        precacheSound(cls.sgPumpPath)
        precacheSound(cls.sgEmptyPath)
        for rl in cls.sgReloadPaths:
            precacheSound(rl)

    def __doBob(self):
        self.setAnimTrack(self.getBobSequence('firehose', 30, 30, 1.0),
                          startNow=True,
                          looping=True)

    def equip(self):
        Gag.equip(self)

        base.audio3d.attachSoundToObject(self.fireSound, self.avatar)
        base.audio3d.attachSoundToObject(self.dblFireSound, self.avatar)
        base.audio3d.attachSoundToObject(self.pumpSound, self.avatar)
        base.audio3d.attachSoundToObject(self.emptySound, self.avatar)
        for s in self.reloadSounds:
            base.audio3d.attachSoundToObject(s, self.avatar)

        if self.isLocal():
            self.sgViewModel = Actor(self.sgActorDef[0], self.sgActorDef[1])
            self.sgViewModel.node().setBounds(OmniBoundingVolume())
            self.sgViewModel.node().setFinal(1)
            self.sgViewModel.setBlend(
                frameBlend=base.config.GetBool('interpolate-frames', False))
            self.sgViewModel.setH(180)
            self.sgViewModel.find("**/shell").setBSPMaterial(
                'phase_14/hl2/casing01.mat')

            fpsCam = self.getFPSCam()
            fpsCam.swapViewModel(self.sgViewModel, 54.0)
            self.setAction(self.actionDraw)
            self.accept('r', self.__doReload)

            taskMgr.add(self.__tick, "HL2ShotgunTick")

        self.gag.setPosHprScale(-0.03, 1.19, -0.14, 2.29, 347.01, 45, 2, 2, 2)
        toonTrack = Sequence(Func(self.avatar.setForcedTorsoAnim, 'firehose'),
                             self.getAnimationTrack('firehose', endFrame=30),
                             Func(self.__doBob))
        self.setAnimTrack(toonTrack, startNow=True)

    def start(self):

        Gag.start(self)

        if self.isLocal():
            fpsCam = self.getFPSCam()
            if self.action in [
                    self.actionReload, self.actionIdle, self.actionBeginReload,
                    self.actionEndReload, self.actionPump
            ]:

                if self.clip <= 0:
                    self.emptySound.play()
                    return

                self.setNextAction(self.actionFire)
        else:
            self.fireSound.play()

    def unEquip(self):
        Gag.unEquip(self)

        if self.isLocal():
            self.getFPSCam().restoreViewModel()
            self.sgViewModel.cleanup()
            self.sgViewModel.removeNode()
            self.sgViewModel = None
            if self.action == self.actionFire:
                self.needsPump = True
            self.ignore('r')
            taskMgr.remove("HL2ShotgunTick")
Beispiel #42
0
class DistributedGeyserFountain(DistributedNode.DistributedNode):
    def __init__(self, tlr):
        DistributedNode.DistributedNode.__init__(self, tlr)
        NodePath.__init__(self, 'dgaFountain')
        self.geyserEffectPlaying = False
        self.geyserTrack = None

    def announceGenerate(self):
        DistributedNode.DistributedNode.announceGenerate(self)
        self.geyserModel = loader.loadModel(
            'phase_6/models/golf/golf_geyser_model')
        self.geyserSound = loader.loadSfx(
            'phase_6/audio/sfx/OZ_Geyser_No_Toon.mp3')
        self.fountainModel = loader.loadModel(
            'phase_8/models/props/tt_m_ara_dga_fountain')
        self.fountainModel.reparentTo(self)
        self.fountainModel.find('**/fountainHead_dga').removeNode()
        geyserPlacer = self.attachNewNode('geyserPlacer')
        geyserPlacer.setPos(0, 0, 4)
        self.geyserSoundInterval = SoundInterval(self.geyserSound,
                                                 node=geyserPlacer,
                                                 listenerNode=base.camera,
                                                 seamlessLoop=False,
                                                 volume=0.6,
                                                 cutOff=120)
        self.geyserActor = Actor(self.geyserModel)
        self.geyserActor.loadAnims({'idle': 'phase_6/models/golf/golf_geyser'})
        self.geyserActor.reparentTo(geyserPlacer)
        self.geyserActor.setScale(0.01)
        self.geyserActor.setPlayRate(8.6, 'idle')
        self.geyserActor.loop('idle')
        self.geyserActor.setDepthWrite(0)
        self.geyserActor.setTwoSided(True, 11)
        self.geyserActor.setColorScale(1)
        self.geyserActor.setBin('fixed', 0)
        mesh = self.geyserActor.find('**/mesh_tide1')
        joint = self.geyserActor.find('**/uvj_WakeWhiteTide1')
        mesh.setTexProjector(mesh.findTextureStage('default'), joint,
                             self.geyserActor)
        self.geyserActor.setZ(geyserPlacer.getZ() - 10.0)
        self.geyserPos = geyserPlacer.getPos()
        self.geyserPlacer = geyserPlacer
        self.triggerName = self.uniqueName('trigger')
        cs = CollisionSphere(0, 0, -1.4, 4)
        cs.setTangible(0)
        cn = CollisionNode(self.triggerName)
        cn.addSolid(cs)
        cn.setIntoCollideMask(OTPGlobals.WallBitmask)
        trigger = self.attachNewNode(cn)
        self.accept('enter%s' % self.triggerName, self.handleEnterSphere)

    def handleEnterSphere(self, collisionEntry):
        self.b_playGeyserEffect()

    def toggleGeyserEffectPlaying(self):
        self.geyserEffectPlaying = not self.geyserEffectPlaying

    def b_playGeyserEffect(self):
        self.playGeyserEffect()
        self.d_playGeyserEffect()

    def d_playGeyserEffect(self):
        self.sendUpdate('playGeyserEffect')

    def playGeyserEffect(self):
        if self.geyserEffectPlaying:
            return None
        self.toggleGeyserEffectPlaying()
        time, maxSize = 1, 0.12
        self.geyserTrack = Sequence()
        upPos = Vec3(self.geyserPos[0], self.geyserPos[1],
                     (self.geyserPos[2] - 8.0))
        downPos = Vec3(self.geyserPos[0], self.geyserPos[1],
                       (self.geyserPos[2] - 8.0))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, (2 * time), 0.1, 0.01),
                LerpPosInterval(self.geyserActor, (2 * time),
                                pos=downPos,
                                startPos=downPos)))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, time, maxSize, 0.1),
                LerpPosInterval(self.geyserActor,
                                time,
                                pos=upPos,
                                startPos=downPos)))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, (2 * time), 0.1, maxSize),
                LerpPosInterval(self.geyserActor, (2 * time),
                                pos=downPos,
                                startPos=upPos)))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, time, maxSize, 0.1),
                LerpPosInterval(self.geyserActor,
                                time,
                                pos=upPos,
                                startPos=downPos)))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, (2 * time), 0.1, maxSize),
                LerpPosInterval(self.geyserActor, (2 * time),
                                pos=downPos,
                                startPos=upPos)))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, time, maxSize, 0.1),
                LerpPosInterval(self.geyserActor,
                                time,
                                pos=upPos,
                                startPos=downPos)))
        self.geyserTrack.append(
            Parallel(
                LerpScaleInterval(self.geyserActor, (4 * time), 0.01, maxSize),
                LerpPosInterval(self.geyserActor, (4 * time),
                                pos=downPos,
                                startPos=upPos)))
        self.geyserTrack.append(Func(self.toggleGeyserEffectPlaying))
        self.geyserTrack.start()
        self.geyserSoundInterval.start()
Beispiel #43
0
def make_cog(head, head_style, suit_style, suit_name, head_text="", path=""):
    """Return a skelecog version of any traditional cog as an Actor.

    Args:
        head (str): The name of the cog.
        head_style (str): The letter representing the suit style
            ("A", "B" or "C").
        suit_style (str): The letter representing the suit style
            ("A", "B" or "C").
        suit_name (str): The name of the suit.
        head_text (str, optional): The name of a head texture.
        path (str, optional): The file path to the Toontown phase files.
            Defaults to Panda3D's search path.

    Examples:
        from toontown import make_cog

        Hollywood = make_cog("yesman", "A", "A", "sell")
        Hollywood.loop("landing")

        RobberBaron = make_cog("yesman", "A", "A", "cash", "robber-baron")
        RobberBaron.loop("walk")

        SpinDoctor = make_cog("telemarketer", "B", "B", "law", "spin-doctor")
        SpinDoctor.loop("throw-paper")

    Returns:
        An instance of Panda3D's Actor class.
    """

    if path:
        path = pfile.fromOsSpecific("%s/" % path).getFullpath()

    abrv = {
        "sell":
        ("s", (0.95, 0.75, 0.95, 1.0), "Sales", (0.843, 0.745, 0.745, 1.0)),
        "cash":
        ("m", (0.65, 0.95, 0.85, 1.0), "Money", (0.749, 0.769, 0.749, 1.0)),
        "law":
        ("l", (0.75, 0.75, 0.95, 1.0), "Legal", (0.749, 0.776, 0.824, 1.0)),
        "boss":
        ("c", (0.95, 0.75, 0.75, 1.0), "Corp", (0.863, 0.776, 0.769, 1.0))
    }

    cog_color = {
        "coldcaller": ((0.75, 0.75, 0.95, 1.0), ""),
        "pennypincher": ((1.0, 0.5, 0.6, 1.0), ""),
        "legaleagle": ((0.25, 0.25, 0.5, 1.0), ""),
        "telemarketer": ((0.5, 0.8, 0.75, 1.0), "spin-doctor"),
        "movershaker": ((0.95, 0.95, 1.0, 1.0), "blood-sucker"),
        "bigcheese": ((0.75, 0.95, 0.75, 1.0), ""),
        "flunky": ((0.85, 0.55, 0.55, 1.0), "corporate-raider")
    }

    blazer = loader.loadTexture("%sphase_3.5/maps/%s_blazer.jpg" %
                                (path, abrv[suit_name][0]))
    sleeve = loader.loadTexture("%sphase_3.5/maps/%s_sleeve.jpg" %
                                (path, abrv[suit_name][0]))
    leg = loader.loadTexture("%sphase_3.5/maps/%s_leg.jpg" %
                             (path, abrv[suit_name][0]))

    animation_dict = cog_animation(suit_style, path)

    if suit_style in ("A", "B"):
        cog = Actor(
            "%sphase_3.5/models/char/suit%s-mod.bam" % (path, suit_style),
            animation_dict)
    else:
        cog = Actor("%sphase_3.5/models/char/suitC-mod.bam" % path,
                    animation_dict)

    if head_style in ("A", "B"):
        head_model = loader.loadModel(
            "%sphase_4/models/char/suit%s-heads.bam" % (path, head_style))
    else:
        head_model = loader.loadModel(
            "%sphase_3.5/models/char/suitC-heads.bam" % path)

    cog_head = head_model.find("**/%s" % head)
    joint_head = cog.find("**/joint_head")
    cog_head.reparentTo(joint_head)

    if head in cog_color.keys() and head_text == cog_color[head][1]:
        cog.find("**/hands").setColor(cog_color[head][0])
    else:
        cog.find("**/hands").setColor(abrv[suit_name][1])

    if head_text and head_text not in ("bottom-feeder", "corporate-raider"):
        head_texture = loader.loadTexture("%sphase_4/maps/%s.jpg" %
                                          (path, head_text))
        cog.findAllMatches("**/%s" % head).setTexture(head_texture, 1)
    elif head_text in ("bottom-feeder", "corporate-raider"):
        head_texture = loader.loadTexture("%sphase_3.5/maps/%s.jpg" %
                                          (path, head_text))
        cog.findAllMatches("**/%s" % head).setTexture(head_texture, 1)

    if head == "flunky" and not head_text:
        head_model.find("**/glasses").reparentTo(cog_head)

    icons = loader.loadModel("%sphase_3/models/gui/cog_icons.bam" % path)
    icon = icons.find("**/%sIcon" % abrv[suit_name][2]).copyTo(
        cog.find("**/joint_attachMeter"))
    icon.setPosHprScale(0.02, 0.05, 0.04, 180.0, 0.0, 0.0, 0.51, 0.51, 0.51)
    icon.setColor(abrv[suit_name][3])
    icons.removeNode()

    cog.find("**/legs").setTexture(leg, 1)
    cog.find("**/torso").setTexture(blazer, 1)
    cog.find("**/arms").setTexture(sleeve, 1)
    cog.reparentTo(render)

    return cog
Beispiel #44
0
class Grenade (Projectile):
    def __init__(self, pos, hpr, color, walker_v, name=None):
        super(Grenade, self).__init__(name)
        self.pos = Vec3(*pos)
        self.hpr = hpr
        self.move_divisor = 9
        self.color = color
        self.forward_m = .25
        self.walker_v = walker_v

    def create_node(self):
        self.model = Actor('grenade.egg')
        self.shell = self.model.find('**/shell')
        self.shell.set_color(*self.color)
        self.inner_top = self.model.find('**/inner_top')
        self.inner_bottom = self.model.find('**/inner_bottom')
        self.inner_top.set_color(*random.choice(ENGINE_COLORS))
        self.inner_bottom.set_color(*random.choice(ENGINE_COLORS))
        self.model.set_scale(GRENADE_SCALE)
        self.model.set_hpr(0,0,0)
        self.spin_bone = self.model.controlJoint(None, 'modelRoot', 'grenade_bone')
        return self.model

    def create_solid(self):
        node = BulletRigidBodyNode(self.name)
        node.set_angular_damping(.9)
        node_shape = BulletSphereShape(.08)
        node.add_shape(node_shape)
        node.set_mass(.5)
        return node

    def attached(self):
        self.node.set_pos(self.pos)
        self.node.set_hpr(self.hpr)
        self.world.register_updater(self)
        self.world.register_collider(self)
        self.solid.setIntoCollideMask(NO_COLLISION_BITS)
        self.solid.set_gravity(DEFAULT_GRAVITY*4.5)
        grenade_iv = self.world.scene.get_relative_vector(self.node, Vec3(0,8.5,13.5))
        grenade_iv += (self.walker_v * 1/2)
        self.solid.apply_impulse(grenade_iv, Point3(*self.pos))

    def decompose(self):
        clist = list(self.color)
        clist.extend([1])
        expl_colors = [clist]
        expl_colors.extend(ENGINE_COLORS)
        expl_pos = self.node.get_pos(self.world.scene)
        for c in expl_colors:
            self.world.attach(TriangleExplosion(expl_pos, 1, size=.1, color=c, lifetime=40))
        self.world.garbage.add(self)

    def update(self, dt):
        self.inner_top.set_color(*random.choice(ENGINE_COLORS))
        self.inner_bottom.set_color(*random.choice(ENGINE_COLORS))
        result = self.world.physics.contact_test(self.solid)
        self.spin_bone.set_hpr(self.spin_bone, 0,0,10)
        contacts = result.getContacts()
        if len(contacts) > 0:
            hit_node = contacts[0].get_node1().get_name()
            if hit_node.endswith("_walker_cap"):
                return
            clist = list(self.color)
            clist.extend([1])
            expl_colors = [clist]
            expl_colors.extend(ENGINE_COLORS)
            expl_pos = self.node.get_pos(self.world.scene)
            for c in expl_colors:
                self.world.attach(TriangleExplosion(expl_pos, 3, size=.1, color=c, lifetime=80,))
            self.world.do_explosion(self.node, 3, 100)
            self.world.garbage.add(self)
class SnapshotRenderer:
    def __init__(self, dnaString):
        self.dnaString = dnaString
        loadModels()
        compileGlobalAnimList()
        self.makeFromNetString(dnaString)
        self.toon = Actor()
        self.generateToon()
        self.renderSnapshot()

    def makeFromNetString(self, string):
        dg = PyDatagram(string)
        dgi = PyDatagramIterator(dg)
        self.type = dgi.getFixedString(1)
        if self.type == 't':
            headIndex = dgi.getUint8()
            torsoIndex = dgi.getUint8()
            legsIndex = dgi.getUint8()
            self.head = toonHeadTypes[headIndex]
            self.torso = toonTorsoTypes[torsoIndex]
            self.legs = toonLegTypes[legsIndex]
            gender = dgi.getUint8()
            if gender == 1:
                self.gender = 'm'
            else:
                self.gender = 'f'
            self.topTex = dgi.getUint8()
            self.topTexColor = dgi.getUint8()
            self.sleeveTex = dgi.getUint8()
            self.sleeveTexColor = dgi.getUint8()
            self.botTex = dgi.getUint8()
            self.botTexColor = dgi.getUint8()
            self.armColor = dgi.getUint8()
            self.gloveColor = dgi.getUint8()
            self.legColor = dgi.getUint8()
            self.headColor = dgi.getUint8()
        else:
            notify.error('unknown avatar type: ', self.type)

    def getAnimal(self):
        if self.head[0] == 'd':
            return 'dog'
        elif self.head[0] == 'c':
            return 'cat'
        elif self.head[0] == 'm':
            return 'mouse'
        elif self.head[0] == 'h':
            return 'horse'
        elif self.head[0] == 'r':
            return 'rabbit'
        elif self.head[0] == 'f':
            return 'duck'
        elif self.head[0] == 'p':
            return 'monkey'
        elif self.head[0] == 'b':
            return 'bear'
        elif self.head[0] == 's':
            return 'pig'
        else:
            notify.error('unknown headStyle: ', self.head[0])

    def getArmColor(self):
        try:
            return allColorsList[self.armColor]
        except:
            return allColorsList[0]

    def getLegColor(self):
        try:
            return allColorsList[self.legColor]
        except:
            return allColorsList[0]

    def getHeadColor(self):
        try:
            return allColorsList[self.headColor]
        except:
            return allColorsList[0]

    def getGloveColor(self):
        try:
            return allColorsList[self.gloveColor]
        except:
            return allColorsList[0]

    def getGender(self):
        return self.gender

    def generateToon(self):
        self.setLODs()
        self.generateToonLegs()
        self.generateToonHead(1, ('1000', '500', '250'))
        self.generateToonTorso()
        self.generateToonColor()
        self.parentToonParts()
        # self.rescaleToon()
        # self.resetHeight()
        # self.setupToonNodes()
        self.toon.reparentTo(render)
        self.toon.setPos(0, 5, -3)
        self.toon.setH(180)
        self.toon.getPart('head', '1000').setR(10)
        self.toon.pose('neutral', 0)

    def generateToonLegs(self, copy=1):
        global Preloaded
        legStyle = self.legs
        filePrefix = LegDict.get(legStyle)
        if filePrefix is None:
            print('unknown leg style: %s' % legStyle)
        self.toon.loadModel(Preloaded[filePrefix + '-1000'], 'legs', '1000',
                            True)
        self.toon.loadModel(Preloaded[filePrefix + '-500'], 'legs', '500',
                            True)
        self.toon.loadModel(Preloaded[filePrefix + '-250'], 'legs', '250',
                            True)
        if not copy:
            self.toon.showPart('legs', '1000')
            self.toon.showPart('legs', '500')
            self.toon.showPart('legs', '250')
        self.toon.loadAnims(LegsAnimDict[legStyle], 'legs', '1000')
        self.toon.loadAnims(LegsAnimDict[legStyle], 'legs', '500')
        self.toon.loadAnims(LegsAnimDict[legStyle], 'legs', '250')
        self.toon.findAllMatches('**/boots_short').stash()
        self.toon.findAllMatches('**/boots_long').stash()
        self.toon.findAllMatches('**/shoes').stash()
        return

    def generateToonTorso(self, copy=1, genClothes=1):
        global Preloaded
        torsoStyle = self.torso
        filePrefix = TorsoDict.get(torsoStyle)
        if filePrefix is None:
            self.notify.error('unknown torso style: %s' % torsoStyle)
        self.toon.loadModel(Preloaded[filePrefix + '-1000'], 'torso', '1000',
                            True)
        if len(torsoStyle) == 1:
            self.toon.loadModel(Preloaded[filePrefix + '-1000'], 'torso',
                                '500', True)
            self.toon.loadModel(Preloaded[filePrefix + '-1000'], 'torso',
                                '250', True)
        else:
            self.toon.loadModel(Preloaded[filePrefix + '-500'], 'torso', '500',
                                True)
            self.toon.loadModel(Preloaded[filePrefix + '-250'], 'torso', '250',
                                True)
        if not copy:
            self.toon.showPart('torso', '1000')
            self.toon.showPart('torso', '500')
            self.toon.showPart('torso', '250')
        self.toon.loadAnims(TorsoAnimDict[torsoStyle], 'torso', '1000')
        self.toon.loadAnims(TorsoAnimDict[torsoStyle], 'torso', '500')
        self.toon.loadAnims(TorsoAnimDict[torsoStyle], 'torso', '250')
        if genClothes == 1 and not len(torsoStyle) == 1:
            self.generateToonClothes()
        return

    def generateToonClothes(self, fromNet=0):
        swappedTorso = 0
        if self.toon.hasLOD():
            if self.getGender() == 'f' and fromNet == 0:
                try:
                    bottomPair = GirlBottoms[self.botTex]
                except:
                    bottomPair = GirlBottoms[0]
            try:
                texName = Shirts[self.topTex]
            except:
                texName = Shirts[0]

            shirtTex = loader.loadTexture(texName, okMissing=True)
            if shirtTex is None:
                shirtTex = loader.loadTexture(Shirts[0])
            shirtTex.setMinfilter(Texture.FTLinearMipmapLinear)
            shirtTex.setMagfilter(Texture.FTLinear)
            try:
                shirtColor = ClothesColors[self.topTexColor]
            except:
                shirtColor = ClothesColors[0]

            try:
                texName = Sleeves[self.sleeveTex]
            except:
                texName = Sleeves[0]

            sleeveTex = loader.loadTexture(texName, okMissing=True)
            if sleeveTex is None:
                self.sendLogSuspiciousEvent('failed to load texture %s' %
                                            texName)
                sleeveTex = loader.loadTexture(Sleeves[0])
            sleeveTex.setMinfilter(Texture.FTLinearMipmapLinear)
            sleeveTex.setMagfilter(Texture.FTLinear)
            try:
                sleeveColor = ClothesColors[self.sleeveTexColor]
            except:
                sleeveColor = ClothesColors[0]

            if self.getGender() == 'm':
                try:
                    texName = BoyShorts[self.botTex]
                except:
                    texName = BoyShorts[0]

            else:
                try:
                    texName = GirlBottoms[self.botTex][0]
                except:
                    texName = GirlBottoms[0][0]

            bottomTex = loader.loadTexture(texName, okMissing=True)
            if bottomTex is None:
                self.sendLogSuspiciousEvent('failed to load texture %s' %
                                            texName)
                if self.getGender() == 'm':
                    bottomTex = loader.loadTexture(BoyShorts[0])
                else:
                    bottomTex = loader.loadTexture(GirlBottoms[0][0])
            bottomTex.setMinfilter(Texture.FTLinearMipmapLinear)
            bottomTex.setMagfilter(Texture.FTLinear)
            try:
                bottomColor = ClothesColors[self.botTexColor]
            except:
                bottomColor = ClothesColors[0]

            darkBottomColor = bottomColor * 0.5
            darkBottomColor.setW(1.0)
            for lodName in self.toon.getLODNames():
                thisPart = self.toon.getPart('torso', lodName)
                top = thisPart.find('**/torso-top')
                top.setTexture(shirtTex, 1)
                top.setColor(shirtColor)
                sleeves = thisPart.find('**/sleeves')
                sleeves.setTexture(sleeveTex, 1)
                sleeves.setColor(sleeveColor)
                bottoms = thisPart.findAllMatches('**/torso-bot')
                for bottomNum in xrange(0, bottoms.getNumPaths()):
                    bottom = bottoms.getPath(bottomNum)
                    bottom.setTexture(bottomTex, 1)
                    bottom.setColor(bottomColor)

                caps = thisPart.findAllMatches('**/torso-bot-cap')
                caps.setColor(darkBottomColor)

        return swappedTorso

    def generateToonColor(self):
        parts = self.toon.findAllMatches('**/head*')
        parts.setColor(self.getHeadColor())
        animalType = self.getAnimal()
        if animalType == 'cat' or animalType == 'rabbit' or animalType == 'bear' or animalType == 'mouse' or animalType == 'pig':
            parts = self.toon.findAllMatches('**/ear?-*')
            parts.setColor(self.getHeadColor())

        armColor = self.getArmColor()
        gloveColor = self.getGloveColor()
        legColor = self.getLegColor()
        for lodName in self.toon.getLODNames():
            torso = self.toon.getPart('torso', lodName)
            if len(self.torso) == 1:
                parts = torso.findAllMatches('**/torso*')
                parts.setColor(armColor)
            for pieceName in ('arms', 'neck'):
                piece = torso.find('**/' + pieceName)
                piece.setColor(armColor)

            hands = torso.find('**/hands')
            hands.setColor(gloveColor)
            legs = self.toon.getPart('legs', lodName)
            for pieceName in ('legs', 'feet'):
                piece = legs.find('**/%s;+s' % pieceName)
                piece.setColor(legColor)

    def generateToonHead(self, copy, lods):
        headStyle = self.head
        fix = None
        if headStyle == 'dls':
            filePrefix = HeadDict['dls']
            headHeight = 0.75
        elif headStyle == 'dss':
            filePrefix = HeadDict['dss']
            headHeight = 0.5
        elif headStyle == 'dsl':
            filePrefix = HeadDict['dsl']
            headHeight = 0.5
        elif headStyle == 'dll':
            filePrefix = HeadDict['dll']
            headHeight = 0.75
        elif headStyle == 'cls':
            filePrefix = HeadDict['c']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'css':
            filePrefix = HeadDict['c']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'csl':
            filePrefix = HeadDict['c']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'cll':
            filePrefix = HeadDict['c']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == 'hls':
            filePrefix = HeadDict['h']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'hss':
            filePrefix = HeadDict['h']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'hsl':
            filePrefix = HeadDict['h']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'hll':
            filePrefix = HeadDict['h']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == 'mls':
            filePrefix = HeadDict['m']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'mss':
            filePrefix = HeadDict['m']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'rls':
            filePrefix = HeadDict['r']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'rss':
            filePrefix = HeadDict['r']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'rsl':
            filePrefix = HeadDict['r']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'rll':
            filePrefix = HeadDict['r']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == 'fls':
            filePrefix = HeadDict['f']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'fss':
            filePrefix = HeadDict['f']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'fsl':
            filePrefix = HeadDict['f']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'fll':
            filePrefix = HeadDict['f']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == 'pls':
            filePrefix = HeadDict['p']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'pss':
            filePrefix = HeadDict['p']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'psl':
            filePrefix = HeadDict['p']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'pll':
            filePrefix = HeadDict['p']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == 'bls':
            filePrefix = HeadDict['b']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'bss':
            filePrefix = HeadDict['b']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'bsl':
            filePrefix = HeadDict['b']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'bll':
            filePrefix = HeadDict['b']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        elif headStyle == 'sls':
            filePrefix = HeadDict['s']
            fix = self.__fixHeadLongShort
            headHeight = 0.75
        elif headStyle == 'sss':
            filePrefix = HeadDict['s']
            fix = self.__fixHeadShortShort
            headHeight = 0.5
        elif headStyle == 'ssl':
            filePrefix = HeadDict['s']
            fix = self.__fixHeadShortLong
            headHeight = 0.5
        elif headStyle == 'sll':
            filePrefix = HeadDict['s']
            fix = self.__fixHeadLongLong
            headHeight = 0.75
        else:
            ToonHead.notify.error('unknown head style: %s' % headStyle)
        if len(lods) == 1:
            self.toon.loadModel(filePrefix + lods[0], 'head', 'lodRoot', copy)
            if not copy:
                self.toon.showAllParts('head')
            if fix != None:
                fix(None, copy)
            self.__lods = lods
            self.__headStyle = headStyle
            self.__copy = copy
        else:
            for lod in lods:
                self.toon.loadModel(filePrefix + lod, 'head', lod, copy)
                if not copy:
                    self.toon.showAllParts('head', lod)
                if fix != None:
                    fix(lod, copy)
                self.__lods = lods
                self.__headStyle = headStyle
                self.__copy = copy

        # self.setupEyelashes()
        self.setupMuzzles()
        return headHeight

    def setupMuzzles(self):
        self.__muzzles = []
        self.__surpriseMuzzles = []
        self.__angryMuzzles = []
        self.__sadMuzzles = []
        self.__smileMuzzles = []
        self.__laughMuzzles = []

        def hideAddNonEmptyItemToList(item, list):
            if not item.isEmpty():
                item.hide()
                list.append(item)

        def hideNonEmptyItem(item):
            if not item.isEmpty():
                item.hide()

        if self.toon.hasLOD():
            for lodName in self.toon.getLODNames():
                animal = self.getAnimal()
                if animal != 'dog':
                    muzzle = self.toon.find('**/' + lodName +
                                            '/**/muzzle*neutral')
                else:
                    muzzle = self.toon.find('**/' + lodName + '/**/muzzle*')
                    if lodName == '1000' or lodName == '500':
                        filePrefix = DogMuzzleDict[self.head]
                        muzzles = self.toon.loadModel(filePrefix + lodName)
                        if base.config.GetBool('want-new-anims', 1):
                            if not self.toon.find(
                                    '**/' + lodName +
                                    '/**/__Actor_head/def_head').isEmpty():
                                muzzles.reparentTo(
                                    self.toon.find(
                                        '**/' + lodName +
                                        '/**/__Actor_head/def_head'))
                            else:
                                muzzles.reparentTo(
                                    self.toon.find('**/' + lodName +
                                                   '/**/joint_toHead'))
                        elif self.toon.find('**/' + lodName +
                                            '/**/joint_toHead'):
                            muzzles.reparentTo(
                                self.toon.find('**/' + lodName +
                                               '/**/joint_toHead'))
                surpriseMuzzle = self.toon.find('**/' + lodName +
                                                '/**/muzzle*surprise')
                angryMuzzle = self.toon.find('**/' + lodName +
                                             '/**/muzzle*angry')
                sadMuzzle = self.toon.find('**/' + lodName + '/**/muzzle*sad')
                smileMuzzle = self.toon.find('**/' + lodName +
                                             '/**/muzzle*smile')
                laughMuzzle = self.toon.find('**/' + lodName +
                                             '/**/muzzle*laugh')
                self.__muzzles.append(muzzle)
                hideAddNonEmptyItemToList(surpriseMuzzle,
                                          self.__surpriseMuzzles)
                hideAddNonEmptyItemToList(angryMuzzle, self.__angryMuzzles)
                hideAddNonEmptyItemToList(sadMuzzle, self.__sadMuzzles)
                hideAddNonEmptyItemToList(smileMuzzle, self.__smileMuzzles)
                hideAddNonEmptyItemToList(laughMuzzle, self.__laughMuzzles)

    def setupEyelashes(self):
        animal = self.head[0]
        model = self.toon.loadModel(EyelashDict[animal])
        if self.toon.hasLOD():
            head = self.toon.getPart('head', '1000')
        else:
            head = self.toon.getPart('head', 'lodRoot')
        length = self.head[1]
        if length == 'l':
            openString = 'open-long'
            closedString = 'closed-long'
        else:
            openString = 'open-short'
            closedString = 'closed-short'
        self.__eyelashOpen = model.find('**/' + openString).copyTo(head)
        self.__eyelashClosed = model.find('**/' + closedString).copyTo(head)
        model.removeNode()
        return

    def parentToonParts(self):
        if self.toon.hasLOD():
            for lodName in self.toon.getLODNames():
                if base.config.GetBool('want-new-anims', 1):
                    if not self.toon.getPart(
                            'torso', lodName).find('**/def_head').isEmpty():
                        self.toon.attach('head', 'torso', 'def_head', lodName)
                    else:
                        self.toon.attach('head', 'torso', 'joint_head',
                                         lodName)
                else:
                    self.toon.attach('head', 'torso', 'joint_head', lodName)
                self.toon.attach('torso', 'legs', 'joint_hips', lodName)
        else:
            self.toon.attach('head', 'torso', 'joint_head')
            self.toon.attach('torso', 'legs', 'joint_hips')

    def __fixHeadLongLong(self, lodName=None, copy=1):
        if lodName == None:
            searchRoot = self.toon
        else:
            searchRoot = self.toon.find('**/' + str(lodName))
        otherParts = searchRoot.findAllMatches('**/*short*')
        for partNum in xrange(0, otherParts.getNumPaths()):
            if copy:
                otherParts.getPath(partNum).removeNode()
            else:
                otherParts.getPath(partNum).stash()

        return

    def __fixHeadLongShort(self, lodName=None, copy=1):
        animalType = self.getAnimal()
        headStyle = self.head
        if lodName == None:
            searchRoot = self.toon
        else:
            searchRoot = self.toon.find('**/' + str(lodName))
        if animalType != 'duck' and animalType != 'horse':
            if animalType == 'rabbit':
                if copy:
                    searchRoot.find('**/ears-long').removeNode()
                else:
                    searchRoot.find('**/ears-long').hide()
            elif copy:
                searchRoot.find('**/ears-short').removeNode()
            else:
                searchRoot.find('**/ears-short').hide()
        if animalType != 'rabbit':
            if copy:
                searchRoot.find('**/eyes-short').removeNode()
            else:
                searchRoot.find('**/eyes-short').hide()
        if animalType != 'dog':
            if copy:
                searchRoot.find('**/joint_pupilL_short').removeNode()
                searchRoot.find('**/joint_pupilR_short').removeNode()
            else:
                searchRoot.find('**/joint_pupilL_short').stash()
                searchRoot.find('**/joint_pupilR_short').stash()
        if animalType != 'rabbit':
            muzzleParts = searchRoot.findAllMatches('**/muzzle-long*')
            for partNum in xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        else:
            muzzleParts = searchRoot.findAllMatches('**/muzzle-short*')
            for partNum in xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        return

    def __fixHeadShortLong(self, lodName=None, copy=1):
        animalType = self.getAnimal()
        headStyle = self.head
        if lodName == None:
            searchRoot = self.toon
        else:
            searchRoot = self.toon.find('**/' + str(lodName))
        if animalType != 'duck' and animalType != 'horse':
            if animalType == 'rabbit':
                if copy:
                    searchRoot.find('**/ears-short').removeNode()
                else:
                    searchRoot.find('**/ears-short').hide()
            elif copy:
                searchRoot.find('**/ears-long').removeNode()
            else:
                searchRoot.find('**/ears-long').hide()
        if animalType != 'rabbit':
            if copy:
                searchRoot.find('**/eyes-long').removeNode()
            else:
                searchRoot.find('**/eyes-long').hide()
        if animalType != 'dog':
            if copy:
                searchRoot.find('**/joint_pupilL_long').removeNode()
                searchRoot.find('**/joint_pupilR_long').removeNode()
            else:
                searchRoot.find('**/joint_pupilL_long').stash()
                searchRoot.find('**/joint_pupilR_long').stash()
        if copy:
            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 xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        else:
            muzzleParts = searchRoot.findAllMatches('**/muzzle-long*')
            for partNum in xrange(0, muzzleParts.getNumPaths()):
                if copy:
                    muzzleParts.getPath(partNum).removeNode()
                else:
                    muzzleParts.getPath(partNum).hide()

        return

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

        return

    def setLODs(self):
        self.toon.setLODNode()
        levelOneIn = base.config.GetInt('lod1-in', 20)
        levelOneOut = base.config.GetInt('lod1-out', 0)
        levelTwoIn = base.config.GetInt('lod2-in', 80)
        levelTwoOut = base.config.GetInt('lod2-out', 20)
        levelThreeIn = base.config.GetInt('lod3-in', 280)
        levelThreeOut = base.config.GetInt('lod3-out', 80)
        self.toon.addLOD(1000, levelOneIn, levelOneOut)
        self.toon.addLOD(500, levelTwoIn, levelTwoOut)
        self.toon.addLOD(250, levelThreeIn, levelThreeOut)

    def loadPhaseAnims(self, phaseStr='phase_3', loadFlag=1):
        if phaseStr == 'phase_3':
            animList = Phase3AnimList
        elif phaseStr == 'phase_3.5':
            animList = Phase3_5AnimList
        elif phaseStr == 'phase_4':
            animList = Phase4AnimList
        elif phaseStr == 'phase_5':
            animList = Phase5AnimList
        elif phaseStr == 'phase_5.5':
            animList = Phase5_5AnimList
        elif phaseStr == 'phase_6':
            animList = Phase6AnimList
        elif phaseStr == 'phase_9':
            animList = Phase9AnimList
        elif phaseStr == 'phase_10':
            animList = Phase10AnimList
        elif phaseStr == 'phase_12':
            animList = Phase12AnimList
        else:
            self.notify.error('Unknown phase string %s' % phaseStr)
        for key in LegDict.keys():
            for anim in animList:
                if loadFlag:
                    pass
                elif anim[0] in LegsAnimDict[key]:
                    if self.legs == key:
                        self.toon.unloadAnims([anim[0]], 'legs', None)

        for key in TorsoDict.keys():
            for anim in animList:
                if loadFlag:
                    pass
                elif anim[0] in TorsoAnimDict[key]:
                    if self.torso == key:
                        self.toon.unloadAnims([anim[0]], 'torso', None)

        for key in HeadDict.keys():
            if key.find('d') >= 0:
                for anim in animList:
                    if loadFlag:
                        pass
                    elif anim[0] in HeadAnimDict[key]:
                        if self.head == key:
                            self.toon.unloadAnims([anim[0]], 'head', None)

    def renderSnapshot(self):
        print 'Rendering Snapshot...'
        base.graphicsEngine.renderFrame()
        base.screenshot(namePrefix='snapshot-render',
                        defaultFilename=1,
                        source=None,
                        imageComment="")
Beispiel #46
0
class Toon(DirectObject.DirectObject):
	def __init__(self, taskMgr):
		#Establish where the current directory of the running file is
		self.currentDirectory = os.path.abspath(sys.path[0])
		self.pandaDirectory = Filename.fromOsSpecific(self.currentDirectory).getFullpath()
		
		#Define variables, particularly to tell if the model is moving
		self.isThrowing = False
		self.isMovingInY = False
		self.isTurning = False
		self.pieIsThrown = False
		self.movementHeading = ''
		self.turnHeading = ''
		self.speed = 0.0
		self.turnSpeed = 0.0
		self.health = 100
		
		#Set object variable to point to the global task manager
		self.taskMgr = taskMgr
		
		#Define pie node, which will serve as the flying part of the pie. Put it far enough away to not cause problems
		self.pieNode = NodePath('pieNode')
		self.pieNode.reparentTo(render)
		self.pieNode.setPos(100, 0, 0)
		
		#Load the pie model and define its scaling motion
		self.pie = loader.loadModel(self.pandaDirectory + "/resources/toon/models/tart.bam")
		self.scalePie = LerpScaleInterval(self.pie, 1, 1, 0)
		
		#Set up the Actor
		self.initActor()
		
		#Initialize animations
		self.toon.loop('neutral', 'torso')
		self.toon.loop('neutral', 'legs')
		
		#Define Y (Forwards/backwards) movement
		self.accept('arrow_up', self.moveInYStart, ['forward'])
		self.accept('arrow_up-up', self.moveInYEnd, ['forward'])
		self.accept('arrow_down', self.moveInYStart, ['backward'])
		self.accept('arrow_down-up', self.moveInYEnd, ['backward'])
		
		#Define turning movement
		self.accept('arrow_right', self.turnStart, ['right'])
		self.accept('arrow_right-up', self.turnEnd, ['right'])
		self.accept('arrow_left', self.turnStart, ['left'])
		self.accept('arrow_left-up', self.turnEnd, ['left'])
		
		#Define pie throwing animation control
		self.accept('control', self.attackStart)
		
		#Set up throwing interval and sequence
		self.throwTorso = self.toon.actorInterval('attackTorso', loop=0)
		self.throw = Sequence(Func(self.toggleIsThrowing),
									Parallel(self.throwTorso, self.scalePie),
									Func(self.toggleIsThrowing),
									Func(self.attackEnd)
									)
		
		#Tell the taskmanager to keep track of this task
		self.taskMgr.add(self.updateToon, 'Update Toon')
		
	def updateToon(self, task):
		#Update the player's position and heading
		if self.isMovingInY:
			self.toon.setY(self.toon, self.speed)
			
		if self.isTurning:
			self.toon.setH(self.toon, self.turnSpeed)
		
		return task.cont
		
	def toggleIsThrowing(self):
		self.isThrowing = not(self.isThrowing)
	
	def attackStart(self):
		#If the player is already throwing, ignore new request
		if self.isThrowing:
			return
		
		#Determine which group of animations to play
		if not self.isMovingInY and not self.isTurning:
			self.toon.loop('attackLegs')
		
		#Render the pie, then throw it!
		self.pie.setHpr(0,0,0)
		self.pie.reparentTo(self.toon.find('**/def_joint_right_hold'))
		self.taskMgr.doMethodLater(2.7, self.throwPie, 'throw pie')
		
		#Call the pre-defined sequence
		self.throw.start()
	
	def attackEnd(self):
		#Determine which animation to play after throwing
		if self.isMovingInY and self.speed > 0:
			self.toon.loop('run', 'torso')
			
		elif self.isMovingInY and self.speed < 0:
			self.toon.loop('walk', 'torso')
		
		elif self.isTurning:
			self.toon.loop('walk', 'torso')
		
		else:
			self.toon.loop('neutral', 'torso')
	
	def throwPie(self, task):
		#Get the current position and hpr of the pie for the pieNode
		self.pieNode.setPos(self.pie.getPos(render))
		pieHpr = Point3(self.toon.getH(render) + 90, self.pie.getP(render), 80)
		
		#Reparent the pie to the pieNode
		self.pie.reparentTo(self.pieNode)
		self.pie.setHpr(pieHpr)
		
		#Arch that pieNode puppy!
		self.flyingPie = ProjectileInterval(self.pieNode, startPos=self.pieNode.getPos(), 
											startVel=render.getRelativeVector(self.pie,Vec3(0,0,75)), duration=5)
		self.flyingPie.start()
		
		self.pieIsThrown = True
		
		return task.done
	
	def turnStart(self, direction):
		#If the player is already turning, ignore the new request
		if self.isTurning:
			return
		
		#Set the object heading to prevent pressing the right and left keys at the same time
		self.turnHeading = direction
		
		#If the player is moving in the Y direction...
		if self.isMovingInY:
			#And the player is moving backwards...
			if self.speed < 0:
				#Replace the run animation with walk and play it backwards
				self.toon.setPlayRate(-1, 'walk')
				
		#If the player is not moving
		else:
			#Play the forward plain walking animations
			self.toon.setPlayRate(1, 'walk')
			self.toon.loop('walk', 'torso')
			self.toon.loop('walk', 'legs')
		
		#Determine which heading the player will turn
		if direction == 'right':
			self.turnSpeed = -0.7
		elif direction == 'left':
			self.turnSpeed = 0.7
		
		#Tell task manager to start turning
		self.isTurning = True
		
	def turnEnd(self, direction):
		#If the requested direction conflicts with the heading, ignore the request
		if direction != self.turnHeading:
			return
			
		#If the player is not moving in the Y direction...
		if not self.isMovingInY:
			#Make the animation play neutral before stopping to turn
			self.toon.loop('neutral', 'torso')
			self.toon.loop('neutral', 'legs')
		
		#Tell task manager to stop turning
		self.isTurning = False
		
	def moveInYStart(self, direction):
		#If the player is already moving, ignore the new request
		if self.isMovingInY:
			return
		
		#Set the object heading to prevent pressing the up and down keys at the same time
		self.movementHeading = direction
		
		#If the up key is pressed...
		if direction == 'forward':
			#Set a positive speed and make the player run
			self.speed = 0.6
			self.toon.loop('run', 'torso')
			self.toon.loop('run', 'legs')
		
		#Otherwise...
		elif direction == 'backward':
			#Set a negative speed and make the player walk backwards
			self.speed = -0.3
			self.toon.setPlayRate(-1, 'walk')
			self.toon.loop('walk', 'torso')
			self.toon.loop('walk', 'legs')
		
		#Tell the task manager to start moving in local Y
		self.isMovingInY = True
			
	def moveInYEnd(self, direction):
		#If the requested direction conflicts with the heading, ignore the request
		if direction != self.movementHeading:
			return
		
		#If the player is not turning...
		if not self.isTurning:
			#Set the speed to positive and have the player idle
			self.speed = 0.6
			self.toon.loop('neutral', 'torso')
			self.toon.loop('neutral', 'legs')
			
		#Otherwise...
		else:
			#Make the player walk instead
			self.toon.setPlayRate(1, 'walk')
			self.speed = 0.6
			self.toon.loop('walk', 'torso')
			self.toon.loop('walk', 'legs')
		
		#Tell the task manager to stop moving in local Y
		self.isMovingInY = False
		
	def initActor(self):
		#Create the toon!
		self.toon = Actor({'torso': self.pandaDirectory + '/resources/toon/models/tt_a_chr_dgl_shorts_torso_1000.bam',
							'legs': self.pandaDirectory + '/resources/toon/models/tt_a_chr_dgm_shorts_legs_1000.bam'},
							{'torso':{
							'neutral': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgl_shorts_torso_neutral.bam',
							'run': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgl_shorts_torso_run.bam',
							'attackTorso': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgl_shorts_torso_pie-throw.bam',
							'walk': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgl_shorts_torso_walk.bam'
							},
							'legs':{
							'neutral': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgm_shorts_legs_neutral.bam',
							'run': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgm_shorts_legs_run.bam',
							'attackLegs': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgm_shorts_legs_pie-throw.bam',
							'walk': self.pandaDirectory + '/resources/toon/animations/tt_a_chr_dgm_shorts_legs_walk.bam'
							}})
		self.toon.attach('torso', 'legs', 'joint_hips')
		self.toon.find('**/neck').setColor(1, 1, 0)
		self.toon.find('**/legs').setColor(1, 1, 0)
		self.toon.find('**/arms').setColor(1, 1, 0)
		self.toon.find('**/hands').setColor(1, 1, 1)
		
		#Set textures and remove unnecessary models
		self.toon.find('**/sleeves').setTexture(loader.loadTexture(self.pandaDirectory + '/resources/toon/textures/ttr_t_chr_avt_shirtSleeve_cashbotCrusher.jpg'),1)
		self.toon.find('**/torso-top').setTexture(loader.loadTexture(self.pandaDirectory + '/resources/toon/textures/ttr_t_chr_avt_shirt_cashbotCrusher.jpg'),1)
		self.toon.find('**/torso-bot').setTexture(loader.loadTexture(self.pandaDirectory + '/resources/toon/textures/ttr_t_chr_avt_shorts_cashbotCrusher.jpg'),1)
		self.toon.find('**/shoes').setTexture(loader.loadTexture(self.pandaDirectory + '/resources/toon/textures/ttr_t_chr_avt_acc_sho_cashbotCrusher.jpg'),1)
		self.toon.find('**/feet').removeNode()
		self.toon.find('**/boots_short').removeNode()
		self.toon.find('**/boots_long').removeNode()
		
		#Create the toon head!
		self.toonHead = loader.loadModel(self.pandaDirectory + '/resources/toon/models/tt_a_chr_dgm_skirt_head_1000.bam')
		self.toonHead.reparentTo(self.toon.find('**/def_head'))
		self.toonHead.find('**/head').setColor(1, 1, 0)
		self.toonHead.find('**/head-front').setColor(1, 1, 0)
		
		#Add a cute hat
		self.topHat = loader.loadModel(self.pandaDirectory + '/resources/toon/models/tt_m_chr_avt_acc_hat_topHat.bam')
		self.topHat.reparentTo(self.toonHead.find('**/head'))
		self.topHat.setZ(0.5)
		self.topHat.setHpr(180,-45,0)
		self.topHat.setTexture(loader.loadTexture(self.pandaDirectory + '/resources/toon/textures/tt_t_chr_avt_acc_hat_topHatQuizmaster.jpg'),1)
		self.topHat.setScale(0.35)
Beispiel #47
0
class Human():
    def __init__(self,parent, world, worldNP):
        """__init__
        parameters:
            self
            parent: the World object
            world: bullet world
            worldNP: where in the world to put it
        returns:
            none
        Description:
            Create the human player
        """
        self.traptime = 0
        self.world = world
        self.worldNP = worldNP
        
        self.projectiles = list()
        self.floatTraps = list()
        
        self.keymap = {"left": 0, "right":0, "up":0,"down":0, "m1":0}
        self.prevTime = 0
        # panda walk
        parent.accept("w",self.setKey,["up",1])
        parent.accept("w-up",self.setKey,["up",0])
        parent.accept("s",self.setKey,["down",1])
        parent.accept("s-up",self.setKey,["down",0])
        parent.accept("a",self.setKey,["left",1])
        parent.accept("a-up",self.setKey,["left",0])
        parent.accept("d",self.setKey,["right",1])
        parent.accept("d-up",self.setKey,["right",0])
        parent.accept("mouse1", self.setKey, ["m1",1])
        
        self.velocity = 0
        self.dir = (0,0,0)
        
        self.vel = (0,0,0)
        
        taskMgr.add(self.fpMove,"moveTask",sort=50)
        taskMgr.add(self.mouseTask, 'mouseTask')
        self.parent = parent
        #self.human = self.parent.human
        #self.human = collision.loadAndPositionModelFromFile("../assets/3d/Actors/robot rig 10 coll.egg",scale=.07,show=0)
        self.human = Actor('../assets/3d/Actors/robot_idle_final_actor.egg', {
          'idle':'../assets/3d/Actors/robot_idle_final_anim.egg',
        #  'throw':'../assets/3d/Actors/animation eggs/robot_throw_final.egg',
        #  'place':'../assets/3d/Actors/animation eggs/robot_place_final.egg',
        #  'death':'../assets/3d/Actors/animation eggs/robot_death_final.egg',
        })
        #print self.human.find("**/eyes_sphere").getPos()
        #self.human.flattenLight()
        print self.human.ls()
        #self.human.node().getChild(0).removeChild(0)
        self.human.setH(camera.getH()+180)
        campos = self.human.getPos()
        campos[2] = campos[2]-5
        camera.lookAt(campos)
        
        pnode = ModelRoot("player")
        self.player = render.attachNewNode(pnode)
        pc = self.player.attachNewNode(CollisionNode("playerCollision"))
        pc.node().addSolid(CollisionRay(0,0,-1,0,0,1))
        self.playerCnode = pc
        self.player.setPos(0,0,1)
        #self.human.play('idle')
        self.human.loop('idle')
    def bulletInit(self,world,pos):
        """bulletInit
        parameters:
            self
            task: the tskMgr structure
        returns:
            none
        Description:
            The rest of init requires bullet things
        """
        oldpath = self.human.find("**/body_coll")
        self.shape = BulletSphereShape(10)#oldpath.node().getSolid(0).getRadius())
        self.character = BulletCharacterControllerNode(self.shape, 0.4, 'Human')
        self.characterNP = render.attachNewNode(self.character)
        self.characterNP.setPos(pos[0],pos[1],pos[2])
        self.character.setGravity(0)
        #self.human.setPos(pos)
        self.human.reparentTo(self.characterNP)
        self.human.hide()
        #self.player.setPos(pos)
        self.player.reparentTo(self.characterNP)
        self.characterNP.setCollideMask(BitMask32.allOn())
        
        world.attachCharacter(self.character)
    def fpMove(self,task):
        """fpMove
        parameters:
            self
            task: the taskMgr structure
        returns:
            none
        Description:
            player movement
        """
        dt = task.time-self.prevTime
        camera.setPos(self.player.getPos()+(0,0,1))
        damp = (1.-(.2*dt))
        self.vel = map(lambda x: damp*x, self.vel)
        if self.traptime>0:
            self.traptime = self.traptime-dt
        #self.human.setZ(self.player.getZ()-.5)
        #if not self.parent.editMode:
        #camera.setPos(self.player.getPos()-(0.0264076, 4.60993, -10.0715))
        self.prevTime = task.time
        pos = self.player.getParent().getPos()
        delta = 10*dt
        h = deg2Rad(camera.getH())
        p = deg2Rad(camera.getP())
        # player control
        if self.keymap["up"] and self.traptime<=0:
            dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
            self.vel = map(lambda i: self.vel[i]+dir[i]*delta, range(3))
        if self.keymap["down"] and self.traptime<=0:
            dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
            self.vel = map(lambda i: self.vel[i]-dir[i]*delta, range(3))
        if self.keymap["m1"] and self.traptime<=0:
            weapon = self.parent.overlay.wepCounter
            if self.parent.overlay.wepAmmo[weapon] > 0:
                self.parent.overlay.changeAmmo(weapon, -1)
                if weapon == 0:
                    self.launch()
                    dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
                    self.vel = map(lambda i: self.vel[i]-dir[i]*100, range(3))
                elif weapon == 1:
                    self.placeFloatTrap()
                elif weapon == 2:
                    self.placeClawTrap()
            self.keymap["m1"] = 0
        self.character.setAngularMovement(0)
        self.character.setLinearMovement(LVector3(self.vel[0],self.vel[1],self.vel[2]),True)
        #get displacement
        dis = (self.vel[0]*dt,self.vel[1]*dt,self.vel[2]*dt)
        #set the new position
        self.player.setPos(pos[0]+dis[0],pos[1]+dis[1],pos[2]+dis[2])
        self.human.setPos(pos[0]+dis[0],pos[1]+dis[1],pos[2]+dis[2])
        #self.human.setX(self.player.getX()+sin(deg2Rad(camera.getH())+math.pi))
        #self.human.setY(self.player.getY()-cos(deg2Rad(camera.getH())+math.pi))
        return task.cont
    def launch(self):
        """launch
        parameters:
            self
        returns:
            none
        Description:
            Fire a projectile
        """
        self.projectiles.append(Projectile(self.player.getPos(),deg2Rad(camera.getH()),deg2Rad(camera.getP()),self,self.vel, self.world, self.worldNP))
    def placeFloatTrap(self):
        """placeFloatTrap
        parameters:
            self
        returns:
            none
        Description:
            Place a float trap
        """
        self.floatTraps.append(floatTrap(self.player.getPos(),self.world,self.worldNP)) 
    def placeClawTrap(self):
        """placeClawTrap
        parameters:
            self
        returns:
            none
        Description:
            Place a claw trap
        """
        trap = clawTrap(self.world,self.worldNP)
        weapon = self.parent.overlay.wepCounter
        self.parent.overlay.changeAmmo(weapon, trap.failed)
    def setKey(self,key,value):
        self.keymap[key] = value
    def mouseTask(self,task): 
        """mouseTask
        parameters:
            self
            task: the tskMgr structure
        returns:
            none
        Description:
            Keep track of the mouse and record its movement
        """
        global mousePos, mousePrevPos 
        
        if (not base.mouseWatcherNode.hasMouse() ): return Task.cont
        
        # Get mouse coordinates from mouse watcher 
        x=base.mouseWatcherNode.getMouseX()
        y=base.mouseWatcherNode.getMouseY()
        mousePos = [x,y] 
        # Calculate mouse movement from last frame and output (print) 
        move = [mousePos[0],mousePos[1]] 
        if move==[0,0]: return Task.cont
        #print "Moved:\t %f right, \t %f up." %(move[0], move[1]) 
        base.win.movePointer(0, base.win.getXSize() / 2, base.win.getYSize() / 2)
        # Save current position for next calculation 
        mousePrevPos = mousePos
        
        camera.setP(camera.getP()+75*move[1])
        camera.setH(camera.getH()-75*move[0])
        
        self.human.setH(camera.getH()+180)
        self.human.setX(self.player.getX()+sin(deg2Rad(camera.getH()+180)))
        self.human.setY(self.player.getY()-cos(deg2Rad(camera.getH()+180)))
        
        contacts = self.world.contactTest(self.character).getContacts()
        for c in contacts:
            contactObject = c.getNode0()
            if c.getNode0().getName()=="Human":
                contactObject = c.getNode1()
            if contactObject.getName()=="env":
                self.vel = map(lambda x: x*.9, self.vel)
        
        return Task.cont
    def die(self,event):
        """die
        parameters:
            self
            task: the tskMgr structure
        returns:
            none
        Description:
            Kill the player
        """
        #base.cTrav.removeCollider(self.wheelsphere)
        self.human.node().getChild(0).removeChild(0)
        self.filters.setInverted()
        print "You Died!"
    def trap1(self):
        """trap1
        parameters:
            self
        returns:
            none
        Description:
            Inflict the floating trap penalty
        """
        self.vel = map(lambda x: x*.25, self.vel)
        self.traptime = self.traptime + 20
        return
    def trap2(self):
        """trap2
        parameters:
            self
        returns:
            none
        Description:
            Inflict the claw trap penalty
        """
        self.vel = (0,0,0)
        self.traptime = self.traptime + 30
        return
    def impact(self,vel):
        diff = map(lambda i: self.vel[i]-vel[i], range(3))
        self.vel = map(lambda i: self.vel[i]-diff[i], range(3))