def generate(self):
     self.level = 12
     self.maxHealth = 200
     self.health = 200
     Suit.generate(self,
                   FactorySneakGuardSuit.SUIT,
                   FactorySneakGuardSuit.VARIANT,
                   hideFirst=False)
     self.setName(self.suitPlan.getName(), None)
     self.cleanupPropeller()
     base.taskMgr.add(self.__viewDistance, self.viewDistanceTaskName)
     self.setPythonTag('guard', self)
     self.eyeLight = Spotlight('eyes')
     self.eyeLens = PerspectiveLens()
     self.eyeLens.setMinFov(90.0 / (4. / 3.))
     self.eyeLight.setLens(self.eyeLens)
     self.eyeNode = self.headModel.attachNewNode(self.eyeLight)
     self.eyeNode.setZ(-5)
     self.eyeNode.setY(-4.5)
     self.trav = CollisionTraverser(self.uniqueName('eyeTrav'))
     ray = CollisionRay(0, 0, 0, 0, 1, 0)
     rayNode = CollisionNode('ToonFPS.rayNode')
     rayNode.addSolid(ray)
     rayNode.setFromCollideMask(CGG.GuardBitmask | CIGlobals.WallBitmask)
     rayNode.setIntoCollideMask(BitMask32.allOff())
     self.rayNP = base.camera.attachNewNode(rayNode)
     self.rayNP.setZ(3)
     self.queue = CollisionHandlerQueue()
     self.trav.addCollider(self.rayNP, self.queue)
     self.trav.addCollider(self.gameWorld.mg.avatarBody, self.queue)
     self.request('Guard')
 def disable(self):
     self.request('Off')
     base.taskMgr.remove(self.taskName("guard"))
     base.taskMgr.remove(self.diedTaskName)
     base.taskMgr.remove(self.viewDistanceTaskName)
     self.trav = None
     if self.rayNP:
         self.rayNP.removeNode()
         self.rayNP = None
     self.queue = None
     self.currentPathIndex = None
     if self.eyeNode:
         self.eyeNode.removeNode()
         self.eyeNode = None
         self.eyeLens = None
         self.eyeLight = None
     self.viewDistanceTaskName = None
     self.guardKey = None
     self.gameWorld = None
     self.pathQueue = None
     if self.walkTrack:
         self.ignore(self.walkTrack.getDoneEvent())
         self.walkTrack.finish()
         self.walkTrack = None
     Suit.disable(self)
    def load(self):
        Entity.load(self)
        entnum = self.cEntity.getEntnum()
        suitId = base.bspLoader.getEntityValueInt(entnum, "suitPlan")
        self.level = base.bspLoader.getEntityValueInt(entnum, "level")
        suitPlan = SuitBank.getSuitById(suitId)
        Suit.generate(self, suitPlan, Variant.NORMAL, Voice.NORMAL, False)

        classAttrs = suitPlan.getCogClassAttrs()
        self.maxHealth = classAttrs.baseHp
        self.maxHealth += SuitGlobals.calculateHP(self.level)
        self.maxHealth *= classAttrs.hpMod

        self.health = self.maxHealth

        if self.level == 0:
            self.maxHealth = 1
            self.health = self.maxHealth

        self.reparentTo(render)

        origin = self.cEntity.getOrigin()
        angles = self.cEntity.getAngles()
        self.setPos(origin)
        self.setHpr(angles)

        self.cleanupPropeller()
        self.animFSM.request('neutral')
 def __init__(self, world, guardKey):
     Suit.__init__(self)
     FSM.__init__(self, 'FactorySneakGuardSuit')
     self.gameWorld = world
     self.guardKey = guardKey
     self.viewDistanceTaskName = self.VIEW_DISTANCE_TASK_NAME + "-" + str(
         id(self))
     self.diedTaskName = "GuardDied-" + str(id(self))
     self.health = 0
     self.maxHealth = 0
     self.eyeLight = None
     self.eyeLens = None
     self.eyeNode = None
     self.moveTrack = None
     self.trav = None
     self.rayNP = None
     self.queue = None
     self.currentKey = self.guardKey
     self.firstPoint = CGG.GuardPointData[self.guardKey]
     self.walkTrack = None
     self.pathQueue = []
     self.currentPathIndex = 0
 def generate(self):
     DistributedNode.generate(self)
     self.cart = loader.loadModel(self.cartModelPath)
     self.cart.reparentTo(self)
     self.cart.setH(180)
     plans = []
     for plan in SuitBank.getSuits():
         if plan.getSuitType() != SuitType.B:
             plans.append(plan)
     plan = random.choice(plans)
     self.suitInCar = Suit()
     self.suitInCar.level = 0
     self.suitInCar.generate(plan, Variant.NORMAL)
     self.suitInCar.loop('sit')
     self.suitInCar.disableRay()
     self.suitInCar.setScale(0.7)
     self.suitInCar.setH(180)
     self.suitInCar.setPos(0, -1, -1.5)
     self.suitInCar.reparentTo(self.cart.find('**/seat1'))
     self.suitInCar.show()
     self.soundEngineLoop = base.audio3d.loadSfx('phase_6/audio/sfx/KART_Engine_loop_0.ogg')
     base.audio3d.attachSoundToObject(self.soundEngineLoop, self)
     base.playSfx(self.soundEngineLoop, looping = 1)
     self.soundDriveByHorn = base.audio3d.loadSfx(self.honkSfxPath)
     base.audio3d.attachSoundToObject(self.soundDriveByHorn, self)
     self.soundDriveBy = base.audio3d.loadSfx('phase_14/audio/sfx/cogtropolis_citycar_driveby.ogg')
     base.audio3d.attachSoundToObject(self.soundDriveBy, self)
     sphere = CollisionSphere(0, 0, 0, 2.5)
     sphere.setTangible(0)
     node = CollisionNode(self.uniqueName('cartSphere'))
     node.setCollideMask(CIGlobals.WallBitmask)
     node.addSolid(sphere)
     self.collNodePath = self.attachNewNode(node)
     self.collNodePath.setZ(1.5)
     self.collNodePath.setSy(2.0)
     self.collNodePath.setSx(1.75)
