コード例 #1
0
ファイル: Swordsman.py プロジェクト: jaimodha/MMOG
class Swordsman(Character):
    ATK_RANGE = 8
    BASIC_ATK_DMG = 15
    SPECIAL_ATK_DMG = 30
    MOVE_SPEED = 10
    CHARGE_SPEED = 15
    MAX_HEALTH = 100
    FOV = 60

    def __init__(self, *args):
        super(Swordsman, self).__init__(*args)
        Character.set_health(self, Swordsman.MAX_HEALTH)
        Character.set_speed(self, Swordsman.MOVE_SPEED)
        actor = Actor(
            "models/swordsman", {
                "idle": "models/swordsman-idle",
                "walk": "models/swordsman-walk",
                "run": "models/swordsman-run",
                "hurt": "models/swordsman-hurt",
                "die": "models/swordsman-die",
                "attack": "models/swordsman-attack"
            })

        team = Character.get_team(self)
        if team == 0:
            """
			actor = Actor("models/swordsman_red", 
						{"idle": "models/swordsman-idle", 
						 "walk": "models/swordsman-walk", 
						 "run": "models/swordsman-run", 
						 "hurt": "models/swordsman-hurt", 
						 "die": "models/swordsman-die", 
						 "attack": "models/swordsman-attack"})
			"""
            tex = loader.loadTexture("models/textures/swordsman_red.png")
            ts = actor.findTextureStage('*')
            actor.setTexture(ts, tex, 1)
            #ts = actor.findTextureStage('ts')
            #actor.setTexture(ts, tex)
        elif team == 1:
            """
			actor = Actor("models/swordsman_blue", 
						{"idle": "models/swordsman-idle", 
						 "walk": "models/swordsman-walk", 
						 "run": "models/swordsman-run", 
						 "hurt": "models/swordsman-hurt", 
						 "die": "models/swordsman-die", 
						 "attack": "models/swordsman-attack"})
			"""
            tex = loader.loadTexture("models/textures/swordsman_blue.png")
            ts = actor.findTextureStage('*')
            actor.setTexture(ts, tex, 1)
            #ts = actor.findTextureStage('ts')
            #actor.setTexture(ts, tex)

        Character.set_actor(self, actor)
        self.hb = HealthBar(1.5, value=Swordsman.MAX_HEALTH)
        self.hb.reparentTo(self._floater)
        self.hb.setValue(self.get_health())

        self.model = loader.loadModel("models/circle")
        self.model.setTransparency(True)
        self.model.reparentTo(self._character)
        self.model.setAlphaScale(0.5)
        self.model.setScale(2)
        self.model.setPos(0, 0, -10)

    def basic_attack(self):
        total_dmg = Swordsman.BASIC_ATK_DMG
        swing_sound = loader.loadSfx("sound/Swoosh.mp3")

        if self._atk_buff == 1:
            total_dmg *= 1.1
        elif self._atk_buff == 2:
            total_dmg *= 1.25

        sound_interval = SoundInterval(swing_sound,
                                       loop=2,
                                       duration=0.6,
                                       volume=0.7,
                                       startTime=0)
        atk_interval1 = self._character.actorInterval("attack",
                                                      startFrame=1,
                                                      endFrame=26)
        atk_interval2 = self._character.actorInterval("attack",
                                                      startFrame=56,
                                                      endFrame=80)
        seq = Sequence(atk_interval1, atk_interval2)
        if self._is_moving:
            seq.append(Func(self.animate, 2))
        seq2 = Sequence(Wait(0.5), sound_interval, sound_interval)
        seq.start()
        seq2.start()

        return total_dmg

    def special_attack(self):
        total_dmg = Swordsman.SPECIAL_ATK_DMG
        swing_sound = loader.loadSfx("sound/Swoosh.mp3")

        if self._atk_buff == 1:
            total_dmg *= 1.1
        elif self._atk_buff == 2:
            total_dmg *= 1.25

        sound_interval = SoundInterval(swing_sound,
                                       loop=2,
                                       duration=0.8,
                                       volume=0.7,
                                       startTime=0)
        atk_interval1 = self._character.actorInterval("attack",
                                                      startFrame=1,
                                                      endFrame=13)
        atk_interval2 = self._character.actorInterval("attack",
                                                      startFrame=38,
                                                      endFrame=80)
        seq = Sequence(atk_interval1, atk_interval2)
        if self._is_moving:
            seq.append(Func(self.animate, 2))
        seq2 = Sequence(Wait(0.5), sound_interval, sound_interval)
        seq.start()
        seq2.start()

        return total_dmg

    def take_damage(self, health_change):
        health = Character.get_health(self)
        if health < health_change and not self._is_dead:
            Character.set_health(self, 0)
            self.hb.setValue(0)
            hurt_interval = self._character.actorInterval("hurt")
            death_interval = self._character.actorInterval("die")
            seq = Sequence(hurt_interval, death_interval)
            seq.append(Wait(2))
            # add Func interval to place the character at a new location
            seq.append(Func(self.respawn))
            seq.start()
            self._is_dead = True
            #self._is_moving=2
        else:
            Character.set_health(self, health - health_change)
            #self.hb.setValue(Character.get_health(self)-health_change)
            self.hb.setValue(Character.get_health(self))
            self._character.play("hurt")

    def apply_def_buff(self):
        if not self._is_dead:
            health = Character.get_health(self)
            if self._def_buff == 1:
                Character.set_health(self, health * 1.1)
                Swordsman.MAX_HEALTH = Swordsman.MAX_HEALTH * 1.1
            elif self._def_buff == 2:
                Character.set_health(self, health * 1.25)
                Swordsman.MAX_HEALTH = Swordsman.MAX_HEALTH * 1.25

    def unapply_def_buff(self):
        if not self._is_dead:
            if self._def_buff == 0:
                Swordsman.MAX_HEALTH = 100
            elif Swordsman.MAX_HEALTH == 125 and self._def_buff == 1:
                Swordsman.MAX_HEALTH = 110

            health = Character.get_health(self)
            if health > Swordsman.MAX_HEALTH:
                health = Swordsman.MAX_HEALTH

    def animate(self, anim_type):
        if anim_type == 0:
            self._character.loop("idle")
        elif anim_type == 1:
            self._character.loop("walk")
        elif anim_type == 2:
            self._character.loop("run")
        elif anim_type == 3:
            atk_interval1 = self._character.actorInterval("attack",
                                                          startFrame=1,
                                                          endFrame=26)
            atk_interval2 = self._character.actorInterval("attack",
                                                          startFrame=56,
                                                          endFrame=80)
            seq = Sequence(atk_interval1, atk_interval2)
            seq.start()
        elif anim_type == 4:
            atk_interval1 = self._character.actorInterval("attack",
                                                          startFrame=1,
                                                          endFrame=13)
            atk_interval2 = self._character.actorInterval("attack",
                                                          startFrame=38,
                                                          endFrame=80)
            seq = Sequence(atk_interval1, atk_interval2)
            seq.start()
        elif anim_type == 5:
            self._character.play("hurt")
        elif anim_type == 6:
            self._character.play("die")

    def respawn(self):
        self._is_moving = 2
        self._character.loop("idle")
