招募:引导特殊招募功能
This commit is contained in:
@@ -334,4 +334,157 @@ export class GachaHandler {
|
||||
goods
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取特殊抽卡数据
|
||||
* @param {{}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async getGuideGachaData(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let { guideCount = 0, guideResultList = [], candidates = [] } = userGacha;
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
guideCount,
|
||||
latest: guideResultList,
|
||||
candidates
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 预抽卡
|
||||
* @param {{}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async guidePull(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
const count = 10;
|
||||
const dicGacha = gameData.gacha.get(gachaId);
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let { guideCount = 0 } = userGacha;
|
||||
if(guideCount >= 50) return resResult(STATUS.GACHA_GUIDE_PULL_CNT_LACK);
|
||||
|
||||
if(guideCount == 0) {
|
||||
// 消耗东西
|
||||
let cost = dicGacha.cost.map(cur => { return { id: cur.id, count: cur.count * count } });
|
||||
let costResult = await handleCost(roleId, sid, cost);
|
||||
if (!costResult) return resResult(STATUS.GACHA_COST_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
let gachaPull = new GachaPull(gachaId, 0, []);
|
||||
gachaPull.setByUserGacha(dicGacha, userGacha);
|
||||
let { resultList } = gachaPull.pull(count);
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { guideResultList: resultList, guideCount: guideCount + 1 })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
guideCount: userGacha.guideCount,
|
||||
latest: userGacha.guideResultList
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 将结果保存到候选列表
|
||||
* @param {{ id: number }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async saveToCandidates(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const gachaId = GACHA_ID.NORMAL;
|
||||
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let { guideResultList, candidates = [] } = userGacha;
|
||||
|
||||
let index = candidates.findIndex(cur => cur.id == id);
|
||||
if(index == -1) {
|
||||
candidates.push({
|
||||
id, list: guideResultList
|
||||
});
|
||||
} else {
|
||||
candidates[index].list = guideResultList;
|
||||
}
|
||||
|
||||
userGacha = await UserGachaModel.updateInfo(roleId, gachaId, 0, { candidates })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
candidates: userGacha.candidates
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 确定使用某个结果
|
||||
* @param {{ id: number }} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof GachaHandler
|
||||
*/
|
||||
async decide(msg: { id: number }, session: BackendSession) {
|
||||
const { id } = msg;
|
||||
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 gachaId = GACHA_ID.NORMAL;
|
||||
const count = 10;
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(role.gachaHasGuide) {
|
||||
return resResult(STATUS.GACHA_GUIDE_HAS_DONE);
|
||||
}
|
||||
let userGacha = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL);
|
||||
let { guideResultList = [], candidates = [] } = userGacha;
|
||||
|
||||
let simpleResult: { contentId: number, hid: number }[] = []
|
||||
if(id == 0) {
|
||||
if(guideResultList.length <= 0) {
|
||||
return resResult(STATUS.GACHA_GUIDE_NOT_DO);
|
||||
}
|
||||
simpleResult = guideResultList;
|
||||
} else {
|
||||
let candidate = candidates.find(cur => cur.id == id);
|
||||
if(!candidate) return resResult(STATUS.WRONG_PARMS);
|
||||
simpleResult = candidate.list;
|
||||
}
|
||||
|
||||
let { lv } = await RoleModel.findByRoleId(roleId);
|
||||
let userHeroes = await HeroModel.findByRole(roleId);
|
||||
|
||||
let gachaPull = new GachaPull(gachaId, lv, userHeroes);
|
||||
let { items, heroInfo, resultList, activityData } = gachaPull.pullBySimpleResult(simpleResult);
|
||||
|
||||
|
||||
|
||||
// 给东西
|
||||
// console.log('****', heroInfo)
|
||||
let { heroes, resultHeroes } = await createHeroes(roleId, roleName, sid, serverId, heroInfo);
|
||||
await addItems(roleId, roleName, sid, items);
|
||||
// 更新数据
|
||||
await RoleModel.updateRoleInfo(roleId, { gachaHasGuide: true });
|
||||
await UserGachaRecModel.createRec(roleId, gachaId, 0, count, resultList);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, TASK_TYPE.GASHA, count, true, {});
|
||||
//活动统计
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.GASHA, count)
|
||||
for (let hero of resultHeroes) {
|
||||
activityData.push({ hid: hero.hid, quality: hero.quality });
|
||||
}
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.GACHA_QUALITY_COUNT, count, { heroes: activityData })
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
gachaId,
|
||||
heroes: resultHeroes,
|
||||
addHeros: heroes,
|
||||
result: resultList
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -309,6 +309,29 @@ export class GachaPull {
|
||||
return { items, heroInfo, resultList, activityData }
|
||||
}
|
||||
|
||||
public pullBySimpleResult(simpleResult: {contentId: number, hid: number}[]) {
|
||||
let items: RewardInter[] = [], heroInfo: CreateHeroParam[] = [], resultList: GachaResult[] = [];
|
||||
let activityData = [];//活动需要统计抽中的英雄、碎片品质
|
||||
|
||||
for (let { contentId, hid } of simpleResult) {
|
||||
let result = new GachaResult(contentId);
|
||||
result.setHero(hid);
|
||||
|
||||
let hasHero = this.userHeroes.find(cur => cur.hid == hid);
|
||||
if (hasHero) { // 已有转换为碎片
|
||||
activityData.push({ hid, quality: hasHero.quality });
|
||||
let { pieceId, count } = transPiece(hid);
|
||||
result.transferToPiece(pieceId, count);
|
||||
items.push({ id: pieceId, count });
|
||||
} else {
|
||||
heroInfo.push({ hid, count: 1 })//默认1个英雄
|
||||
}
|
||||
resultList.push(result);
|
||||
}
|
||||
|
||||
return { items, heroInfo, resultList, activityData }
|
||||
}
|
||||
|
||||
private getPurpleFloor(count: number, index: number, contentId: number, resultList: GachaResult[]) {
|
||||
if (this.gachaType == GACHA_ID.NORMAL && count == 10 && index == count - 1) { // 10连到最后一抽
|
||||
let { type, param } = gameData.gachaContent.get(contentId);
|
||||
|
||||
@@ -100,9 +100,10 @@ async function getModuleData(type: string, data: { role: RoleType, session: Fron
|
||||
case 'pvp': // pvp
|
||||
return await getPvpEntryData(roleId);
|
||||
case 'gacha':
|
||||
const { gachaHasGuide } = role;
|
||||
const gachalist = await getGachaList(roleId);
|
||||
const visitList = await getVisitedHeroList(roleId);
|
||||
return { gachalist, visitList }
|
||||
return { hasInit: !!gachaHasGuide, gachalist, visitList }
|
||||
case 'school':
|
||||
return await getSchoolList(roleId);
|
||||
case 'guild':
|
||||
|
||||
Reference in New Issue
Block a user