Example #6
0
def precacheSuits():
    from src.coginvasion.cog import Variant
    from src.coginvasion.cog.Suit import Suit
    from src.coginvasion.base.Precache import precacheActor
    suit = Suit()
    for suitPlan in totalSuits:
        print "Precaching", suitPlan.name
        suit.suitPlan = suitPlan
        suit.suit = suitPlan.getSuitType()
        suit.head = suitPlan.getHead()
        suit.dept = suitPlan.getDept()
        suit.handColor = suitPlan.getHandColor()
        suit.variant = Variant.NORMAL
        suit.level = 0
        suit.generateCog(nameTag=False)
        precacheActor(suit)
        suit.generateCog(isLose=1, nameTag=False)
        precacheActor(suit)
    suit.disable()
    suit.delete()
class DistributedCityCart(DistributedNode):
    notify = directNotify.newCategory('DistributedCityCart')

    def __init__(self, cr):
        DistributedNode.__init__(self, cr)
        self.fsm = ClassicFSM('DistributedCityCart', [State('off', self.enterOff, self.exitOff),
         State('pathFollow', self.enterPathFollow, self.exitPathFollow),
         State('collision', self.enterCollision, self.exitCollision)], 'off', 'off')
        self.fsm.enterInitialState()
        self.suitInCar = None
        self.cart = None
        self.honkSfxPath = 'phase_14/audio/sfx/cogtropolis_citycar_driveby_horn.ogg'
        self.cartModelPath = 'phase_12/models/bossbotHQ/Coggolf_cart3.bam'
        self.moPaths = ['phase_14/models/paths/ct-citycar-drivepath-1.egg',
            'phase_14/models/paths/ct-citycar-drivepath-2.egg',
            'phase_14/models/paths/ct-citycar-drivepath-3.egg',
            'phase_14/models/paths/ct-citycar-drivepath-4.egg',
            'phase_14/models/paths/ct-citycar-drivepath-5.egg',
            'phase_14/models/paths/ct-citycar-drivepath-6.egg']
        self.moPath = None
        self.soundEngineLoop = None
        self.soundDriveByHorn = None
        self.ivalTDisplace = None
        self.pathIndex = None
        self.wheelSpinTrack = None
        self.collNodePath = None
        self.soundDriveBy = None

    def setIvalTDisplace(self, displace):
        self.ivalTDisplace = displace

    def setPathIndex(self, index):
        self.pathIndex = index

    def setState(self, state, timestamp):
        ts = ClockDelta.globalClockDelta.localElapsedTime(timestamp)
        self.fsm.request(state, [ts])

    def enterOff(self):
        pass

    def exitOff(self):
        pass

    def enterPathFollow(self, ts):
        duration = CityCartGlobals.index2Duration[self.pathIndex]
        self.moPath = NURBSMopath.NURBSMopath(self.moPaths[self.pathIndex], name = self.uniqueName('DCityCart_moPath'))
        startT = 0.0
        if ts > 0.0:
            startT = (ts % duration) * (1.0 / duration)
        self.moPath.play(self, loop = True, duration = duration, startT = startT)
        base.taskMgr.add(self.__drive, self.uniqueName('DCityCart.drive'))
        self.wheelSpinTrack = Parallel()
        for name in ['leftFrontWheel', 'rightBackWheel', 'rightFrontWheel', 'leftBackWheel']:
            wheel = self.find('**/' + name)
            self.wheelSpinTrack.append(LerpHprInterval(wheel, duration = 0.1, hpr = (0, 360, 0), startHpr = (0, 0, 0)))
        self.wheelSpinTrack.loop()
        self.accept('enter' + self.collNodePath.node().getName(), self.__handleRanOver)

    def __handleRanOver(self, entry):
        self.suitInCar.setChat(CityCartGlobals.SuitRanOverTaunt)
        self.sendUpdate('hitByCar')
        self.cr.playGame.getPlace().fsm.request('stop')
        base.localAvatar.b_setAnimState('squish', callback = self.cr.playGame.getPlace().fsm.request, extraArgs = ['walk'])

    def __drive(self, task):
        if base.localAvatar.getDistance(self) < 10.0:
            if self.soundDriveByHorn.status() == self.soundDriveByHorn.READY:
                wantsToHonk = random.randint(0, 3)
                if wantsToHonk == 3:
                    base.playSfx(self.soundDriveByHorn)
                return task.cont
        elif base.localAvatar.getDistance(self) < 20.0:
            if self.soundDriveBy.status() == self.soundDriveBy.READY:
                base.playSfx(self.soundDriveBy)
                return task.cont
        return task.cont

    def exitPathFollow(self):
        self.ignore('enter' + self.collNodePath.node().getName())
        base.taskMgr.remove(self.uniqueName('DCityCart.drive'))
        if self.wheelSpinTrack:
            self.wheelSpinTrack.finish()
            self.wheelSpinTrack = None
        if self.moPath:
            self.moPath.stop()
            self.moPath = None

    def enterCollision(self, ts):
        pass

    def exitCollision(self):
        pass

    def generate(self):
        DistributedNode.generate(self)
        self.cart = loader.loadModel(self.cartModelPath)
        self.cart.reparentTo(self)
        self.cart.setH(180)
        plans = []
        for plan in SuitBank.getSuits():
            if plan.getSuitType() != SuitType.B:
                plans.append(plan)
        plan = random.choice(plans)
        self.suitInCar = Suit()
        self.suitInCar.level = 0
        self.suitInCar.generate(plan, Variant.NORMAL)
        self.suitInCar.loop('sit')
        self.suitInCar.disableRay()
        self.suitInCar.setScale(0.7)
        self.suitInCar.setH(180)
        self.suitInCar.setPos(0, -1, -1.5)
        self.suitInCar.reparentTo(self.cart.find('**/seat1'))
        self.suitInCar.show()
        self.soundEngineLoop = base.audio3d.loadSfx('phase_6/audio/sfx/KART_Engine_loop_0.ogg')
        base.audio3d.attachSoundToObject(self.soundEngineLoop, self)
        base.playSfx(self.soundEngineLoop, looping = 1)
        self.soundDriveByHorn = base.audio3d.loadSfx(self.honkSfxPath)
        base.audio3d.attachSoundToObject(self.soundDriveByHorn, self)
        self.soundDriveBy = base.audio3d.loadSfx('phase_14/audio/sfx/cogtropolis_citycar_driveby.ogg')
        base.audio3d.attachSoundToObject(self.soundDriveBy, self)
        sphere = CollisionSphere(0, 0, 0, 2.5)
        sphere.setTangible(0)
        node = CollisionNode(self.uniqueName('cartSphere'))
        node.setCollideMask(CIGlobals.WallBitmask)
        node.addSolid(sphere)
        self.collNodePath = self.attachNewNode(node)
        self.collNodePath.setZ(1.5)
        self.collNodePath.setSy(2.0)
        self.collNodePath.setSx(1.75)

    def disable(self):
        self.fsm.requestFinalState()
        if self.moPath:
            self.moPath.stop()
            self.moPath = None
        self.moPaths = None
        self.honkSfxPath = None
        self.cartModelPath = None
        self.soundEngineLoop = None
        self.soundDriveBy = None
        if self.suitInCar:
            self.suitInCar.disable()
            self.suitInCar.delete()
            self.suitInCar = None
        if self.cart:
            self.cart.removeNode()
            self.cart = None
        del self.fsm
        DistributedNode.disable(self)
 def __init__(self):
     Entity.__init__(self)
     Suit.__init__(self)
     self.level = 0