🐞 fix(幸运转盘优化): 修改保底

This commit is contained in:
zhangxk
2023-10-18 21:41:24 +08:00
committed by luying
parent fe55bf8da9
commit 850f6656c7
3 changed files with 99 additions and 75 deletions

View File

@@ -3,7 +3,7 @@ import { ActivityModelType } from '../../db/Activity';
import { RewardInter } from '../../pubUtils/interface';
import { getRandEelmWithWeight, parseGoodStr } from '../../pubUtils/util';
import { ActivityBase } from './activityField';
import { ActivityLuckyModelType, TurntableRecord } from '../../db/ActivityLuckyRec';
import { ActivityLuckyModelType, FloorRecord, TurntableRecord } from '../../db/ActivityLuckyRec';
/************** 在数据库中的格式 ***********/
@@ -17,7 +17,6 @@ interface TurntablePoolInDb {
interface TurntableFloorInDb { // 保底每sum次必出count个头奖头奖权重最低的一项
sum: number;
count: number;
id: number;
}
@@ -81,18 +80,19 @@ export class LuckyData extends ActivityBase {
cost: string; // 抽1次的消耗
freeCount: number; // 免费次数
pool: LuckyPool[] = [];
// greateReward: LuckyPool; // 头奖weight最小的那一个
box: LuckyBox[] = [];
floor: { // 保底
sum: number;
count: number;
id: number;
floorCount?: number;
}[];
todayCount: number = 0; // 今天抽了几次
count: number = 0; // 一共抽了几次
records: TurntableRecord[] = []; // 奖励记录
greatRewardCount: number = 0; // 已抽次数,用于计算保底
floorRecord: FloorRecord[] = []; //
public getCost(count: number) {
if (this.todayCount < this.freeCount) {
@@ -116,16 +116,22 @@ export class LuckyData extends ActivityBase {
let pool: LuckyPool[] = [];
for (let obj of this.pool) {
let { gid, numLimit } = obj;
if (numLimit != -1 || numLimit > (gidMap.get(gid) || 0)) pool.push(obj);
if (numLimit == -1 || numLimit > (gidMap.get(gid) || 0)) pool.push(obj);
}
return pool;
}
// 保底
private getFloor(pool: LuckyPool[]) {
let ret: TurntableFloorInDb = { sum: 0, count: 0, id: 0 };
for (let { sum, count, id } of this.floor) {
if (this.greatRewardCount > (sum - count) && this.greatRewardCount <= sum) {
if ((ret?.sum || 0) < sum) ret = { sum, count, id };
let ret: TurntableFloorInDb = { sum: 0, id: 0 };
for (let { sum, id } of this.floor) {
let floorRecord = this.floorRecord.find(cur => cur.id == id);
let count = 0;
if (floorRecord) count = floorRecord.count + 1;
if ((count == sum || count % sum == 0) && count != 0) {
if (sum > ret.sum) {
ret = { sum, id };
if (floorRecord) floorRecord.count = 0;
}
}
}
@@ -138,6 +144,23 @@ export class LuckyData extends ActivityBase {
return {};
}
//获取保底
public getFloorCount() {
for (let obj of this.floor) {
let { sum, id } = obj;
let pool = this.pool.find(cur => cur.id == id)
if (!pool || pool.numLimit <= pool.getCnt) obj.floorCount = 0;
else {
let count = this.floorRecord.find(cur => cur.id == id)?.count || 0;
if (count % sum == 0) obj.floorCount = sum;
else {
obj.floorCount = sum - (count % sum);
}
}
}
return this.floor;
}
public pull(roleName: string, count: number) {
let records: (string | number)[][] = [];
@@ -147,34 +170,26 @@ export class LuckyData extends ActivityBase {
// 1.次数上限
let pool = this.getPoolByRecordNum();
// 2.保底
this.greatRewardCount++;
let { newPool } = this.getFloor(pool);
let randResult = newPool;
if (newPool) {
let floor = this.floor.find(cur => cur.id == newPool.id)
if (floor && floor.sum == this.greatRewardCount) {
this.greatRewardCount = 0;
}
if (!newPool) {
randResult = getRandEelmWithWeight(pool).dic;
}
if (randResult) {
let tempPool = this.pool.find(cur => cur.id == randResult.id);
if (tempPool) {
tempPool.getCnt = (tempPool.getCnt || 0) + 1;
}
}
else {
randResult = getRandEelmWithWeight(pool).dic;
if (randResult) {
let floor = this.floor.find(cur => cur.id == randResult.id);
let tempPool = this.pool.find(cur => cur.id == randResult.id);
if (tempPool) {
tempPool.getCnt = (tempPool.getCnt || 0) + 1;
for (let obj of this.floor) {
let floorRecord = this.floorRecord.find(cur => cur.id == obj.id);
if (obj.id != randResult.id) {
if (!floorRecord) this.floorRecord.push({ id: obj.id, count: 1 });
else floorRecord.count++;
} else {
if (floorRecord) floorRecord.count = 0;
}
if (floor && floor.count <= tempPool.getCnt) {
this.greatRewardCount = 0;
}
}
}
if (randResult) {
this.count++;
this.todayCount++;
let record = { roleName, gid: randResult.gid, count: randResult.count };
@@ -184,7 +199,7 @@ export class LuckyData extends ActivityBase {
goodResult.push({ id: randResult.gid, count: randResult.count });
}
}
return { result, records, goodResult, pool: this.pool.map(pool => pool.getShowResult()), floorCount: this.greatRewardCount };
return { result, records, goodResult, pool: this.pool.map(pool => pool.getShowResult()), floor: this.getFloorCount() };
}
// 宝箱是否可以领取
@@ -203,19 +218,20 @@ export class LuckyData extends ActivityBase {
public setPlayerRecords(playerData: ActivityLuckyModelType) {
if (!playerData) return null
let { todayCount, count, records, box, greatRewardCount } = playerData;
let { todayCount, count, records, box, floorRecord = [] } = playerData;
this.todayCount = todayCount;
this.count = count;
this.records = records;
for (let boxData of this.box) {
boxData.setReceived(box);
}
this.greatRewardCount = greatRewardCount;
let gidMap = this.getGidMap();
for (let obj of this.pool) {
obj.getCnt = (gidMap.get(obj.gid) || 0);
}
this.floorRecord = floorRecord;
}
public initData(data: string) {
@@ -225,9 +241,6 @@ export class LuckyData extends ActivityBase {
for (let pool of dataObj.pool) {
let poolObj = new LuckyPool(pool);
this.pool.push(poolObj);
// if (!this.greateReward || this.greateReward.weight > poolObj.weight) {
// this.greateReward = poolObj;
// }
}
for (let box of dataObj.box) {
this.box.push(new LuckyBox(box));
@@ -245,7 +258,7 @@ export class LuckyData extends ActivityBase {
box: this.box,
pool: this.pool.map(pool => pool.getShowResult()),
records: this.records.map(record => [record.roleName, record.gid, record.count]),
floorCount: this.greatRewardCount,
floor: this.getFloorCount(),
}
}