Beispiel #1
0
    def spawn(self, monster_name, loc, ally=False, mount_unit=None):
        data = Monsters.array[monster_name]
        try:
            other_items = data[16]
        except IndexError:
            other_items = None

        pot_weapons = data[14]
        pot_armor = data[15]

        # Spawn Unit
        unit = Monster(self.game, monster_name, data[0], data[1], data[2],
                       data[3], data[4], data[5], data[6], data[7], data[8],
                       data[9], data[10], data[11], data[12], data[13], loc,
                       other_items)

        # Give innate weapons / shields
        if other_items is not None:
            for item in other_items:
                if item in Ammos.array:
                    given_brand = Brands.ammo_brands[d(
                        len(Brands.ammo_brands)
                    ) - 1] if d(
                        100
                    ) > 99 - self.tier and item not in Weapons.legendaries else None
                    unit.quivered = Ammo.give_ammo(unit,
                                                   item,
                                                   number=(10 + 5 * self.tier,
                                                           4 + 2 * self.tier),
                                                   brand=given_brand)
                elif item in Weapons.array:
                    given_brand = Brands.weapon_brands[d(
                        len(Brands.weapon_brands)
                    ) - 1] if d(
                        100
                    ) > 99 - self.tier and item not in Weapons.legendaries else None
                    given_enchantment = d(int(
                        max(1, self.tier /
                            2))) - 1 if d(10) + (1.5 * self.tier) > 13 else 0
                    Weapon.give_weapon(unit,
                                       item,
                                       hands=False,
                                       brand=given_brand,
                                       enchantment=given_enchantment)
                elif item in Shields.array:
                    unit.give_shield(item)
                elif item in Spells.spells:
                    unit.spells.append(item)
                elif item in Tomes.array:
                    unit.give_tome(item)
                elif item in Potions.array:
                    unit.give_potion(item)
                elif item in Monsters.array:
                    ally = True if unit in self.game.allies else False
                    unit.mount = Mount(self.game.map.room_filler, unit, item,
                                       ally)
                    unit.mount.unit = self.game.units[-1]
                    unit.mount.unit.rider = unit
                else:
                    unit.traits.append(item)

        # Give Weapon and Armor
        items = pot_weapons[d(len(pot_weapons)) - 1]
        if type(items) != list: items = [items]
        for item in items:
            if item in Weapons.array:
                given_brand = Brands.weapon_brands[d(
                    len(Brands.weapon_brands)
                ) - 1] if d(
                    100
                ) > 99 - self.tier and item not in Weapons.legendaries else None
                given_enchantment = d(int(
                    max(1, self.tier /
                        2))) - 1 if d(10) + (1.5 * self.tier) > 13 else 0
                Weapon.give_weapon(unit,
                                   item,
                                   hands=False,
                                   brand=given_brand,
                                   enchantment=given_enchantment)
            elif item in Shields.array:
                unit.give_shield(item)
            elif item in Tomes.array:
                unit.give_tome(item)
        unit.give_armor(pot_armor[d(len(pot_armor)) - 1])

        self.game.units.append(unit)
        if ally: self.game.allies.append(unit)