コード例 #2
0
ファイル: Swordsman.py プロジェクト: jaimodha/MMOG
class Swordsman(Character):
	ATK_RANGE = 8
	BASIC_ATK_DMG = 15
	SPECIAL_ATK_DMG = 30
	MOVE_SPEED = 10
	CHARGE_SPEED = 15
	MAX_HEALTH = 100
	FOV = 60

	def __init__(self, *args):
		super(Swordsman, self).__init__(*args)
		Character.set_health(self, Swordsman.MAX_HEALTH)
		Character.set_speed(self, Swordsman.MOVE_SPEED)
		actor = Actor("models/swordsman", 
						{"idle": "models/swordsman-idle", 
						 "walk": "models/swordsman-walk", 
						 "run": "models/swordsman-run", 
						 "hurt": "models/swordsman-hurt", 
						 "die": "models/swordsman-die", 
						 "attack": "models/swordsman-attack"})

		team = Character.get_team(self)
		if team == 0:
			"""
			actor = Actor("models/swordsman_red", 
						{"idle": "models/swordsman-idle", 
						 "walk": "models/swordsman-walk", 
						 "run": "models/swordsman-run", 
						 "hurt": "models/swordsman-hurt", 
						 "die": "models/swordsman-die", 
						 "attack": "models/swordsman-attack"})
			"""
			tex = loader.loadTexture("models/textures/swordsman_red.png")
			ts = actor.findTextureStage('*')
			actor.setTexture(ts, tex, 1)
			#ts = actor.findTextureStage('ts')
			#actor.setTexture(ts, tex)
		elif team == 1:
			"""
			actor = Actor("models/swordsman_blue", 
						{"idle": "models/swordsman-idle", 
						 "walk": "models/swordsman-walk", 
						 "run": "models/swordsman-run", 
						 "hurt": "models/swordsman-hurt", 
						 "die": "models/swordsman-die", 
						 "attack": "models/swordsman-attack"})
			"""
			tex = loader.loadTexture("models/textures/swordsman_blue.png")
			ts = actor.findTextureStage('*')
			actor.setTexture(ts, tex, 1)
			#ts = actor.findTextureStage('ts')
			#actor.setTexture(ts, tex)
		
		Character.set_actor(self, actor)
		self.hb = HealthBar(1.5, value=Swordsman.MAX_HEALTH)
		self.hb.reparentTo(self._floater)
		self.hb.setValue(self.get_health())
		
		self.model = loader.loadModel("models/circle")
		self.model.setTransparency(True)
		self.model.reparentTo(self._character)
		self.model.setAlphaScale(0.5)
		self.model.setScale(2)
		self.model.setPos(0, 0, -10)
		
	def basic_attack(self):
		total_dmg = Swordsman.BASIC_ATK_DMG
		swing_sound = loader.loadSfx("sound/Swoosh.mp3")

		if self._atk_buff==1:
			total_dmg *= 1.1
		elif self._atk_buff==2:
			total_dmg *= 1.25

		sound_interval = SoundInterval(
    								swing_sound,
    								loop = 2 ,
    								duration = 0.6,
    								volume = 0.7,
    								startTime = 0
									)
		atk_interval1 = self._character.actorInterval("attack", startFrame=1, endFrame=26)
		atk_interval2 = self._character.actorInterval("attack", startFrame=56, endFrame=80)
		seq = Sequence(atk_interval1, atk_interval2)
		if self._is_moving:
			seq.append(Func(self.animate, 2))
		seq2 = Sequence(Wait(0.5), sound_interval, sound_interval)
		seq.start()
		seq2.start()
		
		return total_dmg

	def special_attack(self):
		total_dmg = Swordsman.SPECIAL_ATK_DMG
		swing_sound = loader.loadSfx("sound/Swoosh.mp3")
			
		if self._atk_buff==1:
			total_dmg *= 1.1
		elif self._atk_buff==2:
			total_dmg *= 1.25

		sound_interval = SoundInterval(
    							swing_sound,
    							loop = 2 ,
    							duration = 0.8,
    							volume = 0.7,
    							startTime = 0
								)
		atk_interval1 = self._character.actorInterval("attack", startFrame=1, endFrame=13)
		atk_interval2 = self._character.actorInterval("attack", startFrame=38, endFrame=80)
		seq = Sequence(atk_interval1, atk_interval2)
		if self._is_moving:
			seq.append(Func(self.animate, 2))
		seq2 = Sequence(Wait(0.5), sound_interval, sound_interval)
		seq.start()
		seq2.start()
		
		return total_dmg

	def take_damage(self, health_change):
		health = Character.get_health(self)
		if health < health_change and not self._is_dead:
			Character.set_health(self, 0)
			self.hb.setValue(0)
			hurt_interval = self._character.actorInterval("hurt")
			death_interval = self._character.actorInterval("die")
			seq = Sequence(hurt_interval, death_interval)
			seq.append(Wait(2))
			# add Func interval to place the character at a new location
			seq.append(Func(self.respawn))
			seq.start()
			self._is_dead = True
			#self._is_moving=2
		else:
			Character.set_health(self, health-health_change)
			#self.hb.setValue(Character.get_health(self)-health_change)
			self.hb.setValue(Character.get_health(self))
			self._character.play("hurt")

	def apply_def_buff(self):
		if not self._is_dead:
			health = Character.get_health(self)
			if self._def_buff==1:
				Character.set_health(self, health*1.1)
				Swordsman.MAX_HEALTH = Swordsman.MAX_HEALTH*1.1
			elif self._def_buff==2:
				Character.set_health(self, health*1.25)
				Swordsman.MAX_HEALTH = Swordsman.MAX_HEALTH*1.25

	def unapply_def_buff(self):
		if not self._is_dead:
			if self._def_buff==0:
				Swordsman.MAX_HEALTH = 100
			elif Swordsman.MAX_HEALTH==125 and self._def_buff==1:
				Swordsman.MAX_HEALTH = 110

			health = Character.get_health(self)
			if health > Swordsman.MAX_HEALTH:
					health = Swordsman.MAX_HEALTH

	def animate(self, anim_type):
		if anim_type==0:
			self._character.loop("idle")
		elif anim_type==1:
			self._character.loop("walk")
		elif anim_type==2:
			self._character.loop("run")
		elif anim_type==3:
			atk_interval1 = self._character.actorInterval("attack", startFrame=1, endFrame=26)
			atk_interval2 = self._character.actorInterval("attack", startFrame=56, endFrame=80)
			seq = Sequence(atk_interval1, atk_interval2)
			seq.start()
		elif anim_type==4:
			atk_interval1 = self._character.actorInterval("attack", startFrame=1, endFrame=13)
			atk_interval2 = self._character.actorInterval("attack", startFrame=38, endFrame=80)
			seq = Sequence(atk_interval1, atk_interval2)
			seq.start()
		elif anim_type==5:
			self._character.play("hurt")
		elif anim_type==6:
			self._character.play("die")

	def respawn(self):
		self._is_moving=2
		self._character.loop("idle")
