コード例 #1
0
ファイル: commands.py プロジェクト: pom2ter/immortal
def bash():
	attempt = False
	for x in range(-1, 2):
		for y in range(-1, 2):
			if 'locked' in game.current_map.tile[game.char.x + x][game.char.y + y]:
				dice = util.roll_dice(1, 40)
				name = game.current_map.tile[game.char.x + x][game.char.y + y]['name']
				if game.player.strength >= dice:
					game.message.new('You bash open the ' + name + '.', game.turns)
					if name == 'locked door':
						game.current_map.set_tile_values('opened door', game.char.x + x, game.char.y + y)
					if name == 'locked chest':
						if 'trapped' in game.current_map.tile[game.char.x + x][game.char.y + y]:
							game.current_map.tile[game.char.x + x][game.char.y + y].update({game.chest_trap[libtcod.random_get_int(game.rnd, 0, len(game.chest_trap) - 1)]: True})
							game.current_map.tile[game.char.x + x][game.char.y + y].pop('trapped', None)
							util.trigger_trap(game.char.x + x, game.char.y + y, chest=True)
						game.current_map.set_tile_values('empty chest', game.char.x + x, game.char.y + y)
						nb_items = libtcod.random_get_int(game.rnd, 2, 4)
						for i in range(nb_items):
							game.current_map.objects.append(game.baseitems.loot_generation(game.char.x + x, game.char.y + y, game.current_map.threat_level))
				else:
					game.message.new('You failed to bash open the ' + name + '.', game.turns)
				game.player.take_damage(1, 'bashing a ' + name)
				game.player.lose_stamina(1)
				game.player_move = True
				attempt = True
	if not attempt:
		game.message.new('You bash air. You find it strangely exhilarating.', game.turns)
コード例 #2
0
ファイル: players.py プロジェクト: pom2ter/immortal
	def drop_item(self, item, qty=1):
		for i in range(qty):
			for j in xrange(len(self.inventory)):
				if self.inventory[j] == item:
					pos = j
					break
			obj = mapgen.Object(game.char.x, game.char.y, self.inventory[pos].icon, self.inventory[pos].name, self.inventory[pos].color, True, item=self.inventory[pos])
			obj.first_appearance = self.inventory[pos].turn_created
			game.current_map.objects.append(obj)
			obj.send_to_back()
			self.inventory.pop(pos)

		if qty == 1:
			game.message.new('You drop ' + obj.item.get_name(True) + '.', game.turns, libtcod.red)
		else:
			game.message.new('You drop ' + str(qty) + ' ' + obj.item.get_plural_name() + '.', game.turns, libtcod.red)
		if game.current_map.tile[game.char.x][game.char.y]['type'] == 'trap':
			if self.is_above_ground():
				util.trigger_trap(game.char.x, game.char.y, obj.item.article.capitalize() + obj.item.get_name())
			else:
				util.trigger_trap(game.char.x, game.char.y)
		game.player_move = True
