def announceGenerate(self): entnum = self.cEntity.getBspEntnum() suitId = self.getEntityValueInt("suitPlan") suitPlan = SuitBank.getSuitById(suitId) level = self.getEntityValueInt("level") variant = self.getEntityValueInt("variant") self.b_setLevel(level) self.b_setSuit(suitPlan, variant) self.b_setPlace(self.zoneId) self.b_setName(suitPlan.getName()) self.setPos(self.cEntity.getOrigin()) self.setHpr(self.cEntity.getAngles()) pos = self.getPos() hpr = self.getHpr() self.d_setPosHpr(pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]) DistributedEntityAI.announceGenerate(self) DistributedSuitAI.announceGenerate(self) self.stopAI() self.b_setParent(CIGlobals.SPRender) taskMgr.add(self.monitorHealth, self.uniqueName('monitorHealth')) self.startPosHprBroadcast() spawnflags = self.getEntityValueInt("spawnflags") if spawnflags & self.StartsActive: self.Activate()
def Spawn(self, dept = None): from src.coginvasion.cog.DistributedSuitAI import DistributedSuitAI from src.coginvasion.cog import Dept, SuitBank, Variant from src.coginvasion.arcade.BatchCogSpawnerAI import BatchCogSpawnerAI import random level, availableSuits = SuitBank.chooseLevelAndGetAvailableSuits( [1, 4], random.choice([Dept.BOSS, Dept.SALES, Dept.CASH, Dept.LAW]) if not dept else dept, False) plan = random.choice(availableSuits) suit = DistributedSuitAI(self.air) suit.setPos(self.cEntity.getOrigin()) suit.setHpr(self.cEntity.getAngles()) suit.setBattleZone(self.dispatch) variant = Variant.NORMAL suit.setLevel(level) suit.setSuit(plan, variant) suit.generateWithRequired(self.dispatch.zoneId) #suit.d_setHood(suit.hood) suit.b_setPlace(self.dispatch.zoneId) suit.b_setName(plan.getName()) suit.spawnGeneric() self.spawned.append(suit) if self.hasSpawnFlags(self.DoSupaFlyIn): suit.changeSchedule(suit.getScheduleByName("SUPA_FLY_IN_MOVE")) if self.spawnScript: self.spawnScript.ExecuteScript(suit) BatchCogSpawnerAI.NumSuits += 1 self.dispatchOutput("OnSpawnCog") return suit
def makeSuit(self, spawnData, hangoutData, isChair, boss=False): bldgInfo = SuitBuildingGlobals.buildingInfo[self.hood] if self.currentFloor < self.numFloors - 1: levelRange = bldgInfo[SuitBuildingGlobals.LEVEL_RANGE] else: levelRange = bldgInfo[SuitBuildingGlobals.BOSS_LEVEL_RANGE] battlePoint = None level, availableSuits = SuitBank.chooseLevelAndGetAvailableSuits( levelRange, self.deptClass, boss) plan = random.choice(availableSuits) suit = DistributedCogOfficeSuitAI(self.air, self, spawnData, hangoutData, isChair, self.hood) suit.setBattleZone(self) variant = Variant.NORMAL hood = self.hood if self.hood == ZoneUtil.ToontownCentral: hood = ZoneUtil.BattleTTC if CogBattleGlobals.hi2hi[hood] == CogBattleGlobals.WaiterHoodIndex: variant = Variant.WAITER suit.setLevel(level) suit.setSuit(plan, variant) suit.generateWithRequired(self.zoneId) suit.d_setHood(suit.hood) suit.battleZone = self suit.b_setPlace(self.zoneId) suit.b_setName(plan.getName()) return suit
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 precacheStuff(self): from src.coginvasion.toon import ToonGlobals ToonGlobals.precacheToons() self.cl_attackMgr.precache() from src.coginvasion.gags.LocationSeeker import LocationSeeker LocationSeeker.precache() from src.coginvasion.gags.LocationGag import LocationGag LocationGag.precache() from src.coginvasion.hood.DistributedBuilding import DistributedBuilding DistributedBuilding.precache() from src.coginvasion.cog import SuitBank SuitBank.precacheSuits()
def spawnDoorSuit(self, rearOrFront): import random if self.version == 1: suitOrGoon = 1 elif self.version == 2: # 25% chance of goon on version 2 suitOrGoon = random.randint(0, 3) elif self.version == 3: # 33% on version 3 suitOrGoon = random.randint(0, 2) else: suitOrGoon = 1 if suitOrGoon != 0: from src.coginvasion.cog.DistributedSuitAI import DistributedSuitAI from src.coginvasion.cog import Dept, SuitBank, Variant from src.coginvasion.attack.Attacks import ATTACK_BOMB, ATTACK_FIRED level, availableSuits = SuitBank.chooseLevelAndGetAvailableSuits( self.getVersionSuitLevels(), Dept.SALES, False) plan = random.choice(availableSuits) suit = VPSuitAI(self.air, self) if level >= 5: suit.attackIds.append(ATTACK_FIRED) if level >= 10: suit.attackIds.append(ATTACK_BOMB) suit.rearOrFront = rearOrFront suit.setNPCState(STATE_SCRIPT) suit.setPos(self.getPos()) suit.setHpr(self.getHpr()) suit.setBattleZone(self.dispatch) variant = Variant.NORMAL suit.setLevel(level) suit.setSuit(plan, variant) suit.generateWithRequired(self.dispatch.zoneId) suit.b_setPlace(self.dispatch.zoneId) suit.b_setName(plan.getName()) suit.spawnGeneric() self.numSuits += 1 suit.changeSchedule(suit.getScheduleByName("VP_EXIT"), False) else: goon = VPGoonAI(self.air, self) goon.rearOrFront = rearOrFront goon.setNPCState(STATE_IDLE) goon.setPos(self.getPos()) goon.setHpr(self.getHpr()) goon.setBattleZone(self.dispatch) goon.generateWithRequired(self.dispatch.zoneId) self.numSuits += 1 goon.changeSchedule(goon.getScheduleByName("VP_EXIT"), False)
def createSuit(self, anySuit = 0, levelRange = None, variant = Variant.NORMAL, plan = None): if self.isCogCountFull(): return if anySuit: if not levelRange: levelRange = CogBattleGlobals.HoodIndex2LevelRange[self.battle.getHoodIndex()] availableSuits = [] level = random.choice(levelRange) for suit in SuitBank.getSuits(): if level >= suit.getLevelRange()[0] and level <= suit.getLevelRange()[1]: availableSuits.append(suit) plan = random.choice(availableSuits) else: if not plan: return level = random.randint(plan.getLevelRange()[0], plan.getLevelRange()[1]) if self.battle.getHoodIndex() == CogBattleGlobals.SkeletonHoodIndex and variant == Variant.NORMAL: variant = Variant.SKELETON elif self.battle.getHoodIndex() == CogBattleGlobals.WaiterHoodIndex and variant == Variant.NORMAL: variant = Variant.WAITER suit = DistributedSuitAI(self.air) suit.setManager(self) suit.generateWithRequired(self.zoneId) suit.d_setHood(suit.hood) suit.b_setLevel(level) suit.b_setSuit(plan, variant) suit.b_setPlace(self.zoneId) if variant == Variant.SKELETON: suit.b_setName(CIGlobals.Skelesuit) else: suit.b_setName(plan.getName()) #suit.startPosHprBroadcast() #suit.d_clearSmoothing() #suit.d_broadcastPosHpr() suit.b_setParent(CIGlobals.SPHidden) self.suits[suit.doId] = suit self.numSuits += 1 if self.numSuits == 1: if (self.tournament.inTournament and self.tournament.getRound() == 1 or not self.tournament.inTournament): self.sendUpdate('newSuit', []) if self.tournament.inTournament and self.tournament.getRound() == 1: self.sendUpdate('tournamentSpawned', []) if self.getActiveInvasion(): self.suitsSpawnedThisInvasion += 1 if self.suitsSpawnedThisInvasion == 1: if not self.tournament.inTournament: self.sendUpdate('invasionSpawned', []) if plan in [SuitBank.VicePresident, SuitBank.LucyCrossbill]: self.sendUpdate('bossSpawned', []) return suit
def __spawnSuit(self, task): if self.barrelsRemaining == 0: return task.done plan = random.choice(SuitBank.getSuits()) level = 0 variant = Variant.NORMAL suit = DistributedDeliveryGameSuitAI(self.air, self) suit.generateWithRequired(self.zoneId) suit.b_setLevel(level) suit.b_setSuit(plan, variant) suit.b_setPlace(self.zoneId) suit.b_setName(plan.getName()) suit.b_setParent(CIGlobals.SPHidden) self.suits.append(suit) task.delayTime = self.getSuitSpawnTime() return task.again
def announceGenerate(self): entnum = self.cEntity.getBspEntnum() suitId = self.getEntityValueInt("suitPlan") suitPlan = SuitBank.getSuitById(suitId) level = self.getEntityValueInt("level") variant = self.getEntityValueInt("variant") self.b_setLevel(level) self.b_setSuit(suitPlan, variant) self.b_setPlace(self.zoneId) self.b_setName(suitPlan.getName()) attackNames = self.getEntityValue("attacklist") if len(attackNames) > 0: attackNames = attackNames.split(';') attackIds = [] for name in attackNames: attackIds.append(AttackEnum[name]) self.b_setAttackIds(attackIds) #hp = self.getEntityValueInt("health") #if hp != -1: # self.b_setMaxHealth(hp) # self.b_setHealth(hp) self.setPos(self.cEntity.getOrigin()) self.setHpr(self.cEntity.getAngles()) pos = self.getPos() hpr = self.getHpr() self.d_setPosHpr(pos[0], pos[1], pos[2], hpr[0], hpr[1], hpr[2]) DistributedSuitAI.announceGenerate(self) self.stopAI() #self.b_setParent(CIGlobals.SPRender) taskMgr.add(self.monitorHealth, self.uniqueName('monitorHealth')) self.startPosHprBroadcast() if self.spawnflags & self.StartsActive: self.Activate()
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 __spawnNewBuilding(self, task): number = random.randint(1, 100) if number <= self.spawnChance and self.numCogBuildings < self.maxBuildings: # Let's spawn one!!! bldg = random.choice(self.getToonBuildingsList()) # This building belongs to us! bldg.takenBySuit = True bldg.door.b_setSuitTakingOver(1) hoodName = self.hoodClass.hood if hoodName == ZoneUtil.ToontownCentral: hoodName = ZoneUtil.BattleTTC levelRange = CogBattleGlobals.HoodIndex2LevelRange[CogBattleGlobals.HoodId2HoodIndex[hoodName]] level, planList = SuitBank.chooseLevelAndGetAvailableSuits(levelRange, random.choice([Dept.SALES, Dept.CASH, Dept.LAW, Dept.BOSS])) plan = random.choice(planList) suit = DistributedTakeOverSuitAI(base.air, self, bldg, bldg.door.doId) #suit.setManager(self) suit.generateWithRequired(bldg.zoneId) suit.b_setHood(self.hoodClass.hood) suit.b_setLevel(level) variant = Variant.NORMAL if CogBattleGlobals.hi2hi[hoodName] == CogBattleGlobals.WaiterHoodIndex: variant = Variant.WAITER suit.b_setSuit(plan, variant) suit.b_setPlace(bldg.zoneId) suit.b_setName(plan.getName()) suit.initiateTakeOver() self.suitsTakingOver.append(suit) task.delayTime = random.randint(SuitBuildingGlobals.SPAWN_TIME_RANGE[0], SuitBuildingGlobals.SPAWN_TIME_RANGE[1]) return task.again
def handleCogObjective(self, iconElement=auxIcon, auxText=QuestGlobals.DEFEAT, frameColor=QuestGlobals.BLUE): objective = self.viewObjective infoText = objective.getTaskInfo() if objective.__class__ == RecoverItemObjective: infoText = CIGlobals.makePlural(objective.cog) if not iconElement: iconElement = self.auxIcon # Let's make sure we have a current objective that is # an instance of the CogObjective class and this poster isn't destroyed. if not objective or not hasattr(self, 'titleLabel') or not isinstance( objective, CogObjective): return if objective.dept: icons = loader.loadModel('phase_3/models/gui/cog_icons.bam') deptIcon = None if objective.dept == Dept.BOSS: deptIcon = icons.find('**/CorpIcon') else: deptIcon = icons.find('**/%sIcon' % objective.dept.getTie().title()) # Correct the medallion color. deptIcon.setColor(SuitGlobals.medallionColors[objective.dept]) # Setup the icon and remove the icons node. self.handleSimpleIcon(deptIcon, 0.13, iconElement) icons.removeNode() elif objective.cog == QuestGlobals.Any: # We aren't fighting a Cog in particular. cogIcon = QuestGlobals.getCogIcon() self.handleSimpleIcon(cogIcon, 0.13, iconElement) # We're fighting a Cog in particular. if not objective.cog == QuestGlobals.Any: cogHeadInstance = SuitBank.getSuitByName(objective.cog).getHead() cogHead = cogHeadInstance.generate() cogHead.setName('%sHead' % CIGlobals.Suit) cogHead.setPythonTag('Settings', cogHeadInstance.head) cogHead.setScale(2) cogHead.setLightOff() self.handleComplexIcon(cogHead, iconElement) # HACK FIX: Corrects the buggy Flunky glasses. glasses = cogHead.find('**/glasses') if glasses and not glasses.isEmpty(): glasses.setScale(1) glasses.reparentTo(cogHead) if not iconElement is self.auxIcon: if hasattr(self, 'goalInfo'): # We're working with the second frame, on the right. # Let's update the information pertaining to this side. self.goalInfo['text'] = infoText self.goalInfo.setPos(QuestGlobals.RECOVER_INFO2_POS) self.auxText.setPos(QuestGlobals.RECOVER_AUX_POS) else: raise AttributeError( 'Attempted to setup DoubleFrame information for poster using default style.' ) else: self.objectiveInfo['text'] = infoText # Let's set the progress bar text pgBarText = '%d of %d %s' % (objective.progress, objective.goal, CIGlobals.makePastTense(auxText)) self.progressBar['text'] = pgBarText self.auxText['text'] = auxText # Let's set the color of the poster. frame = self.auxFrame if iconElement is self.auxIcon else self.goalFrame frame['image_color'] = Vec4(*frameColor)
def generateCog(self, isLose=0, nameTag=True): #startTime = globalClock.getRealTime() generateCollector.start() cleanupCollector.start() self.cleanup() cleanupCollector.stop() if not isLose: if self.suitPlan in SuitBank.suitSetups: setup = SuitBank.suitSetups[self.suitPlan] else: setup = SuitBank.SuitSetup() SuitBank.suitSetups[self.suitPlan] = setup if not self.variant in setup.actor: setupActor = Actor() if self.variant == Variant.SKELETON or self.variant == Variant.ZOMBIE: setupActor.loadModel( 'phase_5/models/char/cog%s_robot-zero.bam' % (str(self.suit)), 'body') else: setupActor.loadModel( 'phase_3.5/models/char/suit%s-mod.bam' % (str(self.suit)), 'body') animations = SuitGlobals.animations anims = {} for anim in animations: if not self.suit in anim.getSuitTypes(): continue path = 'phase_%s/models/char/suit%s-%s.bam' % ( anim.getPhase(), self.suit, anim.getFile()) anims[anim.getName()] = path setupActor.loadAnims(anims, 'body') setup.actor[self.variant] = setupActor actorCollector.start() self.copyActor(setup.actor[self.variant]) actorCollector.stop() healthBarCollector.start() self.generateHealthBar() healthBarCollector.stop() footstepCollector.start() if self.suitPlan.suitType == SuitType.A: self.footstepSound = base.audio3d.loadSfx( "phase_5/audio/sfx/ENC_cogafssm.ogg") elif self.suitPlan.suitType == SuitType.B: self.footstepSound = base.audio3d.loadSfx( "phase_5/audio/sfx/ENC_cogbfssm.ogg") elif self.suitPlan.suitType == SuitType.C: self.footstepSound = base.audio3d.loadSfx( "phase_5/audio/sfx/ENC_cogcfssm.ogg") if self.footstepSound: base.audio3d.attachSoundToObject(self.footstepSound, self) self.footstepSound.setVolume(0.0) self.footstepSound.setLoop(True) self.footstepSound.play() footstepCollector.stop() else: if self.variant == Variant.SKELETON or self.variant == Variant.ZOMBIE: self.loadModel( 'phase_5/models/char/cog%s_robot-lose-mod.bam' % (str(self.suit)), 'body') else: self.loadModel( 'phase_4/models/char/suit%s-lose-mod.bam' % (str(self.suit)), 'body') self.loadAnims( { 'lose': 'phase_4/models/char/suit%s-lose.bam' % (str(self.suit)) }, 'body') genHeadCollector.start() if self.variant != Variant.SKELETON: self.headModel = self.head.generate() self.headModel.reparentTo(self.find("**/joint_head")) if self.suitPlan.getName() == SuitGlobals.VicePresident: self.headModel.setScale(0.35) self.headModel.setHpr(270, 0, 270) self.headModel.setZ(-0.10) self.headModel.loop('neutral') if self.variant == Variant.SKELETON: self.headModel = self.find("**/joint_head") #antenna = loader.loadModel("models/police_antenna.bam") ##antenna.reparentTo(self.find("**/joint_head")) #antenna.setPos(0.5, -0.5, 0) #antenna.setScale(1.25) #antenna.clearModelNodes() #antenna.flattenStrong() genHeadCollector.stop() self.setClothes() classScale = 1.0 #self.suitPlan.getCogClassAttrs().scaleMod self.setAvatarScale( (self.suitPlan.getScale() / SuitGlobals.scaleFactors[self.suit]) * classScale) self.setHeight(self.suitPlan.getHeight()) nametagCollector.start() if nameTag: self.setupNameTag() nametagCollector.stop() Avatar.initShadow(self) if self.variant != Variant.SKELETON: # We've already done all manipulating to the cog, we can just flatten it. self.getPart('body').flattenStrong() self.postFlatten() self.headModel.flattenStrong() if isinstance(self.headModel, Actor): self.headModel.postFlatten() #endTime = globalClock.getRealTime() #print("GenerateCog took {0} seconds".format(endTime - startTime)) generateCollector.stop()
def updateInfo(self, leftFrame = True, auxText = QuestGlobals.DEFEAT, frameColor = QuestGlobals.BLUE): Objective.updateInfo(self) self.didEditLeft = leftFrame if self.neededAmount > 1: infoText = str(self.neededAmount) elif not self.name: infoText = 'A' else: infoText = '' if self.level: infoText = str('%s Level %s' % (infoText, str(self.level))) elif self.levelRange: infoText = str('%s Level %s+' % (infoText, str(self.levelRange[0]))) if self.variant: variantText = CIGlobals.Skelesuit if self.neededAmount > 1: variantText = QuestGlobals.makePlural(variantText) infoText = str('%s %s' % (infoText, self.variant if self.neededAmount == 1 else QuestGlobals.makePlural(variantText))) if self.dept: deptName = self.dept.getName() if self.neededAmount == 1 else QuestGlobals.makePlural(self.dept.getName()) infoText = str('%s %s' % (infoText, deptName)) icons = loader.loadModel('phase_3/models/gui/cog_icons.bam') if self.dept == Dept.BOSS: icon = icons.find('**/CorpIcon') else: icon = icons.find('**/%sIcon' % self.dept.getTie().title()) icon.setColor(SuitGlobals.medallionColors[self.dept]) if leftFrame: self.quest.setLeftIconGeom(icon) self.quest.setLeftIconScale(0.13) else: self.quest.setRightIconGeom(icon) self.quest.setRightIconScale(0.13) icons.removeNode() elif not self.name: # Let's load up the general Cogs picture. icon = QuestGlobals.getCogIcon() if leftFrame: self.quest.setLeftIconGeom(icon) self.quest.setLeftIconScale(icon.getScale()) else: self.quest.setRightIconGeom(icon) self.quest.setRightIconScale(icon.getScale()) text = CIGlobals.Suit if self.neededAmount == 1 else CIGlobals.Suits infoText = str('%s %s' % (infoText, text)) if self.name: nameText = self.name if self.neededAmount > 1: nameText = QuestGlobals.makePlural(self.name) infoText = str('%s %s' % (infoText, nameText)) # Let's load up the head. head = SuitBank.getSuitByName(self.name).getHead().generate() head.setName('%sHead' % CIGlobals.Suit) head.setScale(2) head.setH(180) if leftFrame: self.quest.setLeftIconGeom(head) else: self.quest.setRightIconGeom(head) if leftFrame: self.quest.setInfoText(infoText) self.quest.setAuxText(auxText) else: self.quest.setInfo02Text(infoText) self.quest.setInfo02Pos(QuestGlobals.RECOVER_INFO2_POS) self.quest.setRightPicturePos(QuestGlobals.DEFAULT_RIGHT_PICTURE_POS) self.quest.setProgressText('%s of %s %s' % (self.amount, self.neededAmount, QuestGlobals.makePastTense(auxText).lower())) self.quest.setPictureFrameColor(frameColor)