コード例 #3
0
ファイル: Npc.py プロジェクト: jaimodha/MMOG
class Npc():

    def __init__(self,controlPointId,id, anchorx, anchory, anchorz,render,team):
        self.id = id
        self.anchorx = anchorx
        self.anchory = anchory
        self.anchorz = anchorz
        self.controlPointId = controlPointId
        self.target = None
        self.isMoving = False
        self.health = 200
        self.isCurrentUser = False
        self.damage = 8
        self.attackTimer = 0
        self._is_dead = False
        self._team = team
        
        self.render = render
        '''Initializing NPC actors'''
        self.npc = Actor("models/priest",
                                {"walk": "models/priest-walk", "attack":"models/priest-attack", "hurt":"models/priest-hit", "die":"models/priest-die"})
        if self._team==0:
            self.npcTex = loader.loadTexture("models/tex/guard_red.png")
        else:
            self.npcTex = loader.loadTexture("models/tex/guard_blue.png")
        self.npc.setTexture(self.npcTex)
        self.npc.setScale(0.5, 0.5, 0.5)
        self.npc.clearColor()
        self.npc.clearColorScale()
        self.npc.setColor(255, 0, 0, 0)
        self.npc.setColorScale(255, 0, 0, 0)
        self.npc.reparentTo(self.render)
        self.npc.setPos(anchorx,anchory,anchorz)
        
        self.AIchar = AICharacter("npc"+str(self.id),self.npc, 100, 0.05, 5)
        self.AIbehaviors = self.AIchar.getAiBehaviors()
        
        self.hb = HealthBar(1.5, value=self.health)
        #self._floater = NodePath(PandaNode("char_info"))
        #self._floater.reparentTo(self.npc)
        self.hb.setPos(0, 0, 11.9)
        self.hb.reparentTo(self.npc)
        #self.hb.reparentTo(self.npc)
        
    def renderBlue(self,AIworld):
        if not self._is_dead:
            self.AIbehaviors.removeAi("pursue")
            self.npc.detachNode()
        
        print "Started delete procedure for npc ",
        print self.id    
        self.npc.delete()
        self.npc = Actor("models/priest",
                                {"walk": "models/priest-walk", "attack":"models/priest-attack", "hurt":"models/priest-hit", "die":"models/priest-die"})
        self.npcTex = loader.loadTexture("models/tex/guard_blue.png")
        self.npc.setTexture(self.npcTex)
        self.npc.setScale(0.5, 0.5, 0.5)
        self.npc.clearColor()
        self.npc.clearColorScale()
        self.npc.setColor(255, 0, 0, 0)
        self.npc.setColorScale(255, 0, 0, 0)
        self.npc.reparentTo(self.render)
        self.npc.setPos(self.anchorx,self.anchory,self.anchorz)
        
        AIworld.removeAiChar("npc"+str(self.id))
        self.AIchar = AICharacter("npc"+str(self.id),self.npc, 100, 0.05, 5)
        self.AIbehaviors = self.AIchar.getAiBehaviors()
        AIworld.addAiChar(self.AIchar)
        
        self.hb = HealthBar(1.5, value=self.health)
        self.hb.setPos(0, 0, 18.1)
        self.hb.reparentTo(self.npc)
        #self.hb.reparentTo(self.npc)
        
    def renderRed(self,AIworld):
        if not self._is_dead:
            self.AIbehaviors.removeAi("pursue")
            self.npc.detachNode()
            
        self.npc.delete()
        self.npc = Actor("models/priest",
                                {"walk": "models/priest-walk", "attack":"models/priest-attack", "hurt":"models/priest-hit", "die":"models/priest-die"})
        self.npcTex = loader.loadTexture("models/tex/guard_red.png")
        self.npc.setTexture(self.npcTex)
        self.npc.setScale(0.5, 0.5, 0.5)
        self.npc.clearColor()
        self.npc.clearColorScale()
        self.npc.setColor(255, 0, 0, 0)
        self.npc.setColorScale(255, 0, 0, 0)
        self.npc.reparentTo(self.render)
        self.npc.setPos(self.anchorx,self.anchory,self.anchorz)
        
        AIworld.removeAiChar("npc"+str(self.id))
        self.AIchar = AICharacter("npc"+str(self.id),self.npc, 100, 0.05, 5)
        self.AIbehaviors = self.AIchar.getAiBehaviors()
        AIworld.addAiChar(self.AIchar)
        AIworld.update()
        
        self.hb = HealthBar(1.5, value=self.health)
        self.hb.setPos(0, 0, 8.1)
        self.hb.reparentTo(self.npc)
        
    def switchTeam(self,AIworld):
        print self.id,
        print " from team ",
        print self._team,
        print " getting deleted."
        if self._team==0:
            self._team=1
            self.renderBlue(AIworld)
        else:
            self._team=0
            self.renderRed(AIworld)
            
        if self.isCurrentUser:
            main.freeDeadNpc(self.id)
            
        self.target = None
        self.isMoving = False
        self.health = 200
        self.isCurrentUser = False
        self.damage = 8
        self.attackTimer = 0
        self._is_dead = False
            
        
    def set_health(self, health):
        self.health = health
        
    def take_damage(self, health_change):
        health = self.health
        if health <= health_change and not self._is_dead:
            self.killNpc()
        else:
            health = health-health_change
            self.set_health(health)
            self.hb.setValue(self.health)
            self.npc.play("hurt")
            
    def killNpc(self):
        self.set_health(0)
        self.hb.setValue(0)
        self.AIbehaviors.removeAi("pursue")
        hurt_interval = self.npc.actorInterval("hurt")
        death_interval = self.npc.actorInterval("die")
        seq = Sequence(hurt_interval, death_interval)
        seq.start()
        self.npc.pose("die",45)
        self._is_dead = True
        self.npc.detachNode()
        if self.isCurrentUser:
            main.freeDeadNpc(self.id)
            #main.cManager.sendRequest(Constants.CMSG_NPCDEATH, [self.id])
            print Constants.CMSG_NPCDEATH,
            print " + ",
            print self.id
            
            
    def chaseTarget(self, target, status = False):
        if(not self.isMoving):
            self.target = target
            self.AIbehaviors.pursue(self.target)
            self.npc.loop("walk")
            self.isMoving = True
            self.isCurrentUser = status
            
    def stopChase(self):
        
        #self.AIbehaviors.pauseAi("pursue")
        if not self._is_dead:
            self.AIbehaviors.removeAi("pursue")
            p1 = LerpHprInterval(self.npc, 4, Point3(180,0,0))
            p2 = LerpPosInterval(self.npc, 4, Point3(self.anchorx, self.anchory, self.anchorz))
            animInterval = self.npc.actorInterval("walk", loop = 1, duration=4)
            p2.start()
            p1.start()
            animInterval.start()
            self.isMoving = False
            self.target = None
            self.isCurrentUser = False
        
    def givNPCDistance(self,charachter):
        x = self.npc.getX()
        y = self.npc.getY()
        z = self.npc.getZ()
        minDist = math.sqrt( (charachter.getX()-x)*(charachter.getX()-x) + (charachter.getY()-y)*(charachter.getY()-y) + (charachter.getZ()-z)*(charachter.getZ()-z) )
        return minDist
    
    def checkNpcIsAlive(self):
        if(self.health>0):
            return True
        else:
            return False
                         
    def shouldAttack(self,currentTime,cManager):
        if not self._is_dead:
            if self.isMoving:
                if self.attackTimer>0:
                    self.attackTimer = self.attackTimer-currentTime
                    #print self.attackTimer
                if self.AIbehaviors.behaviorStatus("pursue")=="done":
                    #self.npc.stop("walk")
                    #print self.npc.getAnimControl("walk")
                    if self.attackTimer<=0:
                            if self.npc.getAnimControl("walk").isPlaying():
                                self.npc.stop("walk")
                            if not self.npc.getAnimControl("attack").isPlaying():
                                #self.npc.loop("attack")
                                self.npc.play("attack")
                                self.attackTimer = 2
                                #myInterval = self.npc.actorInterval("attack")
                                #seq = Sequence(myInterval)
                                #seq.append(Wait(3))
                                #seq.start()
                            if self.isCurrentUser:
                                cManager.sendRequest(Constants.CMSG_NPCATTACK, [self.id, self.damage])
                
                if self.AIbehaviors.behaviorStatus("pursue")=="active":
                    if self.npc.getAnimControl("attack").isPlaying():
                        self.npc.stop("attack")
                    if not self.npc.getAnimControl("walk").isPlaying():
                        self.npc.loop("walk") 
