gen-card.pl now adds Keyword abilities to generated card (fixes issue 185)

Other abilities are added as comments.
This commit is contained in:
North 2011-07-16 23:39:57 +03:00
parent d5c06da679
commit c8885e3fcd
5 changed files with 19677 additions and 19533 deletions

View file

@ -29,7 +29,11 @@ package mage.sets.[=$set=];
import java.util.UUID; import java.util.UUID;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Rarity;[= if (defined($power)) {$OUT .= "\nimport mage.MageInt;"}=] import mage.Constants.Rarity;[=
if (defined($power)) {
$OUT .= "\nimport mage.MageInt;"
}
=][=$abilitiesImports=]
import mage.cards.CardImpl; import mage.cards.CardImpl;
/** /**
@ -40,13 +44,16 @@ public class [=$className=] extends CardImpl<[=$className=]> {
public [=$className=](UUID ownerId) { public [=$className=](UUID ownerId) {
super(ownerId, [=$cardNumber=], "[=$name=]", Rarity.[=$rarity=], new CardType[]{[=$type=]}, "[=$manaCost=]"); super(ownerId, [=$cardNumber=], "[=$name=]", Rarity.[=$rarity=], new CardType[]{[=$type=]}, "[=$manaCost=]");
this.expansionSetCode = "[=$expansionSetCode=]"; this.expansionSetCode = "[=$expansionSetCode=]";[=$subType=][=$colors=]
[=$subType=] [=$colors=] [=
[=if (defined($power)) { if (defined($power)) {
$OUT .= "this.power = new MageInt($power);\n"; $OUT .= " this.power = new MageInt($power);\n";
}=][=if (defined($toughness)) { }
=][=
if (defined($toughness)) {
$OUT .= " this.toughness = new MageInt($toughness);"; $OUT .= " this.toughness = new MageInt($toughness);";
}=] }
=][=$abilities=]
} }
public [=$className=](final [=$className=] card) { public [=$className=](final [=$className=] card) {

View file

@ -8,13 +8,15 @@ my $authorFile = 'author.txt';
my $dataFile = 'mtg-cards-data.txt'; my $dataFile = 'mtg-cards-data.txt';
my $setsFile = 'mtg-sets-data.txt'; my $setsFile = 'mtg-sets-data.txt';
my $knownSetsFile = 'known-sets.txt'; my $knownSetsFile = 'known-sets.txt';
my $keywordsFile = 'keywords.txt';
my %cards; my %cards;
my %sets; my %sets;
my %knownSets; my %knownSets;
my %keywords;
sub getClassName { sub toCamelCase {
my $string = $_[0]; my $string = $_[0];
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge; $string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
$string =~ s/[-,\s\']//g; $string =~ s/[-,\s\']//g;
@ -51,6 +53,13 @@ while(my $line = <DATA>) {
} }
close(DATA); close(DATA);
open (DATA, $keywordsFile) || die "can't open $keywordsFile";
while(my $line = <DATA>) {
my @data = split('\\|', $line);
$keywords{toCamelCase($data[0])}= $data[1];
}
close(DATA);
my %cardTypes; my %cardTypes;
$cardTypes{'Artifact'} = 'CardType.ARTIFACT'; $cardTypes{'Artifact'} = 'CardType.ARTIFACT';
$cardTypes{'Creature'} = 'CardType.CREATURE'; $cardTypes{'Creature'} = 'CardType.CREATURE';
@ -81,7 +90,7 @@ chomp $cardName;
# Check if card is already implemented # Check if card is already implemented
foreach my $setName (keys %{$cards{$cardName}}) { foreach my $setName (keys %{$cards{$cardName}}) {
if (exists $knownSets{$setName}) { if (exists $knownSets{$setName}) {
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . getClassName($cardName) . ".java"; my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . toCamelCase($cardName) . ".java";
if(-e $fileName) { if(-e $fileName) {
die "$cardName is already implemented (set found: $setName).\n"; die "$cardName is already implemented (set found: $setName).\n";
} }
@ -95,13 +104,13 @@ my %vars;
$vars{'author'} = $author; $vars{'author'} = $author;
$vars{'name'} = $cardName; $vars{'name'} = $cardName;
$vars{'className'} = getClassName($cardName); $vars{'className'} = toCamelCase($cardName);
print "Files generated:\n"; print "Files generated:\n";
my $baseRarity = ''; my $baseRarity = '';
foreach my $setName (keys %{$cards{$cardName}}) { foreach my $setName (keys %{$cards{$cardName}}) {
if (exists $knownSets{$setName}) { if (exists $knownSets{$setName}) {
my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . getClassName($cardName) . ".java"; my $fileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . toCamelCase($cardName) . ".java";
my $result; my $result;
$vars{'set'} = $knownSets{$setName}; $vars{'set'} = $knownSets{$setName};
@ -124,9 +133,9 @@ foreach my $setName (keys %{$cards{$cardName}}) {
push(@types, $cardTypes{$1}); push(@types, $cardTypes{$1});
} else { } else {
if (@types) { if (@types) {
$vars{'subType'} .= " this.subtype.add(\"$1\");\n"; $vars{'subType'} .= "\n this.subtype.add(\"$1\");";
} else { } else {
$vars{'subType'} .= " this.supertype.add(\"$1\");\n"; $vars{'subType'} .= "\n this.supertype.add(\"$1\");";
} }
} }
} }
@ -141,6 +150,55 @@ foreach my $setName (keys %{$cards{$cardName}}) {
foreach my $color (keys %colors) { foreach my $color (keys %colors) {
$vars{'colors'} .= "\n this.color.set$color(true);"; $vars{'colors'} .= "\n this.color.set$color(true);";
} }
if ($vars{'colors'} || $vars{'power'}) {
$vars{'colors'} = "\n" . $vars{'colors'};
}
$vars{'abilitiesImports'} = '';
$vars{'abilities'} = '';
my @abilities = split('\$', $cards{$cardName}{$setName}[8]);
foreach my $ability (@abilities) {
$ability =~ s/ <i>.+?<\/i>//g;
my $notKeyWord;
foreach my $keyword (keys %keywords) {
if (index(toCamelCase($ability), $keyword) eq 0) {
$notKeyWord = 'no';
my @ka = split(', ', $ability);
foreach my $kw (@ka) {
my $kwUnchanged = $kw;
$kw = toCamelCase($kw);
if ($keywords{$kw}) {
if ($keywords{$kw} eq 'instance') {
$vars{'abilities'} .= "\n this.addAbility(" . $kw . "Ability.getInstance());";
} elsif ($keywords{$kw} eq 'new') {
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . "Ability());";
} elsif ($keywords{$kw} eq 'number') {
$ability =~ m/(\b\d+?\b)/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(' . $1 . '));';
} elsif ($keywords{$kw} eq 'cost') {
$ability =~ m/({.*})/g;
$vars{'abilities'} .= "\n this.addAbility(new " . $kw . 'Ability(new ManaCostsImpl("' . $1 . '")));';
$vars{'abilitiesImports'} .= "\nimport mage.abilities.costs.mana.ManaCostsImpl;";
}
$vars{'abilitiesImports'} .= "\nimport mage.abilities.keyword." . $kw . "Ability;";
} else {
$vars{'abilities'} .= "\n // $kwUnchanged";
}
}
}
}
if (!$notKeyWord) {
$vars{'abilities'} .= "\n // $ability";
}
}
if ($vars{'abilities'}) {
$vars{'abilities'} = "\n" . $vars{'abilities'};
}
$vars{'baseSet'} = $vars{'set'}; $vars{'baseSet'} = $vars{'set'};
$vars{'baseClassName'} = $vars{'className'}; $vars{'baseClassName'} = $vars{'className'};
@ -149,7 +207,7 @@ foreach my $setName (keys %{$cards{$cardName}}) {
} else { } else {
$vars{'rarityExtended'} = ''; $vars{'rarityExtended'} = '';
if ($baseRarity ne $cards{$cardName}{$setName}[3]) { if ($baseRarity ne $cards{$cardName}{$setName}[3]) {
$vars{'rarityExtended'} = "\n this.rarity = Rarity.$raritiesConversion{$cards{$cardName}{$setName}[3]};\n"; $vars{'rarityExtended'} = "\n this.rarity = Rarity.$raritiesConversion{$cards{$cardName}{$setName}[3]};";
} }
$result = $templateExtended->fill_in(HASH => \%vars); $result = $templateExtended->fill_in(HASH => \%vars);
} }

View file

@ -9,6 +9,7 @@ my $dataFile = "mtg-cards-data.txt";
my $setsFile = "mtg-sets-data.txt"; my $setsFile = "mtg-sets-data.txt";
my $knownSetsFile = "known-sets.txt"; my $knownSetsFile = "known-sets.txt";
my %cards; my %cards;
my %sets; my %sets;
my %knownSets; my %knownSets;
@ -21,7 +22,7 @@ chomp $setName;
my $template = Text::Template->new(SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]); my $template = Text::Template->new(SOURCE => 'cardExtendedClass.tmpl', DELIMITERS => [ '[=', '=]' ]);
sub getClassName { sub toCamelCase {
my $string = $_[0]; my $string = $_[0];
$string =~ s/\b([\w']+)\b/ucfirst($1)/ge; $string =~ s/\b([\w']+)\b/ucfirst($1)/ge;
$string =~ s/[-,\s\']//g; $string =~ s/[-,\s\']//g;
@ -77,7 +78,7 @@ $vars{'expansionSetCode'} = $sets{$setName};
print "Files generated:\n"; print "Files generated:\n";
foreach my $cardName (@setCards) { foreach my $cardName (@setCards) {
my $className = getClassName($cardName); my $className = toCamelCase($cardName);
my $currentFileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . $className . ".java"; my $currentFileName = "../Mage.Sets/src/mage/sets/" . $knownSets{$setName} . "/" . $className . ".java";
if(! -e $currentFileName) { if(! -e $currentFileName) {
@ -97,7 +98,7 @@ foreach my $cardName (@setCards) {
$vars{'rarityExtended'} = ''; $vars{'rarityExtended'} = '';
if ($cards{$cardName}{$setName}[3] ne $cards{$cardName}{$keySet}[3]) { if ($cards{$cardName}{$setName}[3] ne $cards{$cardName}{$keySet}[3]) {
$vars{'rarityExtended'} = "\n this.rarity = Rarity.$raritiesConversion{$cards{$cardName}{$setName}[3]};\n"; $vars{'rarityExtended'} = "\n this.rarity = Rarity.$raritiesConversion{$cards{$cardName}{$setName}[3]};";
} }
$found = 1; $found = 1;
} }

38
Utils/keywords.txt Normal file
View file

@ -0,0 +1,38 @@
Annihilator|number|
Bushido|number|
Soulshift|number|
Basic landcycling|cost|
Cycling|cost|
Equip|cost|
Level up|cost|
Unearth|cost|
Battle cry|new|
Cascade|new|
Exalted|new|
Forestwalk|new|
Hexproof|new|
Islandwalk|new|
Living weapon|new|
Mountainwalk|new|
Plainswalk|new|
Rebound|new|
Swampwalk|new|
Deathtouch|instance|
Defender|instance|
Double Strike|instance|
Fear|instance|
First strike|instance|
Flash|instance|
Flying|instance|
Haste|instance|
Indestructible|instance|
Infect|instance|
Intimidate|instance|
Lifelink|instance|
Phasing|instance|
Reach|instance|
Shroud|instance|
Trample|instance|
Unblockable|instance|
Vigilance|instance|
Wither|instance|

File diff suppressed because it is too large Load diff