From a0b5efdba5b9103ba2047cbedc6e1e0ef9126851 Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Thu, 25 Jul 2019 21:28:47 +0800 Subject: [PATCH] 1 --- webapp/controller/MatchController.class.php | 48 +++++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/webapp/controller/MatchController.class.php b/webapp/controller/MatchController.class.php index 8834d9f..ab8b133 100644 --- a/webapp/controller/MatchController.class.php +++ b/webapp/controller/MatchController.class.php @@ -15,6 +15,18 @@ class MatchController{ return $r; } + protected function getParameter($para_id) + { + $parameter_meta_cluster = require('../res/parameter@parameter.php'); + $parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id); + $p = array( + 'id' => $parameter_meta['id'], + 'param_name' => $parameter_meta['param_name'], + 'param_value' => $parameter_meta['param_value'], + ); + return $p; + } + protected function getRobot($robot_id, $num) { $address = '../res/robot@robot' . $num . '.php'; @@ -122,23 +134,31 @@ class MatchController{ } else if (count($room_db['member_list']) < 10) { //判断是否添加机器人 if ($flag == 1) { + $p_min = $this->getParameter(16); + $min_num = $p_min['param_value']; + $p_max = $this->getParameter(17); + $max_num = $p_max['param_value']; + $randrobot_num = Rand($min_num, $max_num); + $robot_num = min((10 - count($room_db['member_list'])), $randrobot_num); if (time() >= $join_time + $room_db['last_join_time']) { - //添加机器人 - $num = count($room_db['member_list']); - $random = Rand(1, 100); - $robot_id = 1000 + ($num - 1) * 100 + $random; - $rob = $this->getRobot($robot_id, $num); - $tank_id = Rand(1, 9) + 15000; - array_push ($room_db['member_list'], array( - 'account_id' => $rob['id'], - 'name' => $rob['name'], - 'avatar_url' => $rob['avatar_url'], - 'tank_id' => $tank_id, - 'tankskin_id' => 0 - )); + for ($i = 0; $i < $robot_num; $i++) { + //添加机器人 + $num = count($room_db['member_list']); + $random = Rand(1, 100); + $robot_id = 1000 + ($num - 1) * 100 + $random; + $rob = $this->getRobot($robot_id, $num); + $tank_id = Rand(1, 9) + 15000; + array_push ($room_db['member_list'], array( + 'account_id' => $rob['id'], + 'name' => $rob['name'], + 'avatar_url' => $rob['avatar_url'], + 'tank_id' => $tank_id, + 'tankskin_id' => 0 + )); + } $room_db['last_join_time'] = time(); } - } else { + } else { //加入房间 array_push ($room_db['member_list'], array( 'account_id' => $_REQUEST['account_id'],