Exemplo n.º 1
0
def place_entities(x, y, size, entities, items, game_map,
                   max_monsters_per_room, max_items_per_room):
    number_of_monsters = randint(10, max_monsters_per_room)
    number_of_items = randint(10, max_items_per_room)
    # print("Monsters ", number_of_monsters)
    # print("Items ", number_of_items)
    monster_chances = {'ghost': 80, 'angry_ghost': 20}
    item_chances = {
        'heal potion': 70,
        'lightning scroll': 10,
        'fireball scroll': 10,
        'confuse scroll': 10
    }
    print("coords ", x, y)
    for i in range(number_of_monsters):
        mx = randint(x, x + size)
        my = randint(y, y + size)
        print("monsters coord ", mx, my)
        if (not (mx, my) in entities) and (not (mx, my) in game_map.terrain):
            monster_choice = random_choice_from_dict(monster_chances)

            if monster_choice == 'ghost':
                fighter_component = Fighter(hp=1, defense=0, power=1)
                ai_component = BasicMonster()
                monster = Entity(mx,
                                 my,
                                 '[U+7030]',
                                 'gray',
                                 'Ghost',
                                 fighter=fighter_component,
                                 ai=ai_component)
            else:
                fighter_component = Fighter(hp=1, defense=1, power=1)
                ai_component = BasicMonster()
                monster = Entity(mx,
                                 my,
                                 '[U+7010]',
                                 'white',
                                 'Troll',
                                 fighter=fighter_component,
                                 ai=ai_component)
            entities[(monster.x, monster.y)] = monster
    for i in range(number_of_items):
        print('Items start pont', x, y)
        ix = randint(x, x + size)
        iy = randint(y, y + size)
        print("items coord", ix, iy)
        if not ((ix, iy) in game_map.terrain) and not ((ix, iy) in items):
            item_choice = random_choice_from_dict(item_chances)

            if item_choice == 'heal potion':
                item = Entity(ix, iy, '[U+3000]', 'red', item_choice)
            elif item_choice == 'lightning scroll':
                item = Entity(ix, iy, '[U+6000]', 'yellow', item_choice)
            elif item_choice == 'fireball scroll':
                item = Entity(ix, iy, '[U+6000]', 'red', item_choice)
            elif item_choice == 'confuse scroll':
                item = Entity(ix, iy, '[U+6000]', 'pink', item_choice)

            items[(item.x, item.y)] = item
Exemplo n.º 2
0
    def __init__(self, average_tree_diameter):
        self.average_tree_diameter = average_tree_diameter

        self.primary = random_choice_from_dict(tree_choices)
        self.secondary = random_choice_from_dict(tree_choices)

        self.tree_choices = {}
        self.tree_choices[self.primary] = 90
        self.tree_choices[self.secondary] = 10
Exemplo n.º 3
0
    def place_entities(self, room, entities):
        """Place a random number of monsters in each room of the map."""
        max_monsters_per_room = from_dungeon_level(max_monsters_dungeon, self.dungeon_level)
        max_items_per_room = from_dungeon_level(max_items_dungeon, self.dungeon_level)
        # Get a random number of monsters and items
        number_of_monsters = rd.randint(0, max_monsters_per_room)
        number_of_items = rd.randint(0, max_items_per_room)
        # Generate dictionary (elem -> chance ) for the appropriate dungeon level
        monster_chances = {m['id']: from_dungeon_level(m['spawn_chance'], self.dungeon_level) for m in monsters}
        consumables_chances = {c['id']: from_dungeon_level(c['drop_chance'], self.dungeon_level) for c in consumables}
        equipment_chances = {e['id']: from_dungeon_level(e['drop_chance'], self.dungeon_level) for e in equipment}

        # === Monsters ===
        for i in range(number_of_monsters):
            # Choose a random location in the room
            x = rd.randint(room.x1 + 1, room.x2 - 1)
            y = rd.randint(room.y1 + 1, room.y2 - 1)

            tile_occupied = any([entity for entity in entities if entity.x == x and entity.y == y])
            if not tile_occupied and self.tiles[x][y].can_spawn:
                monster_choice = random_choice_from_dict(monster_chances)

                for monster in monsters:
                    if monster_choice == monster['id']:
                        monster_entity = self.create_monster_entity(x, y, monster, monster['equipment'])

                entities.append(monster_entity)

        # === Items ===
        for i in range(number_of_items):
            x = rd.randint(room.x1 + 1, room.x2 - 1)
            y = rd.randint(room.y1 + 1, room.y2 - 1)

            tile_occupied = any([entity for entity in entities if entity.x == x and entity.y == y])
            if not tile_occupied and self.tiles[x][y].can_spawn:
                select_item_pool = rd.randint(0, 100)

                if select_item_pool < 70:
                    item_choice = random_choice_from_dict(consumables_chances)

                    for consumable in consumables:
                        if item_choice == consumable['id']:
                            item = self.create_item_entity(x, y, consumable)

                else:
                    item_choice = random_choice_from_dict(equipment_chances)

                    for equippable in equipment:
                        if item_choice == equippable['id']:
                            item = self.create_item_entity(x, y, equippable, is_equippable=True)

                entities.append(item)
