From 2121f3e74c3de6fbdf6c13433e127e6b68a2b504 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:25:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9D=E7=AE=B1=E5=BC=80=E5=90=AF=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=A2=9D=E5=A4=96=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/chest_bonus_item.json | 12 +++++++++ docs/uaw.md | 2 ++ initdatas/activity_info.json | 2 +- packages/zutils | 2 +- src/controllers/chest.controller.ts | 14 ++++++++-- src/models/ActivityChest.ts | 5 +++- src/services/game.svr.ts | 41 ++++++++++++++++++++++++++--- 7 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 configs/chest_bonus_item.json diff --git a/configs/chest_bonus_item.json b/configs/chest_bonus_item.json new file mode 100644 index 0000000..8a78547 --- /dev/null +++ b/configs/chest_bonus_item.json @@ -0,0 +1,12 @@ +[ + { + "type": 1, + "name": "White List", + "probability": 2 + }, + { + "type": 2, + "name": "NFT", + "probability": 1 + } +] \ No newline at end of file diff --git a/docs/uaw.md b/docs/uaw.md index 6fdcc72..c3f819f 100644 --- a/docs/uaw.md +++ b/docs/uaw.md @@ -589,6 +589,7 @@ body: id: "001", // 物品id type: 1, // 1白单, 2: nft name: "", // 物品名 + desc: "", // 描述 amount: 1 // 数量 } ] @@ -617,6 +618,7 @@ body: id: "001", // 物品id type: 1, // 1白单, 2: nft name: "", // 物品名 + desc: "", // 描述 amount: 1 // 数量 } ] diff --git a/initdatas/activity_info.json b/initdatas/activity_info.json index 0a7a698..4e5458b 100644 --- a/initdatas/activity_info.json +++ b/initdatas/activity_info.json @@ -10,7 +10,7 @@ "title": "", "type": 1, "desc": "", - "score": 0, + "score": 100, "category": "Social Tasks", "autoclaim": false, "cfg": {"icon": "twitter"}, diff --git a/packages/zutils b/packages/zutils index b97e334..0d231aa 160000 --- a/packages/zutils +++ b/packages/zutils @@ -1 +1 @@ -Subproject commit b97e33472f46eb8fb47a8cf3c3924c5d26af5eca +Subproject commit 0d231aa9ed56073c170b41a2c676696e97b1c6ce diff --git a/src/controllers/chest.controller.ts b/src/controllers/chest.controller.ts index ebb1b35..6c3a4cc 100644 --- a/src/controllers/chest.controller.ts +++ b/src/controllers/chest.controller.ts @@ -5,7 +5,7 @@ import { rankKey, rankLevel, updateRankScore } from 'services/rank.svr' import { formatDate } from 'zutils/utils/date.util' import { ScoreRecord } from 'models/ScoreRecord' import { ChestRecord } from 'models/chain/ChestRecord' -import { generateNewChest } from 'services/game.svr' +import { generateChestBonus, generateNewChest } from 'services/game.svr' import { ENHANCE_CHEST_GIFT, MAX_ENHANCE_COUNT_ADV, @@ -265,6 +265,13 @@ class BoxController extends BaseController { chest.status = ChestStatusEnum.OPENED const score = chest.scoreInit + chest.scoreBonus const dateTag = formatDate(new Date()) + let items = await generateChestBonus(chest) + if (!chest.items) { + chest.items = [] + } + items.forEach(item => { + chest.items.push(item.id) + }) await updateRankScore({ user: user.id, score: score, @@ -274,10 +281,12 @@ class BoxController extends BaseController { date: dateTag, chestId: chest.id, level: chest.level, + items: chest.items, }, }) + await chest.save() - return { score } + return { score, items } } /** @@ -296,6 +305,7 @@ class BoxController extends BaseController { level: record.data.level, // @ts-ignore time: record.createdAt.getTime(), + items: record.data.items, } }) } diff --git a/src/models/ActivityChest.ts b/src/models/ActivityChest.ts index 6a6ebab..711e1aa 100644 --- a/src/models/ActivityChest.ts +++ b/src/models/ActivityChest.ts @@ -34,7 +34,7 @@ export enum ChestStatusEnum { this.shareCode = convert({ numStr: shortId, base: 16, to: 52, alphabet }) } }) -class ActivityChestClass extends BaseModule { +export class ActivityChestClass extends BaseModule { // 盒子的分享码 @prop() public shareCode: string @@ -65,6 +65,9 @@ class ActivityChestClass extends BaseModule { public bonusUsers: string[] @prop({ type: () => [Number], default: [] }) public bonusScores: number[] + // 获得的额外奖励 + @prop({ type: () => [String], default: [] }) + public items: string[] public toJson() { return { diff --git a/src/services/game.svr.ts b/src/services/game.svr.ts index aca0c6d..21b408f 100644 --- a/src/services/game.svr.ts +++ b/src/services/game.svr.ts @@ -1,13 +1,15 @@ import { STEP_CHEST_LEVEL, STEP_CHEST_RATE, STEP_SCORE_MAX, STEP_SCORE_MIN } from 'common/Constants' -import { ActivityChest, ChestStatusEnum } from 'models/ActivityChest' -import { ZError } from 'zutils' +import { ActivityChest, ActivityChestClass, ChestStatusEnum } from 'models/ActivityChest' +import { ZError, ZRedisClient } from 'zutils' +import { DocumentType } from '@typegoose/typegoose' const chestCfg = require('../../configs/chest.json') +const chestBonusItems = require('../../configs/chest_bonus_item.json') const chestLevelMap = new Map() -for (let cfg of chestCfg.chests) { +chestCfg.chests.forEach((cfg: any) => { chestLevelMap.set(cfg.level, cfg) -} +}) export const generateNewChest = (uid: string, activity: string, level = 1, status = ChestStatusEnum.LOCKED) => { let cfg = chestLevelMap.get(level) @@ -61,3 +63,34 @@ export const generateStepReward = (uid: string, activity: string, step: number) } return { score, chests } } + +export const generateChestBonus = async (chest: DocumentType) => { + let rewards = [] + // 如果宝箱的助力用户数量小于最大助力次数, 则不生成奖励 + if (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) { + bonusItem = item + break + } + } + if (!bonusItem) { + return [] + } + const redisKey = `chest_bonus_${bonusItem.type}` + const itemId = await new ZRedisClient().spop(redisKey) + if (!itemId) { + return [] + } + rewards.push({ + id: itemId, + type: bonusItem.type, + name: bonusItem.name, + desc: bonusItem.desc, + amount: 1, + }) +}