#------------------#
#  冒険者ギルド報酬 #
#------------------#
sub comp1 {

#############ここから下はプログラムです。分からない人はいじらないほうが無難です。#####################
	

open(IN,"$boukenlog");
@bouken_chara = <IN>;
close(IN);

$hit=0;
foreach(@bouken_chara){
($bii_no,$bii_pass,$iboukennum,$iboukensitu,$iboukenmiss,$ib1,$ib2,$ib3,$ib4,$ib5,$ib6,$ib7,$ib8,$ib9,$ib10,$ib11,$ib12,$ib13,$ib14,$ib15,$ib16,$ib17,$ib18,$ib19,$ib20,$ib21,$ib22,$ib23,$ib24,$ib25,$ib26,$ib27,$ib28,$ib29,$ib30,$ib31,$ib32,$ib33,$ib34,$ib36,$ib37,$ib38,$ib39,$ib40) = split(/<>/);
		if($bii_no eq "$kid") {last;}
}

open(IN,"$bouken_file");
	@item_array = <IN>;
	close(IN);
	foreach(@item_array){
		($rino,$riname,$ridmg,$rigold,$riitem,$ribuki,$ridef,$rihp,$rikn_0,$rikn_1,$rikn_2,$rikn_3,$rikn_4,$rikn_5,$rikn_6) = split(/<>/);
		if($rino eq "$iboukennum") {last;}
         }


$numbouken=$iboukennum;
########不正対策　アイテム倉庫状況判定##########
if($zitemget ==1 and $riitem != 0){
open(IN,"$titemhozon_file");
@bg1 = <IN>;
close(IN);

$hit=0;
foreach(@bg1){
($ei_no,$ei_pass,$e1,$e2,$e3,$e4) = split(/<>/);
if($in{'id'} eq "$ei_no"){ $hit=1;last; }
}

if($e1 == 0){$hit = 2;}
elsif($e2 == 0){$hit = 2;}
elsif($e3 == 0){$hit = 2;}
elsif($e4 == 0){$hit = 2;}
else{&error("アイテムが満杯です!!");} 
if(!$hit) {&error("アイテムが満杯です");}
}

##こっちで武器処理####
if($bukidef == 1 and $ribuki != 0){
open(IN,"$item_chara_file");
@ch = <IN>;
close(IN);

$hit=0;
foreach(@ch){
($eai_no,$eai_name,$eai1,$eai2,$eai3,$eai4,$eai5,$eai6,$eai7,$eai8,$eai9,$eai10,$eai11,$eai12,$eai13,$eai14,$eai15,$eai16,$eai17,$eai18) = split(/<>/);
if($eai_no eq "$kid") {$hit=1;last; }
}
if($eai1 == 0){$hit = 2;}
elsif($eai2 == 0){$hit = 2;}
elsif($eai3 == 0){$hit = 2;}
elsif($eai4 == 0){$hit = 2;}
elsif($eai5 == 0){$hit = 2;}
elsif($eai6 == 0){$hit = 2;}
elsif($eai7 == 0){$hit = 2;}
elsif($eai8 == 0){$hit = 2;}
elsif($eai9 == 0){$hit = 2;}
elsif($eai10 == 0){$hit = 2;}
elsif($eai11 == 0){$hit = 2;}
elsif($eai12 == 0){$hit = 2;}
elsif($eai13 == 0){$hit = 2;}
elsif($eai14 == 0){$hit = 2;}
elsif($eai15 == 0){$hit = 2;}
elsif($eai16 == 0){$hit = 2;}
elsif($eai17 == 0){$hit = 2;}
elsif($eai18 == 0){$hit = 2;}
else{&error("アイテムが満杯です!!");} 
if(!$hit) {&error("アイテムが満杯です");}
}

if($bukidef == 1 and $ridef != 0){
open(IN,"$def_chara_file");
@def_ch = <IN>;
close(IN);

$hit=0;
foreach(@def_ch){
($eefi_no,$eefi_name,$eef1,$eef2,$eef3,$eef4,$eef5,$eef6,$eef7,$eef8,$eef9,$eef10,$eef11,$eef12,$eef13,$eef14,$eef15,$eef16,$eef17,$eef18) = split(/<>/);
if($eefi_no eq "$kid") {$hit=1;last;}
}
if($eef1 == 0){$hit = 2;}
elsif($eef2 == 0){$hit = 2;}
elsif($eef3 == 0){$hit = 2;}
elsif($eef4 == 0){$hit = 2;}
elsif($eef5 == 0){$hit = 2;}
elsif($eef6 == 0){$hit = 2;}
elsif($eef7 == 0){$hit = 2;}
elsif($eef8 == 0){$hit = 2;}
elsif($eef9 == 0){$hit = 2;}
elsif($eef10 == 0){$hit = 2;}
elsif($eef11 == 0){$hit = 2;}
elsif($eef12 == 0){$hit = 2;}
elsif($eef13 == 0){$hit = 2;}
elsif($eef14 == 0){$hit = 2;}
elsif($eef15 == 0){$hit = 2;}
elsif($eef16 == 0){$hit = 2;}
elsif($eef17 == 0){$hit = 2;}
elsif($eef18 == 0){$hit = 2;}
else{&error("アイテムが満杯です!!");} 
if(!$hit) {&error("アイテムが満杯です");}
}

#####不正対策終わり######


#####アイテム処理
if($zitemget==1 and $riitem !=0){
open(IN,"$titemhozon_file");
@item_chara = <IN>;
close(IN);

$hit=0;@item_get=();
foreach(@item_chara){
($zi_no,$zi_pass,$zb1,$zb2,$zb3,$zb4) = split(/<>/);
if($zi_no eq "$kid") {

if($zb1 eq "") {$zb1 = $riitem;}
elsif($zb2 eq "") {$zb2 = $riitem;}
elsif($zb3 eq "") {$zb3 = $riitem;}
elsif($zb4 eq "") {$zb4 = $riitem;}
else{&error("アイテム欄に空きがありません");}

unshift(@item_get,"$zi_no<>$zi_pass<>$zb1<>$zb2<>$zb3<>$zb4<>\n");
$hit=1;
}else{
push(@item_get,"$_");
}
}

if(!$hit){
unshift(@item_get,"$kid<>$kpass<>$riitem<><><><>\n");
}

open(OUT,">$titemhozon_file");
print OUT @item_get;
close(OUT);
}

if($bukidef==1){
##こっちで武器処理
if($ribuki != 0){
open(IN,"$item_chara_file");
@chara = <IN>;
close(IN);

$hit=0;@buki_get=();
foreach(@chara){
($dai_no,$dai_name,$dai1,$dai2,$dai3,$dai4,$dai5,$dai6,$dai7,$dai8,$dai9,$dai10,$dai11,$dai12,$dai13,$dai14,$dai15,$dai16,$dai17,$dai18) = split(/<>/);
if($dai_no eq "$kid") {

if($dai1 eq "") {$dai1 = $ribuki;}
elsif($dai2 eq "") {$dai2 = $ribuki;}
elsif($dai3 eq "") {$dai3 = $ribuki;}
elsif($dai4 eq "") {$dai4 = $ribuki;}
elsif($dai5 eq "") {$dai5 = $ribuki;}
elsif($dai6 eq "") {$dai6 = $ribuki;}
elsif($dai7 eq "") {$dai7 = $ribuki;}
elsif($dai8 eq "") {$dai8 = $ribuki;}
elsif($dai9 eq "") {$dai9 = $ribuki;}
elsif($dai10 eq "") {$dai10 = $ribuki;}
elsif($dai11 eq "") {$dai11 = $ribuki;}
elsif($dai12 eq "") {$dai12 = $ribuki;}
elsif($dai13 eq "") {$dai13 = $ribuki;}
elsif($dai14 eq "") {$dai14 = $ribuki;}
elsif($dai15 eq "") {$dai15 = $ribuki;}
elsif($dai16 eq "") {$dai16 = $ribuki;}
elsif($dai17 eq "") {$dai17 = $ribuki;}
elsif($dai18 eq "") {$dai18 = $ribuki;}
else{&error("アイテム欄に空きがありません");}

unshift(@buki_get,"$dai_no<>$dai_name<>$dai1<>$dai2<>$dai3<>$dai4<>$dai5<>$dai6<>$dai7<>$dai8<>$dai9<>$dai10<>$dai11<>$dai12<>$dai13<>$dai14<>$dai15<>$dai16<>$dai17<>$dai18<>\n");
$hit=1;
}else{
push(@buki_get,"$_");
}
}

if(!$hit){
unshift(@buki_get,"$kid<>$kpass<>$ribuki<><><><><><><><><><><><><><><><><><>\n");
}

open(OUT,">$item_chara_file");
print OUT @buki_get;
close(OUT);
}
###こっちで防具処理
if($ridef != 0){
open(IN,"$def_chara_file");
@def_chara = <IN>;
close(IN);

$hit=0;@def_get=();
foreach(@def_chara){
($defi_no,$defi_name,$def1,$def2,$def3,$def4,$def5,$def6,$def7,$def8,$def9,$def10,$def11,$def12,$def13,$def14,$def15,$def16,$def17,$def18) = split(/<>/);
if($defi_no eq "$kid") {

if($def1 eq "") {$def1 = $ridef;}
elsif($def2 eq "") {$def2 = $ridef;}
elsif($def3 eq "") {$def3 = $ridef;}
elsif($def4 eq "") {$def4 = $ridef;}
elsif($def5 eq "") {$def5 = $ridef;}
elsif($def6 eq "") {$def6 = $ridef;}
elsif($def7 eq "") {$def7 = $ridef;}
elsif($def8 eq "") {$def8 = $ridef;}
elsif($def9 eq "") {$def9 = $ridef;}
elsif($def10 eq "") {$def10 = $ridef;}
elsif($def11 eq "") {$def11 = $ridef;}
elsif($def12 eq "") {$def12 = $ridef;}
elsif($def13 eq "") {$def13 = $ridef;}
elsif($def14 eq "") {$def14 = $ridef;}
elsif($def15 eq "") {$def15 = $ridef;}
elsif($def16 eq "") {$def16 = $ridef;}
elsif($def17 eq "") {$def17 = $ridef;}
elsif($def18 eq "") {$def18 = $ridef;}
else{&error("アイテム欄に空きがありません");}

unshift(@def_get,"$defi_no<>$defi_name<>$def1<>$def2<>$def3<>$def4<>$def5<>$def6<>$def7<>$def8<>$def9<>$def10<>$def11<>$def12<>$def13<>$def14<>$def15<>$def16<>$def17<>$def18<>\n");
$hit=1;
}else{
push(@def_get,"$_");
}
}

if(!$hit){
unshift(@def_get,"$kid<>$kpass<>$ridef<><><><><><><><><><><><><><><><><><>\n");
}

open(OUT,">$def_chara_file");
print OUT @def_get;
close(OUT);
}
}

	open(IN,"./charalog/$in{'id'}.cgi");
	@item_chara = <IN>;

	$hit=0;@item_new=();
foreach(@item_chara){
	($iid,$ipass,$isite,$iurl,$iname,$isex,$ichara,$in_0,$in_1,$in_2,$in_3,$in_4,$in_5,$in_6,$isyoku,$ihp,$imaxhp,$iex,$ilv,$igold,$ilp,$itotal,$ikati,$iwaza,$iitem,$imons,$ihost,$idate,$imori,$idef,$ibouken,$iboukensitu,$iclearbouken,$iitai,$idtai,$iac,$ish,$ikabuto,$iasi,$imanto,$iie,$ikaji,$ikajiexp,$ikajilv,$ilboss,$itest,$isaihou) = split(/<>/);
		if($iid eq "$kid") {
                     $igold=$igold + $rigold;
              if($statusup==1){
                        $imaxhp=$imaxhp+$rihp;
                        $in_0=$in_0+$rikn_0;
                        $in_1=$in_1+$rikn_1;
                        $in_2=$in_2+$rikn_2;
                        $in_3=$in_3+$rikn_3;
                        $in_4=$in_4+$rikn_4;
                        $in_5=$in_5+$rikn_5;
                        $in_6=$in_6+$rikn_6;     
                        }
           		unshift(@item_new,"$iid<>$ipass<>$isite<>$iurl<>$iname<>$isex<>$ichara<>$in_0<>$in_1<>$in_2<>$in_3<>$in_4<>$in_5<>$in_6<>$isyoku<>$imaxhp<>$imaxhp<>$iex<>$ilv<>$igold<>$ilp<>$itotal<>$ikati<>$iwaza<>$iitem<>$imons<>$host<>$idate<>$imori<>$idef<>$ibouken<>$iboukensitu<>$iclearbouken<>$iitai<>$idtai<>$iac<>$ish<>$ikabuto<>$iasi<>$imanto<>$iie<>$ikaji<>$ikajiexp<>$ikajilv<>$ilboss<>$itest<>$isaihou<>\n");
			$hit=1;
		}else{
			push(@item_new,"$_");
		}
	}
	open(OUT,">./charalog/$in{'id'}.cgi");
	print OUT @item_new;
	close(OUT);


}


1;