Merge branch 'bugfix' into release

This commit is contained in:
dy 2023-12-19 10:08:44 +08:00
commit 83c99c25bd
22 changed files with 201 additions and 110 deletions

View File

@ -120,7 +120,13 @@ export default async function (call: ApiCall<ReqBingo, ResBingo>) {
} }
} else if (shell[0] == 'heroMaxLv') { } else if (shell[0] == 'heroMaxLv') {
let heros = await G.redis.get('hero', call.uid); //let heros = await G.redis.get('hero', call.uid);
let s = await G.mongodb.collection('hero').find({
uid: call.uid
}).toArray();
let heros = s.map(h => G.mongodb.conversionIdObj(h));
for (let [_id, hero] of Object.entries(heros)) { for (let [_id, hero] of Object.entries(heros)) {
await HeroFun.changeHeroAttr(call, hero, { await HeroFun.changeHeroAttr(call, hero, {
lv: Object.keys(G.gc.playerLv).length * 3, lv: Object.keys(G.gc.playerLv).length * 3,

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 G.redis.get('equip', call.conn.uid) || {}; let equipList = await EquipFun.getAllEquips(call);
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 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 (!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 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) 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 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) 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 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) 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(call.conn.gud.cTime), day: PublicShared.getOpenServerDay(),
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(gud.cTime); let zeroTime = PublicShared.getToDayZeroTime(G.openTime);
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

@ -2,20 +2,46 @@ import {ApiCall} from "tsrpc";
import {GHManage} from '../../public/gonghui/manage'; import {GHManage} from '../../public/gonghui/manage';
import {ReqGetList, ResGetList} from "../../shared/protocols/gonghui/PtlGetList"; import {ReqGetList, ResGetList} from "../../shared/protocols/gonghui/PtlGetList";
async function getGongHuiZhanli(ghId:string):Promise<number>{
//如果redis里有则直接返回
let zhanliRes = await G.ioredis.get(`gongHuiZhanLi:${ghId}`);
if(zhanliRes){
return parseInt(zhanliRes);
}
let GHData = await GHManage.getGHList();
let ghs = Object.values(GHData).map(item => item.data).filter(i => !!i.players);
let fuids = R.flatten(ghs.map(i => i.players.map(j => j.uid)))
let allRoles = await G.mongodb.find('user',{uid: {$in: fuids}},['uid','power'])
let zhanlis = Object.fromEntries(allRoles.map(r => [r.uid, r.power]));
for (let gh of ghs) {
let uids = gh.players.map(p => p.uid);
let zhanli = uids.map(u => (zhanlis[u] || 0)).reduce((a, b) => a + b);
//重设redis的值有效期1小时
G.ioredis.setex(`gongHuiZhanLi:${gh._id}`,3600, zhanli);
if(gh._id == ghId){
zhanliRes = zhanli;
}
}
return parseInt(zhanliRes||"0");
}
export default async function (call: ApiCall<ReqGetList, ResGetList>) { export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let arr: ResGetList['list'] = []; let arr: ResGetList['list'] = [];
let GHData = await GHManage.getGHList(); let GHData = await GHManage.getGHList();
let ghs = Object.values(GHData).map(item => item.data).filter(i => !!i.players); let ghs = Object.values(GHData).map(item => item.data).filter(i => !!i.players);
// let fuids = R.flatten(ghs.map(i => i.players.map(j => j.uid)))
let fuids = R.flatten(ghs.map(i => i.players.map(j => j.uid))) // let allRoles = await G.mongodb.find('user',{uid: {$in: fuids}},['uid','power'])
// let zhanlis = Object.fromEntries(allRoles.map(r => [r.uid, r.power]));
let allRoles = await G.mongodb.find('user',{uid: {$in: fuids}},['uid','power'])
let zhanlis = Object.fromEntries(allRoles.map(r => [r.uid, r.power]));
for (let gh of ghs) { for (let gh of ghs) {
let uids = gh.players.map(p => p.uid); //let uids = gh.players.map(p => p.uid);
let zhanli = uids.map(u => (zhanlis[u] || 0)).reduce((a, b) => a + b); //let zhanli = uids.map(u => (zhanlis[u] || 0)).reduce((a, b) => a + b);
let zhanli = await getGongHuiZhanli(gh._id);
arr.push({ arr.push({
gh: gh, gh: gh,
zhanli: zhanli zhanli: zhanli

View File

@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
} }
} else if (call.req.state == 'change') { } else if (call.req.state == 'change') {
if (heroPos[call.req.pos]) { if (heroPos[call.req.pos]) {
let unLoadHero = await G.redis.get('hero', call.uid, heroPos[call.req.pos]); let unLoadHero = await HeroFun.getHero(call, heroPos[call.req.pos]);
unLoadHero && fightHeros.removeOne(id => id == unLoadHero.heroId); unLoadHero && fightHeros.removeOne(id => id == unLoadHero.heroId);
} }
if (fightHeros.includes(hero.heroId.toString())) return call.errorCode(-2); if (fightHeros.includes(hero.heroId.toString())) return call.errorCode(-2);

View File

@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/hero/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['hero']> = {}; //let kvList: k_v<RedisCollections2['hero']> = {};
let arrList = await G.mongodb.collection('hero').find({ uid: call.uid }).toArray(); let arrList = await G.mongodb.collection('hero').find({ uid: call.uid }).toArray();
let heroCon = G.gc.hero; let heroCon = G.gc.hero;
@ -12,7 +12,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let maxherolv = 0; let maxherolv = 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 > maxherolv) maxherolv = v.lv; if (v.lv > maxherolv) maxherolv = v.lv;
@ -23,7 +23,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: { maxherolv: maxherolv, herocolor: color } }, { upsert: true }); { $set: { maxherolv: maxherolv, herocolor: color } }, { upsert: true });
G.redis.set('hero', call.uid, kvList); //G.redis.set('hero', call.uid, kvList);
let recLshd = await G.mongodb.collection('playerInfo', 'lshd_hero').findOne({ uid: call.conn.uid, type: 'lshd_hero' }); let recLshd = await G.mongodb.collection('playerInfo', 'lshd_hero').findOne({ uid: call.conn.uid, type: 'lshd_hero' });
let { uid, _id, type, ...heros } = (recLshd || {}); let { uid, _id, type, ...heros } = (recLshd || {});

View File

@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqJinJie, ResJinJie, ServiceType>)
let selectHeros: ResGetList['list'][''][] = []; let selectHeros: ResGetList['list'][''][] = [];
for (let _id of call.req.idArr) { for (let _id of call.req.idArr) {
let _hero = await G.redis.get('hero', call.uid, _id); let _hero = await HeroFun.getHero(call, _id);
if (!_hero) return call.error(globalThis.lng.hero_1); if (!_hero) return call.error(globalThis.lng.hero_1);
selectHeros.push(_hero); selectHeros.push(_hero);
} }

View File

@ -5,9 +5,16 @@ import {ReqYanShi, ResYanShi} from "../../shared/protocols/kuangdong/PtlYanShi";
export default async function (call: ApiCall<ReqYanShi, ResYanShi>) { export default async function (call: ApiCall<ReqYanShi, ResYanShi>) {
let hdid = call.req.hdid let hdid = call.req.hdid
let kdInfo = await KuangDongfun.getKaiCaiInfo(hdid) let con = await KuangDongfun.getCon(hdid)
if (!kdInfo) { let kdInfo
if (con.public_map == 1){
kdInfo = await KuangDongfun.getKaiCaiInfo(hdid)
}else {
kdInfo = await KuangDongfun.getKaiCaiInfo(hdid, call.uid)
}
if (!kdInfo || !con) {
return call.error('', {code: -1, message: globalThis.lng.kudangdong_1}) return call.error('', {code: -1, message: globalThis.lng.kudangdong_1})
} }
@ -30,12 +37,15 @@ export default async function (call: ApiCall<ReqYanShi, ResYanShi>) {
_need && await PlayerFun.cutNeed(call, _need); _need && await PlayerFun.cutNeed(call, _need);
kdInfo.yanshi = 8 * 3600 kdInfo.yanshi = 8 * 3600
if (!kdInfo.ctime) kdInfo.ctime = G.time
if (!kdInfo.etime) kdInfo.etime = G.time
if (!kdInfo.kdtype) kdInfo.kdtype = con.type
// 如果调用这个方法会upsert在没有查到数据的情况下 // 如果调用这个方法会upsert在没有查到数据的情况下
// 会插入空数据,全服玩家的查询列表接口都会报错 // 会插入空数据,全服玩家的查询列表接口都会报错
// await KuangDongfun.setminingZhanLing(call.uid, hdid, { $set: { yanshi: kdInfo.yanshi } }) // await KuangDongfun.setminingZhanLing(call.uid, hdid, { $set: { yanshi: kdInfo.yanshi } })
await G.mongodb.collection('kuangdong').updateOne({uid: call.uid, hdid: hdid}, await G.mongodb.collection('kuangdong').updateOne({uid: call.uid, hdid: hdid},
{$set: {yanshi: kdInfo.yanshi}}); {$set: kdInfo});
kdInfo._id = kdInfo._id.toString() kdInfo._id = kdInfo._id.toString()
let changeData = { let changeData = {

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,27 +186,29 @@ export class EmailFun {
sendEmail.lngContent = email.lngContent sendEmail.lngContent = email.lngContent
} }
if (!isCross) { //太亏了换其他清理机制getAllEmail是性能消耗大户
let emailList = await this.getAllEmail(uid); //todo.. 换其他清理机制
if (emailList.length >= 50) { // if (!isCross) {
emailList.sort((a, b) => { // let emailList = await this.getAllEmail(uid);
let noPrizeA = a.prizeData == undefined ? 0 : 1; // if (emailList.length >= 50) {
let noPrizeB = b.prizeData == undefined ? 0 : 1; // emailList.sort((a, b) => {
let getA = a.prizeData?.isGet == true ? 0 : 1; // let noPrizeA = a.prizeData == undefined ? 0 : 1;
let getB = b.prizeData?.isGet == true ? 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) { // 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

@ -17,7 +17,7 @@ export class EquipFun {
//穿戴装备时该装备穿戴在另一个英雄身上 //穿戴装备时该装备穿戴在另一个英雄身上
if (change.wearaId != undefined && equip.wearaId && equip.wearaId != change.wearaId && changeHero) { if (change.wearaId != undefined && equip.wearaId && equip.wearaId != change.wearaId && changeHero) {
let takeHero = await G.redis.get('hero', call.uid, equip.wearaId); let takeHero = await HeroFun.getHero(call, equip.wearaId);
if (takeHero) { if (takeHero) {
let _equip = Object.assign({}, takeHero.equip); let _equip = Object.assign({}, takeHero.equip);
_equip[G.gc.equip[equip.equipId].type] = ''; _equip[G.gc.equip[equip.equipId].type] = '';
@ -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,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[]): 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 data = await G.redis.get('equip', call.uid, oid); let {_id, ...info} = await G.mongodb.collection('equip').findOne({
if (!data) { _id: G.mongodb.conversionId(oid)
let {_id, ...info} = await G.mongodb.collection('equip').findOne({ })
_id: G.mongodb.conversionId(oid) let data = Object.assign({_id: _id.toHexString()}, info)
})
data = Object.assign({_id: _id.toHexString()}, info)
}
return data return data
} else { } else {
let equips = await G.mongodb.collection('equip').find({ let filter = {
uid: call.uid, 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)); 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}_pid`);
G.ioredis.del(`gudVersion:${uid}_ver`); G.ioredis.del(`gudVersion:${uid}_ver`);
} }
G.redis.del("equip",uid);
G.redis.del("hero",uid); if(await G.redis.type('tanxian', uid)){
G.redis.del("shiwu",uid); console.log('清空tanxian Redis',uid);
G.redis.del("tanxian",uid);
}
}; };
/** /**

View File

@ -24,9 +24,9 @@ export class HeroFun {
hero.zhanli = HeroShared.getHeroZhanLi(hero, call.otherBuff, Object.values(call.conn.gud.heroPos).indexOf(hero._id)); hero.zhanli = HeroShared.getHeroZhanLi(hero, call.otherBuff, Object.values(call.conn.gud.heroPos).indexOf(hero._id));
change.zhanli = hero.zhanli; change.zhanli = hero.zhanli;
for (let k in change) { // for (let k in change) {
await G.redis.set('hero', call.uid, hero._id, k as any, change[k]); // await G.redis.set('hero', call.uid, hero._id, k as any, change[k]);
} // }
await G.mongodb.collection('hero').updateOne({uid: call.uid, _id: new ObjectId(hero._id)}, { await G.mongodb.collection('hero').updateOne({uid: call.uid, _id: new ObjectId(hero._id)}, {
$set: { $set: {
@ -41,13 +41,13 @@ export class HeroFun {
/**获取英雄 */ /**获取英雄 */
static async getHero(call: call, oid: string) { static async getHero(call: call, oid: string) {
let data = await G.redis.get('hero', call.uid, oid); //let data = await G.redis.get('hero', call.uid, oid);
if (!data) { // 如果redis中的hero数据被清理掉 直接查询数据库 //if (!data) { // 如果redis中的hero数据被清理掉 直接查询数据库
let {_id, ...info} = await G.mongodb.collection("hero").findOne({ let {_id, ...info} = await G.mongodb.collection("hero").findOne({
_id: G.mongodb.conversionId(oid) _id: G.mongodb.conversionId(oid)
}) })
data = Object.assign({_id: _id.toHexString()}, info) let data = Object.assign({_id: _id.toHexString()}, info)
} //}
return data return data
} }

View File

@ -478,9 +478,10 @@ 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({uid: uid}).toArray() || []; let logs = await G.mongodb.collection('dayPay').find({
uid: uid,
logs = logs.filter(log => log.time >= sTime && log.time < eTime); time: {$gte: sTime, $lt: 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

@ -350,10 +350,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);
@ -432,12 +432,12 @@ export class PlayerFun {
//hero/apiGetList里会G.redis.set('hero', call.uid, kvList); //hero/apiGetList里会G.redis.set('hero', call.uid, kvList);
//在这之后再执行下面的代码则不会报错 //在这之后再执行下面的代码则不会报错
if (await G.redis.type('hero', call.uid) != null) { // if (await G.redis.type('hero', call.uid) != null) {
G.redis.set('hero', call.uid, id, { // G.redis.set('hero', call.uid, id, {
_id: id, // _id: id,
...ops // ...ops
}); // });
} // }
call.addEventMsg('msg_s2c/HeroChange', id, { call.addEventMsg('msg_s2c/HeroChange', id, {

View File

@ -38,7 +38,7 @@ export class ShiwuFun {
//穿戴饰物时该装备穿戴在另一个英雄身上 //穿戴饰物时该装备穿戴在另一个英雄身上
if (change.wearId != undefined && shiwu.wearId && shiwu.wearId != change.wearId && changeHero) { if (change.wearId != undefined && shiwu.wearId && shiwu.wearId != change.wearId && changeHero) {
let takeHero = await G.redis.get('hero', call.uid, shiwu.wearId); let takeHero = await HeroFun.getHero(call, shiwu.wearId);
if (takeHero) { if (takeHero) {
let _shiwu = Object.assign({}, takeHero.shiwu); let _shiwu = Object.assign({}, takeHero.shiwu);
let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0]; let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0];
@ -55,7 +55,7 @@ export class ShiwuFun {
//属性发生变化并且穿戴在英雄身上时 //属性发生变化并且穿戴在英雄身上时
if (change.wearId == undefined && shiwu.wearId) { if (change.wearId == undefined && shiwu.wearId) {
let takeHero = await G.redis.get('hero', call.uid, shiwu.wearId); let takeHero = await HeroFun.getHero(call, shiwu.wearId);
if (takeHero) { if (takeHero) {
let _shiwu = Object.assign({}, takeHero.shiwu); let _shiwu = Object.assign({}, takeHero.shiwu);
let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0]; let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0];

View File

@ -2,6 +2,7 @@ import {
Collection, Collection,
CreateIndexesOptions, CreateIndexesOptions,
Db, Db,
FindCursor,
IndexDescription, IndexDescription,
IndexSpecification, IndexSpecification,
MongoClient, MongoClient,
@ -18,6 +19,7 @@ import {HuoDongFun} from './public/huodongfun';
import {zbsGroup} from './api_s2c/hbzb/zbs/fun'; import {zbsGroup} from './api_s2c/hbzb/zbs/fun';
import {clusterRunOnce} from './clusterUtils'; import {clusterRunOnce} from './clusterUtils';
import { PublicShared } from './shared/public/public'; import { PublicShared } from './shared/public/public';
import { addGameLog } from './gameLog';
const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = { const indexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] }> = {
item: [ item: [
@ -626,4 +628,27 @@ export class _mongodb {
indexInformation(name) { indexInformation(name) {
return this.db.indexInformation(name) return this.db.indexInformation(name)
} }
}
//@ts-ignore
FindCursor.prototype._toArray = FindCursor.prototype.toArray;
//@ts-ignore
FindCursor.prototype.toArray = async function(){
let rss = await this._toArray();
//如果返回的数据超过50条
if(rss.length>50){
addGameLog("system","findCount",null,{
collection: this.namespace.collection,
db:this.namespace.db,
count:rss.length
})
console.log("system,findCount",{
collection: this.namespace.collection,
db:this.namespace.db,
count:rss.length
})
console.trace();
}
return rss;
} }

View File

@ -60,10 +60,9 @@ 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,9 +74,9 @@ async function clearRedis() {
G.redis.fromatKey('jjc'), G.redis.fromatKey('jjc'),
G.redis.fromatKey('user'), G.redis.fromatKey('user'),
G.redis.fromatKey('item'), G.redis.fromatKey('item'),
//G.redis.fromatKey('equip'), G.redis.fromatKey('hero'),
//G.redis.fromatKey('hero'), G.redis.fromatKey('equip'),
//G.redis.fromatKey('shiwu'), 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,6 +23,7 @@ export class HeroShared {
return allBuff; return allBuff;
} }
/** /**
* *
* @param hero * @param hero
@ -30,7 +31,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];
@ -39,7 +40,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}`)());
} }
@ -126,7 +127,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;
} }
@ -172,7 +173,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);
} }
} }
@ -260,7 +261,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})])));
} }
} }
} }
@ -286,6 +287,7 @@ 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) {
@ -294,6 +296,7 @@ export class HeroShared {
buff[k] = Math.floor(buff[k]); buff[k] = Math.floor(buff[k]);
} }
} }
/** /**
* *
* @param hero * @param hero
@ -303,6 +306,7 @@ 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);
} }
/** /**
* *
*/ */
@ -313,6 +317,7 @@ 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;
@ -329,11 +334,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 * 1) + ((mindps + maxdps) / 2 * xixuepro) +
((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) +
@ -341,6 +346,7 @@ export class HeroShared {
(hp * pvpdpsdrop * .5) (hp * pvpdpsdrop * .5)
); );
} }
/** /**
* *
* @param id id * @param id id
@ -349,10 +355,11 @@ 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