xiongzhu 2 年 前
コミット
a0f23a7469
6 ファイル変更743 行追加13 行削除
  1. 5 0
      handlebars.js
  2. 1 0
      package.json
  3. 5 0
      src/game/game.controller.ts
  4. 20 7
      src/game/game.service.ts
  5. 8 0
      src/sys-config/sys-config.service.ts
  6. 704 6
      yarn.lock

+ 5 - 0
handlebars.js

@@ -0,0 +1,5 @@
+"use strict";
+exports.__esModule = true;
+var handlebars = require("handlebars");
+var t = handlebars.compile('Hello {{name}}');
+console.log(t({ name: 'world' }));

+ 1 - 0
package.json

@@ -58,6 +58,7 @@
     "express-basic-auth": "^1.2.1",
     "express-handlebars": "^7.0.6",
     "handlebars": "^4.7.7",
+    "handlebars-helpers": "^0.10.0",
     "hbs": "^4.2.0",
     "http-proxy-agent": "^7.0.0",
     "https-proxy-agent": "^7.0.2",

+ 5 - 0
src/game/game.controller.ts

@@ -79,4 +79,9 @@ export class GameController {
     public async stopRun(@Param('id') id: string) {
         return await this.gameService.stopRun(Number(id))
     }
+
+    @Post('/:id/reset')
+    public async reset(@Param('id') id: string) {
+        return await this.gameService.manualResetGame(Number(id))
+    }
 }

+ 20 - 7
src/game/game.service.ts

@@ -634,13 +634,17 @@ export class GameService implements OnModuleInit {
                 lastState: undefined
             })
         )
-        this.send(`${game.id}`, {
-            type: 'reset',
-            data: {
-                newGameId: newGame.id,
-                firstState: newState
-            }
+        const resetDelay = await this.sysConfig.getNumber('reset_delay', 0)
+        setTimeout(resetDelay * 1000).then(() => {
+            this.send(`${game.id}`, {
+                type: 'reset',
+                data: {
+                    newGameId: newGame.id,
+                    firstState: newState
+                }
+            })
         })
+
         await this.gameRepository.update(newGame.id, { currentState: newState.id })
         await this.roomService.setCurrentGameId(game.roomId, newGame.id)
 
@@ -651,6 +655,15 @@ export class GameService implements OnModuleInit {
         return newGame
     }
 
+    async manualResetGame(id: number) {
+        const game = await this.findById(id)
+        if (this.controllers.has(game.roomId)) {
+            await this.stopRun(id)
+        }
+        await this.gameRepository.update(id, { status: GameStatus.Finished })
+        return await this.resetGame(id)
+    }
+
     async startRun(id: number) {
         this.logger.log(`开始运行: ${id}`)
         const game = await this.findById(id)
@@ -792,7 +805,7 @@ export class GameService implements OnModuleInit {
                 const output = await parser.parse(response.content.replace('+', '').replace("'", '"'))
                 return output.map((i) => {
                     i.modifyHp = i.modifyHp.filter(
-                        (j) => j.changeValue !== 0 && charactors.find((k) => k.name === j.name)
+                        (j) => j.changeValue !== 0 && false === charactors.find((k) => k.name === j.name)?.dead
                     )
                     return i as PlotOption
                 })

+ 8 - 0
src/sys-config/sys-config.service.ts

@@ -38,6 +38,14 @@ export class SysConfigService implements OnModuleInit {
                 remark: '加入游戏弹幕规则'
             })
         }
+        if (!(await this.sysConfigRepository.findOneBy({ name: 'reset_delay' }))) {
+            await this.sysConfigRepository.save({
+                name: 'reset_delay',
+                value: '60',
+                type: SysConfigType.Number,
+                remark: '重置延迟'
+            })
+        }
     }
 
     async findAll(req: PageRequest<SysConfig>) {

ファイルの差分が大きいため隠しています
+ 704 - 6
yarn.lock


この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません