Thread MWS-Datei nach Netdraft konvertieren (6 answers)
Opened by Invader at 2011-09-19 18:22

Gast Invader
 2011-09-19 18:22
#152532 #152532
Hallo,
ich habe dieses per script von einer seite runtergeladen, habe aber keine kenntnisse wie ich es zum laufen bringe. Das aktuell Perl habe ich runtergelden. Es sollte von einer Ausgangsdatei (conflux.txt) eine neue datei (conflux.nd) erstellen so wie ich das verstanden habe. Aber wenn ich das script ausführe blinkt die DOS box kurz auf und verschwindet sofort wieder sodass ich nichts lesen kann was drinsteht.
Muss ich dateipfade oder irgendetwas eingeben pls help und danke im voraus :)

Das scipt sieht so aus:



Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/perl -w

#Author: Rutilio

use strict;
use Getopt::Long;
use File::Basename;

my $USAGE =
qq{mws2nd.pl -i <input_file> [-o <output file>] [-m <mythic_symbol>] [-n <number>]

Where:
input_file:    MWS spoiler file name.
ouput_file:    Netdraft output file name (Optional). Default <input_file>.nd
mythic_symbol: Spoiler mythic identifier (Optional). If it contains mythic cards, rares will be duplicated. Default M.
number:        How many times rares will be duplicated (Optional). Default 2.

Example: perl mws2nd.pl -i Conflux.txt -m M -n 2  
};

my $MWS_SPOILER;
my $ND_FILE;
my $index = -1;
my $input;
my $output;
my $m_symbol = 'M';
my $number   = '2';

GetOptions(
        "i=s" => \$input,
        "o=s" => \$output,
        "m=s" => \$m_symbol,
        "n=i" => \$number
) or die $USAGE;

if (!defined $input) {
        print $USAGE;
        exit(1);
}

if (!defined $output) {
        $output = (fileparse($input,'\..*'))[0] . '.nd';
}

open $MWS_SPOILER, '<', $input  or die "Unable to open file: $input";
open $ND_FILE,     '>', $output or die "Unable to create file: $output";

write_nd_file($ND_FILE, read_mws_spoiler($MWS_SPOILER), $m_symbol, 'R',
        $number);

close $MWS_SPOILER;
close $ND_FILE;

exit(0);

#MWS Format example:
# Card Name:    Aerie Mystics
# Card Color:   W
# Mana Cost:    4W
# Type & Class: Creature - Bird Cleric
# Pow/Tou:      3/3
# Card Text:    Flying  %1%G%U, %T: Creatures you control gain shroud until end of turn.
# Flavor Text:
# Artist:
# Rarity:               U
# Card #:               1/145
sub read_mws_spoiler {
        my ($MWS_FH) = @_;
        my @card_list;

        while (my $line = <$MWS_FH>) {
                chop $line;
                if ($line =~ /^Card Name:\s+(.+)$/) {
                        $index++;
                        $card_list[$index]{name} = $1;
                }
                elsif ($line =~ /^Card Color:\s+(.+)$/) {
                        $card_list[$index]{color} = $1;
                }
                elsif ($line =~ /^Mana Cost:\s+(.+)$/) {
                        $card_list[$index]{cost} = $1;
                }
                elsif ($line =~ /^Type & Class:\s+(.+)$/) {
                        $card_list[$index]{type} = $1;
                }
                elsif ($line =~ /^Pow\/Tou:\s+(.+)$/) {
                        $card_list[$index]{pow_tou} = $1;
                }
                elsif ($line =~ /^Card Text:\s+(.+)$/) {
                        $card_list[$index]{text} = $1;
                }
                elsif ($line =~ /^Rarity:\s+(.+)$/) {
                        $card_list[$index]{rarity} = $1;
                }
        }
        return \@card_list;
}

sub write_nd_file {
        my ($ND_FH, $card_list, $mythic_symbol, $duplicate_symbol, $times) = @_;

        my $has_mythics = has_mythics($card_list, $mythic_symbol);

        binmode $ND_FH;
        write_nd_header($ND_FH);

        foreach my $card (@{$card_list}) {
                my $counter = 0;
                do {
                        write_nd_field($ND_FH, $card->{name}, 1);
                        write_nd_field(
                                $ND_FH,
                                get_nd_rarity(
                                        $card->{rarity}, $mythic_symbol, $duplicate_symbol
                                ),
                                0
                        );
                        write_nd_field($ND_FH, get_nd_color($card->{color}), 0);
                        write_nd_field($ND_FH, $card->{cost},                1);
                        write_nd_field($ND_FH, $card->{type},                1);
                        write_nd_field($ND_FH, get_nd_text($card->{text}),   1);
                        write_nd_field($ND_FH, $card->{pow_tou},             1);
                  } while ($has_mythics == 1
                        and $card->{rarity} eq $duplicate_symbol
                        and ++$counter < $times);
        }
        write_nd_tail($ND_FILE);
}

sub has_mythics {
        my ($list, $symbol) = @_;

        foreach my $card (@{$list}) {
                return 1 if ($card->{rarity} eq $symbol);
        }
        return 0;
}

sub write_nd_header {
        my ($ND_FH) = @_;
        print {$ND_FH} "\1\0\3\0\12\0";
        return;
}

sub write_nd_field {
        my ($ND_FH, $field_value, $is_string) = @_;
        $field_value = (defined $field_value ? $field_value : '');
        my $length = $is_string ? length($field_value) + 1 : length($field_value);
        print {$ND_FH} chr($length & 0xFF), chr($length >> 8);
        print {$ND_FH} "$field_value";
        if ($is_string == 1) {
                print {$ND_FH} "\0";
        }
        return;
}

sub write_nd_tail {
        my ($ND_FH) = @_;
        print {$ND_FH} "\3\0END\1\0.\1\0.\0\0\0\0\0\0\0\0";
        return;
}

sub get_nd_rarity {
        my ($rarity, $mythic, $duplicate) = @_;
        $rarity =~ s/R/+/;
        $rarity =~ s/U/=/;
        $rarity =~ s/C/-/;
        if ($duplicate eq 'R') {
                $rarity =~ s/$mythic/+/;
        }
        elsif ($duplicate eq 'U') {
                $rarity =~ s/$mythic/=/;
        }
        else {
                $rarity =~ s/$mythic/-/;
        }
        return $rarity;
}

sub get_nd_text {
        my ($text) = @_;
        return $text unless (defined $text);
        $text =~ s/\%//g;
        $text =~ s/\s{2}/\n/g;
        return $text;
}

sub get_nd_color {
        my ($color) = @_;
        $color =~ s/Gld/M/;
        $color =~ s/Art/A/;
        $color =~ s/Lnd/L/;
        return $color;
}


modedit Editiert von GwenDragon: Code-Tags hinzu; Titel umbenannt

Bitte Formatierungshilfe vor dem Posten lesen und Code in Perl-Tags stellen!
Last edited: 2011-09-19 18:35:32 +0200 (CEST)

View full thread MWS-Datei nach Netdraft konvertieren