Exemplo n.º 4
0
    def generate_location(self):
        location_choice = random_choice_from_dict(weight_factor(self.locations))
        location = self.locations[location_choice]

        location_type = random_choice_from_dict(location['types'])
        if location_choice == 'temple':
            name = '{0} of the {1}'.format(location_type, choice(location['names']))
        elif location_choice == 'settlement':
            name = '{0} {1} {2}'.format(choice(location['first_names']), choice(location['last_names']), location_type).strip()

        landmark = self.generate_landmark(name, location_choice, location_type)
        location = GameMap(map_vars.width, map_vars.height, map_creator=ForestMap(5, landmark=landmark))
        return location
Exemplo n.º 5
0
    def place_entities(self, room, entities):
        max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]],
                                                   self.dungeon_level)
        max_items_per_room = from_dungeon_level([[1, 1], [2, 4]],
                                                self.dungeon_level)

        # Get a random number of monsters
        number_of_monsters = randint(0, max_monsters_per_room)
        number_of_items = randint(0, max_items_per_room)

        monster_chances, item_chances = get_content(self)

        for i in range(number_of_monsters):
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            #choose a random location in room
            if self.tiles[x][y].blocked == True:
                skip = True
            else:
                skip = False

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]) and not skip:
                monster_choice = random_choice_from_dict(monster_chances)
                monster = create_entity(x, y, monster_choice)
                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)

            #choose a random location in room
            if self.tiles[x][y].blocked == True:
                skip = True
            else:
                skip = False

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]) and not skip:
                item_choice = random_choice_from_dict(item_chances)

                item = create_item(x, y, item_choice)

                entities.append(item)
Exemplo n.º 6
0
    def initialize_tiles(self):
        forest_chars = {
            str(chr(tcod.CHAR_ARROW_N)): 25,
            str(chr(tcod.CHAR_VLINE)): 5,
            str(chr(tcod.CHAR_ARROW2_S)): 10,
            '|': 3,
            '\\': 7,
            '/': 7,
            'T': 40,
            'Y': 35,
        }

        tiles = [[None for y in range(self.height)] for x in range(self.width)]
        for x in range(self.width):
            for y in range(self.height):
                tile = WorldTile(biom=Biomes.FOREST,
                                 bg_color=color_vars.forest_bg)
                tree_entity = Entity(
                    x,
                    y,
                    char=random_choice_from_dict(forest_chars),
                    color=color_vars.forest)
                tile.place_static_entity(tree_entity)

                tiles[x][y] = tile

        return tiles
