宝箱开启增加额外奖励
This commit is contained in:
parent
d50448b74e
commit
2121f3e74c
12
configs/chest_bonus_item.json
Normal file
12
configs/chest_bonus_item.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"type": 1,
|
||||||
|
"name": "White List",
|
||||||
|
"probability": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": 2,
|
||||||
|
"name": "NFT",
|
||||||
|
"probability": 1
|
||||||
|
}
|
||||||
|
]
|
@ -589,6 +589,7 @@ body:
|
|||||||
id: "001", // 物品id
|
id: "001", // 物品id
|
||||||
type: 1, // 1白单, 2: nft
|
type: 1, // 1白单, 2: nft
|
||||||
name: "", // 物品名
|
name: "", // 物品名
|
||||||
|
desc: "", // 描述
|
||||||
amount: 1 // 数量
|
amount: 1 // 数量
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -617,6 +618,7 @@ body:
|
|||||||
id: "001", // 物品id
|
id: "001", // 物品id
|
||||||
type: 1, // 1白单, 2: nft
|
type: 1, // 1白单, 2: nft
|
||||||
name: "", // 物品名
|
name: "", // 物品名
|
||||||
|
desc: "", // 描述
|
||||||
amount: 1 // 数量
|
amount: 1 // 数量
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
"title": "",
|
"title": "",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"desc": "",
|
"desc": "",
|
||||||
"score": 0,
|
"score": 100,
|
||||||
"category": "Social Tasks",
|
"category": "Social Tasks",
|
||||||
"autoclaim": false,
|
"autoclaim": false,
|
||||||
"cfg": {"icon": "twitter"},
|
"cfg": {"icon": "twitter"},
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit b97e33472f46eb8fb47a8cf3c3924c5d26af5eca
|
Subproject commit 0d231aa9ed56073c170b41a2c676696e97b1c6ce
|
@ -5,7 +5,7 @@ import { rankKey, rankLevel, updateRankScore } from 'services/rank.svr'
|
|||||||
import { formatDate } from 'zutils/utils/date.util'
|
import { formatDate } from 'zutils/utils/date.util'
|
||||||
import { ScoreRecord } from 'models/ScoreRecord'
|
import { ScoreRecord } from 'models/ScoreRecord'
|
||||||
import { ChestRecord } from 'models/chain/ChestRecord'
|
import { ChestRecord } from 'models/chain/ChestRecord'
|
||||||
import { generateNewChest } from 'services/game.svr'
|
import { generateChestBonus, generateNewChest } from 'services/game.svr'
|
||||||
import {
|
import {
|
||||||
ENHANCE_CHEST_GIFT,
|
ENHANCE_CHEST_GIFT,
|
||||||
MAX_ENHANCE_COUNT_ADV,
|
MAX_ENHANCE_COUNT_ADV,
|
||||||
@ -265,6 +265,13 @@ class BoxController extends BaseController {
|
|||||||
chest.status = ChestStatusEnum.OPENED
|
chest.status = ChestStatusEnum.OPENED
|
||||||
const score = chest.scoreInit + chest.scoreBonus
|
const score = chest.scoreInit + chest.scoreBonus
|
||||||
const dateTag = formatDate(new Date())
|
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({
|
await updateRankScore({
|
||||||
user: user.id,
|
user: user.id,
|
||||||
score: score,
|
score: score,
|
||||||
@ -274,10 +281,12 @@ class BoxController extends BaseController {
|
|||||||
date: dateTag,
|
date: dateTag,
|
||||||
chestId: chest.id,
|
chestId: chest.id,
|
||||||
level: chest.level,
|
level: chest.level,
|
||||||
|
items: chest.items,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
await chest.save()
|
await chest.save()
|
||||||
return { score }
|
return { score, items }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -296,6 +305,7 @@ class BoxController extends BaseController {
|
|||||||
level: record.data.level,
|
level: record.data.level,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
time: record.createdAt.getTime(),
|
time: record.createdAt.getTime(),
|
||||||
|
items: record.data.items,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ export enum ChestStatusEnum {
|
|||||||
this.shareCode = convert({ numStr: shortId, base: 16, to: 52, alphabet })
|
this.shareCode = convert({ numStr: shortId, base: 16, to: 52, alphabet })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
class ActivityChestClass extends BaseModule {
|
export class ActivityChestClass extends BaseModule {
|
||||||
// 盒子的分享码
|
// 盒子的分享码
|
||||||
@prop()
|
@prop()
|
||||||
public shareCode: string
|
public shareCode: string
|
||||||
@ -65,6 +65,9 @@ class ActivityChestClass extends BaseModule {
|
|||||||
public bonusUsers: string[]
|
public bonusUsers: string[]
|
||||||
@prop({ type: () => [Number], default: [] })
|
@prop({ type: () => [Number], default: [] })
|
||||||
public bonusScores: number[]
|
public bonusScores: number[]
|
||||||
|
// 获得的额外奖励
|
||||||
|
@prop({ type: () => [String], default: [] })
|
||||||
|
public items: string[]
|
||||||
|
|
||||||
public toJson() {
|
public toJson() {
|
||||||
return {
|
return {
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { STEP_CHEST_LEVEL, STEP_CHEST_RATE, STEP_SCORE_MAX, STEP_SCORE_MIN } from 'common/Constants'
|
import { STEP_CHEST_LEVEL, STEP_CHEST_RATE, STEP_SCORE_MAX, STEP_SCORE_MIN } from 'common/Constants'
|
||||||
import { ActivityChest, ChestStatusEnum } from 'models/ActivityChest'
|
import { ActivityChest, ActivityChestClass, ChestStatusEnum } from 'models/ActivityChest'
|
||||||
import { ZError } from 'zutils'
|
import { ZError, ZRedisClient } from 'zutils'
|
||||||
|
import { DocumentType } from '@typegoose/typegoose'
|
||||||
|
|
||||||
const chestCfg = require('../../configs/chest.json')
|
const chestCfg = require('../../configs/chest.json')
|
||||||
|
const chestBonusItems = require('../../configs/chest_bonus_item.json')
|
||||||
const chestLevelMap = new Map()
|
const chestLevelMap = new Map()
|
||||||
|
|
||||||
for (let cfg of chestCfg.chests) {
|
chestCfg.chests.forEach((cfg: any) => {
|
||||||
chestLevelMap.set(cfg.level, cfg)
|
chestLevelMap.set(cfg.level, cfg)
|
||||||
}
|
})
|
||||||
|
|
||||||
export const generateNewChest = (uid: string, activity: string, level = 1, status = ChestStatusEnum.LOCKED) => {
|
export const generateNewChest = (uid: string, activity: string, level = 1, status = ChestStatusEnum.LOCKED) => {
|
||||||
let cfg = chestLevelMap.get(level)
|
let cfg = chestLevelMap.get(level)
|
||||||
@ -61,3 +63,34 @@ export const generateStepReward = (uid: string, activity: string, step: number)
|
|||||||
}
|
}
|
||||||
return { score, chests }
|
return { score, chests }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const generateChestBonus = async (chest: DocumentType<ActivityChestClass>) => {
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user