added processing of basic keywords to cardTemplateScript.py

This commit is contained in:
ArsenalNut
2012-09-30 20:59:23 +00:00
parent 0b7eca2164
commit d0f57e7410

View File

@@ -4,6 +4,7 @@ pathToMtgData = "mtg-data.txt"
############IMPLEMENTATION FOLLOWS############
import os,sys,fnmatch
import re
class Card:
def __init__(self, name):
@@ -144,8 +145,74 @@ def initSets():
# Return to Ravnica
forgeSets.append('RTR')
#forgeSets.append('GTC')
#forgeSets.append('UNK')
#forgeSets.append('UNK')
def initKeywords():
keyWords.append('Cascade')
keyWords.append('Convoke')
keyWords.append('Deathtouch')
keyWords.append('Defender')
keyWords.append('Delve')
keyWords.append('Desertwalk')
keyWords.append('Double Strike')
keyWords.append('Epic')
keyWords.append('Exalted')
keyWords.append('Fear')
keyWords.append('First Strike')
keyWords.append('Flanking')
keyWords.append('Flash')
keyWords.append('Flying')
keyWords.append('Forestwalk')
keyWords.append('Haste')
keyWords.append('Hexproof')
keyWords.append('Hideaway')
keyWords.append('Horsemanship')
keyWords.append('Indestructible')
keyWords.append('Infect')
keyWords.append('Intimidate')
keyWords.append('Islandwalk')
keyWords.append('Lifelink')
keyWords.append('Living Weapon')
keyWords.append('Mountainwalk')
keyWords.append('Persist')
keyWords.append('Phasing')
keyWords.append('Plainswalk')
keyWords.append('Provoke')
keyWords.append('Reach')
keyWords.append('Rebound')
keyWords.append('Shadow')
keyWords.append('Shroud')
keyWords.append('Soulbond')
keyWords.append('Storm')
keyWords.append('Sunburst')
keyWords.append('Swampwalk')
keyWords.append('Trample')
keyWords.append('Unblockable')
keyWords.append('Undying')
keyWords.append('Vigilance')
keyWords.append('Wither')
def handleKeyords(line,keywords):
# split line by spaces to see if first token matches a keyword
line = line.rstrip();
p = re.compile( '\s\(.*\)$')
line = p.sub('',line)
allKeywords = True
if line.find('Enchant') != -1 :
print 'K:'+line
return allKeywords
else :
# Multiple keywords could be comma seperated in mtgdata
words=line.split(', ')
for token in words :
if token.title() in keywords :
print 'K:'+token.title()
else :
allKeywords = False
return allKeywords
if not os.path.exists(pathToMtgData) :
print("This script requires the text version of Arch's mtg-data to be present.You can download it from slightlymagic.net's forum and either place the text version next to this script or edit this script and provide the path to the file at the top.")
print("Press Enter to exit")
@@ -153,6 +220,7 @@ if not os.path.exists(pathToMtgData) :
sys.exit()
forgeSets = []
keyWords = []
mtgDataCards = {}
setCodes = []
tmpName = ""
@@ -160,6 +228,7 @@ line = ""
# initialize sets supported by Forge
initSets()
initKeywords()
#Parse mtg-data
mtgdata = open(pathToMtgData,"r")
line = mtgdata.readline()
@@ -231,6 +300,7 @@ while inputName != 'quit' :
cleanName = cleanName.replace("'",'')
cleanName = cleanName.replace(',','')
cleanName = cleanName.replace(' ','_')
cleanName = cleanName.replace('-','_')
print '\nName:'+cardData.name
print 'ManaCost:'+cardData.cost
print 'Types:'+cardData.types
@@ -239,10 +309,31 @@ while inputName != 'quit' :
print 'PT:'+cardData.pt
elif cardData.types.find('Planeswalker') != -1 :
print 'Loyalty:'+cardData.pt
print "\n<Script Start>"
for text in cardData.oracle :
print text
print "<Script End>\n"
# do some prescripting
tokens = line.split(' ');
if text.find("When CARDNAME enters the battlefield") != -1 :
print "\n"+text
print "<Trigger Script Start>"
print 'T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Creature.Self | Execute$ <TriggerFunc> | TriggerDescription$ '+text
print 'SVar:<TriggerFunc>:AB$ <Added Triggered Ability HERE>'
print "<Trigger Script End>\n"
elif text.find("When CARDNAME leaves the battlefield") != -1 :
print "\n"+text
print "<Trigger Script Start>"
print 'T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Any | ValidCard$ Creature.Self | Execute$ <TriggerFunc> | TriggerDescription$ '+text
print 'SVar:<TriggerFunc>:AB$ <Added Triggered Ability HERE>'
print "<Trigger Script End>\n"
elif text.find("Unleash") != -1 :
print 'K:ETBReplacement:Other:Unleash:Optional'
print 'SVar:Unleash:DB$ PutCounter | Defined$ Self | CounterType$ P1P1 | CounterNum$ 1 | SpellDescription$ Unleash (You may have this creature enter the battlefield with a +1/+1 counter on it. It can\'t block as long as it has a +1/+1 counter on it.)'
print 'S:Mode$ Continuous | Affected$ Card.Self | AddHiddenKeyword$ HIDDEN CARDNAME can\'t block. | CheckSVar$ X | SVarCompare$ GE1 | References$ X'
print 'SVar:X:Count$NumCounters.P1P1'
else :
if handleKeyords(text,keyWords) == False:
print text
#print "\n"
tmpSets = cardData.sets
tmpSets = tmpSets.split(', ')
setInfo = [];
@@ -266,6 +357,3 @@ while inputName != 'quit' :
print inputName+' not found\n'
inputName = raw_input("Enter Card Name: ")
inputName = inputName.rstrip()