示例#1
0
def add_spell_list(curs, curs_list, struct):
	if not struct['type'] == 'spell_list':
		raise Exception("This should only be run on spell list files")
	if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"):
		struct['class'] = "Sorcerer"
		add_spell_list(curs, curs_list, struct)
		struct['class'] = "Wizard"
		add_spell_list(curs, curs_list, struct)
		return
	struct = fix_spell_list(struct)
	level = struct['level']
	class_name = cap_words(struct['class'])
	for sp in struct['spells']:
		name = cap_words(sp['name'].strip())
		find_section(curs, name=name, type='spell')
		spell = curs.fetchone()
		use_curs = curs
		if not spell:
			for c in curs_list:
				find_section(c, name=name, type='spell')
				spell = c.fetchone()
				use_curs = c
				if spell:
					break
		if not spell:
			raise Exception("Cannot find spell %s" % name)
		do_add_spell_list(use_curs, spell, sp, class_name, level)
示例#2
0
def add_spell_list(curs, struct):
	if not struct['type'] == 'spell_list':
		raise Exception("This should only be run on spell list files")
	if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"):
		struct['class'] = "Sorcerer"
		add_spell_list(curs, struct)
		struct['class'] = "Wizard"
		add_spell_list(curs, struct)
		return
	struct = fix_spell_list(struct)
	level = struct['level']
	class_name = cap_words(struct['class'])
	for sp in struct['spells']:
		name = cap_words(sp['name'].strip())
		find_section(curs, name=name, type='spell')
		spell = curs.fetchone()
		if not spell:
			raise Exception("Cannot find spell %s" % name)
		fetch_spell_lists(curs, spell['section_id'], class_name=class_name)
		if not curs.fetchone():
			magic_type = find_magic_type(class_name.lower())
			insert_spell_list(curs, spell['section_id'], level, class_name, magic_type)
			fix_spell_level_text(curs, spell['section_id'])
		if sp.has_key('description'):
			update_section(curs, spell['section_id'], description=sp['description'])
示例#3
0
def add_spell_list(curs, struct):
	if not struct['type'] == 'spell_list':
		raise Exception("This should only be run on spell list files")
	if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"):
		struct['class'] = "Sorcerer"
		add_spell_list(curs, struct)
		struct['class'] = "Wizard"
		add_spell_list(curs, struct)
		return
	struct = fix_spell_list(struct)
	level = struct['level']
	class_name = cap_words(struct['class'])
	for sp in struct['spells']:
		name = cap_words(sp['name'].strip())
		find_section(curs, name=name, type='spell')
		spell = curs.fetchone()
		if not spell:
			raise Exception("Cannot find spell %s" % name)
		fetch_spell_lists(curs, spell['section_id'], class_name=class_name)
		if not curs.fetchone():
			magic_type = find_magic_type(class_name.lower())
			insert_spell_list(curs, spell['section_id'], level, class_name, magic_type)
			fix_spell_level_text(curs, spell['section_id'])
		if sp.has_key('description'):
			update_section(curs, spell['section_id'], description=sp['description'])
示例#4
0
def add_spell_list(curs, curs_list, struct):
	if not struct['type'] == 'spell_list':
		raise Exception("This should only be run on spell list files")
	if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"):
		struct['class'] = "Sorcerer"
		add_spell_list(curs, curs_list, struct)
		struct['class'] = "Wizard"
		add_spell_list(curs, curs_list, struct)
		return
	struct = fix_spell_list(struct)
	level = struct['level']
	class_name = cap_words(struct['class'])
	for sp in struct['spells']:
		name = cap_words(sp['name'].strip())
		find_section(curs, name=name, type='spell')
		spell = curs.fetchone()
		use_curs = curs
		if not spell:
			for c in curs_list:
				find_section(c, name=name, type='spell')
				spell = c.fetchone()
				use_curs = c
				if spell:
					break
		if not spell:
			raise Exception("Cannot find spell %s" % name)
		do_add_spell_list(use_curs, spell, sp, class_name, level)
示例#5
0
def parent_pass_in_file(struct):
	parent = struct['sections'][0]
	for spell in struct['sections']:
		if spell != parent:
			spell['parent'] = cap_words(parent['name'])
		if spell['name'].find(",") > -1:
			parts = spell['name'].split(",")
			spell['parent'] = cap_words(parts[0].strip())
