活动:成长活动统计任务,领取奖励接口
This commit is contained in:
@@ -13,7 +13,7 @@ import { RoleModel, RoleType } from '../db/Role';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { getBeforeDaySeconds, nowSeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip } from './taskUtil';
|
||||
import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
|
||||
export async function addSkins(roleId: string, id: number) {
|
||||
let skinInfo = gameData.fashion.get(id);
|
||||
@@ -37,7 +37,7 @@ export async function addBags(roleId: string, roleName: string, data: BagInter)
|
||||
|
||||
export async function addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
||||
let { id, name, quality, suitId, hole, randomEffect, itid, hid } = weapon;
|
||||
let {type} = ITID.get(itid);
|
||||
let { type } = ITID.get(itid);
|
||||
|
||||
let randomNum = RANDOM_SE_COUNT.get(quality);
|
||||
let randomResult: number[] = getRandEelm(randomEffect, randomNum);
|
||||
@@ -45,7 +45,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
let randSe: Array<RandSe> = randomResult.map((id: number, i: number) => {
|
||||
let random = gameData.randomEffectPool.get(id)
|
||||
let rand = 0;
|
||||
if(random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
if (random.id > 0) rand = getRandValueByMinMax(random.Min, random.Max, 0);
|
||||
return {
|
||||
id: i + 1,
|
||||
seid: random.id,
|
||||
@@ -53,16 +53,16 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
locked: false
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
let randRange = getRandValueByMinMax(0 - FIX_ATTRIBUTES_RAN, FIX_ATTRIBUTES_RAN, 0);
|
||||
|
||||
|
||||
let holes = new Array<Holes>();
|
||||
for(let i = 0; i < hole; i++) {
|
||||
holes.push({id: i+1, isOpen: false, jewel: 0})
|
||||
for (let i = 0; i < hole; i++) {
|
||||
holes.push({ id: i + 1, isOpen: false, jewel: 0 })
|
||||
}
|
||||
|
||||
const equip = await EquipModel.createEquip({roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid});
|
||||
|
||||
const equip = await EquipModel.createEquip({ roleId, roleName, id, name, quality, suitId, randRange, ePlaceId: type, randSe, holes, hid });
|
||||
|
||||
// 任务
|
||||
let pushMessage = await checkTaskWithEquip(roleId, TASK_TYPE.EQUIP_SUIT, equip);
|
||||
|
||||
@@ -74,7 +74,7 @@ export async function addEquips(roleId: string, roleName: string, weapon: EquipI
|
||||
* @param count 元宝数量
|
||||
*/
|
||||
export function getGoldObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count};
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ export function getGoldObject(count: number) {
|
||||
* @param count 友情点数量
|
||||
*/
|
||||
export function getFriendPointObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count};
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.FRIEND_POINT), count };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ export function getFriendPointObject(count: number) {
|
||||
* @param count 功勋数量
|
||||
*/
|
||||
export function getHonourObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count};
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count };
|
||||
}
|
||||
/**
|
||||
* 解锁头像/相框
|
||||
@@ -99,47 +99,47 @@ export function getHonourObject(count: number) {
|
||||
* @param role 如果已查询过role表就直接可以使用
|
||||
*/
|
||||
export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) {
|
||||
if(!role || !role.heads || !role.frames) {
|
||||
if (!role || !role.heads || !role.frames) {
|
||||
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
}
|
||||
let { heads, frames, spines } = role;
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for(let {type, paramHid, paramFavourLv, paramSkinId } of conditions) {
|
||||
for (let { type, paramHid, paramFavourLv, paramSkinId } of conditions) {
|
||||
let canUnLockList = gameData.figureCondition.get(type);
|
||||
if(canUnLockList) {
|
||||
for(let {id, params, gid} of canUnLockList) {
|
||||
if (canUnLockList) {
|
||||
for (let { id, params, gid } of canUnLockList) {
|
||||
let flag = false; // 是否达成条件
|
||||
if(type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
|
||||
let [ hid ] = params;
|
||||
if(paramHid == hid) flag = true;
|
||||
if (type == FIGURE_UNLOCK_CONDITION.GET_HERO) {
|
||||
let [hid] = params;
|
||||
if (paramHid == hid) flag = true;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.HERO_FAVOR) {
|
||||
let [ hid, favourLv ] = params;
|
||||
if(paramHid == hid && paramFavourLv >= favourLv) flag = true;
|
||||
} else if ( type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
|
||||
let [ id ] = params;
|
||||
if(paramSkinId == id) flag = true;
|
||||
let [hid, favourLv] = params;
|
||||
if (paramHid == hid && paramFavourLv >= favourLv) flag = true;
|
||||
} else if (type == FIGURE_UNLOCK_CONDITION.GET_SKIN) {
|
||||
let [id] = params;
|
||||
if (paramSkinId == id) flag = true;
|
||||
}
|
||||
if(!flag) continue;
|
||||
if (!flag) continue;
|
||||
let dicGood = gameData.goods.get(gid);
|
||||
if(!dicGood) continue;
|
||||
if (!dicGood) continue;
|
||||
let dicItid = ITID.get(dicGood.itid);
|
||||
if(!dicItid) continue;
|
||||
|
||||
if(dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, false, id);
|
||||
if(figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, false, id);
|
||||
if(figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, false, id);
|
||||
if(figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
@@ -151,30 +151,30 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p
|
||||
export async function addFigure(roleId: string, ids: number[]) {
|
||||
let role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
|
||||
if(!role) return false;
|
||||
if (!role) return false;
|
||||
let { heads, frames, spines } = role;
|
||||
|
||||
let figureInfo = { heads: [], frames: [], spines: [] };
|
||||
for(let gid of ids) {
|
||||
for (let gid of ids) {
|
||||
let dicGoods = gameData.goods.get(gid);
|
||||
if(!dicGoods) continue;
|
||||
if (!dicGoods) continue;
|
||||
let dicItid = ITID.get(dicGoods.itid);
|
||||
if(!dicItid) continue;
|
||||
|
||||
if(dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
if (!dicItid) continue;
|
||||
|
||||
if (dicItid.type == CONSUME_TYPE.HEAD) {
|
||||
let figure = unlockSingleFigure(heads, gid, true);
|
||||
if(figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.heads.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.FRAME) {
|
||||
let figure = unlockSingleFigure(frames, gid, true);
|
||||
if(figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.frames.push(figure);
|
||||
} else if (dicItid.type == CONSUME_TYPE.SPINE) {
|
||||
let figure = unlockSingleFigure(spines, gid, true);
|
||||
if(figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
if (figure && figure.unlocked) figureInfo.spines.push(figure);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
return figureInfo;
|
||||
}
|
||||
@@ -188,32 +188,32 @@ export async function addFigure(roleId: string, ids: number[]) {
|
||||
*/
|
||||
function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = false, conditionId?: number) {
|
||||
let figure = dbFigures.find(cur => cur.id == id);
|
||||
if(!figure) {
|
||||
if (!figure) {
|
||||
figure = new Figure(id, false);
|
||||
dbFigures.push(figure);
|
||||
}
|
||||
if(figure.unlocked) return; // 已解锁过
|
||||
if(!figure.unlockedId) figure.unlockedId = new Array<number>();
|
||||
if (figure.unlocked) return; // 已解锁过
|
||||
if (!figure.unlockedId) figure.unlockedId = new Array<number>();
|
||||
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
|
||||
let hasUnlockedAll = true;
|
||||
if(!unlockDirect) { // 不能直接获得,需要通过type解锁
|
||||
if(figure.unlockedId.includes(conditionId)) return;
|
||||
if (!unlockDirect) { // 不能直接获得,需要通过type解锁
|
||||
if (figure.unlockedId.includes(conditionId)) return;
|
||||
|
||||
figure.unlockedId.push(conditionId);
|
||||
|
||||
for(let { id: cid } of dicGoods.condition) {
|
||||
if(!figure.unlockedId.includes(cid)) {
|
||||
|
||||
for (let { id: cid } of dicGoods.condition) {
|
||||
if (!figure.unlockedId.includes(cid)) {
|
||||
hasUnlockedAll = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasUnlockedAll) {
|
||||
if (hasUnlockedAll) {
|
||||
figure.unlocked = true;
|
||||
delete figure.unlockedId;
|
||||
|
||||
if(dicGoods.timeLimit) {
|
||||
if (dicGoods.timeLimit) {
|
||||
figure.time = getBeforeDaySeconds(-1 * dicGoods.timeLimit); // timeLimit天以后
|
||||
}
|
||||
}
|
||||
@@ -227,13 +227,13 @@ export async function createHero(roleId: string, heroInfo: HeroUpdate) {
|
||||
}
|
||||
|
||||
export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
|
||||
|
||||
let heroNum = 0;
|
||||
let skinIds = new Array<number>();
|
||||
let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResults = [];
|
||||
|
||||
for(let heroInfo of heroInfos) {
|
||||
for (let heroInfo of heroInfos) {
|
||||
let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero);
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {}); calHeroResults.push(calHeroResult);
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds); calAllHeroResults.push(calAllHeroResult);
|
||||
@@ -241,9 +241,9 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroInfo.skins.forEach(cur => {
|
||||
skinIds.push(cur.id);
|
||||
conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id});
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id });
|
||||
});
|
||||
heroNum ++;
|
||||
heroNum++;
|
||||
}
|
||||
let figureInfo = await unlockFigure(roleId, conditions); // 解锁头像
|
||||
|
||||
@@ -254,5 +254,7 @@ export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
let m3 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, heroes);
|
||||
let m4 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_LV, heroes);
|
||||
let taskPushMessage = m1.concat(m2, m3, m4);
|
||||
//成长任务
|
||||
await accomplishTask(roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults, taskPushMessage }
|
||||
}
|
||||
Reference in New Issue
Block a user