63 lines
2.6 KiB
TypeScript
63 lines
2.6 KiB
TypeScript
import {ApiCall} from 'tsrpc';
|
|
import {ResOpen} from '../shared/protocols/tanxian/PtlOpen';
|
|
import {TeQuanFun} from './tequan';
|
|
import {addGameLog} from "../gameLog";
|
|
|
|
type dataChange = Partial<ResOpen>;
|
|
|
|
export class TanXianFun {
|
|
/**
|
|
* 修改探险数据
|
|
* 此改动是为了不影响旧的数据结构
|
|
* 下面changeDataNew和此方法一样
|
|
*/
|
|
static async changeData(call: ApiCall, change: dataChange) {
|
|
let {_id, uid, ...data} = (await G.mongodb.collection('tanxian').findOneAndUpdate({uid: call.uid}, {$set: {...change}}, {returnDocument: 'after'})).value;
|
|
G.ioredis.setex(`tanxian:${uid}`, 600, JSON.stringify(data));
|
|
}
|
|
|
|
/**
|
|
* 此方法是为了不影响旧的数据结构
|
|
* 用inc去叠加用户限制的次数
|
|
* @param call
|
|
* @param change
|
|
*/
|
|
static async changeDataNew(call: ApiCall, change) {
|
|
let {_id, uid, ...data} = (await G.mongodb.collection('tanxian').findOneAndUpdate({uid: call.uid}, change, {returnDocument: 'after'})).value;
|
|
G.ioredis.setex(`tanxian:${uid}`, 600, JSON.stringify(data));
|
|
addGameLog(call.uid, "_fastguajiChange", {}, data)
|
|
}
|
|
|
|
/**获取探险数据 */
|
|
static async getData(call: ApiCall, cache = true) {
|
|
let cacheData = await G.ioredis.get(`tanxian:${call.uid}`);
|
|
if (cacheData && cache) return JSON.parse(cacheData);
|
|
let {_id, uid, ...data} = await G.mongodb.collection('tanxian').findOne({uid: call.uid});
|
|
if (!data.eventTime) {
|
|
data.eventTime = G.time;
|
|
G.mongodb.collection('tanxian').updateOne({uid: call.uid}, {$set: {eventTime: G.time}});
|
|
}
|
|
G.ioredis.setex(`tanxian:${call.uid}`, 600, JSON.stringify(data));
|
|
return data;
|
|
}
|
|
|
|
/**获取快速探险次数 */
|
|
static async getFastGuaJiNum(call: ApiCall) {
|
|
let num = G.gc.tanxian_com.fastGuaJiNum + await TeQuanFun.getTxFreeNum(call);
|
|
|
|
if (call.conn.gud.vip) {
|
|
num += G.gc.tanxian_com.fastGuaJiNumAddBuyVip[call.conn.gud.vip] || G.gc.tanxian_com.fastGuaJiNumAddBuyVip.last();
|
|
} else {
|
|
num += G.gc.tanxian_com.fastGuaJiNumAddBuyVip[call.conn.gud.vip];
|
|
}
|
|
return num;
|
|
}
|
|
|
|
/**获取最后领取奖励的id与sort后的数组*/
|
|
static getLastMapId(receivePrizeConfId: string[]) {
|
|
if (!receivePrizeConfId) receivePrizeConfId = []
|
|
receivePrizeConfId = receivePrizeConfId.sort((a, b) => ~~a - ~~b);
|
|
let receiveLastId = receivePrizeConfId.length > 0 ? receivePrizeConfId[receivePrizeConfId.length - 1] : '0';// 获取当前的领取进度
|
|
return {receiveLastId, receivePrizeConfId}
|
|
}
|
|
} |