Les échecs de défis donnent lieu à un mouvement de points nul
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- The values [WIN_CHALLENGE] on the enum `MoneyUpdateType` will be removed. If these variants are still used in the database, this will fail.
|
||||
|
||||
*/
|
||||
-- AlterEnum
|
||||
BEGIN;
|
||||
CREATE TYPE "MoneyUpdateType_new" AS ENUM ('START', 'NEW_RUN', 'CHALLENGE', 'BUY_TRAIN');
|
||||
ALTER TABLE "MoneyUpdate" ALTER COLUMN "reason" TYPE "MoneyUpdateType_new" USING ("reason"::text::"MoneyUpdateType_new");
|
||||
ALTER TYPE "MoneyUpdateType" RENAME TO "MoneyUpdateType_old";
|
||||
ALTER TYPE "MoneyUpdateType_new" RENAME TO "MoneyUpdateType";
|
||||
DROP TYPE "MoneyUpdateType_old";
|
||||
COMMIT;
|
@@ -114,6 +114,6 @@ model MoneyUpdate {
|
||||
enum MoneyUpdateType {
|
||||
START
|
||||
NEW_RUN
|
||||
WIN_CHALLENGE
|
||||
CHALLENGE
|
||||
BUY_TRAIN
|
||||
}
|
||||
|
@@ -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 },
|
||||
|
@@ -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 }
|
||||
|
Reference in New Issue
Block a user