wip
This commit is contained in:
parent
10a112489d
commit
c964c49c58
|
@ -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
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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'],
|
||||||
|
|
Loading…
Reference in a new issue