示例#6
0
def parent_pass_in_file(struct):
	parent = struct['sections'][0]
	for spell in struct['sections']:
		if spell != parent:
			spell['parent'] = cap_words(parent['name'])
		if spell['name'].find(",") > -1:
			parts = spell['name'].split(",")
			spell['parent'] = cap_words(parts[0].strip())
示例#7
0
def spell_list_pass(cl):
    field_dict = {
        "Alchemist": "Alchemist Formulae",
        "Inquisitor": "Inquisitor Spells",
        "Witch": "Witch Spells",
        "Summoner": "Summoner Spells",
        "Magus": "Magus Spell List"
    }
    if cl['name'] in field_dict.keys():
        name = field_dict[cl['name']]
        sl = find_section(cl, name=name, section_type='section')
        sections = sl['sections']
        for section in sections:
            section['type'] = 'spell_list'
            section['class'] = cl['name']
            m = re.search('(\d)', section['name'])
            section['level'] = int(m.group(0))
            soup = BeautifulSoup(section['text'])
            text = ''.join(soup.findAll(text=True))
            text = text.replace('—', '')
            text = text.replace('*', '')
            text = text.replace('.', '')
            del section['text']
            spells = []
            section['spells'] = spells
            for spell_name in text.split(", "):
                spell_name = spell_name.strip()
                spell_name = cap_words(spell_name)
                spell_name = spell_name.replace(" (Mass)", ", Mass")
                spell_name = spell_name.replace(" (Greater)", ", Greater")
                spell_name = spell_name.replace(" (Lesser)", ", Lesser")
                spell_name = spell_name.replace("Topoison", "To Poison")
                spells.append({"name": spell_name})
    return cl
示例#8
0
def insert_spell_records(curs, section_id, spell):
	if spell.has_key('parent'):
		orig = fetch_complete_spell(curs, spell['parent'])
		if not orig:
			raise ProcessLastException(spell['parent'])
		spell = merge_spells(orig, spell)
	descriptor_text = ', '.join(spell.get('descriptor', []))
	if descriptor_text == "":
		descriptor_text = None
	else:
		spell['descriptor_text'] = descriptor_text
	level_list = []
	for level in spell.get('level', []):
		level_list.append(level['class'] + ": " + str(level['level']))
	level_text = "; ".join(level_list)
	spell['level_text'] = level_text
	insert_spell_detail(curs, **spell)
	for descriptor in spell.get('descriptor', []):
		insert_spell_descriptor(curs, section_id, descriptor)
	for level in spell.get('level', []):
		magic_type = find_magic_type(level['class'])
		insert_spell_list(curs, section_id, level['level'], cap_words(level['class']), magic_type)
	for component in spell.get('components', []):
		insert_spell_component(curs, section_id, component.get('type'), component.get('text'), 0)
	for effect in spell.get('effects', []):
		insert_spell_effect(curs, section_id, effect['name'], effect['text'])
示例#9
0
def insert_spell_records(curs, section_id, spell):
	if spell.has_key('parent'):
		orig = fetch_complete_spell(curs, spell['parent'])
		if not orig:
			raise ProcessLastException(spell['parent'])
		spell = merge_spells(orig, spell)
	descriptor_text = ', '.join(spell.get('descriptor', []))
	if descriptor_text == "":
		descriptor_text = None
	else:
		spell['descriptor_text'] = descriptor_text
	level_list = []
	for level in spell.get('level', []):
		level_list.append(level['class'] + ": " + str(level['level']))
	level_text = "; ".join(level_list)
	spell['level_text'] = level_text
	insert_spell_detail(curs, **spell)
	for descriptor in spell.get('descriptor', []):
		insert_spell_descriptor(curs, section_id, descriptor)
	for level in spell.get('level', []):
		magic_type = find_magic_type(level['class'])
		insert_spell_list(curs, section_id, level['level'], cap_words(level['class']), magic_type)
	for component in spell.get('components', []):
		insert_spell_component(curs, section_id, component['type'], component.get('text'), 0)
	for effect in spell.get('effects', []):
		insert_spell_effect(curs, section_id, effect['name'], effect['text'])