コード例 #4
0
class Axeman(Character):
    BASIC_ATK_DMG = 12
    SPECIAL_ATK_DMG = 40
    MAX_HEALTH = 120
    ATK_RANGE = 8
    MOVE_SPEED = 8
    FOV = 60
    
    def __init__(self, *args):
        super(Axeman, self).__init__(*args)
        Character.set_health(self, Axeman.MAX_HEALTH)
        actor = Actor("models/axeman", {"idle": "models/axeman-idle", 
                                        "walk": "models/axeman-walk", 
                                        "run": "models/axeman-run" ,
                                        "hurt": "models/axeman-hurt", 
                                        "die": "models/axeman-die", 
                                        "attack": "models/axeman-swing", 
                                        "special":"models/axeman-special-attack"})
        Character.set_speed(self, Axeman.MOVE_SPEED)

        # loda texture based on team 
        team = Character.get_team(self)
        if team == 0:
            tex = loader.loadTexture("models/textures/axeman_red.png")
            ts = actor.findTextureStage("*")
            actor.setTexture(ts, tex, 1)
        elif team == 1:
            tex = loader.loadTexture("models/textures/axeman_blue.png")
            ts = actor.findTextureStage('*')
            actor.setTexture(ts, tex, 1)

        Character.set_actor(self, actor)

        #attach axe 
        rightHand = self._character.exposeJoint(None, 'modelRoot', 'hand_ctrl_r')
        axe = loader.loadModel("models/axe")
        axe_tex = loader.loadTexture("models/textures/axe.png")
        axe.setTexture(axe_tex, 1)
        axe.setPos(-3.0, 0.6, -0.2)
        axe.setHpr(0, -90, -90)
        axe.setScale(10)
        axe.reparentTo(rightHand)
        axe.show()

        self.hb = HealthBar(1.5, value=Axeman.MAX_HEALTH)
       	self.hb.reparentTo(self._floater)

	self.hb.setValue(self.get_health())
		
        model = loader.loadModel("models/circle")
        model.setTransparency(True)
        model.reparentTo(self._character)
        model.setAlphaScale(0.5)
        model.setScale(2)
        model.setPos(0, 0, -10)
		
        
    def basic_attack(self):
        total_dmg = Axeman.BASIC_ATK_DMG
        swing_sound = loader.loadSfx("sound/Woosh.wav")
        
        if self._atk_buff==1:
            total_dmg *= 1.1
        elif self._atk_buff==2:
            total_dmg *= 1.25
        # play animation
        sound_interval1 = SoundInterval(
                                    swing_sound,
                                    loop = 1 ,
                                    duration = 0,
                                    volume = 0.7,
                                    startTime = 0
                                    )
        seq2 = Sequence(Wait(0.5),sound_interval1, sound_interval1)
        #self._character.play("attack")
        atk_interval = self._character.actorInterval("attack")
        seq = Sequence(atk_interval)
        if self._is_moving:
            seq.append(Func(self.animate, 2))
        seq.start()
        seq2.start()

        return total_dmg

          
    def special_attack(self):
        total_dmg = Axeman.SPECIAL_ATK_DMG
        
        if self._atk_buff==1:
            total_dmg *= 1.1
        elif self._atk_buff==2:
            total_dmg *= 1.25
         
        #self._character.play("special",fromFrame = 10)
        atk_interval = self._character.actorInterval("special", startFrame=10)
        seq = Sequence(atk_interval)
        if self._is_moving:
            seq.append(Func(self.animate, 2))
        seq.start()

        return total_dmg

    def apply_def_buff(self):
        if not self._is_dead:
            health = Character.get_health(self)
            if self._def_buff==1:
                Character.set_health(self, health*1.1)
                Axeman.MAX_HEALTH = Axeman.MAX_HEALTH*1.1
            elif self._def_buff==2:
                Character.set_health(self, health*1.25)
                Axeman.MAX_HEALTH = Axeman.MAX_HEALTH*1.25
        
    def unapply_def_buff(self):
        if not self._is_dead:
            if self._def_buff==0:
                Axeman.MAX_HEALTH = 100
            elif Axeman.MAX_HEALTH==140 and self._def_buff==1:
                Axeman.MAX_HEALTH = 110

            health = Character.get_health(self)
            if health > Axeman.MAX_HEALTH:
                    health = Axeman.MAX_HEALTH
        pass
       
    def take_damage(self, health_change):
        health = Character.get_health(self)
        if health <= health_change and not self._is_dead:
            Character.set_health(self, 0)
            self.hb.setValue(0)
            hurt_interval = self._character.actorInterval("hurt")
            death_interval = self._character.actorInterval("die")
            seq = Sequence(hurt_interval, death_interval)
            seq.append(Wait(2))
            seq.append(Func(self.respawn))
            seq.start()
            self._is_dead = True
        else:
            Character.set_health(self, health-health_change)
            #self.hb.setValue(Character.get_health(self)-health_change)
            self.hb.setValue(Character.get_health(self))
            self._character.play("hurt")

    def animate(self, anim_type):
        if anim_type==0:
            self._character.loop("idle")
        elif anim_type==1:
            self._character.loop("walk")
        elif anim_type==2:
            self._character.loop("run")
        elif anim_type==3:
            self._character.play("attack")
        elif anim_type==4:
            self._character.play("special",fromFrame = 10)
        elif anim_type==5:
            self._character.play("hurt")
        elif anim_type==6:
            self._character.play("die")

    def respawn(self):
        self._is_moving=2
        self._character.loop("idle")