コード例 #3
0
ファイル: commands.py プロジェクト: pom2ter/immortal
def use_skill():
	skills = []
	for x in game.player.skills:
		if x.can_use:
			skills.append(x)
	output = [x.name for x in skills]
	choice = game.messages.box('Use a skill', 'Up/down to select, ENTER to use, ESC to exit', 'center_mapx', 'center_mapy', 65, max(19, len(output) + 4), output, step=2, mouse_exit=True)
	if choice != -1:
		if output[choice] == 'Detect Traps':
			skills[choice].active()

		if output[choice] == 'Artifacts':
			output2 = game.player.inventory + game.player.equipment
			choice2 = game.messages.box('Use skill on which item', 'Up/down to select, ENTER to use, ESC to exit', 'center_mapx', 'center_mapy', 65, max(19, len(output) + 4), output2, inv=True, step=2, mouse_exit=True)
			if choice2 != -1:
				if output2[choice2].is_identified():
					game.message.new('That item is already identified.', game.turns)
				elif output2[choice2].assay == game.player.level:
					game.message.new('You already tried to identify that item. You can do it once per item per level.', game.turns)
				else:
					if output2[choice2].level * 5 > skills[choice].level:
						game.message.new('Your skill is not high enough to identity that item.', game.turns)
						output2[choice2].assay = game.player.level
						skills[choice].gain_xp(1)
					else:
						game.message.new('You identify the item!', game.turns)
						output2[choice2].flags.append('identified')
						skills[choice].gain_xp(5)
					game.player_move = True

		if output[choice] == 'Disarm Traps':
			attempt = False
			for x in range(-1, 2):
				for y in range(-1, 2):
					if 'trapped' in game.current_map.tile[game.char.x + x][game.char.y + y]:
						dice = libtcod.random_get_int(game.rnd, 0, 150)
						if skills[choice].level >= dice:
							if game.current_map.tile[game.char.x + x][game.char.y + y]['type'] == 'trap':
								game.current_map.set_tile_values('floor', game.char.x + x, game.char.y + y)
								game.message.new('You disarm the trap.', game.turns)
							else:
								game.message.new('You disarm the trap chest.', game.turns)
								game.current_map.tile[game.char.x + x][game.char.y + y].pop('trapped', None)
							skills[choice].gain_xp(5)
						else:
							game.message.new('You failed to disarm the trap.', game.turns)
							dice = util.roll_dice(1, 50)
							if dice > game.player.karma:
								if game.current_map.tile[game.char.x + x][game.char.y + y]['type'] == 'trap':
									util.trigger_trap(game.char.x + x, game.char.y + y)
								else:
									game.current_map.tile[game.char.x + x][game.char.y + y].update({game.chest_trap[libtcod.random_get_int(game.rnd, 0, len(game.chest_trap) - 1)]: True})
									game.current_map.tile[game.char.x + x][game.char.y + y].pop('trapped', None)
									util.trigger_trap(game.char.x + x, game.char.y + y, chest=True)
							skills[choice].gain_xp(1)
						game.player_move = True
						attempt = True
			if not attempt:
				game.message.new('There are no traps in your surroundings.', game.turns)

		if output[choice] == 'Lockpicking':
			attempt = False
			for x in range(-1, 2):
				for y in range(-1, 2):
					if 'locked' in game.current_map.tile[game.char.x + x][game.char.y + y]:
						dice = libtcod.random_get_int(game.rnd, 0, 150)
						name = game.current_map.tile[game.char.x + x][game.char.y + y]['name']
						if skills[choice].level >= dice:
							game.message.new('You unlock the ' + name + '.', game.turns)
							if name == 'locked door':
								game.current_map.set_tile_values('opened door', game.char.x + x, game.char.y + y)
							if name == 'locked chest':
								game.current_map.set_tile_values('empty chest', game.char.x + x, game.char.y + y)
								nb_items = util.roll_dice(2, 4)
								for i in range(nb_items):
									game.current_map.objects.append(game.baseitems.loot_generation(game.char.x + x, game.char.y + y, game.current_map.threat_level))
							skills[choice].gain_xp(5)
						else:
							game.message.new('You failed to unlock the ' + name + '.', game.turns)
							if 'trapped' in game.current_map.tile[game.char.x + x][game.char.y + y]:
								dice = util.roll_dice(1, 30)
								if game.player.karma < dice:
									game.current_map.tile[game.char.x + x][game.char.y + y].update({game.chest_trap[libtcod.random_get_int(game.rnd, 0, len(game.chest_trap) - 1)]: True})
									game.current_map.tile[game.char.x + x][game.char.y + y].pop('trapped', None)
									util.trigger_trap(game.char.x + x, game.char.y + y, chest=True)
							skills[choice].gain_xp(1)
						game.player_move = True
						attempt = True
			if not attempt:
				game.message.new('There is nothing to unlock in your surroundings.', game.turns)
	game.draw_gui = True
