Exemplo n.º 1
0
def handle_creature(conn, section):
	curs = conn.cursor()
	try:
		fetch_creature_detail(curs, section['section_id'])
		detail = curs.fetchone()
		if detail:
			del detail['creature_details_id']
			del detail['section_id']
			section.update(detail)
		fetch_creature_spells(curs, section['section_id'])
		spells = []
		for spell in curs.fetchall():
			spells.append({spell['name']: spell['body']})
		if len(spells) > 0:
			section['spells'] = spells
	finally:
		curs.close()
Exemplo n.º 2
0
def handle_creature(conn, section):
    curs = conn.cursor()
    try:
        fetch_creature_detail(curs, section['section_id'])
        detail = curs.fetchone()
        if detail:
            del detail['creature_details_id']
            del detail['section_id']
            section.update(detail)
        fetch_creature_spells(curs, section['section_id'])
        spells = []
        for spell in curs.fetchall():
            spells.append({spell['name']: spell['body']})
        if len(spells) > 0:
            section['spells'] = spells
    finally:
        curs.close()
Exemplo n.º 3
0
    def test_gen_spells(self):
        counter = 0
        for creature in self.fetch_creatures():
            #print creature
            fetch_creature_spells(self.curs, creature['section_id'])
            creature_spells = self.curs.fetchall()
            #print creature_spells
            for spell in creature_spells:
                self.assertTrue('name' in spell, spell)
                self.assertTrue('body' in spell, spell)
            spells = gen_spells(creature_spells)
            #print spells
            for spell in creature_spells:
                self.assertTrue('name' not in spell, spell)
                self.assertTrue('body' not in spell, spell)
            counter += 1

        self.assertTrue(counter >= 966, counter)
	def test_gen_spells(self):
		counter = 0
		for creature in self.fetch_creatures():
			#print creature
			fetch_creature_spells(self.curs, creature['section_id'])
			creature_spells = self.curs.fetchall()
			#print creature_spells
			for spell in creature_spells:
				self.assertTrue('name' in spell, spell)
				self.assertTrue('body' in spell, spell)
			spells = gen_spells(creature_spells)
			#print spells
			for spell in creature_spells:
				self.assertTrue('name' not in spell, spell)
				self.assertTrue('body' not in spell, spell)
			counter += 1

		self.assertTrue(counter >= 966, counter)