コード例 #5
0
ファイル: Axeman.py プロジェクト: jaimodha/MMOG
class Axeman(Character):
    BASIC_ATK_DMG = 12
    SPECIAL_ATK_DMG = 40
    MAX_HEALTH = 120
    ATK_RANGE = 3
    MOVE_SPEED = 8
    FOV = 45
    
    def __init__(self, *args):
        super(Axeman, self).__init__(*args)
        Character.set_health(self, Axeman.MAX_HEALTH)
        actor = Actor("models/axeman", {"idle": "models/axeman-idle", 
                                        "walk": "models/axeman-walk", 
                                        "run": "models/axeman-run" ,
                                        "hurt": "models/axeman-hurt", 
                                        "die": "models/axeman-die", 
                                        "attack": "models/axeman-swing", 
                                        "special":"models/axeman-special-attack"})
        Character.set_speed(self, Axeman.MOVE_SPEED)

        # loda texture based on team 
        team = Character.get_team(self)
        if team == 0:
            tex = loader.loadTexture("models/textures/axeman_red.png")
            ts = actor.findTextureStage("*")
            actor.setTexture(ts, tex, 1)
        elif team == 1:
            tex = loader.loadTexture("models/textures/axeman_blue.png")
            ts = actor.findTextureStage('*')
            actor.setTexture(ts, tex, 1)

        Character.set_actor(self, actor)

        #attach axe 
        rightHand = self._character.exposeJoint(None, 'modelRoot', 'hand_ctrl_r')
        axe = loader.loadModel("models/axe")
        axe_tex = loader.loadTexture("models/textures/axe.png")
        axe.setTexture(axe_tex, 1)
        axe.setPos(-3.0, 0.6, -0.2)
        axe.setHpr(0, -90, -90)
        axe.setScale(10)
        axe.reparentTo(rightHand)
        axe.show()

        self.hb = HealthBar(1.5, value=Axeman.MAX_HEALTH)
        self.hb.reparentTo(self._character)
		
        model = loader.loadModel("models/circle")
        model.setTransparency(True)
        model.reparentTo(self._character)
        model.setAlphaScale(0.5)
        model.setScale(2)
        model.setPos(0, 0, -10)
		
        
    def basic_attack(self):
        total_dmg = Axeman.BASIC_ATK_DMG
        swing_sound = loader.loadSfx("sound/Woosh.wav")
        
        if self._atk_buff==1:
            total_dmg *= 1.1
        elif self._atk_buff==2:
            total_dmg *= 1.25
        # play animation
        sound_interval1 = SoundInterval(
                                    swing_sound,
                                    loop = 1 ,
                                    duration = 0,
                                    volume = 0.7,
                                    startTime = 0
                                    )
        seq2 = Sequence(Wait(0.5),sound_interval1, sound_interval1)
        #self._character.play("attack")
        atk_interval = self._character.actorInterval("attack")
        seq = Sequence(atk_interval)
        if self._is_moving:
            seq.append(Func(self.loop_run))
        seq.start()
        seq2.start()

        return total_dmg

          
    def special_attack(self):
        total_dmg = Axeman.SPECIAL_ATK_DMG
        
        if self._atk_buff==1:
            total_dmg *= 1.1
        elif self._atk_buff==2:
            total_dmg *= 1.25
         
        #self._character.play("special",fromFrame = 10)
        atk_interval = self._character.actorInterval("special", startFrame=10)
        seq = Sequence(atk_interval)
        if self._is_moving:
            seq.append(Func(self.loop_run))
        seq.start()

        return total_dmg
             
    def loop_run(self):
        self._character.loop("run")

    def apply_def_buff(self):
        if not self._is_dead:
            health = Character.get_health(self)
            if self._def_buff==1:
                Character.set_health(self, health*1.1)
                Axeman.MAX_HEALTH = Axeman.MAX_HEALTH*1.1
            elif self._def_buff==2:
                Character.set_health(self, health*1.25)
                Axeman.MAX_HEALTH = Axeman.MAX_HEALTH*1.25
        
    def unapply_def_buff(self):
        if not self._is_dead:
            if self._def_buff==0:
                Axeman.MAX_HEALTH = 100
            elif Axeman.MAX_HEALTH==140 and self._def_buff==1:
                Axeman.MAX_HEALTH = 110

            health = Character.get_health(self)
            if health > Axeman.MAX_HEALTH:
                    health = Axeman.MAX_HEALTH
        pass
       
    def take_damage(self, health_change):
        health = Character.get_health(self)
        if health <= health_change and not self._is_dead:
            Character.set_health(self, 0)
            self.hb.setValue(0)
            hurt_interval = self._character.actorInterval("hurt")
            death_interval = self._character.actorInterval("die")
            seq = Sequence(hurt_interval, death_interval)
            seq.start()
            self._is_dead = True
        else:
            Character.set_health(self, health-health_change)
            self.hb.setValue(Character.get_health(self)-health_change)
            self._character.play("hurt")

    def animate(self, anim_type):
        if anim_type==0:
            self._character.loop("idle")
        elif anim_type==1:
            self._character.loop("walk")
        elif anim_type==2:
            self._character.loop("run")
        elif anim_type==3:
            self._character.play("attack")
        elif anim_type==4:
            self._character.play("special",fromFrame = 10)
        elif anim_type==5:
            self._character.play("hurt")
        elif anim_type==6:
            self._character.play("die")
