Transistor 發表於 2017-3-16 17:17:25

複數買賣船隻

之前幫達海寫的

買船的

yard.cgi
.............................
.............................

print qq|造船所:購入  |;
&submit_button;
print qq|<div align=right>購買數:<input type=text name=quan size=3 value=1></div>|;

.............................
.............................
# Sub Buy Ship #
sub buy_ship {

.............................
.............................

          ($goods,$kind,$goods_img,$sale_area,$sale_port,$volume,$ship_hp,$knot,$price)
         = split(/<>/, $yardline[$F{'goods'}] );
          if($kind == 1 ){$price *= $F{'quan'};}
          if ( $sale_area !~ /$area/ && $sale_port !~ /$port/ ) { &play("發生錯誤"); exit }
          &price_up;
          my $ship_number = $#ship_ind + $F{'quan'};
          if ( $money < $price ) { &play("資金不足"); exit }
          if ( $ship_number > 16 && $kind == 1 ) { &play("船艦數大於17艘,無法再購買"); exit}
          if ( $kind == 1 && $ship_number <= 16 ) {
               for ($i = 0; $i < $F{'quan'}; $i++) {
                        push(@ship_ind , "$goods_img,$volume,$ship_hp,$knot,$goods");
                        &msg("購入$goods");
                        &add_record("以$price G購入$goods")
                }
         }





賣船的



sub yard_sell {
.............................

.............................

.............................

.............................

.............................

.............................

      for ($i = 0; $i <= $#ship_ind; $i++) {
                ($price) = map{ (split(/<>/)) } grep {$ship[$i] eq (split(/<>/,$_))} @yardline;
                $price = int($price / 2);                                             
                $checked = $i == 0 ? ' checked' : '';
                print qq|<input type=checkbox name=goods$i value="$i">|;
                print qq|$ship[$i]:$price G<br>\n|;
                print qq|[積載:$ship[$i] 耐久:$ship[$i] 速度:$ship[$i]]<br>|;
      }
.............................

.............................

.............................

}






sub sell_ship {
      &get_me($F{'id'});
      if ($action ne $F{'reload'}) { &play; exit }
      &ship_data;
      &fleet;
      &load_data;
      
      my @sell_ship_array =            
      ($F{'goods0'},$F{'goods1'},$F{'goods2'},$F{'goods3'},$F{'goods4'},$F{'goods5'},$F{'goods6'},$F{'goods7'},                         $F{'goods8'},$F{'goods9'},$F{'goods10'},$F{'goods11'},$F{'goods12'},$F{'goods13'},$F{'goods14'},
      $F{'goods15'},$F{'goods16'});
      my $total_ship_capacity = 0;
      my $sell_ship_count = 0;
      my $total_ship_number = $#ship_ind;











      for ($i = 0; $i <= $total_ship_number; $i++){
      if(defined $sell_ship_array[$i]){
      $total_ship_capacity += $ship[$sell_ship_array[$i]];
      }
      }

      if ( ($total - $total_load - $food - $sailor - $total_ship_capacity) < 0 ) {
                &play("剩餘的容量不足");
                return
      }
      
      for ($i = 0; $i <= $total_ship_number; $i++){
                if(defined $sell_ship_array[$i]){
                $action = '';
                my $YardFile = new Nfile("$datadir/$yarddat",'read');
                my @yardline = $YardFile->read;
                ($price) = map{ (split(/<>/)) } grep {$ship[$sell_ship_array[$i]] eq (split(/<>/,$_))} @yardline;
                splice(@ship_ind , $sell_ship_array[$i] - $sell_ship_count ,1);
                my $upmoney = int($price / 2);
                $money += $upmoney;
                &msg("售出$ship[$sell_ship_array[$i]]");
                &add_record("以$upmoney G售出$ship[$sell_ship_array[$i]      ]");
                $sell_ship_count++;
                }
               
      }
      &play;
}

Transistor 發表於 2017-3-17 15:46:23

print qq|</td></tr><tr><td align=left>\n|;
print qq|<div align=right>購買數:<input type=text name=quan size=3 value=1></div>|;

這樣放版面會比較漂亮:lol

barl1989 發表於 2017-3-18 10:36:51

發現異常,買100艘小船,結果船隻數量超出極限17艘。
而且,訊息顯示的價格也有點不對,只是小船,為什麼一艘船會顯示到一萬二千?。

以600 G售出輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船
以120000 G購入輕木帆船

Transistor 發表於 2017-3-18 11:54:42

          my $ship_number = $#ship_ind + $F{'quan'};
          if ( $money < $price ) { &play("資金不足"); exit }
          if ( $ship_number > 16 && $kind == 1 ) { &play("船艦數大於17艘,無法再購買"); exit}

這幾行你有貼嗎??   我是正常在達海也正常的


至於價錢顯示的是總數不是個數

Transistor 發表於 2017-3-18 11:59:29

另外賣船出現兩個按鈕

print qq|<input type=checkbox name=goods$i value="$i">|;
print qq|<input type=radio name=goods value="$i"$checked>|;<<<<要把這個刪掉!!

Transistor 發表於 2017-3-18 12:22:42

我把整個程式搬過來了...
管理員你麻煩看看哪邊不一樣


# Sub Buy Yard #
sub yard_buy {
        my $YardFile = new Nfile("$datadir/$yarddat",'read');
        my @yardline = $YardFile->read;
        &form_table('up','100%',1);
        &reload;
        print qq|造船所:購入  |;
        &submit_button;
        print qq|</td></tr><tr><td align=left>\n|;
        print qq|<div align=left>船數:<input type=text name=quan size=3 value=1></div>|;
        foreach (0 .. $#yardline) {
                ($goods,$kind,$goods_img,$sale_area,$sale_port,$volume,$ship_hp,$knot,$price)
                = split(/<>/,$yardline[$_]);
                if ($sale_area =~ /$area/ || $sale_port =~ /$port/) {
                        $checked = !$first ? ' checked' : '';
                        $first = 1;
                        &price_up;
                        print qq|<input type=radio name=goods value="$_"$checked>|;
                        print qq|<img src="$img/$goods_img" height=15>$goods:$price G<br>|;
                        if ($kind == 1) {
                                print qq|[積載:$volume 耐久:$ship_hp 速度:$knot]<br>\n|;
                        }
                        elsif ($kind == 2) {
                                print qq|戰鬥力+$volume<br>\n|;
                        }
                        elsif ($kind == 3) {
                                print qq|指揮力+$volume<br>\n|;
                        }
                        elsif ($kind == 4) {
                                print qq|航海力+$volume<br>\n|;
                        }
                }
        }
        print qq|<input type=hidden name=yard value="1"><input type=hidden name=mode value="buy_ship">\n|;
        &id_ps;
        &form_table('down');
}

# Sub Price Up #
sub price_up {
        if ($kind == 2 || $kind == 3 || $kind ==4) {
                my $rate = $atk + $cmd + $nav;
                $price = int($price * exp($rate * 0.03 - 3))
        }
}

# Sub Buy Ship #
sub buy_ship {
        &get_me($F{'id'});
        if ($action ne $F{'reload'}) { &play; exit }
        &get_port($area,$port);
        &ship_data;
        my $YardFile = new Nfile("$datadir/$yarddat",'read');
        my @yardline = $YardFile->read;
        ($goods,$kind,$goods_img,$sale_area,$sale_port,$volume,$ship_hp,$knot,$price)
       = split(/<>/, $yardline[$F{'goods'}] );
        if($kind == 1 ){$price *= $F{'quan'};}
        if ( $sale_area !~ /$area/ && $sale_port !~ /$port/ ) { &play("發生錯誤"); exit }
        &price_up;
        my $ship_number = $#ship_ind + $F{'quan'};
        if ( $money < $price ) { &play("資金不足"); exit }
        if ( $ship_number > 16 && $kind == 1 ) { &play("船艦數已滿,無法再購買"); exit}
        if ( $kind == 1 && $ship_number <= 16 ) {
                for ($i = 0; $i < $F{'quan'}; $i++) {
                push(@ship_ind , "$goods_img,$volume,$ship_hp,$knot,$goods");
                &msg("購入$goods");
                &add_record("以$price G購入$goods")
                }
        }
        elsif ( $kind == 2 ) {
                if ($atk >= $atk_limit) { &play("已至極限,無法再強化"); exit }
                $atk += $volume;
                &msg("武裝強化");
                &add_record("戰鬥力 + $volume")
        }
        elsif ( $kind == 3 ) {
                if ($cmd >= $cmd_limit) { &play("已至極限,無法再強化"); exit }
                $cmd += $volume;
                &msg("指揮力提高了");
                &add_record("指揮力 + $volume")
        }
        elsif ( $kind == 4 ) {
                if ($nav >= $nav_limit) { &play("已至極限,無法再強化"); exit }
                $nav += $volume;
                &msg("航海力提高了");
                &add_record("航海力 + $volume")
        }
        $action = '';
        $money -= $price;
        &play;
}

# Sub Yard Sell #
sub yard_sell {
        if ( $#ship_ind < 0) { print qq|你已經沒有船了|; &return_button; return }
        my $YardFile = new Nfile("$datadir/$yarddat",'read');
        my @yardline = $YardFile->read;
        &form_table('up','100%',1);
        &reload;
        print qq|造船所:售出  |;
        &submit_button;
        print qq|</td></tr><tr><td align=left>\n|;
        for ($i = 0; $i <= $#ship_ind; $i++) {
                ($price) = map{ (split(/<>/)) } grep {$ship[$i] eq (split(/<>/,$_))} @yardline;
                $price = int($price / 2);
                print qq|<input type=checkbox name=goods$i value="$i">|;
                print qq|$ship[$i]:$price G<br>\n|;
                print qq|[積載:$ship[$i] 耐久:$ship[$i] 速度:$ship[$i]]<br>|;
        }
        print qq||;
        print qq|<input type=hidden name=yard value="2"><input type=hidden name=mode value="sell_ship">\n|;
        &id_ps;
        &form_table('down');
}

# Sub Sell Ship #
sub sell_ship {
        &get_me($F{'id'});
        if ($action ne $F{'reload'}) { &play; exit }
        &ship_data;
        &fleet;
        &load_data;
        @sell_ship_array = ($F{'goods0'},$F{'goods1'},$F{'goods2'},$F{'goods3'},$F{'goods4'},$F{'goods5'},$F{'goods6'},$F{'goods7'},$F{'goods8'},$F{'goods9'},
        $F{'goods10'},$F{'goods11'},$F{'goods12'},$F{'goods13'},$F{'goods14'},$F{'goods15'},$F{'goods16'});
        my $total_ship_capacity = 0;
        my $sell_ship_count = 0;
        my $total_ship_number = $#ship_ind;
        for ($i = 0; $i <= $total_ship_number; $i++){
                if(defined $sell_ship_array[$i]){$total_ship_capacity += $ship[$sell_ship_array[$i]];}
        }

        if ( ($total - $total_load - $food - $sailor - $total_ship_capacity) < 0 ) {
                &play("剩餘的容量不足");
                return
        }
       
        for ($i = 0; $i <= $total_ship_number; $i++){
                if(defined $sell_ship_array[$i]){
                $action = '';
                my $YardFile = new Nfile("$datadir/$yarddat",'read');
                my @yardline = $YardFile->read;
                ($price) = map{ (split(/<>/)) } grep {$ship[$sell_ship_array[$i]] eq (split(/<>/,$_))} @yardline;
                splice(@ship_ind , $sell_ship_array[$i] - $sell_ship_count ,1);
                my $upmoney = int($price / 2);
                $money += $upmoney;
                &msg("售出$ship[$sell_ship_array[$i]]");
                &add_record("以$upmoney G售出$ship[$sell_ship_array[$i]        ]");
                $sell_ship_count++;
                }
        }
        &play;
}

teng 發表於 2017-3-18 13:52:43

台中人大大, 你加進去的時候# Sub Yard Sell #
sub yard_sell {的部份


是把print qq|<input type=radio name=goods value="$i"$checked>|;改成print qq|<input type=checkbox name=goods$i value="$i">|; #############不是加,是改

至於 無限買的原因是:        if ( $#ship_ind == 16 && $kind == 1 ) { &play("船艦數已滿,無法再購買"); exit}
       
        if ( $kind == 1 && $#ship_ind < 16 ) {                ##################
                push(@ship_ind , "$goods_img,$volume,$ship_hp,$knot,$goods");
                &msg("購入$goods");
                &add_record("以$price G購入$goods")
        }
要改成          if ( $ship_number > 16 && $kind == 1 ) { &play("船艦數大於17艘,無法再購買"); exit}

          if ( $kind == 1 && $ship_number <= 16 ) {                                               
               for ($i = 0; $i < $F{'quan'}; $i++) {                                               
                        push(@ship_ind , "$goods_img,$volume,$ship_hp,$knot,$goods");               
                        &msg("購入$goods");                                                       
                        &add_record("以$price G購入$goods")                                       
                }                                                                               
        }        還請台中人大大還原到一天前, 有些玩家測試BUG 的時候買了一大堆船了=口=

Transistor 發表於 2017-3-18 17:11:47

if ($F{'quan'} =~ /[^0-9]/) { &play("輸入的數值錯誤");exit }
if($kind == 1 ){$price *= $F{'quan'};}

忘了補上這條...避免用小數點購船

o9270537 發表於 2017-3-18 21:13:50

建議改回來原先的原始碼吧 免得問題又發生..
船隻才17艘 多點幾次 佔不了多少時間..:L

Transistor 發表於 2017-3-18 22:00:56

其實原始碼沒問題

有問題是套用....
頁: [1]
查看完整版本: 複數買賣船隻