活动:添加新任务的统计

This commit is contained in:
qiaoxin
2021-06-24 16:01:59 +08:00
parent d906392764
commit 49d5580f02
3 changed files with 34 additions and 18 deletions
@@ -275,6 +275,7 @@ export class NormalBattleHandler {
let roleId = session.get('roleId'); let roleId = session.get('roleId');
let roleName = session.get('roleName'); let roleName = session.get('roleName');
let sid = session.get('sid'); let sid = session.get('sid');
let serverId = session.get('serverId');
let funcs: number[] = session.get('funcs'); let funcs: number[] = session.get('funcs');
let warInfo = gameData.war.get(battleId); let warInfo = gameData.war.get(battleId);
if (!warInfo) { if (!warInfo) {
@@ -289,7 +290,7 @@ export class NormalBattleHandler {
// 扣体力 // 扣体力
let role = await RoleModel.findByRoleId(roleId, 'lv'); let role = await RoleModel.findByRoleId(roleId, 'lv');
let apJson = await setAp(roleId, role.lv, -1 * warInfo.cost * count, sid, funcs); // 扣除体力 let apJson = await setAp(roleId, role.lv, -1 * warInfo.cost * count, sid, funcs); // 扣除体力
if (!apJson) { if (!apJson) {
return resResult(STATUS.BATTLE_ACTION_POINT_LACK); return resResult(STATUS.BATTLE_ACTION_POINT_LACK);
} }
@@ -329,6 +330,8 @@ export class NormalBattleHandler {
// 任务 // 任务
await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_MAIN_SWEEP, battleId, [], count, 0); await checkTaskWithWar(roleId, sid, funcs, TASK_TYPE.BATTLE_MAIN_SWEEP, battleId, [], count, 0);
//活动任务
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.BATTLE_MAIN_SWEEP, 1, { battleId })
return resResult(STATUS.SUCCESS, { return resResult(STATUS.SUCCESS, {
battleId, count, battleId, count,
+19 -16
View File
@@ -4,10 +4,11 @@
import { ActionPointModel } from '../db/ActionPoint'; import { ActionPointModel } from '../db/ActionPoint';
import { TASK_TYPE, STATUS } from '../consts'; import { TASK_TYPE, STATUS } from '../consts';
import { checkTask } from './taskService'; import { checkActivityTask, checkTask } from './taskService';
import { getDicApByLv } from '../pubUtils/data'; import { getDicApByLv } from '../pubUtils/data';
import { pinus } from 'pinus'; import { pinus } from 'pinus';
import { resResult } from '../pubUtils/util'; import { resResult } from '../pubUtils/util';
import { RoleModel } from '../db/Role';
/** /**
* 获取当前体力 * 获取当前体力
@@ -20,21 +21,21 @@ export async function getAp(roleId: string, lv: number) {
let dataAp = await ActionPointModel.getAp(roleId); let dataAp = await ActionPointModel.getAp(roleId);
const maxAp = dicAp.maxAp; // 最大体力值 const maxAp = dicAp.maxAp; // 最大体力值
const per = dicAp.perApRestoreTime * 1000; // 恢复时间(ms) const per = dicAp.perApRestoreTime * 1000; // 恢复时间(ms)
let {ap, refTime} = dataAp; let { ap, refTime } = dataAp;
if(ap >= maxAp) { if (ap >= maxAp) {
// 体力溢出不需要做时间的处理 // 体力溢出不需要做时间的处理
return { ap, maxAp, refTime: now, apRemainTime:0, apMaxRemainTime: 0, isOver: true } return { ap, maxAp, refTime: now, apRemainTime: 0, apMaxRemainTime: 0, isOver: true }
} else { } else {
if(refTime > now) refTime = now; // refTime:每次记录时候最近的一个整的时间点,绝对不会大于now if (refTime > now) refTime = now; // refTime:每次记录时候最近的一个整的时间点,绝对不会大于now
let n = Math.floor((now - refTime)/per); // 上次记录到现在可以增长多少体力 let n = Math.floor((now - refTime) / per); // 上次记录到现在可以增长多少体力
ap += n; // 增加上 ap += n; // 增加上
if(ap >= maxAp) { // 加上后溢出了 if (ap >= maxAp) { // 加上后溢出了
ap = maxAp; ap = maxAp;
return { ap, maxAp, refTime: now, apRemainTime:0, apMaxRemainTime: 0, isOver: true } return { ap, maxAp, refTime: now, apRemainTime: 0, apMaxRemainTime: 0, isOver: true }
} else { } else {
refTime += n * per; // 更新refTime到离现在最近的一个整的时间点 refTime += n * per; // 更新refTime到离现在最近的一个整的时间点
let apRemainTime = Math.floor((refTime + per - now)/1000); // 恢复下一点需要多少时间 let apRemainTime = Math.floor((refTime + per - now) / 1000); // 恢复下一点需要多少时间
let apMaxRemainTime = (maxAp - ap - 1) * dicAp.perApRestoreTime + apRemainTime; let apMaxRemainTime = (maxAp - ap - 1) * dicAp.perApRestoreTime + apRemainTime;
return { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, isOver: false } return { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, isOver: false }
} }
@@ -55,24 +56,26 @@ export async function setAp(roleId: string, lv: number, changeAp: number, sid: s
let ApResult = await getAp(roleId, lv); let ApResult = await getAp(roleId, lv);
let { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, isOver } = ApResult; // 更新ap let { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, isOver } = ApResult; // 更新ap
ap += changeAp; ap += changeAp;
if(ap >= maxAp) { // 溢出 if (ap >= maxAp) { // 溢出
refTime = now; refTime = now;
apRemainTime = 0; apRemainTime = 0;
apMaxRemainTime = 0; apMaxRemainTime = 0;
} }
if(ap < 0) return null // 体力不足 if (ap < 0) return null // 体力不足
await ActionPointModel.saveAp(roleId, ap, refTime); await ActionPointModel.saveAp(roleId, ap, refTime);
if(isOver && ap < maxAp) { // 特殊处理,溢出之后做减少体力的操作时 if (isOver && ap < maxAp) { // 特殊处理,溢出之后做减少体力的操作时
apRemainTime = dicAp.perApRestoreTime; apRemainTime = dicAp.perApRestoreTime;
apMaxRemainTime = (maxAp - ap) * dicAp.perApRestoreTime; apMaxRemainTime = (maxAp - ap) * dicAp.perApRestoreTime;
} }
if(changeAp < 0) { if (changeAp < 0) {
await checkTask(roleId, sid, funcs, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp, true, {}); await checkTask(roleId, sid, funcs, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp, true, {});
let { serverId } = await RoleModel.findByRoleId(roleId);
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp,);
} }
let apJson = {ap, maxAp, refTime, apMaxRemainTime, apRemainTime}; let apJson = { ap, maxAp, refTime, apMaxRemainTime, apRemainTime };
if(changeAp != 0) { if (changeAp != 0) {
let uids = [{ uid: roleId, sid }]; let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onApUpdate', resResult(STATUS.SUCCESS, { apJson }), uids); pinus.app.get('channelService').pushMessageByUids('onApUpdate', resResult(STATUS.SUCCESS, { apJson }), uids);
} }
+10
View File
@@ -1203,6 +1203,16 @@ export function isComplete(roleId: string, taskType: TASK_TYPE, taskParam: strin
addCount = count; addCount = count;
break; break;
} }
case TASK_TYPE.BATTLE_COST_AP:
{
addCount = count;
break;
}
case TASK_TYPE.BATTLE_MAIN_SWEEP:
{
addCount = count;
break;
}
default: default:
addCount = 0; addCount = 0;