public static function xenobeHunter(\PDO $pdo_db, \ADODB_mysqli $db, array $playerinfo, $xenobeisdead, array $langvars, Reg $tkireg) { $targetinfo = array(); $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"); \Tki\Db::LogDbErrors($pdo_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->SelectLimit("SELECT * FROM {$db->prefix}ships WHERE ship_destroyed='N' AND email NOT LIKE '%@xenobe' AND ship_id > 1 ORDER BY score DESC", $topnum); \Tki\Db::LogDbErrors($pdo_db, $res, __LINE__, __FILE__); // Choose a target from the top player list $i = 1; $targetnum = random_int(1, $topnum); while (!$res->EOF) { if ($i == $targetnum) { $targetinfo = $res->fields; } $i++; $res->MoveNext(); } // Make sure we have a target if (!$targetinfo) { \Tki\PlayerLog::WriteLog($pdo_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'])); \Tki\Db::LogDbErrors($pdo_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'])); \Tki\Db::LogDbErrors($pdo_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'])); \Tki\Db::LogDbErrors($pdo_db, $move_result, __LINE__, __FILE__); \Tki\PlayerLog::WriteLog($pdo_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(); \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Move failed with error: {$error} "); return; } // Check for sector defenses $i = 0; $all_sector_fighters = 0; $defenses = array(); $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id = :sector_id AND defense_type = 'F' ORDER BY quantity DESC"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $targetinfo['sector']); $stmt->execute(); $defenses_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($defenses_present !== null) { foreach ($defenses_present as $tmp_defense) { $defenses[$i] = $tmp_defense; $all_sector_fighters += $defenses[$i]['quantity']; $i++; } } $i = 0; $total_sector_mines = 0; $sql = "SELECT * FROM ::prefix::sector_defense WHERE sector_id = :sector_id AND defense_type = 'M'"; $stmt = $pdo_db->prepare($sql); $stmt->bindParam(':sector_id', $targetinfo['sector']); $stmt->execute(); $defenses_present = $stmt->fetchAll(\PDO::FETCH_ASSOC); if ($defenses_present !== null) { foreach ($defenses_present as $tmp_defense) { $defenses[$i] = $tmp_defense; $total_sector_mines += $defenses[$i]['quantity']; $i++; } } if ($all_sector_fighters > 0 || $total_sector_mines > 0 || $all_sector_fighters > 0 && $total_sector_mines > 0) { // Attack sector defenses $targetlink = $targetinfo['sector']; self::xenobeToSecDef($pdo_db, $db, $langvars, $playerinfo, $targetlink, $tkireg); } if ($xenobeisdead > 0) { return; // Sector defenses killed the Xenobe } \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Xenobe launching an attack on {$targetinfo['character_name']}."); // Attack the target if ($targetinfo['planet_id'] > 0) { self::xenobeToPlanet($pdo_db, $db, $targetinfo['planet_id'], $tkireg, $playerinfo, $langvars); // Yes, so move to that planet } else { self::xenobeToShip($pdo_db, $db, $targetinfo['ship_id'], $tkireg, $playerinfo, $langvars); // Not on a planet, so move to the ship } } else { \Tki\PlayerLog::WriteLog($pdo_db, $playerinfo['ship_id'], LOG_RAW, "Xenobe hunt failed, target {$targetinfo['character_name']} was in a no attack zone (sector {$targetinfo['sector']})."); } }