✨ feat(礼包): 礼包添加保底
This commit is contained in:
@@ -5,13 +5,15 @@ import { RewardParam } from '../../domain/activityField/rewardField';
|
||||
import { CreateHeroParam } from '../../domain/roleField/hero';
|
||||
import { DicGiftPackage } from '../../pubUtils/dictionary/DicGiftPackage';
|
||||
import { ItemInter, RewardInter } from '../../pubUtils/interface';
|
||||
import { decodeArrayListStr, resResult } from '../../pubUtils/util';
|
||||
import { decodeArrayListStr, getRandEelmWithWeight, resResult } from '../../pubUtils/util';
|
||||
import { createHeroes } from '../role/createHero';
|
||||
import { GuildModel } from '../../db/Guild';
|
||||
import { pushGuildInfoUpdate } from '../guildService';
|
||||
import { combineItems } from '../role/util';
|
||||
import { recordGuildFund } from './timeLimitRankService';
|
||||
import { filterGoods, isGoodsHidden, isHeroHidden } from '../dataService';
|
||||
import { DicGiftPackagePlan } from '../../pubUtils/dictionary/DicGiftPackagePlan';
|
||||
import { GiftPackageFloorModel } from '../../db/GiftPackageFloor';
|
||||
|
||||
|
||||
|
||||
@@ -32,17 +34,14 @@ export async function useGiftPackage(roleId: string, roleName: string, sid: stri
|
||||
}
|
||||
console.log('dddddddddddddd', giftID, JSON.stringify(giftPackageData))
|
||||
let giftType = giftPackageData.type;//礼包类型
|
||||
let reward = giftPackageData.reward;//奖励内容,数组
|
||||
let dicGiftPackagePlan = gameData.giftPackagePlan.get(giftPackageData.id)||[];
|
||||
|
||||
switch (giftType) {
|
||||
case GIFT_PACKAGE_TYPE.ALL://全部
|
||||
{
|
||||
let allReward = [];
|
||||
if (giftCount > 1) {
|
||||
for (let obj of reward) {
|
||||
allReward.push({ type: obj.type, id: obj.id, count: obj.count * giftCount })
|
||||
}
|
||||
} else {
|
||||
allReward = reward;
|
||||
for (let obj of dicGiftPackagePlan) {
|
||||
allReward.push({ type: obj.contentType, id: obj.content, count: obj.count * giftCount });
|
||||
}
|
||||
|
||||
result = await addReward(roleId, roleName, sid, serverId, allReward, ITEM_CHANGE_REASON.USE_GIFT_PACKAGE);
|
||||
@@ -54,14 +53,10 @@ export async function useGiftPackage(roleId: string, roleName: string, sid: stri
|
||||
if (selected.length != count) {
|
||||
break;
|
||||
}
|
||||
let selectedReward = getSelectedReward(giftPackageData.reward, selected)
|
||||
let selectedReward = getSelectedReward(dicGiftPackagePlan, selected)
|
||||
let allReward: { type: number, id: number, count: number }[] = [];
|
||||
if (giftCount > 1) {
|
||||
for (let obj of selectedReward) {
|
||||
allReward.push({ type: obj.type, id: obj.id, count: obj.count * giftCount })
|
||||
}
|
||||
} else {
|
||||
allReward = selectedReward;
|
||||
for (let obj of selectedReward) {
|
||||
allReward.push({ type: obj.type, id: obj.id, count: obj.count * giftCount });
|
||||
}
|
||||
let gids = allReward.filter(cur => cur.type == 2).map(cur => cur.id);
|
||||
if(gids.length > 0 && isGoodsHidden(...gids)) return resResult(STATUS.ITEM_IS_HIDDEN);
|
||||
@@ -74,12 +69,12 @@ export async function useGiftPackage(roleId: string, roleName: string, sid: stri
|
||||
case GIFT_PACKAGE_TYPE.RANDOM_X://随机
|
||||
{
|
||||
let count = giftPackageData.count;//随机个数
|
||||
let pool = giftPackageData.reward.filter(cur => cur.type == 1? !isHeroHidden(cur.id): !isGoodsHidden(cur.id));
|
||||
let pool = dicGiftPackagePlan.filter(cur => cur.contentType == 1? !isHeroHidden(cur.id): !isGoodsHidden(cur.id));
|
||||
if(pool.length <= 0) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let allReward: { type: number, id: number, count: number }[] = [];
|
||||
for (let i = 0; i < giftCount; i++) {
|
||||
let selectedArray = randomSelectedData(pool.length, count);
|
||||
let selectedReward = getSelectedReward(pool, selectedArray)
|
||||
allReward.push(...selectedReward);
|
||||
let rewards = await randomSelectedData(pool, roleId, giftID, count);
|
||||
allReward.push(...rewards);
|
||||
}
|
||||
result = await addReward(roleId, roleName, sid, serverId, allReward, ITEM_CHANGE_REASON.USE_GIFT_PACKAGE);
|
||||
break;
|
||||
@@ -144,28 +139,54 @@ export function rewardItemData(reward: Array<RewardParam>) {
|
||||
return { goods, heroes }
|
||||
}
|
||||
|
||||
export function getSelectedReward(reward: RewardParam[], selected: Array<number>): Array<RewardParam> {
|
||||
console.log('bbbbbbbbbbbbbbbbbbb', JSON.stringify(selected), JSON.stringify(reward))
|
||||
export function getSelectedReward(plans: DicGiftPackagePlan[], selected: Array<number>): Array<RewardParam> {
|
||||
|
||||
let selectedReward: Array<RewardParam> = [];
|
||||
for (let i = 0; i < selected.length; i++) {
|
||||
let index = selected[i];
|
||||
if (reward.length > index) {
|
||||
selectedReward.push(reward[index]);
|
||||
if (plans.length > index) {
|
||||
let { contentType, content, count } = plans[index];
|
||||
selectedReward.push({ type: contentType, id: content, count });
|
||||
}
|
||||
}
|
||||
return selectedReward;
|
||||
}
|
||||
|
||||
function randomSelectedData(total: number, count: number) {
|
||||
var selected: number[] = []; //temp存放生成的随机数组
|
||||
var arr = Array.from({ length: total }, (v, k) => k);
|
||||
for (let i = 0; i < count; i++) {
|
||||
var num = Math.floor(Math.random() * arr.length); //生成随机数num
|
||||
selected.push(arr[num]); //获取arr[num]并放入temp
|
||||
arr.splice(num, 1);
|
||||
async function randomSelectedData(pool: DicGiftPackagePlan[], roleId: string, giftPackageId: number, count: number) {
|
||||
let rewards: RewardParam[] = [];
|
||||
let floorPlan = pool.find(cur => cur.floorCount > 0);
|
||||
let dropHistory = floorPlan? await GiftPackageFloorModel.findByPlanId(roleId, giftPackageId, floorPlan?.id): { getNum: 0, allNum: 0, getSum: 0, allSum: 0 };
|
||||
let { getNum = 0, allNum = 0, getSum = 0, allSum = 0 } = dropHistory;
|
||||
|
||||
for(let i = 0; i < count; i++) {
|
||||
let randResult = getRandEelmWithWeight(pool)?.dic;
|
||||
if(!randResult) continue;
|
||||
if(!floorPlan) {
|
||||
rewards.push({ type: randResult.contentType, id: randResult.content, count: randResult.count });
|
||||
continue;
|
||||
}
|
||||
|
||||
let flag = randResult.id == floorPlan.id; // 是否获得
|
||||
if(allNum - getNum >= floorPlan.floorFrequency - floorPlan.floorCount) {
|
||||
flag = true;
|
||||
}
|
||||
if(flag) {
|
||||
getNum ++; getSum++;
|
||||
rewards.push({ type: floorPlan.contentType, id: floorPlan.content, count: floorPlan.count });
|
||||
} else {
|
||||
rewards.push({ type: randResult.contentType, id: randResult.content, count: randResult.count });
|
||||
}
|
||||
allNum ++; allSum ++;
|
||||
if(getNum >= floorPlan.floorCount) {
|
||||
allNum = 0; getNum = 0;
|
||||
}
|
||||
}
|
||||
return selected;
|
||||
if(floorPlan) {
|
||||
await GiftPackageFloorModel.updateByPlanId(roleId, giftPackageId, floorPlan.id, {
|
||||
getNum, allNum, getSum, allSum
|
||||
});
|
||||
}
|
||||
return rewards
|
||||
}
|
||||
|
||||
//数据格式转换'类型&id&数量|类型&id&数量|' ->> Array<RewardParam> 活动奖励
|
||||
|
||||
@@ -514,6 +514,7 @@ export const FILENAME = {
|
||||
DIC_GACHA_PLAN: 'dic_zyz_gachaPlan',
|
||||
DIC_GACHA_FLOOR: 'dic_zyz_gachaFloor',
|
||||
DIC_GIFT_PACKAGE: 'dic_zyz_giftPackage',
|
||||
DIC_GIFT_PACKAGE_PLAN: 'dic_zyz_giftPackagePlan',
|
||||
DIC_RECRUIT: 'dic_zyz_recruit',
|
||||
DIC_RMB: 'dic_zyz_rmb',
|
||||
DIC_ACTIVITY_TYPE: 'dic_zyz_activityType',
|
||||
|
||||
45
shared/db/GiftPackageFloor.ts
Normal file
45
shared/db/GiftPackageFloor.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 战斗记录接口
|
||||
*/
|
||||
@index({ roleId: 1, giftPackageId: 1, floorPlanId: 1 })
|
||||
|
||||
export default class GiftPackageFloor extends BaseModel {
|
||||
@prop({ required: true })
|
||||
roleId: string; // 角色 id
|
||||
@prop({ required: true })
|
||||
giftPackageId: number; // 礼包 id
|
||||
@prop({ required: true })
|
||||
floorPlanId: number; // 物品id
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
getNum: number; // 获取次数,当allNum超过配置次数重置
|
||||
@prop({ required: true, default: 0 })
|
||||
allNum: number; // 全部次数,当超过配置次数重置
|
||||
@prop({ required: true, default: 0 })
|
||||
getSum: number; // 获取道具的全部次数
|
||||
@prop({ required: true, default: 0 })
|
||||
allSum: number; // 全部全部次数,不重置
|
||||
|
||||
|
||||
public static async findByPlanId(roleId: string, giftPackageId: number, floorPlanId: number, lean = true) {
|
||||
const result: GiftPackageFloorType = await GiftPackageFloorModel.findOneAndUpdate({ roleId, giftPackageId, floorPlanId}, {}, {new: true, upsert: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateByPlanId(roleId: string, giftPackageId: number, floorPlanId: number, params: {getNum: number, allNum: number, getSum: number, allSum: number}, lean = true) {
|
||||
const result: GiftPackageFloorType = await GiftPackageFloorModel.findOneAndUpdate({roleId, giftPackageId, floorPlanId}, {$set: params}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async deleteAccount(roleId: string) {
|
||||
let result = await GiftPackageFloorModel.deleteMany({roleId});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GiftPackageFloorModel = getModelForClass(GiftPackageFloor);
|
||||
|
||||
export interface GiftPackageFloorType extends Pick<DocumentType<GiftPackageFloor>, keyof GiftPackageFloor>{}
|
||||
@@ -117,6 +117,7 @@ import { dicArtifactQualityPlan, loadArtifactQualityPlan } from "./dictionary/Di
|
||||
import { dicArtifactSeid, loadArtifactSeid } from "./dictionary/DicArtifactSeid";
|
||||
import { DicArtifact } from "./dictionary/DicArtifact";
|
||||
import { DicArtifactQuality } from "./dictionary/DicArtifactQuality";
|
||||
import { dicGiftPackagePlan, loadGiftPackagePlan } from "./dictionary/DicGiftPackagePlan";
|
||||
|
||||
export const gameData = {
|
||||
daily: dicDaily,
|
||||
@@ -228,6 +229,7 @@ export const gameData = {
|
||||
gachaPickHeroCnt: new Map<number, number>(),
|
||||
heroTransPiece: new Map<number, number>(),
|
||||
giftPackage: dicGiftPackage,
|
||||
giftPackagePlan: dicGiftPackagePlan,
|
||||
comBtlLvRange: new Map<number, {min: number, max: number}>(),
|
||||
recruit: dicRecruit,
|
||||
rmb: dicRMB,
|
||||
@@ -1215,6 +1217,7 @@ function loadDatas() {
|
||||
loadGachaPlan();
|
||||
loadGachaFloor();
|
||||
loadGiftPackage();
|
||||
loadGiftPackagePlan();
|
||||
loadRecruit();
|
||||
loadRMB();
|
||||
loadActivityType();
|
||||
|
||||
57
shared/pubUtils/dictionary/DicGiftPackagePlan.ts
Normal file
57
shared/pubUtils/dictionary/DicGiftPackagePlan.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
// 礼包奖励表
|
||||
import { readFileAndParse } from '../util';
|
||||
import { FILENAME } from '../../consts';
|
||||
const _ = require('lodash');
|
||||
|
||||
export interface DicGiftPackagePlan {
|
||||
// 唯一id
|
||||
readonly id: number;
|
||||
// 礼包类型 dic_zyz_giftPackage的id
|
||||
readonly giftPackageId: number;
|
||||
// addReward中的type
|
||||
readonly contentType: number;
|
||||
// 物品id或武将id
|
||||
readonly content: number;
|
||||
// 数量
|
||||
readonly count: number;
|
||||
// 权重
|
||||
readonly weight: number;
|
||||
// 保底, 每floor必出floorCount个,提前获取到次数就重置
|
||||
readonly floorFrequency: number;
|
||||
// 保底数量
|
||||
readonly floorCount: number;
|
||||
}
|
||||
|
||||
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
||||
const DicGiftPackagePlanKeys: KeysEnum<DicGiftPackagePlan> = {
|
||||
id: true,
|
||||
giftPackageId: true,
|
||||
contentType: true,
|
||||
content: true,
|
||||
count: true,
|
||||
weight: true,
|
||||
floorFrequency: true,
|
||||
floorCount: true
|
||||
}
|
||||
|
||||
export const dicGiftPackagePlan = new Map<number, DicGiftPackagePlan[]>(); // packageId => [plan]
|
||||
export function loadGiftPackagePlan() {
|
||||
dicGiftPackagePlan.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_GIFT_PACKAGE_PLAN);
|
||||
|
||||
arr.forEach(o => {
|
||||
if(o.floor == '&') {
|
||||
o.floorFrequency = 0;
|
||||
o.floorCount = 0;
|
||||
} else {
|
||||
let arr = o.floor.split('&');
|
||||
o.floorFrequency = isNaN(parseInt(arr[0]))? 0: parseInt(arr[0]);
|
||||
o.floorCount = isNaN(parseInt(arr[1]))? 0: parseInt(arr[1]);
|
||||
}
|
||||
if(!dicGiftPackagePlan.has(o.giftPackageId)) {
|
||||
dicGiftPackagePlan.set(o.giftPackageId, []);
|
||||
}
|
||||
dicGiftPackagePlan.get(o.giftPackageId)?.push(_.pick(o, Object.keys(DicGiftPackagePlanKeys)));
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
21452
shared/resource/jsons/dic_zyz_giftPackagePlan.json
Normal file
21452
shared/resource/jsons/dic_zyz_giftPackagePlan.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user