任务:按条件开启任务

This commit is contained in:
luying
2021-04-19 13:17:18 +08:00
parent 260744e7d2
commit dd6c3355c3
32 changed files with 296 additions and 195 deletions
@@ -30,7 +30,7 @@ export async function getAp(now: number, roleId: string) {
}
}
export async function setAp(now: number, roleId: string, sid: string, changeAp: number) {
export async function setAp(now: number, roleId: string, sid: string, funcs: number[], changeAp: number) {
let ApResult = await getAp(now, roleId);
let { ap, maxAp, refTime, apRemainTime, isOver } = ApResult; // 更新ap
ap += changeAp;
@@ -44,7 +44,7 @@ export async function setAp(now: number, roleId: string, sid: string, changeAp:
if(isOver && ap < maxAp) apRemainTime = Math.floor(ACTION_POIN.PER / 1000); // 特殊处理
if(changeAp < 0) {
await checkTask(roleId, sid, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp, true, {});
await checkTask(roleId, sid, funcs, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp, true, {});
}
return {ap, maxAp, refTime, apRemainTime}
}
+2 -2
View File
@@ -48,7 +48,7 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
}};
}
export async function towerBattleEnd(sid: string, roleId: string, serverId: number, battleCode: string, battleId: number, succeed: boolean, heroes: Array<number>) {
export async function towerBattleEnd(sid: string, funcs: number[], roleId: string, serverId: number, battleCode: string, battleId: number, succeed: boolean, heroes: Array<number>) {
if (succeed) {
let battleRec = await BattleRecordModel.getBattleRecordByCode(battleCode);
if (battleRec.battleId != battleId) {
@@ -93,7 +93,7 @@ export async function towerBattleEnd(sid: string, roleId: string, serverId: numb
pinus.app.get('channelService').pushMessageByUids('hangUpEnable', resResult(STATUS.SUCCESS, {enable: true}), [{uid: roleId, sid}]);
}
// 任务
await checkTask(roleId, sid, TASK_TYPE.BATTLE_TOWER_LV, role.towerLv, false, {});
await checkTask(roleId, sid, funcs, TASK_TYPE.BATTLE_TOWER_LV, role.towerLv, false, {});
}
return {
status: 0,
+14 -14
View File
@@ -54,7 +54,7 @@ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>,
* @param id 装备类型
* @param seqId 要装上的装备的唯一id 装备B
*/
export async function changeEquip(roleId: string, sid: string, equipA: EquipType, hid: number, id: number, equipB: EquipType) {
export async function changeEquip(roleId: string, sid: string, equipA: EquipType, hid: number, id: number, equipB: EquipType, funcs: number[]) {
let heroB: HeroType;
if (!!hid) //需要卸下或者替换的武将
heroB = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);//需要替换的武将
@@ -63,24 +63,24 @@ export async function changeEquip(roleId: string, sid: string, equipA: EquipType
if (!!heroB) {
let goodInfo = getGoodById(equipA.id);
if (goodInfo.lvLimited > heroB.lv) {
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力
return res;
}
let { jobid } = gameData.hero.get(hid);
let { job_class } = getHeroJob(jobid);
let { classId } = getHeroEquipByClassId(goodInfo.itid);
if (indexOf(classId, job_class) < 0) {
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力
return res;
}
let res = await dressEquip(roleId, sid, heroB, equipA);//替换给武将,并计算战力
let res = await dressEquip(roleId, sid, heroB, equipA, funcs);//替换给武将,并计算战力
return res;
} else {
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力
return res;
}
} else if (!!heroB) {//从穿戴装备的武将上卸下装备
await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id, funcs);//卸下装备并重算战力
}
}
/**
@@ -91,16 +91,16 @@ export async function changeEquip(roleId: string, sid: string, equipA: EquipType
* @param hero
* @param id
*/
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero:HeroType, equip: EquipType, id: number ) {
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero:HeroType, equip: EquipType, id: number, funcs: number[] ) {
let args = calEquipSeids(hero);
hero = await HeroModel.removeEquip(roleId, hero.hid, id, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
// 任务
await checkTask(roleId, sid, TASK_TYPE.EQUIP_SUM, 1, true, {});
await checkTaskWithHero(roleId, sid, TASK_TYPE.EQUIP_BY_HERO, hero, [1]);
await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_QUALITY, equip, [1]);
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_SUM, 1, true, {});
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_BY_HERO, hero, [1]);
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equip, [1]);
return { seqId: equip.seqId, hid: 0};
}
@@ -111,16 +111,16 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, he
* @param hero
* @param equip
*/
export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType) {
export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType, funcs: number[]) {
let args = calEquipSeids(hero);
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
// 任务
await checkTask(roleId, sid, TASK_TYPE.EQUIP_SUM, -1, true, {});
await checkTaskWithHero(roleId, sid, TASK_TYPE.EQUIP_BY_HERO, hero, [-1]);
await checkTaskWithEquip(roleId, sid, TASK_TYPE.EQUIP_QUALITY, equip, [-1]);
await checkTask(roleId, sid, funcs, TASK_TYPE.EQUIP_SUM, -1, true, {});
await checkTaskWithHero(roleId, sid, funcs, TASK_TYPE.EQUIP_BY_HERO, hero, [-1]);
await checkTaskWithEquip(roleId, sid, funcs, TASK_TYPE.EQUIP_QUALITY, equip, [-1]);
return { seqId: equip.seqId, hid: hero.hid };
}
+1 -1
View File
@@ -279,7 +279,7 @@ export async function settleGuildWeekly() {
});
await sendMail(MAIL_TYPE.GUILD_ACTIVE_REWARD, roleId, '系统', [], reward);
// 任务
await checkTask(roleId, null, TASK_TYPE.GUILD_JOB, 1, false, { job });
await checkTask(roleId, null, null, TASK_TYPE.GUILD_JOB, 1, false, { job });
}
await GuildModel.updateInfo(code, { activeWeekly: 0 }, {});
@@ -32,7 +32,7 @@ export async function roleLevelup(roleId: string, kingExp: number, session: Back
await r.setRankWithRoleInfo(roleId, newLv, Date.now(), role);
// 任务
await checkTask(roleId, session.get('sid'), TASK_TYPE.ROLE_LV, newLv, false, {});
await checkTask(roleId, session.get('sid'), session.get('funcs'), TASK_TYPE.ROLE_LV, newLv, false, {});
}
let actordata = [];
for(let i = lv; i <= newLv; i++) {
+4 -3
View File
@@ -281,8 +281,8 @@ export async function clearChannelServers() {
* @param userCode user表唯一字符串标识
* @param sid connector服的那个sid
*/
export async function roleLogin(roleId: string, userCode: string, sid: string, pkgName: string) {
let param = { userCode, sid, pkgName };
export async function roleLogin(roleId: string, userCode: string, sid: string, pkgName: string, funcs: number[]) {
let param = { userCode, sid, pkgName, funcs };
return await redisClient().hsetAsync(REDIS_KEY.ONLINE_USERS, roleId, JSON.stringify(param));
}
@@ -318,7 +318,8 @@ export async function getRoleOnlineInfo(roleId: string) {
isOnline: true,
userCode: result.userCode,
sid: result.sid,
pkgName: result.pkgName
pkgName: result.pkgName,
funcs: result.funcs
}
} catch(e) {
return { isOnline: false }
+3 -3
View File
@@ -126,14 +126,14 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
if (!!equipInfos.length)
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, {equipInfos}), uids);
pushTaskUpdate(roleId, sid, taskPushMessage);
pushTaskUpdate(roleId, sid, null, taskPushMessage);
//货币推送
if (!!Object.keys(currencysMap).length) {
let role = await RoleModel.findByRoleId(roleId);
for (let key in currencysMap) {
if (key == 'ap') {
let {ap} = await setAp(Date.now(), roleId, sid, currencysMap[key]);
let {ap} = await setAp(Date.now(), roleId, sid, null, currencysMap[key]);
currencysMap.ap = ap;
} else {
currencysMap[key] += role[key];
@@ -315,7 +315,7 @@ export async function createHero(roleId: string, sid: string, serverId: number,
hero = await pushCalPlayerCe(roleId, sid, calHeroResult);
await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
pushTaskUpdate(roleId, sid, taskPushMessage);
pushTaskUpdate(roleId, sid, null, taskPushMessage);
return hero;
}
+49 -42
View File
@@ -8,47 +8,54 @@ import { HeroType } from '../db/Hero';
import { EquipType } from '../db/Equip';
import { getRoleOnlineInfo } from './redisService';
import { HeroScores } from '../db/PvpHistoryOpp';
import { ItemInter } from '../pubUtils/interface';
export async function checkTaskWithRoles(roleId: string, sid: string, taskType: number, roles: RoleType[]) {
export async function checkTaskWithRoles(roleId: string, sid: string, funcs: number[], taskType: number, roles: RoleType[]) {
for(let role of roles) {
await checkTaskWithRole(role.roleId, role.roleId == roleId? sid: null, taskType, role);
await checkTaskWithRole(role.roleId, role.roleId == roleId? sid: null, role.roleId == roleId? funcs: null, taskType, role);
}
}
export async function checkTaskWithRole(roleId: string, sid: string, taskType: number, role: RoleType) {
let pushMessage = await taskUtil.checkTaskWithRole(roleId, taskType, role);
pushTaskUpdate(roleId, sid, pushMessage);
export async function checkTaskWithRole(roleId: string, sid: string, funcs: number[], taskType: number, role: RoleType) {
let pushMessage = await taskUtil.checkTaskWithRole(roleId, taskType, role, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function checkTaskWithHero(roleId: string, sid: string, taskType: number, hero: HeroType, args?: number[]) {
let pushMessage = await taskUtil.checkTaskWithHero(roleId, taskType, hero, args);
pushTaskUpdate(roleId, sid, pushMessage);
export async function checkTaskWithHero(roleId: string, sid: string, funcs: number[], taskType: number, hero: HeroType, args?: number[]) {
let pushMessage = await taskUtil.checkTaskWithHero(roleId, taskType, hero, args, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function checkTaskWithEquip(roleId: string, sid: string, taskType: number, equip: EquipType, args?: number[]) {
let pushMessage = await taskUtil.checkTaskWithEquip(roleId, taskType, equip, args);
pushTaskUpdate(roleId, sid, pushMessage);
export async function checkTaskWithEquip(roleId: string, sid: string, funcs: number[], taskType: number, equip: EquipType, args?: number[]) {
let pushMessage = await taskUtil.checkTaskWithEquip(roleId, taskType, equip, args, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function checkTaskWithArgs(roleId: string, sid: string, taskType: number, args: number[]) {
let pushMessage = await taskUtil.checkTaskWithArgs(roleId, taskType, args);
pushTaskUpdate(roleId, sid, pushMessage);
export async function checkTaskWithArgs(roleId: string, sid: string, funcs: number[], taskType: number, args: number[]) {
let pushMessage = await taskUtil.checkTaskWithArgs(roleId, taskType, args, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function checkTaskWithWar(roleId: string, sid: string, taskType: number, warId: number, heroes: number[], count: number, star: number) {
let pushMessage = await taskUtil.checkTaskWithWar(roleId, taskType, warId, heroes, count, star);
pushTaskUpdate(roleId, sid, pushMessage);
export async function checkTaskWithWar(roleId: string, sid: string, funcs: number[], taskType: number, warId: number, heroes: number[], count: number, star: number) {
let pushMessage = await taskUtil.checkTaskWithWar(roleId, taskType, warId, heroes, count, star, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function checkTask(roleId: string, sid: string, taskType: number, count: number, isInc: boolean, param: TaskParam) {
let pushMessage = await taskUtil.checkTask(roleId, taskType, count, isInc, param);
pushTaskUpdate(roleId, sid, pushMessage);
export async function checkTaskWithGoods(roleId: string, sid: string, funcs: number[], taskType: number, goods: ItemInter[]) {
let pushMessage = await taskUtil.checkTaskWithGoods(roleId, taskType, goods, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function pushTaskUpdate(roleId: string, sid: string, pushMessage: {type: number, id: number, count: number, received: boolean}[]) {
if(!sid) {
export async function checkTask(roleId: string, sid: string, funcs: number[], taskType: number, count: number, isInc: boolean, param: TaskParam) {
let pushMessage = await taskUtil.checkTask(roleId, taskType, count, isInc, param, funcs);
pushTaskUpdate(roleId, sid, funcs, pushMessage);
}
export async function pushTaskUpdate(roleId: string, sid: string, funcs: number[], pushMessage: {type: number, id: number, count: number, received: boolean}[]) {
if(!sid || !funcs) {
let onlineUser = await getRoleOnlineInfo(roleId);
sid = onlineUser.sid;
funcs = onlineUser.funcs||[];
}
if(!!sid) {
let uids = [{uid: roleId, sid}];
@@ -59,40 +66,40 @@ export async function pushTaskUpdate(roleId: string, sid: string, pushMessage: {
/**
* battle.normalBattleHandler.battleEnd 中会触发的任务,因为有点多提出来了
*/
export async function checkTaskInBattleEnd(roleId: string, sid: string, battleId: number, heroes: number[], star: number) {
export async function checkTaskInBattleEnd(roleId: string, sid: string, funcs: number[], battleId: number, heroes: number[], star: number) {
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_WITH_HERO, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_MAIN, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DAILY_STAR, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DAILY, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DUNGEON, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_DUNGEON_WAR, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_TOWER, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_VESTIGE, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, TASK_TYPE.BATTLE_EXPEDITION, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_WITH_HERO, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_MAIN, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_DAILY_STAR, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_DAILY, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_DUNGEON, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_DUNGEON_WAR, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_TOWER, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_VESTIGE, battleId, heroes, 1, star);
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_EXPEDITION, battleId, heroes, 1, star);
}
export async function checkTaskInComBattleEnd(roleIds: string[], capId: string, quality: number) {
for(let roleId of roleIds) {
if(roleId == capId && roleIds.length > 1) { // 招募队友
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE_CREATE_TEAM, 1, true, {});
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE_CREATE_TEAM, 1, true, {});
} else if (roleId !== capId) { // 协助寻宝
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE_ASSIST_TEAM, 1, true, {});
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE_ASSIST_TEAM, 1, true, {});
}
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE, 1, true, {});
await checkTask(roleId, null, TASK_TYPE.COM_BATTLE_QUALITY, 1, true, { quality });
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE, 1, true, {});
await checkTask(roleId, null, null, TASK_TYPE.COM_BATTLE_QUALITY, 1, true, { quality });
}
}
export async function checkTaskInPvpEnd(roleId: string, sid: string, isSuccess: boolean, heroScores: HeroScores[]) {
await checkTask(roleId, sid, TASK_TYPE.PVP, 1, true, {});
export async function checkTaskInPvpEnd(roleId: string, sid: string, funcs: number[], isSuccess: boolean, heroScores: HeroScores[]) {
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP, 1, true, {});
if(isSuccess) {
await checkTask(roleId, sid, TASK_TYPE.PVP_WIN, 1, true, {});
await checkTask(roleId, sid, TASK_TYPE.PVP_WIN_SERIES, 1, true, {});
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP_WIN, 1, true, {});
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP_WIN_SERIES, 1, true, {});
} else {
await checkTask(roleId, sid, TASK_TYPE.PVP_WIN_SERIES, 0, false, {});
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP_WIN_SERIES, 0, false, {});
}
await checkTask(roleId, sid, TASK_TYPE.PVP, 0, false, { heroScores });
await checkTask(roleId, sid, funcs, TASK_TYPE.PVP, 0, false, { heroScores });
}
+2 -2
View File
@@ -186,8 +186,8 @@ export async function checkResult(pvpDefense: PvpDefenseType, seasonNum: number,
seasonNum: pvpDefense.seasonNum, challengeCnt, challengeRefTime, seasonEndTime: oldSeasonEndTime
}, heroGoods, rankGoods, show: true });//结算修改玩家pvp信息
// 更新任务
await checkTask(pvpDefense.roleId, null, TASK_TYPE.PVP_HERO_SCORE, 0, false, { heroScores: pvpDefense.heroScores });
await checkTask(pvpDefense.roleId, null, TASK_TYPE.PVP_RANK, 1, false, { rankLv });
await checkTask(pvpDefense.roleId, null, null, TASK_TYPE.PVP_HERO_SCORE, 0, false, { heroScores: pvpDefense.heroScores });
await checkTask(pvpDefense.roleId, null, null, TASK_TYPE.PVP_RANK, 1, false, { rankLv });
return { rankLv, score, pLv, heroScores: pvpDefense.heroScores, seasonNum, challengeCnt:PVP.PVP_CHALLENGE_COUNTS, challengeRefTime:0, oldSeasonEndTime, heroGoods:heroGoods.map(({id, count})=>{
return {id, count};
}), rankGoods};