Exemplo n.º 5
0
def output_creature(conn, creature_name):
	curs = conn.cursor()

	find_section(curs, name=creature_name)
	creatures = curs.fetchall()
	assert len(creatures) == 1
	creature = creatures[0]
	assert creature['type'] == 'creature'
	#pprint.pprint(creature)

	fetch_creature_detail(curs, creature['section_id'])
	creature_details = curs.fetchone()
	#pprint.pprint(creature_details)

	fetch_creature_spells(curs, creature['section_id'])
	creature_spells = curs.fetchall()
	#pprint.pprint(creature_spells)

	data = {}
	#	META
	data['source'] = gen_source(creature)
	data['url'] = gen_url(creature)
	data['name'] = gen_name(creature)
	data['description'] = gen_description(creature)
	#	BASE
	data['cr'] = gen_cr(creature_details)
	data['xp'] = gen_xp(creature_details)
	data['sex'] = gen_sex(creature_details)
	data['super_race'] = gen_super_race(creature_details)
	data['level'] = gen_level(creature_details)
	data['alignment'] = gen_alignment(creature_details)
	data['size'] = gen_size(creature_details)
	data['hit_dice'] = gen_hit_dice(creature_details)
	data['creature_type'] = gen_creature_type(creature_details)
	data['creature_subtype'] = gen_creature_subtype(creature_details)
	data['init'] = gen_init(creature_details)
	data['senses'] = gen_senses(creature_details)
	data['aura'] = gen_aura(creature_details)
	#	DEFENSE
	data['ac'] = gen_ac(creature_details)
	data['hp'] = gen_hp(creature_details)
	data['saves'] = {}
	data['saves']['fortitude'] = gen_fortitude(creature_details)
	data['saves']['reflex'] = gen_reflex(creature_details)
	data['saves']['will'] = gen_will(creature_details)
	data['defensive_abilities'] = gen_defensive_abilities(creature_details)
	data['dr'] = gen_dr(creature_details)
	data['immune'] = gen_immune(creature_details)
	data['weaknesses'] = gen_weaknesses(creature_details)
	data['sr'] = gen_sr(creature_details)
	data['natural_armor'] = gen_natural_armor(creature_details)
	data['resist'] = gen_resist(creature_details)
	#	OFFENSE
	data['speed'] = gen_speed(creature_details)
	data['melee'] = gen_melee(creature_details)
	data['ranged'] = gen_ranged(creature_details)
	data['breath_weapon'] = gen_breath_weapon(creature_details)
	data['space'] = gen_space(creature_details)
	data['reach'] = gen_reach(creature_details)
	data['special_attacks'] = gen_special_attacks(creature_details)
	data['spells'] = gen_spells(creature_spells)
	#	STATISTICS
	data['abilities'] = {}
	data['abilities']['strength'] = gen_strength(creature_details)
	data['abilities']['dexterity'] = gen_dexterity(creature_details)
	data['abilities']['constitution'] = gen_constitution(creature_details)
	data['abilities']['intelligence'] = gen_intelligence(creature_details)
	data['abilities']['wisdom'] = gen_wisdom(creature_details)
	data['abilities']['charisma'] = gen_charisma(creature_details)
	data['base_attack'] = gen_base_attack(creature_details)
	data['cmb'] = gen_cmb(creature_details)
	data['cmd'] = gen_cmd(creature_details)
	data['feats'] = gen_feats(creature_details)
	data['skills'] = gen_skills(creature_details)
	data['racial_modifiers'] = gen_racial_modifiers(creature_details)
	data['languages'] = gen_languages(creature_details)
	data['special_qualities'] = gen_special_qualities(creature_details)
	data['gear'] = gen_gear(creature_details)
	#	ECOLOGY
	data['environment'] = gen_environment(creature_details)
	data['organization'] = gen_organization(creature_details)
	data['treasure'] = gen_treasure(creature_details)
	#	SPECIAL ABILITIES
	# TODO
	#	TEXT
	# TODO

	del creature['create_index']
	del creature['lft']
	del creature['parent_id']
	del creature['rgt']
	del creature['section_id']
	del creature['abbrev'] # is null for all the creatures we have in the database
	del creature['alt'] # is null for all the creatures we have in the database
	del creature['body'] # only has value for seven creatures; what should we do with it?
	# sqlite> select name, body from sections where type = 'creature' and body is not  null;
	# Swarm, Bat|<StatBlockSection Special Features [(u'Wounding (Ex)', u'Any living creature damaged by a bat swarm continues to bleed, losing 1 hit point per round thereafter. Multiple wounds do not result in cumulative bleeding loss. The bleeding can be stopped by a DC 10 Heal check or the application of a cure spell or some other healing magic.')]>
	# Bat, Mobat|<p>XP 800	</p>
	# Blindheim|<p>Init +2; <b>Senses</b> darkvision 60 ft., low-light vision; <b>Perception</b> +9</p>
	# Daemon, Piscodaemon|<p><span class="char-style-override-30">XP</span> 9,600</p>
	# Daemon, Purrodaemon|<p><span class="char-style-override-30">XP</span> 153,600</p>
	# Fetchling|<p>Fetchling rogue 1</p>
	# Werebear (Hybrid Form)|<p>Human natural werebear ranger 4</p>
	del creature['image'] # is null for all the creatures we have in the database
	del creature['subtype'] # is null or familiar
	del creature['type']
	assert creature == {}

	del creature_details['creature_details_id']
	del creature_details['section_id']
	assert creature_details == {}

	for spell in creature_spells:
		del spell['creature_spells_id']
		del spell['section_id']
		assert spell == {}

	schema = json.load(open(os.path.join(CONF_DIR, 'creature_level1.json'), 'r'))
	jsonschema.validate(data, schema)

	pprint.pprint(data)