抽卡:新武将抽卡接入

This commit is contained in:
luying
2021-07-02 11:05:52 +08:00
parent 1e09f6bc43
commit fc97dc3040
4 changed files with 22 additions and 51 deletions

View File

@@ -1,13 +1,13 @@
import { Application, BackendSession } from 'pinus';
import { getRandEelmWithWeight, resResult } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
import { STATUS, GACHA_ID } from '../../../consts';
import { getPlayerNewHeroGachaData } from '../../../services/activity/newHeroGachaService';
import { RoleModel } from '../../../db/Role';
import { HeroModel } from '../../../db/Hero';
import { RewardInter } from '../../../pubUtils/interface';
import { CreateHeroParam } from '../../../domain/roleField/hero';
import { GachaResult } from '../../../domain/activityField/gachaField';
import { getResultFromContentIdNewHeroActivity } from '../../../services/activity/gachaService';
import { getResultFromContentIdNewHeroActivity, GachaPull } from '../../../services/activity/gachaService';
import { transPiece } from '../../../pubUtils/itemUtils';
import { addItems, createHeroes, handleCost } from '../../../services/rewardService';
import { ActivityNewHeroGachaModel } from '../../../db/ActivityNewHeroGacha';
@@ -86,42 +86,10 @@ export class NewHeroGachaHandler {
let userHeroes = await HeroModel.findByRole(roleId);
let items: RewardInter[] = [], heroInfo: CreateHeroParam[] = [], resultList: GachaResult[] = [];
let floorReward = false;//是否中保底奖励
let activityData = [];//活动需要统计抽中的英雄、碎片品质
for (let i = 0; i < count; i++) {
let base = 0;
let goodId = 0;
if (floorReward! && (item.count + i >= item.floorCount)) {//保底奖励
let reward = item.percent[item.floorReward];//{"id":1,"weight":59,"goodId":1}
base = reward.id;
goodId = reward.goodId;
} else {//按照一般概率抽出
let randomObj = getRandEelmWithWeight(item.percent);//{"dic":{"id":1,"weight":59,"goodId":1},"index":0}
base = randomObj.dic.id;
goodId = randomObj.dic.goodId;
}
if (base == item.floorReward) {//中了保底
floorReward = true;
}
let result = getResultFromContentIdNewHeroActivity(base, goodId, lv);
if (result.hid > 0) {
let hasHero = userHeroes.find(cur => cur.hid == result.hid);
if (hasHero) { // 已有转换为碎片
activityData.push({ hid: hasHero.hid, quality: hasHero.quality });
let { pieceId, count } = transPiece(result.hid);
result.transferToPiece(pieceId, count);
items.push({ id: pieceId, count });
} else {
heroInfo.push({ hid: result.hid, count: 1 })//默认1个英雄
}
} else {
items.push({ id: result.id, count: result.count });
}
resultList.push(result);
}
let gachaPull = new GachaPull(GACHA_ID.TIMELIMIT, lv, userHeroes);
gachaPull.setByActivity(item);
let { items, heroInfo, resultList, activityData } = gachaPull.pull(count);
let { hasGetFloor, floorCount } = gachaPull.getActivityParam();
// 消耗东西
let cost = item.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
@@ -129,10 +97,7 @@ export class NewHeroGachaHandler {
if (!costResult) return resResult(STATUS.ACTIVITY_RES_NOT_ENOUGH);
//记录数据
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, count, JSON.stringify(resultList), floorReward);
if (floorReward) {//抽中保底奖励,重置统计次数
await ActivityNewHeroGachaModel.resetCount(serverId, activityId, roleId, 0);
}
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
// 给东西
let { heroes } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);