wip
This commit is contained in:
parent
be3b2558d1
commit
38e3d248fb
10 changed files with 49 additions and 89 deletions
|
@ -376,7 +376,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
private async dahai(room: Room, engine: Mahjong.MasterGameEngine, house: Mahjong.House, tile: Mahjong.Tile, riichi = false) {
|
||||
private async dahai(room: Room, engine: Mahjong.MasterGameEngine, house: Mahjong.House, tile: Mahjong.TileId, riichi = false) {
|
||||
const res = engine.commit_dahai(house, tile, riichi);
|
||||
room.gameState = engine.state;
|
||||
await this.saveRoom(room);
|
||||
|
@ -384,8 +384,6 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
|
|||
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 (res.asking) {
|
||||
console.log('asking', res);
|
||||
|
||||
const answers: CallingAnswers = {
|
||||
pon: null,
|
||||
cii: null,
|
||||
|
@ -478,11 +476,10 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async commit_dahai(roomId: MiMahjongGame['id'], user: MiUser, tile: string, riichi = false) {
|
||||
public async commit_dahai(roomId: MiMahjongGame['id'], user: MiUser, tile: Mahjong.TileId, riichi = false) {
|
||||
const room = await this.getRoom(roomId);
|
||||
if (room == null) return;
|
||||
if (room.gameState == null) return;
|
||||
if (!Mahjong.isTile(tile)) return;
|
||||
|
||||
const engine = new Mahjong.MasterGameEngine(room.gameState);
|
||||
const myHouse = getHouseOfUserId(room, engine, user.id);
|
||||
|
@ -493,7 +490,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async commit_ankan(roomId: MiMahjongGame['id'], user: MiUser, tile: string) {
|
||||
public async commit_ankan(roomId: MiMahjongGame['id'], user: MiUser, tile: Mahjong.TileId) {
|
||||
const room = await this.getRoom(roomId);
|
||||
if (room == null) return;
|
||||
if (room.gameState == null) return;
|
||||
|
@ -511,7 +508,7 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async commit_kakan(roomId: MiMahjongGame['id'], user: MiUser, tile: string) {
|
||||
public async commit_kakan(roomId: MiMahjongGame['id'], user: MiUser, tile: Mahjong.TileId) {
|
||||
const room = await this.getRoom(roomId);
|
||||
if (room == null) return;
|
||||
if (room.gameState == null) return;
|
||||
|
@ -643,11 +640,10 @@ export class MahjongService implements OnApplicationShutdown, OnModuleInit {
|
|||
|
||||
if (engine.state.riichis[house]) {
|
||||
// リーチ時はアガリ牌でない限りツモ切り
|
||||
const handTiles = engine.state.handTiles[house];
|
||||
const horaSets = Mahjong.getHoraSets(handTiles);
|
||||
const horaSets = Mahjong.getHoraSets(engine.handTileTypes[house]);
|
||||
if (horaSets.length === 0) {
|
||||
setTimeout(() => {
|
||||
this.dahai(room, engine, house, handTiles.at(-1));
|
||||
this.dahai(room, engine, house, engine.state.handTiles[house].at(-1));
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ class MahjongRoomChannel extends Channel {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
private async dahai(tile: string, riichi = false) {
|
||||
private async dahai(tile: number, riichi = false) {
|
||||
if (this.user == null) return;
|
||||
|
||||
this.mahjongService.commit_dahai(this.roomId!, this.user, tile, riichi);
|
||||
|
@ -136,14 +136,14 @@ class MahjongRoomChannel extends Channel {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
private async ankan(tile: string) {
|
||||
private async ankan(tile: number) {
|
||||
if (this.user == null) return;
|
||||
|
||||
this.mahjongService.commit_ankan(this.roomId!, this.user, tile);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async kakan(tile: string) {
|
||||
private async kakan(tile: number) {
|
||||
if (this.user == null) return;
|
||||
|
||||
this.mahjongService.commit_kakan(this.roomId!, this.user, tile);
|
||||
|
|
BIN
packages/frontend/assets/mahjong/tiles/m5r.png
Normal file
BIN
packages/frontend/assets/mahjong/tiles/m5r.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.8 KiB |
BIN
packages/frontend/assets/mahjong/tiles/p5r.png
Normal file
BIN
packages/frontend/assets/mahjong/tiles/p5r.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
packages/frontend/assets/mahjong/tiles/s5r.png
Normal file
BIN
packages/frontend/assets/mahjong/tiles/s5r.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.8 KiB |
|
@ -5,26 +5,26 @@ 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"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[0])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[1])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[2])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[3])" :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"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[0])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[1])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[2])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[3])" :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"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[0])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[1])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(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"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[0])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[1])" :variation="variation" :doras="doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(huro.tiles[2])" :variation="variation" :doras="doras"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -36,7 +36,7 @@ import XTile from './tile.vue';
|
|||
const props = defineProps<{
|
||||
huro: Mahjong.Huro;
|
||||
variation: string;
|
||||
doras: Mahjong.Tile[];
|
||||
doras: Mahjong.TileType[];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
|
|
|
@ -76,28 +76,28 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
<div :class="$style.hoTilesContainerOfToimen">
|
||||
<div :class="$style.hoTilesOfToimen">
|
||||
<div v-for="(tile, i) in engine.state.hoTiles[Mahjong.prevHouse(Mahjong.prevHouse(engine.myHouse))]" :class="$style.hoTile" :style="{ zIndex: engine.state.hoTiles[Mahjong.prevHouse(Mahjong.prevHouse(engine.myHouse))].length - i }">
|
||||
<XTile :tile="tile" variation="2" :doras="engine.doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(tile)" variation="2" :doras="engine.doras"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="$style.hoTilesContainerOfKamitya">
|
||||
<div :class="$style.hoTilesOfKamitya">
|
||||
<div v-for="tile in engine.state.hoTiles[Mahjong.prevHouse(engine.myHouse)]" :class="$style.hoTile">
|
||||
<XTile :tile="tile" variation="4" :doras="engine.doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(tile)" variation="4" :doras="engine.doras"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="$style.hoTilesContainerOfSimotya">
|
||||
<div :class="$style.hoTilesOfSimotya">
|
||||
<div v-for="(tile, i) in engine.state.hoTiles[Mahjong.nextHouse(engine.myHouse)]" :class="$style.hoTile" :style="{ zIndex: engine.state.hoTiles[Mahjong.nextHouse(engine.myHouse)].length - i }">
|
||||
<XTile :tile="tile" variation="5" :doras="engine.doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(tile)" variation="5" :doras="engine.doras"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="$style.hoTilesContainerOfMe">
|
||||
<div :class="$style.hoTilesOfMe">
|
||||
<div v-for="tile in engine.state.hoTiles[engine.myHouse]" :class="$style.hoTile">
|
||||
<XTile :tile="tile" variation="1" :doras="engine.doras"/>
|
||||
<XTile :tile="Mahjong.findTileByIdOrFail(tile)" variation="1" :doras="engine.doras"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -106,20 +106,20 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
<div :class="$style.handTilesOfMe">
|
||||
<div
|
||||
v-for="tile in Mahjong.sortTiles((isMyTurn && iTsumoed) ? engine.myHandTiles.slice(0, engine.myHandTiles.length - 1) : engine.myHandTiles)"
|
||||
:class="[$style.myTile, { [$style.myTileNonSelectable]: selectableTiles != null && !selectableTiles.includes(tile), [$style.myTileDora]: engine.doras.includes(tile) }]"
|
||||
:class="[$style.myTile, { [$style.myTileNonSelectable]: selectableTiles != null && !selectableTiles.includes(Mahjong.findTileByIdOrFail(tile).t), [$style.myTileDora]: engine.doras.includes(Mahjong.findTileByIdOrFail(tile).t) }]"
|
||||
@click="chooseTile(tile, $event)"
|
||||
>
|
||||
<img :src="`/client-assets/mahjong/tile-front.png`" :class="$style.myTileBg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" :class="$style.myTileFg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${Mahjong.findTileByIdOrFail(tile).red ? Mahjong.findTileByIdOrFail(tile).t + 'r' : Mahjong.findTileByIdOrFail(tile).t}.png`" :class="$style.myTileFg"/>
|
||||
</div>
|
||||
<div
|
||||
v-if="isMyTurn && iTsumoed"
|
||||
style="display: inline-block; margin-left: 5px;"
|
||||
:class="[$style.myTile, { [$style.myTileNonSelectable]: selectableTiles != null && !selectableTiles.includes(engine.myHandTiles.at(-1)), [$style.myTileDora]: engine.doras.includes(engine.myHandTiles.at(-1)) }]"
|
||||
:class="[$style.myTile, { [$style.myTileNonSelectable]: selectableTiles != null && !selectableTiles.includes(Mahjong.findTileByIdOrFail(engine.myHandTiles.at(-1)).t), [$style.myTileDora]: engine.doras.includes(Mahjong.findTileByIdOrFail(engine.myHandTiles.at(-1)).t) }]"
|
||||
@click="chooseTile(engine.myHandTiles.at(-1), $event)"
|
||||
>
|
||||
<img :src="`/client-assets/mahjong/tile-front.png`" :class="$style.myTileBg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${engine.myHandTiles.at(-1)}.png`" :class="$style.myTileFg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${Mahjong.findTileByIdOrFail(engine.myHandTiles.at(-1)).red ? Mahjong.findTileByIdOrFail(engine.myHandTiles.at(-1)).t + 'r' : Mahjong.findTileByIdOrFail(engine.myHandTiles.at(-1)).t}.png`" :class="$style.myTileFg"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -259,7 +259,7 @@ const canHora = computed(() => {
|
|||
return Mahjong.getHoraSets(engine.value.myHandTiles).length > 0;
|
||||
});
|
||||
|
||||
const selectableTiles = ref<Mahjong.Tile[] | null>(null);
|
||||
const selectableTiles = ref<Mahjong.TileType[] | null>(null);
|
||||
const ronSerifHouses = reactive<Record<Mahjong.House, boolean>>({ e: false, s: false, w: false, n: false });
|
||||
const ciiSerifHouses = reactive<Record<Mahjong.House, boolean>>({ e: false, s: false, w: false, n: false });
|
||||
const ponSerifHouses = reactive<Record<Mahjong.House, boolean>>({ e: false, s: false, w: false, n: false });
|
||||
|
@ -267,43 +267,6 @@ const kanSerifHouses = reactive<Record<Mahjong.House, boolean>>({ e: false, s: f
|
|||
const tsumoSerifHouses = reactive<Record<Mahjong.House, boolean>>({ e: false, s: false, w: false, n: false });
|
||||
const riichiSerifHouses = reactive<Record<Mahjong.House, boolean>>({ e: false, s: false, w: false, n: false });
|
||||
|
||||
/*
|
||||
console.log(Mahjong.getTilesForRiichi([
|
||||
'm1',
|
||||
'm2',
|
||||
'm2',
|
||||
'm3',
|
||||
'm3',
|
||||
'm5',
|
||||
'm6',
|
||||
'p4',
|
||||
'p5',
|
||||
'p6',
|
||||
's6',
|
||||
's7',
|
||||
's8',
|
||||
'm7',
|
||||
]));
|
||||
*/
|
||||
/*
|
||||
console.log(Mahjong.getHoraSets([
|
||||
'm3',
|
||||
'm3',
|
||||
'm4',
|
||||
'm4',
|
||||
'm5',
|
||||
'm5',
|
||||
'p4',
|
||||
'p4',
|
||||
'p7',
|
||||
'p8',
|
||||
'p9',
|
||||
's4',
|
||||
's5',
|
||||
's6',
|
||||
]));
|
||||
*/
|
||||
|
||||
/*
|
||||
if (room.value.isStarted && !room.value.isEnded) {
|
||||
useInterval(() => {
|
||||
|
@ -354,7 +317,7 @@ let ankanSelect = false;
|
|||
let kakanSelect = false;
|
||||
let ciiSelect = false;
|
||||
|
||||
function chooseTile(tile: Mahjong.Tile, ev: MouseEvent) {
|
||||
function chooseTile(tile: Mahjong.TileId, ev: MouseEvent) {
|
||||
if (!isMyTurn.value) return;
|
||||
|
||||
iTsumoed.value = false;
|
||||
|
@ -390,22 +353,22 @@ function riichi() {
|
|||
if (!isMyTurn.value) return;
|
||||
|
||||
riichiSelect = true;
|
||||
selectableTiles.value = Mahjong.getTilesForRiichi(engine.value.myHandTiles);
|
||||
console.log(Mahjong.getTilesForRiichi(engine.value.myHandTiles));
|
||||
selectableTiles.value = Mahjong.getTilesForRiichi(engine.value.myHandTileTypes);
|
||||
console.log(Mahjong.getTilesForRiichi(engine.value.myHandTileTypes));
|
||||
}
|
||||
|
||||
function ankan() {
|
||||
if (!isMyTurn.value) return;
|
||||
|
||||
ankanSelect = true;
|
||||
selectableTiles.value = engine.value.getAnkanableTiles();
|
||||
selectableTiles.value = engine.value.getAnkanableTiles().map(id => Mahjong.findTileByIdOrFail(id).t);
|
||||
}
|
||||
|
||||
function kakan() {
|
||||
if (!isMyTurn.value) return;
|
||||
|
||||
kakanSelect = true;
|
||||
selectableTiles.value = engine.value.getKakanableTiles();
|
||||
selectableTiles.value = engine.value.getKakanableTiles().map(id => Mahjong.findTileByIdOrFail(id).t);
|
||||
}
|
||||
|
||||
function tsumoHora() {
|
||||
|
@ -957,7 +920,6 @@ onUnmounted(() => {
|
|||
aspect-ratio: 0.7;
|
||||
transition: translate 0.1s ease;
|
||||
cursor: pointer;
|
||||
overflow: clip;
|
||||
}
|
||||
.myTile:hover {
|
||||
translate: 0 -10px;
|
||||
|
@ -967,6 +929,7 @@ onUnmounted(() => {
|
|||
opacity: 0.7;
|
||||
pointer-events: none;
|
||||
}
|
||||
/*
|
||||
.myTileDora {
|
||||
&:after {
|
||||
content: "";
|
||||
|
@ -982,6 +945,7 @@ onUnmounted(() => {
|
|||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
*/
|
||||
.myTileBg {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
|
|
|
@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
<template>
|
||||
<div :class="[$style.root, { [$style.h]: ['3', '4', '5'].includes(variation), [$style.v]: ['1', '2'].includes(variation), [$style.isDora]: isDora }]">
|
||||
<img :src="`/client-assets/mahjong/putted-tile-${variation}.png`" :class="$style.bg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" :class="$style.fg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile.red ? tile.t + 'r' : tile.t}.png`" :class="$style.fg"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -15,12 +15,12 @@ import { computed } from 'vue';
|
|||
import * as Mahjong from 'misskey-mahjong';
|
||||
|
||||
const props = defineProps<{
|
||||
tile: Mahjong.Tile;
|
||||
tile: Mahjong.TileInstance;
|
||||
variation: string;
|
||||
doras: Mahjong.Tile[];
|
||||
doras: Mahjong.TileType[];
|
||||
}>();
|
||||
|
||||
const isDora = computed(() => props.doras.includes(props.tile));
|
||||
const isDora = computed(() => props.doras.includes(props.tile.t));
|
||||
</script>
|
||||
|
||||
<style lang="scss" module>
|
||||
|
@ -59,7 +59,7 @@ const isDora = computed(() => props.doras.includes(props.tile));
|
|||
height: 53%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/*
|
||||
.isDora {
|
||||
&:after {
|
||||
content: "";
|
||||
|
@ -74,5 +74,5 @@ const isDora = computed(() => props.doras.includes(props.tile));
|
|||
animation: shine 2s infinite;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
</style>
|
||||
|
|
|
@ -14,7 +14,7 @@ function $(tileId: TileId): Common.TileInstance {
|
|||
}
|
||||
|
||||
function $type(tileId: TileId): TileType {
|
||||
return Common.findTileByIdOrFail(tileId).t;
|
||||
return $(tileId).t;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
@ -148,7 +148,7 @@ export class MasterGameEngine {
|
|||
}
|
||||
|
||||
public static createInitialState(): MasterState {
|
||||
const ikasama: TileId[] = [125, 129, 9, 54, 57, 61, 77, 81, 85, 133, 134, 135, 121, 122];
|
||||
const ikasama: TileId[] = [125, 129, 9, 56, 57, 61, 77, 81, 85, 133, 134, 135, 121, 122];
|
||||
|
||||
const tiles = [...Common.TILE_ID_MAP.keys()];
|
||||
tiles.sort(() => Math.random() - 0.5);
|
||||
|
|
|
@ -13,7 +13,7 @@ function $(tileId: TileId): Common.TileInstance {
|
|||
}
|
||||
|
||||
function $type(tileId: TileId): TileType {
|
||||
return Common.findTileByIdOrFail(tileId).t;
|
||||
return $(tileId).t;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
|
Loading…
Reference in a new issue