def enemyUpdater(self, task): if self._stateHandlerRef.state != self._stateHandlerRef.PLAY or not self._enemyActive: self.enemyModel.stop() # Do not do anything when paused return task.cont self.checkGroundCollisions() if self.getIsDead(): self.onDeath() return task.done if self._playerRef.getIsDead(): return task.cont playerPos = self._playerRef.playerNode.getPos() enemyPos = self.enemyNode.getPos() # If player is within enemy perception range if utils.getIsInRange(playerPos, enemyPos, self.perceptionRange): # If enemy is not doing anything if self.state == 'Idle': # Start pursuing if self.state != 'Pursue': self.request('Pursue') # If enemy is already pursueing elif self.state == 'Pursue': # If player is within combat range if utils.getIsInRange(playerPos, enemyPos, self.combatRange): #print 'enemy go to combat' # Go to combat if self.state != 'Combat': self.request('Combat') # If enemy is already in combat elif self.state == 'Combat': # If player has moved out of combat range if not utils.getIsInRange(playerPos, enemyPos, self.combatRange): # Start pursuing if self.state != 'Pursue': self.request('Pursue') # If enemy is disabled elif self.state == 'Disabled': if self.enemyAI.getMaxForce() != self.movementSpeed: self.enemyAI.setMaxForce(self.movementSpeed) # If player is not within perception range else: if self.state != 'Idle': self.request('Idle') return task.cont
def shiftTheBattlefield(self): bSuccess = False playerPos = self.playerNode.getPos() for enemy in self._enemyListRef: enemyPos = enemy.enemyNode.getPos() if utils.getIsInRange(playerPos, enemyPos, self.combatRange): bSuccess = True if self.getStrengthModifier() + utils.getD20() > enemy.armorClass: self._hudRef.printFeedback('Shift the Battlefield hit', True) self.enemyFleeFromPlayer(enemy) # Might want to replace the getD8 to depend on the player's weapon dmg = 2 * utils.getD8() + self.getStrengthModifier() enemy.receiveDamage(dmg) enemy.enemyModel.play('hit') else: #print 'shiftTheBattlefield missed' self._hudRef.printFeedback('Shift the Battlefield missed') dmg = (2 * utils.getD8() + self.getStrengthModifier()) / 2 enemy.receiveDamage(dmg) enemy.enemyModel.play('hit') return bSuccess
def thicketOfBlades(self): bSuccess = False numEntries = self.attackCollisionHandler.getNumEntries() if numEntries > 0: self.attackCollisionHandler.sortEntries() for i in range(numEntries): entry = self.attackCollisionHandler.getEntry(i).getIntoNode() entryName = entry.getName()[:-6] #print('entryFound:', entryName) enemy = utils.enemyDictionary[entryName] if enemy is not None and not enemy.getIsDead(): if utils.getIsInRange(self.playerNode.getPos(), enemy.enemyNode.getPos(), self.combatRange): bSuccess = True if self.getStrengthModifier() + utils.getD20() > enemy.armorClass: self._hudRef.printFeedback('Thicket of Blades hit', True) enemy.slowMovementByPercentage(50, 10) # slow by 50 % in 10 seconds, automatically removes it again enemy.enemyModel.play('hit') else: #print 'thicketOfBlades missed' self._hudRef.printFeedback('Thicket of Blades missed') return bSuccess
def shiftAttack(self, task): if self._stateHandlerRef.state != self._stateHandlerRef.PLAY: return task.done #print 'shiftAttack. shift:', self._shiftButtonDown if self._shiftButtonDown and base.mouseWatcherNode.hasMouse(): #print 'attack!' self.playerModel.play('attack') self.plane = Plane(Vec3(0, 0, 1), Point3(0, 0, 0)) mousePos = base.mouseWatcherNode.getMouse() pos3d = Point3() nearPoint = Point3() farPoint = Point3() base.camLens.extrude(mousePos, nearPoint, farPoint) if self.plane.intersectsLine(pos3d, base.render.getRelativePoint(camera, nearPoint), base.render.getRelativePoint(camera, farPoint)): #print('Mouse ray intersects ground at ', pos3d) destination = pos3d pitchRoll = self.playerNode.getP(), self.playerNode.getR() self.playerNode.headsUp(destination) self.playerNode.setHpr(self.playerNode.getH(), *pitchRoll) numEntries = self.attackCollisionHandler.getNumEntries() if numEntries > 0: self.attackCollisionHandler.sortEntries() bAttacked = 0 for i in range(numEntries): entry = self.attackCollisionHandler.getEntry(i).getIntoNode() entryName = entry.getName()[:-6] #print('entryFound:', entryName) enemy = utils.enemyDictionary[entryName] if enemy is not None and not enemy.getIsDead(): if utils.getIsInRange(self.playerNode.getPos(), enemy.enemyNode.getPos(), self.combatRange): bAttacked = self.attack(enemy) # Returns 1 if player attacked but did not hit, returns 2 on hit if bAttacked != 0: #print('attackEnemies') for i in range(numEntries): enemyTargetName = self.attackCollisionHandler.getEntry(i).getIntoNode().getName()[:-6] enemyTarget = utils.enemyDictionary[enemyTargetName] if enemyTarget is not None and not enemyTarget.getIsDead(): self.setCurrentTarget(enemyTarget) break; return task.again else: self.playerModel.stop() return task.done
def applyPointLightToObj(self, newPLightNode, obj): if len(obj.getChildren()) > 1: #print 'apply light to the children of:', obj for newObj in obj.getChildren(): self.applyPointLightToObj(newPLightNode, newObj) else: if utils.getIsInRange(obj.getPos(render), newPLightNode.getPos(render), 2): #print 'apply light from ', newPLightNode, ' to ', obj obj.setLight(newPLightNode)
def updateHealthGoblet(self, task): playerNode = self._playerRef.playerNode if utils.getIsInRange(playerNode.getPos(), self.healthGobletNode.getPos(), self.perceptionRange): print 'healed player for:', self.healthGiven self._playerRef.heal(self.healthGiven) self.healthGobletModel.stop() self.suicide() return task.done return task.again
def attackEnemies(self, task): if self._stateHandlerRef.state != self._stateHandlerRef.PLAY: return task.done if self._shiftButtonDown: return task.again numEntries = self.attackCollisionHandler.getNumEntries() if numEntries > 0: self.attackCollisionHandler.sortEntries() bAttacked = 0 for i in range(numEntries): entry = self.attackCollisionHandler.getEntry(i).getIntoNode() entryName = entry.getName()[:-6] #print('entryFound:', entryName) enemy = utils.enemyDictionary[entryName] if enemy is not None and not enemy.getIsDead(): if utils.getIsInRange(self.playerNode.getPos(), enemy.enemyNode.getPos(), self.combatRange): bAttacked = self.attack(enemy) # Returns 1 if player attacked but did not hit, returns 2 on hit if bAttacked == 2: enemy.enemyModel.play('hit') # Only play animations if player actually attacked if bAttacked != 0: #print('attackEnemies') self.playerModel.play('attack') for i in range(numEntries): enemyTargetName = self.attackCollisionHandler.getEntry(i).getIntoNode().getName()[:-6] enemyTarget = utils.enemyDictionary[enemyTargetName] if enemyTarget is not None and not enemyTarget.getIsDead(): self.setCurrentTarget(enemyTarget) break; return task.again else: #print('go to idle') self.removeCurrentTarget() if self.state == 'Combat': self.request('Idle') return task.done
def updatePlayerLights(self, task): # If time between frames is way too much, stop the task here if globalClock.getDt() > .5: return task.again playerNode = self._playerRef.playerNode if len(self.pointLightList) > 0: # Make point lights light up player as well for plight in self.pointLightList: if utils.getIsInRange(plight.getPos(render), playerNode.getPos(render), 2): playerNode.setLight(plight) else: if playerNode.hasLight(plight): playerNode.clearLight(plight) return task.cont
def areaTransitionChecker(self, task): player = self._playerRef playerNode = player.playerNode if utils.getIsInRange(self.oII.getPos(render), playerNode.getPos(render), .5): if not player.areaTransitioning: #print 'fire up area transition dialog' player.areaTransitioning = True self.exitGate.play(self.exitGateAnim, fromFrame=0, toFrame=12) else: if player.areaTransitioning: #print 'close area transition dialog' player.areaTransitioning = False self.exitGate.play(self.exitGateAnim, fromFrame=13, toFrame=25) return task.again
def enemySpawnActivator(self, task): if self._playerRef is None: # Load player reference self._playerRef = self._mainRef.player playerPos = self._playerRef.playerNode.getPos() for enemy in self._enemyListRef: if not enemy._enemyActive: node = enemy.enemyNode if utils.getIsInRange(playerPos, node.getPos(), enemy.perceptionRange * 2): node.show() enemy._enemyActive = True enemy.request('Idle') #print('activate enemy') # Call again after initial delay to reduce overhead return task.again