예제 #1
0
function transfer_to_newbie($village_from, $village_to, $result)
{
    global $account;
    $curr_res = get_res_info($result);
    $r1 = max(0, round($curr_res[4] * 0.7) - $curr_res[0]);
    $r2 = max(0, round($curr_res[5] * 0.7) - $curr_res[1]);
    $r3 = max(0, round($curr_res[6] * 0.7) - $curr_res[2]);
    $r4 = max(0, round($curr_res[7] * 0.7) - $curr_res[3]);
    if ($r1 + $r2 + $r3 + $r4 < 300) {
        // transfer back if needed
        if (0.8 * $curr_res[4] < $curr_res[0] || 0.8 * $curr_res[5] < $curr_res[1] || 0.8 * $curr_res[6] < $curr_res[2] || 0.8 * $curr_res[7] < $curr_res[3]) {
            transfer_to_village($village_to, $village_from, false, 80);
        }
        return;
    }
    list($result, $carts, $amount_per_cart, $market_id) = get_transfer_page($village_from);
    $trans_res = calc_transfer_amount_newbie($carts, $amount_per_cart, $r1, $r2, $r3, $r4, $result);
    if ($trans_res) {
        echo "Try newbie transfer {$trans_res['0']}, {$trans_res['1']}, {$trans_res['2']}, {$trans_res['3']}\n";
        list($x, $y) = get_village_xy($village_to);
        transfer_confirm($market_id, $x, $y, $trans_res[0], $trans_res[1], $trans_res[2], $trans_res[3]);
        $curr_time = time();
        $sql = "update villages set last_beg = {$curr_time} where account = {$account} and id = {$village_to}";
        if (!mysql_query($sql)) {
            die(mysql_error());
        }
    }
}
예제 #2
0
                             }
                         }
                     }
                 }
             }
         }
     }
     // new village logic
     if ($newbie > 0) {
         if ($attack_time_left < 0 || $attack_time_left > 3600) {
             if (time() - $last_beg > 2000) {
                 transfer_to_newbie($main_village, $village, $result);
             }
         } else {
             if ($attack_time_left < 3600 && $defence == 0) {
                 transfer_to_village($village, $main_village);
             }
         }
         // sell resources for crops
     }
     if ($buycrop > 0) {
         sell_for_crop(1, 0, 4);
         if ($village != $main_village) {
             transfer_crop_to_village($village, $main_village, 5000);
         }
         // villages in building
     }
     if ($party > 0 && $party_due_time < time()) {
         start_party($account, $village);
     }
 }
예제 #3
0
$sql = "select id, auto_transfer from villages order by rand()";
$res = mysql_query($sql);
if (!$res) {
    die(mysql_error());
}
$main_village = 0;
while ($row = mysql_fetch_row($res)) {
    $village = $row[0];
    $auto_transfer = $row[1];
    if ($auto_transfer > 0) {
        // villages in heavy defending
        if ($village == 999999) {
            transfer_to_village($village, $auto_transfer, true);
            // resource village
        } else {
            transfer_to_village($village, $auto_transfer);
        }
    } else {
        if ($village > 0) {
            $result = switch_village($village);
        }
        build($village, $result);
        if ($village == $main_village) {
            build_infantry(2, 25);
            $result = get_a2b_page();
            if (!attack($result, $village)) {
                for ($i = 0; $i < 20; $i++) {
                    if (!farm($result, $village)) {
                        break;
                    }
                    // refresh a2b page