示例#10
0
def spell_list_pass(cl):
    field_dict = {
        "Alchemist": "Alchemist Formulae",
        "Inquisitor": "Inquisitor Spells",
        "Witch": "Witch Spells",
        "Summoner": "Summoner Spells",
        "Magus": "Magus Spell List",
    }
    if cl["name"] in field_dict.keys():
        name = field_dict[cl["name"]]
        sl = find_section(cl, name=name, section_type="section")
        sections = sl["sections"]
        for section in sections:
            section["type"] = "spell_list"
            section["class"] = cl["name"]
            m = re.search("(\d)", section["name"])
            section["level"] = int(m.group(0))
            soup = BeautifulSoup(section["text"])
            text = "".join(soup.findAll(text=True))
            text = text.replace("—", "")
            text = text.replace("*", "")
            text = text.replace(".", "")
            del section["text"]
            spells = []
            section["spells"] = spells
            for spell_name in text.split(", "):
                spell_name = spell_name.strip()
                spell_name = cap_words(spell_name)
                spell_name = spell_name.replace(" (Mass)", ", Mass")
                spell_name = spell_name.replace(" (Greater)", ", Greater")
                spell_name = spell_name.replace(" (Lesser)", ", Lesser")
                spell_name = spell_name.replace("Topoison", "To Poison")
                spells.append({"name": spell_name})
    return cl
示例#11
0
def spell_list_pass(cl):
	field_dict = {
		"Alchemist": "Alchemist Formulae",
		"Inquisitor": "Inquisitor Spells",
		"Witch": "Witch Spells",
		"Summoner": "Summoner Spells",
		"Magus": "Magus Spell List"
	}
	if cl['name'] in field_dict.keys():
		name = field_dict[cl['name']]
		sl = find_section(cl, name=name, section_type='section')
		sections = sl['sections']
		for section in sections:
			section['type'] = 'spell_list'
			section['class'] = cl['name']
			m = re.search('(\d)', section['name'])
			section['level'] = int(m.group(0))
			soup = BeautifulSoup(section['text'])
			text = ''.join(soup.findAll(text=True))
			text = text.replace('—', '')
			text = text.replace('*', '')
			text = text.replace('.', '')
			del section['text']
			spells = []
			section['spells'] = spells
			for spell_name in text.split(", "):
				spell_name = spell_name.strip()
				spell_name = cap_words(spell_name)
				spell_name = spell_name.replace(" (Mass)", ", Mass")
				spell_name = spell_name.replace(" (Greater)", ", Greater")
				spell_name = spell_name.replace(" (Lesser)", ", Lesser")
				spell_name = spell_name.replace("Topoison", "To Poison")
				spells.append({"name": spell_name})
	return cl
示例#12
0
def insert_spell_records(curs, curs_list, section_id, spell):
	if spell.has_key('parent'):
		orig = fetch_complete_spell(curs, spell['parent'])
		if not orig:
			# Need to handle case where spell is in a previous book
			for c in curs_list:
				orig = fetch_complete_spell(c, spell['parent'])
				if orig:
					break
		if not orig:
			raise ProcessLastException(spell['parent'])
		spell = merge_spells(orig, spell)
	descriptor_text = ', '.join(spell.get('descriptor', []))
	if descriptor_text == "":
		descriptor_text = None
	else:
		spell['descriptor_text'] = descriptor_text
	level_list = []
	for level in spell.get('level', []):
		level_list.append(level['class'] + ": " + str(level['level']))
	level_text = "; ".join(level_list)
	spell['level_text'] = level_text
	insert_spell_detail(curs, **spell)
	if spell.has_key('subschool') and spell['subschool']:
		for subschool in subschool_list(spell['subschool']):
			insert_spell_subschool(curs, section_id, subschool)
	for descriptor in filter_descriptors(spell.get('descriptor', [])):
		insert_spell_descriptor(curs, section_id, descriptor)
	for level in spell.get('level', []):
		magic_type = find_magic_type(level['class'])
		insert_spell_list(curs, section_id, level['level'], cap_words(level['class']), magic_type)
	for component in spell.get('components', []):
		insert_spell_component(curs, section_id, component.get('type'), component.get('text'), 0)
	for effect in spell.get('effects', []):
		insert_spell_effect(curs, section_id, effect['name'], effect['text'])