コード例 #6
0
ファイル: Npc.py プロジェクト: jaimodha/MMOG
class Npc():
    def __init__(self, controlPointId, id, anchorx, anchory, anchorz, render,
                 team):
        self.id = id
        self.anchorx = anchorx
        self.anchory = anchory
        self.anchorz = anchorz
        self.controlPointId = controlPointId
        self.target = None
        self.isMoving = False
        self.health = 200
        self.isCurrentUser = False
        self.damage = 8
        self.attackTimer = 0
        self._is_dead = False
        self._team = team

        self.render = render
        '''Initializing NPC actors'''
        self.npc = Actor(
            "models/priest", {
                "walk": "models/priest-walk",
                "attack": "models/priest-attack",
                "hurt": "models/priest-hit",
                "die": "models/priest-die"
            })
        if self._team == 0:
            self.npcTex = loader.loadTexture("models/tex/guard_red.png")
        else:
            self.npcTex = loader.loadTexture("models/tex/guard_blue.png")
        self.npc.setTexture(self.npcTex)
        self.npc.setScale(0.5, 0.5, 0.5)
        self.npc.clearColor()
        self.npc.clearColorScale()
        self.npc.setColor(255, 0, 0, 0)
        self.npc.setColorScale(255, 0, 0, 0)
        self.npc.reparentTo(self.render)
        self.npc.setPos(anchorx, anchory, anchorz)

        self.AIchar = AICharacter("npc" + str(self.id), self.npc, 100, 0.05, 5)
        self.AIbehaviors = self.AIchar.getAiBehaviors()

        self.hb = HealthBar(1.5, value=self.health)
        #self._floater = NodePath(PandaNode("char_info"))
        #self._floater.reparentTo(self.npc)
        self.hb.setPos(0, 0, 11.9)
        self.hb.reparentTo(self.npc)
        #self.hb.reparentTo(self.npc)

    def renderBlue(self, AIworld):
        if not self._is_dead:
            self.AIbehaviors.removeAi("pursue")
            self.npc.detachNode()

        print "Started delete procedure for npc ",
        print self.id
        self.npc.delete()
        self.npc = Actor(
            "models/priest", {
                "walk": "models/priest-walk",
                "attack": "models/priest-attack",
                "hurt": "models/priest-hit",
                "die": "models/priest-die"
            })
        self.npcTex = loader.loadTexture("models/tex/guard_blue.png")
        self.npc.setTexture(self.npcTex)
        self.npc.setScale(0.5, 0.5, 0.5)
        self.npc.clearColor()
        self.npc.clearColorScale()
        self.npc.setColor(255, 0, 0, 0)
        self.npc.setColorScale(255, 0, 0, 0)
        self.npc.reparentTo(self.render)
        self.npc.setPos(self.anchorx, self.anchory, self.anchorz)

        AIworld.removeAiChar("npc" + str(self.id))
        self.AIchar = AICharacter("npc" + str(self.id), self.npc, 100, 0.05, 5)
        self.AIbehaviors = self.AIchar.getAiBehaviors()
        AIworld.addAiChar(self.AIchar)

        self.hb = HealthBar(1.5, value=self.health)
        self.hb.setPos(0, 0, 18.1)
        self.hb.reparentTo(self.npc)
        #self.hb.reparentTo(self.npc)

    def renderRed(self, AIworld):
        if not self._is_dead:
            self.AIbehaviors.removeAi("pursue")
            self.npc.detachNode()

        self.npc.delete()
        self.npc = Actor(
            "models/priest", {
                "walk": "models/priest-walk",
                "attack": "models/priest-attack",
                "hurt": "models/priest-hit",
                "die": "models/priest-die"
            })
        self.npcTex = loader.loadTexture("models/tex/guard_red.png")
        self.npc.setTexture(self.npcTex)
        self.npc.setScale(0.5, 0.5, 0.5)
        self.npc.clearColor()
        self.npc.clearColorScale()
        self.npc.setColor(255, 0, 0, 0)
        self.npc.setColorScale(255, 0, 0, 0)
        self.npc.reparentTo(self.render)
        self.npc.setPos(self.anchorx, self.anchory, self.anchorz)

        AIworld.removeAiChar("npc" + str(self.id))
        self.AIchar = AICharacter("npc" + str(self.id), self.npc, 100, 0.05, 5)
        self.AIbehaviors = self.AIchar.getAiBehaviors()
        AIworld.addAiChar(self.AIchar)
        AIworld.update()

        self.hb = HealthBar(1.5, value=self.health)
        self.hb.setPos(0, 0, 8.1)
        self.hb.reparentTo(self.npc)

    def switchTeam(self, AIworld):
        print self.id,
        print " from team ",
        print self._team,
        print " getting deleted."
        if self._team == 0:
            self._team = 1
            self.renderBlue(AIworld)
        else:
            self._team = 0
            self.renderRed(AIworld)

        if self.isCurrentUser:
            main.freeDeadNpc(self.id)

        self.target = None
        self.isMoving = False
        self.health = 200
        self.isCurrentUser = False
        self.damage = 8
        self.attackTimer = 0
        self._is_dead = False

    def set_health(self, health):
        self.health = health

    def take_damage(self, health_change):
        health = self.health
        if health <= health_change and not self._is_dead:
            self.killNpc()
        else:
            health = health - health_change
            self.set_health(health)
            self.hb.setValue(self.health)
            self.npc.play("hurt")

    def killNpc(self):
        self.set_health(0)
        self.hb.setValue(0)
        self.AIbehaviors.removeAi("pursue")
        hurt_interval = self.npc.actorInterval("hurt")
        death_interval = self.npc.actorInterval("die")
        seq = Sequence(hurt_interval, death_interval)
        seq.start()
        self.npc.pose("die", 45)
        self._is_dead = True
        self.npc.detachNode()
        if self.isCurrentUser:
            main.freeDeadNpc(self.id)
            #main.cManager.sendRequest(Constants.CMSG_NPCDEATH, [self.id])
            print Constants.CMSG_NPCDEATH,
            print " + ",
            print self.id

    def chaseTarget(self, target, status=False):
        if (not self.isMoving):
            self.target = target
            self.AIbehaviors.pursue(self.target)
            self.npc.loop("walk")
            self.isMoving = True
            self.isCurrentUser = status

    def stopChase(self):

        #self.AIbehaviors.pauseAi("pursue")
        if not self._is_dead:
            self.AIbehaviors.removeAi("pursue")
            p1 = LerpHprInterval(self.npc, 4, Point3(180, 0, 0))
            p2 = LerpPosInterval(
                self.npc, 4, Point3(self.anchorx, self.anchory, self.anchorz))
            animInterval = self.npc.actorInterval("walk", loop=1, duration=4)
            p2.start()
            p1.start()
            animInterval.start()
            self.isMoving = False
            self.target = None
            self.isCurrentUser = False

    def givNPCDistance(self, charachter):
        x = self.npc.getX()
        y = self.npc.getY()
        z = self.npc.getZ()
        minDist = math.sqrt((charachter.getX() - x) * (charachter.getX() - x) +
                            (charachter.getY() - y) * (charachter.getY() - y) +
                            (charachter.getZ() - z) * (charachter.getZ() - z))
        return minDist

    def checkNpcIsAlive(self):
        if (self.health > 0):
            return True
        else:
            return False

    def shouldAttack(self, currentTime, cManager):
        if not self._is_dead:
            if self.isMoving:
                if self.attackTimer > 0:
                    self.attackTimer = self.attackTimer - currentTime
                    #print self.attackTimer
                if self.AIbehaviors.behaviorStatus("pursue") == "done":
                    #self.npc.stop("walk")
                    #print self.npc.getAnimControl("walk")
                    if self.attackTimer <= 0:
                        if self.npc.getAnimControl("walk").isPlaying():
                            self.npc.stop("walk")
                        if not self.npc.getAnimControl("attack").isPlaying():
                            #self.npc.loop("attack")
                            self.npc.play("attack")
                            self.attackTimer = 2
                            #myInterval = self.npc.actorInterval("attack")
                            #seq = Sequence(myInterval)
                            #seq.append(Wait(3))
                            #seq.start()
                        if self.isCurrentUser:
                            cManager.sendRequest(Constants.CMSG_NPCATTACK,
                                                 [self.id, self.damage])

                if self.AIbehaviors.behaviorStatus("pursue") == "active":
                    if self.npc.getAnimControl("attack").isPlaying():
                        self.npc.stop("attack")
                    if not self.npc.getAnimControl("walk").isPlaying():
                        self.npc.loop("walk")