郑晓宇 6 年之前
父节点
当前提交
9231a1bcc9
共有 4 个文件被更改,包括 27 次插入21 次删除
  1. 14 4
      app/Console/Commands/gamematch.php
  2. 7 16
      app/Console/Commands/robot.php
  3. 5 1
      app/Home/Controllers/GameController.php
  4. 1 0
      app/Jobs/Distribute.php

+ 14 - 4
app/Console/Commands/gamematch.php

@@ -61,15 +61,25 @@ class gamematch extends Command
                         echo "未找到匹配房间\n";
                         continue;
                     }
-                    //获取线机器人
-                    $user = User::inRandomOrder()->select('user_id','name')->where("is_robot",1)->where("is_login",0)->first();
+                    //获取线机器人
+                    $user = User::inRandomOrder()->select('user_id','name','client_id')->where("is_robot",1)->where("is_login", 1)->first();
                     if(!$user){
-                        echo "没有线机器人\n";
+                        echo "没有线机器人\n";
                         sleep(1);
                         continue;
                     }
+                    if(!Gateway::isUidOnline($user->user_id)){
+                        $update_data = [
+                            "is_login" => 0,
+                            "client_id" => '',
+                        ];
+                        //更新机器人登陆状态
+                        User::where("user_id", $user->user_id)->update($update_data);
+                    }
+
                     //发布启动机器人
-                    Redis::publish("startRobot", $user->user_id);
+                    $message['type'] = 'gotomatch';
+                    Gateway::sendToUid($user->user_id, json_encode($message));
                 }
                 sleep(3);
                 $match_times++;

+ 7 - 16
app/Console/Commands/robot.php

@@ -109,12 +109,12 @@ class robot extends Command
                     //更新机器人登陆状态
                     User::where("user_id", $user->user_id)->update($update_data);
                     //启动匹配
-                    $response = $client->request('GET', $http_addr . 'Home/Game/Join',[
-                        'form_params' => [
-                            'client_id' => $client_id,
-                        ]
-                    ]);
-                    echo "{$client_id} 成功加入匹配\n";
+                    // $response = $client->request('GET', $http_addr . 'Home/Game/Join',[
+                    //     'form_params' => [
+                    //         'client_id' => $client_id,
+                    //     ]
+                    // ]);
+                    // echo "{$client_id} 成功加入匹配\n";
                 }
                 //唤起匹配
                 if($json_data->type == 'gotomatch'){
@@ -155,20 +155,11 @@ class robot extends Command
 
                 //结算
                 if($json_data->type == 'game_end'){
-                    $update_data = [
-                        "is_login" => 0,
-                        "client_id" => '',
-                    ];
-                    //更新机器人登陆状态
-                    User::where("user_id", $user->user_id)->update($update_data);
                     unset($update_data);
                     $update_data['state'] = 2;
                     RoomUser::where("user_id", $user->user_id)->where("state", 1)->update($update_data);
-                    echo "已结算,关闭机器人";
+                    echo "已结算,机器人离开房间";
                     Gateway::leaveGroup($client_id, $room_id);
-                    Gateway::unbindUid($client_id, $user->user_id);
-                    Gateway::closeClient($client_id);
-                    $worker->stopAll();
                 }
 
             };

+ 5 - 1
app/Home/Controllers/GameController.php

@@ -120,8 +120,12 @@ class GameController extends Controller
                 "room_id" => $room_id,
             ])->increment('score', $score);
         }
-
+        $total_score = (int) RoomUser::where([
+            "user_id" => $user_id,
+            "room_id" => $room_id,
+        ])->value('score');
         $message['score'] = $score;
+        $message['total_score'] = $total_score;
         $message['user_id'] = $user_id;
         $message['type'] = 'answer';
         Gateway::sendToGroup($room_id, json_encode($message));

+ 1 - 0
app/Jobs/Distribute.php

@@ -69,6 +69,7 @@ class Distribute implements ShouldQueue
             $info['question'] = $question; 
             $info['options'] = $options; 
             $info['start_at'] = $date; 
+            $info['sequence'] = count($questions_id) + 1; 
             $message = [
                 "type" => 'question',
                 "msg" => "获取题目成功",