Have actions YAML-SQL but still need to do actions_traits

bradl/monsters-adult-gold-dragon
James Miller 2019-11-14 00:05:59 -06:00
parent f96544cf9e
commit 7d585f02f3
3 changed files with 74 additions and 3 deletions

View File

@ -12,6 +12,7 @@ actioncategory:
- abbr: CRB
page_start: 472
page_stop: 472
# NOTE: action assumes a single source entry
action:
- actioncategory: Basic
actioncost_name: Free Action
@ -51,6 +52,7 @@ action:
- Move
trigger: null
- actioncategory: Basic
actioncost_name: Free Action
descr: You wait for the right moment to act. The rest of your turn doesnt happen
yet. Instead, youre removed from the initiative order. You can return to the
initiative order as a free action triggered by the end of any other creatures
@ -125,6 +127,7 @@ action:
- Manipulate
trigger: null
- actioncategory: Basic
actioncost_name: Varies
descr: 'You invest your energy in an item with the invested trait as you don it.
This process requires 1 or more Interact actions, usually taking the same amount
of time it takes to don the item. Once youve Invested the Item, you benefit from
@ -184,6 +187,7 @@ action:
- Concentrate
trigger: null
- actioncategory: Basic
actioncost_name: Free Action
descr: You release something youre holding in your hand or hands. This might mean
dropping an item, removing one hand from your weapon while continuing to hold
it in another hand, releasing a rope suspending a chandelier, or performing a
@ -333,6 +337,7 @@ action:
trait: null
trigger: null
- actioncategory: Specialty Basic
actioncost_name: Varies
descr: You call forth the effect of an item by properly activating it. This is a
special activity that takes a variable number of actions, as listed in the items
stat block.\n\nSome items can be activated as a reaction or free action. In this
@ -423,6 +428,7 @@ action:
- Move
trigger: null
- actioncategory: Specialty Basic
actioncost_name: Varies
descr: "You cast a spell you have prepared or in your repertoire. Casting a Spell
is a special activity that takes a variable number of actions depending on the
spell, as listed in each spells stat block. As soon as the spellcasting actions

View File

@ -25,8 +25,6 @@ abilityscore:
short_name: Free2
long_name: Free 2
actioncost:
- name: Varies
abbr: varies
- name: Single Action
abbr: 1
- name: Two Actions
@ -37,6 +35,8 @@ actioncost:
abbr: free
- name: Reaction
abbr: reaction
- name: Varies
abbr: varies
alignment:
- name: Lawful Good
abbr: LG

View File

@ -74,7 +74,72 @@ def main():
def do_actions(data, conn):
do_action_categories(data, conn)
pass
do_action_main(data, conn)
def do_action_main(data, conn):
table = """
CREATE TABLE action (
action_id INTEGER PRIMARY KEY,
sourceentry_id INTEGER,
actioncategory_id INTEGER NOT NULL,
actioncost_id INTEGER,
name TEXT NOT NULL UNIQUE,
req TEXT,
trigger TEXT,
descr TEXT NOT NULL,
FOREIGN KEY (actioncategory_id) REFERENCES actioncategory(actioncategory_id),
FOREIGN KEY (actioncost_id) REFERENCES actioncost(actioncost_id),
FOREIGN KEY (sourceentry_id) REFERENCES sourceentry(sourceentry_id)
);
"""
c = conn.cursor()
c.execute(table)
# print(data)
for i in data['action']:
# print(i)
srcentrydata = []
for j in i['source']:
abbr = j['abbr']
page_start = j['page_start']
# Not all YAML entries have page_stop data
if 'page_stop' in j:
page_stop = j['page_stop']
else:
page_stop = page_start
srcentrydata.append((abbr, page_start, page_stop))
# need to insert sourceentry data first but check and make sure the
# length is only one
if len(srcentrydata) != 1:
raise AssertionError(
'length of srcentrydata should only be 1, no more no less, on action'
)
# print("length of srcentrydata:{}\tsrcentrydata:{}".format(len(srcentrydata),srcentrydata))
util_insert_into_sourceentry(srcentrydata, conn)
stmt = """
INSERT INTO action(name, descr, req, trigger, actioncategory_id, actioncost_id, sourceentry_id)
VALUES (?,?,?,?,
(SELECT actioncategory_id FROM actioncategory WHERE name=?),
(SELECT actioncost_id from actioncost WHERE name=?),
(SELECT sourceentry_id FROM sourceentry
WHERE source_id=(SELECT source_id FROM source WHERE abbr=?)
AND page_start=?
AND page_stop=?
)
);
"""
print('executing on name:{}'.format(i['name']))
try:
conn.execute(
stmt,
(i['name'], i['descr'],i['req'],i['trigger'],i['actioncategory'],i['actioncost_name'], srcentrydata[0][0],
srcentrydata[0][1], srcentrydata[0][2]))
except Exception as e:
print("Error creating action: {}".format(e))
else:
conn.commit()
def do_action_categories(data, conn):
table = """