wip
This commit is contained in:
		| @@ -280,28 +280,18 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit { | ||||
|  | ||||
| 		room.gameState = Mmj.MasterGameEngine.createInitialState(); | ||||
| 		room.isStarted = true; | ||||
|  | ||||
| 		await this.saveRoom(room); | ||||
|  | ||||
| 		this.globalEventService.publishMahjongRoomStream(room.id, 'started', { room: room }); | ||||
|  | ||||
| 		return room; | ||||
| 		this.kyokuStarted(room); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	public async packRoom(room: Room, me: MiUser) { | ||||
| 		if (room.gameState) { | ||||
| 			const mj = new Mmj.MasterGameEngine(room.gameState); | ||||
| 			const myIndex = room.user1Id === me.id ? 1 : room.user2Id === me.id ? 2 : room.user3Id === me.id ? 3 : 4; | ||||
| 			return { | ||||
| 				...room, | ||||
| 				gameState: mj.createPlayerState(myIndex), | ||||
| 			}; | ||||
| 		} else { | ||||
| 			return { | ||||
| 				...room, | ||||
| 			}; | ||||
| 		} | ||||
| 	private kyokuStarted(room: Room) { | ||||
| 		const mj = new Mmj.MasterGameEngine(room.gameState); | ||||
|  | ||||
| 		this.waitForTurn(room, mj.turn, mj); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| @@ -379,6 +369,17 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit { | ||||
| 		}, 2000); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	private async nextKyoku(room: Room, mj: Mmj.MasterGameEngine) { | ||||
| 		const res = mj.commit_nextKyoku(); | ||||
| 		room.gameState = mj.getState(); | ||||
| 		await this.saveRoom(room); | ||||
| 		this.globalEventService.publishMahjongRoomStream(room.id, 'nextKyoku', { | ||||
| 			room: room, | ||||
| 		}); | ||||
| 		this.kyokuStarted(room); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	private async dahai(room: Room, mj: Mmj.MasterGameEngine, house: Mmj.House, tile: Mmj.TileId, riichi = false) { | ||||
| 		const res = mj.commit_dahai(house, tile, riichi); | ||||
| @@ -551,6 +552,8 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit { | ||||
| 		await this.saveRoom(room); | ||||
|  | ||||
| 		this.globalEventService.publishMahjongRoomStream(room.id, 'tsumoHora', { house: myHouse, handTiles: res.handTiles, tsumoTile: res.tsumoTile }); | ||||
|  | ||||
| 		this.endKyoku(room, mj); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| @@ -700,6 +703,27 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit { | ||||
| 		await this.redisClient.del(`mahjong:gameTurnWaiting:${roomId}`); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	public packState(room: Room, me: MiUser) { | ||||
| 		const mj = new Mmj.MasterGameEngine(room.gameState); | ||||
| 		const myIndex = room.user1Id === me.id ? 1 : room.user2Id === me.id ? 2 : room.user3Id === me.id ? 3 : 4; | ||||
| 		return mj.createPlayerState(myIndex); | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	public async packRoom(room: Room, me: MiUser) { | ||||
| 		if (room.gameState) { | ||||
| 			return { | ||||
| 				...room, | ||||
| 				gameState: this.packState(room, me), | ||||
| 			}; | ||||
| 		} else { | ||||
| 			return { | ||||
| 				...room, | ||||
| 			}; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	@bindThis | ||||
| 	public dispose(): void { | ||||
| 	} | ||||
|   | ||||
| @@ -40,6 +40,11 @@ class MahjongRoomChannel extends Channel { | ||||
| 			this.send('started', { | ||||
| 				room: packed, | ||||
| 			}); | ||||
| 		} else if (message.type === 'nextKyoku') { | ||||
| 			const packed = this.mahjongService.packState(message.body.room, this.user!); | ||||
| 			this.send('nextKyoku', { | ||||
| 				state: packed, | ||||
| 			}); | ||||
| 		} else { | ||||
| 			this.send(message.type, message.body); | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo