Exemple #1
1
class PoisonBolt(object):
	
	range = 4
	damage = 1, 4
	heal = False
	name = "Poison bolt"
	color = THECOLORS['green']
	icon = "magicbolt"
	cooldown = 0
	
	def __init__(self, caster, location, item):
		self.item = item
		self.caster = caster
		self.target = location
		self.range = self.__class__.range
		self.damage = self.__class__.damage
		self.color = self.__class__.color
		casterName = self.caster.getName()
		self.entityHit = self.caster.world.getEntityFromLocation(self.target)
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at nothing!')
		
		self.projectile = Star(caster.position, location, self.color, self.fire, self.impact)
		self.done = False
	 
	def update(self):
		self.projectile.update()
		if self.projectile.done:
			if not self.entityHit is None:
				self.entityHit.inflict(self.caster, randint(self.damage[0], self.damage[1]))
			self.done = True
			return True
		
		return False
		
	def draw(self, surface, position, visible):
		if not self.done:
			self.projectile.draw(surface, position, visible)
	
	@classmethod
	def validTarget(cls, actor, target):

		if not target in actor.getEnemies():
			return False

		if not target.isAlive():
			return False

		if not actor.partyCanSee(target.position):
			return False

		return True

	def fire(self):
		self.caster.world.sounds.get("magic-missile.wav").play()
	
	def impact(self):
		self.caster.world.sounds.get("fireball-impact.wav").play()
Exemple #2
0
class HealBolt(object):
	
	range = 5
	damage = 2, 5
	heal = True
	name = "Heal Bolt"
	icon = "healbolt"
	cooldown = 0
	
	def __init__(self, caster, location, item):
		self.item = item
		self.caster = caster
		self.target = location
		self.done = False
		self.color = THECOLORS['yellow']
		self.entityHit = self.caster.world.getEntityFromLocation(self.target)
		self.projectile = Star(caster.position, self.target, self.color, self.fire)
		casterName = self.caster.getName()
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast Heal at ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast Heal at nothing!')
	 
	def update(self):
		pos = None
		if self.entityHit is not None:
			pos = self.entityHit.position
		self.projectile.update(pos)
		if self.projectile.done:
			if not self.entityHit is None:
				self.entityHit.heal(self.caster, randint(self.damage[0], self.damage[1]))
			self.done = True
			return True
		return False
		
	def draw(self, surface, position, visible):
		if not self.done:
			self.projectile.draw(surface, position, visible)
	
	@classmethod
	def validTarget(cls, actor, target):

		if not target in actor.getFriends():
			return False

		if not target.isAlive():
			return False

		if target.health / target.maxHealth > 0.8:
			return False

		if not actor.partyCanSee(target.position):
			return False

		return True
		
	
	def fire(self):
		self.caster.world.sounds.get("spell-healing.wav").play()
Exemple #3
0
class Resurrection(object):
	
	range = 5
	color = THECOLORS['palegoldenrod']
	heal = True
	name = "Ressurection"
	icon = "ankh"
	cooldown = 0
	
	def __init__(self, caster, location, item):
		self.range = self.__class__.range
		self.caster = caster
		self.target = location
		self.done = False
		self.entityHit = self.caster.world.getEntityFromLocation(self.target, False)
		self.projectile = Star(caster.position, location, self.__class__.color, self.fire)
		casterName = self.caster.getName()
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast resurrection on ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast resurrection on nothing!')
	 
	def update(self):
		self.projectile.update()

		if not self.projectile.done:
			return False

		if not self.entityHit is None:
			self.entityHit.revive(self.caster)

		self.done = True
		return True
		
	def draw(self, surface, position, visible):
		self.projectile.draw(surface, position, visible)
	
	@classmethod
	def validTarget(cls, actor, target):

		if not target in actor.getFriends():
			return False

		if target.isAlive():
			return False

		if not actor.partyCanSee(target.position):
			return False

		return True
		
	def fire(self):
		self.caster.world.sounds.get("resurrection.wav").play()
Exemple #4
0
	def __init__(self, caster, location, item):
		self.range = self.__class__.range
		self.caster = caster
		self.target = location
		self.done = False
		self.entityHit = self.caster.world.getEntityFromLocation(self.target, False)
		self.projectile = Star(caster.position, location, self.__class__.color, self.fire)
		casterName = self.caster.getName()
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast resurrection on ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast resurrection on nothing!')
Exemple #5
0
	def __init__(self, caster, location, item):
		self.item = item
		self.caster = caster
		self.target = location
		self.done = False
		self.color = THECOLORS['yellow']
		self.entityHit = self.caster.world.getEntityFromLocation(self.target)
		self.projectile = Star(caster.position, self.target, self.color, self.fire)
		casterName = self.caster.getName()
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast Heal at ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast Heal at nothing!')
Exemple #6
0
	def __init__(self, caster, location, item):
		self.item = item
		self.caster = caster
		self.target = location
		self.range = self.__class__.range
		self.damage = self.__class__.damage
		self.color = self.__class__.color
		casterName = self.caster.getName()
		self.entityHit = self.caster.world.getEntityFromLocation(self.target)
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at nothing!')
		
		self.projectile = Star(caster.position, location, self.color, self.fire, self.impact)
		self.done = False
Exemple #7
0
	def update(self):
	
		self.projectile.update()
		if self.projectile.done:
			if self.entityHit is not None:
				self.entityHit.inflict(self.caster, randint(self.damage[0], self.damage[1]))
			if self.bolts <= 0 or self.entityHit is None:
				self.done = True
				return True
			else:
				self.bolts -= 1
				nextTarget = self.getAllyInRange(self.entityHit, self.range)
				if nextTarget is None:
					self.done = True
					return True
				self.projectile = Star(self.entityHit.position, nextTarget.position, self.color, self.fire, self.impact)
				self.entityHit = nextTarget
		return False
Exemple #8
0
class Explosion(object):
	
	range = 6
	radius = 4
	damage = 2, 5
	heal = False
	name = "Explosion"
	icon = "firebolt"
	cooldown = 7
	
	def __init__(self, caster, location, item):
		self.item = item
		self.range = Explosion.range
		self.caster = caster
		self.target = location
		self.range = self.__class__.range
		self.damage = self.__class__.damage
		self.color = THECOLORS['orange']
		casterName = self.caster.getName()
		self.entityHit = self.caster.world.getEntityFromLocation(self.target)
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at nothing!')
		
		self.projectile = Star(caster.position, location, self.color, self.fire, self.impact)
		self.explosion = []
		self.done = False
	 
	def update(self):
	
		if not self.projectile.done:
			self.projectile.update()
			
			if self.projectile.done:
				#explosion start
				targets = Explosion.getNearbyTiles(self.target, Explosion.radius)
				if not targets:
					self.done = True
					return True
				for pos in targets:
					newStar = Star(self.target, pos, self.color, None, None)
					self.explosion.append(newStar)
			return False

		if not self.explosion:
			return True
		
		done = True
		for star in self.explosion:
			if star.done:
				continue
			star.update()
			if star.done:
				e = self.caster.world.getEntityFromLocation(star.end)
				if e is not None:
					e.inflict(self.caster, randint(self.damage[0], self.damage[1]))
			else:
				done = False
				
		if done:
			self.done = True
			
		return done
		
	def draw(self, surface, position, visible):
		if not self.done:
			if not self.projectile.done:
				self.projectile.draw(surface, position, visible)
			if self.explosion:
				for star in self.explosion:
					star.draw(surface, position, visible)
		
	@staticmethod
	def getNearbyTiles(pos, r):
		targets = []
		xP = pos[0] - (r - 1)
		yP = pos[1] - (r - 1)
		for x in xrange(r * 2 - 1):
			for y in xrange(r * 2 - 1):
				toHit = (xP + x, yP + y)
				if Explosion.canHit(pos, toHit, r):
					targets.append(toHit)
		return targets
	
	@staticmethod
	def canHit(origin, position, r):
		
		relx = abs(float(origin[0]) - float(position[0]))
		rely = abs(float(origin[1]) - float(position[1]))
		
		distance = sqrt(relx**2 + rely**2)
		
		if(distance <= r - 1):
			return True
			
		return False
		
	@classmethod
	def validTarget(cls, actor, target):

		if not target in actor.getEnemies():
			return False
	
		if not target.isAlive():
			return False
	
		if not actor.partyCanSee(target.position):
			return False
	
		nearbyTiles = cls.getNearbyTiles(target.position, Explosion.radius)
		for pos in nearbyTiles:
			e = actor.world.getEntityFromLocation(pos)
			if e is None:
				continue
			if not target.isAlive():
				continue
			if e is actor:
				return False
			if e in actor.getFriends():
				return False
	
		return True

	def fire(self):
		self.caster.world.sounds.get("fireball.wav").play()
	
	def impact(self):
		self.caster.world.sounds.get("explosion.wav").play()
		
	def getAllyInRange(self, entity, radius):
		
		for e in entity.getFriends():
			if e is entity:
				continue
			if not e.isAlive():
				continue
			if e.distance(entity.position) < radius:
				return e
Exemple #9
0
class ChainBolt(object):
	
	range = 5
	damage = 2, 5
	heal = False
	name = "Chain Bolt"
	icon = "magicbolt"
	cooldown = 4
	
	def __init__(self, caster, location, item):
		self.item = item
		self.caster = caster
		self.target = location
		self.range = self.__class__.range
		self.damage = self.__class__.damage
		casterName = self.caster.getName()
		self.color = THECOLORS['lightcyan']
		self.entityHit = self.caster.world.getEntityFromLocation(self.target)
		self.bolts = 3
		if not self.entityHit is None:
			targetName = self.entityHit.getName()
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at ' + targetName)
		else:
			self.caster.world.log.append(casterName + ' cast ' + self.__class__.__name__ + ' at nothing!')
		
		self.projectile = Star(caster.position, location, self.color, self.fire, self.impact)
		self.done = False
	 
	def update(self):
	
		self.projectile.update()
		if self.projectile.done:
			if self.entityHit is not None:
				self.entityHit.inflict(self.caster, randint(self.damage[0], self.damage[1]))
			if self.bolts <= 0 or self.entityHit is None:
				self.done = True
				return True
			else:
				self.bolts -= 1
				nextTarget = self.getAllyInRange(self.entityHit, self.range)
				if nextTarget is None:
					self.done = True
					return True
				self.projectile = Star(self.entityHit.position, nextTarget.position, self.color, self.fire, self.impact)
				self.entityHit = nextTarget
		return False
		
	def draw(self, surface, position, visible):
		if not self.done:
			self.projectile.draw(surface, position, visible)
	
	@classmethod
	def validTarget(cls, actor, target):

		if not target in actor.getEnemies():
			return False

		if not target.isAlive():
			return False

		if not actor.partyCanSee(target.position):
			return False

		return True

	def fire(self):
		self.caster.world.sounds.get("magic-missile.wav").play()
	
	def impact(self):
		self.caster.world.sounds.get("fireball-impact.wav").play()
		
	def getAllyInRange(self, entity, radius):
		
		for e in entity.getFriends():
			if e is entity:
				continue
			if not e.isAlive():
				continue
			if e.distance(entity.position) < radius:
				return e