コード例 #4
0
ファイル: commands.py プロジェクト: pom2ter/immortal
def player_move(dx, dy):
	#the coordinates the player is moving to/attacking
	x = game.char.x + dx
	y = game.char.y + dy

	#try to find an attackable object there
	target = None
	for object in game.current_map.objects:
		if object.y == y and object.x == x and object.entity:
			target = object
			break

	#attack if target found, move otherwise
	if target is not None:
		game.player.attack(target)
	elif not game.player.can_move():
		game.message.new("You can't move!", game.turns)
		game.player_move = True
	else:
		if game.current_map.tile[game.char.x + dx][game.char.y + dy]['name'] == 'door':
			open_door(dx, dy)
		elif game.current_map.tile[game.char.x + dx][game.char.y + dy]['name'] == 'locked door':
			game.message.new('The door is locked!', game.turns)
		else:
			game.char.move(dx, dy, game.current_map)
			if game.current_map.tile[game.char.x][game.char.y]['type'] == 'trap' and not game.player.is_above_ground():
				if game.current_map.tile_is_invisible(game.char.x, game.char.y):
					util.trigger_trap(game.char.x, game.char.y)
				else:
					game.message.new('You sidestep the ' + game.current_map.tile[game.char.x][game.char.y]['name'] + '.', game.turns)
			if game.current_map.tile[game.char.x][game.char.y]['name'] in ['deep water', 'very deep water']:
				if 'swimming' not in game.player.flags:
					game.player.flags.append('swimming')
				stamina_loss = (100 - game.player.skills[game.player.find_skill('Swimming')].level) / 2
				if stamina_loss == 0:
					stamina_loss = 1
				game.player.lose_stamina(stamina_loss)
				if game.player.no_stamina():
					game.message.new('You drown!', game.turns, libtcod.light_orange)
					game.message.new('*** Press space ***', game.turns)
					game.killer = 'drowning'
					game.game_state = 'death'
				else:
					game.player.skills[game.player.find_skill('Swimming')].gain_xp(2)
			elif 'swimming' in game.player.flags:
				game.player.flags.remove('swimming')

			if game.current_map.location_id == 0:
				px = game.current_map.map_width / 3
				py = game.current_map.map_height / 3
				if (game.char.y / py) == 0 or (game.char.x / px) == 0 or (game.char.y / py) == 2 or (game.char.x / px) == 2:
					game.worldmap.player_positionx += dx
					game.worldmap.player_positiony += dy
					if game.worldmap.player_positionx not in range(game.WORLDMAP_WIDTH):
						game.worldmap.player_positionx = game.WORLDMAP_WIDTH - abs(game.worldmap.player_positionx)
					if game.worldmap.player_positiony not in range(game.WORLDMAP_HEIGHT):
						game.worldmap.player_positiony = game.WORLDMAP_HEIGHT - abs(game.worldmap.player_positiony)
					level = (game.worldmap.player_positiony * game.WORLDMAP_WIDTH) + game.worldmap.player_positionx
					util.change_maps(level)
			util.items_at_feet()
		game.fov_recompute = True
コード例 #5
0
ファイル: game.py プロジェクト: pom2ter/immortal
	def play_game(self):
		global wm, player_action, draw_gui, player_move
		wm = libtcod.console_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT)
		game.worldmap.create_map_legend(wm, 3)
		libtcod.console_clear(0)
		util.initialize_fov()
		player_action = ''
		while not libtcod.console_is_window_closed():
			if draw_gui:
				util.render_gui(libtcod.Color(70, 80, 90))
				util.render_message_panel()
				util.render_player_stats_panel()
				draw_gui = False
			util.render_map()
			libtcod.console_flush()

			# player movement
			if not player.is_disabled() and not ('overburdened' in player.flags and turns % 3 == 0):
				player_action = commands.keyboard_commands()
			else:
				player_move = True
			if player_action == 'save':
				IO.save_game()
				break
			if player_action == 'quit':
				death.death_screen(True)
				break
			if player_action == 'exit':
				break

			# let monsters take their turn
			if player_move:
				for obj in reversed(current_map.objects):
					if game_state != 'death':
						if obj.item:
							if obj.item.is_active():
								obj.delete()
							if obj.item.is_expired() or ((turns >= (obj.first_appearance + obj.item.expiration)) and obj.item.expiration > 0):
								obj.delete()
						if obj.entity:
							if not obj.entity.is_disabled():
								obj.x, obj.y = obj.entity.take_turn(obj.x, obj.y)
								if current_map.tile[obj.x][obj.y]['type'] == 'trap' and not obj.entity.is_above_ground() and obj.entity.can_move(obj.x, obj.y):
									if current_map.tile_is_invisible(obj.x, obj.y):
										util.trigger_trap(obj.x, obj.y, obj.entity.article.capitalize() + obj.entity.get_name())
									elif libtcod.map_is_in_fov(fov_map, obj.x, obj.y):
										message.new('The ' + obj.entity.get_name() + ' sidestep the ' + current_map.tile[obj.x][obj.y]['name'] + '.', turns)
							obj.entity.check_condition(obj.x, obj.y)
							if obj.entity.is_dead():
								if libtcod.map_is_in_fov(fov_map, obj.x, obj.y):
									message.new('The ' + obj.entity.get_name() + ' dies!', turns, libtcod.light_orange)
								else:
									message.new('You hear a dying scream.', turns)
								obj.entity.loot(obj.x, obj.y)
								obj.delete()
				if game_state != 'death':
					monsters.spawn()
					effects.check_active_effects()
					util.add_turn()
				player_move = False

			# death screen summary
			if game_state == 'death':
				key = libtcod.Key()
				util.render_map()
				libtcod.console_flush()
				while not key.vk == libtcod.KEY_SPACE:
					libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True)
				death.death_screen()
				player_action = 'exit'
				break