任务:埋点30/70

This commit is contained in:
luying
2021-04-19 13:17:17 +08:00
parent bc07e1ea31
commit 9f4f346447
38 changed files with 1088 additions and 692 deletions
@@ -3,7 +3,8 @@
*/
import { ActionPointModel } from '../db/ActionPoint';
import { ACTION_POIN } from '../consts';
import { ACTION_POIN, TASK_TYPE } from '../consts';
import { checkTask } from './taskService';
export async function getAp(now: number, roleId: string) {
let dataAp = await ActionPointModel.getAp(roleId);
@@ -29,7 +30,7 @@ export async function getAp(now: number, roleId: string) {
}
}
export async function setAp(now: number, roleId: string, changeAp: number) {
export async function setAp(now: number, roleId: string, sid: string, changeAp: number) {
let ApResult = await getAp(now, roleId);
let { ap, maxAp, refTime, apRemainTime, isOver } = ApResult; // 更新ap
ap += changeAp;
@@ -41,5 +42,9 @@ export async function setAp(now: number, roleId: string, changeAp: number) {
await ActionPointModel.saveAp(roleId, ap, refTime);
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, {});
}
return {ap, maxAp, refTime, apRemainTime}
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { MemComBtlTeam } from './../domain/battleField/ComBattleTeamField';
import { ItemModel } from './../db/Item';
import { IT_TYPE } from './../consts/consts';
import { IT_TYPE } from './../consts';
import { COM_BTL_QUALITY } from './../consts/constModules/itemConst';
import { FriendRelationModel } from './../db/FriendRelation';
import { RoleModel, RoleType } from './../db/Role';
+35 -28
View File
@@ -3,10 +3,11 @@ import { EquipModel } from "../db/Equip";
import { HeroModel, EPlace, HeroType } from "../db/Hero";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data";
import { calPlayerCeAndSave } from "./playerCeService";
import { HERO_SYSTEM_TYPE } from "../consts";
import { HERO_SYSTEM_TYPE, TASK_TYPE } from "../consts";
import { EquipType } from "../db/Equip";
import { calEquipSeids } from '../pubUtils/playerCe';
import { indexOf, findIndex } from 'underscore';
import { checkTask, checkTaskWithHero, checkTaskWithEquip } from './taskService';
/**
* 校验前端传入的消耗数量是否准确,并返回消耗的道具并加上特殊材料needConsumes
* @param consumes
@@ -44,40 +45,42 @@ export function checkMaterialEnough(consumes:Array<{id: number, count: number}>,
return needConsumes;
}
/**
* 将装备卸载下来,并坚持是否有替换装备的武将,若有则替换
* @param roleId
* 将装备卸载下来,并检查是否有替换装备的武将,若有则替换
* 武将A(装备A&武将B(装备B ==> 武将A(装备B)&武将B(装备A)
* @param roleId 玩家id
* @param sid
* @param equip
* @param hid
* @param id
* @param seqId
* @param equip 目标武将要卸下的装备,装备A
* @param hid 要装上的装备备原来装备着的武将id, 武将B
* @param id 装备类型
* @param seqId 要装上的装备的唯一id 装备B
*/
export async function changeEquip(roleId: string, sid: string, equip: EquipType, hid: number, id: number, seqId: number) {
let hero;
export async function changeEquip(roleId: string, sid: string, equipA: EquipType, hid: number, id: number, equipB: EquipType) {
let heroB: HeroType;
if (!!hid) //需要卸下或者替换的武将
hero = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);//需要替换的武将
if (!!equip) {//需要卸下的装备
if (!!hero) {
let goodInfo = getGoodById(equip.id);
if (goodInfo.lvLimited > hero.lv) {
let res = await takeOffEquip(equip.seqId);//不能替换,卸载装备不算战力
heroB = await HeroModel.findByHidAndRoleWithEquip(hid, roleId);//需要替换的武将
if (!!equipA) {//需要卸下的装备
if (!!heroB) {
let goodInfo = getGoodById(equipA.id);
if (goodInfo.lvLimited > heroB.lv) {
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
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 takeOffEquip(equip.seqId);//不能替换,卸载装备不算战力
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
return res;
}
let res = await dressEquip(roleId, sid, hero, equip);//替换给武将,并计算战力
let res = await dressEquip(roleId, sid, heroB, equipA);//替换给武将,并计算战力
return res;
} else {
let res = await takeOffEquip(equip.seqId);//不能替换,卸载装备不算战力
let res = await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
return res;
}
} else if (!!hero) {//从穿戴装备的武将上卸下装备
await takeOffEquipAndCalPlayerCe(roleId, sid, hero, equip, id);//卸下装备并重算战力
} else if (!!heroB) {//从穿戴装备的武将上卸下装备
await takeOffEquipAndCalPlayerCe(roleId, sid, heroB, equipB, id);//卸下装备并重算战力
}
}
/**
@@ -93,6 +96,12 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, he
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]);
return { seqId: equip.seqId, hid: 0};
}
/**
@@ -107,13 +116,11 @@ export async function dressEquip(roleId: string, sid: string, hero:HeroType, equ
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]);
return { seqId: equip.seqId, hid: hero.hid };
}
/**
* 修改装备未穿戴状态,不计算战力
* @param seqId
*/
async function takeOffEquip(seqId: number) {
await EquipModel.updateEquipInfo(seqId, { hid: 0 });
return { seqId, hid: 0};
}
@@ -31,6 +31,7 @@ export async function increaseFrdCnt(role1: RoleType, role2: RoleType, originalF
return getResStr(STATUS.FRIEND_THEY_CNT_MAX);
}
originalFriendCnt = incMyFrdCnt.friendCnt;
role1 = incMyFrdCnt; role2 = incHisFrdCnt;
return '';
}
@@ -4,10 +4,11 @@ import Role, { RoleModel } from '../db/Role'
import { getLvByExp, getExpByLv, gameData } from '../pubUtils/data';
import { updateUserInfo } from './redisService';
import { switchOnFunc } from './funcSwitchService';
import { FUNC_OPT_TYPE } from '../consts';
import { FUNC_OPT_TYPE, TASK_TYPE } from '../consts';
import { BackendSession } from 'pinus';
import { REDIS_KEY } from '../consts';
import { Rank } from './rankService';
import { checkTask } from './taskService';
export async function roleLevelup(roleId: string, kingExp: number, session: BackendSession) {
let role = await RoleModel.findByRoleId(roleId);
@@ -29,6 +30,9 @@ export async function roleLevelup(roleId: string, kingExp: number, session: Back
let r = new Rank(REDIS_KEY.USER_LV, { serverId: role.serverId });
await r.setRankWithRoleInfo(roleId, newLv, Date.now(), role);
// 任务
await checkTask(roleId, session.get('sid'), TASK_TYPE.ROLE_LV, newLv, false, {});
}
let actordata = [];
for(let i = lv; i <= newLv; i++) {
+2
View File
@@ -143,6 +143,8 @@ export async function matchPlayerByRank(seasonNum: number, oppPlayers: OppPlayer
oppRank ++;
}
}
} else if(myRank == 0){
return false
} else {
if(pos == 1 || pos == 2) { // 刷新我前一名
oppRank = myRank - 1;
+10 -4
View File
@@ -15,6 +15,7 @@ import { uniq, indexOf, findIndex } from 'underscore';
import { HeroModel } from '../db/Hero';
import { Figure } from '../domain/dbGeneral';
import { Rank } from './rankService';
import { pushTaskUpdate } from './taskService';
export async function handleFixedReward(roleId: string, roleName: string, sid: string, rewardStr: string, multi: number) {
let reward = parseGoodStr(rewardStr);
@@ -114,22 +115,25 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
let figures: Array<number> = [];
let uids = [{uid: roleId, sid}];
sortItems(goods, bags, skins, figures, currencysMap, equips, showItems);
let equipInfos = [];
let equipInfos = [], taskPushMessage = [];
for (let equip of equips) {
let equipInfo = await addEquips(roleId, roleName, equip);
let { equipInfo, pushMessage } = await addEquips(roleId, roleName, equip);
showItems.push({seqId: equipInfo.seqId, id: equip.id, count: 1});
equipInfos.push(equipInfo);
taskPushMessage.concat(pushMessage);
}
//装备推送
if (!!equipInfos.length)
pinus.app.get('channelService').pushMessageByUids('onEquipAdd', resResult(STATUS.SUCCESS, {equipInfos}), uids);
pushTaskUpdate(roleId, sid, 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, currencysMap[key]);
let {ap} = await setAp(Date.now(), roleId, sid, currencysMap[key]);
currencysMap.ap = ap;
} else {
currencysMap[key] += role[key];
@@ -301,7 +305,7 @@ export async function pushFigureUpdate(roleId: string, sid: string, figureInfo:
}
export async function createHero(roleId: string, sid: string, serverId: number, heroInfo) {
let { hero, role, figureInfo, calHeroResult, calAllHeroResult } = await pubCreateHero(roleId, heroInfo);
let { hero, role, figureInfo, calHeroResult, calAllHeroResult, taskPushMessage } = await pubCreateHero(roleId, heroInfo);
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
@@ -311,5 +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);
return hero;
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { ChannelUser } from './../domain/ChannelUser';
import { Channel } from 'pinus';
import { getRandNum, getRandomArr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts/consts";
import { TERAPH_RANDOM } from "../consts";
import { indexOf } from 'underscore';
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph, RoleModel } from '../db/Role';
+1 -1
View File
@@ -37,7 +37,7 @@ export async function pushHeroStarMax(roleId: string, roleName: string, serverId
}
export async function pushHeroWakeUp(roleId: string, roleName: string, serverId: number | string, heroInfo: Partial<HeroType>) {
await pushNormalHeroInfoBySource(roleId, roleName, serverId, MSG_SOURCE.HERO_WAKEUP, heroInfo);
await pushNormalHeroInfoBySource(roleId, roleName, serverId, MSG_SOURCE.HERO_WAKE_UP, heroInfo);
}
+51
View File
@@ -0,0 +1,51 @@
import * as taskUtil from '../pubUtils/taskUtil';
import { RoleType } from '../db/Role';
import { pinus } from 'pinus';
import { resResult } from '../pubUtils/util';
import { STATUS } from '../consts';
import { TaskParam } from '../domain/roleField/task';
import { HeroType } from '../db/Hero';
import { EquipType } from '../db/Equip';
import { getRoleOnlineInfo } from './redisService';
export async function checkTaskWithRoles(roleId: string, sid: string, taskType: number, roles: RoleType[]) {
for(let role of roles) {
await checkTaskWithRole(role.roleId, role.roleId == roleId? sid: 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 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 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 checkTaskWithArgs(roleId: string, sid: string, taskType: number, args: number[]) {
let pushMessage = await taskUtil.checkTaskWithArgs(roleId, taskType, args);
pushTaskUpdate(roleId, sid, 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 pushTaskUpdate(roleId: string, sid: string, pushMessage: {type: number, id: number, count: number, received: boolean}[]) {
if(!sid) {
let onlineUser = await getRoleOnlineInfo(roleId);
sid = onlineUser.sid;
}
if(!!sid) {
let uids = [{uid: roleId, sid}];
pinus.app.get('channelService').pushMessageByUids('onTaskUpdate', resResult(STATUS.SUCCESS, pushMessage), uids);
}
}