def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, "Player", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def generate_character(x, y, race, with_AI): """Generates a random character of the chosen race""" race_template = race_templates[race] attribute_values = generate_attribute_values(race_template) character_component = Character(attribute_values["age"], race_template) attacks = generate_attack_set(unarmed_attack_definitions) fighter_component = Fighter(hp=attribute_values["hp"], endurance=attribute_values["endurance"], strength=attribute_values["strength"], intelligence=1, willpower=1, known_attacks=attacks) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() ai_component = None if with_AI: ai_component = NeutralAI() character_name = race_template["race_name"] color = libtcod.gray else: character_name = "Player" color = libtcod.orange character = Entity(x, y, '@', color, character_name, blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, character=character_component, ai=ai_component) return character
def __init__(self): super().__init__( name="player", player=True, # Let's us work with the player component around the game. char="@", color=(255, 255, 255), ai=None, equipment=Equipment(), fighter=Fighter(max_hp=30, base_ac=10), offense=OffenseComponent(Attack('punch', [2])), attributes=Attributes(base_strength=5), # Original inventory capacity is 267 because we have 26 lowercase letters plus $ inventory=PlayerInventory(capacity=27), level=Level(level_up_base=20, difficulty=0), energy=EnergyComponent(refill=12), regeneration=Regeneration(), light=LightComponent(radius=1), )
def get_game_variables(constants): """ Crée une nouvelle partie Parametres: ---------- constants : dict Renvoi: ------- player : Entity entities : list game_map : GameMap message_log : MessageLog game_state : int """ fighter_component = Fighter(hp=100, defense=1, power=3) inventory_component = Inventory() level_component = Level() equipment_component = Equipment() player = Entity(0, 0, constants.get('graphics').get('player'), libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, constants.get('graphics').get('dagger'), libtcod.sky, 'Dague', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities, constants.get('graphics')) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def create_player(game_map): """Create the player entity and place on the game map.""" from game_objects.items import (HealthPotion, MagicMissileScroll, FireblastScroll, SpeedPotion, TeleportationPotion, ThrowingKnife, Torch, FireStaff, IceStaff, ConfusionPotion) from game_objects.weapons import Raipier # This is you. Kill some Orcs. player = Entity(0, 0, PLAYER_CONFIG["char"], COLORS[PLAYER_CONFIG["color"]], PLAYER_CONFIG["name"], blocks=True, render_order=RenderOrder.ACTOR, attacker=Attacker(power=PLAYER_CONFIG["power"]), burnable=AliveBurnable(), defender=Defender(), equipment=Equipment(), harmable=Harmable(hp=PLAYER_CONFIG["hp"], defense=PLAYER_CONFIG["defense"]), input_handler=PlayerInputHandler(), inventory=Inventory(PLAYER_CONFIG["inventory_size"]), movable=Movable(), scaldable=AliveScaldable(), swimmable=PlayerSwimmable(PLAYER_CONFIG["swim_stamina"])) # Setup Initial Inventory, for testing. player.inventory.extend([HealthPotion.make(0, 0) for _ in range(3)]) player.inventory.extend([ConfusionPotion.make(0, 0)]) player.inventory.extend([SpeedPotion.make(0, 0)]) player.inventory.extend([TeleportationPotion.make(0, 0)]) player.inventory.extend([ThrowingKnife.make(0, 0)]) player.inventory.extend([MagicMissileScroll.make(0, 0)]) player.inventory.extend([FireblastScroll.make(0, 0)]) player.inventory.extend([Torch.make(0, 0)]) player.inventory.extend([Raipier.make(0, 0)]) player.inventory.extend([FireStaff.make(0, 0)]) player.inventory.extend([IceStaff.make(0, 0)]) return player
def get_game_variables(constants): fighter_component = Fighter(hp=80, defense=2, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, "@", (255, 255, 255), "Shark", blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, "-", constants["colors"].get("sky"), "holdout blade", equippable=equippable_component) player.inventory.add_item(dagger, constants["colors"]) player.equipment.toggle_equip(dagger) game_map = GameMap(constants["map_width"], constants["map_height"]) make_map(game_map, constants["max_rooms"], constants["room_min_size"], constants["room_max_size"], constants["map_width"], constants["map_height"], player, entities, constants["colors"]) message_log = MessageLog(constants["message_x"], constants["message_width"], constants["message_height"]) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_players(constants, entities): players = [] for i in range(constants['player_count']): # Building the players fighter_component = Fighter(hp=30, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() vision_component = Vision(None, constants['fov_radius']) players.append( Entity(0, 0, '@', libtcod.blue, 'Player{0}'.format(i + 1), blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, vision=vision_component)) # Give the player a dagger to start with equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) players[-1].inventory.add_item(dagger) players[-1].equipment.toggle_equip(dagger) entities.append(players[-1]) return players
def get_game_variables(constants): fighter_component = Fighter(hp=3000, defense=2, power=5) inventory_component = Inventory(26) game_map = GameMap(constants['map_width'], constants['map_height']) fov_component = Fov(game_map) equipment_component = Equipment() player = Entity(0, 0, '@', 'You', 'white', game_map.entities, fighter=fighter_component, fov=fov_component, inventory=inventory_component, equipment=equipment_component) equippable_component = Equippable(EquipmentSlots.RIGHT_HAND, power_bonus=2) dagger = Entity(0, 0, '-', 'Dagger', 'blue', game_map.items, equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) # game_map.get_player(player) map_type = 'chunks' generate_map(game_map, player, map_type) # player.fov.calc_fov(game_map) game_map.get_player(player) game_state = GameStates.PLAYERS_TURN camera = Camera(constants['camera_width'], constants['camera_height']) camera.move_camera(player.x, player.y, game_map) message_log = MessageLog() return game_map, player, game_state, camera, message_log, map_type
def get_game_variables(constants): player = Entity(0, 0, blocks_movement=True, render_order=RenderOrder.ACTOR, components={ 'fighter': Fighter(hp=100, defense=1, power=2), 'inventory': Inventory(26), 'level': Level(), 'equipment': Equipment(), }) player.set_appearance('@', tcod.white, 'Player') entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, components={ 'equippable': equippable_component, }) dagger.set_appearance( '-', tcod.sky, 'Dagger', ) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height'], constants['room_min_size'], constants['room_max_size']) entities.extend(game_map.make_map(constants['max_rooms'], player)) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_vars(constants): player = Entity(0, 0, '@', tcod.yellow, 'Ratiel Snailface the Snek Oil Snekman (Player Character)', block_movement=True, render_order=RenderOrder.ACTOR, combatant=Combatant(health=24, stamina=60, attack=3, ac=3), item=None, inventory=Inventory(26), level=Level(), equipment=Equipment()) entities = [player] dagger = Entity(0, 0, '!', tcod.sky, 'Ceremonial Dagger', render_order=RenderOrder.ITEM, equippable=Equippable(EquipmentSlots.MAIN_HAND, bonus_attack=2)) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYER_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(): fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() position_component = Position(0, 0) player = Entity('@', tcod.white, 'Player', blocks=True, position=position_component, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity('-', tcod.sky, 'Dagger', equippable=equippable_component, position=position_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap(c.MAP_WIDTH, c.MAP_HEIGHT) game_map.make_map(c.MAX_ROOMS, c.ROOM_MIN_SIZE, c.ROOM_MAX_SIZE, c.MAP_WIDTH, c.MAP_HEIGHT, player, entities) message_log = MessageLog(c.MESSAGE_X, c.MESSAGE_WIDTH, c.MESSAGE_HEIGHT) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(): fighter_component = Fighter(hp=100, defense=1, power=2) inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', colors.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=2) dagger = Entity(0, 0, '-', colors.sky, 'Dagger', equippable=equippable_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) game_map = GameMap() make_map(game_map, player, entities) message_log = MessageLog() game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0, status=None, mana=100) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, constants['player_overworld_tile'], libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, equipment_inventory=equipment_inventory_component) entities = [player] equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1, gold=1) dagger = Entity(0, 0, constants['dagger_tile'], libtcod.white, "Terrium Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) item_component = Item(use_function=cast_magic, damage=2, maximum_range=3, gold=2) magic_wand = Entity(0, 0, constants['magic_wand_tile'], libtcod.white, "Magic Wand", item=item_component) player.inventory.add_item(magic_wand) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map( constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities, constants['orc_tile'], constants['healing_potion_tile'], constants['scroll_tile'], constants['troll_tile'], constants['stairs_tile'], constants['sword_tile'], constants['shield_tile'], constants['dagger_tile'], constants['magic_wand_tile'], constants['greater_healing_potion_tile'], constants['ghost_tile'], constants['slime_tile'], constants['corpse_tile'], constants['goblin_tile'], constants['baby_slime_tile'], constants['skeleton_tile'], constants['slime_corpse_tile'], constants['baby_slime_corpse_tile'], constants['skeleton_corpse_tile'], constants['mana_potion_tile'], constants['wizard_staff_tile'], constants['health_talisman_tile'], constants['basilisk_tile'], constants['treasure_tile'], constants['chestplate_tile'], constants['leg_armor_tile'], constants['helmet_tile'], constants['amulet_tile'], constants['floor_tile'], constants['long_bow_tile'], constants['arrow_tile'], constants['wall_tile'], constants['grass_tile'], constants['path_tile'], constants['roof_tile'], constants['brick_tile'], constants['player_overworld_tile'], constants['player_tile'], constants['forest_tile'], constants['door_tile'], constants['sign_tile']) item_descriptors = [ 'Valor', 'Power', 'Ingenuity', 'Glory', 'Strength', 'Speed', 'Wealth', 'Divinity', 'Energy', 'Honor', 'Resistance', 'Greatness', 'Courage', 'Intelligence' ] all_shop_items = [] item_component = Item(use_function=heal, amount=20, gold=20) item = Entity(0, 0, constants['healing_potion_tile'], libtcod.white, "Health Potion (+20 HP)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) item_component = Item(use_function=recover_mana, amount=20, gold=10) item = Entity(0, 0, constants['mana_potion_tile'], libtcod.white, "Mana Potion (+20 MANA)", render_order=RenderOrder.ITEM, item=item_component) all_shop_items.append(item) all_shop_equipment = [] sword_amount = randint(2, 4) equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=sword_amount, gold=10) item = Entity(0, 0, constants['sword_tile'], libtcod.white, "Terrium Sword of " + random.choice(item_descriptors) + " (+" + str(sword_amount) + " atk)", equippable=equippable_component) all_shop_equipment.append(item) shield_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=shield_amount, gold=7) item = Entity(0, 0, constants['shield_tile'], libtcod.white, "Terrium Shield of " + random.choice(item_descriptors) + " (+" + str(shield_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) chestplate_amount = randint(2, 3) equippable_component = Equippable(EquipmentSlots.CHEST, defense_bonus=chestplate_amount, gold=20) item = Entity(0, 0, constants['chestplate_tile'], libtcod.darker_grey, "Terrium Chestplate of " + random.choice(item_descriptors) + " (+" + str(chestplate_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) leg_amount = randint(1, 3) equippable_component = Equippable(EquipmentSlots.LEGS, defense_bonus=leg_amount, gold=15) item = Entity(0, 0, constants['leg_armor_tile'], libtcod.darker_grey, "Terrium Leg Armor of " + random.choice(item_descriptors) + " (+" + str(leg_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) helmet_amount = randint(1, 2) equippable_component = Equippable(EquipmentSlots.HEAD, defense_bonus=helmet_amount, gold=5) item = Entity(0, 0, constants['helmet_tile'], libtcod.darker_grey, "Terrium Helmet of " + random.choice(item_descriptors) + " (+" + str(helmet_amount) + " def)", equippable=equippable_component) all_shop_equipment.append(item) amulet_amount = randint(1, 4) equippable_component = Equippable(EquipmentSlots.AMULET, magic_bonus=amulet_amount, gold=6) item = Entity(0, 0, constants['amulet_tile'], libtcod.darker_grey, "Terrium Amulet of " + random.choice(item_descriptors) + " (+" + str(amulet_amount) + " mgk)", equippable=equippable_component) all_shop_equipment.append(item) number_of_shop_items = randint(1, 3) for i in range(number_of_shop_items): random_item = randint(0, len(all_shop_items) - 1) game_map.shop_items.append(all_shop_items[random_item]) number_of_shop_equipment = randint(1, 2) for i in range(number_of_shop_equipment): random_equipment = randint(0, len(all_shop_equipment) - 1) game_map.shop_equipment_items.append( all_shop_equipment[random_equipment]) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=2, magic=0, magic_defense=1, talismanhp=0, gold=0) inventory_component = Inventory(26) equipment_inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, equipment_inventory=equipment_inventory_component) entities = [player] gold_value = 1 equipment_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1, gold=gold_value) dagger = Entity(0, 0, '-', libtcod.darker_orange, "Terrium Dagger (+1 atk)", equippable=equipment_component) player.equipment_inventory.add_item(dagger) player.equipment.toggle_equip(dagger) gold_value = 2 item_component = Item(use_function=cast_magic, damage=2, maximum_range=3, gold=gold_value) magic_wand = Entity(0, 0, '|', libtcod.darker_sepia, "Magic Wand", item=item_component) player.inventory.add_item(magic_wand) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def play_game(player, entities, game_map, message_log, game_state, con, panel, constants): fov_recompute = True fov_map = initialize_fov(game_map) previous_game_state = game_state targeting_item = None message_log.add_message( Message(f'You are a ghost. You have nothing.', libtcod.white)) message_log.add_message( Message(f'Use the arrow keys to move', libtcod.white)) message_log.add_message( Message(f'Press \'p\' to possess a creature and gain its abilities...', libtcod.white)) message_log.add_message( Message(f'(Mouse over symbols for more information)', libtcod.white)) first_body = True first_inventory = True mouse_event = None while True: key_event = None left_click = None right_click = None exit_game = False for event in libtcod.event.get(): #print(f"Got Event: {event.type}") if event.type in ("QUIT"): print("QUIT event: Exiting") raise SystemExit() if event.type == "KEYDOWN": if event.sym == libtcod.event.K_ESCAPE: print(f"{event.type} K_ESCAPE: Exiting") exit_game = True else: key_event = event #print(f"Got Event: {event.type}: {key}") if event.type == "MOUSEMOTION": mouse_event = event if event.state & libtcod.event.BUTTON_LMASK: left_click = mouse_event if event.state & libtcod.event.BUTTON_RMASK: right_click = mouse_event if exit_game: break fov_radius = player.fighter.fov( ) if player.fighter else Constants.min_fov_radius if fov_recompute: recompute_fov(fov_map, player.x, player.y, fov_radius, Constants.fov_light_walls, Constants.fov_algorithm) render_all(con, panel, entities, player, game_map, fov_map, fov_recompute, message_log, Constants.screen_width, Constants.screen_height, Constants.bar_width, Constants.panel_height, Constants.panel_y, mouse_event, Constants.colors, game_state) fov_recompute = False libtcod.console_flush() clear_all(con, entities) action = handle_keys(key_event, game_state) move = action.get('move') wait = action.get('wait') pickup = action.get('pickup') show_inventory = action.get('show_inventory') drop_inventory = action.get('drop_inventory') inventory_index = action.get('inventory_index') take_stairs = action.get('take_stairs') level_up = action.get('level_up') show_character_screen = action.get('show_character_screen') exit = action.get('exit') fullscreen = action.get('fullscreen') possession = action.get('possession') #start_test_mode = action.get('start_test_mode') restart = action.get('restart') player_turn_results = [] if False: # start_test_mode: fighter_component = Fighter(hp=30, defense=2, power=8, body='god mode', xp=100, will_power=4) player.fighter = fighter_component player.fighter.owner = player player.inventory = Inventory(26) player.equipment = Equipment() player.inventory.owner = player player.equipment.owner = player equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) item = Entity(player.x, player.y, '/', libtcod.red, 'Small Dagger', equippable=equippable_component) entities.append(item) if restart: player, entities, game_map, message_log, game_state = get_game_variables( Constants) game_state = GameStates.PLAYERS_TURN fov_map = initialize_fov(game_map) fov_recompute = True con.clear() if possession: if not player.fighter: for entity in entities: if entity.fighter and entity.x == player.x and entity.y == player.y: if player.level.current_level >= entity.fighter.will_power: message_log.add_message( Message( f"You take control of the {entity.name}'s body...", libtcod.white)) if first_body: message_log.add_message( Message(f'(Press p to release it)', libtcod.gray)) first_body = False if entity.inventory and first_inventory: message_log.add_message( Message( f'(Press g to Get items, i for Inventory)', libtcod.gray)) first_inventory = False player.fighter = entity.fighter player.inventory = entity.inventory player.equipment = entity.equipment player.possessed_entity = entity player.fighter.owner = player player.char = entity.char player.render_order = entity.render_order player.name = f'Ghost/{entity.name}' entities.remove(entity) else: message_log.add_message( Message( f'The {entity.name} is too powerful for you to possess!', libtcod.yellow)) else: message_log.add_message( Message( f'You cast your spirit out of the {player.possessed_entity.name}, leaving a shambling husk behind...', libtcod.red)) ai_component = SlowMonster() zombie_name = f'Zombie {player.possessed_entity.name}' zombie_char = player.possessed_entity.char zombie = Entity(player.x, player.y, zombie_char, libtcod.desaturated_green, zombie_name, blocks=True, render_order=RenderOrder.ACTOR, fighter=player.fighter, ai=ai_component, inventory=player.inventory, equipment=player.equipment) zombie.fighter.xp = 5 zombie.fighter.owner = zombie entities.append(zombie) player.fighter = None player.inventory = None player.equipment = None player.char = ' ' player.render_order = RenderOrder.GHOST player.name = 'Ghost' if move and game_state == GameStates.PLAYERS_TURN: dx, dy = move destination_x = player.x + dx destination_y = player.y + dy if not game_map.is_blocked(destination_x, destination_y): target = get_blocking_entities_at_location( entities, destination_x, destination_y) if target and player.fighter: attack_results = player.fighter.attack(target) player_turn_results.extend(attack_results) else: player.move(dx, dy) fov_recompute = True over_entities = [ e for e in entities if e.x == player.x and e.y == player.y and e != player ] if over_entities: over_fighters = [e for e in over_entities if e.fighter] over_items = [ e for e in over_entities if not e.fighter ] if over_fighters: over_fighter = over_fighters[0] message_log.add_message( Message( f'Your shadow falls over the {over_fighter.name}...', libtcod.white)) elif over_items: if len(over_items) == 1: over_items_list = f'{over_items[0].name}' elif len(over_items) == 2: over_items_list = f'{over_items[1].name} and a {over_items[0].name}' else: over_items_list = [ n.name for n in over_items[:-1] ].join(', a ') over_items_list += "and a {over_items[-1].name}" message_log.add_message( Message(f'There is a {over_items_list} here.', libtcod.white)) if 'Staircase' in [e.name for e in over_items ] and player.fighter: message_log.add_message( Message( f'(Press enter/return to use stairs)', libtcod.gray)) game_state = GameStates.ENEMY_TURN elif wait: game_state = GameStates.ENEMY_TURN elif pickup and game_state == GameStates.PLAYERS_TURN: if player.inventory: for entity in entities: if entity.item and entity.x == player.x and entity.y == player.y: pickup_results = player.inventory.add_item(entity) player_turn_results.extend(pickup_results) break else: message_log.add_message( Message('There is nothing here to pick up!', libtcod.yellow)) elif player.fighter: message_log.add_message( Message('This creature cannot carry items.', libtcod.yellow)) else: message_log.add_message( Message( "You can't pick up items without a body of some kind...", libtcod.yellow)) if show_inventory: if player.inventory: previous_game_state = game_state game_state = GameStates.SHOW_INVENTORY elif player.fighter: message_log.add_message( Message('This creature cannot carry items.', libtcod.yellow)) else: message_log.add_message( Message('You lack a body to carry items...', libtcod.yellow)) if drop_inventory: previous_game_state = game_state game_state = GameStates.DROP_INVENTORY if inventory_index is not None and player.inventory and previous_game_state != GameStates.PLAYER_DEAD and inventory_index < len( player.inventory.items): item = player.inventory.items[inventory_index] if game_state == GameStates.SHOW_INVENTORY: player_turn_results.extend( player.inventory.use(item, entities=entities, fov_map=fov_map)) elif game_state == GameStates.DROP_INVENTORY: player_turn_results.extend(player.inventory.drop_item(item)) if take_stairs and game_state == GameStates.PLAYERS_TURN: for entity in entities: if entity.stairs and entity.x == player.x and entity.y == player.y: entities = game_map.next_floor(player, message_log, constants) fov_map = initialize_fov(game_map) fov_recompute = True libtcod.console_clear(con) break else: message_log.add_message( Message('There are no stairs here.', libtcod.yellow)) if level_up: if player.fighter: if level_up == 'hp': player.fighter.base_max_hp += 20 player.fighter.hp += 20 elif level_up == 'str': player.fighter.base_power += 1 elif level_up == 'def': player.fighter.base_defense += 1 game_state = previous_game_state if show_character_screen: previous_game_state = game_state game_state = GameStates.CHARACTER_SCREEN if game_state == GameStates.TARGETING: if left_click: target_x, target_y = left_click item_use_results = player.inventory.use(targeting_item, entities=entities, fov_map=fov_map, target_x=target_x, target_y=target_y) player_turn_results.extend(item_use_results) elif right_click: player_turn_results.append({'targeting_cancelled': True}) if exit: if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY, GameStates.CHARACTER_SCREEN): game_state = previous_game_state elif game_state == GameStates.TARGETING: player_turn_results.append({'targeting_cancelled': True}) else: save_game(player, entities, game_map, message_log, game_state) return True if fullscreen: libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) for player_turn_result in player_turn_results: message = player_turn_result.get('message') dead_entity = player_turn_result.get('dead') item_added = player_turn_result.get('item_added') item_consumed = player_turn_result.get('consumed') item_dropped = player_turn_result.get('item_dropped') equip = player_turn_result.get('equip') targeting = player_turn_result.get('targeting') targeting_cancelled = player_turn_result.get('targeting_cancelled') xp = player_turn_result.get('xp') if message: message_log.add_message(message) if targeting_cancelled: game_state = previous_game_state message_log.add_message( Message('Targeting cancelled', libtcod.yellow)) if dead_entity: if dead_entity.fighter == player.fighter: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if xp: leveled_up = player.level.add_xp(xp) fighter_leveled_up = player.fighter.level.add_xp(xp) message_log.add_message( Message('You gain {0} experience points.'.format(xp), libtcod.white)) if leveled_up: message_log.add_message( Message( 'You grow stronger! You reached level {0}'.format( player.level.current_level) + '!', libtcod.green)) message_log.add_message( Message('You can now possess larger creatures...', libtcod.red)) if fighter_leveled_up: previous_game_state = game_state game_state = GameStates.LEVEL_UP if item_added: entities.remove(item_added) game_state = GameStates.ENEMY_TURN if item_consumed: game_state = GameStates.ENEMY_TURN if item_dropped: entities.append(item_dropped) game_state = GameStates.ENEMY_TURN if equip: equip_results = player.equipment.toggle_equip(equip) for equip_result in equip_results: equipped = equip_result.get('equipped') dequipped = equip_result.get('dequipped') if equipped: message_log.add_message( Message('You equipped the {0}'.format( equipped.name))) if dequipped: message_log.add_message( Message('You dequipped the {0}'.format( dequipped.name))) game_state = GameStates.ENEMY_TURN if targeting: previous_game_state = GameStates.PLAYERS_TURN game_state = GameStates.TARGETING targeting_item = targeting message_log.add_message(targeting_item.item.targeting_message) if game_state == GameStates.ENEMY_TURN: for entity in entities: if entity.ai: enemy_turn_results = entity.ai.take_turn( player, fov_map, game_map, entities) for enemy_turn_result in enemy_turn_results: message = enemy_turn_result.get('message') dead_entity = enemy_turn_result.get('dead') if message: message_log.add_message(message) if dead_entity: if dead_entity.fighter == player.fighter: message, game_state = kill_player(dead_entity) else: message = kill_monster(dead_entity) message_log.add_message(message) if game_state == GameStates.PLAYER_DEAD: break if game_state == GameStates.PLAYER_DEAD: break else: game_state = GameStates.PLAYERS_TURN
def get_new_game_variables(constants): race_component = None class_component = None game_state = GameStates.SELECT_SEX previous_game_state = game_state key = libtcod.Key() mouse = libtcod.Mouse() while not libtcod.console_is_window_closed(): libtcod.sys_check_for_event( libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse) libtcod.console_flush() action = handle_keys(key, game_state) if game_state == GameStates.SELECT_SEX: select_sex_menu(0, 50, constants['screen_width'], constants['screen_height'], constants['sexes']) action = handle_keys(key, game_state) male = action.get('male') female = action.get('female') exit = action.get('exit') if male: sex = 'Male' game_state = GameStates.ENTER_PLAYER_NAME elif female: sex = 'Female' game_state = GameStates.ENTER_PLAYER_NAME elif exit: break elif game_state == GameStates.ENTER_PLAYER_NAME: select_name_menu(0, 50, constants['screen_width'], constants['screen_height']) libtcod.console_flush() name = enter_player_name(constants['screen_width'], constants['screen_height']) if name == None: game_state = GameStates.SELECT_SEX else: game_state = GameStates.SELECT_RACE elif game_state == GameStates.SELECT_RACE: select_race_menu(0, 50, constants['screen_width'], constants['screen_height'], constants['races']) action = handle_keys(key, game_state) human = action.get('human') exit = action.get('exit') if human: race_component = Human() game_state = GameStates.SELECT_CLASS elif exit: game_state = GameStates.ENTER_PLAYER_NAME elif game_state == GameStates.SELECT_CLASS: select_combat_class_menu(0, 50, constants['screen_width'], constants['screen_height'], constants['combat_classes']) action = handle_keys(key, game_state) warrior = action.get('warrior') archer = action.get('archer') exit = action.get('exit') if warrior: class_component = Warrior() break if archer: class_component = Archer() break elif exit: game_state = GameStates.SELECT_RACE if exit: libtcod.console_clear(0) libtcod.console_flush() return None, None, None, None, None inventory_component = Inventory(26) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, 1, libtcod.white, name, sex, player=True, blocks=True, render_order=RenderOrder.ACTOR, combat_class=class_component, race=race_component, inventory=inventory_component, level=level_component, equipment=equipment_component) player = apply_class_stats_to_race(player) if player.combat_class.class_name == 'Warrior': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, min_damage_bonus=0, max_damage_bonus=1) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) dagger.item.description = "Better than your bare hands." player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) elif player.combat_class.class_name == 'Archer': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, min_damage_bonus=0, max_damage_bonus=1) dagger = Entity(0, 0, '-', libtcod.sky, 'Dagger', equippable=equippable_component) dagger.item.description = "Better than your bare hands." player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) entities = [player] game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_log_x'], constants['message_width'], constants['message_panel_height']) game_state = GameStates.PLAYERS_TURN return player, entities, game_map, message_log, game_state
def place_entities(self, room, entities, names_list, colors_list): max_monsters_per_room = from_dungeon_level([[2, 1], [3, 6], [4, 10]], self.dungeon_level) max_items_per_room = from_dungeon_level( [[1, 1], [1, 2], [1, 3], [2, 4]], self.dungeon_level) # Get a random number of monsters number_of_monsters = randint(0, max_monsters_per_room) # Get a random number of items #number_of_items = randint(0, max_items_per_room) number_of_items = 0 monster_chances = { 'rat': from_dungeon_level([[40, 1], [30, 2], [25, 3], [10, 4], [15, 5]], self.dungeon_level), 'rat_prince': from_dungeon_level([[5, 2], [25, 3], [45, 4], [75, 5]], self.dungeon_level), 'bat': from_dungeon_level([[30, 1], [25, 2], [20, 3], [20, 4], [10, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]], self.dungeon_level), 'goblin': from_dungeon_level([ [15, 2], [25, 3], [30, 4], [30, 5], [30, 6], [30, 7], [30, 8], [30, 9], [30, 10], ], self.dungeon_level), 'troll': from_dungeon_level([[5, 2], [15, 3], [15, 4], [20, 5], [30, 6], [60, 7], [60, 8], [60, 9], [60, 10]], self.dungeon_level) } item_chances = { #SCROLL TEST #'cure_wounds': 25, #'lightning_scroll': 25, #'fireball_scroll': 25, #'confusion_scroll': 25 #EVERYTHING TEST #'cure_wounds': 1, #'foul_liquid': 1, #'restore_wounds': 1, #'sword': 1, #'shield': 1, #'lightning_scroll': 1, #'fireball_scroll': 1, #'confusion_scroll': 1 #'none': from_dungeon_level([[10, 1], [10,2], [5,3]], self.dungeon_level), 'cure_wounds': from_dungeon_level([[5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]], self.dungeon_level), 'foul_liquid': from_dungeon_level([[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]], self.dungeon_level), 'restore_wounds': from_dungeon_level([[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]], self.dungeon_level), 'sword': from_dungeon_level([[2, 2], [2, 3], [6, 4], [5, 5], [5, 6], [5, 7], [5, 8], [5, 9], [12, 10]], self.dungeon_level), 'shield': from_dungeon_level( [[5, 4], [5, 5], [15, 6], [15, 7], [15, 8], [15, 9], [15, 10]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[10, 4], [15, 5], [20, 6], [20, 7], [20, 8], [20, 9], [20, 10]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[10, 6], [15, 7], [20, 8], [20, 9], [25, 10]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[2, 3], [5, 4], [10, 5], [10, 6], [10, 7], [15, 8], [15, 9], [20, 10]], self.dungeon_level), 'arrows': 10 } for i in range(number_of_monsters): # Choose a random location in the room x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) # Check if an entity is already in that location if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'rat': fighter_component = Fighter(hp=3, defense=0, power=3, speed=10, xp=5) ai_component = BasicMonster() monster = Entity(x, y, 272, libtcod.Color(191, 191, 191), 'rat', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) chance_for_swarm = 40 swarm_check = randint(0, 100) if swarm_check <= chance_for_swarm: for i in range(1, randint(0, 3) + 1): rx = randint(room.x1 + 1, room.x2 - 1) ry = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == rx and entity.y == ry ]): fighter_component = Fighter(hp=3, defense=0, power=3, speed=10, xp=5) ai_component = BasicMonster() swarm = Entity(rx, ry, 272, libtcod.Color(191, 191, 191), 'rat', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(swarm) elif monster_choice == 'rat_prince': fighter_component = Fighter(hp=15, defense=0, power=8, speed=8, xp=40) ai_component = BasicMonster() monster = Entity(x, y, 274, libtcod.lighter_violet, 'rat prince', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) chance_for_swarm = 10 swarm_check = randint(0, 100) if swarm_check <= chance_for_swarm: for i in range(1, randint(0, 2)): rx = randint(room.x1 + 1, room.x2 - 1) ry = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == rx and entity.y == ry ]): fighter_component = Fighter(hp=3, defense=0, power=3, speed=10, xp=5) ai_component = BasicMonster() swarm = Entity(rx, ry, 272, libtcod.Color(191, 191, 191), 'rat', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(swarm) elif monster_choice == 'bat': fighter_component = Fighter(hp=9, defense=0, power=3, speed=10, xp=10) ai_component = RandomWalk(randomfactor=66) monster = Entity(x, y, 278, libtcod.Color(191, 191, 191), 'bat', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'goblin': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=1) monster_weapon = Entity(x, y, 371, libtcod.lighter_green, 'Goblin Spear', equippable=equippable_component) equipment_component = Equipment() monster_inv = Inventory(3) fighter_component = Fighter(hp=20, defense=0, power=8, speed=5, xp=30) ai_component = BasicMonster() monster = Entity(x, y, 280, libtcod.Color(107, 164, 107), 'goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component, inventory=monster_inv, equipment=equipment_component) monster.equipment.list.append(monster_weapon) monster.conditions.append( Poison(target=monster, active=True, duration=5, damage=2)) monster.conditions.append( Healing(target=monster, active=True, duration=10, healing=1)) else: #troll fighter_component = Fighter(hp=30, defense=1, power=10, speed=3, xp=80) ai_component = BasicMonster() monster = Entity(x, y, 282, libtcod.Color(242, 221, 131), 'troll', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) entities.append(monster) for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'none': a = 1 if item_choice == 'cure_wounds': item_component = Item( use_function=heal, stackable=False, amount=20, description= "A small glass vial containing a semi-translusent crystalline liquid which shimmers slightly in the light.", effect="Used as an instant cure to minor wounds.") item = Entity(x, y, 349, colors_list[names_list['Cure Wounds']], 'Cure Wounds', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'restore_wounds': item_component = Item( use_function=restore_wounds, stackable=False, duration=10, healing=4, description= "A small glass vial containing a semi-translusent crystalline liquid which shimmers slightly in the light.", effect="Used to slowly restore moderate wounds.") item = Entity(x, y, 349, colors_list[names_list['Restore Wounds']], 'Restore Wounds', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'foul_liquid': item_component = Item( use_function=poison_potion, stackable=False, duration=5, damage=2, description= "A small glass vial containing a semi-translusent crystalline liquid which shimmers slightly in the light.", effect="Smells like smoke and tar.") item = Entity(x, y, 349, colors_list[names_list['Foul Liquid']], 'Foul Liquid', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'sword': equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=3) item = Entity(x, y, 369, colors_list[names_list['Sword']], 'Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, 375, colors_list[names_list['Shield']], 'Shield', equippable=equippable_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', libtcod.light_cyan), damage=25, radius=3, flammable=False) #Fireball scrolls are not flamable item = Entity(x, y, 333, choice(colors_list['Scrolls']), 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', libtcod.light_cyan), flammable=True) item = Entity(x, y, 333, choice(colors_list['Scrolls']), 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'lightning_scroll': item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5, flammable=True) item = Entity(x, y, 333, choice(colors_list['Scrolls']), 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'arrows': arrow_count = randint(1, 10) hit_component = BasicShot(2) ammo_component = Ammo(hit_function=hit_component, retrievable=True) item_component = Item(use_function=None, stackable=True, count=arrow_count, ammo=ammo_component, flammable=True, range=0, description="Arrow. Pewpew!") item = Entity(x, y, 378, colors_list[names_list['Arrow']], 'Arrow', item=item_component) else: print("Unhandled item spawn choice .. " + str(item_choice) + " .. game_map line 585.") if item_choice != 'none': entities.append(item)
def place_entities(self, room, entities): # 部屋のオブジェクト数の決定 max_monsters_per_room = from_dungeon_level( [[2, 1], [3, 4], [5, 6], [6, 12]], self.dungeon_level) max_items_per_room = from_dungeon_level([[1, 1], [2, 6]], self.dungeon_level) number_of_monsters = randint(0, max_monsters_per_room) number_of_items = randint(0, max_items_per_room) # [確率,発生する階数] monster_chances = { 'goblin': from_dungeon_level([[80, 1], [60, 7], [30, 10], [0, 14]], self.dungeon_level), 'troll': from_dungeon_level([[15, 3], [60, 5], [80, 14]], self.dungeon_level), 'ogre': from_dungeon_level([[15, 6], [30, 10], [60, 14]], self.dungeon_level) } item_chances = { 'healing_potion': 15, 'bronze_sword': from_dungeon_level([[5, 4]], self.dungeon_level), 'shield': from_dungeon_level([[5, 6]], self.dungeon_level), 'iron_sword': from_dungeon_level([[5, 8]], self.dungeon_level), 'lightning_scroll': from_dungeon_level([[25, 4], [40, 8]], self.dungeon_level), 'fireball_scroll': from_dungeon_level([[25, 6], [40, 10]], self.dungeon_level), 'confusion_scroll': from_dungeon_level([[10, 2], [20, 4]], self.dungeon_level) } # モンスターの数だけ実行 for i in range(number_of_monsters): # 部屋のランダムな位置を取得 x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) # 得られた座標に既にEntitiyが存在しないならば if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): monster_choice = random_choice_from_dict(monster_chances) if monster_choice == 'goblin': fighter_component = Fighter(hp=25, defense=0, power=3, xp=35) ai_component = BasicMonster() monster = Entity(x, y, 'g', libtcod.desaturated_green, 'goblin', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, ai=ai_component) elif monster_choice == 'troll': fighter_component = Fighter(hp=40, defense=2, power=4, xp=70) ai_component = BasicMonster() monster = Entity(x, y, 'T', libtcod.darker_green, 'Troll', blocks=True, fighter=fighter_component, render_order=RenderOrder.ACTOR, ai=ai_component) elif monster_choice == 'ogre': fighter_component = Fighter(hp=70, defense=1, power=4, xp=120) ai_component = BasicMonster() equipment_component = Equipment() equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_daice=2, daice=2, base_power=3) club = Entity(0, 0, 'l', libtcod.sky, 'club', equippable=equippable_component) monster = Entity(x, y, 'O', libtcod.darker_green, 'Ogre', blocks=True, fighter=fighter_component, equipment=equipment_component, render_order=RenderOrder.ACTOR, ai=ai_component) monster.equipment.toggle_equip(club) entities.append(monster) else: i -= 1 # アイテムの数だけ実行 for i in range(number_of_items): x = randint(room.x1 + 1, room.x2 - 1) y = randint(room.y1 + 1, room.y2 - 1) # 得られた座標に既にEntitiyが存在しないならば if not any([ entity for entity in entities if entity.x == x and entity.y == y ]): item_choice = random_choice_from_dict(item_chances) if item_choice == 'healing_potion': item_component = Item(use_function=heal, amount=40) item = Entity(x, y, '!', libtcod.violet, 'Healing Potion', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'fireball_scroll': item_component = Item( use_function=cast_fireball, targeting=True, targeting_message=Message( 'Left-click a target tile for the fireball, or right-click to cancel.', libtcod.light_cyan), damage=25, radius=3) item = Entity(x, y, '#', libtcod.red, 'Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'confusion_scroll': item_component = Item( use_function=cast_confuse, targeting=True, targeting_message=Message( 'Left-click an enemy to confuse it, or right-click to cancel.', libtcod.light_cyan)) item = Entity(x, y, '#', libtcod.light_pink, 'Confusion Scroll', render_order=RenderOrder.ITEM, item=item_component) elif item_choice == 'bronze_sword': equippable_component = Equippable( EquipmentSlots.MAIN_HAND, power_daice=2, daice=3, base_power=1) item = Entity(x, y, '/', libtcod.sky, 'Bronze Sword', equippable=equippable_component) elif item_choice == 'shield': equippable_component = Equippable( EquipmentSlots.OFF_HAND, defense_bonus=1) item = Entity(x, y, '[', libtcod.darker_orange, 'Shield', equippable=equippable_component) elif item_choice == 'iron_sword': equippable_component = Equippable( EquipmentSlots.MAIN_HAND, power_daice=4, daice=3, base_power=2) item = Entity(x, y, '/', libtcod.sky, 'Iron Sword', equippable=equippable_component) else: item_component = Item(use_function=cast_lightning, damage=40, maximum_range=5) item = Entity(x, y, '#', libtcod.yellow, 'Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component) entities.append(item) else: i -= 1
def test_attribute_bonus__ac_default_is_0(): e = Equipment() assert e.attribute_bonus('AC') == 0
def test_attribute_bonus__ac_with_armor(leather_armor): e = Equipment(leather_armor) assert e.attribute_bonus('AC') == leather_armor.equippable.modifiers['AC']
def test_attribute_bonus__strength_default_is_0(): e = Equipment() assert e.attribute_bonus('STRENGTH') == 0
def test_item_is_equipped__weapon_equipped(dagger): e = Equipment(dagger) assert e.is_equipped(dagger)
def test_item_is_equipped__none_equipped(): e = Equipment() assert e.is_equipped('giant jockstrap') is False
def test_attribute_bonus__strength_with_weapon(dagger): e = Equipment(dagger) assert e.attribute_bonus('STRENGTH') == dagger.equippable.modifiers['STRENGTH']
def get_game_variables(constants): fighter_component = Fighter(hp=100, defense=1, power=5, agility=1, job=0, mana=10, nutrition=500, base_psyche=2, starvation_bonus=0) inventory_component = Inventory(26) skills_component = Skills(15) level_component = Level() equipment_component = Equipment() player = Entity(0, 0, '@', libtcod.white, 'Player', blocks=True, render_order=RenderOrder.ACTOR, fighter=fighter_component, inventory=inventory_component, level=level_component, equipment=equipment_component, skills=skills_component) entities = [player] equippable_component = Equippable(EquipmentSlots.MAIN_HAND, power_bonus=4) item_component = Item(use_function=None) dagger = Entity(0, 0, '/', libtcod.sky, 'Carving Knife', equippable=equippable_component, item=item_component) equippable_component = Equippable(EquipmentSlots.OFF_HAND, defense_bonus=1, agility_bonus=-1) item_component = Item(use_function=None) buckler = Entity(0, 0, '{', libtcod.sky, 'Buckler', equippable=equippable_component, item=item_component) player.inventory.add_item(dagger) player.equipment.toggle_equip(dagger) player.inventory.add_item(buckler) player.equipment.toggle_equip(buckler) game_map = GameMap(constants['map_width'], constants['map_height']) game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'], constants['max_maze_rooms'], constants['maze_min_size'], constants['maze_max_size'], constants['map_width'], constants['map_height'], player, entities) message_log = MessageLog(constants['message_x'], constants['message_width'], constants['message_height']) game_state = GameStates.CHARACTER_CREATION ggender = Gender.male return player, entities, game_map, message_log, game_state, ggender
def test_item_slot_equipped__armor(leather_armor): e = Equipment(leather_armor) assert e.slot_equipped('ARMOR')
def test_item_is_equipped__armor_equipped(leather_armor): e = Equipment(leather_armor) assert e.is_equipped(leather_armor)
def test_item_slot_equipped__invalid_slot_raises_ValueError(leather_armor): e = Equipment(leather_armor) with pytest.raises(ValueError): e.slot_equipped('GIMPSUIT')
from components.ai import HostileEnemy from components import consumable, equippable from components.equipment import Equipment from components.fighter import Fighter from components.inventory import Inventory from components.level import Level from entity import Actor, Item player = Actor( char="@", color=(255, 255, 255), name="Player", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=30, base_defense=1, base_power=2), inventory=Inventory(capacity=26), level=Level(level_up_base=200), ) orc = Actor( char="o", color=(63, 127, 63), name="Orc", ai_cls=HostileEnemy, equipment=Equipment(), fighter=Fighter(hp=10, base_defense=0, base_power=3), inventory=Inventory(capacity=0), level=Level(xp_given=35), ) troll = Actor( char="T", color=(0, 127, 0),
def test_item_slot_equipped__weapon(dagger): e = Equipment(dagger) assert e.slot_equipped('WEAPON')