Merge branch 'bugfix' into release

This commit is contained in:
dy 2023-12-21 13:25:04 +08:00
commit ba978c827a
9 changed files with 1227 additions and 41 deletions

View File

@ -11,4 +11,6 @@ WORKDIR /app
RUN npm config set registry http://registry.npm.taobao.org/ && npm install pm2@5.2.2 -g
RUN rm -rf node_modules/tsbuffer-validator/index.js && cp tsbufferIndex.js node_modules/tsbuffer-validator/index.js
CMD cd /app && sh zoeninfo.sh "Asia/Tokyo" && pm2-runtime start js_pm2.config.js -- ${Param}

View File

@ -6,9 +6,9 @@
"private": true,
"scripts": {
"dev": "tsrpc-cli dev",
"build": "tsrpc-cli build && copy js_pm2.config.js dist && copy zoeninfo.sh dist && mkdir dist\\json && xcopy src\\json dist\\json /e ",
"build_win": "tsrpc-cli build && copy js_pm2.config.js dist && copy zoeninfo.sh dist && mkdir dist\\json && xcopy src\\json dist\\json /e ",
"build_linux": "tsrpc-cli build && cp js_pm2.config.js dist && cp zoeninfo.sh dist && cp src/json/ -a dist ",
"build": "tsrpc-cli build && copy js_pm2.config.js dist && copy zoeninfo.sh dist && copy tsbufferIndex.js dist && mkdir dist\\json && xcopy src\\json dist\\json /e ",
"build_win": "tsrpc-cli build && copy js_pm2.config.js dist && copy zoeninfo.sh dist && copy tsbufferIndex.js dist && mkdir dist\\json && xcopy src\\json dist\\json /e ",
"build_linux": "tsrpc-cli build && cp js_pm2.config.js dist && cp zoeninfo.sh dist && cp tsbufferIndex.js dist && cp src/json/ -a dist ",
"build_docker_win": "npm run build_win && cd dist && npm i --omit=dev",
"build_docker_linux": "npm run build_linux && cd dist && npm i --omit=dev",
"doc": "tsrpc-cli doc && node js_uploadDoc.js",

View File

@ -50,19 +50,44 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
call.succ(db as any);
}
export async function refreshEnemys(call: ApiCall) {
let section = [call.conn.gud.mapId - 8, call.conn.gud.mapId + 8];
//let allUser = Object.values(await G.redis.get('user')).filter(u => u.mapId >= section[0] && u.mapId <= section[1] && u.uid != call.uid);
//let dbUser = await G.mongodb.collection('wanted').find({uid: {$in: allUser.map(u => u.uid)}}).toArray();
let lastRefreshTime: number
let enemyObject: object = {}
let allUser = await G.mongodb.find('user', {
$and: [
{mapId: {$gte: section[0]}},
{mapId: {$lte: section[1]}},
{uid: {$ne: call.uid}}
]
}, ['uid']);
let dbUser = await G.mongodb.find('wanted', {uid: {$in: allUser.map(u => u.uid)}}, ['uid', 'wanted']);
/**
* 30308080100
*/
async function checkAndRefreshEnemy() {
if (lastRefreshTime + 3600 > G.time) return
lastRefreshTime = G.time
for (let i = 3; i <= 8; i++) {
let users = await G.mongodb.collection('user').aggregate([
{
$match: {
$and: [
{lv: {$gte: i * 10}},
{lv: {$lt: i == 8 ? 101 : (i + 1) * 10}},
]
}
},
{
$project: {uid: 1}
},
{
$sample: {size: 100}
}
]).toArray()
let dbUser = await G.mongodb.find('wanted', {uid: {$in: users.map(u => u.uid)}}, ['uid', 'wanted']);
enemyObject[i] = dbUser || []
}
}
export async function refreshEnemys(call: ApiCall) {
if (!lastRefreshTime) await checkAndRefreshEnemy()
let lvDw = Math.floor(call.conn.gud.lv / 10 > 8 ? 8 : call.conn.gud.lv / 10)
let dbUser = enemyObject[lvDw] || []
let enemys: joinFightData[] = [];
@ -74,7 +99,6 @@ export async function refreshEnemys(call: ApiCall) {
let filter = dbUser.filter(u => conf.need <= u.wanted && u.wanted < needMax);
let uids = filter.map(f => f.uid);
dbUser.remove(u => uids.includes(u.uid));
let a = configs[0].npc.random()
let enemy = uids.length > 0 ? await FightFun.getPlayerFightData(uids.random()) : formatNpcData(configs[0].npc.random());
if (!enemy) enemy = formatNpcData(configs[0].npc.random())
if (enemy.player.isNpc) enemy.player.name = G.gc.gonglukuangbiao.npcname.random()
@ -83,7 +107,7 @@ export async function refreshEnemys(call: ApiCall) {
PublicShared.randomNum(G.gc.gonglukuangbiao.wanted[0].wanted[0], G.gc.gonglukuangbiao.wanted[0].wanted[1])
enemys.push(enemy);
}
checkAndRefreshEnemy()
return enemys.reverse();
}

View File

@ -2,13 +2,14 @@ import {RedisClientType, createClient} from "redis";
import {redisClient} from "./setRedis";
import {ConnectionStatus, WsServer} from "tsrpc";
import cluster from 'cluster';
import { clusterFun } from "./clusterFunction";
import {clusterFun} from "./clusterFunction";
//维护当前uid和pid的对应关系
let uid2processId = {};
//订阅redis
let subscribeRedis: RedisClientType
let firstPid = null;
//发布和可写redis复用原 setRedis 里的redisClient
@ -20,10 +21,10 @@ let firstPid = null;
*/
export function clusterSubscribe(key: string, callback: Function) {
subscribeRedis.subscribe(G.redis.fromatKey(key), function (msg) {
try{
try {
callback(msg);
}catch(e){
console.error("clusterSubscribe error",e);
} catch (e) {
console.error("clusterSubscribe error", e);
}
});
}
@ -43,14 +44,19 @@ export function clusterPublish(key: string, data: any) {
* N个进程中使
*/
export function clusterRunOnce(fun) {
console.log(`${process.pid}环境变量pm_id===>${process.env.pm_id}`);
if (process.env.pm_id == null || process.env.pm_id === '0') {
//非pm2启动的或是pm2下启动的第一个进程
console.log("run clusterRunOnce1 ===>", process.pid)
fun();
return;
}
if(firstPid == process.pid){
if(G.config.isG123)return;
if (firstPid == process.pid) {
//pm2的其中一个进程
console.log("run clusterRunOnce2 ===>", process.pid)
fun();
return;
}
@ -60,16 +66,16 @@ export function clusterRunOnce(fun) {
*
* uid所在的进程执行fun方法uid不在任何进程的话
*/
export function clusterFunctionRunAtUidProcess(uid:string, fun:string, ...arg:any[]) {
if(!uid2processId[uid] || uid2processId[uid] == process.pid){
clusterFun[ fun ].call(this, ...arg);
export function clusterFunctionRunAtUidProcess(uid: string, fun: string, ...arg: any[]) {
if (!uid2processId[uid] || uid2processId[uid] == process.pid) {
clusterFun[fun].call(this, ...arg);
return;
}
clusterPublish("RunclusterFunction", JSON.stringify({
"uid": uid,
"fun": fun,
"arg" : arg
"arg": arg
}))
}
@ -159,17 +165,17 @@ async function initSubscribeRedis() {
clusterSubscribe('broadcastClusterMsg', function (msg) {
let data = JSON.parse(msg);
if(!data.filter){
if (!data.filter) {
//如果不是有条件发送的话
G.server.broadcastMsg(data.msgName, data.msg);
}else {
} else {
//但是如果是有条件发送的话
//条件里可能需要进程内的信息,则需要每个进程都分别筛选后执行
if (data.filter.ghId != null) {
//指定公会
let conns = G.server.connections;
conns = conns.filter(c => c?.gud?.ghId == data.filter.ghId);
conns.length>0 && G.server.broadcastMsg(data.msgName, data.msg, conns);
conns.length > 0 && G.server.broadcastMsg(data.msgName, data.msg, conns);
}
}
});
@ -178,7 +184,7 @@ async function initSubscribeRedis() {
clusterSubscribe('RunclusterFunction', function (msg) {
let data = JSON.parse(msg);
if (uid2processId[data.uid] == process.pid) {
clusterFun[ data.fun ].call(this, ...data.arg);
clusterFun[data.fun].call(this, ...data.arg);
}
});
}
@ -194,7 +200,7 @@ export async function clusterMain() {
//初始化订阅redis
await initSubscribeRedis();
if(process.env.pm_id != null){
if (process.env.pm_id != null) {
//pm2启动的设置key为我的pid
firstPid = await redisClient.get(G.redis.fromatKey("firstPid"));
if (!firstPid) {

View File

@ -22,12 +22,15 @@ export class CrossEmailPull extends Scheduler {
G.clientCross.callApi("email/GetCrossEmail", {server_id: G.config.serverId + ""}).then((res) => {
if (!res.isSucc) return;
res.res.emails.forEach(async (email) => {
let _prize = email?.prizeData?.prize || [];
if (email?.prizeData) delete email.prizeData;
email["prize"] = _prize;
if (email.uid != "system") {
await EmailFun.addEmail(email)
} else {
await EmailFun.addQuanFuEmail(email)
}
await EmailFun.addEmail(email)
})
if (res.res.emails.length > 0) {
G.clientCross.callApi("email/DelCrossEmail", {eids: res.res.emails.map(e => e._id)})

View File

@ -788,7 +788,7 @@ export class TaskAllEmitFun {
let _val = node.call.req.num;
G.emit("Class_task_136", 'Class_task_136', node.call, _val, 0);
// todo 统计藏品修复胶此处只是临时处理防止线上任务数据出错正确做法是统计修复胶的消耗走136任务的统计
G.emit("Class_task_134", 'Class_task_134', node.call, _val, 0, {});
G.emit("Class_task_134", 'Class_task_134', node.call, _val, 0, []);
}
if (node.call.service.name == 'peijian/LvUp' && node.return.isSucc) {

View File

@ -390,7 +390,10 @@ export module manager {
async initVal(call: ApiCall, con) {
const data = await TanXianFun.getData(call);
return data.useFastGuaJiNum || 0
if (data?.resetTime > PublicShared.getToDayZeroTime()) {
return data.useFastGuaJiNum || 0
}
return 0
}
}
@ -401,7 +404,10 @@ export module manager {
async initVal(call: ApiCall, con) {
let data = await JJCFun.getData(call);
return data?.useFightNum || 0
if (data?.resetTime >= PublicShared.getToDayZeroTime()) {
return data?.useFightNum || 0
}
return 0
}
}
@ -418,7 +424,10 @@ export module manager {
async initVal(call: ApiCall, con) {
let myData = await G.mongodb.cPlayerInfo('meirishilian').findOne({uid: call.uid, type: 'meirishilian'});
return R.compose(R.sum(), R.map(i => i[0].useFightNum), R.values())(myData.data.numInfo) || 0
if (myData.data.refreshTime > PublicShared.getToDayZeroTime()) {
return R.compose(R.sum(), R.map(i => i[0].useFightNum), R.values())(myData.data.numInfo) || 0
}
return 0
}
}
@ -435,7 +444,10 @@ export module manager {
async initVal(call: ApiCall, con) {
let myData = await G.mongodb.cPlayerInfo('qjzzd').findOne({uid: call.uid, type: 'qjzzd'});
return myData.useFightNum || 0
if (myData?.refreFightTime > PublicShared.getToDayZeroTime()) {
return myData?.useFightNum || 0
}
return 0
}
}
@ -491,7 +503,10 @@ export module manager {
async initVal(call: ApiCall, con) {
let data: Partial<CollectionWanted> = await G.mongodb.collection('wanted').findOne({uid: call.uid}) || {};
return data.toDayUseNum || 0
if (data.refreshTime > PublicShared.getToDayZeroTime()) {
return data.toDayUseNum || 0
}
return 0
}
}
@ -766,6 +781,7 @@ export module manager {
return call.conn.gud?.helpHeros?.length || 0;
}
}
// 第56个任务 完成圣诞活动小游戏
export class Class_task_154 extends BaseClass {
stype = 154
@ -775,6 +791,7 @@ export module manager {
return 1;
}
}
// 第57个任务 领取每日任务最终宝箱
export class Class_task_155 extends BaseClass {
stype = 155

View File

@ -182,6 +182,18 @@ export function getBuffDPS(toRole: FightObj, fromRole: FightObj, extData: { xiao
// todo 主角技能还没有限制百分比的最大伤害以下判断修复技能buff没有伤害
if (fromRole.getData('pos') != 7){
dps = dps > maxDps ? maxDps : dps;
} else {
// 主角技能伤害最大值: avg(所有上场干部的maxDps) * 2
let sumHeroMaxDps = 0, heroCount = 0;
const fromRoleSide = fromRole.getData('side');
fromRole.fightControl.fightRolesArr.forEach(role => {
if (role.getData('pos') < 7 && role.getData('side') === fromRoleSide) {
sumHeroMaxDps += role.getData('maxdps');
heroCount++;
}
});
maxDps = sumHeroMaxDps / heroCount * 2;
dps = dps > maxDps ? maxDps : dps;
}
return { num: -dps, dps: -dps, miss: miss, baoji: baoji, fromRole: fromRole, toRole: toRole };

1122
tsbufferIndex.js Normal file

File diff suppressed because it is too large Load Diff