Beispiel #2
0
	def turn(self, game):

		# Manage Terrified
		for passive in self.passives:
			if passive[0] == "terrified":

				# Fear Radius
				spaces = []
				for x in range(-1,2):
					for y in range(-1,2):
						if self.loc[0] + x >= 0 and self.loc[1] + y >= 0: spaces.append((self.loc[0] + x, self.loc[1] + y))
				shuffle(spaces)

				# Move to random square
				for space in spaces:
					if game.map.can_move(space):
						self.loc = space
						break

				# Check for Traps
				for item in game.items:
					if type(item) == Trap and item.loc == self.loc:
						item.trip(game)

				self.time += self.mspeed
				return


		# Ally Unit
		if self in game.allies:
			enemy, mini = None, 100
			for unit in game.units:
				if unit in game.allies: continue
				los = ai.los(self.loc, unit.loc, Maps.rooms[game.map.map][0], game )
				if los is not None:
					if unit.name == "you": self.range_from_player = len(los)
					elif len(los) < mini: enemy, mini, minlos = unit, len(los), los

			# No enemies in room
			if enemy is None:
				move_towards(self, game.player, game.map)
				self.time += self.mspeed
				return

		# Enemy Unit
		else:
			minlos = ai.los(self.loc, game.player.loc, Maps.rooms[game.map.map][0], game )
			try: mini, enemy = len(minlos), game.player
			except: mini, enemy = 100, game.player
			for unit in game.allies:
				los = ai.los(self.loc, unit.loc, Maps.rooms[game.map.map][0], game )
				if los is not None:
					if unit.name == "you": self.range_from_player = len(los)
					if len(los) <= mini: enemy, mini, minlos = unit, len(los), los


		melee_attacked = False

		# MAGIC!!
		if len(self.spells) > 0:

			# Chance to use spells
			if d(10) + min(self.int, 7) >= 12:

				if minlos is not None:

					# Zap with spells
					for spell in self.spells:

						# Check for mana
						if self.mana >= Spells.spells[spell][1]:
							spell_fun = Spells.spells[spell][0]

							# If target
							if Spells.spells[spell][4]:

								# If in spell range
								if len(minlos) - 1 <= Spells.spells[spell][5]:

									# Player Resist spell
									if d(100) / 100 <= max(0.05, min(0.9, (enemy.cha / 2) / self.int)):
										self.time += Spells.spells[spell][2]
										self.mana -= Spells.spells[spell][1]
										if enemy.name == 'you': game.game_log.append("You resist the " + spell + " from " + self.info[0] + "!")
										else: game.game_log.append(enemy.info[3] + " resists the " + spell + " from " + self.info[0] + "!")

									elif spell_fun(spell, self, enemy, game, Maps.rooms[game.map.map][0], game.map.room_filler):
										self.time += Spells.spells[spell][2]
										self.mana -= Spells.spells[spell][1]

										if self.mount is not None: self.mount.unit.loc = self.loc
										if self.rider is not None: self.rider.loc = self.loc
							# No target
							else:
								if spell_fun(spell, self, enemy, game, Maps.rooms[game.map.map][0], game.map.room_filler):
									self.time += Spells.spells[spell][2]
									self.mana -= Spells.spells[spell][1]

									if self.mount is not None: self.mount.unit.loc = self.loc
									if self.rider is not None: self.rider.loc = self.loc

							# Manage the Black Cross 2
							for unit in self.game.units:
								for item in unit.wielding:
									if item.base_string == "the Black Cross":
										for school, spells in Spells.spell_schools.items():
											if spell in spells:
												if school in Spells.school_info:
													if Spells.school_info[school][1] is not None:
														self.game.game_log.append("Yet " + item.name + " condemns " + self.info[1] + " use of magic, it " + Colors.color("ignites", "fire") + " " + self.info[2] + " flesh!")
														apply(self, "aflame", 3)

							# Manage Longfang 2
							for weapon in self.wielding:
								if weapon.base_string == "Longfang":
									for school, spells in Spells.spell_schools.items():
										if spell in spells:
											if school in Spells.school_info:
												if Spells.school_info[school][1] is not None:
													weapon.passives = [[Spells.school_info[school][1] , 1]]
													weapon.brand = Spells.school_info[school][1]
													game.game_log.append(weapon.name + " absorbs the power of " + self.info[1] + " spell and becomes " + Colors.color(weapon.brand, Brands.colors[weapon.brand]) + "!")
													break

							# One spell per turn
							return



		# Melee Attack
		if adjacent_to(self, enemy):

			# Find weapons
			weaps = [item for item in self.wielding[::-1] if type(item) == Weapon and item.wclass not in Weapons.ranged_wclasses]


			maxas = 0
			for weapon in weaps:
				 if weapon.speed > maxas and weapon.wclass not in Weapons.ranged_wclasses: maxas = weapon.speed

			# Hit with melee
			for item in weaps:
				item.strike(self, enemy, game)
				if self in game.allies:
					# Enemy Well-being Statement
					try: game.player.well_being_statement(enemy, self, item)
					except: pass

			self.time += maxas
			melee_attacked = True

		# Add thrown weapon platform
		thrown = False
		if self.quivered is not None:
			if self.quivered.wclass in Ammos.thrown_amclasses:
				thrown = True
				Weapon.give_weapon(self, self.quivered.base_string)

		# Make Ranged attacks
		for item in self.wielding:
			if item.wclass in Weapons.ranged_wclasses or item.wclass in Ammos.thrown_amclasses:

				if self.quivered is not None or item.hands == 0:

					if item.hands > 0 and melee_attacked:
						if thrown: self.wielding.pop()
						return

					# los = los(self.loc, enemy.loc, Maps.rooms[game.map.map][0], game )
					if minlos is not None:

						# Ranged range
						if mini <= (2 * item.damage + item.to_hit):
							item.strike(self, enemy, game)
							if self in game.allies:
								# Enemy Well-being Statement
								try: game.player.well_being_statement(enemy, self, item)
								except: pass


							# Remove Ammo
							if thrown: self.wielding.pop()
							if item.hands > 0:
								self.quivered.number -= 1
								if self.quivered.number == 0: self.quivered = None
								self.time += item.speed
								return
						else:
							if thrown: self.wielding.pop()
					else:
						if thrown: self.wielding.pop()

		# If can't, move
		immobile = False
		for name, count in self.passives:
			if name == 'immobile': immobile = True

		if not melee_attacked and self.behavior_type != 'as':

			if not immobile:
				coordinates = self.loc
				if self.mount is None: smart_move_towards(self, enemy, game)

				# Check for Traps
				for item in game.items:
					if type(item) == Trap and item.loc == self.loc:
						item.trip()

				# Manage Furious Charge (enemies)
				if "furious charge" in self.traits:
					if self in game.allies:
						for unit in game.units:
							if unit in game.allies: continue
							if unit.loc == (coordinates[0] - 2 * (self.loc[0] - unit.loc[0]), self.loc[1] - 2 * (self.loc[1] - unit.loc[1])):
								for weapon in self.wielding: weapon.strike(self, unit, game, False)
								break
					else:
						for unit in game.allies:
							if unit.loc == (coordinates[0] - 2 * (self.loc[0] - unit.loc[0]), coordinates[1] - 2 * (self.loc[1] - unit.loc[1])):
								for weapon in self.wielding: weapon.strike(self, unit, game,  False)
								break

				# Manage Lance (enemies)
				if self.rider is not None:
					for weapon in self.rider.wielding:
						if weapon.wclass == 'lance':
							for unit in game.units:
								if unit.loc == (coordinates[0] - 2 * (self.loc[0] - unit.loc[0]), coordinates[1] - 2 * (self.loc[1] - unit.loc[1])):
									weapon.strike(self.rider, unit, game, False)
									break

			self.time += self.mspeed

			if self.rider is not None:
				self.rider.prev_loc = self.rider.loc
				self.rider.loc = self.loc