wip
This commit is contained in:
parent
606c88aa6b
commit
db7bd0e94e
9 changed files with 127 additions and 18 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
BIN
packages/frontend/assets/mahjong/tile-top-h.png
Normal file
BIN
packages/frontend/assets/mahjong/tile-top-h.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5 KiB |
BIN
packages/frontend/assets/mahjong/tile-top-v.png
Normal file
BIN
packages/frontend/assets/mahjong/tile-top-v.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB |
|
@ -28,28 +28,28 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
<div :class="$style.hoTilesContainerOfToimen">
|
||||
<div :class="$style.hoTilesOfToimen">
|
||||
<div v-for="tile in engine.getHoTilesOf(Mahjong.Utils.prevHouse(Mahjong.Utils.prevHouse(engine.myHouse)))" :class="$style.hoTile">
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" style="position: absolute; width: 100%;"/>
|
||||
<XTile :tile="tile" direction="v"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="$style.hoTilesContainerOfKamitya">
|
||||
<div :class="$style.hoTilesOfKamitya">
|
||||
<div v-for="tile in engine.getHoTilesOf(Mahjong.Utils.prevHouse(engine.myHouse))" :class="$style.hoTile">
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" style="position: absolute; width: 100%;"/>
|
||||
<XTile :tile="tile" direction="v"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="$style.hoTilesContainerOfSimotya">
|
||||
<div :class="$style.hoTilesOfSimotya">
|
||||
<div v-for="tile in engine.getHoTilesOf(Mahjong.Utils.nextHouse(engine.myHouse))" :class="$style.hoTile">
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" style="position: absolute; width: 100%;"/>
|
||||
<XTile :tile="tile" direction="v"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div :class="$style.hoTilesContainerOfMe">
|
||||
<div :class="$style.hoTilesOfMe">
|
||||
<div v-for="tile in engine.myHoTiles" :class="$style.hoTile">
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" style="position: absolute; width: 100%;"/>
|
||||
<XTile :tile="tile" direction="v"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -69,16 +69,17 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
<div :class="$style.huroTilesOfMe">
|
||||
<div v-for="huro in engine.getHurosOf(engine.myHouse)" style="display: inline-block;">
|
||||
<div v-if="huro.type === 'pon'">
|
||||
<img :src="`/client-assets/mahjong/tiles/${huro.tile}.png`"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${huro.tile}.png`"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${huro.tile}.png`"/>
|
||||
<XTile :tile="huro.tile" direction="v"/>
|
||||
<XTile :tile="huro.tile" direction="v"/>
|
||||
<XTile :tile="huro.tile" direction="v"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<MkButton v-if="engine.state.canPonSource != null" @click="pon">Pon</MkButton>
|
||||
<MkButton v-if="engine.state.canPonSource != null" @click="skip">Skip pon</MkButton>
|
||||
<MkButton v-if="isMyTurn && canHora">Hora</MkButton>
|
||||
<MkButton v-if="engine.state.canRonSource != null" primary gradate @click="ron">Ron</MkButton>
|
||||
<MkButton v-if="engine.state.canPonSource != null" primary @click="pon">Pon</MkButton>
|
||||
<MkButton v-if="engine.state.canRonSource != null || engine.state.canPonSource != null" @click="skip">Skip</MkButton>
|
||||
<MkButton v-if="isMyTurn && canHora">Tsumo</MkButton>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -86,6 +87,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
import { computed, onActivated, onDeactivated, onMounted, onUnmounted, ref, shallowRef, triggerRef, watch } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import * as Mahjong from 'misskey-mahjong';
|
||||
import XTile from './tile.vue';
|
||||
import MkButton from '@/components/MkButton.vue';
|
||||
import MkFolder from '@/components/MkFolder.vue';
|
||||
import MkSwitch from '@/components/MkSwitch.vue';
|
||||
|
@ -190,6 +192,14 @@ function dahai(tile: Mahjong.Common.Tile, ev: MouseEvent) {
|
|||
});
|
||||
}
|
||||
|
||||
function ron() {
|
||||
engine.value.op_ron(engine.value.state.canRonSource, engine.value.myHouse);
|
||||
triggerRef(engine);
|
||||
|
||||
props.connection!.send('ron', {
|
||||
});
|
||||
}
|
||||
|
||||
function pon() {
|
||||
engine.value.op_pon(engine.value.state.canPonSource, engine.value.myHouse);
|
||||
triggerRef(engine);
|
||||
|
@ -464,9 +474,6 @@ onUnmounted(() => {
|
|||
.hoTile {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 32px;
|
||||
aspect-ratio: 0.7;
|
||||
background: #fff;
|
||||
margin-bottom: -8px;
|
||||
}
|
||||
|
||||
|
|
45
packages/frontend/src/pages/mahjong/tile.vue
Normal file
45
packages/frontend/src/pages/mahjong/tile.vue
Normal file
|
@ -0,0 +1,45 @@
|
|||
<!--
|
||||
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div :class="$style.root">
|
||||
<img v-if="direction === 'v'" :src="`/client-assets/mahjong/tile-top-v.png`" :class="$style.bg"/>
|
||||
<img v-if="direction === 'h'" :src="`/client-assets/mahjong/tile-top-h.png`" :class="$style.bg"/>
|
||||
<img :src="`/client-assets/mahjong/tiles/${tile}.png`" :class="$style.fg"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onActivated, onDeactivated, onMounted, onUnmounted, ref, shallowRef, triggerRef, watch } from 'vue';
|
||||
import * as Mahjong from 'misskey-mahjong';
|
||||
|
||||
const props = defineProps<{
|
||||
tile: Mahjong.Common.Tile;
|
||||
direction: 'v' | 'h';
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style lang="scss" module>
|
||||
.root {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
width: 35px;
|
||||
aspect-ratio: 0.7;
|
||||
}
|
||||
.bg {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
.fg {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 80%;
|
||||
object-fit: contain;
|
||||
}
|
||||
</style>
|
|
@ -365,8 +365,9 @@ export class MasterGameEngine {
|
|||
const horaSets = Utils.getHoraSets(this.getHandTilesOf(house).concat(tile));
|
||||
if (horaSets.length === 0) return false; // 完成形じゃない
|
||||
|
||||
const yakus = YAKU_DEFINITIONS.filter(yaku => yaku.calc(this.state, { tsumoTile: null, ronTile: tile }));
|
||||
if (yakus.length === 0) return false; // 役がない
|
||||
// TODO
|
||||
//const yakus = YAKU_DEFINITIONS.filter(yaku => yaku.calc(this.state, { tsumoTile: null, ronTile: tile }));
|
||||
//if (yakus.length === 0) return false; // 役がない
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -494,6 +495,9 @@ export type PlayerState = {
|
|||
latestDahaiedTile: Tile | null;
|
||||
turn: House | null;
|
||||
canPonSource: House | null;
|
||||
canCiiSource: House | null;
|
||||
canKanSource: House | null;
|
||||
canRonSource: House | null;
|
||||
canCiiTo: House | null;
|
||||
canKanTo: House | null;
|
||||
canRonTo: House | null;
|
||||
|
@ -596,14 +600,34 @@ export class PlayerGameEngine {
|
|||
|
||||
if (house === this.myHouse) {
|
||||
} else {
|
||||
const canRon = Utils.getHoraSets(this.myHandTiles.concat(tile)).length > 0;
|
||||
const canPon = this.myHandTiles.filter(t => t === tile).length === 2;
|
||||
|
||||
// TODO: canCii
|
||||
|
||||
if (canRon) this.state.canRonSource = house;
|
||||
if (canPon) this.state.canPonSource = house;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ロンします
|
||||
* @param source 牌を捨てた人
|
||||
* @param target ロンした人
|
||||
*/
|
||||
public op_ron(source: House, target: House) {
|
||||
this.state.canRonSource = null;
|
||||
|
||||
const lastTile = this.getHoTilesOf(source).pop();
|
||||
if (lastTile == null) throw new PlayerGameEngine.InvalidOperationError();
|
||||
if (target === this.myHouse) {
|
||||
this.myHandTiles.push(lastTile);
|
||||
} else {
|
||||
this.getHandTilesOf(target).push(null);
|
||||
}
|
||||
this.state.turn = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ポンします
|
||||
* @param source 牌を捨てた人
|
||||
|
@ -627,6 +651,7 @@ export class PlayerGameEngine {
|
|||
}
|
||||
|
||||
public op_nop() {
|
||||
this.state.canRonSource = null;
|
||||
this.state.canPonSource = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue