招募:引导特殊招募功能
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':
|
||||
|
||||
@@ -359,6 +359,9 @@ export const STATUS = {
|
||||
GACHA_HAS_VISITED: { code: 31106, simStr: '该武将已拜访过' },
|
||||
GACHA_VISITED_COUNT_OVER: { code: 31107, simStr: '今天武将拜访已超过次数' },
|
||||
GACHA_HOPE_HAS_GET: { code: 31108, simStr: '该心愿已实现' },
|
||||
GACHA_GUIDE_PULL_CNT_LACK: { code: 31109, simStr: '预抽卡次数不足' },
|
||||
GACHA_GUIDE_NOT_DO: { code: 31110, simStr: '没有预抽卡过' },
|
||||
GACHA_GUIDE_HAS_DONE: { code: 31111, simStr: '不可多次预抽卡' },
|
||||
// 礼包码 31201-31300
|
||||
GIFT_CODE_USED_NUM_MAX: { code: 31201, simStr: '礼包码使用次数超过' },
|
||||
YOU_HAVE_USED_THIS_CODE: { code: 31202, simStr: '您已使用过该码' },
|
||||
|
||||
@@ -320,8 +320,10 @@ export default class Role extends BaseModel {
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
rankReceived: number[]; // 已领取奖励
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
guide: number[]; // 已领取奖励
|
||||
guide: number[]; // 引导
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
gachaHasGuide: boolean; // 是否进行过引导特殊招募
|
||||
|
||||
@prop({ required: true })
|
||||
renameCnt: number; // 改名次数
|
||||
|
||||
@@ -36,6 +36,24 @@ class Turntable {
|
||||
hasGet: boolean; // 是否得到
|
||||
}
|
||||
|
||||
class SimpleResult {
|
||||
@prop({ required: true })
|
||||
contentId: number;
|
||||
@prop({ required: true })
|
||||
hid: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 特殊引导候选列表
|
||||
* @memberof UserGacha
|
||||
*/
|
||||
class Candidate {
|
||||
@prop({ required: true })
|
||||
id: number; // 列表id
|
||||
@prop({ required: true, type: SimpleResult, _id: false })
|
||||
list: SimpleResult[]; // 是否得到
|
||||
}
|
||||
|
||||
/**
|
||||
* 玩家抽卡表
|
||||
**/
|
||||
@@ -73,7 +91,7 @@ export default class UserGacha extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
costPoint: number; // 消耗的积分
|
||||
|
||||
|
||||
// 积分
|
||||
public get point() {
|
||||
return Math.floor(this.count/RECRUIT.RECRUIT_BONUS) - (this.costPoint||0);
|
||||
@@ -91,6 +109,16 @@ export default class UserGacha extends BaseModel {
|
||||
@prop({ required: true, default: getZeroPointD })
|
||||
refVisitedTime: Date; // 玩家指定武将
|
||||
|
||||
// 初始特殊引导
|
||||
@prop({ required: true, default: 0 })
|
||||
guideCount: number; // 预抽卡次数
|
||||
|
||||
@prop({ required: true, type: SimpleResult, default: [], _id: false })
|
||||
guideResultList: SimpleResult[]; // 预抽卡结果
|
||||
|
||||
@prop({ required: true, type: Candidate, default: [], _id: false })
|
||||
candidates: Candidate[]; // 预抽卡候选
|
||||
|
||||
public static async findAllByRole(roleId: string) {
|
||||
let rec: UserGachaType[] = await UserGachaModel.find({ roleId }).lean({ virtuals: true });
|
||||
return rec;
|
||||
|
||||
Reference in New Issue
Block a user