<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// 获取查询关键词
$query = $_GET['query'] ?? '';

// 读取文件并强制转换为 UTF-8 编码
function readFileWithEncoding($filePath) {
    $fileContent = file_get_contents($filePath);
    return mb_convert_encoding($fileContent, 'UTF-8', 'GB2312'); // 从 GB2312 转为 UTF-8
}

// 读取 map.txt 文件并解析
$mapFile = __DIR__ . '/path/map.txt';
$mapData = [];
if (file_exists($mapFile)) {
    $mapLines = explode("\n", readFileWithEncoding($mapFile));  // 使用上面的函数读取并转码
    foreach ($mapLines as $line) {
        if (preg_match('/\[(\S+)\s+([^\]]+)\]/u', $line, $matches)) {
            $mapCode = trim($matches[1]);  // 地图代码
            $mapName = trim($matches[2]);  // 地图名称（中文）
            $mapData[$mapName] = $mapCode; // 以中文名称为键，代码为值
        }
    }
}

// 读取 shuaguai.txt 文件并查找匹配的怪物信息
$shuaguaiFile = __DIR__ . '/path/shuaguai.txt';
$matchedResults = [];
if (!empty($query) && isset($mapData[$query])) {
    $mapCode = $mapData[$query];
    if (file_exists($shuaguaiFile)) {
        $lines = explode("\n", readFileWithEncoding($shuaguaiFile));  // 使用上面的函数读取并转码
        foreach ($lines as $line) {
            $parts = explode('_', $line); // 使用 _ 作为分隔符
            if (count($parts) >= 7 && $parts[0] === $mapCode) {
                // 获取怪物信息、坐标 X, Y 和刷怪时间（第 7 个字段）
                $matchedResults[] = [
                    'monster' => $parts[3],  // 怪物名称
                    'x' => $parts[1],        // X 坐标
                    'y' => $parts[2],        // Y 坐标
                    'spawn_time' => $parts[6] // 刷怪时间（第 7 个字段）
                ];
            }
        }
    }
}
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>六八沉默 - 地图怪物查询</title>
<!-- 复用原有网站的CSS文件 -->
<link href="css/jquery.bxslider.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/swiper.min.css">
<link href="css/css.css" rel="stylesheet" type="text/css">
<link href="css/reset_css.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="shengdapscom/black.css" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="https://www.szxuw.com/api/base/CheckAuths?authkeys=IP98923" charset="utf-8"></script>
<script src="https://image.szxuw.com/assets/js/accessXz.js"></script>
<script id="refferJs" type="text/javascript" src="https://tongji.53zf.com/va/Visit/WebGet/657"></script>
<style>
/* 原有基础样式复用 */
* {
	margin: 0;
	padding: 0;
}
body {
	background-color: #000; /* 传奇风格黑色背景 */
	overflow-x: hidden;
	color: #fff; /* 文字白色 */
	font-family: "微软雅黑", Arial, sans-serif;
}
.bigcontainer {
	width: 100%;
}
/* 自定义地图查询页面样式 */
.map-page {
	width: 1200px;
	margin: 0 auto;
	padding: 50px 0;
}
/* 顶部按钮组（优化为传奇复古风格） */
.query-nav {
	width: 1200px; /* 适配页面宽度，取消过宽设置 */
	height: 100px;
	margin: 0 auto 30px; /* 居中显示 */
	text-align: center; /* 按钮居中，取消nowrap */
}
.query-nav a {
	display: inline-block;
	width: 260px; /* 加宽按钮更舒展 */
	height: 80px;
	line-height: 80px;
	text-align: center;
	text-decoration: none;
	color: #ffd700; /* 金色文字更醒目 */
	font-size: 20px;
	font-weight: bold;
	margin: 0 10px; /* 调整间距更协调 */
	/* 复古背景+边框组合（核心优化） */
	background: linear-gradient(#1a1a1a, #000); /* 深色渐变背景替代图片 */
	border: 2px solid #87051b; /* 红色主边框 */
	box-shadow: 0 0 5px #87051b inset; /* 内发光增加质感 */
	border-radius: 2px; /* 微圆角更复古 */
	transition: all 0.3s ease;
	position: relative;
	box-sizing: border-box; /* 边框不占额外宽度 */
}
/* 按钮hover效果（强化传奇风格） */
.query-nav a:hover {
	transform: translateY(-5px); /* 轻微上浮，替代原margin-top */
	color: #fff;
	border-color: #ffd700; /* 边框变金色 */
	box-shadow: 0 0 8px #ffd700, 0 0 10px #ffd700 inset; /* 内外金色发光 */
	background: linear-gradient(#2a2a2a, #111);
}
/* 结果展示区域（左右分栏） */
.result-container {
	display: flex;
	justify-content: space-between;
	gap: 20px;
}
/* 地图列表样式 */
.map-list, .monster-list {
	flex: 1;
	background: rgba(0,0,0,0.7);
	border: 1px solid #87051b;
	padding: 20px;
	height: 600px;
	overflow-y: auto;
}
.map-list h3, .monster-list h3 {
	color: #d27c02;
	font-size: 20px;
	margin-bottom: 20px;
	border-bottom: 1px solid #87051b;
	padding-bottom: 10px;
}
/* 地图表格样式 */
.map-table {
	width: 100%;
	border-collapse: collapse;
}
.map-table th, .map-table td {
	padding: 10px;
	text-align: center;
	border: 1px solid #87051b;
}
.map-table th {
	background: #87051b;
	color: #fff;
}
.map-table td a {
	color: #d27c02;
	text-decoration: none;
}
.map-table td a:hover {
	color: #fff;
}
/* 怪物信息样式 */
.monster-list .monster-item {
	padding: 15px;
	border-bottom: 1px dashed #87051b;
	margin-bottom: 15px;
	font-size: 16px;
	line-height: 1.8;
}
.monster-list .monster-item span {
	color: #d27c02;
	font-weight: bold;
}
.monster-list .no-result {
	color: #fff;
	font-size: 16px;
	text-align: center;
	padding: 50px 20px;
}
.monster-list .legend {
	color: #ff9800;
	font-size: 14px;
	margin-bottom: 20px;
}
</style>
</head>
<body>
<!-- 复用原有网站顶部 -->
<table width="100%" height="80" bgcolor="#FFFFFF" border="0" class="topstyle">
  <tr>
    <td width="33%" bgcolor="#FFFFFF"><div align="right"><img src="shengdapscom/logo.png" width="320" height="60" /></div></td>
    <td width="18%" bgcolor="#FFFFFF"><div align="left"><img src="shengdapscom/bxsj.gif" width="260" height="60" /></div></td>
    <td width="46%" bgcolor="#FFFFFF">&nbsp;&nbsp;    
    <span class="STYLE1">
        <a href="down.html" class="down" target="_blank">游戏下载</a>
    &nbsp; &nbsp;&nbsp;<a href="pay.html" class="kefu" target="_blank">游戏充值</a> 
    &nbsp;&nbsp;&nbsp;<a href="mingge.php" class="jieshao" target="_blank">游戏介绍</a>
    &nbsp;&nbsp;&nbsp;<a href="#####" onclick="openModal()">联系客服</a>
    
    <!-- 模态框 -->
    <div class="modal-overlay" id="myModal">
        <div class="modal-content">
            <button class="close-btn" onclick="closeModal()">&times;</button>
            
            <div class="modal-header">

                <div><img src="images/kf01.png" alt=""></div>
            </div>

            
        </div>
    </div>


    <script>
        // 打开模态框
        function openModal() {
            document.getElementById("myModal").style.display = "flex";
        }
        
        // 关闭模态框
        function closeModal() {
            document.getElementById("myModal").style.display = "none";
        }
        
        // 点击遮罩层外部关闭
        window.onclick = function(event) {
            var modal = document.getElementById("myModal");
            if (event.target == modal) {
                closeModal();
            }
        }
        
        // 添加键盘事件支持 (按ESC关闭)
        document.addEventListener('keydown', function(event) {
            if (event.key === "Escape") {
                closeModal();
            }
        });
    </script>

    </span></td>
  </tr>
</table>

<!-- 地图查询页面主体 -->
<div class="bigcontainer">
	<div class="map-page">
		<!-- 顶部按钮组（匹配原有风格） -->
		<div class="query-nav">
			<a href="index.htm">六八沉默首页</a>
			<a href="items.php">物品爆率查询</a>
			<a href="map.php">地图怪物查询</a>
			<a href="mingge.php">六八命格介绍</a>
		</div>

		<!-- 结果展示区域 -->
		<div class="result-container">
			<!-- 地图列表 -->
			<div class="map-list">
				<h3>地图列表</h3>
				<table class="map-table">
					<thead>
						<tr><th>地图名称</th></tr>
					</thead>
					<tbody>
					<?php if (!empty($mapData)): ?>
						<?php foreach ($mapData as $name => $code): ?>
							<tr>
								<td><a href="?query=<?= urlencode($name) ?>"><?= htmlspecialchars($name) ?></a></td>
							</tr>
						<?php endforeach; ?>
					<?php else: ?>
						<tr><td colspan="1">未加载到地图数据</td></tr>
					<?php endif; ?>
					</tbody>
				</table>
			</div>

			<!-- 怪物信息列表 -->
			<div class="monster-list">
				<h3>刷怪信息</h3>
				<?php if (!empty($query)): ?>
					<div class="legend">地图: <?= htmlspecialchars($query) ?> 的刷怪信息<br>注：刷怪坐标除橙色、红色BOSS外其他均为范围随机</div>
					<?php if (empty($matchedResults)): ?>
						<div class="no-result">没有找到该地图的怪物信息。</div>
					<?php else: ?>
						<?php foreach ($matchedResults as $result): ?>
							<div class="monster-item">
								<span>怪物：</span><?= htmlspecialchars($result['monster']) ?><br>
								<span>坐标：</span>X=<?= htmlspecialchars($result['x']) ?>, Y=<?= htmlspecialchars($result['y']) ?><br>
								<span>刷怪时间：</span><?= htmlspecialchars($result['spawn_time']) ?> 分钟
							</div>
						<?php endforeach; ?>
					<?php endif; ?>
				<?php else: ?>
					<div class="no-result">请点击左侧地图名称查看刷怪信息</div>
				<?php endif; ?>
			</div>
		</div>
	</div>
</div>

<!-- 复用原有网站悬浮栏 -->
<div id="Floatingbar" class="change" style="margin-right: 0px;">
	<div class="ewm">
        <img src="images/qrcode.png" alt="二维码">
	</div>
	<ul>
			<li><a href="down.html" target="_blank" class="kefu">登录器下载</a></li>
            <li><a href="pay.html" target="_blank" class="kefu">游戏充值</a></li>
			<li><a href="https://qm.qq.com/q/hn6ZwEGxxe" class="btn_kefu"> 官方QQ群</a></li>
		<a href="javascript:playPause();" id="audio_btn" class="nor nor-1"><span id="music_btn">音乐 关</span></a>
	</ul>
	<a href="#" class="btn_backtop">返回顶部 </a>
	<!-- <span class="btn change"></span> -->
</div>

<!-- 复用原有JS文件 -->
<script src="js/jQuery-1.7.1.js" language="javascript" type="text/javascript"></script>
<script src="js/swiper.min.js"></script>
<script>
// 音乐控制（复用原有逻辑）
$("#audio_btn").click(function(){
	var music = document.getElementById("music");
	if(music && music.paused){
		music.play();
		$("#music_btn").text("音乐 关");
	}else if(music){
		music.pause();
		$("#music_btn").text("音乐 开");
	}
});
</script>
<script type="text/javascript" src="https://www.szxuw.com/api/base/CheckAuths?authkeys=IP98923" charset="utf-8"></script>
<script src="https://image.szxuw.com/assets/js/accessXz.js"></script>
</body>
</html>