108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
|
|
import {createGameCommandRegistry} from "@/core/game";
|
|||
|
|
import {RegicideState} from "@/samples/regicide/state";
|
|||
|
|
|
|||
|
|
export const registry = createGameCommandRegistry<RegicideState>();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 打出一张牌
|
|||
|
|
*/
|
|||
|
|
const playCmd = registry.register({
|
|||
|
|
schema: 'play <player:string> <cardId:string>',
|
|||
|
|
run: async (game, player, cardId) => {
|
|||
|
|
const state = game.value;
|
|||
|
|
const card = state.cards[cardId];
|
|||
|
|
|
|||
|
|
if (!card) {
|
|||
|
|
return {success: false, error: `卡牌 ${cardId} 不存在`};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 检查卡牌是否在玩家手牌中
|
|||
|
|
const playerHand = state.playerHands[player as keyof typeof state.playerHands];
|
|||
|
|
if (!playerHand || !playerHand.includes(cardId)) {
|
|||
|
|
return {success: false, error: `卡牌 ${cardId} 不在玩家 ${player} 的手牌中`};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 检查是否有当前敌人
|
|||
|
|
if (!state.currentEnemy) {
|
|||
|
|
return {success: false, error: '没有活跃的敌人'};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 计算伤害(基础伤害为卡牌面值)
|
|||
|
|
let damage = card.value;
|
|||
|
|
|
|||
|
|
// TODO: 花色能力 - 梅花双倍伤害
|
|||
|
|
// if (card.suit === 'clubs') {
|
|||
|
|
// damage *= 2;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// TODO: A牌配合机制 - 如果card.rank === 'A',可以额外打出一张牌
|
|||
|
|
|
|||
|
|
// 对敌人造成伤害
|
|||
|
|
game.produce(state => {
|
|||
|
|
state.currentEnemy!.hp -= damage;
|
|||
|
|
|
|||
|
|
// 从手牌移除卡牌
|
|||
|
|
const hand = state.playerHands[player as keyof typeof state.playerHands];
|
|||
|
|
const cardIndex = hand.indexOf(cardId);
|
|||
|
|
if (cardIndex !== -1) {
|
|||
|
|
hand.splice(cardIndex, 1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 将卡牌移到弃牌堆
|
|||
|
|
state.cards[cardId].regionId = 'discardPile';
|
|||
|
|
|
|||
|
|
// TODO: 触发花色能力
|
|||
|
|
// TODO: 检查敌人是否被击败
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
return {success: true, result: {damage, enemyHp: state.currentEnemy.hp}};
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 让过(不出牌)
|
|||
|
|
*/
|
|||
|
|
const passCmd = registry.register({
|
|||
|
|
schema: 'pass <player:string>',
|
|||
|
|
run: async (game, player) => {
|
|||
|
|
const state = game.value;
|
|||
|
|
|
|||
|
|
// 即使让过,也会受到敌人反击
|
|||
|
|
// TODO: 实现反击逻辑
|
|||
|
|
|
|||
|
|
return {success: true, result: {message: `${player} 让过`}};
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 检查敌人是否被击败
|
|||
|
|
*/
|
|||
|
|
const checkEnemyDefeatedCmd = registry.register({
|
|||
|
|
schema: 'check-enemy-defeated',
|
|||
|
|
run: async (game) => {
|
|||
|
|
const state = game.value;
|
|||
|
|
|
|||
|
|
if (!state.currentEnemy) {
|
|||
|
|
return {success: false, error: '没有活跃的敌人'};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const isDefeated = state.currentEnemy.hp <= 0;
|
|||
|
|
|
|||
|
|
if (isDefeated) {
|
|||
|
|
// 敌人被击败,移到弃牌堆
|
|||
|
|
game.produce(state => {
|
|||
|
|
// TODO: 将当前敌人移到弃牌堆
|
|||
|
|
// TODO: 翻开下一个敌人
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {success: true, result: {isDefeated, enemy: state.currentEnemy}};
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
export {
|
|||
|
|
playCmd as play,
|
|||
|
|
passCmd as pass,
|
|||
|
|
checkEnemyDefeatedCmd as checkEnemyDefeated,
|
|||
|
|
};
|