Commit b955be6b authored by Nemo Ma's avatar Nemo Ma Committed by GitHub

Merge pull request #220 from amarillonmc/codex/create-bot-control-system-in-bothost-v6c6nq

fix: 死亡 BOT 自动退场并按概率补位,避免 bothost 超时空转
parents 66c4558d 12bfdf09
......@@ -11,6 +11,10 @@ require_once $gameRoot.'include/common.inc.php';
require_once GAME_ROOT.'./include/game.func.php';
require_once GAME_ROOT.'./bot/revbot.func.php';
$bot_respawn_chance = isset($_GET['respawn_chance']) ? (int)$_GET['respawn_chance'] : 35;
if($bot_respawn_chance < 0) $bot_respawn_chance = 0;
if($bot_respawn_chance > 100) $bot_respawn_chance = 100;
# 注意:因为进程锁的存在,运行bot脚本时必须确保游戏处于未开始状态
# 否则请先中止游戏,并手动清空lock目录下所有文件,然后确保游戏正处于未开始状态下运行脚本
......@@ -77,14 +81,29 @@ while($id)
{
$flag = bot_acts($id);
if ($flag == 0) {
unset($gamevars['botid'][array_search($id, $gamevars['botid'])]);
$index = array_search($id, $gamevars['botid']);
if($index !== false) unset($gamevars['botid'][$index]);
$roll = mt_rand(1,100);
if($gamestate > 10 && $bot_respawn_chance > 0 && $roll <= $bot_respawn_chance) {
$gamevars['botplayer'] = isset($gamevars['botplayer']) ? (int)$gamevars['botplayer'] + 1 : 1;
echo "BOT:{$id} 已死亡;已加入重生队列。roll={$roll}, chance={$bot_respawn_chance}\n";
} else {
echo "BOT:{$id} 已死亡;不加入重生队列。roll={$roll}, chance={$bot_respawn_chance}\n";
}
save_gameinfo();
save_combatinfo();
if (empty($gamevars['botid'])) break;
ob_end_flush();
break;
}
echo "\nBOT:{$id} 行动完成\n";
ob_end_flush();
}
else
{
echo "BOT:{$id} 不在活动队列,进程退出。\n";
ob_end_flush();
break;
}
sleep(1);
}
else
......
......@@ -42,7 +42,7 @@ python bothost/main.py -c bothost/config.json
- `disable_env_proxy`:是否禁用环境变量中的 HTTP/HTTPS 代理(默认 true,建议保持)。
- `insecure_skip_tls_verify`:是否跳过 TLS 证书校验(默认 false,仅测试环境临时使用)。
- `headers`:额外请求头。
- `query`:附加查询参数。
- `query`:附加查询参数。可加入 `respawn_chance`(0-100)控制 BOT 死亡后的随机补位概率。
## 注意事项
......@@ -58,3 +58,5 @@ python bothost/main.py -c bothost/config.json
- 若出现证书错误,可先确认站点证书链;仅在临时测试中可设 `insecure_skip_tls_verify=true`
-`last_error` 中包含 `include(...common.inc.php): failed to open stream` 等报错,通常是目标站 `bot/revbotservice.php` 在 Web 环境下工作目录不正确;本仓库已修复为基于脚本目录计算 GAME_ROOT。
- 当目标端输出“已死亡;已加入重生队列 / 不加入重生队列”时,bothost 会将该 worker 标记为 `bot_dead_queued` / `bot_dead_retired`,并等待连接退出后自动重连。
......@@ -11,9 +11,11 @@
"disable_env_proxy": true,
"insecure_skip_tls_verify": false,
"headers": {
"User-Agent": "bothost/0.2"
"User-Agent": "bothost/0.3"
},
"query": {}
"query": {
"respawn_chance": "35"
}
}
]
}
......@@ -178,6 +178,15 @@ class BotHost:
state.status = "running"
if "等待中" in line:
state.status = "waiting_lock"
if "已死亡;已加入重生队列" in line:
state.status = "bot_dead_queued"
state.bot_id = None
if "已死亡;不加入重生队列" in line:
state.status = "bot_dead_retired"
state.bot_id = None
if "不在活动队列,进程退出" in line:
state.status = "bot_retired"
state.bot_id = None
low = line.lower()
if "fatal error" in low or "warning:" in low or "uncaught error" in low:
state.last_error = line
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment