Compare commits

..

No commits in common. "a1b7cb1d7c5c9d06e63dad37a5fb3d1b95efd3b0" and "20bb0c9478013969f4040c8b6e1f5899f282f65c" have entirely different histories.

13 changed files with 77 additions and 100 deletions

View File

@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/equip/PtlGetList"
export default async function (call: ApiCall<ReqGetList, ResGetList>) { export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let list: ResGetList['list'] = {}; let list: ResGetList['list'] = {};
//let kvList: k_v<RedisCollections2['equip']> = {}; let kvList: k_v<RedisCollections2['equip']> = {};
let arrList = await G.mongodb.collection('equip').find({ uid: call.uid }).toArray(); let arrList = await G.mongodb.collection('equip').find({ uid: call.uid }).toArray();
let equipCon = G.gc.equip let equipCon = G.gc.equip
@ -12,7 +12,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let maxequiplv = 0 let maxequiplv = 0
arrList.forEach(v => { arrList.forEach(v => {
let d = G.mongodb.conversionIdObj(v); let d = G.mongodb.conversionIdObj(v);
//kvList[G.formatRedisKey(d._id)] = d; kvList[G.formatRedisKey(d._id)] = d;
list[d._id] = d; list[d._id] = d;
if (v.lv > maxequiplv) maxequiplv = v.lv if (v.lv > maxequiplv) maxequiplv = v.lv
@ -24,7 +24,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' }, await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' },
{ $set: { maxequiplv: maxequiplv, equipcolor: color } }, { upsert: true }) { $set: { maxequiplv: maxequiplv, equipcolor: color } }, { upsert: true })
//G.redis.set('equip', call.uid, kvList); G.redis.set('equip', call.uid, kvList);
let recLshd = await G.mongodb.collection('playerInfo', 'lshd_equip').findOne({ uid: call.conn.uid, type: 'lshd_equip' }); let recLshd = await G.mongodb.collection('playerInfo', 'lshd_equip').findOne({ uid: call.conn.uid, type: 'lshd_equip' });
let { uid, _id, type, ...equips } = (recLshd || {}); let { uid, _id, type, ...equips } = (recLshd || {});

View File

@ -14,7 +14,7 @@ export default async function (call: ApiCall<ReqOneKeyWear, ResOneKeyWear, Servi
let wearNum = 0; let wearNum = 0;
let wearData = hero.equip || {}; let wearData = hero.equip || {};
let equipList = await EquipFun.getAllEquips(call); let equipList = await G.redis.get('equip', call.conn.uid) || {};
let allEquip = Object.values(equipList); let allEquip = Object.values(equipList);
let heroIds = Object.values(call.conn.gud.heroPos).filter(i => !!i) let heroIds = Object.values(call.conn.gud.heroPos).filter(i => !!i)

View File

@ -11,7 +11,7 @@ import { PublicShared } from "../../shared/public/public";
export default async function (call: ApiCall<ReqStarUp, ResStarUp, ServiceType>) { export default async function (call: ApiCall<ReqStarUp, ResStarUp, ServiceType>) {
let equip = await EquipFun.getEquip(call, call.req.equipId); let equip = await G.redis.get('equip', call.uid, call.req.equipId);
if (!equip) return call.error(globalThis.lng.equip_1); if (!equip) return call.error(globalThis.lng.equip_1);
if (!G.gc.equipstar[equip.equipId]) return call.error(globalThis.lng.equip_4); if (!G.gc.equipstar[equip.equipId]) return call.error(globalThis.lng.equip_4);
@ -28,7 +28,7 @@ export default async function (call: ApiCall<ReqStarUp, ResStarUp, ServiceType>)
for (let _id of call.req.equipArr) { for (let _id of call.req.equipArr) {
//遍历客户端传过来的所有装备,如果不存在或处于穿戴中,则报错 //遍历客户端传过来的所有装备,如果不存在或处于穿戴中,则报错
let equip = await EquipFun.getEquip(call, _id); let equip = await G.redis.get('equip', call.conn.uid, _id);
if (!equip) return call.error(globalThis.lng.equip_6); if (!equip) return call.error(globalThis.lng.equip_6);
if (equip.wearaId) return call.error(globalThis.lng.equip_7); if (equip.wearaId) return call.error(globalThis.lng.equip_7);
equipArr.push(equip); equipArr.push(equip);

View File

@ -5,7 +5,7 @@ import { ServiceType } from '../../shared/protocols/serviceProto';
import kfjsFun from "../../public/kaifujingsai"; import kfjsFun from "../../public/kaifujingsai";
export default async function (call: ApiCall<ReqTakeOff, ResTakeOff, ServiceType>) { export default async function (call: ApiCall<ReqTakeOff, ResTakeOff, ServiceType>) {
let equip = await EquipFun.getEquip(call, call.req.equipId); let equip = await G.redis.get('equip', call.conn.uid, call.req.equipId);
if (!equip) return call.error(globalThis.lng.equip_1); if (!equip) return call.error(globalThis.lng.equip_1);
if (!equip.wearaId) return call.error(globalThis.lng.equip_9); if (!equip.wearaId) return call.error(globalThis.lng.equip_9);

View File

@ -12,7 +12,7 @@ export default async function (call: ApiCall<ReqWear, ResWear, ServiceType>) {
if (!hero) return call.error(globalThis.lng.equip_10); if (!hero) return call.error(globalThis.lng.equip_10);
if (hero.lv < G.gc.herocom.equipOpenLv) return call.error(`英雄${G.gc.herocom.equipOpenLv}级开启`); if (hero.lv < G.gc.herocom.equipOpenLv) return call.error(`英雄${G.gc.herocom.equipOpenLv}级开启`);
let equip = await EquipFun.getEquip(call, call.req.equipId); let equip = await G.redis.get('equip', call.conn.uid, call.req.equipId);
if (!equip) return call.error(globalThis.lng.equip_1); if (!equip) return call.error(globalThis.lng.equip_1);
if (equip.wearaId == hero._id) return call.error(globalThis.lng.equip_11); if (equip.wearaId == hero._id) return call.error(globalThis.lng.equip_11);

View File

@ -31,7 +31,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
call.succ({ call.succ({
...ops, ...ops,
day: PublicShared.getOpenServerDay(), day: PublicShared.getOpenServerDay(call.conn.gud.cTime),
taskFinished: taskFinished taskFinished: taskFinished
}); });
} }
@ -79,7 +79,7 @@ export async function getTaskVal(gud: player, taskTyps: string[]) {
else if (t.indexOf('toDayPay') != -1) { else if (t.indexOf('toDayPay') != -1) {
let daystr = t.split('_')[1] || '1'; let daystr = t.split('_')[1] || '1';
let day = Number(daystr); let day = Number(daystr);
let zeroTime = PublicShared.getToDayZeroTime(G.openTime); let zeroTime = PublicShared.getToDayZeroTime(gud.cTime);
val[t] = await PayFun.getPayDaysAllPayNum( val[t] = await PayFun.getPayDaysAllPayNum(
gud.uid, gud.uid,
zeroTime + (day - 1) * 24 * 3600, zeroTime + day * 24 * 3600 zeroTime + (day - 1) * 24 * 3600, zeroTime + day * 24 * 3600

View File

@ -172,7 +172,7 @@ export class EmailFun {
sendEmail.sid = uid.split('_')[0] sendEmail.sid = uid.split('_')[0]
} }
if (prize?.length > 0) { if (prize.length > 0) {
sendEmail.prizeData = { sendEmail.prizeData = {
prize: email.prize, prize: email.prize,
isGet: false isGet: false
@ -186,29 +186,27 @@ export class EmailFun {
sendEmail.lngContent = email.lngContent sendEmail.lngContent = email.lngContent
} }
//太亏了换其他清理机制getAllEmail是性能消耗大户 if (!isCross) {
//todo.. 换其他清理机制 let emailList = await this.getAllEmail(uid);
// if (!isCross) { if (emailList.length >= 50) {
// let emailList = await this.getAllEmail(uid); emailList.sort((a, b) => {
// if (emailList.length >= 50) { let noPrizeA = a.prizeData == undefined ? 0 : 1;
// emailList.sort((a, b) => { let noPrizeB = b.prizeData == undefined ? 0 : 1;
// let noPrizeA = a.prizeData == undefined ? 0 : 1; let getA = a.prizeData?.isGet == true ? 0 : 1;
// let noPrizeB = b.prizeData == undefined ? 0 : 1; let getB = b.prizeData?.isGet == true ? 0 : 1;
// let getA = a.prizeData?.isGet == true ? 0 : 1;
// let getB = b.prizeData?.isGet == true ? 0 : 1;
// if (noPrizeA != noPrizeB) { if (noPrizeA != noPrizeB) {
// return noPrizeA - noPrizeB; return noPrizeA - noPrizeB;
// } else if (getA != getB) { } else if (getA != getB) {
// return getA - getB; return getA - getB;
// } }
// return a.createTime - b.createTime; return a.createTime - b.createTime;
// }); });
// this.removeEmail(uid, emailList[0]._id); this.removeEmail(uid, emailList[0]._id);
// G.server.sendMsgByUid(uid, 'msg_s2c/EmailDel', emailList[0]._id); G.server.sendMsgByUid(uid, 'msg_s2c/EmailDel', emailList[0]._id);
// } }
// } }
let _id = (await G.mongodb.collection('email').insertOne({ let _id = (await G.mongodb.collection('email').insertOne({
ttl: new Date(), ...G.mongodb.conversionIdObj(sendEmail) ttl: new Date(), ...G.mongodb.conversionIdObj(sendEmail)

View File

@ -27,9 +27,9 @@ export class EquipFun {
Object.assign(equip, change); Object.assign(equip, change);
// for (let k in change) { for (let k in change) {
// G.redis.set('equip', call.uid, equip._id, k as keyof CollectionEquip, change[k]); G.redis.set('equip', call.uid, equip._id, k as keyof CollectionEquip, change[k]);
// } }
G.mongodb.collection('equip').updateOne({uid: call.uid, _id: new ObjectId(equip._id)}, {$set: {...change}}); G.mongodb.collection('equip').updateOne({uid: call.uid, _id: new ObjectId(equip._id)}, {$set: {...change}});
call.addEventMsg('msg_s2c/EquipChange', equip._id, change); call.addEventMsg('msg_s2c/EquipChange', equip._id, change);
} }
@ -37,37 +37,24 @@ export class EquipFun {
/** /**
* *
*/ */
static async getEquip(call: ApiCall, oid?: string): Promise<CollectionEquip>; static async getEquip(call: ApiCall, oid: string): Promise<CollectionEquip>;
static async getEquip(call: ApiCall, oid?: string[]): Promise<CollectionEquip[]>; static async getEquip(call: ApiCall, oid: string[]): Promise<CollectionEquip[]>;
static async getEquip(call: ApiCall, oid?: string | string[]) { static async getEquip(call: ApiCall, oid: string | string[]) {
if (typeof oid == 'string') { if (typeof oid == 'string') {
let {_id, ...info} = await G.mongodb.collection('equip').findOne({ let data = await G.redis.get('equip', call.uid, oid);
_id: G.mongodb.conversionId(oid) if (!data) {
}) let {_id, ...info} = await G.mongodb.collection('equip').findOne({
let data = Object.assign({_id: _id.toHexString()}, info) _id: G.mongodb.conversionId(oid)
})
data = Object.assign({_id: _id.toHexString()}, info)
}
return data return data
} else { } else {
let filter = { let equips = await G.mongodb.collection('equip').find({
uid: call.uid, uid: call.uid,
} _id: {$in: oid.map(v => G.mongodb.conversionId(v))}
if(oid && oid.length > 0){ }).toArray();
filter['_id'] = {$in: oid.map(v => G.mongodb.conversionId(v))}
}
let equips = await G.mongodb.collection('equip').find(filter).toArray();
return equips.map(v => G.mongodb.conversionIdObj(v)); return equips.map(v => G.mongodb.conversionIdObj(v));
} }
} }
/**
*
* redis返回的格式
*/
static async getAllEquips(call: ApiCall):Promise<k_v<CollectionEquip>>{
let res = {};
let equips:CollectionEquip[] = await this.getEquip(call,[]);
equips.map(v => {
res['_'+v._id] = v;
});
return res;
}
} }

View File

@ -18,11 +18,9 @@ export async function clearGud(uid) {
G.ioredis.del(`gudVersion:${uid}_pid`); G.ioredis.del(`gudVersion:${uid}_pid`);
G.ioredis.del(`gudVersion:${uid}_ver`); G.ioredis.del(`gudVersion:${uid}_ver`);
} }
G.redis.del("equip",uid);
if(await G.redis.type('tanxian', uid)){ G.redis.del("hero",uid);
console.log('清空tanxian Redis',uid); G.redis.del("shiwu",uid);
G.redis.del("tanxian",uid);
}
}; };
/** /**

View File

@ -501,10 +501,9 @@ export class PayFun {
* *
*/ */
static async getPayDaysAllPayNum(uid: string, sTime: number, eTime: number) { static async getPayDaysAllPayNum(uid: string, sTime: number, eTime: number) {
let logs = await G.mongodb.collection('dayPay').find({ let logs = await G.mongodb.collection('dayPay').find({uid: uid}).toArray() || [];
uid: uid,
time: {$gte: sTime, $lt: eTime} logs = logs.filter(log => log.time >= sTime && log.time < eTime);
}).toArray() || [];
if (logs.length <= 0) return 0; if (logs.length <= 0) return 0;
return logs.map(log => log.payNum).reduce((a, b) => a + b); return logs.map(log => log.payNum).reduce((a, b) => a + b);

View File

@ -372,10 +372,10 @@ export class PlayerFun {
let id = result.insertedIds[key].toHexString(); let id = result.insertedIds[key].toHexString();
let {_id, ...ops} = v; let {_id, ...ops} = v;
// G.redis.set('equip', call.uid, id, { G.redis.set('equip', call.uid, id, {
// _id: id, _id: id,
// ...ops ...ops
// }); });
Wjjl.setVal(call.uid, `has_equip_color_${G.gc.equip[ops.equipId].colour}`, 1, false); Wjjl.setVal(call.uid, `has_equip_color_${G.gc.equip[ops.equipId].colour}`, 1, false);

View File

@ -60,9 +60,10 @@ export async function initRedis() {
//启动前清理redis残余数据 //启动前清理redis残余数据
clusterRunOnce(async () => { clusterRunOnce(async () => {
await clearRedis(); await clearRedis();
await setRedis();
}) })
if (G.config.cleanRedis) await redisClient.flushDb(); if (G.config.cleanRedis) await redisClient.flushDb();
await setRedis();
console.log('connect redis succ'); console.log('connect redis succ');
} }
@ -75,8 +76,9 @@ async function clearRedis() {
G.redis.fromatKey('user'), G.redis.fromatKey('user'),
G.redis.fromatKey('item'), G.redis.fromatKey('item'),
G.redis.fromatKey('hero'), G.redis.fromatKey('hero'),
G.redis.fromatKey('equip'),
G.redis.fromatKey('shiwu'), //G.redis.fromatKey('equip'),
//G.redis.fromatKey('shiwu'),
//G.redis.fromatKey('gbtx'), //G.redis.fromatKey('gbtx'),
//G.redis.fromatKey('dxlt'), //G.redis.fromatKey('dxlt'),
]) ])

View File

@ -1,10 +1,10 @@
import {ResGetList} from '../protocols/hero/PtlGetList'; import { ResGetList } from '../protocols/hero/PtlGetList';
import {player} from '../protocols/user/type'; import { player } from '../protocols/user/type';
import {EquipShared} from './equip'; import { EquipShared } from './equip';
import {PeijianShared} from './peijian'; import { PeijianShared } from './peijian';
import {PlayerShared} from './player'; import { PlayerShared } from './player';
import {PublicShared} from './public'; import { PublicShared } from './public';
import {ShiwuShared} from './shiwu'; import { ShiwuShared } from './shiwu';
export type otherBuff = Partial<player & { export type otherBuff = Partial<player & {
allBuff: k_v<number>; allBuff: k_v<number>;
@ -23,7 +23,6 @@ export class HeroShared {
return allBuff; return allBuff;
} }
/** /**
* *
* @param hero * @param hero
@ -31,7 +30,7 @@ export class HeroShared {
*/ */
static getHeroBasicAttr(hero: heroDataType, otherBuff: otherBuff = G.otherBuff, pos = 0) { static getHeroBasicAttr(hero: heroDataType, otherBuff: otherBuff = G.otherBuff, pos = 0) {
let jiban = 0; let jiban = 0;
let buff: k_v<any> = {skillArr: []}; let buff: k_v<any> = { skillArr: [] };
let heroConf = G.gc.hero[hero.heroId]; let heroConf = G.gc.hero[hero.heroId];
let heroLv = G.gc.herolv[heroConf.lvup]; let heroLv = G.gc.herolv[heroConf.lvup];
let heroGrow = G.gc.herogrow[heroConf.jjup]?.[hero.jieji]; let heroGrow = G.gc.herogrow[heroConf.jjup]?.[hero.jieji];
@ -40,7 +39,7 @@ export class HeroShared {
for (let k in heroLv.buff) { for (let k in heroLv.buff) {
let val = heroLv.buff[k]; let val = heroLv.buff[k];
if (typeof val == 'number') buff[k] = val; if (typeof val == 'number') buff[k] = val;
else buff[k] = PublicShared.eval(val, {lv: hero.lv}); else buff[k] = PublicShared.eval(val, { lv: hero.lv });
// else buff[k] = Math.floor(new Function(`let lv=${hero.lv}; return ${val}`)()); // else buff[k] = Math.floor(new Function(`let lv=${hero.lv}; return ${val}`)());
} }
@ -127,7 +126,7 @@ export class HeroShared {
PublicShared.mergeProperty(buff, PeijianShared.getAttr(p)); PublicShared.mergeProperty(buff, PeijianShared.getAttr(p));
let conf = G.gc.peijian[p.peijianId]; let conf = G.gc.peijian[p.peijianId];
if (conf.suit) { if (conf.suit) {
if (!suitObj[conf.suit]) suitObj[conf.suit] = {num: 0, minLv: 0}; if (!suitObj[conf.suit]) suitObj[conf.suit] = { num: 0, minLv: 0 };
suitObj[conf.suit].num++; suitObj[conf.suit].num++;
if (!suitObj[conf.suit].minLv || p.lv < suitObj[conf.suit].minLv) suitObj[conf.suit].minLv = p.lv; if (!suitObj[conf.suit].minLv || p.lv < suitObj[conf.suit].minLv) suitObj[conf.suit].minLv = p.lv;
} }
@ -173,7 +172,7 @@ export class HeroShared {
if (hero.qiannneg) { if (hero.qiannneg) {
for (let type in hero.qiannneg) { for (let type in hero.qiannneg) {
// console.log(PublicShared.mergeProperty(buff, G.gc.hero_qianneng[type]?.[hero.qiannneg[type]].buff)) // console.log(PublicShared.mergeProperty(buff, G.gc.hero_qianneng[type]?.[hero.qiannneg[type]].buff))
for (let i = 1; i <= hero.qiannneg[type]; i++) { for(let i = 1; i <= hero.qiannneg[type]; i++) {
G.gc.hero_qianneng[type]?.[i] && PublicShared.mergeProperty(buff, G.gc.hero_qianneng[type]?.[i].buff); G.gc.hero_qianneng[type]?.[i] && PublicShared.mergeProperty(buff, G.gc.hero_qianneng[type]?.[i].buff);
} }
} }
@ -261,7 +260,7 @@ export class HeroShared {
if (otherBuff?.skills) { if (otherBuff?.skills) {
for (let [id, lv] of Object.entries(otherBuff.skills)) { for (let [id, lv] of Object.entries(otherBuff.skills)) {
if (lv && G.gc.xunlianjihua[id].use == 0) { if (lv && G.gc.xunlianjihua[id].use == 0) {
PublicShared.mergeProperty(buff, Object.fromEntries([G.gc.xunlianjihua[id].skill].map(k => [k, PublicShared.eval(G.gc.xunlianjihua[id].v[0], {slv: lv})]))); PublicShared.mergeProperty(buff, Object.fromEntries([G.gc.xunlianjihua[id].skill].map(k => [k, PublicShared.eval(G.gc.xunlianjihua[id].v[0], { slv: lv })])));
} }
} }
} }
@ -287,7 +286,6 @@ export class HeroShared {
return buff; return buff;
}; };
/**修正属性 数值取整*/ /**修正属性 数值取整*/
static amendAttr(buff: k_v<number>) { static amendAttr(buff: k_v<number>) {
for (let k in buff) { for (let k in buff) {
@ -296,7 +294,6 @@ export class HeroShared {
buff[k] = Math.floor(buff[k]); buff[k] = Math.floor(buff[k]);
} }
} }
/** /**
* *
* @param hero * @param hero
@ -306,7 +303,6 @@ export class HeroShared {
let buff = this.getHeroBasicAttr(hero, otherBuff, pos); let buff = this.getHeroBasicAttr(hero, otherBuff, pos);
return this.computeHeroZhanLi(buff); return this.computeHeroZhanLi(buff);
} }
/** /**
* *
*/ */
@ -317,7 +313,6 @@ export class HeroShared {
let def = buff.def || 0; let def = buff.def || 0;
let hp = buff.hp || 0; let hp = buff.hp || 0;
let speed = buff.speed || 0; let speed = buff.speed || 0;
let speedpro = buff.speedpro || 0;
let hppro = buff.hppro || 0; let hppro = buff.hppro || 0;
let dpspro = buff.dpspro || 0; let dpspro = buff.dpspro || 0;
let undpspro = buff.undpspro || 0; let undpspro = buff.undpspro || 0;
@ -334,11 +329,11 @@ export class HeroShared {
(maxdps * .75) + (maxdps * .75) +
(def * 1.03) + (def * 1.03) +
(hp * 1) + (hp * 1) +
(speed * 21.28) +
(hp * hppro * .5) + (hp * hppro * .5) +
(speed * (speedpro + 1) * 21.28) +
((mindps + maxdps) / 2 * dpspro * .75) + ((mindps + maxdps) / 2 * dpspro * .75) +
(hp * undpspro * .6) + (hp * undpspro * .6) +
((mindps + maxdps) / 2 * xixuepro) + ((mindps + maxdps) / 2 * xixuepro * 1) +
((mindps + maxdps) / 2 * baoshangpro * .75) + ((mindps + maxdps) / 2 * baoshangpro * .75) +
((mindps + maxdps) / 2 * shanbipro * .5) + ((mindps + maxdps) / 2 * shanbipro * .5) +
((mindps + maxdps) / 2 * mingzhongpro * .5) + ((mindps + maxdps) / 2 * mingzhongpro * .5) +
@ -346,7 +341,6 @@ export class HeroShared {
(hp * pvpdpsdrop * .5) (hp * pvpdpsdrop * .5)
); );
} }
/** /**
* *
* @param id id * @param id id
@ -355,11 +349,10 @@ export class HeroShared {
static getHeroLvUpNeed(id: string | number, lv = 1): atn[] { static getHeroLvUpNeed(id: string | number, lv = 1): atn[] {
return [ return [
{a: 'item', t: '1', n: G.gc.herolvup[lv].expneed}, { a: 'item', t: '1', n: G.gc.herolvup[lv].expneed },
{a: 'attr', t: 'jinbi', n: G.gc.herolvup[lv].jinbineed} { a: 'attr', t: 'jinbi', n: G.gc.herolvup[lv].jinbineed }
]; ];
} }
/** /**
* *
* @param id id * @param id id