✨ feat(百家争鸣):祈灵 更新至 eb9f941ae

This commit is contained in:
luying
2023-08-25 14:57:06 +08:00
parent f8349849eb
commit e6665208e1
13 changed files with 417 additions and 137 deletions
@@ -0,0 +1,65 @@
import { Application, BackendSession, HandlerService, } from "pinus";
import { getPlayerAuthorGachaDataShow } from "../../../services/activity/authorGachaService";
import { parseGoodStrWithType, resResult } from "../../../pubUtils/util";
import { ITEM_CHANGE_REASON, STATUS } from "../../../consts";
import { AuthorGachaData } from "../../../domain/activityField/authorGachaField";
import { addReward } from "../../../services/activity/giftPackageService";
import { ActivityAuthorGachaRecModel } from "../../../db/AuthorGachaRec";
export default function (app: Application) {
new HandlerService(app, {});
return new AuthorGachaHandler(app);
}
export class AuthorGachaHandler {
constructor(private app: Application) {
}
/**
* 祈灵获取数据
* @param msg
* @param session
* @returns
*/
async getData(msg: { activityId: number }, session: BackendSession) {
const roleId: string = session.get('roleId');
const serverId: number = session.get('serverId');
const { activityId } = msg;
let playerData = await getPlayerAuthorGachaDataShow(activityId, serverId, roleId);
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
return resResult(STATUS.SUCCESS, { ...playerData });
}
/**
* 祈灵获取奖励
* @param msg
* @param session
* @returns
*/
async receiveBox(msg: { activityId: number, count: number }, session: BackendSession) {
const roleId: string = session.get('roleId');
const roleName: string = session.get('roleName');
const serverId: number = session.get('serverId');
const sid: string = session.get('sid');
const { activityId, count } = msg;
let playerData = await getPlayerAuthorGachaDataShow(activityId, serverId, roleId);
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
let box = playerData.box.find(cur => cur.count == count);
if (box == undefined || box.hasReceived) return resResult(STATUS.ACTIVITY_REWARDED);
box.hasReceived = true;
let rewards = parseGoodStrWithType(box.rewards);
let result = await addReward(roleId, roleName, sid, serverId, rewards, ITEM_CHANGE_REASON.AUTHOR_GACHA_REWARD);
await ActivityAuthorGachaRecModel.record(serverId, activityId, playerData.roundIndex, roleId, count);
return resResult(STATUS.SUCCESS, { goods: result.goods, curBox: playerData.box })
}
}
@@ -19,6 +19,8 @@ import { isHeroHidden } from "../../../services/dataService";
import { GachaResultIndb } from "../../../domain/activityField/gachaField";
import { CreateHeroParam } from "../../../domain/roleField/hero";
import { ItemInter, RewardInter } from "../../../pubUtils/interface";
import { getPlayerAuthorGachaData } from "../../../services/activity/authorGachaService";
import { ActivityAuthorGachaRecModel, ActivityAuthorGachaRecModelType } from "../../../db/AuthorGachaRec";
export default function (app: Application) {
new HandlerService(app, {});
@@ -113,6 +115,14 @@ export class GachaHandler {
await UserGachaRecModel.createRec(roleId, gachaId, activityId, count, resultList);
if(dicGacha.isTask) await checkTaskInGacha(serverId, roleId, sid, count, resultHeroes, resultList, false);
//百家争鸣祈灵
let playerData = await getPlayerAuthorGachaData(activityId, serverId, roleId);
let dbAuthorGacha:ActivityAuthorGachaRecModelType;
if (playerData) {
dbAuthorGacha = await ActivityAuthorGachaRecModel.updateGachaCnt(serverId, activityId, playerData.roundIndex, roleId, gachaId, count);
}
return resResult(STATUS.SUCCESS, {
gachaId, activityId,
isFree: freeCount < newDicGacha.free.count, cost: newDicGacha.cost,
@@ -120,7 +130,8 @@ export class GachaHandler {
// heroes: resultHeroes,
addHeros: heroes,
result: resultList,
remainFloor: getGachaRemainFloor(gachaId, floor)
remainFloor: getGachaRemainFloor(gachaId, floor),
authorGachaCnt:dbAuthorGacha?.gachaCnt||0,
});
}