This commit is contained in:
syuilo 2024-02-03 13:52:13 +09:00
parent 7cdaa10d46
commit 2dd886e285
10 changed files with 351 additions and 133 deletions

View file

@ -215,11 +215,13 @@ export interface MahjongRoomEventTypes {
dahai: { dahai: {
house: Mahjong.Common.House; house: Mahjong.Common.House;
tile: Mahjong.Common.Tile; tile: Mahjong.Common.Tile;
riichi: boolean;
}; };
dahaiAndTsumo: { dahaiAndTsumo: {
dahaiHouse: Mahjong.Common.House; dahaiHouse: Mahjong.Common.House;
dahaiTile: Mahjong.Common.Tile; dahaiTile: Mahjong.Common.Tile;
tsumoTile: Mahjong.Common.Tile; tsumoTile: Mahjong.Common.Tile;
riichi: boolean;
}; };
ponned: { ponned: {
caller: Mahjong.Common.House; caller: Mahjong.Common.House;

View file

@ -26,7 +26,7 @@ import { ReversiGameEntityService } from './entities/ReversiGameEntityService.js
import type { OnApplicationShutdown, OnModuleInit } from '@nestjs/common'; import type { OnApplicationShutdown, OnModuleInit } from '@nestjs/common';
const INVITATION_TIMEOUT_MS = 1000 * 20; // 20sec const INVITATION_TIMEOUT_MS = 1000 * 20; // 20sec
const CALL_AND_RON_ASKING_TIMEOUT_MS = 1000 * 5; // 5sec const CALL_AND_RON_ASKING_TIMEOUT_MS = 1000 * 7; // 7sec
const TURN_TIMEOUT_MS = 1000 * 30; // 30sec const TURN_TIMEOUT_MS = 1000 * 30; // 30sec
const NEXT_KYOKU_CONFIRMATION_TIMEOUT_MS = 1000 * 15; // 15sec const NEXT_KYOKU_CONFIRMATION_TIMEOUT_MS = 1000 * 15; // 15sec
@ -318,7 +318,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
switch (res.type) { switch (res.type) {
case 'tsumo': case 'tsumo':
this.globalEventService.publishMahjongRoomStream(room.id, 'tsumo', { house: res.house, tile: res.tile }); this.globalEventService.publishMahjongRoomStream(room.id, 'tsumo', { house: res.house, tile: res.tile });
this.next(room, engine); this.waitForTurn(room, res.turn, engine);
break; break;
case 'ponned': case 'ponned':
this.globalEventService.publishMahjongRoomStream(room.id, 'ponned', { caller: res.caller, callee: res.callee, tile: res.tile }); this.globalEventService.publishMahjongRoomStream(room.id, 'ponned', { caller: res.caller, callee: res.callee, tile: res.tile });
@ -349,23 +349,6 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
} }
} }
@bindThis
private async next(room: Room, engine: Mahjong.MasterGameEngine) {
const turn = engine.state.turn;
if (turn == null) throw new Error('turn is null');
const aiHouses = [[1, room.user1Ai], [2, room.user2Ai], [3, room.user3Ai], [4, room.user4Ai]].filter(([id, ai]) => ai).map(([id, ai]) => engine.getHouse(id));
if (aiHouses.includes(turn)) {
// TODO: ちゃんと思考するようにする
setTimeout(() => {
this.dahai(room, engine, turn, engine.state.handTiles[turn].at(-1));
}, 500);
} else {
this.waitForTurn(room, turn, engine);
}
}
@bindThis @bindThis
private async endKyoku(room: Room, engine: Mahjong.MasterGameEngine) { private async endKyoku(room: Room, engine: Mahjong.MasterGameEngine) {
const confirmation: NextKyokuConfirmation = { const confirmation: NextKyokuConfirmation = {
@ -469,11 +452,11 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
} }
}, 1000); }, 1000);
this.globalEventService.publishMahjongRoomStream(room.id, 'dahai', { house: house, tile }); this.globalEventService.publishMahjongRoomStream(room.id, 'dahai', { house: house, tile, riichi });
} else { } else {
this.globalEventService.publishMahjongRoomStream(room.id, 'dahaiAndTsumo', { dahaiHouse: house, dahaiTile: tile, tsumoTile: res.tsumoTile }); this.globalEventService.publishMahjongRoomStream(room.id, 'dahaiAndTsumo', { dahaiHouse: house, dahaiTile: tile, tsumoTile: res.tsumoTile, riichi });
this.next(room, engine); this.waitForTurn(room, res.next, engine);
} }
} }
@ -556,7 +539,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
const res = engine.commit_tsumoHora(myHouse); const res = engine.commit_tsumoHora(myHouse);
this.globalEventService.publishMahjongRoomStream(room.id, 'tsumoHora', { }); this.globalEventService.publishMahjongRoomStream(room.id, 'tsumoHora', { house: myHouse, handTiles: res.handTiles, tsumoTile: res.tsumoTile });
} }
@bindThis @bindThis
@ -624,6 +607,8 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
*/ */
@bindThis @bindThis
private async waitForTurn(room: Room, house: Mahjong.Common.House, engine: Mahjong.MasterGameEngine) { private async waitForTurn(room: Room, house: Mahjong.Common.House, engine: Mahjong.MasterGameEngine) {
const aiHouses = [[1, room.user1Ai], [2, room.user2Ai], [3, room.user3Ai], [4, room.user4Ai]].filter(([id, ai]) => ai).map(([id, ai]) => engine.getHouse(id));
if (engine.state.riichis[house]) { if (engine.state.riichis[house]) {
// リーチ時はアガリ牌でない限りツモ切り // リーチ時はアガリ牌でない限りツモ切り
const handTiles = engine.state.handTiles[house]; const handTiles = engine.state.handTiles[house];
@ -636,6 +621,13 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
} }
} }
if (aiHouses.includes(house)) {
setTimeout(() => {
this.dahai(room, engine, house, engine.state.handTiles[house].at(-1));
}, 500);
return;
}
const id = Math.random().toString(36).slice(2); const id = Math.random().toString(36).slice(2);
console.log('waitForTurn', house, id); console.log('waitForTurn', house, id);
this.redisClient.sadd(`mahjong:gameTurnWaiting:${room.id}`, id); this.redisClient.sadd(`mahjong:gameTurnWaiting:${room.id}`, id);

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View file

