This commit is contained in:
syuilo 2024-02-01 20:34:05 +09:00
parent 10a112489d
commit c964c49c58
3 changed files with 59 additions and 7 deletions

View file

@ -511,6 +511,24 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
await this.dahai(room, engine, myHouse, tile, riichi); await this.dahai(room, engine, myHouse, tile, riichi);
} }
@bindThis
public async commit_ankan(roomId: MiMahjongGame['id'], user: MiUser, tile: string) {
const room = await this.getRoom(roomId);
if (room == null) return;
if (room.gameState == null) return;
const engine = new Mahjong.MasterGameEngine(room.gameState);
const myHouse = getHouseOfUserId(room, engine, user.id);
await this.clearTurnWaitingTimer(room.id);
const res = engine.commit_ankan(myHouse, tile);
this.globalEventService.publishMahjongRoomStream(room.id, 'ankanned', { });
this.waitForTurn(room, myHouse, engine);
}
@bindThis @bindThis
public async commit_kakan(roomId: MiMahjongGame['id'], user: MiUser) { public async commit_kakan(roomId: MiMahjongGame['id'], user: MiUser) {
const room = await this.getRoom(roomId); const room = await this.getRoom(roomId);
@ -599,7 +617,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
} }
/** /**
* () * ()
* *
* NOTE: 時間切れチェックが行われたときにタイミングによっては次のwaitingが始まっている場合があることを考慮しSetに一意のIDを格納する構造としている * NOTE: 時間切れチェックが行われたときにタイミングによっては次のwaitingが始まっている場合があることを考慮しSetに一意のIDを格納する構造としている
* @param room * @param room
@ -642,7 +660,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
} }
/** /**
* () * ()
* @param roomId * @param roomId
*/ */
@bindThis @bindThis

View file

@ -213,6 +213,10 @@ export class MasterGameEngine {
return this.state.handTiles[house].filter(t => t === tile).length === 2; return this.state.handTiles[house].filter(t => t === tile).length === 2;
} }
private canCii(house: House, tile: Tile): boolean {
// TODO
}
public getHouse(index: 1 | 2 | 3 | 4): House { public getHouse(index: 1 | 2 | 3 | 4): House {
switch (index) { switch (index) {
case 1: return this.state.user1House; case 1: return this.state.user1House;
@ -376,7 +380,35 @@ export class MasterGameEngine {
}; };
} }
public commit_kakan(house: House) { public commit_kakan(house: House, tile: Tile) {
const pon = this.state.huros[house].find(h => h.type === 'pon' && h.tile === tile);
if (pon == null) throw new Error('No such pon');
this.state.handTiles[house].splice(this.state.handTiles[house].indexOf(tile), 1);
this.state.huros[house].push({ type: 'minkan', tile, from: pon.from });
this.state.activatedDorasCount++;
const rinsyan = this.tsumo();
return {
rinsyan,
};
}
public commit_ankan(house: House, tile: Tile) {
this.state.handTiles[house].splice(this.state.handTiles[house].indexOf(tile), 1);
this.state.handTiles[house].splice(this.state.handTiles[house].indexOf(tile), 1);
this.state.handTiles[house].splice(this.state.handTiles[house].indexOf(tile), 1);
this.state.handTiles[house].splice(this.state.handTiles[house].indexOf(tile), 1);
this.state.huros[house].push({ type: 'ankan', tile });
this.state.activatedDorasCount++;
const rinsyan = this.tsumo();
return {
rinsyan,
};
} }
/** /**
@ -408,7 +440,7 @@ export class MasterGameEngine {
public commit_resolveCallAndRonInterruption(answers: { public commit_resolveCallAndRonInterruption(answers: {
pon: boolean; pon: boolean;
cii: boolean; cii: false | [Tile, Tile];
kan: boolean; kan: boolean;
ron: House[]; ron: House[];
}) { }) {
@ -467,14 +499,16 @@ export class MasterGameEngine {
}; };
} else if (cii != null && answers.cii) { } else if (cii != null && answers.cii) {
const tile = this.state.hoTiles[cii.callee].pop()!; const tile = this.state.hoTiles[cii.callee].pop()!;
this.state.huros[cii.caller].push({ type: 'cii', tile, from: cii.callee }); this.state.handTiles[cii.caller].splice(this.state.handTiles[cii.caller].indexOf(answers.cii[0]), 1);
this.state.handTiles[cii.caller].splice(this.state.handTiles[cii.caller].indexOf(answers.cii[1]), 1);
this.state.huros[cii.caller].push({ type: 'cii', tiles: [tile, answers.cii[0], answers.cii[1]], from: cii.callee });
this.state.turn = cii.caller; this.state.turn = cii.caller;
return { return {
type: 'ciied' as const, type: 'ciied' as const,
caller: cii.caller, caller: cii.caller,
callee: cii.callee, callee: cii.callee,
tile, tiles: [tile, answers.cii[0], answers.cii[1]],
turn: this.state.turn, turn: this.state.turn,
}; };
} else if (this.state.tiles.length === 0) { } else if (this.state.tiles.length === 0) {

View file

@ -43,7 +43,7 @@ type HoraSet = {
mentsus: [Tile, Tile, Tile][]; mentsus: [Tile, Tile, Tile][];
}; };
const SHUNTU_PATTERNS: [Tile, Tile, Tile][] = [ export const SHUNTU_PATTERNS: [Tile, Tile, Tile][] = [
['m1', 'm2', 'm3'], ['m1', 'm2', 'm3'],
['m2', 'm3', 'm4'], ['m2', 'm3', 'm4'],
['m3', 'm4', 'm5'], ['m3', 'm4', 'm5'],