数数:埋点

This commit is contained in:
luying
2021-12-14 18:04:00 +08:00
parent b6501ee4a2
commit dd7cf449d6
23 changed files with 357 additions and 72 deletions
+18 -9
View File
@@ -3,7 +3,7 @@
*/
import { ActionPointModel, ActionPointType } from '../db/ActionPoint';
import { TASK_TYPE, STATUS } from '../consts';
import { TASK_TYPE, STATUS, TA_EVENT, ITEM_CHANGE_REASON } from '../consts';
import { checkActivityTask, checkTask } from './taskService';
import { getDicApByLv } from '../pubUtils/data';
import { pinus } from 'pinus';
@@ -11,24 +11,26 @@ import { resResult, shouldRefresh } from '../pubUtils/util';
import { RoleModel } from '../db/Role';
import { pick } from 'underscore';
import { AP } from '../pubUtils/dicParam';
import { reportTAEvent } from './sdkService';
/**
* 获取当前体力
* @param roleId 玩家id
* @param lv 玩家等级
*/
export async function getAp(roleId: string, lv: number, fromGetAp = false) {
export async function getAp(roleId: string, ip: string, lv: number, fromGetAp = false) {
let dataAp = await ActionPointModel.getAp(roleId);
return getApWithDataAp(lv, dataAp, fromGetAp);
return getApWithDataAp(roleId, ip, lv, dataAp, fromGetAp);
}
function getApWithDataAp(lv: number, dataAp: ActionPointType, fromGetAp = false) {
function getApWithDataAp(roleId: string, ip: string, lv: number, dataAp: ActionPointType, fromGetAp = false) {
const now = Date.now();
const dicAp = getDicApByLv(lv);
const maxAp = dicAp.maxAp; // 最大体力值
const per = AP.PERAPRESTORETIME * 1000; // 恢复时间(ms)
let { ap, refTime, buyRefTime = 0, buyTimes = 0 } = dataAp;
let oldAp = ap;
if(shouldRefresh(new Date(buyRefTime), new Date())) {
buyTimes = 0;
@@ -52,6 +54,10 @@ function getApWithDataAp(lv: number, dataAp: ActionPointType, fromGetAp = false)
result = { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, isOver: false, buyTimes, buyRefTime };
}
}
if(result.ap > oldAp) {
reportTAEvent(roleId, TA_EVENT.AP_GET, { change_count: oldAp - result.ap, change_after: result.ap, change_reason: ITEM_CHANGE_REASON.AP_RECOVERY })
}
return fromGetAp?result: pick(result, ['ap', 'maxAp', 'apRemainTime', 'apMaxRemainTime', 'buyTimes']);
}
@@ -62,10 +68,10 @@ function getApWithDataAp(lv: number, dataAp: ActionPointType, fromGetAp = false)
* @param changeAp 体力变化,正是加,负是减
* @param sid
*/
export async function setAp(roleId: string, lv: number, changeAp: number, sid: string) {
export async function setAp(roleId: string, ip: string, lv: number, changeAp: number, sid: string, reason: ITEM_CHANGE_REASON) {
const now = Date.now();
const dicAp = getDicApByLv(lv);
let ApResult = await getAp(roleId, lv, true);
let ApResult = await getAp(roleId, ip, lv, true);
let { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, isOver, buyTimes } = ApResult; // 更新ap
ap += changeAp;
if (ap >= maxAp) { // 溢出
@@ -85,8 +91,11 @@ export async function setAp(roleId: string, lv: number, changeAp: number, sid: s
await checkTask(roleId, sid, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp, true, {});
let { serverId } = await RoleModel.findByRoleId(roleId);
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.BATTLE_COST_AP, -1 * changeAp,);
reportTAEvent(roleId, TA_EVENT.AP_CONSUME, { change_count: -1 * changeAp, change_after: ap, change_reason: reason }, ip)
} else {
reportTAEvent(roleId, TA_EVENT.AP_GET, { change_count: changeAp, change_after: ap, change_reason: reason }, ip)
}
let apJson = await getApWithDataAp(lv, dataAp);
let apJson = await getApWithDataAp(roleId, ip, lv, dataAp);
if (changeAp != 0) {
let uids = [{ uid: roleId, sid }];
@@ -96,10 +105,10 @@ export async function setAp(roleId: string, lv: number, changeAp: number, sid: s
return apJson
}
export async function setApBuyTimes(roleId: string, lv: number, sid: string, incTimes: number) {
export async function setApBuyTimes(roleId: string, ip: string, lv: number, sid: string, incTimes: number) {
if(incTimes <= 0) return false;
let ApResult = await getAp(roleId, lv, true);
let ApResult = await getAp(roleId, ip, lv, true);
let { ap, maxAp, refTime, apRemainTime, apMaxRemainTime, buyTimes, buyRefTime } = ApResult; // 更新ap
if(shouldRefresh(new Date(buyRefTime), new Date())) {