Merge branch 'bugfix' into dev

This commit is contained in:
dy 2023-12-18 19:19:13 +08:00
commit a1b7cb1d7c
13 changed files with 100 additions and 77 deletions

View File

@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/equip/PtlGetList"
export default async function (call: ApiCall<ReqGetList, ResGetList>) {
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 equipCon = G.gc.equip
@ -12,7 +12,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let maxequiplv = 0
arrList.forEach(v => {
let d = G.mongodb.conversionIdObj(v);
kvList[G.formatRedisKey(d._id)] = d;
//kvList[G.formatRedisKey(d._id)] = d;
list[d._id] = d;
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' },
{ $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 { uid, _id, type, ...equips } = (recLshd || {});

View File

@ -14,7 +14,7 @@ export default async function (call: ApiCall<ReqOneKeyWear, ResOneKeyWear, Servi
let wearNum = 0;
let wearData = hero.equip || {};
let equipList = await G.redis.get('equip', call.conn.uid) || {};
let equipList = await EquipFun.getAllEquips(call);
let allEquip = Object.values(equipList);
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>) {
let equip = await G.redis.get('equip', call.uid, call.req.equipId);
let equip = await EquipFun.getEquip(call, call.req.equipId);
if (!equip) return call.error(globalThis.lng.equip_1);
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) {
//遍历客户端传过来的所有装备,如果不存在或处于穿戴中,则报错
let equip = await G.redis.get('equip', call.conn.uid, _id);
let equip = await EquipFun.getEquip(call, _id);
if (!equip) return call.error(globalThis.lng.equip_6);
if (equip.wearaId) return call.error(globalThis.lng.equip_7);
equipArr.push(equip);

View File

@ -5,7 +5,7 @@ import { ServiceType } from '../../shared/protocols/serviceProto';
import kfjsFun from "../../public/kaifujingsai";
export default async function (call: ApiCall<ReqTakeOff, ResTakeOff, ServiceType>) {
let equip = await G.redis.get('equip', call.conn.uid, call.req.equipId);
let equip = await EquipFun.getEquip(call, call.req.equipId);
if (!equip) return call.error(globalThis.lng.equip_1);
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.lv < G.gc.herocom.equipOpenLv) return call.error(`英雄${G.gc.herocom.equipOpenLv}级开启`);
let equip = await G.redis.get('equip', call.conn.uid, call.req.equipId);
let equip = await EquipFun.getEquip(call, call.req.equipId);
if (!equip) return call.error(globalThis.lng.equip_1);
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({
...ops,
day: PublicShared.getOpenServerDay(call.conn.gud.cTime),
day: PublicShared.getOpenServerDay(),
taskFinished: taskFinished
});
}
@ -79,7 +79,7 @@ export async function getTaskVal(gud: player, taskTyps: string[]) {
else if (t.indexOf('toDayPay') != -1) {
let daystr = t.split('_')[1] || '1';
let day = Number(daystr);
let zeroTime = PublicShared.getToDayZeroTime(gud.cTime);
let zeroTime = PublicShared.getToDayZeroTime(G.openTime);
val[t] = await PayFun.getPayDaysAllPayNum(
gud.uid,
zeroTime + (day - 1) * 24 * 3600, zeroTime + day * 24 * 3600

View File

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

View File

@ -27,9 +27,9 @@ export class EquipFun {
Object.assign(equip, change);
for (let k in change) {
G.redis.set('equip', call.uid, equip._id, k as keyof CollectionEquip, change[k]);
}
// for (let k in change) {
// 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}});
call.addEventMsg('msg_s2c/EquipChange', equip._id, change);
}
@ -37,24 +37,37 @@ 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 | string[]) {
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[]) {
if (typeof oid == 'string') {
let data = await G.redis.get('equip', call.uid, oid);
if (!data) {
let {_id, ...info} = await G.mongodb.collection('equip').findOne({
_id: G.mongodb.conversionId(oid)
})
data = Object.assign({_id: _id.toHexString()}, info)
}
let {_id, ...info} = await G.mongodb.collection('equip').findOne({
_id: G.mongodb.conversionId(oid)
})
let data = Object.assign({_id: _id.toHexString()}, info)
return data
} else {
let equips = await G.mongodb.collection('equip').find({
let filter = {
uid: call.uid,
_id: {$in: oid.map(v => G.mongodb.conversionId(v))}
}).toArray();
}
if(oid && oid.length > 0){
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));
}
}
/**
*
* 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,9 +18,11 @@ export async function clearGud(uid) {
G.ioredis.del(`gudVersion:${uid}_pid`);
G.ioredis.del(`gudVersion:${uid}_ver`);
}
G.redis.del("equip",uid);
G.redis.del("hero",uid);
G.redis.del("shiwu",uid);
if(await G.redis.type('tanxian', uid)){
console.log('清空tanxian Redis',uid);
G.redis.del("tanxian",uid);
}
};
/**

View File

@ -501,9 +501,10 @@ export class PayFun {
*
*/
static async getPayDaysAllPayNum(uid: string, sTime: number, eTime: number) {
let logs = await G.mongodb.collection('dayPay').find({uid: uid}).toArray() || [];
logs = logs.filter(log => log.time >= sTime && log.time < eTime);
let logs = await G.mongodb.collection('dayPay').find({
uid: uid,
time: {$gte: sTime, $lt: eTime}
}).toArray() || [];
if (logs.length <= 0) return 0;
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, ...ops} = v;
G.redis.set('equip', call.uid, id, {
_id: id,
...ops
});
// G.redis.set('equip', call.uid, id, {
// _id: id,
// ...ops
// });
Wjjl.setVal(call.uid, `has_equip_color_${G.gc.equip[ops.equipId].colour}`, 1, false);

View File

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

View File

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