Les échecs de défis donnent lieu à un mouvement de points nul

This commit is contained in:
2024-12-14 13:30:26 +01:00
parent 9dfb2ba15d
commit 979362d012
6 changed files with 52 additions and 12 deletions

View File

@ -75,7 +75,7 @@ export class ChallengeActionsService {
data: {
playerId: player.id,
amount: challenge.reward,
reason: MoneyUpdateType.WIN_CHALLENGE,
reason: MoneyUpdateType.CHALLENGE,
actionId: challengeAction.id,
}
})
@ -87,6 +87,14 @@ export class ChallengeActionsService {
penaltyStart: now,
penaltyEnd: new Date(now.getTime() + Constants.PENALTY_TIME * 60 * 1000),
}
await this.prisma.moneyUpdate.create({
data: {
playerId: player.id,
amount: 0,
reason: MoneyUpdateType.CHALLENGE,
actionId: challengeAction.id,
}
})
}
await this.prisma.player.update({
where: { id: player.id },

View File

@ -164,14 +164,14 @@ export class GameService {
await this.prisma.moneyUpdate.deleteMany({ where: { reason: MoneyUpdateType.BUY_TRAIN, tripId: null } })
deleted.push(...orpanTrainMoneyUpdates)
const challengeActions = await this.prisma.challengeAction.findMany({ include: { moneyUpdate: true, challenge: true } })
const challengeActions = await this.prisma.challengeAction.findMany({ include: { moneyUpdate: true, challenge: true, activePlayer: true } })
for (const challengeAction of challengeActions) {
if (challengeAction.success && !challengeAction.moneyUpdate) {
const challengeMoneyUpdate = await this.prisma.moneyUpdate.create({
data: {
playerId: challengeAction.playerId,
amount: challengeAction.challenge.reward,
reason: MoneyUpdateType.WIN_CHALLENGE,
reason: MoneyUpdateType.CHALLENGE,
actionId: challengeAction.id,
}
})
@ -184,14 +184,32 @@ export class GameService {
})
modified.push(modifiedMoneyUpdate)
}
else if (!challengeAction.success && challengeAction.moneyUpdate) {
else if (!challengeAction.success && !challengeAction.activePlayer && !challengeAction.moneyUpdate) {
const challengeMoneyUpdate = await this.prisma.moneyUpdate.create({
data: {
playerId: challengeAction.playerId,
amount: 0,
reason: MoneyUpdateType.CHALLENGE,
actionId: challengeAction.id,
}
})
added.push(challengeMoneyUpdate)
}
else if (!challengeAction.success && !challengeAction.activePlayer && challengeAction.moneyUpdate.amount !== 0) {
const modifiedMoneyUpdate = await this.prisma.moneyUpdate.update({
where: { id: challengeAction.moneyUpdate.id },
data: { amount: 0 },
})
modified.push(modifiedMoneyUpdate)
}
else if (!challengeAction.success && challengeAction.activePlayer && challengeAction.moneyUpdate) {
deleted.push(challengeAction.moneyUpdate)
await this.prisma.moneyUpdate.delete({ where: { id: challengeAction.moneyUpdate.id } })
}
}
const orpanChallengeMoneyUpdates = await this.prisma.moneyUpdate.findMany({ where: { reason: MoneyUpdateType.WIN_CHALLENGE, actionId: null } })
await this.prisma.moneyUpdate.deleteMany({ where: { reason: MoneyUpdateType.WIN_CHALLENGE, actionId: null } })
const orpanChallengeMoneyUpdates = await this.prisma.moneyUpdate.findMany({ where: { reason: MoneyUpdateType.CHALLENGE, actionId: null } })
await this.prisma.moneyUpdate.deleteMany({ where: { reason: MoneyUpdateType.CHALLENGE, actionId: null } })
deleted.push(...orpanChallengeMoneyUpdates)
return { added: added, modified: modified, deleted: deleted }