@ -0,0 +1,46 @@
<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div v-if="huro.type === 'ankan'" :class="[$style.root]">
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
</div>
<div v-else-if="huro.type === 'minkan'" :class="[$style.root]">
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
</div>
<div v-else-if="huro.type === 'cii'" :class="[$style.root]">
<XTile :tile="huro.tiles[0]" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tiles[1]" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tiles[2]" :variation="variation" :doras="doras"/>
</div>
<div v-else :class="[$style.root]">
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
<XTile :tile="huro.tile" :variation="variation" :doras="doras"/>
</div>
</template>
<script lang="ts" setup>
import { computed } from 'vue';
import * as Mahjong from 'misskey-mahjong';
import XTile from './tile.vue';
const props = defineProps<{
huro: Mahjong.Common.Huro;
variation: string;
doras: Mahjong.Common.Tile[];
}>();
</script>
<style lang="scss" module>
.root {
}
</style>

View file

@ -56,6 +56,22 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
</div> </div>
<div :class="$style.huroTilesOfToimen">
<XHuro v-for="huro in engine.state.huros[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :huro="huro" :variation="1" :doras="engine.doras"/>
</div>
<div :class="$style.huroTilesOfKamitya">
<XHuro v-for="huro in engine.state.huros[Mahjong.Common.prevHouse(engine.myHouse)]" :huro="huro" :variation="1" :doras="engine.doras"/>
</div>
<div :class="$style.huroTilesOfSimotya">
<XHuro v-for="huro in engine.state.huros[Mahjong.Common.nextHouse(engine.myHouse)]" :huro="huro" :variation="1" :doras="engine.doras"/>
</div>
<div :class="$style.huroTilesOfMe">
<XHuro v-for="huro in engine.state.huros[engine.myHouse]" :huro="huro" :variation="1" :doras="engine.doras"/>
</div>
<div :class="$style.hoTilesContainer"> <div :class="$style.hoTilesContainer">
<div :class="$style.hoTilesContainerOfToimen"> <div :class="$style.hoTilesContainerOfToimen">
<div :class="$style.hoTilesOfToimen"> <div :class="$style.hoTilesOfToimen">
@ -107,44 +123,66 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
</div> </div>
<div :class="$style.huroTilesOfMe">
<div v-for="huro in engine.state.huros[engine.myHouse]" style="display: inline-block;">
<div v-if="huro.type === 'pon'">
<XTile :tile="huro.tile" variation="1" :doras="engine.doras"/>
<XTile :tile="huro.tile" variation="1" :doras="engine.doras"/>
<XTile :tile="huro.tile" variation="1" :doras="engine.doras"/>
</div>
</div>
</div>
<div :class="$style.serifContainer"> <div :class="$style.serifContainer">
<div :class="$style.serifContainerOfToimen"> <div :class="$style.serifContainerOfToimen">
<Transition
:enterActiveClass="$style.transition_serif_enterActive"
:leaveActiveClass="$style.transition_serif_leaveActive"
:enterFromClass="$style.transition_serif_enterFrom"
:leaveToClass="$style.transition_serif_leaveTo"
>
<img v-if="ronSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/> <img v-if="ronSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/>
<img v-else-if="ciiSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/> <img v-else-if="ciiSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/>
<img v-else-if="ponSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/> <img v-else-if="ponSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/>
<img v-else-if="kanSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/> <img v-else-if="kanSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/>
<img v-else-if="tsumoSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/> <img v-else-if="tsumoSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/>
<img v-else-if="riichiSerifHouses[Mahjong.Common.prevHouse(Mahjong.Common.prevHouse(engine.myHouse))]" :src="`/client-assets/mahjong/riichi.png`" style="display: block; width: 100%;"/>
</Transition>
</div> </div>
<div :class="$style.serifContainerOfKamitya"> <div :class="$style.serifContainerOfKamitya">
<Transition
:enterActiveClass="$style.transition_serif_enterActive"
:leaveActiveClass="$style.transition_serif_leaveActive"
:enterFromClass="$style.transition_serif_enterFrom"
:leaveToClass="$style.transition_serif_leaveTo"
>
<img v-if="ronSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/> <img v-if="ronSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/>
<img v-else-if="ciiSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/> <img v-else-if="ciiSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/>
<img v-else-if="ponSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/> <img v-else-if="ponSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/>
<img v-else-if="kanSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/> <img v-else-if="kanSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/>
<img v-else-if="tsumoSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/> <img v-else-if="tsumoSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/>
<img v-else-if="riichiSerifHouses[Mahjong.Common.prevHouse(engine.myHouse)]" :src="`/client-assets/mahjong/riichi.png`" style="display: block; width: 100%;"/>
</Transition>
</div> </div>
<div :class="$style.serifContainerOfSimotya"> <div :class="$style.serifContainerOfSimotya">
<Transition
:enterActiveClass="$style.transition_serif_enterActive"
:leaveActiveClass="$style.transition_serif_leaveActive"
:enterFromClass="$style.transition_serif_enterFrom"
:leaveToClass="$style.transition_serif_leaveTo"
>
<img v-if="ronSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/> <img v-if="ronSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/>
<img v-else-if="ciiSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/> <img v-else-if="ciiSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/>
<img v-else-if="ponSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/> <img v-else-if="ponSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/>
<img v-else-if="kanSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/> <img v-else-if="kanSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/>
<img v-else-if="tsumoSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/> <img v-else-if="tsumoSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/>
<img v-else-if="riichiSerifHouses[Mahjong.Common.nextHouse(engine.myHouse)]" :src="`/client-assets/mahjong/riichi.png`" style="display: block; width: 100%;"/>
</Transition>
</div> </div>
<div :class="$style.serifContainerOfMe"> <div :class="$style.serifContainerOfMe">
<Transition
:enterActiveClass="$style.transition_serif_enterActive"
:leaveActiveClass="$style.transition_serif_leaveActive"
:enterFromClass="$style.transition_serif_enterFrom"
:leaveToClass="$style.transition_serif_leaveTo"
>
<img v-if="ronSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/> <img v-if="ronSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/ron.png`" style="display: block; width: 100%;"/>
<img v-else-if="ciiSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/> <img v-else-if="ciiSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/cii.png`" style="display: block; width: 100%;"/>
<img v-else-if="ponSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/> <img v-else-if="ponSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/pon.png`" style="display: block; width: 100%;"/>
<img v-else-if="kanSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/> <img v-else-if="kanSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/kan.png`" style="display: block; width: 100%;"/>
<img v-else-if="tsumoSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/> <img v-else-if="tsumoSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/tsumo.png`" style="display: block; width: 100%;"/>
<img v-else-if="riichiSerifHouses[engine.myHouse]" :src="`/client-assets/mahjong/riichi.png`" style="display: block; width: 100%;"/>
</Transition>
</div> </div>
</div> </div>
@ -156,6 +194,18 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkButton v-if="isMyTurn && engine.canRiichi()" primary @click="riichi">Riichi</MkButton> <MkButton v-if="isMyTurn && engine.canRiichi()" primary @click="riichi">Riichi</MkButton>
</div> </div>
</div> </div>
<div v-if="kyokuEnded" :class="$style.kyokuResult">
<div v-for="(res, house) in kyokuResults" :key="house">
<div v-if="res != null">
<div>{{ house === 'e' ? i18n.ts._mahjong.east : house === 's' ? i18n.ts._mahjong.south : house === 'w' ? i18n.ts._mahjong.west : i18n.ts._mahjong.north }}</div>
<div v-for="yaku in res.yakus">
<div>{{ yaku.name }} ({{ yaku.fan }})</div>
</div>
<div>{{ res.doraCount }} dora</div>
<div>{{ res.pointDeltas.e }} / {{ res.pointDeltas.s }} / {{ res.pointDeltas.w }} / {{ res.pointDeltas.n }}</div>
</div>
</div>
</div>
</div> </div>
</template> </template>
@ -164,6 +214,7 @@ import { computed, onActivated, onDeactivated, onMounted, onUnmounted, reactive,
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import * as Mahjong from 'misskey-mahjong'; import * as Mahjong from 'misskey-mahjong';
import XTile from './tile.vue'; import XTile from './tile.vue';
import XHuro from './huro.vue';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import MkFolder from '@/components/MkFolder.vue'; import MkFolder from '@/components/MkFolder.vue';
import MkSwitch from '@/components/MkSwitch.vue'; import MkSwitch from '@/components/MkSwitch.vue';
@ -202,6 +253,7 @@ const ciiSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: fals
const ponSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false }); const ponSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false });
const kanSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false }); const kanSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false });
const tsumoSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false }); const tsumoSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false });
const riichiSerifHouses = reactive<Record<Mahjong.Common.House, boolean>>({ e: false, s: false, w: false, n: false });
/* /*
console.log(Mahjong.Common.getTilesForRiichi([ console.log(Mahjong.Common.getTilesForRiichi([
@ -338,6 +390,19 @@ function skip() {
const iTsumoed = ref(false); const iTsumoed = ref(false);
const kyokuEnded = ref(false); const kyokuEnded = ref(false);
const kyokuResults = ref<Record<Mahjong.Common.House, {
yakus: {
name: string;
fan: number;
}[];
doraCount: number;
pointDeltas: Record<Mahjong.Common.House, number>;
} | null>>({
e: null,
s: null,
w: null,
n: null,
});
function kyokuEnd() { function kyokuEnd() {
kyokuEnded.value = true; kyokuEnded.value = true;
@ -359,9 +424,14 @@ function onStreamDahai(log) {
// return; // return;
//} //}
engine.value.commit_dahai(log.house, log.tile); engine.value.commit_dahai(log.house, log.tile, log.riichi);
triggerRef(engine); triggerRef(engine);
riichiSerifHouses[log.house] = log.riichi;
window.setTimeout(() => {
riichiSerifHouses[log.house] = false;
}, 2000);
myTurnTimerRmain.value = room.value.timeLimitForEachTurn; myTurnTimerRmain.value = room.value.timeLimitForEachTurn;
} }
@ -402,9 +472,14 @@ function onStreamDahaiAndTsumo(log) {
playbackRate: 1, playbackRate: 1,
}); });
engine.value.commit_dahai(log.dahaiHouse, log.dahaiTile); engine.value.commit_dahai(log.dahaiHouse, log.dahaiTile, log.riichi);
triggerRef(engine); triggerRef(engine);
riichiSerifHouses[log.dahaiHouse] = log.riichi;
window.setTimeout(() => {
riichiSerifHouses[log.dahaiHouse] = false;
}, 2000);
window.setTimeout(() => { window.setTimeout(() => {
engine.value.commit_tsumo(Mahjong.Common.nextHouse(log.dahaiHouse), log.tsumoTile); engine.value.commit_tsumo(Mahjong.Common.nextHouse(log.dahaiHouse), log.tsumoTile);
triggerRef(engine); triggerRef(engine);
@ -431,9 +506,9 @@ function onStreamPonned(log) {
engine.value.commit_pon(log.caller, log.callee); engine.value.commit_pon(log.caller, log.callee);
triggerRef(engine); triggerRef(engine);
ponSerifHouses[log.house] = true; ponSerifHouses[log.caller] = true;
window.setTimeout(() => { window.setTimeout(() => {
ponSerifHouses[log.house] = false; ponSerifHouses[log.caller] = false;
}, 2000); }, 2000);
myTurnTimerRmain.value = room.value.timeLimitForEachTurn; myTurnTimerRmain.value = room.value.timeLimitForEachTurn;
@ -442,21 +517,31 @@ function onStreamPonned(log) {
function onStreamRonned(log) { function onStreamRonned(log) {
console.log('onStreamRonned', log); console.log('onStreamRonned', log);
engine.value.commit_ronHora(log.callers, log.callee, log.handTiles); const res = engine.value.commit_ronHora(log.callers, log.callee, log.handTiles);
triggerRef(engine); triggerRef(engine);
kyokuResults.value = res;
kyokuEnded.value = true;
for (const caller of log.callers) { for (const caller of log.callers) {
ronSerifHouses[caller] = true; ronSerifHouses[caller] = true;
} }
console.log('ronned', res);
} }
function onStreamTsumoHora(log) { function onStreamTsumoHora(log) {
console.log('onStreamTsumoHora', log); console.log('onStreamTsumoHora', log);
const res = engine.value.commit_tsumoHora(log.house, log.handTiles, log.tsumoTile);
triggerRef(engine);
kyokuResults.value[log.house] = res;
kyokuEnded.value = true;
tsumoSerifHouses[log.house] = true; tsumoSerifHouses[log.house] = true;
engine.value.commit_tsumoHora(); console.log('tsumohora', res);
triggerRef(engine);
} }
function restoreRoom(_room) { function restoreRoom(_room) {
@ -516,6 +601,18 @@ onUnmounted(() => {
100% { translate: -130px; } 100% { translate: -130px; }
} }
.transition_serif_enterActive,
.transition_serif_leaveActive {
transition: opacity 0.1s linear, scale 0.1s linear;
}
.transition_serif_enterFrom {
scale: 1.25;
opacity: 0;
}
.transition_serif_leaveTo {
opacity: 0;
}
.root { .root {
background: #3C7A43; background: #3C7A43;
background-image: url('/client-assets/mahjong/bg.jpg'); background-image: url('/client-assets/mahjong/bg.jpg');
@ -535,6 +632,22 @@ onUnmounted(() => {
box-sizing: border-box; box-sizing: border-box;
} }
.kyokuResult {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
width: 100%;
height: 100%;
max-width: 800px;
margin: auto;
box-sizing: border-box;
background: #0009;
color: #fff;
}
.centerPanel { .centerPanel {
position: absolute; position: absolute;
top: 0; top: 0;
@ -634,6 +747,24 @@ onUnmounted(() => {
right: 80px; right: 80px;
} }
.huroTilesOfToimen {
position: absolute;
top: 0;
left: 80px;
}
.huroTilesOfKamitya {
position: absolute;
top: 80px;
left: 0;
}
.huroTilesOfSimotya {
position: absolute;
top: 80px;
right: 0;
}
.hoTilesContainer { .hoTilesContainer {
position: absolute; position: absolute;
top: 0; top: 0;
@ -766,6 +897,7 @@ onUnmounted(() => {
aspect-ratio: 0.7; aspect-ratio: 0.7;
transition: translate 0.1s ease; transition: translate 0.1s ease;
cursor: pointer; cursor: pointer;
overflow: clip;
} }
.myTile:hover { .myTile:hover {
translate: 0 -10px; translate: 0 -10px;

View file

@ -158,7 +158,7 @@ type EnvForCalcYaku = {
house: House; house: House;
/** /**
* () * ()
*/ */
handTiles: Tile[]; handTiles: Tile[];
@ -214,6 +214,12 @@ export const YAKU_DEFINITIONS = [{
calc: (state: EnvForCalcYaku) => { calc: (state: EnvForCalcYaku) => {
return state.riichi; return state.riichi;
}, },
}, {
name: 'tsumo',
fan: 1,
calc: (state: EnvForCalcYaku) => {
return state.tsumoTile != null;
},
}, { }, {
name: 'red', name: 'red',
fan: 1, fan: 1,
@ -272,7 +278,7 @@ export const YAKU_DEFINITIONS = [{
calc: (state: EnvForCalcYaku) => { calc: (state: EnvForCalcYaku) => {
const yaochuTiles: Tile[] = ['m1', 'm9', 'p1', 'p9', 's1', 's9', 'e', 's', 'w', 'n', 'haku', 'hatsu', 'chun']; const yaochuTiles: Tile[] = ['m1', 'm9', 'p1', 'p9', 's1', 's9', 'e', 's', 'w', 'n', 'haku', 'hatsu', 'chun'];
return ( return (
(state.handTiles.filter(t => yaochuTiles.includes(t)).length === 0) && (!state.handTiles.some(t => yaochuTiles.includes(t))) &&
(state.huros.filter(huro => (state.huros.filter(huro =>
huro.type === 'pon' ? yaochuTiles.includes(huro.tile) : huro.type === 'pon' ? yaochuTiles.includes(huro.tile) :
huro.type === 'ankan' ? yaochuTiles.includes(huro.tile) : huro.type === 'ankan' ? yaochuTiles.includes(huro.tile) :
@ -281,6 +287,27 @@ export const YAKU_DEFINITIONS = [{
false).length === 0) false).length === 0)
); );
}, },
}, {
name: 'pinfu',
fan: 1,
calc: (state: EnvForCalcYaku) => {
// 面前じゃないとダメ
if (state.huros.length !== 0) return false;
// 三元牌はダメ
if (state.handTiles.some(t => ['haku', 'hatsu', 'chun'].includes(t))) return false;
// TODO: 両面待ちかどうか
const horaSets = getHoraSets(state.handTiles.concat(state.tsumoTile ?? state.ronTile));
return horaSets.some(horaSet => {
// 風牌判定(役牌でなければOK)
if (horaSet.head === state.seatWind) return false;
if (horaSet.head === state.fieldWind) return false;
// 全て順子か?
if (horaSet.mentsus.some((mentsu) => mentsu[0] === mentsu[1])) return false;
});
},
}]; }];
export function fanToPoint(fan: number, isParent: boolean): number { export function fanToPoint(fan: number, isParent: boolean): number {
@ -423,29 +450,44 @@ export const SHUNTU_PATTERNS: [Tile, Tile, Tile][] = [
['s7', 's8', 's9'], ['s7', 's8', 's9'],
]; ];
const SHUNTU_PATTERN_IDS = [ export type KyokuResult = {
'm123', yakus: { name: string; fan: number; }[];
'm234', doraCount: number;
'm345', pointDeltas: { e: number; s: number; w: number; n: number; };
'm456', };
'm567',
'm678', function extractShuntsus(tiles: Tile[]): [Tile, Tile, Tile][] {
'm789', const tempTiles = [...tiles];
'p123',
'p234', tempTiles.sort((a, b) => {
'p345', const aIndex = TILE_TYPES.indexOf(a);
'p456', const bIndex = TILE_TYPES.indexOf(b);
'p567', return aIndex - bIndex;
'p678', });
'p789',
's123', const shuntsus: [Tile, Tile, Tile][] = [];
's234', while (tempTiles.length > 0) {
's345', let isShuntu = false;
's456', for (const shuntuPattern of SHUNTU_PATTERNS) {
's567', if (
's678', tempTiles[0] === shuntuPattern[0] &&
's789', tempTiles.includes(shuntuPattern[1]) &&
] as const; tempTiles.includes(shuntuPattern[2])
) {
shuntsus.push(shuntuPattern);
tempTiles.splice(0, 1);
tempTiles.splice(tempTiles.indexOf(shuntuPattern[1]), 1);
tempTiles.splice(tempTiles.indexOf(shuntuPattern[2]), 1);
isShuntu = true;
break;
}
}
if (!isShuntu) tempTiles.splice(0, 1);
}
return shuntsus;
}
/** /**
* *
@ -537,34 +579,7 @@ export function getHoraSets(handTiles: Tile[]): HoraSet[] {
tempHandTilesWithoutKotsu.splice(tempHandTilesWithoutKotsu.indexOf(kotsuTile), 1); tempHandTilesWithoutKotsu.splice(tempHandTilesWithoutKotsu.indexOf(kotsuTile), 1);
} }
tempHandTilesWithoutKotsu.sort((a, b) => { const shuntsus = extractShuntsus(tempHandTilesWithoutKotsu);
const aIndex = TILE_TYPES.indexOf(a);
const bIndex = TILE_TYPES.indexOf(b);
return aIndex - bIndex;
});
const tempHandTilesWithoutKotsuAndShuntsu: (Tile | null)[] = [...tempHandTilesWithoutKotsu];
const shuntsus: [Tile, Tile, Tile][] = [];
while (tempHandTilesWithoutKotsuAndShuntsu.length > 0) {
let isShuntu = false;
for (const shuntuPattern of SHUNTU_PATTERNS) {
if (
tempHandTilesWithoutKotsuAndShuntsu[0] === shuntuPattern[0] &&
tempHandTilesWithoutKotsuAndShuntsu.includes(shuntuPattern[1]) &&
tempHandTilesWithoutKotsuAndShuntsu.includes(shuntuPattern[2])
) {
shuntsus.push(shuntuPattern);
tempHandTilesWithoutKotsuAndShuntsu.splice(0, 1);
tempHandTilesWithoutKotsuAndShuntsu.splice(tempHandTilesWithoutKotsuAndShuntsu.indexOf(shuntuPattern[1]), 1);
tempHandTilesWithoutKotsuAndShuntsu.splice(tempHandTilesWithoutKotsuAndShuntsu.indexOf(shuntuPattern[2]), 1);
isShuntu = true;
break;
}
}
if (!isShuntu) tempHandTilesWithoutKotsuAndShuntsu.splice(0, 1);
}
if (shuntsus.length * 3 === tempHandTilesWithoutKotsu.length) { // アガリ形 if (shuntsus.length * 3 === tempHandTilesWithoutKotsu.length) { // アガリ形
horaSets.push({ horaSets.push({

View file

@ -380,6 +380,7 @@ export class MasterGameEngine {
return { return {
asking: false as const, asking: false as const,
tsumoTile: tsumoTile, tsumoTile: tsumoTile,
next: this.state.turn,
}; };
} }
@ -439,6 +440,11 @@ export class MasterGameEngine {
console.log('yakus', house, yakus); console.log('yakus', house, yakus);
this.endKyoku(); this.endKyoku();
return {
handTiles: this.state.handTiles[house],
tsumoTile: this.state.handTiles[house].at(-1)!,
};
} }
public commit_resolveCallAndRonInterruption(answers: { public commit_resolveCallAndRonInterruption(answers: {

View file

@ -64,6 +64,12 @@ export type PlayerState = {
canRonTo: House | null; canRonTo: House | null;
}; };
export type KyokuResult = {
yakus: { name: string; fan: number; }[];
doraCount: number;
pointDeltas: { e: number; s: number; w: number; n: number; };
};
export class PlayerGameEngine { export class PlayerGameEngine {
/** /**
* desyncが疑われる * desyncが疑われる
@ -145,10 +151,33 @@ export class PlayerGameEngine {
if (this.state.turn !== house) throw new PlayerGameEngine.InvalidOperationError(); if (this.state.turn !== house) throw new PlayerGameEngine.InvalidOperationError();
} }
public commit_tsumoHora(house: House) { public commit_tsumoHora(house: House, handTiles: Tile[], tsumoTile: Tile): KyokuResult {
console.log('commit_tsumoHora', this.state.turn, house); console.log('commit_tsumoHora', this.state.turn, house);
// TODO: ツモした人の手牌情報を貰う必要がある const yakus = YAKU_DEFINITIONS.filter(yaku => yaku.calc({
house: house,
handTiles: handTiles,
huros: this.state.huros[house],
tsumoTile: tsumoTile,
ronTile: null,
riichi: this.state.riichis[house],
}));
const doraCount = Common.calcOwnedDoraCount(handTiles, this.state.huros[house], this.doras);
const fans = yakus.map(yaku => yaku.fan).reduce((a, b) => a + b, 0) + doraCount;
const pointDeltas = Common.calcTsumoHoraPointDeltas(house, fans);
this.state.points.e += pointDeltas.e;
this.state.points.s += pointDeltas.s;
this.state.points.w += pointDeltas.w;
this.state.points.n += pointDeltas.n;
return {
yakus: yakus.map(yaku => ({
name: yaku.name,
fan: yaku.fan,
})),
doraCount,
pointDeltas,
};
} }
/** /**
@ -161,23 +190,16 @@ export class PlayerGameEngine {
s: Tile[]; s: Tile[];
w: Tile[]; w: Tile[];
n: Tile[]; n: Tile[];
}) { }): Record<House, KyokuResult | null> {
console.log('commit_ronHora', this.state.turn, callers, callee); console.log('commit_ronHora', this.state.turn, callers, callee);
this.state.canRonSource = null; this.state.canRonSource = null;
const yakusMap: Record<House, { name: string; fan: number; }[]> = { const resultMap: Record<House, KyokuResult> = {
e: [] as { name: string; fan: number; }[], e: { yakus: [], doraCount: 0, pointDeltas: { e: 0, s: 0, w: 0, n: 0 } },
s: [] as { name: string; fan: number; }[], s: { yakus: [], doraCount: 0, pointDeltas: { e: 0, s: 0, w: 0, n: 0 } },
w: [] as { name: string; fan: number; }[], w: { yakus: [], doraCount: 0, pointDeltas: { e: 0, s: 0, w: 0, n: 0 } },
n: [] as { name: string; fan: number; }[], n: { yakus: [], doraCount: 0, pointDeltas: { e: 0, s: 0, w: 0, n: 0 } },
};
const doraCountsMap: Record<House, number> = {
e: 0,
s: 0,
w: 0,
n: 0,
}; };
for (const house of callers) { for (const house of callers) {
@ -194,14 +216,17 @@ export class PlayerGameEngine {
const point = Common.fanToPoint(fans, house === 'e'); const point = Common.fanToPoint(fans, house === 'e');
this.state.points[callee] -= point; this.state.points[callee] -= point;
this.state.points[house] += point; this.state.points[house] += point;
yakusMap[house] = yakus.map(yaku => ({ name: yaku.name, fan: yaku.fan })); resultMap[house].yakus = yakus.map(yaku => ({ name: yaku.name, fan: yaku.fan }));
doraCountsMap[house] = doraCount; resultMap[house].doraCount = doraCount;
console.log('yakus', house, yakus); resultMap[house].pointDeltas[callee] = -point;
resultMap[house].pointDeltas[house] = point;
} }
return { return {
yakusMap, e: callers.includes('e') ? resultMap.e : null,
doraCountsMap, s: callers.includes('s') ? resultMap.s : null,
w: callers.includes('w') ? resultMap.w : null,
n: callers.includes('n') ? resultMap.n : null,
}; };
} }