Freeze pack rates in a campaign when it is created
A gifted pack using the pack's own rates was drawn with whatever rates were in force when the player opened it. Campaigns now copy those rates at creation (packRates), every pack of the code draws with them, and the reveal shows them. Older campaigns keep following the live rates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
26984bb6c0
commit
fd47514d81
6 changed files with 57 additions and 7 deletions
|
|
@ -10,7 +10,9 @@ export const MAX_ITEM_QUANTITY = 10;
|
|||
|
||||
// Une récompense est une liste d'éléments : { items: [élément, …] }, au plus 50 éléments.
|
||||
// Élément « carte » : { type: "card", editionId, quantity: 1 }, chaque carte au plus une fois
|
||||
// Élément « paquet » : { type: "pack", collectionId, rarityWeights | null, guarantee | null, quantity }
|
||||
// Élément « paquet » : { type: "pack", collectionId, rarityWeights | null, packRates | null, guarantee | null, quantity }
|
||||
// packRates : sans taux personnalisés, copie des taux du paquet à la création de la campagne ; chaque joueur
|
||||
// du code tire avec ces taux, même si l'administration modifie ensuite ceux du paquet.
|
||||
// guarantee : { type: "rarity", rarity, count (1 à 3) } ou { type: "edition", editionId }
|
||||
export function normalizeReward(reward, catalog) {
|
||||
const items = reward?.items;
|
||||
|
|
@ -66,5 +68,6 @@ function normalizeItem(reward, catalog) {
|
|||
invalid("Garantie inconnue.");
|
||||
}
|
||||
if (!rarityWeights && !collection.dropWeights) invalid("Cette collection n’a pas de taux de tirage : définissez des taux personnalisés.");
|
||||
return { type: "pack", collectionId: collection.id, rarityWeights, guarantee };
|
||||
const packRates = rarityWeights ? null : Object.fromEntries(catalog.rarities.map((rarity) => [rarity.id, collection.dropWeights[rarity.id] ?? 0]));
|
||||
return { type: "pack", collectionId: collection.id, rarityWeights, packRates, guarantee };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -762,7 +762,7 @@ export class CardsService {
|
|||
const gift = this.db.prepare("SELECT * FROM gift_packs WHERE id = ? AND player_id = ? AND opening_id IS NULL").get(giftPackId, playerId);
|
||||
if (!gift) fail(404, "GIFT_PACK_NOT_FOUND", "Ce paquet offert n'est plus disponible.");
|
||||
const options = JSON.parse(gift.options_json);
|
||||
const { openingId, editionIds } = this.insertOpening(playerId, gift.collection_id, drawPack(this.catalog, gift.collection_id, this.random, { weights: options.rarityWeights, guarantee: options.guarantee, requireActive: false }));
|
||||
const { openingId, editionIds } = this.insertOpening(playerId, gift.collection_id, drawPack(this.catalog, gift.collection_id, this.random, { weights: options.rarityWeights ?? options.packRates ?? null, guarantee: options.guarantee, requireActive: false }));
|
||||
this.db.prepare("UPDATE gift_packs SET opening_id = ?, opened_at = ? WHERE id = ?").run(openingId, this.now(), gift.id);
|
||||
this.audit(playerId, "gift_pack_opened", openingId, { collectionId: gift.collection_id, campaignId: gift.campaign_id, ...(gift.expedition_id ? { expeditionId: gift.expedition_id } : {}), cards: editionIds });
|
||||
return openingId;
|
||||
|
|
@ -1154,7 +1154,8 @@ export class CardsService {
|
|||
if (!edition) fail(409, "REWARD_UNAVAILABLE", "Une carte de cette récompense n’existe plus dans le catalogue.");
|
||||
this.addCard(playerId, edition.id);
|
||||
} else {
|
||||
const options = { rarityWeights: item.rarityWeights, guarantee: item.guarantee };
|
||||
// Les campagnes créées avant packRates gardent null : leurs paquets suivent les taux en vigueur à l'ouverture.
|
||||
const options = { rarityWeights: item.rarityWeights, packRates: item.packRates ?? null, guarantee: item.guarantee };
|
||||
this.db.prepare("INSERT INTO gift_packs(id, player_id, campaign_id, collection_id, options_json, created_at) VALUES (?, ?, ?, ?, ?, ?)")
|
||||
.run(randomUUID(), playerId, row.id, item.collectionId, JSON.stringify(options), this.now());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue