def test_get_monster_sets(): mm = MonsterManual() sets = mm.get_monster_sets(any_tags=['evil', 'forest'], all_tags=['humanoid'], none_tags=['human']) desired = ['forest goblins', 'yuan-ti', 'gnolls', 'drow'] undesired = ['bandits', 'cult of obox-ob', 'blights', 'bullywugs'] assert all([set_ in sets for set_ in desired]) assert not any(set_ in sets for set_ in undesired)
def test_exclude_monster_set_by_tags(): mm = MonsterManual() desired_tags = ['dungeon-explorer'] sets = mm.get_monster_set_by_tags(desired_tags, any_or_all=any) assert ('goblins' in sets) assert ('cult of baphomet' in sets) undesired_tags = ['human'] sets = mm.get_monster_set_by_tags(undesired_tags, monster_sets=sets, any_or_all=any, exclude=True) assert ('goblins' in sets) assert ('cult of baphomet' not in sets)
def __init__(self, level, terrain, history, tags, random_state=None): self.level = level self.terrain = terrain self.history = history self.tags = history + [terrain] + tags self.other_features = {} if random_state is None: self.random_state = Random() else: self.random_state = random_state possible_features = terrain_features[terrain] for era in self.history: possible_features += history_features[era] self.features = self.random_state.sample(possible_features, 3) possible_places = [ place for place in places if self.possible_place(place) ] n = self.random_state.randint(2, 3) self.monster_manual = MonsterManual(terrain=self.terrain) self.places = [ self.make_place(place) for place in self.random_state.sample(possible_places, n) ] if self.random_state.randint(1, 6) >= 5: self.other_features['NPC'] = NPC( random_state=self.random_state).details()
def __init__(self, terrain=None, all_tags=None, none_tags=None, any_tags=None, level=None, monster_set=None): self.mm = MonsterManual(terrain=terrain) if monster_set is None: sets = self.mm.get_monster_sets(all_tags=all_tags, none_tags=none_tags, any_tags=any_tags, level=level) monster_set = random.choice(sets) self.monster_set = monster_set self.source = EncounterSource(encounter_level=level, monster_sets=[self.monster_set])
def __init__(self, level, layout, terrain=None, random_state=None): if random_state is None: self.random_state = Random() else: self.random_state = random_state self.level = level self.layout = layout self.encounter_sources = {} self.encounters = {} self.signs = {} treasure = RawHoardSource( level, random_state=self.random_state).get_treasure() self.treasure_manager = TreasureManager(treasure, random_state=self.random_state) self.terrain = terrain self.monster_manual = MonsterManual(terrain=terrain) self.events = [] self.name_generator = NameGenerator(random_state=self.random_state) self.wandering_monsters = {}
def add_encounter_source(self, source_name, monster_set, event_description, wandering=False): logger.debug('Adding encounter source %s (%s)' % (source_name, monster_set)) encounter_source = EncounterSource( encounter_level=self.level, monster_sets=[monster_set], supplied_monster_manual=MonsterManual(terrain=self.terrain), random_state=self.random_state) self.encounter_sources[source_name] = encounter_source self.encounters[source_name] = 0 self.signs[source_name] = [] self.add_event(source_name, event_description, monster_set, wandering=wandering)
def template_from_monster_set(self, monster_set): dummy_manager = MonsterManual() potentials = [] for bunch in template_bunches[self.base_type]: sets = [] i = 1 while len(sets) == 0 and i <= len(bunch): template = bunch[-i] sets = template( None, dummy_manager, random_state=self.random_state).get_monster_sets() if monster_set in sets: potentials.append((bunch, i)) i += 1 if len(potentials) > 0: return self.random_state.choice(potentials) else: sets = self.random_state.choice(template_bunches[self.base_type]) if sets[-1] == ExplorerTemplate: return (sets, 1) else: return (sets + [ExplorerTemplate], 1)
class PlacePopulator: def __init__(self, terrain=None, all_tags=None, none_tags=None, any_tags=None, level=None, monster_set=None): self.mm = MonsterManual(terrain=terrain) if monster_set is None: sets = self.mm.get_monster_sets(all_tags=all_tags, none_tags=none_tags, any_tags=any_tags, level=level) monster_set = random.choice(sets) self.monster_set = monster_set self.source = EncounterSource(encounter_level=level, monster_sets=[self.monster_set]) def apply(self, graph): for node, data in graph.nodes(data=True): if random.randint(1, 6) >= 5: data["signs"] = self.source.get_sign() data["encounter"] = self.source.get_encounter()
def use_real_monster_manual(): global monster_manual monster_manual = MonsterManual()
def test_get_monster_set_level(): mm = MonsterManual()
class DungeonManager: def __init__(self, level, layout, terrain=None, random_state=None): if random_state is None: self.random_state = Random() else: self.random_state = random_state self.level = level self.layout = layout self.encounter_sources = {} self.encounters = {} self.signs = {} treasure = RawHoardSource( level, random_state=self.random_state).get_treasure() self.treasure_manager = TreasureManager(treasure, random_state=self.random_state) self.terrain = terrain self.monster_manual = MonsterManual(terrain=terrain) self.events = [] self.name_generator = NameGenerator(random_state=self.random_state) self.wandering_monsters = {} def add_encounter_source(self, source_name, monster_set, event_description, wandering=False): logger.debug('Adding encounter source %s (%s)' % (source_name, monster_set)) encounter_source = EncounterSource( encounter_level=self.level, monster_sets=[monster_set], supplied_monster_manual=MonsterManual(terrain=self.terrain), random_state=self.random_state) self.encounter_sources[source_name] = encounter_source self.encounters[source_name] = 0 self.signs[source_name] = [] self.add_event(source_name, event_description, monster_set, wandering=wandering) def add_special_encounter_source(self, source_name, encounter_source): logger.debug('Adding special encounter source %s' % (source_name)) self.encounter_sources[source_name] = encounter_source self.encounters[source_name] = 0 self.signs[source_name] = [] def add_event(self, source_name, description, monster_set, wandering=False): logger.debug('Adding event for source %s (%s)' % (source_name, monster_set)) event = { 'event': description, 'monster_set': monster_set, 'source_name': source_name } self.events.append(event) if wandering: self.wandering_monsters[source_name] = monster_set def get_encounter(self, source_name, **kwargs): logger.debug('Getting encouter from encounter source %s' % (source_name)) encounter = self.encounter_sources[source_name].get_encounter(**kwargs) if encounter.get('success'): self.encounters[source_name] += 1 encounter['source name'] = source_name return encounter else: return None def delete_encounter(self, encounter): logger.debug('Deleting encouter from encounter source %s' % (encounter.get('source name'))) source_name = encounter.get('source name') self.encounters[source_name] -= 1 def get_sign(self, source_name): logger.debug('Getting sign from encounter source %s' % (source_name)) sign = Sign(self.encounter_sources[source_name].get_sign()) self.signs[source_name].append(sign) return sign def delete_signs(self, source_name): logger.debug('Deleting sign from encounter source %s' % (source_name)) for sign in self.signs[source_name]: sign.delete() def __enter__(self, *args): return self def get_treasure(self, shares=1): return self.treasure_manager.get_treasure(shares) def delete_treasure(self, treasure_to_delete): self.treasure_manager.delete_treasure(treasure_to_delete) def get_monster_sets(self, **kwargs): return self.monster_manual.get_monster_sets(**kwargs) def parse_event(self, event): text = event['event'] monster_set = event['monster_set'] return f'{text}: ({monster_set})' def __exit__(self, eType, eValue, eTrace): logger.debug('Exiting dungeon manager') for source_name in self.encounter_sources: if self.encounters[source_name] == 0: self.delete_signs(source_name) wandering = [] for source_name, set_name in self.wandering_monsters.items(): if self.encounters[source_name] > 0: wandering.append(set_name) self.layout.wandering_monster_table = WanderingMonsters( self.level, wandering, random_state=self.random_state).table self.layout.name = self.name_generator.dungeon_name( self.layout.purpose, terrain=self.terrain) self.layout.terrain = self.terrain self.layout.events = [ self.parse_event(event) for event in self.events if event['source_name'] == 'special' or self.encounters[event['source_name']] > 0 ] self.layout.level = self.level
def test_get_monster_set_by_tags(): mm = MonsterManual() tags = ['savage', 'dungeon-explorer'] sets = mm.get_monster_set_by_tags(tags, any_or_all=all) desired = ['bugbears', 'orcs', 'goblins', 'gnolls', 'kobolds'] assert all(set_ in sets for set_ in desired)
def new_monster_manual(terrain): global monster_manual monster_manual = MonsterManual(terrain)
from monster_manual.monster_manual import MonsterManual from tests.mocks.mock_monster_list import MockMonsterManual monster_manual = MonsterManual() def use_mock_monster_manual(): global monster_manual monster_manual = MockMonsterManual() def use_real_monster_manual(): global monster_manual monster_manual = MonsterManual() def new_monster_manual(terrain): global monster_manual monster_manual = MonsterManual(terrain)
def test_appropriate_level(): mm = MonsterManual()
def test_get_tags(): mm = MonsterManual()
def test_specify_terrain(): mm = MonsterManual(terrain='forest')
def test_get_sings(): mm = MonsterManual()