示例#13
0
def parse_creature_descriptor(creature, value):
	print "%s: %s" %(creature, value)
	if value.startswith('AC'):
		default_closure('ac')(creature, value[2:])
		return
	bsb = None
	if value.find('(but see below) ') > -1:
		value = value.replace('(but see below) ', '')
		bsb = " (but see below)"
	any_al = None
	if value.find('Any alignment (same as creator)') > -1:
		any_al = 'Any alignment (same as creator)'
		value = value.replace(any_al, 'Any')
	descsplit = value.split("(")
	if len(descsplit) > 1:
		value = descsplit.pop(0)
		subtype = ''.join(descsplit)
		subtype = subtype.replace(')', '')
		creature['creature_subtype'] = subtype
	values = value.split()
	if len(values) == 2:
		creature['alignment'] = values.pop(0)
		creature['creature_type'] = cap_words(values.pop(0))
	elif len(values) >= 3:
		creature['alignment'] = values.pop(0)
		if any_al:
			creature['alignment'] = any_al
		if values[0] == 'alignment':
			creature['alignment'] = creature['alignment'] + " " + values.pop(0)
		if bsb:
			creature['alignment'] = creature['alignment'] + bsb
		if values[0] == 'or':
			alignment = creature['alignment']
			alignment = alignment + " " + values.pop(0)
			alignment = alignment + " " + values.pop(0)
			creature['alignment'] = alignment
		creature['size'] = values.pop(0)
		creature['creature_type'] = cap_words(values.pop(0))
	if len(values) > 0:
		if values[0] in ['beast', 'humanoid']:
			creature['creature_type'] = creature['creature_type'] + \
				" " + cap_words(values.pop(0))
	if len(values) > 0:
		raise Exception('well f**k: %s' %(values))
示例#14
0
def parse_creature_descriptor(creature, value):
    if value.startswith('AC'):
        default_closure('ac')(creature, value[2:])
        return
    bsb = None
    if value.find('(but see below) ') > -1:
        value = value.replace('(but see below) ', '')
        bsb = " (but see below)"
    any_al = None
    if value.find('Any alignment (same as creator)') > -1:
        any_al = 'Any alignment (same as creator)'
        value = value.replace(any_al, 'Any')
    descsplit = value.split("(")
    if len(descsplit) > 1:
        value = descsplit.pop(0)
        subtype = ''.join(descsplit)
        subtype = subtype.replace(')', '')
        creature['creature_subtype'] = subtype
    values = value.split()
    if len(values) == 2:
        creature['alignment'] = values.pop(0)
        creature['creature_type'] = cap_words(values.pop(0))
    elif len(values) >= 3:
        creature['alignment'] = values.pop(0)
        if any_al:
            creature['alignment'] = any_al
        if values[0] == 'alignment':
            creature['alignment'] = creature['alignment'] + " " + values.pop(0)
        if bsb:
            creature['alignment'] = creature['alignment'] + bsb
        if values[0] == 'or':
            alignment = creature['alignment']
            alignment = alignment + " " + values.pop(0)
            alignment = alignment + " " + values.pop(0)
            creature['alignment'] = alignment
        creature['size'] = values.pop(0)
        creature['creature_type'] = cap_words(values.pop(0))
    if len(values) > 0:
        if values[0] in ['beast', 'humanoid']:
            creature[
                'creature_type'] = creature['creature_type'] + " " + cap_words(
                    values.pop(0))
    if len(values) > 0:
        raise Exception('well f**k: %s' % (values))
示例#15
0
def add_spell_list(curs, curs_list, struct):
	if not struct['type'] == 'spell_list':
		raise Exception("This should only be run on spell list files")
	if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"):
		struct['class'] = "Sorcerer"
		add_spell_list(curs, curs_list, struct)
		struct['class'] = "Wizard"
		add_spell_list(curs, curs_list, struct)
		return
	struct = fix_spell_list(struct)
	level = struct['level']
	class_name = cap_words(struct['class'])
	for sp in struct['spells']:
		spell, use_curs = find_spell_in_books(sp['name'], curs, curs_list)
		do_add_spell_list(use_curs, spell, sp.get('description'), "class", class_name, level, None)
