#!/usr/bin/perl
require '/home/rexi-jp/public_html/jj/lib/lib.pl';
require '/home/rexi-jp/public_html/jj/lib/mobile.pl';
$mycgi = 'index.cgi';
$mid = $uid;
$uid = '';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$ip = $ENV{'REMOTE_ADDR'};
$host = gethostbyaddr(pack("C4", split(/\./, $ip)), 2);
$host ||= $ENV{'REMOTE_HOST'};
$host ||= $ip;
$referer=$ENV{'HTTP_REFERER'};
$script=$ENV{'SCRIPT_NAME'};
$query = CGI->new;
my @params = $query->param();#全てのパラメータ名を取得 なのでこれを$inにしてしまえば$inで使用可能
foreach my $param (@params) {
$in{$param} = $query->param($param);
}
$uid = &get_usr_cookie;
$pcid = &get_pcid_cookie;
if ($pcid eq ''){&err("このコンテンツはキャラクターを選択していないとご利用できません。");}
$dbh = &connectDB($mainDB);
$death_flg = &death_check($pcid,$dbh);
&name_rtn;
#キャラクター情報取得
$sql = "select name1,attribute,class,position,cp from character where pcid = '$pcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'name1'},$attribute,$class,$position,$pc_cp)=@{$ref->[0]};
$hd =<<"EOT";
研究所調整
EOT
if ($in{'mode'} eq ''){
&list;
}
elsif ($in{'mode'} eq 'buy'){
&buy;
}
elsif ($in{'mode'} eq 'buy2'){
&buy2;
}
elsif ($in{'mode'} eq 'sp_conf'){
&sp_conf;
}
elsif ($in{'mode'} eq 'huku_buy'){
&huku_buy;
}
elsif ($in{'mode'} eq 'enquete'){
&enquete;
}
elsif ($in{'mode'} eq 'buy_base'){
&buy_base;
}
elsif ($in{'mode'} eq 'buy2_base'){
&buy2_base;
}
elsif ($in{'mode'} eq 'blueprint'){
&blueprint;
}
elsif ($in{'mode'} eq 'blueprint_conf'){
&blueprint_conf;
}
elsif ($in{'mode'} eq 'blueprint_start'){
&blueprint_start;
}
else{
&err("不正なパラメータ");
}
&disconDB($dbh);
exit;
#---------------------------------------
# HTML出力
#---------------------------------------
sub html_out {
$file = $_[0];
open FILE,$file;
print $header;
while(){
s/!(\w+)!/$out{$1}/g;
print;
}
close FILE;
exit;
}
#---------------------------------------
# 陳列リスト
#---------------------------------------
sub list {
# if ($uid eq 4 || $uid eq 2){
# $out{'repair'} = ' ';
# }
$sql = "select a.seq,a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text,a.last_buy,b.power,b.weapon_category,b.base_size_index,b.base_scale from shop a,item_master b where (a.sell_start <= now() or a.sell_start is null) and (a.sell_limit >= now() or a.sell_limit is null) and a.id = b.id and b.distribute_attribute in (0,$attribute) order by b.parts desc,b.kind,b.name;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($seq,$id,$stock,$last_buy,$cp_plus,$name,$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$text,$last_buy,$power,$weapon_category,$base_size_index,$base_scale)=@{$_};
$pre = '';
if ($base_size_index ne 0 && $base_size_index ne ''){$pre .= "サイズ:$base_size_index\n";}
if ($base_scale ne 0 && $base_scale ne ''){$pre .= "室内サイズ:$base_scale\n";}
$text = $pre . $text;
$cp = $cp / 10;
$cp_plus = $cp_plus / 10;
$ncp = $cp + $cp_plus;
$pc_cp = $pc_cp / 10;
# if ($pc_cp < $ncp){&err("CPが不足しているため、購入できません。");}
if ($condition eq 0){$condition = "両方";}
elsif ($condition eq 1){$condition = "変身後";}
elsif ($condition eq 2){$condition = "人間時";}
if ($kind eq '店舗' || $kind eq '設備' || $kind eq '備品'){$condition = "−";}
$sell_limit = substr($sell_limit,0,10);
$sell_limit =~ s/\-/\//g;
if ($sell_limit eq ''){$sell_limit = "−";}
# $text =~ s/\n/ /g;
# $text =~ s/\x0D\x0A|\x0D|\x0A//g;
# if ($s_flg1 eq 1 && $s_flg2 eq 1 && $s_flg3 eq 1){
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);
$dt = "";
if ($stock <= 0 && $h_flg eq 1){
&date_rtn;
$last_buy = substr($last_buy,0,10);
$last_buy =~ s/\-//g;
$last_buy =~ s/\://g;
if ($last_buy ne ''){
$c_date = &calDate(substr($last_buy,0,4),substr($last_buy,4,2),substr($last_buy,6,2),3);
$c_date =~ s/\-//g;
}
else{
$c_date = "00000000";
}
if ($c_date <= "$g_year$g_mon$g_mday"){$h_flg = 0;}
if ($uid eq 4){$dt="$last_buy,$c_date,$g_year$g_mon$g_mday ";}
}
if ($h_flg eq 1){
if (substr($kind,-4) eq '武器'){
$text =<<"EOT";
威力:$power
$text
EOT
}
$text =~ s/\x0D\x0A|\x0D|\x0A/ /g;
$text =~ s/\n/ /g;
if ($stock < 0){$stock = 0;}
#武器系統対応
$wcstr = '';
if ($weapon_category eq ''){$wcstr = '';}
else{
@wcs = ();
@wcs = split(/\,/,$weapon_category);
foreach (@wcs){
$wc_id = $_;
$wcstr .= "@weapon_category_str[$wc_id]/";
}
if ($wcstr ne ''){
# $wcstr = '(' . substr($wcstr,0,-2) . ')';
$wcstr = substr($wcstr,0,-2);
$kind = $wcstr;
}
}
$out{'list'} .=<<"EOT";
$name $kind $weight $condition $ncp $stock $sell_limit
EOT
if ($stock > 0 && $death_flg eq 0){
$out{'list'} .=<<"EOT";
EOT
}
$out{'list'} .=<<"EOT";
$dt
EOT
}
}
#基地CP販売リスト
$sql = "select seq from base where leader = '$pcid' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($tmp)=@{$ref->[0]};
if (($tmp ne '' || $uid eq 10) && $death_flg eq 0){
# if (($uid eq 2 || $uid eq 10)){
$sql = "select a.seq,a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text,a.last_buy,b.power,b.weapon_category,b.base_size_index,b.base_scale from shop_base a,item_master b where (a.sell_start <= now() or a.sell_start is null) and (a.sell_limit >= now() or a.sell_limit is null) and a.id = b.id and b.distribute_attribute in (0,$attribute) order by b.parts desc,b.kind,b.name;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($seq,$id,$stock,$last_buy,$cp_plus,$name,$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$text,$last_buy,$power,$weapon_category,$base_size_index,$base_scale)=@{$_};
$pre = '';
if ($base_size_index ne 0 && $base_size_index ne ''){$pre .= "サイズ:$base_size_index\n";}
if ($base_scale ne 0 && $base_scale ne ''){$pre .= "室内サイズ:$base_scale\n";}
$text = $pre . $text;
$cp = $cp / 10;
$cp_plus = $cp_plus / 10;
$ncp = $cp + $cp_plus;
$pc_cp = $pc_cp / 10;
$sell_limit = substr($sell_limit,0,10);
$sell_limit =~ s/\-/\//g;
if ($sell_limit eq ''){$sell_limit = "−";}
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);
$dt = "";
if ($stock <= 0 && $h_flg eq 1){
&date_rtn;
$last_buy = substr($last_buy,0,10);
$last_buy =~ s/\-//g;
$last_buy =~ s/\://g;
if ($last_buy ne ''){
$c_date = &calDate(substr($last_buy,0,4),substr($last_buy,4,2),substr($last_buy,6,2),3);
$c_date =~ s/\-//g;
}
else{
$c_date = "00000000";
}
if ($c_date <= "$g_year$g_mon$g_mday"){$h_flg = 0;}
if ($uid eq 4){$dt="$last_buy,$c_date,$g_year$g_mon$g_mday ";}
}
if ($h_flg eq 1){
$text =~ s/\x0D\x0A|\x0D|\x0A/ /g;
$text =~ s/\n/ /g;
if ($stock < 0){$stock = 0;}
$list2 .=<<"EOT";
$name $kind $ncp $stock $sell_limit
EOT
if ($stock > 0){
$list2 .=<<"EOT";
EOT
}
$list2 .=<<"EOT";
EOT
}
}
$out{'list2'} =<<"EOT";
名称 種類 必要 基地CP 在庫 取扱期限
$list2
●解説(アイテム名称をクリックするとここに詳細が表示されます)
EOT
}
#新着情報
$sql = "select a.seq,a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text from shop a,item_master b where a.sell_start >= now() and a.stock > 0 and a.info is not null and a.id = b.id and b.distribute_attribute in (0,$attribute);";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($seq,$id,$stock,$last_buy,$cp_plus,$name,$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$text)=@{$_};
if ($sell_limit eq ''){$sell_limit = "−";}
if ($info eq ''){$info = ' ';}
$info =~ s/\n/ /g;
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2,1);
if ($h_flg eq 1){
$out{'new'} .=<<"EOT";
$name $info
EOT
}
}
if ($out{'new'} eq ''){
$out{'new'} =<<"EOT";
現在、新着情報はありません。
EOT
}
#福袋リスト
if ($death_flg eq 0){
$sql = "select no,name,substr(sell_limit,1,10),price from hukubukuro_master where (sell_start <= now() or sell_start is null) and (sell_limit >= now() or sell_limit is null) and state = 0 order by no;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
foreach(@$ref) {
($no,$name,$sell_limit,$price)=@{$_};
$sell_limit =~ s/\-/\//g;
$out{'hukubukuro'} .=<<"EOT";
$name $price Rex $sell_limit
EOT
}
}
# &date_rtn;
# if ("$g_year$g_mon$g_mday$g_hour$g_min$g_sec" <= "20071225000000"){
# $out{'enq'} =<<"EOT";
#
#
#
#■スペシャル品クリスマス企画!!
# 12月25日取り扱い開始のスペシャルアイテム「クリスマスプレゼントスペシャル」では、クリスマス特別企画として、お客様からリクエストを募り、要望の多いアイテムを詰め合わせます。
# リクエストがある場合は、下記フォームからアイテム名の投稿を行ってください。
# 12月24日24:00まで に集まったご要望にあわせて内容を確定させていただきます。
#
#
#
#
#EOT
# }
&out_enc;
if ($mid ne ''){
&html_out("shop_top_m.html");
}
else{
&html_out("shop_top.html");
}
}
#---------------------------------------
# 特別頒布品購入確認
#---------------------------------------
sub sp_conf {
&death_check($pcid,$dbh,1);
$out{'no'} = $in{'no'};
if ($in{'no'} eq ''){&err("指定が不正です。");}
$sql = "select name,price from hukubukuro_master where no = $in{'no'} and (sell_start <= now() or sell_start is null) and (sell_limit >= now() or sell_limit is null) and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'name'},$price)=@{$ref->[0]};
if ($out{'name'} eq ''){&err("指定が不正です。");}
$out{'nrex'} = $price;
$rex = &get_rex($pcid);
if ($uid ne 4 && $uid ne 10 && $uid ne 8 && $uid ne 2){
if ($rex < $price){&err("Rex残高が不足しているため、スペシャル品の購入を行えません。");}
}
$out{'price'} = $price;
&out_enc;
&html_out("huku_buy_conf.html");
}
#---------------------------------------
# 特別頒布品購入確認
#---------------------------------------
sub huku_buy {
&death_check($pcid,$dbh,1);
if ($in{'no'} eq ''){&err("指定が不正です。");}
$sql = "select name,price from hukubukuro_master where no = $in{'no'} and (sell_start <= now() or sell_start is null) and (sell_limit >= now() or sell_limit is null) and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'name'},$price)=@{$ref->[0]};
if ($out{'name'} eq ''){&err("指定が不正です。");}
$rex = &get_rex($pcid);
if ($uid ne 4 && $uid ne 10 && $uid ne 8 && $uid ne 2){
if ($rex < $price){&err("Rex残高が不足しているため、特別頒布品の購入を行えません。");}
}
#テーブル1
TBL1:
$sql = "select sum(per) from hukubukuro where no = $in{'no'} and attribute = $attribute and index = 1;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($sum1)=@{$ref->[0]};
$rand = int(rand($sum1));
# &err("$sum1,$rand");
$sql = "select item_id,per from hukubukuro where no = $in{'no'} and attribute = $attribute and index = 1;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
$per_sum = 0;
foreach(@$ref) {
($item_id,$per)=@{$_};
$per_sum = $per_sum + $per;
# &err("$per_sum , $per,$rand,$item_id");
if ($per_sum >= $rand){
$item1 = $item_id;
# &err("$per_sum , $per,$rand,$item_id,$item1");
last;
}
}
# &err($item1);
if ($item1 eq ''){goto TBL1;}
# &err("$sum1,$rand,$item1");
#テーブル2
TBL2:
$sql = "select sum(per) from hukubukuro where no = $in{'no'} and attribute = $attribute and index = 2;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($sum2)=@{$ref->[0]};
my $rand2 = int(rand($sum2));
#&err("$sum2,$rand");
$item2 = '';
$sql = "select item_id,per from hukubukuro where no = $in{'no'} and attribute = $attribute and index = 2;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
$per_sum2 = 0;
$tmp = "sum2:$sum2,rand2:$rand2 ";
foreach(@$ref) {
($item_id2,$per)=@{$_};
$tmp .= "$item_id2,$per ";
$per_sum2 = $per_sum2 + $per;
if ($per_sum2 >= $rand2){
$item2 = $item_id2;
last;
}
}
if ($item2 eq ''){goto TBL2;}
# &err("$sum2,$rand2,$item2,$item_id2");
$tmp .= "per_sum2:$per_sum item2:$item2";
# &err($tmp);
&item_issue($item1,$pcid);
if ($uid ne 4 && $uid ne 10 && $uid ne 8 && $uid ne 2){
&log_write($pcid,"hukubukuro","no:$in{'no'},index:1,item1:$item1,price:$price");
}
&item_issue($item2,$pcid);
if ($uid ne 4 && $uid ne 10 && $uid ne 8 && $uid ne 2){
&log_write($pcid,"hukubukuro","no:$in{'no'},index:2,item2:$item2,price:$price");
}
if ($uid ne 4 && $uid ne 10 && $uid ne 8 && $uid ne 2){
$sql = "insert into huku_log (pcid,no,attribute,item1,item2) values ('$pcid',$in{'no'},$attribute,$item1,$item2);";
$dbh->do($sql) or &err("エラーが発生しました。");
}
if ($uid ne 4 && $uid ne 10 && $uid ne 8 && $uid ne 2){
$use_price = $price * -1;
&use_rex($pcid,'',$use_price,'特別頒布品',"no:$in{'no'},item1:$item1,item2:$item2");
}
$out{'urex'} = &get_rex($pcid);
$sql = "select name,text from item_master where id = $item1;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'item_name1'},$out{'text1'})=@{$ref->[0]};
$sql = "select name,text from item_master where id = $item2;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'item_name2'},$out{'text2'})=@{$ref->[0]};
$out{'text1'} =~ s/\n/ /g;
$out{'text2'} =~ s/\n/ /g;
&out_enc;
&html_out("huku_buy_end.html");
}
#---------------------------------------
# 購入確認
#---------------------------------------
sub buy {
&death_check($pcid,$dbh,1);
$sql = "select a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text from shop a,item_master b where a.seq = $in{'seq'} and (a.sell_start <= now() or a.sell_start is null) and a.id = b.id and b.distribute_attribute in (0,$attribute);";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($id,$stock,$last_buy,$cp_plus,$out{'name'},$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$out{'text'})=@{$ref->[0]};
$out{'text'} =~ s/\n/ /g;
$out{'ncp'} = ($cp + $cp_plus) / 10;
$pc_cp = $pc_cp / 10;
# if ($pc_cp < $out{'ncp'}){&err("CPが不足しているため、購入できません。");}
# &err($sql);
if ($id eq ''){&err("本日の取り扱いは終了しました");}
if ($stock < 0){&err("指定された商品の在庫がなくなりました。");}
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);
# &err("$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);");
if ($h_flg ne 1){&err("本日の取り扱いは終了しました。");}
$out{'seq'} = $in{'seq'};
if ($pc_cp < $out{'ncp'}){
&cp_rp($pc_cp,$out{'ncp'});
}
&out_enc;
&html_out("shop_buy_conf.html");
}
#---------------------------------------
# 購入
#---------------------------------------
sub buy2 {
&death_check($pcid,$dbh,1);
$sql = "select a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text from shop a,item_master b where a.seq = $in{'seq'} and (a.sell_start <= now() or a.sell_start is null) and a.id = b.id and b.distribute_attribute in (0,$attribute);";
if ($uid eq 2){
$sql = "select a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text from shop a,item_master b where a.seq = $in{'seq'} and a.id = b.id and b.distribute_attribute in (0,$attribute);";
}
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($id,$stock,$last_buy,$cp_plus,$name,$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$out{'text'})=@{$ref->[0]};
$ncp = ($cp + $cp_plus) / 10;
$pc_cp = $pc_cp / 10;
# if ($pc_cp < $ncp){&err("CPが不足しているため、購入できません。");}
if ($id eq ''){&err("本日の取り扱いは終了しました。");}
if ($stock < 0){&err("指定された商品の在庫がなくなりました。");}
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);
if ($h_flg ne 1){&err("本日の取り扱いは終了しました。");}
if ($pc_cp < $ncp){
&cp_rp2($pc_cp,$ncp);
$sql = "update character set cp = 0 where pcid = '$pcid';";
$dbh->do($sql) or &err("エラーが発生しました。");
# $use_cp = $pc_cp;
$use_cp = $pc_cp * 10;
if ($uid ne 4 && $uid ne 10 && $uid ne 8){
$use_rex_p = ($ncp - $pc_cp) * 100;
if ($use_rex_p eq ''){$use_rex_p = 0;}
}
else{
$use_rex_p = 0;
}
}
else{
$sql = "update character set cp = cp - ($cp + $cp_plus) where pcid = '$pcid';";
$dbh->do($sql) or &err("エラーが発生しました。");
$use_cp = $cp + $cp_plus;
$use_rex_p = 0;
}
&item_issue($id,$pcid);
&log_write($pcid,'研究所アイテム購入',"id:$id,name:$name");
$sql = "update shop set stock = stock - 1,last_buy = now() where seq = $in{'seq'};";
$dbh->do($sql) or &err("エラーが発生しました。");
$sql = "insert into sell_item_log (pcid,id,use_cp,use_rex) values ('$pcid',$id,$use_cp,$use_rex_p);";
$dbh->do($sql) or &err("エラーが発生しました。");
$out{'urex'} = &get_rex($pcid);
&out_enc;
&html_out("shop_buy_end.html");
# print "Location: ./shop_buy_end.html\n\n";
}
#---------------------------------------
# CP不足処理
#---------------------------------------
sub cp_rp {
my $usr_cp = $_[0];
my $need_cp = $_[1];
my $hcp = $need_cp - $usr_cp; #不足CP
my $rcp = $hcp * 100; #補填REX
my $rp = &get_rex($pcid);
if ($rp < $rcp && $uid ne 4 && $uid ne 10 && $uid ne 8){&err("CPが不足しているため、購入できません。");}
$out{'need_cp'} = $need_cp;
$out{'usr_cp'} = $usr_cp;
$out{'hcp'} = $hcp;
$out{'rcp'} = $rcp;
$out{'rp'} = $rp;
&out_enc;
&html_out("shop_buy_conf2.html");
exit;
}
#---------------------------------------
# CP不足購入処理
#---------------------------------------
sub cp_rp2 {
my $usr_cp = $_[0];
my $need_cp = $_[1];
my $hcp = $need_cp - $usr_cp; #不足CP
my $rcp = $hcp * 100; #補填REX
my $rp = &get_rex($pcid);
if ($rp < $rcp && $uid ne 4 && $uid ne 10 && $uid ne 8){&err("CPが不足しているため、購入できません。");}
my $trex = $rcp * -1;
if ($uid ne 4 && $uid ne 10 && $uid ne 8){
&use_rex($pcid,'',$trex,'研究所アイテム購入REX補填',$id);
}
}
#---------------------------------------
# 表示チェック処理
#---------------------------------------
sub hyouji_able {
#クラス制限
my $li_class = $_[0];
my $li_position = $_[1];
my $li_terms1 = $_[2];
my $li_terms2 = $_[3];
my $li_flg = $_[4];
my @l_class = ();
my $s_flg1 = 1;
if ($li_class ne ''){
@l_class = split(/\,/,$li_class);
$s_flg1 = 0;
foreach(@l_class){
$tmp = $_;
if ($class eq $tmp){
$s_flg1 = 1;
last;
}
}
}
#立場制限
my @l_position = ();
my $s_flg2 = 1;
if ($li_position ne ''){
@l_position = split(/\,/,$li_position);
$s_flg2 = 0;
foreach(@l_position){
$tmp = $_;
if ($position eq $tmp){
$s_flg2 = 1;
last;
}
}
}
#条件1
my @l_terms1 = ();
my $s_flg3 = 1;
if ($li_flg ne 1){
&date_rtn;
if ($li_terms1 ne '' && $li_terms1 ne '0'){
@l_terms1 = split(/\,/,$li_terms1);
$s_flg3 = 0;
foreach(@l_terms1){
$tmp = $_;
if ($g_youbi eq $tmp){
$s_flg3 = 1;
last;
}
}
}
}
#条件2
my @l_terms2 = ();
my $s_flg4 = 1;
my $s1_flg1 = 0;
my $s1_flg2 = 0;
if ($li_flg ne 1){
if ($li_terms2 ne ''){
@l_terms2 = split(/\,/,$li_terms2);
if (@l_terms2[0] ne '' && @l_terms2[1] ne ''){
$s_flg4 = 0;
if (@l_terms2[0] eq '' || @l_terms2[0] eq '00:00'){$s1_flg1 = 1;}
else{
@l_terms2[0] =~ s/\://g;
if (int(@l_terms2[0]) < 1000){@l_terms2[0] = "0" . int(@l_terms2[0]);}
if ("$g_hour$g_min" >= @l_terms2[0]){$s1_flg1 = 1;}
}
if (@l_terms2[1] eq '' || @l_terms2[1] eq '00:00'){$s1_flg2 = 1;}
else{
@l_terms2[1] =~ s/\://g;
if (int(@l_terms2[1]) < 1000){@l_terms2[1] = "0" . int(@l_terms2[1]);}
if ("$g_hour$g_min" <= @l_terms2[1]){$s1_flg2 = 1;}
}
if ($s1_flg1 eq 1 && $s1_flg2 eq 1){$s_flg4 = 1;}
}
}
}
# if ($id eq 217){&err("$g_hour$g_min,@l_terms2[0],@l_terms2[1],$s1_flg1,$s1_flg2");}
if ($s_flg1 eq 1 && $s_flg2 eq 1 && $s_flg3 eq 1 && $s_flg4 eq 1){
return 1;
}
else{
return 0;
}
}
#---------------------------------------
# スペシャル品アンケート投稿
#---------------------------------------
sub enquete {
&in_enc;
if ($pcid eq ''){&err("この機能はログインしないと利用できません。");}
if ($in{'item_text'} eq ''){&err("アイテム名が記入されていません。");}
$len = length($in{'item_text'});
if ($len > 40){&err("アイテム名は全角20字までです。");}
open FILE,'>>../admin/enquete_item.dat';
print FILE $uid . "\t" . $pcid . "\t" . $in{'item_text'} . "\t" . $ip . "\t" . $host . "\n";
close FILE;
print "Location: ./enquete_end.html\n\n";
}
#---------------------------------------
# 購入確認(基地アイテム)
#---------------------------------------
sub buy_base {
&death_check($pcid,$dbh,1);
$sql = "select a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text from shop_base a,item_master b where a.seq = $in{'seq'} and (a.sell_start <= now() or a.sell_start is null) and a.id = b.id and b.distribute_attribute in (0,$attribute);";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($id,$stock,$last_buy,$cp_plus,$out{'name'},$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$out{'text'})=@{$ref->[0]};
$sql = "select cp from base where leader = '$pcid' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($base_cp)=@{$ref->[0]};
if ($base_cp eq ''){&err("このアイテムは秘密基地の司令官/首領のみ購入できます。");}
$out{'bcp'} = $base_cp / 10;
$out{'text'} =~ s/\n/ /g;
$out{'ncp'} = ($cp + $cp_plus) / 10;
$base_cp = $base_cp / 10;
if ($id eq ''){&err("本日の取り扱いは終了しました");}
if ($stock < 0){&err("指定された商品の在庫がなくなりました。");}
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);
if ($h_flg ne 1){&err("本日の取り扱いは終了しました。");}
$out{'seq'} = $in{'seq'};
if ($base_cp < $out{'ncp'}){
# &cp_rp($pc_cp,$out{'ncp'});
&err("基地CPが不足している為、購入できません。");
}
&out_enc;
&html_out("shop_buy_conf_base.html");
}
#---------------------------------------
# 購入(基地アイテム)
#---------------------------------------
sub buy2_base {
&death_check($pcid,$dbh,1);
$sql = "select a.id,a.stock,a.last_buy,a.cp_plus,b.name,b.kind,b.condition,b.distribute_attribute,b.limit_class,b.limit_position,b.cp,a.sell_start,a.sell_limit,a.terms1,a.terms2,a.info,a.info_x,b.weight,b.condition,b.text from shop_base a,item_master b where a.seq = $in{'seq'} and (a.sell_start <= now() or a.sell_start is null) and a.id = b.id and b.distribute_attribute in (0,$attribute);";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($id,$stock,$last_buy,$cp_plus,$name,$kind,$condition,$distribute_attribute,$limit_class,$limit_position,$cp,$sell_start,$sell_limit,$terms1,$terms2,$info,$info_x,$weight,$condition,$out{'text'})=@{$ref->[0]};
$ncp = ($cp + $cp_plus) / 10;
$sql = "select seq,name,cp from base where leader = '$pcid' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($base_seq,$out{'base_name'},$base_cp)=@{$ref->[0]};
if ($base_cp eq ''){&err("このアイテムは秘密基地の司令官/首領のみ購入できます。");}
$bcp = $base_cp / 10;
if ($base_cp < $ncp){&err("基地CPが不足しているため、購入できません。");}
if ($id eq ''){&err("本日の取り扱いは終了しました。");}
if ($stock < 0){&err("指定された商品の在庫がなくなりました。");}
$h_flg = &hyouji_able($limit_class,$limit_position,$terms1,$terms2);
if ($h_flg ne 1){&err("本日の取り扱いは終了しました。");}
$sql = "update base set cp = cp - ($cp + $cp_plus) where seq = $base_seq;";
$dbh->do($sql) or &err("エラーが発生しました。");
$use_cp = $cp + $cp_plus;
$use_rex_p = 0;
# &item_issue($id,$pcid);
$sql = "insert into item (pcid,id,equip,base_seq) values ('$pcid',$id,-2,$base_seq);";
$dbh->do($sql) or &err("エラーが発生しました。");
&log_write($pcid,'研究所基地アイテム購入',"id:$id,name:$name");
$sql = "update shop_base set stock = stock - 1,last_buy = now() where seq = $in{'seq'};";
$dbh->do($sql) or &err("エラーが発生しました。");
$sql = "insert into sell_item_log (pcid,id,use_cp,use_rex,type) values ('$pcid',$id,$use_cp,$use_rex_p,1);";
$dbh->do($sql) or &err("エラーが発生しました。");
$out{'bcp'} = ($base_cp - $use_cp) / 10;
&out_enc;
&html_out("shop_buy_end_base.html");
}
#---------------------------------------
# 設計図使用
#---------------------------------------
sub blueprint {
&death_check($pcid,$dbh,1);
$sql = "select seq from base where leader = '$pcid' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01 エラーが発生しました。");
($base_seq)=@{$ref->[0]};
if ($base_seq eq ''){&err(" この機能は秘密基地の司令官/首領のみ利用できます。");}
$sql = "select use_item,result_item,need_days,substr(set_time,1,10) from joint_plan where base_seq = $base_seq and result = 0 order by seq;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-02 エラーが発生しました。");
foreach(@$ref) {
($use_item,$result_item,$need_days,$set_time)=@{$_};
@uitem = ();
@uitem = split(/\,/,$use_item);
$useiname = '';
foreach(@uitem){
$id = $_;
$sql2 = "select name from item_master where id = $id;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:B-01 エラーが発生しました。");
($iname)=@{$ref2->[0]};
$useiname .= $iname . "、";
}
@ritem = ();
@ritem = split(/\,/,$result_item);
$username = '';
foreach(@ritem){
$id = $_;
$sql2 = "select name from item_master where id = $id;";
$ref2 = $dbh->selectall_arrayref($sql2) or &err("CODE:B-01 エラーが発生しました。");
($rname)=@{$ref2->[0]};
$username .= $rname . "、";
}
$username = substr($username,0,-2);
$set_time =~ s/\-/\//g;
$plan_list .=<<"EOT";
$username $need_days日 $set_time
EOT
}
if ($plan_list ne ''){
$out{'develop_list'} =<<"EOT";
開発アイテム 開発期間 開発開始日
$plan_list
EOT
}
else{$out{'develop_list'} = "開発中のものはありません。 ";}
$sql = "select a.seq,b.name from item a,item_master b where a.base_seq = $base_seq and a.equip = -2 and a.state = 0 and a.damage_flg = 0 and a.scenario_flg is null and a.id = b.id order by b.id;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-02 エラーが発生しました。");
foreach(@$ref) {
($seq,$name)=@{$_};
$list .=<<"EOT";
$name
EOT
}
if ($list eq ''){$out{'list'} = "基地ロッカーにアイテムがありません。 ";}
else{
$out{'list'} =<<"EOT";
EOT
}
&out_enc;
&html_out("shop_blueprint01.html");
}
#---------------------------------------
# 設計図使用確認
#---------------------------------------
sub blueprint_conf {
&death_check($pcid,$dbh,1);
$sql = "select seq from base where leader = '$pcid' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01 エラーが発生しました。");
($base_seq)=@{$ref->[0]};
if ($base_seq eq ''){&err("この機能は秘密基地の司令官/首領のみ利用できます。");}
@set_item = ();
foreach $key (keys(%in)){
if (substr($key,0,5) eq 'item_' && $in{$key} eq 1){
push set_item,substr($key,5);
}
}
@set_item = sort @set_item;
$set_id_str = '';
@id_ary = ();
foreach(@set_item){
$sql = "select id from item where seq = $_;";
$set_seq .= $_ . ',';
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01 エラーが発生しました。");
($id)=@{$ref->[0]};
push id_ary,$id;
# $set_id_str .= $id . ",";
}
@id_ary = sort @id_ary;
foreach(@id_ary){
$id = $_;
$set_id_str .= $id . ",";
}
if ($set_id_str ne ''){chop $set_id_str;}
else{&err("アイテムが選択されていません。");}
chop $set_seq;
$out{'need_item'} = $set_seq;
$sql = "select result_id,need_base_cp,need_days from joint_master where base_id = '$set_id_str';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01 エラーが発生しました。");
($result_id,$need_base_cp,$need_days)=@{$ref->[0]};
if ($result_id eq ''){&err("適切なアイテムが揃っていません。");}
@result_item = split(/\,/,$result_id);
foreach (@result_item){
$id = $_;
$sql = "select name from item_master where id = $id;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-02 エラーが発生しました。");
($item_name)=@{$ref->[0]};
$reslut_item_name .= "「$item_name」、";
}
if ($reslut_item_name eq ''){&err("適切なアイテムが揃っていません。");}
$reslut_item_name = substr($reslut_item_name,0,-2);
$out{'result'} = $reslut_item_name;
$out{'nday'} = $need_days;
$out{'ncp'} = $need_base_cp / 10;
&out_enc;
&html_out("shop_blueprint02.html");
}
#---------------------------------------
# 開発実行
#---------------------------------------
sub blueprint_start {
&death_check($pcid,$dbh,1);
$sql = "select seq,cp from base where leader = '$pcid' and state = 0;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-01 エラーが発生しました。");
($base_seq,$base_cp)=@{$ref->[0]};
if ($base_seq eq ''){&err("この機能は秘密基地の司令官/首領のみ利用できます。");}
if ($in{'need_item'} eq ''){&err("必要アイテム情報がありません。");}
@id_ary = ();
@nitem = split(/\,/,$in{'need_item'});
foreach (@nitem){
$iseq = $_;
$sql = "select id from item where seq = $iseq and equip = -2 and base_seq = $base_seq;";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-02 エラーが発生しました。");
($item_id)=@{$ref->[0]};
push id_ary,$item_id;
# $item_str .= $item_id . ",";
}
@id_ary = sort @id_ary;
foreach(@id_ary){
$id = $_;
$item_str .= $id . ",";
}
if ($item_str eq ''){&err("アイテムが選択されていません。");}
chop $item_str;
$sql = "select result_id,need_base_cp,need_days from joint_master where base_id = '$item_str';";
$ref = $dbh->selectall_arrayref($sql) or &err("CODE:B-03 エラーが発生しました。");
($result_id,$need_base_cp,$need_days)=@{$ref->[0]};
if ($result_id eq ''){&err("適切なアイテムが揃っていません。");}
if ($base_cp < $need_base_cp){&err("開発に必要な基地CPが不足しています。");}
#&err($result_id);
foreach (@nitem){
$iseq = $_;
$sql = "update item set state = 1 where seq = $iseq;";
$dbh->do($sql) or &err("CODE:B-04 エラーが発生しました。");
}
$sql = "update base set cp = cp - $need_base_cp where seq = $base_seq;";
$dbh->do($sql) or &err("CODE:B-05 エラーが発生しました。");
if ($need_days eq 0){$res = 1;}
else{$res = 0;}
$sql = "insert into joint_plan (use_item,result_item,use_base_cp,need_days,set_time,result_day,result,base_seq) values ('$item_str','$result_id',$need_base_cp,$need_days,now(),now() + '$need_days days',$res,$base_seq);";
$dbh->do($sql) or &err("CODE:B-06 エラーが発生しました。".$dbh->errstr);
if ($res eq 1){
#0日開発時のみ即時アイテム発行
@ritem = split(/\,/,$result_id);
foreach(@ritem){
$id = $_;
$sql = "insert into item (pcid,id,equip,base_seq) values ('$pcid',$id,-2,$base_seq)";
$dbh->do($sql) or &err("CODE:B-07 エラーが発生しました。");
}
$html_file ="shop_blueprint03b.html";
}
else{$html_file = "shop_blueprint03a.html";}
&out_enc;
&html_out($html_file);
}