This commit is contained in:
syuilo
2024-01-28 17:31:32 +09:00
parent 606c88aa6b
commit db7bd0e94e
9 changed files with 127 additions and 18 deletions

View File

@@ -205,18 +205,23 @@ export interface MahjongRoomEventTypes {
room: Packed<'MahjongRoomDetailed'>;
};
tsumo: {
house: Mahjong.Engine.House;
house: Mahjong.Common.House;
tile: Mahjong.Common.Tile;
};
dahai: {
house: Mahjong.Engine.House;
house: Mahjong.Common.House;
tile: Mahjong.Common.Tile;
};
dahaiAndTsumo: {
house: Mahjong.Engine.House;
dahaiHouse: Mahjong.Common.House;
dahaiTile: Mahjong.Common.Tile;
tsumoTile: Mahjong.Common.Tile;
};
ponned: {
source: Mahjong.Common.House;
target: Mahjong.Common.House;
tile: Mahjong.Common.Tile;
};
}
//#endregion

View File

@@ -412,6 +412,25 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
await this.dahai(room, engine, myHouse, tile);
}
@bindThis
public async op_ron(roomId: MiMahjongGame['id'], user: MiUser) {
const room = await this.getRoom(roomId);
if (room == null) return;
if (room.gameState == null) return;
const engine = new Mahjong.Engine.MasterGameEngine(room.gameState);
const myHouse = user.id === room.user1Id ? engine.state.user1House : user.id === room.user2Id ? engine.state.user2House : user.id === room.user3Id ? engine.state.user3House : engine.state.user4House;
// TODO: 自分にロン回答する権利がある状態かバリデーション
// TODO: この辺の処理はアトミックに行いたいけどJSONサポートはRedis Stackが必要
const current = await this.redisClient.get(`mahjong:gameCallAndRonAsking:${room.id}`);
if (current == null) throw new Error('no asking found');
const currentAnswers = JSON.parse(current) as CallAndRonAnswers;
currentAnswers.ron[myHouse] = true;
await this.redisClient.set(`mahjong:gameCallAndRonAsking:${room.id}`, JSON.stringify(currentAnswers));
}
@bindThis
public async op_pon(roomId: MiMahjongGame['id'], user: MiUser) {
const room = await this.getRoom(roomId);

View File

@@ -39,6 +39,7 @@ class MahjongRoomChannel extends Channel {
case 'updateSettings': this.updateSettings(body.key, body.value); break;
case 'addAi': this.addAi(); break;
case 'dahai': this.dahai(body.tile); break;
case 'ron': this.ron(); break;
case 'pon': this.pon(); break;
case 'nop': this.nop(); break;
case 'claimTimeIsUp': this.claimTimeIsUp(); break;
@@ -73,6 +74,13 @@ class MahjongRoomChannel extends Channel {
this.mahjongService.op_dahai(this.roomId!, this.user, tile);
}
@bindThis
private async ron() {
if (this.user == null) return;
this.mahjongService.op_ron(this.roomId!, this.user);
}
@bindThis
private async pon() {
if (this.user == null) return;