fix logic
This commit is contained in:
parent
34eea8ac2e
commit
bcc2913d0f
1 changed files with 11 additions and 12 deletions
|
|
@ -87,9 +87,9 @@ export class QuizService {
|
|||
//question.answered = true;
|
||||
question.answeredBy = id;
|
||||
this.logger.verbose(`extra ${question.note}`);
|
||||
// this.eventBus.publish(
|
||||
// new ValidAnswerReceivedEvent(id, filtered, question.note),
|
||||
// );
|
||||
this.eventBus.publish(
|
||||
new ValidAnswerReceivedEvent(id, filtered, question.note),
|
||||
);
|
||||
await question.save();
|
||||
await this.markQuestionStorageAsAnsweredCorrectly(question.text);
|
||||
return true;
|
||||
|
|
@ -140,15 +140,15 @@ export class QuizService {
|
|||
console.log(playerAnswers);
|
||||
const sortedAnswers = playerAnswers.sort((a, b) => a.time - b.time);
|
||||
const winner = sortedAnswers.find((answer) => answer.valid);
|
||||
let targetUser = 0;
|
||||
if(winner) {
|
||||
const totalWinningScore = 100;
|
||||
sortedAnswers.forEach((answer) => {
|
||||
const totalWinningScore = 80;
|
||||
sortedAnswers.filter(x => x.valid).forEach((answer) => {
|
||||
this.commandBus.execute(new IncreasePlayerWinningRateCommand(answer.user,
|
||||
totalWinningScore / sortedAnswers.filter((answer) => answer.valid).length))
|
||||
});
|
||||
await this.commandBus.execute(new IncreasePlayerWinningRateCommand(sortedAnswers[0].user, 20));
|
||||
await this.commandBus.execute(new CreateNewQueueItemCommand(winner.user, GameQueueTypes.showresults));
|
||||
|
||||
await this.commandBus.execute(new IncreasePlayerWinningRateCommand(sortedAnswers[0].user, 15));
|
||||
targetUser = winner.user;
|
||||
}
|
||||
|
||||
const invalidAnswers = sortedAnswers.filter((answer) => !answer.valid)
|
||||
|
|
@ -157,11 +157,10 @@ export class QuizService {
|
|||
if(!lastInvalidAnswer) {
|
||||
return;
|
||||
}
|
||||
await this.commandBus.execute(new CreateNewQueueItemCommand(lastInvalidAnswer.user, GameQueueTypes.showresults));
|
||||
await this.commandBus.execute(new CreateNewQueueItemCommand(lastInvalidAnswer.user, GameQueueTypes.penalty, "лох"));
|
||||
|
||||
|
||||
targetUser = lastInvalidAnswer.user;
|
||||
await this.commandBus.execute(new CreateNewQueueItemCommand(lastInvalidAnswer.user, GameQueueTypes.penalty));
|
||||
}
|
||||
await this.commandBus.execute(new CreateNewQueueItemCommand(targetUser, GameQueueTypes.showresults));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue