Versus fixes
This commit is contained in:
parent
ac9116e138
commit
666240dfb8
10 changed files with 97 additions and 8 deletions
13
src/game/comand-handlers/begin-versus-command.handler.ts
Normal file
13
src/game/comand-handlers/begin-versus-command.handler.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {CommandHandler, ICommandHandler} from "@nestjs/cqrs";
|
||||||
|
import {BeginVersusCommand} from "../commands/begin-versus.command";
|
||||||
|
import {VersusService} from "../versus/versus.service";
|
||||||
|
|
||||||
|
@CommandHandler(BeginVersusCommand)
|
||||||
|
export class BeginVersusCommandHandler implements ICommandHandler<BeginVersusCommand> {
|
||||||
|
constructor(private versusService:VersusService) {
|
||||||
|
}
|
||||||
|
execute(command: BeginVersusCommand): Promise<any> {
|
||||||
|
return this.versusService.beginVersus(command.sourceId,command.destinationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
6
src/game/commands/begin-versus.command.ts
Normal file
6
src/game/commands/begin-versus.command.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
export class BeginVersusCommand {
|
||||||
|
constructor(public sourceId: number, public destinationId: number) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,8 +19,9 @@ import {SetGuestPropertyCommand} from "../../guests/command/set-guest-property.c
|
||||||
import {StringHelper} from "../../helpers/stringhelper";
|
import {StringHelper} from "../../helpers/stringhelper";
|
||||||
import {GetGuestQuery} from "../../guests/queries/getguest.query";
|
import {GetGuestQuery} from "../../guests/queries/getguest.query";
|
||||||
import {CardsSetChangedEvent} from "../events/cards-events/cards-set-changed.event";
|
import {CardsSetChangedEvent} from "../events/cards-events/cards-set-changed.event";
|
||||||
import {GetGuestPropertyQuery} from "../../guests/command/get-guest-property.handler";
|
|
||||||
import {GuestPropertiesConsts} from "../../schemas/properties.consts";
|
import {GuestPropertiesConsts} from "../../schemas/properties.consts";
|
||||||
|
import {BeginVersusCommand} from "../commands/begin-versus.command";
|
||||||
|
import {CheckIfAnotherVersusInProgressQuery} from "../queries/check-if-another-versus-in-progress.query";
|
||||||
|
|
||||||
export interface IGameCard {
|
export interface IGameCard {
|
||||||
setupHandlers(eventBus: EventBus, commandBus: CommandBus, queryBus: QueryBus): void;
|
setupHandlers(eventBus: EventBus, commandBus: CommandBus, queryBus: QueryBus): void;
|
||||||
|
|
@ -74,7 +75,7 @@ export class DoubleTreasureCard extends GameCard {
|
||||||
await this.commandBus.execute(
|
await this.commandBus.execute(
|
||||||
new GiveOutAPrizeCommand(this.telegramId),
|
new GiveOutAPrizeCommand(this.telegramId),
|
||||||
);
|
);
|
||||||
const userSrc = await this.queryBus.execute(new GetGuestQuery(this.telegramId));;
|
const userSrc = await this.queryBus.execute(new GetGuestQuery(this.telegramId));
|
||||||
const subjcaseFrom = userSrc.get(StringHelper.getPropertyName(GuestPropertiesConsts.NameSubjectiveCase));
|
const subjcaseFrom = userSrc.get(StringHelper.getPropertyName(GuestPropertiesConsts.NameSubjectiveCase));
|
||||||
const message = `${subjcaseFrom} решает удвоить приз!`;
|
const message = `${subjcaseFrom} решает удвоить приз!`;
|
||||||
await this.commandBus.execute(new SendToastCommand(message, 8000));
|
await this.commandBus.execute(new SendToastCommand(message, 8000));
|
||||||
|
|
@ -174,6 +175,45 @@ export class AvoidPenaltyCard extends GameCard {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class VersusCard extends GameCard {
|
||||||
|
dealOnStart = true;
|
||||||
|
name = VersusCard.name;
|
||||||
|
chance = 10;
|
||||||
|
emoji = '🆚';
|
||||||
|
description = 'Поединок';
|
||||||
|
mightBePlayed = QuizAnswerStateEnum.betweenRounds;
|
||||||
|
async setupHandlers(eventBus: EventBus, commandBus: CommandBus, queryBus: QueryBus) {
|
||||||
|
super.setupHandlers(eventBus, commandBus, queryBus);
|
||||||
|
eventBus.pipe(
|
||||||
|
ofType(DebuffCardPlayedEvent),
|
||||||
|
filter(x => x.debufName == DebuffsConsts.versus))
|
||||||
|
.subscribe(async (r) =>{
|
||||||
|
const versusInProgress = await queryBus.execute(new CheckIfAnotherVersusInProgressQuery());
|
||||||
|
this.logger.verbose(`versusInProgress ${versusInProgress}`);
|
||||||
|
if(versusInProgress) {
|
||||||
|
this.logger.warn(`another versus in progress`);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const destUser = await queryBus.execute(new GetGuestQuery(r.dest))
|
||||||
|
const sourceUser = await queryBus.execute(new GetGuestQuery(r.from));
|
||||||
|
await commandBus.execute(new BeginVersusCommand(sourceUser.telegramId, destUser.telegramId));
|
||||||
|
});
|
||||||
|
//eventBus.pipe(ofType(DebuffCardPlayedEvent)).subscribe(r => console.log(r));
|
||||||
|
}
|
||||||
|
async handle() {
|
||||||
|
await this.commandBus.execute(
|
||||||
|
new SelectTargetPlayerCommand(this.telegramId, DebuffsConsts.versus, 0)
|
||||||
|
)
|
||||||
|
await this.queryBus.execute(new FilterGuestsWithPropertyQuery(null,null,null));
|
||||||
|
this.eventBus.subscribe((data) =>{
|
||||||
|
this.logger.verbose(`Response from cmdBus: ${data}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BanPlayer extends GameCard {
|
export class BanPlayer extends GameCard {
|
||||||
dealOnStart = true;
|
dealOnStart = true;
|
||||||
|
|
@ -227,5 +267,6 @@ export const gameCards: typeof GameCard[] = [
|
||||||
ShitCard,
|
ShitCard,
|
||||||
LuckyCard,
|
LuckyCard,
|
||||||
AvoidPenaltyCard,
|
AvoidPenaltyCard,
|
||||||
BanPlayer
|
BanPlayer,
|
||||||
|
VersusCard,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
export class DebuffsConsts {
|
export class DebuffsConsts {
|
||||||
static bannedFor = 'bannedFor';
|
static bannedFor = 'bannedFor';
|
||||||
|
static versus = 'versus';
|
||||||
}
|
}
|
||||||
|
|
@ -20,6 +20,8 @@ import {GuestsModule} from "../guests/guests.module";
|
||||||
import { VersusService } from './versus/versus.service';
|
import { VersusService } from './versus/versus.service';
|
||||||
import { VersusController } from './versus/versus.controller';
|
import { VersusController } from './versus/versus.controller';
|
||||||
import {Versus, VersusSchema} from "../schemas/versus.schema";
|
import {Versus, VersusSchema} from "../schemas/versus.schema";
|
||||||
|
import {BeginVersusCommandHandler} from "./comand-handlers/begin-versus-command.handler";
|
||||||
|
import {CheckIfAnotherVersusInProgressHandler} from "./queries/handlers/check-if-another-versus-in-progress.handler";
|
||||||
|
|
||||||
|
|
||||||
const eventHandlers = [
|
const eventHandlers = [
|
||||||
|
|
@ -37,8 +39,11 @@ const commandHandlers = [
|
||||||
GamePrizeChanceIncreasedEventHandler,
|
GamePrizeChanceIncreasedEventHandler,
|
||||||
GameProceedGameQueueCommandHandler,
|
GameProceedGameQueueCommandHandler,
|
||||||
SelectTargetPlayerHandler,
|
SelectTargetPlayerHandler,
|
||||||
SendBetweenRoundsActionsHandler
|
SendBetweenRoundsActionsHandler,
|
||||||
|
BeginVersusCommandHandler,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const queryHandlers = [CheckIfAnotherVersusInProgressHandler];
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
|
@ -49,7 +54,7 @@ const commandHandlers = [
|
||||||
]),
|
]),
|
||||||
forwardRef(() => GuestsModule)
|
forwardRef(() => GuestsModule)
|
||||||
],
|
],
|
||||||
providers: [GameService, ConfigService, ...eventHandlers, ...commandHandlers, VersusService],
|
providers: [GameService, ConfigService, ...eventHandlers, ...commandHandlers,...queryHandlers, VersusService],
|
||||||
exports: [GameService],
|
exports: [GameService],
|
||||||
controllers: [GameController, VersusController],
|
controllers: [GameController, VersusController],
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
export class CheckIfAnotherVersusInProgressQuery {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {IQueryHandler, QueryHandler} from "@nestjs/cqrs";
|
||||||
|
import {CheckIfAnotherVersusInProgressQuery} from "../check-if-another-versus-in-progress.query";
|
||||||
|
import {VersusService} from "../../versus/versus.service";
|
||||||
|
|
||||||
|
@QueryHandler(CheckIfAnotherVersusInProgressQuery)
|
||||||
|
export class CheckIfAnotherVersusInProgressHandler implements IQueryHandler<CheckIfAnotherVersusInProgressHandler> {
|
||||||
|
constructor(private versusService: VersusService) {
|
||||||
|
}
|
||||||
|
async execute(query: CheckIfAnotherVersusInProgressHandler): Promise<any> {
|
||||||
|
return await this.versusService.checkIfAnotherVersusInProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import {Injectable, Logger} from '@nestjs/common';
|
||||||
import {SocketEvents} from "../../shared/events.consts";
|
import {SocketEvents} from "../../shared/events.consts";
|
||||||
import {GuestsService} from "../../guests/guests.service";
|
import {GuestsService} from "../../guests/guests.service";
|
||||||
import {SharedService} from "../../shared/shared.service";
|
import {SharedService} from "../../shared/shared.service";
|
||||||
|
|
@ -14,6 +14,7 @@ import {IncreasePlayerWinningRateCommand} from "../commands/increase-player-winn
|
||||||
export class VersusService {
|
export class VersusService {
|
||||||
static configKeyCurrentAction = 'current_action';
|
static configKeyCurrentAction = 'current_action';
|
||||||
static configKeyActiveVersus = 'active_versus';
|
static configKeyActiveVersus = 'active_versus';
|
||||||
|
private logger = new Logger(VersusService.name);
|
||||||
constructor(
|
constructor(
|
||||||
private guestService: GuestsService,
|
private guestService: GuestsService,
|
||||||
private sharedService: SharedService,
|
private sharedService: SharedService,
|
||||||
|
|
@ -95,4 +96,11 @@ export class VersusService {
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkIfAnotherVersusInProgress() {
|
||||||
|
this.logger.debug(`checkIfAnotherVersusInProgress enter`)
|
||||||
|
const currentAction = await this.sharedService.getConfig(VersusService.configKeyCurrentAction);
|
||||||
|
return currentAction.value !== '';
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import {Promise} from "mongoose";
|
||||||
import {GuestsService} from "../guests.service";
|
import {GuestsService} from "../guests.service";
|
||||||
|
|
||||||
export class SendBetweenRoundsActionsCommand {
|
export class SendBetweenRoundsActionsCommand {
|
||||||
constructor(public user: number, public inline: boolean = false) {
|
constructor(public user: number, public inline: boolean = true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import {IQueryHandler, QueryHandler} from "@nestjs/cqrs";
|
import {IQueryHandler, QueryHandler} from "@nestjs/cqrs";
|
||||||
import {GetGuestQuery} from "../getguest.query";
|
import {GetGuestQuery} from "../getguest.query";
|
||||||
import {Promise} from "mongoose";
|
|
||||||
import {GuestsService} from "../../guests.service";
|
import {GuestsService} from "../../guests.service";
|
||||||
|
|
||||||
@QueryHandler(GetGuestQuery)
|
@QueryHandler(GetGuestQuery)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue