Merge branch 'feature/gacha'
This commit is contained in:
@@ -4,18 +4,15 @@ import { STATUS, GACHA_ID, HERO_QUALITY_TYPE, TASK_TYPE, REFRESH_TIME, TIME_OUTP
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { GachaListReturn, GachaResult, GachaData } from "../../../domain/activityField/gachaField";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getFloorResult, getResultFromContentId, getGachaList, getVisitedHeroList, getAllHeroByQuality } from "../../../services/activity/gachaService";
|
||||
import { refreshGacha, getFloorResult, getGachaList, getVisitedHeroList, getAllHeroByQuality, GachaPull } from "../../../services/activity/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
import { handleCost, createHeroes, addItems } from "../../../services/rewardService";
|
||||
import { getZeroPointD, getTimeFun } from "../../../pubUtils/timeUtil";
|
||||
import { UserGachaRecModel } from "../../../db/UserGachaRec";
|
||||
import { ActivityModel } from "../../../db/Activity";
|
||||
import { checkActivityTask, checkTask } from "../../../services/taskService";
|
||||
import { RECRUIT } from "../../../pubUtils/dicParam";
|
||||
import { transPiece } from "../../../pubUtils/itemUtils";
|
||||
import { CreateHeroParam } from "../../../domain/roleField/hero";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GachaHandler(app);
|
||||
@@ -61,37 +58,16 @@ export class GachaHandler {
|
||||
if (!dicGacha.count.includes(count)) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, gachaId, activityId);
|
||||
let { floor, freeCount, hope, point, pickHero, refFreeTime, count: historyCount } = await refreshGacha(dicGacha, userGacha);
|
||||
userGacha = await refreshGacha(dicGacha, userGacha);
|
||||
let { freeCount, point, pickHero, refFreeTime, count: historyCount } = userGacha;
|
||||
if ((gachaId == GACHA_ID.ASSIGN || gachaId == GACHA_ID.TIMELIMIT) && !pickHero) return resResult(STATUS.GACHA_NOT_ASSIGN);
|
||||
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let items: RewardInter[] = [], heroInfo: CreateHeroParam[] = [], resultList: GachaResult[] = [];
|
||||
|
||||
let activityData = [];//活动需要统计抽中的英雄、碎片品质
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 按照一般概率抽出
|
||||
let { dic: { id: base } } = getRandEelmWithWeight(dicGacha.percent);
|
||||
let contentId = getFloorResult(gachaId, base, floor);
|
||||
if (contentId == false) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let result = getResultFromContentId(contentId, lv, hope);
|
||||
|
||||
if (result.hid > 0) {
|
||||
result.setSetPickHero(pickHero);
|
||||
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(gachaId, lv, userHeroes);
|
||||
gachaPull.setByUserGacha(dicGacha, userGacha);
|
||||
let { items, heroInfo, resultList, activityData } = gachaPull.pull(count);
|
||||
let { hope, floor } = gachaPull.getUserGachaParam(userGacha);
|
||||
|
||||
let costNum = count;
|
||||
if (count == 1 && dicGacha.free.count > 0) { // 单抽的时候免费
|
||||
@@ -110,6 +86,7 @@ export class GachaHandler {
|
||||
if (!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
}
|
||||
// 给东西
|
||||
console.log('****', heroInfo)
|
||||
let { heroes } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items);
|
||||
// 更新数据
|
||||
|
||||
@@ -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';
|
||||
@@ -55,13 +55,8 @@ export class NewHeroGachaHandler {
|
||||
const { activityId, hid } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
await ActivityNewHeroGachaModel.selectedHero(serverId, activityId, roleId, hid);
|
||||
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let { createTime } = await RoleModel.findByRoleId(roleId);
|
||||
let playerData = new NewHeroGachaData(activityData, createTime);
|
||||
for (let pageData of playerData.list) {
|
||||
await ActivityNewHeroGachaModel.selectedHero(serverId, activityId, roleId, pageData.hid, pageData.hid == hid);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -91,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 } });
|
||||
@@ -134,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));
|
||||
if (floorReward) {//抽中保底奖励,重置统计次数
|
||||
await ActivityNewHeroGachaModel.resetCount(serverId, activityId, roleId, hid, 0);
|
||||
}
|
||||
await ActivityNewHeroGachaModel.addRecord(serverId, activityId, roleId, hid, floorCount, JSON.stringify(resultList), hasGetFloor);
|
||||
|
||||
// 给东西
|
||||
let { heroes } = await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfo);
|
||||
|
||||
Reference in New Issue
Block a user