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.answered = true;
|
||||||
question.answeredBy = id;
|
question.answeredBy = id;
|
||||||
this.logger.verbose(`extra ${question.note}`);
|
this.logger.verbose(`extra ${question.note}`);
|
||||||
// this.eventBus.publish(
|
this.eventBus.publish(
|
||||||
// new ValidAnswerReceivedEvent(id, filtered, question.note),
|
new ValidAnswerReceivedEvent(id, filtered, question.note),
|
||||||
// );
|
);
|
||||||
await question.save();
|
await question.save();
|
||||||
await this.markQuestionStorageAsAnsweredCorrectly(question.text);
|
await this.markQuestionStorageAsAnsweredCorrectly(question.text);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -140,15 +140,15 @@ export class QuizService {
|
||||||
console.log(playerAnswers);
|
console.log(playerAnswers);
|
||||||
const sortedAnswers = playerAnswers.sort((a, b) => a.time - b.time);
|
const sortedAnswers = playerAnswers.sort((a, b) => a.time - b.time);
|
||||||
const winner = sortedAnswers.find((answer) => answer.valid);
|
const winner = sortedAnswers.find((answer) => answer.valid);
|
||||||
|
let targetUser = 0;
|
||||||
if(winner) {
|
if(winner) {
|
||||||
const totalWinningScore = 100;
|
const totalWinningScore = 80;
|
||||||
sortedAnswers.forEach((answer) => {
|
sortedAnswers.filter(x => x.valid).forEach((answer) => {
|
||||||
this.commandBus.execute(new IncreasePlayerWinningRateCommand(answer.user,
|
this.commandBus.execute(new IncreasePlayerWinningRateCommand(answer.user,
|
||||||
totalWinningScore / sortedAnswers.filter((answer) => answer.valid).length))
|
totalWinningScore / sortedAnswers.filter((answer) => answer.valid).length))
|
||||||
});
|
});
|
||||||
await this.commandBus.execute(new IncreasePlayerWinningRateCommand(sortedAnswers[0].user, 20));
|
await this.commandBus.execute(new IncreasePlayerWinningRateCommand(sortedAnswers[0].user, 15));
|
||||||
await this.commandBus.execute(new CreateNewQueueItemCommand(winner.user, GameQueueTypes.showresults));
|
targetUser = winner.user;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const invalidAnswers = sortedAnswers.filter((answer) => !answer.valid)
|
const invalidAnswers = sortedAnswers.filter((answer) => !answer.valid)
|
||||||
|
|
@ -157,11 +157,10 @@ export class QuizService {
|
||||||
if(!lastInvalidAnswer) {
|
if(!lastInvalidAnswer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.commandBus.execute(new CreateNewQueueItemCommand(lastInvalidAnswer.user, GameQueueTypes.showresults));
|
targetUser = lastInvalidAnswer.user;
|
||||||
await this.commandBus.execute(new CreateNewQueueItemCommand(lastInvalidAnswer.user, GameQueueTypes.penalty, "лох"));
|
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