From c45c4c5bf46eec7a68b30a8b2cfdf4567c372601 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=80=E5=AE=9D=E7=AE=B1?= =?UTF-8?q?=E9=80=BB=E8=BE=91,=20=E6=B5=8B=E8=AF=95=E6=9C=8D=E4=B8=8D?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E5=8A=A9=E5=8A=9B=E6=BB=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/chest_bonus_item.json | 4 ++-- src/controllers/chest.controller.ts | 23 +++++++++++------------ src/services/game.svr.ts | 8 ++++++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/configs/chest_bonus_item.json b/configs/chest_bonus_item.json index 8a78547..e4af209 100644 --- a/configs/chest_bonus_item.json +++ b/configs/chest_bonus_item.json @@ -2,11 +2,11 @@ { "type": 1, "name": "White List", - "probability": 2 + "probability": 100 }, { "type": 2, "name": "NFT", - "probability": 1 + "probability": 100 } ] \ No newline at end of file diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index 93e3fbb..9a016e0 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -338,18 +338,17 @@ class BoxController extends BaseController { const score = chest.scoreInit + chest.scoreBonus const dateTag = formatDate(new Date()) let items: any[] = [] - if (!user.inWhiteList) { - items = await generateChestBonus(chest) - if (!chest.items) { - chest.items = [] - } - items.forEach(item => { - chest.items.push(item.id) - }) - if (items.find(item => item.type === 1)) { - user.inWhiteList = true - await user.save() - } + + items = await generateChestBonus(chest, user.inWhiteList) + if (!chest.items) { + chest.items = [] + } + items.forEach(item => { + chest.items.push(item.id) + }) + if (items.find(item => item.type === 1)) { + user.inWhiteList = true + await user.save() } await updateRankScore({ diff --git a/src/services/game.svr.ts b/src/services/game.svr.ts index 7ec007b..48af435 100644 --- a/src/services/game.svr.ts +++ b/src/services/game.svr.ts @@ -87,16 +87,19 @@ export const generateStepReward = (uid: string, activity: string, step: number) return { score, chests } } -export const generateChestBonus = async (chest: DocumentType) => { +export const generateChestBonus = async (chest: DocumentType, hasWhite: boolean) => { let rewards = [] // 如果宝箱的助力用户数量小于最大助力次数, 则不生成奖励 - if (chest.bonusUsers.length < chest.maxBounsCount) { + if (process.env.NODE_ENV === 'production' && chest.bonusUsers.length < chest.maxBounsCount) { return [] } let bonusItem for (let i = 0; i < chestBonusItems.length; i++) { let item = chestBonusItems[i] if (Math.random() < item.probability / 100) { + if (item.type === 1 && hasWhite) { + continue + } bonusItem = item break } @@ -116,4 +119,5 @@ export const generateChestBonus = async (chest: DocumentType desc: bonusItem.desc, amount: 1, }) + return rewards }