Commit e03b622d authored by hisuinohoshi's avatar hisuinohoshi

rev botservice phase 0.6

变化:
- 为bot脚本添加自动初始化逻辑与进程锁;
- 暂时禁止bot使用礼品盒类道具;
parent f48f7db7
...@@ -41,6 +41,7 @@ gamedata/bak/ ...@@ -41,6 +41,7 @@ gamedata/bak/
gamedata/templates/ gamedata/templates/
templates/default/lastgb.htm templates/default/lastgb.htm
templates/default/lastnews.htm templates/default/lastnews.htm
bot/lock/
# PSD Material # PSD Material
*.psd *.psd
......
@echo off @echo off
PATH=%PATH%;C:\wamp64\bin\php\php7.4.0 PATH=%PATH%;C:\wamp64\bin\php\php7.4.0
php -v php -v
set BOT_CD=2
cd .. cd ..
:loop
php bot/revbotservice.php php bot/revbotservice.php
timeout /t %BOT_CD%
goto loop
\ No newline at end of file
...@@ -315,13 +315,13 @@ function bot_use_items(&$pa) ...@@ -315,13 +315,13 @@ function bot_use_items(&$pa)
continue; continue;
} }
# 礼盒直接开 # 礼盒直接开
if(strpos($pa['itmk'.$i],'p')!==false) /*if(strpos($pa['itmk'.$i],'p')!==false)
{ {
do{ do{
itemuse($i,$pa); itemuse($i,$pa);
}while(!empty($pa['itms'.$i])); }while(!empty($pa['itms'.$i]));
continue; continue;
} }*/
# 技能书、攻防药直接吃 300效以下陷阱直接用 # 技能书、攻防药直接吃 300效以下陷阱直接用
if(strpos($pa['itmk'.$i],'M')===0 || strpos($pa['itmk'.$i],'V')===0 || (strpos($pa['itmk'.$i],'T')===0 && $pa['itme'.$i]<=300) ) if(strpos($pa['itmk'.$i],'M')===0 || strpos($pa['itmk'.$i],'V')===0 || (strpos($pa['itmk'.$i],'T')===0 && $pa['itme'.$i]<=300) )
{ {
......
...@@ -3,39 +3,81 @@ define('CURSCRIPT', 'revbotservice'); ...@@ -3,39 +3,81 @@ define('CURSCRIPT', 'revbotservice');
include './include/common.inc.php'; include './include/common.inc.php';
include GAME_ROOT . './include/game.func.php'; include GAME_ROOT . './include/game.func.php';
include GAME_ROOT . './bot/revbot.func.php'; include GAME_ROOT . './bot/revbot.func.php';
# 注意:因为进程锁的存在,运行bot脚本时必须确保游戏处于未开始状态
# 否则请先中止游戏,并手动清空lock目录下所有文件,然后确保游戏正处于未开始状态下运行脚本
# 进程初始化
bot_prepare_flag:
$id = 0; $id = 0;
if ($gamestate > 10) { $dir = GAME_ROOT.'./bot/lock/';
$ids = bot_player_valid(1); $scdir = scandir($dir);
$id = $ids[0]; # 为进程创建对应编号的进程锁
unset($gamevars['botplayer']); $process_id = $scdir ? count($scdir)-1 : 1;
$gamevars['botid'] = $ids; touch($dir.$process_id.'.lock');
save_gameinfo();
echo "BOT初始化完成,id:" . ($id) . "\n"; while(true)
{
load_gameinfo();
echo "进程id【{$process_id}】正在运行,当前游戏状态:{$gamestate}\n";
ob_end_flush(); ob_end_flush();
} sleep(1);
while (true) { # bot初始化阶段
if ($gamestate > 10) { if ($gamestate > 10 && !empty($gamevars['botplayer']))
var_dump($gamevars['botplayer']); {
if (!empty($gamevars['botplayer'])) { $scdir = scandir($dir);
# bot初始化 # 在这个阶段 进程锁数量应该是与进程id一一对应的,建议先只运行一个脚本校对进程锁数量
# 如果发现进程锁数量与进程id不能对应,则可能是系统原因,文件夹lock内存在其他隐藏文件,记得根据差值自己调整$scnums后面的 + -
$scnums = count($scdir)-2;
echo "当前进程锁数量:".$scnums\n;
ob_end_flush();
# 进程锁数量等于当前编号ID时,才会进行初始化
if($process_id == $scnums)
{
$ids = bot_player_valid(1); $ids = bot_player_valid(1);
$id = $ids[0]; $id = $ids[0];
unset($gamevars['botplayer']); //unset($gamevars['botplayer']);
$gamevars['botid'] = $ids; $gamevars['botid'][] = $id;
$gamevars['botplayer'] --;
save_gameinfo(); save_gameinfo();
echo "BOT初始化完成,id:" . ($id) . "\n"; # 解锁
sleep(1);
unlink($dir.$process_id.'.lock');
echo "BOT初始化完成,id:" . ($id) . "\n剩余待初始化bot数量:{$gamevars['botplayer']}";
ob_end_flush();
goto bot_act_flag;
}
else
{
echo "有其他进程正在进行初始化,等待中...\n";
ob_end_flush(); ob_end_flush();
} elseif (!empty($gamevars['botid'])) { { sleep(1);
$flag = bot_acts($id); }
if ($flag == 0) { }
unset($gamevars['botid'][array_search($botid, $gamevars['botid'])]); }
save_gameinfo();
if (empty($gamevars['botid'])) break; # bot开始行动
} bot_act_flag:
echo "所有BOT行动完成\n"; while($id)
ob_end_flush(); {
load_gameinfo();
if ($gamestate > 10)
{
if (!empty($gamevars['botid']))
{
$flag = bot_acts($id);
if ($flag == 0) {
unset($gamevars['botid'][array_search($botid, $gamevars['botid'])]);
save_gameinfo();
if (empty($gamevars['botid'])) break;
} }
echo "\nBOT:{$id} 行动完成\n";
ob_end_flush();
} }
sleep(2); sleep(1);
}
else
{
goto bot_prepare_flag;
} }
} }
\ No newline at end of file
...@@ -112,7 +112,7 @@ if(CURSCRIPT !== 'chat'){ ...@@ -112,7 +112,7 @@ if(CURSCRIPT !== 'chat'){
addnews($starttime,'newgame',$gamenum); addnews($starttime,'newgame',$gamenum);
systemputchat($starttime,'newgame'); systemputchat($starttime,'newgame');
//是否部署BOT -> 数量; //是否部署BOT -> 数量;
$gamevars['botplayer'] = 1; $gamevars['botplayer'] = 2;
$ginfochange = true; $ginfochange = true;
} }
} }
......
...@@ -305,7 +305,7 @@ function load_gameinfo() { ...@@ -305,7 +305,7 @@ function load_gameinfo() {
$gamevars = json_decode($gamevars,true); $gamevars = json_decode($gamevars,true);
if(isset($gamevars['sanmaact']) && isset($gamevars['sanmadead'])) unset($gamevars['sanmaact']); if(isset($gamevars['sanmaact']) && isset($gamevars['sanmadead'])) unset($gamevars['sanmaact']);
$combonum = $gameinfo['combonum']; $combonum = $gameinfo['combonum'];
return; return Array($gamestate,$gamevars);
} }
function save_gameinfo() { function save_gameinfo() {
......
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