Esempio n. 1
0
function xenobehunter()
{
    // Setup general Variables
    global $playerinfo, $targetlink, $xenobeisdead, $db;
    $rescount = $db->Execute("SELECT COUNT(*) AS num_players FROM {$db->prefix}ships WHERE ship_destroyed='N' AND email NOT LIKE '%@xenobe' AND ship_id > 1");
    db_op_result($db, $rescount, __LINE__, __FILE__);
    $rowcount = $rescount->fields;
    $topnum = min(10, $rowcount['num_players']);
    // If we have killed all the players in the game then stop here.
    if ($topnum < 1) {
        return;
    }
    $res = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_destroyed='N' AND email NOT LIKE '%@xenobe' AND ship_id > 1 ORDER BY score DESC LIMIT ?", array($topnum));
    db_op_result($db, $res, __LINE__, __FILE__);
    // Choose a target from the top player list
    $i = 1;
    $targetnum = mt_rand(1, $topnum);
    while (!$res->EOF) {
        if ($i == $targetnum) {
            $targetinfo = $res->fields;
        }
        $i++;
        $res->MoveNext();
    }
    // Make sure we have a target
    if (!$targetinfo) {
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "Hunt Failed: No Target ");
        return;
    }
    // Jump to target sector
    $sectres = $db->Execute("SELECT sector_id, zone_id FROM {$db->prefix}universe WHERE sector_id=?", array($targetinfo['sector']));
    db_op_result($db, $sectres, __LINE__, __FILE__);
    $sectrow = $sectres->fields;
    $zoneres = $db->Execute("SELECT zone_id,allow_attack FROM {$db->prefix}zones WHERE zone_id=?", array($sectrow['zone_id']));
    db_op_result($db, $zoneres, __LINE__, __FILE__);
    $zonerow = $zoneres->fields;
    // Only travel there if we can attack in the target sector
    if ($zonerow['allow_attack'] == "Y") {
        $stamp = date("Y-m-d H-i-s");
        $move_result = $db->Execute("UPDATE {$db->prefix}ships SET last_login=?, turns_used=turns_used+1, sector=? WHERE ship_id=?", array($stamp, $targetinfo['sector'], $playerinfo['ship_id']));
        db_op_result($db, $move_result, __LINE__, __FILE__);
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "Xenobe used a wormhole to warp to sector {$targetinfo['sector']} where he is hunting player {$targetinfo['character_name']}.");
        if (!$move_result) {
            $error = $db->ErrorMsg();
            playerlog($db, $playerinfo[ship_id], LOG_RAW, "Move failed with error: {$error} ");
            return;
        }
        // Check for sector defences
        $resultf = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? AND defence_type ='F' ORDER BY quantity DESC", array($targetinfo['sector']));
        db_op_result($db, $resultf, __LINE__, __FILE__);
        $i = 0;
        $total_sector_fighters = 0;
        if ($resultf > 0) {
            while (!$resultf->EOF) {
                $defences[$i] = $resultf->fields;
                $total_sector_fighters += $defences[$i]['quantity'];
                $i++;
                $resultf->MoveNext();
            }
        }
        $resultm = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? AND defence_type ='M'", array($targetinfo['sector']));
        db_op_result($db, $resultm, __LINE__, __FILE__);
        $i = 0;
        $total_sector_mines = 0;
        if ($resultm > 0) {
            while (!$resultm->EOF) {
                $defences[$i] = $resultm->fields;
                $total_sector_mines += $defences[$i]['quantity'];
                $i++;
                $resultm->MoveNext();
            }
        }
        if ($total_sector_fighters > 0 || $total_sector_mines > 0 || $total_sector_fighters > 0 && $total_sector_mines > 0) {
            // Attack sector defences
            $targetlink = $targetinfo['sector'];
            xenobetosecdef();
        }
        if ($xenobeisdead > 0) {
            return;
            // Sector defenses killed the Xenobe
        }
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "Xenobe launching an attack on {$targetinfo['character_name']}.");
        // Attack the target
        if ($targetinfo['planet_id'] > 0) {
            xenobetoplanet($targetinfo['planet_id']);
            // Yes, so move to that planet
        } else {
            xenobetoship($targetinfo['ship_id']);
            // Not on a planet, so move to the ship
        }
    } else {
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "Xenobe hunt failed, target {$targetinfo['character_name']} was in a no attack zone (sector {$targetinfo['sector']}).");
    }
}
Esempio n. 2
0
function xenobemove()
{
    global $playerinfo, $sector_max, $targetlink, $xenobeisdead, $db;
    // Obtain a target link
    if ($targetlink == $playerinfo['sector']) {
        $targetlink = 0;
    }
    $linkres = $db->Execute("SELECT * FROM {$db->prefix}links WHERE link_start=?", array($playerinfo['sector']));
    db_op_result($db, $linkres, __LINE__, __FILE__);
    if ($linkres > 0) {
        while (!$linkres->EOF) {
            $row = $linkres->fields;
            // Obtain sector information
            $sectres = $db->Execute("SELECT sector_id,zone_id FROM {$db->prefix}universe WHERE sector_id=?", array($row['link_dest']));
            db_op_result($db, $sectres, __LINE__, __FILE__);
            $sectrow = $sectres->fields;
            $zoneres = $db->Execute("SELECT zone_id,allow_attack FROM {$db->prefix}zones WHERE zone_id=?", array($sectrow['zone_id']));
            db_op_result($db, $zoneres, __LINE__, __FILE__);
            $zonerow = $zoneres->fields;
            if ($zonerow['allow_attack'] == "Y") {
                $setlink = mt_rand(0, 2);
                // 33% Chance of replacing destination link with this one
                if ($setlink == 0 || !$targetlink > 0) {
                    $targetlink = $row['link_dest'];
                }
            }
            $linkres->MoveNext();
        }
    }
    if (!$targetlink > 0) {
        $wormto = mt_rand(1, $sector_max - 15);
        // Generate a random sector number
        $limitloop = 1;
        // Limit the number of loops
        while (!$targetlink > 0 && $limitloop < 15) {
            // Obtain sector information
            $sectres = $db->Execute("SELECT sector_id,zone_id FROM {$db->prefix}universe WHERE sector_id=?", array($wormto));
            db_op_result($db, $sectres, __LINE__, __FILE__);
            $sectrow = $sectres->fields;
            $zoneres = $db->Execute("SELECT zone_id,allow_attack FROM {$db->prefix}zones WHERE zone_id=?", array($sectrow['zone_id']));
            db_op_result($db, $zoneres, __LINE__, __FILE__);
            $zonerow = $zoneres->fields;
            if ($zonerow['allow_attack'] == "Y") {
                $targetlink = $wormto;
                playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Used a wormhole to warp to a zone where attacks are allowed.");
            }
            $wormto++;
            $wormto++;
            $limitloop++;
        }
    }
    if ($targetlink > 0) {
        $resultf = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? and defence_type ='F' ORDER BY quantity DESC", array($targetlink));
        db_op_result($db, $resultf, __LINE__, __FILE__);
        $i = 0;
        $total_sector_fighters = 0;
        if ($resultf > 0) {
            while (!$resultf->EOF) {
                $defences[$i] = $resultf->fields;
                $total_sector_fighters += $defences[$i]['quantity'];
                $i++;
                $resultf->MoveNext();
            }
        }
        $resultm = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? and defence_type ='M'", array($targetlink));
        db_op_result($db, $resultm, __LINE__, __FILE__);
        $i = 0;
        $total_sector_mines = 0;
        if ($resultm > 0) {
            while (!$resultm->EOF) {
                $defences[$i] = $resultm->fields;
                $total_sector_mines += $defences[$i]['quantity'];
                $i++;
                $resultm->MoveNext();
            }
        }
        if ($total_sector_fighters > 0 || $total_sector_mines > 0 || $total_sector_fighters > 0 && $total_sector_mines > 0) {
            if ($playerinfo['aggression'] == 2 || $playerinfo['aggression'] == 1) {
                xenobetosecdef();
                // Attack sector defences
                return;
            } else {
                playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Move failed, the sector is defended by {$total_sector_fighters} fighters and {$total_sector_mines} mines.");
                return;
            }
        }
    }
    if ($targetlink > 0) {
        $stamp = date("Y-m-d H-i-s");
        $move_result = $db->Execute("UPDATE {$db->prefix}ships SET last_login=?, turns_used=turns_used+1, sector=? WHERE ship_id=?", array($stamp, $targetlink, $playerinfo['ship_id']));
        db_op_result($db, $move_result, __LINE__, __FILE__);
        if (!$move_result) {
            $error = $db->ErrorMsg();
            playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Move failed with error: {$error} ");
        }
    } else {
        playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Move failed due to lack of target link.");
        // We have no target link for some reason
        $targetlink = $playerinfo['sector'];
        // Reset target link so it is not zero
    }
}