Exemple #1
0
function farm($result, $village)
{
    global $server;
    $url = "http://{$server}/a2b.php";
    $min_clubs = 5;
    // How many clubs there ?
    // onClick="document.snd.t1.value=1; return false;
    if (!preg_match('/onClick="document\\.snd\\.t1\\.value=([0-9]+); return false;/', $result, $matches)) {
        echo "no club there.\n";
        return false;
    }
    $curr_clubs = $matches[1];
    echo $curr_clubs . " clubs.\n";
    if ($curr_clubs < $min_clubs) {
        echo "no enough clubs (min).\n";
        return false;
    }
    // Get a target
    $sql = "SELECT x, y, `raid` FROM `targets` WHERE `village` = {$village} and `invalid` = 0 and NOW() > date_add(`timestamp`, INTERVAL (`interval` * 70) MINUTE) order by date_add(`timestamp`, INTERVAL (`interval` * 70) MINUTE) limit 1";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        echo "Warning: too many clubs. {$village} \n";
        return false;
    }
    $target_x = $row[0];
    $target_y = $row[1];
    $raid = $row[2];
    if ($raid == 0) {
        $clubs = $min_clubs;
    } else {
        $clubs = $min_clubs * $raid;
    }
    echo $row[0] . " , " . $row[1] . "\n";
    if ($curr_clubs < $clubs) {
        echo "no enough clubs. {$clubs}\n";
        return false;
    }
    if ($curr_clubs < $clubs + $min_clubs) {
        $clubs = $curr_clubs;
    }
    // Update the target
    $sql = "update `targets` set `timestamp` = now() where x = " . $target_x . " and y = " . $target_y;
    mysql_query($sql);
    if (attack_func($target_x, $target_y, $clubs, '', '', '', '', '', $result)) {
        return $clubs < $curr_clubs;
    }
    return true;
}
Exemple #2
0
function attack($result, $village)
{
    global $server;
    global $account;
    $url = "http://{$server}/a2b.php";
    $server_hour = get_server_hour($result);
    // echo "Current hour : " . $server_hour . "\n";
    $start = $server_hour == 0 ? 23 : $server_hour - 1;
    $stop = $server_hour == 23 ? 0 : $server_hour + 1;
    $sql = "select x, y, min_clubs, `recursive`, `seq`, `ram` from mission where account = {$account} and village = {$village} and TO_DAYS(now()) > `recursive` and `hour` in (" . $start . "," . $server_hour . "," . $stop . ") order by `recursive`";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        // echo "No mission.\n";
        return false;
    }
    $target_x = $row[0];
    $target_y = $row[1];
    $min_clubs = $row[2];
    $recursive = $row[3];
    $seq = $row[4];
    $with_ram = $row[5];
    echo "Mission : (" . $row[0] . " , " . $row[1] . ") with " . $min_clubs . " clubs\n";
    //		if(being_attacked()){
    //			echo "Cancel mission.\n";
    //			return false;
    //		}
    // How many clubs there ?
    // onClick="document.snd.t1.value=1; return false;
    if (!preg_match('/on[cC]lick="document\\.snd\\.t1\\.value=([0-9]+); return false;/', $result, $matches)) {
        echo "no club for mission .\n";
        return true;
    }
    $curr_clubs = $matches[1];
    echo $curr_clubs . " clubs.\n";
    if ($curr_clubs < $min_clubs) {
        echo "no enough clubs for mission.\n";
        return true;
    }
    $axes = '';
    $tks = '';
    $hero = '';
    $rams = '';
    if ($recursive > 0) {
        // update the mission
        $sql = "update mission set `recursive` = TO_DAYS(now()) where `seq` = " . $seq;
        if (!mysql_query($sql)) {
            die(mysql_error());
        }
        // daily farm
        $clubs = $min_clubs;
    } else {
        // uniq mission, need all clubs, axes, tks and hero
        // onClick="document.snd.t11.value=1; return false;"
        if (preg_match('/on[cC]lick="document\\.snd\\.t11\\.value=1; return false;/', $result, $matches)) {
            $hero = 1;
        } else {
            echo "Hero does NOT in home.\n";
            return true;
        }
        // onClick="document.snd.t3.value=1; return false;
        if (!preg_match('/on[cC]lick="document\\.snd\\.t3\\.value=([0-9]+); return false;/', $result, $matches)) {
            $axes = 0;
        } else {
            $axes = $matches[1];
        }
        // onClick="document.snd.t6.value=1; return false;
        if (!preg_match('/on[cC]lick="document\\.snd\\.t6\\.value=([0-9]+); return false;/', $result, $matches)) {
            $tks = 0;
        } else {
            $tks = $matches[1];
        }
        // ram
        if ($with_ram == 1) {
            // onClick="document.snd.t7.value=1; return false;
            if (preg_match('/on[cC]lick="document\\.snd\\.t7\\.value=([0-9]+); return false;/', $result, $matches)) {
                $rams = $matches[1];
            }
        }
        // Delete the mission
        $sql = "delete from mission where `seq` = " . $seq;
        if (!mysql_query($sql)) {
            die(mysql_error());
        }
        $clubs = $curr_clubs;
    }
    attack_func($target_x, $target_y, $clubs, $axes, $tks, $rams, '', $hero, $result);
    return true;
}
Exemple #3
0
function avoid_attack_teutonic($x, $y)
{
    $result = get_a2b_page();
    $troops = get_troops($result);
    $attack_types = array(1, 3, 6, 7, 8, 11);
    $total = 0;
    foreach ($troops as $t => $num) {
        if (in_array($t, $attack_types)) {
            $total += $num;
        }
    }
    if ($total < 50) {
        return;
    }
    $t1 = '';
    $t3 = '';
    $t6 = '';
    $t7 = '';
    $t8 = '';
    $t11 = '';
    foreach ($troops as $t => $num) {
        if ($t == 1) {
            $t1 = $num;
        } else {
            if ($t == 3) {
                $t3 = $num;
            } else {
                if ($t == 6) {
                    $t6 = $num;
                } else {
                    if ($t == 7) {
                        $t7 = $num;
                    } else {
                        if ($t == 8) {
                            $t8 = $num;
                        } else {
                            if ($t == 11) {
                                $t11 = $num;
                            }
                        }
                    }
                }
            }
        }
    }
    attack_func($x, $y, $t1, $t3, $t6, $t7, $t8, $t11, $result);
}
Exemple #4
0
function farm($result, $village)
{
    global $server;
    global $account;
    global $farm_lo, $farm_hi;
    global $village_x, $village_y;
    $url = "http://{$server}/a2b.php";
    $max_clubs = $farm_hi;
    $min_clubs = $farm_lo;
    $troops = get_troops($result);
    $curr_clubs = 0;
    $curr_axes = 0;
    $curr_tks = 0;
    if (isset($troops[1])) {
        $curr_clubs = $troops[1];
    }
    if (isset($troops[3])) {
        $curr_axes = $troops[3];
    }
    if (isset($troops[6])) {
        $curr_tks = $troops[6];
    }
    if ($curr_clubs < $min_clubs && $curr_axes < $min_clubs && $curr_tks < $min_clubs) {
        return false;
    }
    echo "{$curr_clubs} clubs, {$curr_axes} axes, {$curr_tks} tks availabe.\n";
    // Get a target
    $sql = "SELECT x, y, `raid`, `score`, `player` FROM `targets` WHERE account = {$account} and `village` = {$village} and `invalid` = 0 and NOW() > `timestamp` order by (sqrt((x - {$village_x}) * (x - {$village_x}) + (y - {$village_y}) * (y - {$village_y}))) / IF(avg_score=0, 1, avg_score) limit 1";
    echo $sql . "\n";
    $res = mysql_query($sql);
    if (!$res) {
        die(mysql_error());
    }
    $row = mysql_fetch_row($res);
    if (!$row) {
        echo "Warning: too many clubs. {$village} \n";
        return false;
    }
    $target_x = $row[0];
    $target_y = $row[1];
    $raid = $row[2];
    $score_str = $row[3];
    $player = $row[4];
    $score = calc_score($score_str);
    echo "Average score:  {$score} \n";
    $old_min_clubs = $min_clubs;
    if ($raid > 1) {
        $min_clubs = $min_clubs * $raid;
        $max_clubs = $max_clubs * $raid;
    }
    echo "Want to raid : (" . $row[0] . " , " . $row[1] . ")\n";
    if ($curr_clubs < $min_clubs && $curr_axes < $min_clubs && $curr_tks < $min_clubs) {
        echo "no enough troops. {$min_clubs} \n";
        return false;
    }
    $clubs = '';
    $axes = '';
    $tks = '';
    if ($curr_clubs >= $min_clubs) {
        if ($curr_clubs <= $max_clubs) {
            $clubs = $curr_clubs;
        } else {
            $clubs = $min_clubs + round(($max_clubs - $min_clubs) * $score * $score / 10000);
            if ($curr_clubs - $clubs < $old_min_clubs) {
                $clubs = $curr_clubs;
            }
        }
    } else {
        if ($curr_axes >= $min_clubs) {
            if ($curr_axes <= $max_clubs) {
                $axes = $curr_axes;
            } else {
                $axes = $min_clubs + round(($max_clubs - $min_clubs) * $score * $score / 10000);
                if ($curr_axes - $axes < $old_min_clubs) {
                    $axes = $curr_axes;
                }
            }
        } else {
            if ($curr_tks >= $min_clubs) {
                if ($curr_tks <= $max_clubs) {
                    $tks = $curr_tks;
                } else {
                    $tks = $min_clubs + round(($max_clubs - $min_clubs) * $score * $score / 10000);
                    if ($curr_axes - $tks < $old_min_clubs) {
                        $tks = $curr_tks;
                    }
                }
            }
        }
    }
    $distance = sqrt(($target_x - $village_x) * ($target_x - $village_x) + ($target_y - $village_y) * ($target_y - $village_y));
    echo "distance: {$distance}\n";
    $second_cost = round($distance / 5 * 3600);
    echo "second_cost: {$second_cost}\n";
    $second_cost = max($second_cost, 198 * 60);
    $next_raid_interval = rand($second_cost, 2 * $second_cost);
    echo "next_raid_interval: {$next_raid_interval}\n";
    // Update the target
    $sql = "update `targets` set `timestamp` = FROM_UNIXTIME(unix_timestamp(now()) + {$next_raid_interval}) where account = {$account} and x = " . $target_x . " and y = " . $target_y;
    mysql_query($sql);
    if (attack_func($target_x, $target_y, $clubs, $axes, $tks, '', '', '', $result, $player)) {
        return $curr_clubs - intval($clubs) >= $old_min_clubs || $curr_axes - intval($axes) >= $old_min_clubs || $curr_tks - intval($tks) >= $old_min_clubs;
    }
    return true;
}