示例#16
0
def insert_mythic_spell_records(curs, curs_list, section_id, mythic_spell):
	name = cap_words(mythic_spell['spell_source'].strip())
	find_section(curs, name=name, type='spell')
	spell = curs.fetchone()
	use_curs = curs
	if not spell:
		for c in curs_list:
			find_section(c, name=name, type='spell')
			spell = c.fetchone()
			use_curs = c
			if spell:
				mythic_spell['spell_source'] = spell['name']
				break
	if not spell:
		raise Exception("Cannot find spell %s" % name)
	insert_mythic_spell_detail(curs, **mythic_spell)
示例#17
0
def find_spell_in_books(spell_name, curs, curs_list):
	name = cap_words(spell_name.strip())
	find_section(curs, name=name, type='spell')
	spell = curs.fetchone()
	use_curs = curs
	if spell:
		return spell, use_curs
	else:
		for c in curs_list:
			find_section(c, name=name, type='spell')
			spell = c.fetchone()
			use_curs = c
			if spell:
				return spell, use_curs
	if not spell:
		raise Exception("Cannot find spell %s" % name)
示例#18
0
def insert_mythic_spell_records(curs, curs_list, section_id, mythic_spell):
    name = cap_words(mythic_spell['spell_source'].strip())
    find_section(curs, name=name, type='spell')
    spell = curs.fetchone()
    use_curs = curs
    if not spell:
        for c in curs_list:
            find_section(c, name=name, type='spell')
            spell = c.fetchone()
            use_curs = c
            if spell:
                mythic_spell['spell_source'] = spell['name']
                break
    if not spell:
        raise Exception("Cannot find spell %s" % name)
    insert_mythic_spell_detail(curs, **mythic_spell)
示例#19
0
def add_spell_list(curs, curs_list, struct):
    if not struct['type'] == 'spell_list':
        raise Exception("This should only be run on spell list files")
    if struct['class'] in ("Sorcerer/wizard", "Sorcerer/Wizard"):
        struct['class'] = "Sorcerer"
        add_spell_list(curs, curs_list, struct)
        struct['class'] = "Wizard"
        add_spell_list(curs, curs_list, struct)
        return
    struct = fix_spell_list(struct)
    level = struct['level']
    class_name = cap_words(struct['class'])
    for sp in struct['spells']:
        spell, use_curs = find_spell_in_books(sp['name'], curs, curs_list)
        do_add_spell_list(use_curs, spell, sp.get('description'), "class",
                          class_name, level, None)
示例#20
0
def find_spell_in_books(spell_name, curs, curs_list):
    name = cap_words(spell_name.strip())
    find_section(curs, name=name, type='spell')
    spell = curs.fetchone()
    use_curs = curs
    if spell:
        return spell, use_curs
    else:
        for c in curs_list:
            find_section(c, name=name, type='spell')
            spell = c.fetchone()
            use_curs = c
            if spell:
                return spell, use_curs
    if not spell:
        raise Exception("Cannot find spell %s" % name)
示例#21
0
def parent_pass_out_of_file(spell):
	if spell['name'].find(",") > -1:
		parts = spell['name'].split(",")
		spell['parent'] = cap_words(parts[0].strip())
示例#22
0
def parent_pass_out_of_file(spell):
	if spell['name'].find(",") > -1:
		parts = spell['name'].split(",")
		spell['parent'] = cap_words(parts[0].strip())
示例#23
0
def cap_pass(spell):
	spell['name'] = cap_words(spell['name'])
	if not spell.has_key('level'):
		print "WTF: level %s %s" % (spell['name'], spell.keys())
	for level in spell.get('level', []):
		level['class'] = cap_words(level['class'])
示例#24
0
def cap_pass(spell):
	spell['name'] = cap_words(spell['name'])
	if not spell.has_key('level') and spell['type'] == 'spell':
		print "WTF: level %s %s" % (spell['name'], spell.keys())
	for level in spell.get('level', []):
		level['class'] = cap_words(level['class'])