Exemplo n.º 7
0
    def grow_thicket(self, center_x, center_y, map_obj, flora_data=fungi):
        flora_choices = weight_factor(flora_data)
        flora_choice = random_choice_from_dict(flora_choices)
        plant_info = flora_data[flora_choice]

        self.thickets.append({
            'center': (center_x, center_y),
            'plant': flora_choice,
        })

        min_radius = flora_data.get('min_thicket_radius', 0)
        max_radius = flora_data.get('max_thicket_radius', 5)
        thicket_radius = randint(min_radius, max_radius)
        for distance in range(thicket_radius):
            chance_for_plant = distance * 20
            for dx in range(-distance, distance):
                dy = int(pow(distance * distance - dx * dx, 0.5))
                dys = [-dy, dy]
                for dy in dys:
                    if randint(0, 100) < chance_for_plant:
                        continue
                    x = center_x + dx
                    y = center_y + dy
                    if not map_obj.is_void(
                            x, y) and not map_obj.tiles[x][y].static_entities:
                        map_obj.tiles[x][y].place_static_entity(
                            self.plant(x, y, plant_info))
Exemplo n.º 8
0
    def return_scrolls(self, x, y):
        item_chances = {
            'a': 10,
            'b': from_dungeon_level([[2, 4]], self.dungeon_level),
            'c': from_dungeon_level([[3, 4]], self.dungeon_level),
            'd': from_dungeon_level([[4, 4]], self.dungeon_level),
            'e': from_dungeon_level([[5, 4]], self.dungeon_level),
            'f': from_dungeon_level([[6, 4]], self.dungeon_level),
            'g': from_dungeon_level([[7, 4]], self.dungeon_level),
            'h': 10,
            'i': from_dungeon_level([[2, 4]], self.dungeon_level),
            'j': from_dungeon_level([[3, 4]], self.dungeon_level),
            'k': from_dungeon_level([[4, 4]], self.dungeon_level),
            'l': from_dungeon_level([[5, 4]], self.dungeon_level),
            'm': from_dungeon_level([[6, 4]], self.dungeon_level)
            }

        item_choice = random_choice_from_dict(item_chances)

        if item_choice == 'a':
            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=12, radius=2)
            item = Entity(x, y, '#', libtcod.red, 'Smudged Burnt Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'b':
            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=15, radius=2)
            item = Entity(x, y, '#', libtcod.red, 'Burnt Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'c':
            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=17, radius=3)
            item = Entity(x, y, '#', libtcod.red, 'Smudged Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'd':
            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 == 'e':
            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=35, radius=3)
            item = Entity(x, y, '#', libtcod.red, 'Calculated Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'f':
            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=50, radius=5)
            item = Entity(x, y, '#', libtcod.red, 'Bloodfeud Fireball Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'g':
            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 == 'h':
            item_component = Item(use_function=cast_lightning, damage=15, maximum_range=4)
            item = Entity(x, y, '#', libtcod.yellow, 'Smudged Burnt Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'i':
            item_component = Item(use_function=cast_lightning, damage=20, maximum_range=4)
            item = Entity(x, y, '#', libtcod.yellow, 'Burnt Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'j':
            item_component = Item(use_function=cast_lightning, damage=25, maximum_range=5)
            item = Entity(x, y, '#', libtcod.yellow, 'Smudged Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'k':
            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)
        elif item_choice == 'l':
            item_component = Item(use_function=cast_lightning, damage=60, maximum_range=5)
            item = Entity(x, y, '#', libtcod.yellow, 'Calculated Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component)
        elif item_choice == 'm':
            item_component = Item(use_function=cast_lightning, damage=80, maximum_range=7)
            item = Entity(x, y, '#', libtcod.yellow, 'Bloodfeud Lightning Scroll', render_order=RenderOrder.ITEM, item=item_component)

        return item
Exemplo n.º 9
0
def place_specific_entity(x, y, entities, otype, dungeon_level=1):
    item = load_rand_entity(random_choice_from_dict(otype),
                            otype,
                            x,
                            y,
                            dungeon_level=1)
    return (item)
Exemplo n.º 10
0
 def make_beds(self):
     plant_choices = {
         'turnip': 25,
         'potato': 30,
         'tomato': 25,
         'beetroot': 25,
     }
     number_of_beds = self.rect.h if self.rect.h < self.rect.w else self.rect.w
     self.beds = [random_choice_from_dict(plant_choices) for _ in range(number_of_beds)]
Exemplo n.º 11
0
    def grow_cave_entrance_zone(self, cave, zones):
        wall_plant_choices = weight_factor(entrance_plants['wall'])
        ground_plant_choices = weight_factor(entrance_plants['ground'])

        for entrance_zone in zones:
            center_x, center_y = entrance_zone['center']
            for x, y in entrance_zone['coords']:
                if cave.tiles[x][y].static_entities:
                    continue

                distance_from_center = math.sqrt(
                    pow(center_x - x, 2) + pow(center_y - y, 2))
                chance_for_growth = distance_from_center * 2
                if randint(0, 100) < chance_for_growth:
                    continue

                if cave.is_blocked(x, y):
                    plant_info = entrance_plants['wall'][
                        random_choice_from_dict(wall_plant_choices)]
                else:
                    plant_info = entrance_plants['ground'][
                        random_choice_from_dict(ground_plant_choices)]

                char = plant_info['char']
                base_name = plant_info['name']
                name = plant_info['display_name']
                color = plant_info['color']
                if type(color) == list:
                    color = choice(color)
                if plant_info.get('bloom_factor'):
                    if randint(1, 100) <= plant_info['bloom_factor']:
                        color = plant_info['flower_color']
                        name = 'Blooming {0}'.format(name)

                plant = Entity(x,
                               y,
                               char=char,
                               color=color,
                               name=name,
                               base_name=base_name,
                               render_order=RenderOrder.GROUND_FLORA)
                cave.tiles[x][y].place_static_entity(plant)
Exemplo n.º 12
0
    def choose_plant(self, tile_shadowed):
        plant_choices = one_tile_plant_choices.copy()
        if tile_shadowed:
            plant_choices.update(weight_factor(fungi))
            plant_choices.update({k: (v // 3) for k, v in saplings.items()})
            plant_choices.update({k: (v * 2) for k, v in soil.items()})
        else:
            plant_choices.update(saplings)
            plant_choices.update(soil)

        return random_choice_from_dict(plant_choices)
Exemplo n.º 13
0
    def populate_by_type(self, points, monster_type, entities):
        monster_list = {}
        for name, monster in self.monsters.items():
            if monster_type in monster['types']:
                monster_list[name] = monster

        monster_chances = weight_factor(monster_list)
        for x, y in points:
            monster_choice = random_choice_from_dict(monster_chances)
            monster = self.get_monster(x, y, monster_choice)
            entities.append(monster)
Exemplo n.º 14
0
    def populate_room(self, room, dungeon_level, entities):
        max_monsters_per_room = from_dungeon_level(max_monsters_per_room_weights, dungeon_level)
        number_of_monsters = randint(0, max_monsters_per_room)
        monster_chances = weight_factor(monsters, dungeon_level)

        for _ in range(number_of_monsters):
            # Choose a random location in room
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)
            if not entities.find_by_point(x, y):
                monster_choice = random_choice_from_dict(monster_chances)
                monster = self.get_monster(x, y, monster_choice)
                entities.append(monster)
Exemplo n.º 15
0
    def generate_location(self):
        location_choice = random_choice_from_dict(weight_factor(
            self.locations))
        location = self.locations[location_choice]

        location_type = random_choice_from_dict(location['types'])
        if location_choice == 'city':
            name = 'Remains of {0} of the city of {1}'.format(
                location_type, choice(location['names']))
        elif location_choice == 'cave':
            name = '{0} of {1}'.format(location_type,
                                       choice(location['names'])).strip()
            landmark = Landmark(name, location_choice, location_type)
            return GameMap(map_vars.width,
                           map_vars.height,
                           map_creator=CaveMap(landmark=landmark))

        landmark = Landmark(name, location_choice, location_type)
        location = GameMap(map_vars.width,
                           map_vars.height,
                           map_creator=DungeonMap(10, 3, 5, landmark=landmark))
        return location
Exemplo n.º 16
0
    def place_mozaic_objects(self, obj_list, game_map, obj_char, place_chance, blocked = False, block_sight = False):
        place_choices = {
            'place': place_chance,
            'dont': 100 - place_chance,
        }

        for (x, y) in obj_list:
            if random_choice_from_dict(place_choices) == 'place':
                game_map.tiles[x][y].place_static_entity(Entity(x, y, **obj_char))
                if blocked:
                    game_map.tiles[x][y].regulatory_flags.add('blocked')
                if block_sight:
                    game_map.tiles[x][y].regulatory_flags.add('block_sight')
Exemplo n.º 17
0
    def fill_room(self, room, dungeon_level, entities):
        max_items_per_room = from_dungeon_level(max_items_per_room_weights, dungeon_level)
        number_of_items = randint(0, max_items_per_room)
        item_chances = weight_factor(items, dungeon_level)

        for _ in range(number_of_items):
            # Choose a random location in room
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)
            if not entities.find_by_point(x, y):
                item_choice = random_choice_from_dict(item_chances)
                item = self.get_item(x, y, item_choice)
                entities.append(item)
Exemplo n.º 18
0
    def populate(self, forest, entities):
        number_of_monsters = round(math.pow(forest.width * forest.height,
                                            0.25))
        monster_chances = weight_factor(monsters)

        for _ in range(number_of_monsters):
            # Choose a random location in room
            x = randint(0, forest.width - 1)
            y = randint(0, forest.height - 1)
            if not forest.is_blocked(x, y) and not entities.find_by_point(
                    x, y):
                monster_choice = random_choice_from_dict(monster_chances)
                monster = self.get_monster(x, y, monster_choice)
                entities.append(monster)
	def place_entities(self, room, entities):
		max_monsters_per_room = from_dungeon_level([[3,1],[5,3],[8,5]], self.dungeon_level)
		max_items_per_room = from_dungeon_level([[1,1],[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)

		monster_chances = get_easy_monsters(self.dungeon_level)

		item_chances = get_early_items(self.dungeon_level)

		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)

				monster = choose_easy_monster(monster_choice, self.dungeon_level, x, y)

				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)

				item = choose_early_item(item_choice, x, y)

				entities.append(item)
Exemplo n.º 20
0
 def generate_enchantment(self, dungeon_level):
     "Generates a random enchantment for the given item based on dungeon level. The modifier will potentially apply a bonus and change the name of the item"
     modifierChances = {
         key: from_dungeon_level(value.chance, dungeon_level)
         for key, value in equippable_enchantment.items()
         if self.slot in value.slot_restrictions
     }
     modifier_name = random_choice_from_dict(modifierChances)
     modifier = equippable_enchantment.get(modifier_name)
     if modifier.bonus_dic:
         for key, value in modifier.bonus_dic.items():
             # Bonus type is whatever is written in modifier
             setattr(self, key, getattr(self, key) + value)
             return ' of ' + modifier_name
     return ''
 def handle_blood_path(self):
     blood_char = random_choice_from_dict(self.blood_chars)
     blood_entity = Entity(self.body_part.x,
                           self.body_part.y,
                           char=blood_char,
                           color=color_vars.blood,
                           name='Drop of blood',
                           render_order=RenderOrder.EFFECT)
     self.engine.world_map.current_dungeon.tiles[self.body_part.x][
         self.body_part.y].place_static_entity(blood_entity)
     self.animation_entities.append(blood_entity)
     if len(self.animation_entities) > self.trail_length:
         entity_to_remove = self.animation_entities.pop(0)
         tile = self.engine.world_map.current_dungeon.tiles[
             entity_to_remove.x][entity_to_remove.y]
         tile.remove_static_entity(entity_to_remove)
Exemplo n.º 22
0
    def choose_encounter(self):
        possible_encounters = self.possible_encounters()
        if not possible_encounters:
            return False

        challenge = choice(list(EncounterChallenge))

        encounter_choices = weight_factor(possible_encounters)
        encounter_choice = random_choice_from_dict(encounter_choices)
        encounter_conf = possible_encounters[encounter_choice]

        self.encounter = encounter_conf['class'](
            encounter_choice,
            challenge=challenge,
            **encounter_conf['parameters'])
        return True
Exemplo n.º 23
0
    def populate_cave(self, cave, entities):
        max_monsters = from_dungeon_level(max_monsters_per_level_weights, cave.dungeon_level)
        number_of_monsters = randint(0, max_monsters)
        monster_chances = weight_factor(monsters, cave.dungeon_level)

        if cave.map_creator.twilight_zone:
            zone = cave.map_creator.twilight_zone
        elif cave.map_creator.dark_zone:
            zone = cave.map_creator.dark_zone

        for _ in range(number_of_monsters):
            x, y = choice(tuple(zone))
            if not entities.find_by_point(x, y):
                monster_choice = random_choice_from_dict(monster_chances)
                monster = self.get_monster(x, y, monster_choice)
                entities.append(monster)
Exemplo n.º 24
0
    def get_tree(self):
        diameter = randint(1, self.average_tree_diameter * 2)
        tree_key = random_choice_from_dict(self.tree_choices)

        base_name = base_name = trees[tree_key]['name']
        if diameter < 4:
            name = 'Trunk of {0}'.format(base_name)
        else:
            name = 'Giant trunk of {0}'.format(base_name)

        return Entity(-1,
                      -1,
                      bg_color=trees[tree_key]['color'],
                      name=name,
                      base_name=base_name,
                      blocks=True,
                      tree=Tree(diameter=diameter))
Exemplo n.º 25
0
    def make_landmark_objects(self):
        # family house
        main_hold = random_choice_from_dict({
            'house': 70,
            'hut': 30,
        })
        if main_hold == 'house':
            main_hold_method = self.make_house
        else:
            main_hold_method = self.make_hut
        self.make_landmark_object('main_hold', main_hold_method)

        # sheds
        self.make_landmark_object('shed', self.make_shed)

        # kitchen-garden
        self.make_landmark_object('kitchen-garden', self.make_kitchen_garden)
Exemplo n.º 26
0
    def next_tick(self):
        if self.path_index >= len(self.path) or self.completed:
            return []

        x, y = self.path[self.path_index]
        lightning_arc = Entity(x,
                               y,
                               char=random_choice_from_dict(
                                   self.lightning_chars),
                               color=color_vars.lightning_arc,
                               name='Lightning Arc',
                               render_order=RenderOrder.EFFECT)
        self.lightning_entities.append(lightning_arc)
        self.engine.entities.append(lightning_arc)

        self.path_index += 1
        if self.path_index >= len(self.path):
            return self.complete()

        return []
Exemplo n.º 27
0
 def generate_material(self, dungeon_level):
     "Generates a random material for the given item based on dungeon level. The modifier will potentially apply a bonus and change the name of the item. Bonus will usually be defensive for armor and offensive for weapons"
     modifierChances = {
         key: from_dungeon_level(value.chance, dungeon_level)
         for key, value in equippable_material.items()
         if self.slot in value.slot_restrictions
     }
     modifier_name = random_choice_from_dict(modifierChances)
     modifier = equippable_material.get(modifier_name)
     if modifier.bonus_dic:
         for _, value in modifier.bonus_dic.items():
             # Set power if weapon, defense if armor
             if self.slot in EquipmentSlotGroups.WEAPONS:
                 setattr(self, 'power_bonus',
                         getattr(self, 'power_bonus') + value)
             else:
                 setattr(self, 'defense_bonus',
                         getattr(self, 'defense_bonus') + value)
             return modifier_name + ' '
     return ''
Exemplo n.º 28
0
    def place_monsters(m, chunks, monster_chances, level):
        entities = []
        chance_any = monster_chances["any"]
        del monster_chances["any"]
        max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], level + 1)
        for idx, c in enumerate(chunks):
            c.monsters = []
            rval = random.randint(0, 100)
            if rval > chance_any:
                continue
            if idx == 0:
                num_monsters = 1  # don't overwhelm in the first room
            else:
                num_monsters = random.randint(1, max_monsters_per_room)
            room_center = Pos(c.x + c.width // 2, c.y + c.height // 2)
            skip_room = False

            for _ in range(num_monsters):
                x = random.randint(c.x + 1, c.x + c.width - 1)
                y = random.randint(c.y + 1, c.y + c.height - 1)
                if idx == 0:
                    # first room, don't spawn right next to player
                    attempts = 0
                    while Pos(x, y).distance_to(room_center) < 4:
                        x = random.randint(c.x + 1, c.x + c.width - 2)
                        y = random.randint(c.y + 1, c.y + c.height - 2)
                        attempts += 1
                        if attempts > 100:
                            skip_room = True
                if skip_room:
                    continue

                already_there = [entity for entity in entities if entity.pos.x == x and entity.pos.y == y]
                if not any(already_there) and not m.tiles[x][y].blocked:
                    monster_choice = random_choice_from_dict(monster_chances)
                    monster_data = get_monster(x, y, m, c, monster_choice, entities)
                    entities.extend(monster_data)
                    c.monsters.extend(monster_data)

        m.entities = entities
Exemplo n.º 29
0
    def place_entities(self, room, player):
        entities = []
        # Get a random number of monsters
        max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level)
        number_of_monsters = randint(0, max_monsters_per_room)

        monster_chances = {
            'kobold': from_dungeon_level([[80, 1], [40, 3], [20, 4], [0, 5]], self.dungeon_level),
            'orc': from_dungeon_level([[40, 1], [80, 2]], self.dungeon_level),
            'troll': from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level),
            'ogre': from_dungeon_level([[20, 2], [15, 4], [0, 6]], self.dungeon_level),
            'red_dragon': from_dungeon_level([[5, 5], [10, 6], [15, 7]], self.dungeon_level),
        }

        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)

            if not any([entity for entity in entities if entity.x == x and entity.y == y]) and \
                    player.x != x and player.y != y:
                monster_choice = random_choice_from_dict(monster_chances)

                if monster_choice == 'red_dragon' and self.number_of_bosses < self.max_number_of_bosses:
                    monster = spawn_dragon(x, y)
                    self.number_of_bosses += 1
                elif monster_choice == 'ogre' and self.number_of_bosses < self.max_number_of_bosses:
                    monster = spawn_ogre(x, y)
                    self.number_of_bosses += 1
                elif monster_choice == 'troll':
                    monster = spawn_troll(x, y)
                elif monster_choice == 'orc':
                    monster = spawn_orc(x, y)
                else:
                    monster = spawn_kobold(x, y)

                entities.append(monster)

        return entities
Exemplo n.º 30
0
    def __init__(self, max_rooms, room_min_size, room_max_size, landmark=None):
        super().__init__()
        self.default_tile_blocked = True

        self.max_rooms = max_rooms
        self.room_min_size = room_min_size
        self.room_max_size = room_max_size
        self.landmark = landmark

        self.player_start = None

        self.flora = Flora()
        self.fauna = Fauna()
        self.loot = Loot()

        materials = {
            'stone': color_vars.dungeon_stone,
            'dirt': color_vars.dungeon_dirt,
        }
        self.material = materials[random_choice_from_dict({
            'stone': 10,
            'dirt': 10,
        })]
Exemplo n.º 31
0
	def place_entities(self, room, entities):
		max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]], self.dungeon_level)
		max_items_per_room = from_dungeon_level([[1, 1], [2, 4]], self.dungeon_level)

		#get a random number of monsters
		number_of_monsters = randint(0, max_monsters_per_room)
		number_of_items = randint(0, max_items_per_room)

		monster_chances = {
			'orc': 80,
			'troll':from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level)
		}

		item_chances = {
			'healing_potion': 35,
			'lightning_scroll': from_dungeon_level([[25, 4]], self.dungeon_level),
			'fireball_scroll': from_dungeon_level([[25, 6]], self.dungeon_level),
			'confusion_scroll': from_dungeon_level([[10, 2]], self.dungeon_level)
		}

		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)

			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 == 'orc':
					fighter_component = Fighter(hp=20, defense=0, power=4, xp=35)
					ai_component = BasicMonster()

					monster = Entity(x, y, 'o', libtcod.desaturated_green, 'Orc', blocks=True, render_order=RenderOrder.ACTOR,
									fighter=fighter_component, ai=ai_component)
				else:
					fighter_component = Fighter(hp=30, defense=2, power=8, xp=100)
					ai_component = BasicMonster()

					monster = Entity(x, y, 'T', libtcod.darker_green, 'Troll', blocks=True, 
									fighter=fighter_component, render_order=RenderOrder.ACTOR, 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 == '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 canc el.', 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 == 'confuction_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)	
				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)