76 lines
3.4 KiB
TypeScript
76 lines
3.4 KiB
TypeScript
/**
|
|
* 每日本相关
|
|
*/
|
|
|
|
import DailyRecord, { DailyRecordModel } from '../db/DailyRecord';
|
|
import { getGamedata } from '../pubUtils/gamedata';
|
|
import { resResult } from '../pubUtils/util';
|
|
import { STATUS } from '../consts/statusCode';
|
|
import { RoleModel } from '../db/Role';
|
|
|
|
// 检查每日本次数checkBattle使用
|
|
export async function checkDaily(roleId: string, battleId: number, inc: number) {
|
|
let dicDaily = getGamedata('dic_zyz_daily');
|
|
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
|
let dailyWar = dicDailyWar.find(cur => cur.war_id == battleId);
|
|
if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) };
|
|
let type = dailyWar.dailyType;
|
|
|
|
let curDaily = dicDaily.find(cur => cur.dailyType == type);
|
|
if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) };
|
|
let dailyRecord = await DailyRecordModel.refreshRecord(roleId, type);
|
|
let { count = 0, buyCount = 0 } = dailyRecord;
|
|
if(count + inc > curDaily.timesPerDay + buyCount ) {
|
|
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
|
|
}
|
|
let checkDailyResult = await getDailyNum(dailyRecord, curDaily.timesPerDay, curDaily.timesCanBuy);
|
|
return {status: 1, data: {type, ...checkDailyResult}};
|
|
}
|
|
|
|
/**
|
|
* 检查每日本次数并添加,warEnd和warSweep使用
|
|
* @param roleId
|
|
* @param battleId
|
|
* @param inc 增加的次数
|
|
* @param isRef 在计算之前是否检查每日的刷新
|
|
*/
|
|
|
|
export async function checkDailyAndIncrease(roleId: string, battleId: number, inc: number, isRef: boolean) {
|
|
let dicDaily = getGamedata('dic_zyz_daily');
|
|
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
|
let dailyWar = dicDailyWar.find(cur => cur.war_id == battleId);
|
|
if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) };
|
|
let type = dailyWar.dailyType;
|
|
|
|
let curDaily = dicDaily.find(cur => cur.dailyType == type);
|
|
if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) };
|
|
|
|
let dailyRecord: any;
|
|
if(isRef) {
|
|
dailyRecord = await DailyRecordModel.refreshRecord(roleId, type);
|
|
} else { // 如果是手动挑战,由于在进入时已经检查过了,所以即使结算时过去了一天也还是累计在上一天
|
|
dailyRecord = await DailyRecordModel.getDailyRecordById(roleId, type);
|
|
}
|
|
let { count = 0, buyCount = 0 } = dailyRecord;
|
|
if(count + inc > curDaily.timesPerDay + buyCount ) {
|
|
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
|
|
}
|
|
let result = await DailyRecordModel.increseDailyCount(roleId, type, inc);
|
|
let checkDailyResult = await getDailyNum(result, curDaily.timesPerDay, curDaily.timesCanBuy);
|
|
return {status: 1, data: {type, ...checkDailyResult}};
|
|
}
|
|
|
|
export async function getDailyNum(dailyRecord: DailyRecord, timesPerDay?: number, timesCanBuy?: number) {
|
|
let {roleId, type, count = 0, buyCount = 0} = dailyRecord;
|
|
if(!timesPerDay || !timesCanBuy) {
|
|
const dicDaily = getGamedata('dic_zyz_daily');
|
|
const curDaily = dicDaily.find(cur => cur.dailyType == type);
|
|
timesPerDay = curDaily.timesPerDay;
|
|
timesCanBuy = curDaily.timesCanBuy;
|
|
}
|
|
let {vLv} = await RoleModel.findByRoleId(roleId);
|
|
if(vLv > 0) {
|
|
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
|
}
|
|
return {battleCount: timesPerDay - count + buyCount, buyCount: timesCanBuy - buyCount}
|
|
} |