Skip to content

Instantly share code, notes, and snippets.

@2nd-player
Created February 5, 2019 10:32
Show Gist options
  • Save 2nd-player/59943b26e7c54e55a77724993c954f73 to your computer and use it in GitHub Desktop.
Save 2nd-player/59943b26e7c54e55a77724993c954f73 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# (C) 2nd-player
# this script is licensed under CC BY-NC-SA 2.1 JP
# https://creativecommons.org/licenses/by-nc-sa/2.1/jp/
use utf8;
use Encode qw/encode decode/;
use 5.8.8;
use integer;# I think there is no need to handle float
use Socket;#required in HTTPpost()
use FileHandle;#required in HTTPpost()
use lib './lib';
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
use pwbotDB;
$db = new pwbotDBf("./data/dex-jedf.txt",'<:utf8');
$zdb = new pwbotDBf("./data/zhdex.txt",'<:utf8');
$wazdb = new pwbotDBf("./data/mov-jedf.txt",'<:utf8');
#print STDOUT $db->Lookup("アンノーン",1,5);exit;
my $dash = '―';
our @serverstat = (1,1);
our @lgstat = (0,1);
our $getpageErr;
our @lnglet = qw/ja zh/;
our @url = qw|http://wiki.xn--rckteqa2e.com/w/ http://wiki.52poke.com/|;
our @usr = qw|2P_(CP) 2P|;
our @pass;
my @tmp;
our $lnglets = 'ja|zh';
my %sockadr;
my $getpageErr;
my $wikitxt;
my %carddata;
my %typejz = (
"草"=>"草",
"炎"=>"火",
"水"=>"水",
"雷"=>"电",
"闘"=>"格斗",
"超"=>"超能力",
"悪"=>"恶",
"鋼"=>"钢",
"ドラゴン"=>"龙",
"竜"=>"龙",
"フェアリー"=>"妖精",
"妖"=>"妖精",
"無色"=>"一般",
"無"=>"一般"
);
my %typeh = (
"草"=>"kusa",
"炎"=>"honoo",
"水"=>"mizu",
"雷"=>"rai",
"闘"=>"tou",
"超"=>"chou",
"悪"=>"aku",
"鋼"=>"hagane",
"ドラゴン"=>"dragon",
"フェアリー"=>"fairy",
"妖"=>"fairy",
"無色"=>"mu",
"無"=>"mu"
);
my %typez = %typejz;
$typez{'闘'}='斗';
$typez{'超'}='超';
$typez{'フェアリー'}=$typez{'妖'}='妖';
$typez{'無色'}=$typez{'無'}='无';
my %evostjz = (
'たね'=>'基本',
'1進化'=>'一阶',
'2進化'=>'二阶',
'M進化'=>'M进化',
'BREAK進化'=>'BREAK进化'
);
my %scjz = (
'マヒ'=>'麻痹',
'ねむり'=>'睡眠',
'こんらん'=>'混乱',
'どく'=>'中毒',
'やけど'=>'灼伤'
);
sub unlink_r($){
my $txt = shift;
$txt =~ s/^.*?\|//s;
return $txt;
}
sub blf ($) {
my $str = $_[0];
$str =~ s/\015\012/\012/g;
$str =~ tr/\015/\012/;
$str =~ tr/\012/\n/;
return $str;
}
sub decommentout ($) {
#Public Function decommentout (ByVal $str As String) As String
#the simplest method to remove commentout.
my $str = $_[0];
$str =~ s/<!--.*?-->//sg;
return $str;
}
sub UrlEncodeUTF8 ($) {
# == memo ==
# unreserved characters (RFC3986):
# arabic numeral, roman alphabet, underscore, hyphen-minus, period, tilde
# see also RFC1866 section8.2.1
my $str;
$str = encode('utf8',$_[0]);
$str =~ s/([^ 0-9a-zA-Z_\-.~])/"%".uc(unpack("H2",$1))/eg;
$str =~ s/ /+/g;
return $str;
}
sub UrlDecodeUTF8 ($) {
my $str = $_[0];
$str =~ s/\+/ /g;
$str =~ s/%([0-9a-fA-F]{2})/pack("H2",$1)/eg;
$str = decode('utf8',$str);
return $str;
}
use Compress::Zlib;
sub HTTPpost ($;$$$$) {
#Public Function HTTPpost(URL As String, Optional query as String, Optional cookie As String, Optional boundary As Boolean, Optional nocacheaddr As Boolean) As String
# version 1.5[primal-alpha]
my $path;
my $host = $_[0];
$host =~ s|^http://||;
($host,$path) = split('/',$host,2);
$path = '/' . $path;
#print $host , "\n$path\n";
my $sockaddr;
# generate socket
if ($sockadr{$host}) {
$sockaddr = $sockadr{$host};
}else{
# host not cached yet
my $ip = inet_aton($host) || return;#die "host($host) not found.\n";
$sockaddr = pack_sockaddr_in('80', $ip);
unless ($_[4]){
$sockadr{$host} = $sockaddr;
}
}
socket(SOCKET, PF_INET, SOCK_STREAM, 0) || return;#die "socket error.\n";
# connect
connect(SOCKET, $sockaddr) || return; #die "connect $host error.\n";
#select(SOCKET);
# $|=1;
#select(STDOUT);
autoflush SOCKET (1);
# send request
$query = $_[1];
#print 'query: ', $query,"\n";
my $len = length $query;
my $res = "POST $path HTTP/1.1\015\012User-Agent: Mozilla/5.0 ($^O; Perl_$]; pwbot.pl; 2P_CP;)\015\012Host: $host\015\012";
if ($_[2] ne '') {
$res .= "Cookie: $_[2]\015\012";
}
$res .= "Accept-Encoding: gzip\015\012";#zlib
$res .= "Content-Length: $len\015\012";
$res .= "Connection: Close\015\012";
if ($_[3]){
$res .= "Content-Type: multipart/form-data; boundary=$_[3]\015\012\015\012$query\015\012";
}else{
$res .= "Content-Type: application/x-www-form-urlencoded\015\012\015\012$query\015\012";
}
print SOCKET $res;
# receive response
while (<SOCKET>) {
$res .= $_;
}
close(SOCKET);
#chop($res);
$res =~ s/^.*?\015\012\015\012//s; #remove request header
substr($res,0,$len+2) = '';#remove request content
#print $res,"\n";exit;
my $head;
($head, $res) = $res =~ /\A(.*?)\015\012\015\012(.*)\z/s;#separate header($1) from content($2)
($len) = $head =~ m/\015\012Content-Length:\s*([0-9]*)/;
if ($len > 0){
$res = substr($res,0,$len);
}elsif($head=~/\015\012Transfer-Encoding: chunked/){
my $content;
($len) = $res =~ /^([0-9a-f]*)/;#read chunk-size. this is hexadecimal
$len = hex $len;#now it's decimal
$res =~ s/^.*?\015\012//;#cut chunk-size and chunk-extension
while ($len > 0) {
$content .= substr($res,0,$len);#push chunk-body into $content
substr($res,0,$len+2) = '';# '+2' means CRLF, the terminator of the chunk
($len) = $res =~ /^([0-9a-f]*)/;# read chunk-size. this is hexadecimal
$len = hex $len;#now it's decimal
$res =~ s/^.*?\015\012//;#cut chunk-size and chunk-extension
}#wend
$res = $content;
}
if ($head =~ /\015\012Content-Encoding: gzip/){
$res = Compress::Zlib::memGunzip($res);
}
$resheader = $head;
$res = decode('utf8',$res);
$res = &blf($res);
if ($_[2]){
my ($attr, $v);
my @sc = $head =~ /Set-Cookie:\s*([^;]+)/g;
for (@sc){
($attr,$v) = /(.*?)=(.*)/;
if (index($_[2], $attr) >= 0){
$attr = quotemeta($attr);
$_[2] =~ s/(?<=$attr)=[^;]*/=$v/;
}
}
}
return $res;
}#End Function
sub getpage ($$) {
#Public Function getpage(lng As Integer, Page As String) As String
# version 3.9922[alpha]
# compatible with MW 1.22+
my ($lng,$page)=@_;
my $res;
my $str;
my $t = 2;
while ($t--) {
#use json format
$res = &HTTPpost ($url[$lng].'api.php', 'action=query&prop=revisions&titles='. &UrlEncodeUTF8 ($page) . '&rvprop=content&format=json&utf8=1',$cookie[$lng]);
($str) = $res =~ m/[,{]"\*":"(.*)"\}\]\}\}\}\}\s*$/s;
if ($str ne '') {
$str=~s/\\n/\n/g;
$str=~s/\\"/"/g;
$str=~s/\\\\/\\/g;# MW1.22+
$getpageErr = 0;
return $str;
}else {
unless ($res=~/\}\}\}\}\s*$/) {
$getpageErr = 2; #failed to download
unless (index($res,'"*":"')>=0) {
#no data received
if ($t==1){
if ($lgstat[$lng]){
&postlogin($lng);
return undef unless $serverstat[$lng];
}
}else{
$serverstat[$lng]=0;
return '';
}
}
} else {
$getpageErr = 1; #article not found, connection has no problem
return '';
}
}
}#wend
}#end function
sub readdata{
%carddata = undef;
($carddata{'pkmn'}) = $wikitxt =~ /ポケモン名\s*=\s*(.*?)\s*\n/;
($carddata{'pref'}) = $wikitxt =~ /名前の前\s*= *(.*?)\s*\n/;
($carddata{'pkmn2'}) = $wikitxt =~ /ポケモン名2\s*=\s*(.*?)\s*\n/;
($carddata{'suf'}) = $wikitxt =~ /名前の後\s*= *(.*?)\s*\n/;
($carddata{'type'}) = $wikitxt =~ /色\s*=\s*(.*?)\s*\n/;
($carddata{'hp'}) = $wikitxt =~ /HP\s*=\s*(.*?)\s*\n/;
($carddata{'evostage'}) = $wikitxt =~ /種類\s*= *(.*?)\s*\n/;
$carddata{'evostage'} = 'たね' unless $carddata{'evostage'};
if ($carddata{'evostage'} eq 'M進化'){
$carddata{'evofrom'} = $carddata{'pkmn'} . 'EX';
}elsif ($carddata{'evostage'} ne 'たね'){
($carddata{'evofrom'}) = $wikitxt =~ /進化前\s*=\s*(.*?)\s*\n/;
}
if($wikitxt =~ /アルセウスルール\s*=\s*1/){
($carddata{'arceus'}) = 1;
}
if (($carddata{'item'}) = $wikitxt =~ /アイテム\s*= *(.*?)\s*\n/){
($carddata{'itemeffect'}) = $wikitxt =~ /アイテム説明\s*=\s*(.*?)\s*\n/;
}
if (($carddata{'ability'}) = $wikitxt =~ /特性\s*= *(.*?)\s*\n/){
($carddata{'abilityeffect'}) = $wikitxt =~ /特性説明\s*=\s*(.*?)\s*\n/;
}
if (($carddata{'power'}) = $wikitxt =~ /特殊能力\s*= *(.*?)\s*\n/){
($carddata{'powertype'}) = $wikitxt =~ /特殊能力分類\s*=\s*(.*?)\s*\n/;
($carddata{'powereffect'}) = $wikitxt =~ /特殊能力説明\s*=\s*(.*?)\s*\n/;
if (($carddata{'power2'}) = $wikitxt =~ /特殊能力2\s*= *(.*?)\s*\n/){
($carddata{'powertype2'}) = $wikitxt =~ /特殊能力2分類\s*=\s*(.*?)\s*\n/;
($carddata{'powereffect2'}) = $wikitxt =~ /特殊能力2説明\s*=\s*(.*?)\s*\n/;
}
}
if (($carddata{'ancient'}) = $wikitxt =~ /古代能力\s*=\s*(.*?)\s*\n/){
if ($carddata{'ancient'} eq 'αグロウ'){
$carddata{'ancienteffect'}='このポケモンに、手札からエネルギーをつけるとき、同時に2枚までつけられる。(ワザ・特性・トレーナーズでつける場合はのぞく。)';
}elsif ($carddata{'ancient'} eq 'α回復'){
$carddata{'ancienteffect'}='このポケモンのHPが回復するとき、その回復する量は2倍になる。';
}elsif ($carddata{'ancient'} eq 'Ωバリア'){
$carddata{'ancienteffect'}='このポケモンは、相手が使うトレーナーズの効果を受けない。(ポケモンのどうぐ・スタジアムはのぞく。)';
}elsif ($carddata{'ancient'} eq 'Ω連打'){
$carddata{'ancienteffect'}="このポケモンは、ワザを2回連続で使える。(1回目で相手のバトルポケモンが'''きぜつ'''したなら、次のポケモンが出た後、2回目を使う。)";
}elsif ($carddata{'ancient'} eq 'Δ進化'){
$carddata{'ancienteffect'}='このカードは、最初の自分の番や出したばかりのポケモンからでも、手札から進化できる。';
}elsif ($carddata{'ancient'} eq 'Δプラス'){
$carddata{'ancienteffect'}="このポケモンが、ワザのダメージで相手のポケモンを'''きぜつ'''させたなら、サイドを1枚多くとる。";
}elsif ($carddata{'ancient'} eq 'Δワイルド'){
$carddata{'ancienteffect'}='このポケモンが、相手の[草][炎][水][雷]ポケモンから受けるワザのダメージは「-20」される。';
}elsif ($carddata{'ancient'} eq 'θストップ'){
$carddata{'ancienteffect'}='このポケモンは、相手のポケモンからの特性の効果を受けない。';
}elsif ($carddata{'ancient'} eq 'θダブル'){
$carddata{'ancienteffect'}='このポケモンは、「ポケモンのどうぐ」を2個までつけられる。';
}elsif ($carddata{'ancient'} eq 'θマックス'){
$carddata{'ancienteffect'}='このポケモンになったとき、このポケモンのHPをすべて回復する。';
}
}
$carddata{'numatk'}=1;
while (($carddata{'atk' . $carddata{'numatk'}}) = $wikitxt =~ /ワザ$carddata{'numatk'}\s*= *(.*?)\s*\n/){
($carddata{'atkenergy' . $carddata{'numatk'}}) = $wikitxt =~ /ワザ$carddata{'numatk'}エネルギー\s*= *(.*?)\s*\n/;
($carddata{'atkdmg' . $carddata{'numatk'}}) = $wikitxt =~ /ワザ$carddata{'numatk'}ダメージ\s*= *(.*?)\s*\n/;
($carddata{'atkeffect' . $carddata{'numatk'}}) = $wikitxt =~ /ワザ$carddata{'numatk'}説明\s*= *(.*?)\s*\n/;
# print STDOUT $carddata{'atkeffect' . $carddata{'numatk'}}, "\n";
$carddata{'numatk'}++;
}
if (($carddata{'atkgx'}) = $wikitxt =~ /GXワザ\s*= *(.*?)\s*\n/){
($carddata{'atkenergygx'}) = $wikitxt =~ /GXワザエネルギー\s*= *(.*?)\s*\n/;
($carddata{'atkdmggx'}) = $wikitxt =~ /GXワザダメージ\s*= *(.*?)\s*\n/;
($carddata{'atkeffectgx'}) = $wikitxt =~ /GXワザ説明\s*= *(.*?)\s*\n/;
# print STDOUT $carddata{'atkeffect' . $carddata{'numatk'}}, "\n";
}
$carddata{'numatk'}--;
($carddata{'weak'}) = $wikitxt =~ /弱点\s*= *(.*?)\s*\n/;
($carddata{'res'}) = $wikitxt =~ /抵抗力\s*= *(.*?)\s*\n/;
$carddata{'res'} = "ERROR" if $carddata{'res'} != 0;
($carddata{'ret'}) = $wikitxt =~ /にげるコスト\s*=\s*(\d*)/;
($carddata{'cn'}) = $wikitxt =~ /コレクションナンバー\s*= *(.*?)\s*\n/;
($carddata{'illus'}) = $wikitxt =~ /イラスト担当\s*= *(.*?)\s*\n/;
($carddata{'rar'}) = $wikitxt =~ /レアリティ\s*= *(.*?)\s*\n/;
unless($carddata{'suf'}){
($carddata{'flav'}) = $wikitxt =~ /解説文\s*=*\s*(.*?)\s*\n/;
$carddata{'flav'} =~ s/\{\{TCG-節?stub\}\}//g;
$carddata{'flav'} =~ s/\[\[\s*Category.*//sg
}
$carddata{'beast'} = 1 if $wikitxt =~ /ウルトラビースト\s=\s*1/;
$carddata{'tagteam'} = 1 if $wikitxt =~ /タッグチーム\s=\s*1/;
}
sub zh_local(){
#my ($exp, $zexp, $date, $ztitle,$detitle,$entitle);
open RFILE, '<:utf8', './list.txt' or die "couldn't open ./list.txt\n";
print STDOUT "exp:";
$exp = <STDIN>;
chop $exp;
open EFILE, '<:utf8', "./exp/${exp}.txt" or die "couldn't open ./exp/${exp}.txt\n";
{
local $/ = undef;
$wikitxt =<EFILE>;
}
close EFILE;
($zexp) = $wikitxt=~/zh\s*= *(.*)/;
($date) = $wikitxt=~/date\s*= *([0-9\-]+)/;
for my $dir('./new', './old'){
opendir (TITLELIST, $dir) || die "failed to open $dir/";
for $_(readdir (TITLELIST)){
next unless s/\.txt$//;
next unless /$exp/;
next if s/^\.//;
$pagename = decode('utf8',$_);
#my $wikitxt;
open (TXT, '<:utf8', "$dir/$pagename" . '.txt')||die "failed to open $dir/${pagename}.txt";
{
local $/ = undef;
$wikitxt = <TXT>;
}
close TXT;
my $ztxt = &zh_int($pagename, $wikitxt);
}
}
}
sub zh(){
#my ($exp, $zexp, $date, $ztitle,$detitle,$entitle);
open RFILE, '<:utf8', './list.txt' or die "couldn't open ./list.txt\n";
print STDOUT "exp:";
$exp = <STDIN>;
chop $exp;
open EFILE, '<:utf8', "./exp/${exp}.txt" or die "couldn't open ./exp/${exp}.txt\n";
{
local $/ = undef;
$wikitxt =<EFILE>;
}
close EFILE;
($zexp) = $wikitxt=~/zh\s*= *(.*)/;
($date) = $wikitxt=~/date\s*= *([0-9\-]+)/;
until (<RFILE> =~ /^\{\|/){}
my ($expline, $cn, $type, $cardtitle, $rar, $pkmn, $i, $prevtype, $expshort);
my @aimailine;
$i = 0;
while ($expline = <RFILE>){
if ($expline =~ /^\|-/){
undef $edtcmt;
$expline = <RFILE>;
($cn) = $expline =~ /^\|\s*(.*)\s*\n/;
next unless <RFILE> =~ /ポケモン/;
$expline = <RFILE>;
($type) = $expline =~ /^\|\s*(.*)/;
$expline = <RFILE>;
($cardtitle) = $expline =~ /\[\[\s*(.*?)[|\]]/;
#print $cat;exit;
$cardtitle =~ tr/_/ /;
$cardtitle =~ s/\s*$//;
($expshort) = $cardtitle =~ /\((.*?)\)/;
$expshort ||= 'ABBR';
$expline = <RFILE>;
($rar) = $expline =~ /^\|\s*(.*)/;
print STDOUT "checking $cardtitle\n";
$wikitxt = &getpage(0, $cardtitle);
while ($wikitxt =~ /^#\s*(?:REDIRECT|リダイレクト|転送)/i){
($cardtitle) = $wikitxt =~ /\[\[\s*(.*?)[|\]]/;
$wikitxt = &getpage(0, $cardtitle);
last unless $wikitxt;
}
unless ($wikitxt){
next;
}
my $ztxt = &zh_int($cardtitle, $wikitxt);
}#endif
}#wend
}#endfun
sub wisdom(){
#my ($exp, $zexp, $date, $ztitle,$detitle,$entitle);
print STDOUT "WISDOM cnvrtr\n";
open RFILE, '<:utf8', './list.txt' or die "couldn't open ./list.txt\n";
open WISDOM, '>:encoding(shiftjis)', './wisdom.csv' or die "couldn't open ./wisdom.csv\n";
local $/ = "\n";
until (<RFILE> =~ /^\{\|/){}
my ($expline, $cn, $type, $cardtitle, $rar, $pkmn, $i, $prevtype, $expshort, $delta);
my @aimailine;
$i = 0;
while ($expline = <RFILE>){
if ($expline =~ /^\|-/){
undef $edtcmt;
$expline = <RFILE>;
($cn) = $expline =~ /^\|\s*(.*)\s*\n/;
next unless <RFILE> =~ /ポケモン/;
$expline = <RFILE>;
($type) = $expline =~ /^\|\s*(.*)/;
$expline = <RFILE>;
($cardtitle) = $expline =~ /\[\[\s*(.*?)[|\]]/;
#print $cat;exit;
$cardtitle =~ tr/_/ /;
$cardtitle =~ s/\s*$//;
($expshort) = $cardtitle =~ /\((.*?)\)/;
$expshort ||= 'ABBR';
$expline = <RFILE>;
($rar) = $expline =~ /^\|\s*(.*)/;
print STDOUT "checking $cardtitle\n";
$wikitxt = &getpage(0, $cardtitle);
while ($wikitxt =~ /^#\s*(?:REDIRECT|リダイレクト|転送)/i){
($cardtitle) = $wikitxt =~ /\[\[\s*(.*?)[|\]]/;
$wikitxt = &getpage(0, $cardtitle);
last unless $wikitxt;
}
unless ($wikitxt){
next;
}
#print STDOUT "continue? [y/n]:";
#next if substr(<STDIN>,0,1) == 'y';
$wikitxt = blf($wikitxt);
$wikitxt =~ s/\[\[(.*?)\]\]/&unlink_r($1)/eg;
$wikitxt =~ tr/[]() /[]()/d;
$wikitxt =~ s/[フェアリー]/[妖]/g;
$wikitxt =~ s/[ドラゴン]/[竜]/g;
$wikitxt =~ s/[無色]/[無]/g;
$wikitxt =~ s/。 */。 /g;
$wikitxt =~ s/。 *([])])/。$1/g;
$wikitxt =~ s/'''''M'''''/M/g;
$wikitxt =~ s/'''''M''進化'''/'''M進化'''/g;
$wikitxt =~ s/'''''EX'''''/EX/g;
$wikitxt =~ s/'''(.*?)'''/$1/g;
$wikitxt =~ s/''(.*?)''/$1/g;
$wikitxt =~ s/[(.)]ポケモン/${1}ポケモン/g;
$wikitxt =~ s/[(.)]エネルギー/${1}エネルギー/g;
&readdata;
$carddata{'type'} =~ s/フェアリー/妖/;
$carddata{'type'} =~ s/ドラゴン/竜/;
$carddata{'type'} =~ s/無色/無/;
if ($carddata{'type'} eq $prevtype){
$i = sprintf("%03d", $i+1);
}else{
$prevtype = $carddata{'type'};
$i = '001';
}
if ($carddata{'weak'}){
$carddata{'weak'}=~ s/ドラゴン/竜/;
$carddata{'weak'}=~ s/フェアリー/妖/;
}else{
$carddata{'weak'} = '';
}
if ($carddata{'res'}){
$carddata{'res'}=~ s/ドラゴン/竜/;
$carddata{'res'}=~ s/フェアリー/妖/;
}else{
$carddata{'res'} = '';
}
if ($carddata{'suf'} =~ s/δ-デルタ種//){
$delta = 1;
}else{
undef $delta;
}
$carddata{'ret'}+=0;
$carddata{'rar'}||='-';
$carddata{'evostage'}.= 'ポケモン';
$carddata{'pkmn'} .= '&' . $carddata{'pkmn2'} if $carddata{'pkmn2'};
print WISDOM join(',','0',$carddata{'pref'}.$carddata{'pkmn'}.$carddata{'suf'}, $carddata{'type'}, $carddata{'evostage'},$carddata{'hp'},$carddata{'weak'},$carddata{'res'},$carddata{'ret'},$carddata{'rar'},'PACK',$expshort);
if ($delta){
print WISDOM ',,【δ-デルタ種】,';
}
if ($carddata{'beast'}){
print WISDOM ',,【ウルトラビースト】,';
}
if ($carddata{'tagteam'}){
print WISDOM ',,【タッグチーム】,';
}
if ($carddata{'arceus'}){
print WISDOM ',【アルセウスルール】,,このカードは、デッキに何枚でも入れられる。';
}
if ($carddata{'power'}){
$carddata{'powertype'}||='特殊能力';
print WISDOM ',【', $carddata{'powertype'} , '】', $carddata{'power'}, ',,', $carddata{'powereffect'};
}
if ($carddata{'power2'}){
$carddata{'powertype2'}||='特殊能力';
print WISDOM ',【', $carddata{'powertype2'} , '】', $carddata{'power2'}, ',,', $carddata{'powereffect2'};
}
if ($carddata{'ancient'}){
print WISDOM ',【古代能力】', $carddata{'ancient'}, ',,', $carddata{'ancienteffect'};
}
if ($carddata{'ability'}){
print WISDOM ',【特性】', $carddata{'ability'}, ',,', $carddata{'abilityeffect'};
}
if ($carddata{'item'}){
print WISDOM ',【ポケモンのどうぐ】', $carddata{'item'}, ',,', $carddata{'itemeffect'};
}
for $_(1..$carddata{'numatk'}){
$carddata{'atkeffect'. $_};
$carddata{'atkenergy' . $_} = '―' if $carddata{'atkenergy' . $_} eq '';
my $t = $carddata{'atkenergy'. $_} . ' ' . $carddata{'atkdmg'. $_};
$t =~ s/^\s*//;
$t =~ s/\s*$//;
print WISDOM ',', join(',', $carddata{'atk' . $_}, $t, $carddata{'atkeffect' . $_} );
}
if ($carddata{'atkgx'}){
local $_ = 'gx';
my $t = $carddata{'atkenergy'. $_} . ' ' . $carddata{'atkdmg'. $_};
$t =~ s/^\s*//;
$t =~ s/\s*$//;
print WISDOM ',', join(',', '【GXワザ】' . $carddata{'atk' . $_} . 'GX', $t, $carddata{'atkeffect' . $_} );
}
print WISDOM "\015\012";
}
}#wend
}#endsub
sub zh_int($$){
my $jatitle = shift;
$jatitle =~ tr/_/ /;
my $wikitxt = blf(shift);
($detitle) = $wikitxt =~ m/\[\[\s*de\s*:\s*(.*?)\]\]/;
($entitle) = $wikitxt =~ m/\[\[\s*en\s*:\s*(.*?)\]\]/;
$wikitxt =~ s/\[\[(.*?)\]\]/&unlink_r($1)/eg;
&readdata;
$num = $db->seek0->Match($carddata{'pkmn'},1)->f(0);
$zpm = $zdb->RecordByNumber($num)->f(1);
$epm = $db->f(2);
$num = sprintf("%03d",$num);
$cn = $carddata{'cn'};
$cn =~ s/\/.*$//s;
($ztitle) = $jatitle=~/\((.*?)\)/;
if($carddata{'pref'} eq 'アローラ'){
$carddata{'pref'} = '阿罗拉';
}
$ztitle = $carddata{'pref'} . $zpm . $carddata{'suf'} . '(' . $ztitle . ')';
for($carddata{'type'}, $carddata{'weak'}, $carddata{'res'}){
tr/雷鋼炎悪/电钢火惡/;
s/超能?力?/超能力/;
s/闘/格斗/;
s/フェアリー|妖精?/妖精/;
s/竜|ドラゴン/龙/;
s/無色?/一般/;
s/×\d+//;
s/-\d+//;
}
$_ = "{{N|$carddata{'pref'}$zpm$carddata{'suf'}||$carddata{'pkmn'}|<!--$epm-->}}是一张{{TCG|$carddata{'type'}}}属性的{{TCG|$evostjz{$carddata{'evostage'}}宝可梦}}卡。";
if($carddata{'suf'} eq 'EX'){
if($carddata{'evostage'} eq 'M進化'){
$_ = "{{N|\{\{Mega}}$zpm\{\{EX}}||M$carddata{'pkmn'}EX|<!--M $epm-EX-->}}是一张{{TCG|$carddata{'type'}}}属性的{{TCG|$evostjz{$carddata{'evostage'}}宝可梦}}卡。";
}else{
$_ = "{{N|$zpm\{\{EX}}||$carddata{'pkmn'}EX|<!--$epm-EX-->}}是一张{{TCG|$carddata{'type'}}}属性的{{TCG|$evostjz{$carddata{'evostage'}}宝可梦}}卡。";
}
}elsif($carddata{'suf'} eq 'GX'){
$_ = "{{N|$zpm\{\{GX}}||$carddata{'pkmn'}GX|<!--$epm-GX-->}}是一张{{TCG|$carddata{'type'}}}属性的{{TCG|$evostjz{$carddata{'evostage'}}宝可梦}}卡。";
}
$zhtxt = <<EOF;
{{日版卡片}}
{{未完成|卡片}}
$_
==卡片信息==
EOF
if($carddata{'suf'} eq 'EX'){
$zhtxt .= <<EOF;
{{卡片信息/header/EX
|name=$zpm
|hp=$carddata{'hp'}
|type=$carddata{'type'}
|evostage=$evostjz{carddata{'evostage'}}
EOF
if($carddata{'pref'}){
if ($carddata{'pref'} eq '阿罗拉'){
$zhtxt =~ s/\|hp=/\|names=<span style="font-size:75%">阿罗拉<\/span>$zpm\n|hp=/;
}else{
$zhtxt =~ s/\|hp=/\|names=$carddata{'pref'}$zpm\n|hp=/;
}
}
if($carddata{'evostage'} eq 'M進化'){
$zhtxt .=<<EOF;
|evo=$zpm
|evonumber=$num
EOF
}#end M-evolution
}else{#not EX
$zhtxt .=<<EOF;
{{卡片信息/header
|name=$zpm
|hp=$carddata{'hp'}
|type=$carddata{'type'}
|evostage=$evostjz{$carddata{'evostage'}}
EOF
if ($carddata{'suf'} eq 'GX'){
$zhtxt =~ s/header/header\/GX/;
}
if($carddata{'evostage'} ne 'たね'){
$prev = sprintf("%03d",$db->seek0->Match($carddata{'evofrom'},1)->f(0));
$zhtxt .= '|evo=' . $db->f(5) . "\n|evonumber=$prev\n";
}
$zhtxt .="|ndex=$num\n|species=" . $zdb->f(2) . "\n|height=" . $zdb->f(3) . "\n|weight=" . $zdb->f(4);
}
#for all
$zhtxt .="|image=${exp}${cn}.jpg\n}}\n";
#end header
if ($carddata{'ability'}){
$zhtxt .= <<EOF;
{{卡片信息/power
|powertype=特性
|type=$carddata{'type'}
|name=|link=
|jname=$carddata{'ability'}
|ename=
|ceffect=
|jeffect=$carddata{'abilityeffect'}
|eeffect=
}}
EOF
}
for $_(1..$carddata{'numatk'}){
$zhtxt .= "{{卡片信息/attack\n|type=$carddata{'type'}\n|name=" . $wazdb->Lookup($carddata{'atk'. $_}, 1,5) ."|link=\n|jname=" . $carddata{'atk'. $_}."\n|ename=\n|cost=";
for ($carddata{'atkenergy'.$_}){
tr/雷鋼炎悪龍竜/电钢火惡龙龙/;
}
$zhtxt .= join('|',$carddata{'atkenergy'.$_}=~/(.)/g) . "\n|damage=" . $carddata{'atkdmg' . $_} . "\n";
if ($carddata{'atkeffect'.$_}){
my $myef = $carddata{'atkeffect'.$_};
$zhtxt .= "|ceffect=" . transeffect_zh($carddata{'atkeffect'.$_})."\n|jeffect=" . $myef . "\n|eeffect=\n";
}
$zhtxt .= "}}\n";
}#next atk
if ($carddata{'suf'} eq 'GX'){
$_ = 'gx';
$zhtxt .= "{{卡片信息/attack/GX\n|type=$carddata{'type'}\n|name=" . $wazdb->Lookup($carddata{'atk'. $_}, 1,5) ."|link=\n|jname=" . $carddata{'atk'. $_}."\n|ename=\n|cost=";
for ($carddata{'atkenergy'.$_}){
tr/雷鋼炎悪龍竜/电钢火惡龙龙/;
}
$zhtxt .= join('|',$carddata{'atkenergy'.$_}=~/(.)/g) . "\n|damage=" . $carddata{'atkdmg' . $_} . "\n";
if ($carddata{'atkeffect'.$_}){
my $myef = $carddata{'atkeffect'.$_};
$zhtxt .= "|ceffect=" . transeffect_zh($carddata{'atkeffect'.$_})."\n|jeffect=" . $myef . "\n|eeffect=\n";
}
$zhtxt .= "}}\n";
}
if($carddata{'evostage'} eq 'BREAK進化'){
$zhtxt .= "|}\n";
}else{
$zhtxt .= <<EOF;
{{卡片信息/end
|type=$carddata{'type'}
|weakness=$carddata{'weak'}
|resistance=$carddata{'res'}
|retreat=$carddata{'ret'}
EOF
unless($carddata{'suf'}){
$zhtxt .= "|dex=\n|jdex=$carddata{'flav'}\n|edex=\n";
}
$zhtxt .= "}}\n";
}#end footer
#expansionlist and trivia
$zhtxt .= <<EOF;
{{ExpansionList/header|$carddata{'type'}}}
{{ExpansionList/main|$carddata{'type'}|enexpansion=|enseries=|entime=|enrar=|enno=|enimg=|enimgrow=1
|jaicon=${exp}|jaexpansion=$zexp|jaseries=太阳·月亮|jatime=$date|jarar=$carddata{'rar'}|jano=$carddata{'cn'}|jaimg=${exp}${cn}.jpg|jaimgrow=1
|illus=$carddata{'illus'}|illus2=}}
{{ExpansionList/end|$carddata{'type'}}}
==细节==
* 这张卡片的宝可梦图鉴来自{{game|S}}。
{{神奇宝贝百科卡片工程}}
EOF
$zhtxt .= "\n[[de:$detitle]]" if $detitle;
$zhtxt .= "\n[[en:$entitle]]" if $entitle;
$zhtxt .= "\n[[ja:$jatitle]]" if $jatitle;
if($carddata{'suf'}){
$zhtxt =~s/\*\s*这张卡片的宝可梦图鉴来自.*?。//;
}
open EFILE, '>:utf8', "./draft/${exp}${cn}.txt" or die "couldn't open ./draft/${exp}${cn}.txt\n";
print EFILE $zhtxt;
close EFILE;
return $zhtxt
}#end zh
sub main(){
unless (@ARGV){
&zh;
}elsif ($ARGV[0] eq 'wis'){
&wisdom;
}
exit;
my $a;
while(1){
print STDOUT "input:";
$a = <STDIN>;
print STDOUT transeffect_zh($a);
}
}
sub transsc_zh($){
$_ = shift;
tr/と/和/;
s/'*(どく|マヒ|ねむり|やけど|こんらん)'*/"'''{{TCG|" . $scjz{$1} . "}}'''"/ge;
return $_;
}
sub transeffect_zh($){
my $j = $_[0];
my $z = '';
my ($a,$b,$c);
$j =~ tr/  //d;
$j =~ s/\[(草|炎|雷|水|超|闘|悪|鋼|無色?|フェアリー|妖|ドラゴン|竜)\]/{{e|$1}}/g;
$j =~ s/'*\[ベンチ(?:へのダメージ)?は弱点・抵抗力(?:の計算を|を計算)しない。\]'*//g;
#print STDOUT "$j\n";
my $f = $j;
while($f){
$f = 0;
if ($j =~ s/^コインを(\d+)回投げ(?:る。|、)?/$z .= "投掷${1}次硬币。" and ""/e &&++$f){
}
if ($j =~ s/^オモテの数×(\d+)ダメージ。/$z .= "这次攻击的基本伤害为「${1}×硬币正面次数」。" and ""/e &&++$f){
}elsif($j =~ s/^オモテの数×(\d+)ダメージを?追加。/$z .= "这次攻击的基本伤害追加「${1}×硬币正面次数」。" and ""/e &&++$f){
}elsif ($j =~ s/^オモテなら、// &&++$f){
$z .= "如果出现正面,";
}elsif ($j =~ s/^ウラなら、// &&++$f){
$z .= "如果出现反面,";
}elsif ($j =~ s/^自分の手札と相手の手札が同じ枚数なら、// &&++$f){
$z .= "如果自己的手牌数与对手的手牌数相等,";
}elsif ($j =~ s/^このポケモンに((?:\{\{.*?\}\})?)エネルギーがついているなら、/$z .= "如果自身携带有${1}能量," and ""/e &&++$f){
}elsif ($j =~ s/^場に「?スタジアム」?が出ているなら、// &&++$f){
$z .= "如果场上存在{{TCG|训练场卡}},";
}
if ($j =~ s/^このワザは失敗。// &&++$f){
$z .= "这个招式使用失败。";
}
if ($j =~ s/^(\d+)ダメージを?追加[。、し]*/$z .= "这次攻击的基本伤害追加「${1}」点。" and ""/e &&++$f){
}
if ($j =~ s/^相手のバトルポケモンを((?:'''(?:どく|マヒ|ねむり|やけど|こんらん)'''と?)+)にする。/$z .= "对手的出战宝可梦即刻陷入" . transsc_zh($1) . "状态。" and ""/e &&++$f){
}
if ($j =~ s/^このポケモンを((?:'''(?:どく|マヒ|ねむり|やけど|こんらん)'''と?)+)にする。/$z .= "自身即刻陷入" . transsc_zh($1) . "状态。" and ""/e &&++$f){
}
if ($j =~ s/^相手の手札を見る。// &&++$f){
$z .= "查看你對手的手牌。";
}
if ($j =~ s/^このワザのダメージは抵抗力[のを]計算を?しない。// &&++$f){
$z .= "这次攻击造成的伤害不受抗性的影响。";
}elsif ($j =~ s/^このワザのダメージは弱点抵抗力[のを]計算を?しない。// &&++$f){
$z .= "这次攻击造成的伤害不受弱点与抗性的影响。";
}
if ($j =~ s/^このポケモンをベンチポケモンと入れ替える。// &&++$f){
$z .= "将自身与后备宝可梦交换。";
}
if ($j =~ s/^相手のバトルポケモンをベンチポケモンと入れ替える。'*\[バトル場に出すポケモンは相手が選ぶ。\]'*// &&++$f){
$z .= "对手将目标宝可梦与后备区一只宝可梦交换。";
}
if ($j =~ s/^このポケモンのHPを「(\d+)」回復する。/$z .= "自身的HP恢复「${1}」点。" and ""/e &&++$f){
}
if ($j =~ s/^このワザを受けたポケモンが使うワザのダメージは「-(\d+)」される。/$z .= "受到这个招式攻击的目标宝可梦使用的招式造成的伤害减少「${1}」点。" and ""/e &&++$f){
}
if ($j =~ s/^相手のベンチポケモンを1匹選び、そのポケモンにも(\d+)ダメージ。(?:'*\[ベンチは弱点・抵抗力(?:の計算を|を計算)しない。\]'*)?/$z .= "向对手的1只后备宝可梦造成${1}点伤害。''(若为后备宝可梦,则不计算弱点与抗性。)''" and ""/e &&++$f){
}
if ($j =~ s/^自分の山札を(\d+)枚引く。/$z .= "抽${1}张卡。 " and ""/e &&++$f){
}
if ($j =~ s/^このポケモンについている((?:\{\{.*?\}\})?)エネルギーを、?(\d+)個(?:選び、)?トラッシュする。/$z .= "选择自身身上的${2}个${1}能量并丢弃。" and ""/e &&++$f){
}elsif ($j =~ s/^このポケモンについている((?:\{\{.*?\}\})?)エネルギーをすべてトラッシュする。/$z .= "选择自身身上全部的${1}能量并丢弃。" and ""/e &&++$f){
}
if ($j =~ s/^相手のバトルポケモンについている((?:\{\{.*?\}\})?)エネルギーを、?(\d+)個(?:選び、)?トラッシュする。/$z .= "选择对手的出战宝可梦身上的${2}个${1}能量并丢弃。" and ""/e &&++$f){
}
if ($j =~ s/^このポケモンにのっているダメカンの数×(\d+)ダメージぶん、このワザのダメージは小さくなる。/$z .= "这次攻击的基本伤害减少「${1}×自身携带的伤害指示物数目」。" and ""/e &&++$f){
}
if ($j =~ s/^次の自分の[晩番]、// &&++$f){
$z .= "在己方接下来的回合,";
}elsif ($j =~ s/^次の相手の[晩番]、// &&++$f){
$z .= "在对手接下来的回合,";
}
if ($j =~ s/^(?:このポケモンは)?ワザのダメージや効果を受けない。// &&++$f){
$z .= "自身不会受到任何攻击的效果影响。";
}elsif ($j =~ s/^(?:このポケモンは)?ワザのダメージを受けない。// &&++$f){
$z .= "自身不受任何招式造成的伤害。";
}elsif ($j =~ s/^このポケモンはワザ[がを]使えない。// &&++$f){
$z .= "自身不能使用招式。";
}
if ($j =~ s/^このワザを受けた(?:相手のバトル)?ポケモンは、にげられない。// &&++$f){
$z .= "受到这个招式效果影响的宝可梦不能主动撤回。";
}elsif ($j =~ s/^このポケモンは、にげられない。// &&++$f){
$z .= "自身不能主动撤回。";
}elsif ($j =~ s/^このポケモンの'*にげる'*ため(?:に必要な|の)エネルギーは、すべてなくなる。// &&++$f){
$z .= "自身的撤回费用为0。";
}
if ($j =~ s/^相手のベンチポケモン(?:を1匹選び、そのポケモン|1匹)にも、?(\d+)ダメージ。/$z .= "向对手的1只后备寶可夢造成${1}点伤害。" and ""/e &&++$f){
}elsif ($j =~ s/^相手のポケモン全員に、それぞれ(\d+)ダメージ。/$z .= "向对手全部的宝可梦各造成${1}点伤害。" and ""/e &&++$f){
}elsif ($j =~ s/^相手のベンチポケモン全員にも、それぞれ(\d+)ダメージ。/$z .= "向对手全部的后备宝可梦各造成${1}点伤害。" and ""/e &&++$f){
}
if ($j =~ s/^このポケモンにも(\d+)ダメージ。/$z .= "对自身造成${1}点伤害。" and ""/e &&++$f){
}
if ($j =~ s/^のぞむなら、(\d+)ダメージを?追加(?:してよい)。/$z .= "你可以选择这次攻击的基本伤害追加「${1}」点。" and ""/e &&++$f){
}
if ($j =~ s/^その場合、// &&++$f){
$z .= "如果你这么做,";
}
if ($j =~ s/^自分のベンチポケモン(?:を1匹選び、そのポケモン|1匹)にも、?(\d+)ダメージ。/$z .= "向己方的1只后备寶可夢造成${1}点伤害。" and ""/e &&++$f){
}
}
$z = '<!--'.$z.'-->' if $j && $z;
print STDOUT $z, "\n";
return $z;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment