This commit is contained in:
ciniao 2024-01-10 11:35:16 +08:00
commit 4c37d4c846
325 changed files with 89786 additions and 18681 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
/node_modules
/.idea
/.vscode
/dist
/doc

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"ms-ceintl.vscode-language-pack-zh-hans"
]
}

50
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,50 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "消息服",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}/src/index.ts",
"-serverType",
"msg",
"-logModel",
"debug"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register"
],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "跨服",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}/src/index.ts",
"-serverType",
"cross",
"-logModel",
"debug"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register"
],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"editor.suggest.snippetsPreventQuickSuggestions": false,
"aiXcoder.showTrayIcon": true
}

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

@ -35,7 +35,7 @@ function dockerLogin() {
const region = 'ap-northeast-1';
const instanceId = 'cri-fe5eqsg73zl4vd4m';
const version = '2018-12-01';
const command = `aliyun cr GetAuthorizationToken --profile dev --region ${region} --InstanceId ${instanceId} --version ${version} --force`;
const command = `aliyun cr GetAuthorizationToken --profile heijiao-dev --region ${region} --InstanceId ${instanceId} --version ${version} --force`;
const output = execSync(command, { encoding: 'utf8' });
const result = JSON.parse(output);
const password = result.AuthorizationToken.replace(/"/g, '');

View File

@ -35,7 +35,7 @@ function dockerLogin() {
const region = 'ap-northeast-1';
const instanceId = 'cri-azy285s79zw3ti5v';
const version = '2018-12-01';
const command = `aliyun cr GetAuthorizationToken --profile prod --region ${region} --InstanceId ${instanceId} --version ${version} --force`;
const command = `aliyun cr GetAuthorizationToken --profile heijiao-prod --region ${region} --InstanceId ${instanceId} --version ${version} --force`;
const output = execSync(command, { encoding: 'utf8' });
const result = JSON.parse(output);
const password = result.AuthorizationToken.replace(/"/g, '');

View File

@ -60,6 +60,8 @@ const localApps = [
instances: instancesNum,
// 传递给脚本的参数
args: '-serverType msg',
//允许强制gc
node_args: '--expose-gc',
// 是否启用监控模式默认是false。如果设置成true当应用程序变动时pm2会自动重载。这里也可以设置你要监控的文件。
watch: false,
// 不用监听的文件
@ -86,6 +88,8 @@ const crossApps = [
cwd: './',
// 传递给脚本的参数
args: '-serverType cross',
//允许强制gc
node_args: '--expose-gc',
// 是否启用监控模式默认是false。如果设置成true当应用程序变动时pm2会自动重载。这里也可以设置你要监控的文件。
watch: false,
// 不用监听的文件

5920
package-lock.json generated

File diff suppressed because it is too large Load Diff

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",
@ -37,15 +37,17 @@
"axios": "^1.4.0",
"crypto-js": "^4.1.1",
"express": "^4.18.2",
"inspector-api": "^1.4.8",
"ioredis": "^5.3.2",
"json5": "^2.2.3",
"mathjs": "^11.4.0",
"mongodb": "^4.17.1",
"node-gyp": "^10.0.1",
"ramda": "^0.29.1",
"redis": "^4.3.1",
"shelljs": "^0.8.5",
"sync-request": "^6.1.0",
"tsrpc": "^3.4.12",
"tsrpc": "^3.4.14",
"xlsx": "^0.18.5"
}
}

View File

@ -1,16 +1,49 @@
import { ApiCall } from "tsrpc";
import { ReqFindEnemy, ResFindEnemy } from "../../cross/protocols/clsl/PtlFindEnemy";
import { formatNpcData } from '../../shared/fightControl/fightFun';
import { PublicShared } from "../../shared/public/public";
export default async function (call: ApiCall<ReqFindEnemy, ResFindEnemy>) {
let my = await G.mongodb.collection('clslCrossUser').findOne({ uid: call.req.uid });
let starConf = getStarConf(my.allStar);
let others = await G.mongodb.collection('clslCrossUser').find({ uid: { $nin: [call.req.uid] } }).toArray();
let enemy = others.random();
let p = PublicShared.randomNum(1, 1000);
let starConf = getStarConf(call.req.myStasr);
let enemy: { allStar: number, info: any };
// 本次随机到npc概率判断
if (p <= starConf.pro * 1000) {
enemy = {
allStar: call.req.myStasr,
info: formatNpcData(starConf.npc)
}
} else {
// 在自定范围内随机一个对手
let others = await G.mongodb.collection("clslCrossUser").aggregate([
{
$match: {
allStar: { $gte: starConf.fighter[0], $lte: starConf.fighter[1] }
}
}, {
$sample: { size: 1 }
}
]).toArray();
if (others.length <= 0) {
enemy = {
allStar: call.req.myStasr,
info: formatNpcData(starConf.npc)
}
} else {
enemy = {
allStar: others[0].allStar,
info: others[0].info,
}
}
}
call.succ({
allStar: enemy?.allStar || my.allStar,
info: enemy?.info || formatNpcData(starConf.npc)
allStar: enemy.allStar,
info: enemy.info || formatNpcData(starConf.npc)
});
}

View File

@ -4,7 +4,7 @@ import { FightFun } from '../../public/fight';
export default async function (call: ApiCall<ReqLog, ResLog>) {
if (call.req.result) {
// FightFun.saveLog(call.req.uid, 'clsl', call.req.result);
FightFun.saveLog(call.req.uid, 'clsl', call.req.result);
call.succ({});
} else {
call.succ({

View File

@ -1,10 +1,37 @@
import { ApiCall } from "tsrpc";
import { ReqRank, ResRank } from "../../cross/protocols/clsl/PtlRank";
import { Rank } from '../../public/rank/rank';
import { PublicShared } from "../../shared/public/public";
import { RankClslCross } from "../../public/rank/rank_clsl";
export default async function (call: ApiCall<ReqRank, ResRank>) {
let group_time = G.gc.clsl_com.divideTime;
let week_zero_time = PublicShared.getToWeekMondayZeroTime();
if (G.time < week_zero_time + group_time) {
call.succ({ rankList: [], myRank: { rank: -1, player: {}, valArr: [] } })
return
}
let a = await G.mongodb.collection('clslCrossUser').findOne({
uid: call.req.uid
});
if (!a || !a.group){
call.succ({ rankList: [], myRank: { rank: -1, player: {}, valArr: [] } })
return
}
let rank: Rank;
if (Rank.list[`clslCross_${a.group}`]) {
rank = Rank.list[`clslCross_${a.group}`]
}
else {
rank = new RankClslCross(a.group)
}
let page = call.req.page || 0
let offset = call.req.offset || -1 // 预防未查询到的调用,按原逻辑查询全部,避免引起未知问题
let {min, max} = Rank.pageToMin(page, offset)
call.succ(await Rank.list.clslCross.getRankList(call.req.gud.uid, { min, max }));
let { min, max } = Rank.pageToMin(page, offset)
call.succ(await rank.getRankList(call.req.uid, { min, max }));
}

View File

@ -1,9 +0,0 @@
import { ApiCall } from "tsrpc";
import { ReqRankUids, ResRankUids } from "../../cross/protocols/clsl/PtlRankUids";
import { Rank } from '../../public/rank/rank';
export default async function (call: ApiCall<ReqRankUids, ResRankUids>) {
// 返回排名的uids, 应用场景是定时器发送奖励,不分页。
let uids = await Rank.list.clslCross.getRankListIdKeyAll()
call.succ({uids});
}

View File

@ -1,23 +1,49 @@
import { ApiCall } from "tsrpc";
import { ReqUpLoad, ResUpLoad } from "../../cross/protocols/clsl/PtlUpLoad";
import { Rank } from '../../public/rank/rank';
import { PublicShared } from "../../shared/public/public";
import { RankClslCross } from "../../public/rank/rank_clsl";
export default async function (call: ApiCall<ReqUpLoad, ResUpLoad>) {
let { allStar, uid, ...ops } = call.req;
let a = await G.mongodb.collection('clslCrossUser').findOneAndUpdate(
let a = (await G.mongodb.collection('clslCrossUser').findOneAndUpdate(
{ uid: uid },
{
$inc: { allStar: allStar || 0 },
$set: ops
},
{ upsert: true }
);
{ upsert: true, returnDocument: "after" }
)).value;
// 周四 并且没有分组 更新玩家分组
if ((PublicShared.getWeek(G.time) || 7) >= 4 && !a.group) {
// 查询分组数据
let week = PublicShared.getToWeek();
let group = await G.mongodb.collection('clslCrossGroup').findOne({ week: week });
for (let groupid in group.groups) {
let groupinfo = group.groups[groupid];
if (a.info.player.cTime >= groupinfo.st && a.info.player.cTime < groupinfo.et) {
a.group = groupid;
G.mongodb.collection('clslCrossUser').updateOne({ uid: uid }, { $set: { group: a.group } });
break;
}
}
}
if (allStar != undefined && ops.info) {
Rank.list.clslCross.addNew({
player: a.value.info.player,
valArr: [(await G.mongodb.collection('clslCrossUser').findOne({ uid: uid })).allStar]
});
if (a.group) { // 分完组之后就可以更新排行榜了
if (allStar != undefined && ops.info) {
let rank;
if (Rank.list[`clslCross_${a.group}`]) {
rank = Rank.list[`clslCross_${a.group}`]
}
else {
rank = new RankClslCross(a.group)
}
rank.addNew({
player: a.info.player,
valArr: [a.allStar, a.info.player.power]
});
}
}
}

View File

@ -5,7 +5,7 @@ export default async function (call: ApiCall<ReqDelCrossEmail, ResDelCrossEmail>
let eids = call.req.eids;
G.mongodb.collection("email").updateMany({
_id: {$in: eids.map((i) => G.mongodb.conversionId(i))}
}, {isdel: true})
}, {$set: {isdel: true}})
call.succ({result:true})
}

View File

@ -1,18 +1,23 @@
import { ApiCall } from "tsrpc";
import { ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser } from "../../cross/protocols/hbzb/PtlUpdateHbzbCrossUser";
import {ApiCall} from "tsrpc";
import {ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser} from "../../cross/protocols/hbzb/PtlUpdateHbzbCrossUser";
/**更新跨服数据库里,黑帮争霸的玩家数据 */
export default async function (call: ApiCall<ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser>) {
let setData = {
"data":{
let setData: any = {
"data": {
player: call.req.user.player,
roles: call.req.user.roles,
uid: call.req.uid
},
"jifen": -999999,
"rank": -999999,
"zbsgroup":""
};
G.mongodb.collection('hbzb_user_cross').updateOne({ uid: setData.data.uid }, { $set: setData }, { upsert: true });
call.succ({ });
if (call.req.isNew) {
setData = {
...setData,
"jifen": -999999,
"rank": -999999,
"zbsgroup": ""
}
}
G.mongodb.collection('hbzb_user_cross').updateOne({uid: setData.data.uid}, {$set: setData}, {upsert: true});
call.succ({});
}

View File

@ -47,7 +47,8 @@ export default async function (call: ApiCall<ReqGetEnemy, ResGetEnemy>) {
$and: [
{"data.player.power": {$gte: r[0]}},
{"data.player.power": {$lte: r[1]}},
{uid: {$nin: blackUids}}
{uid: {$nin: blackUids}},
{"data.player.sid":user.data.player.sid}
]
}
},

View File

@ -1,39 +1,38 @@
import { ApiCall } from "tsrpc";
import { ReqRank, ResRank } from "../../cross/protocols/wzry/PtlRank";
import { ChatFun } from "../../public/chat";
import { EmailFun } from "../../public/email";
import { FightFun } from "../../public/fight";
import { Rank } from '../../public/rank/rank';
import { SchedulerWzryDlDstart, wzrygroup } from "../../public/scheduler/scheduler_wzry";
import { WangZheRongYaofun } from "../../public/wzry";
import { PublicShared } from "../../shared/public/public";
import { player } from "../../shared/protocols/user/type";
import { rankInfo } from "../../shared/protocols/type";
import { FindOptions } from "mongodb";
import {ApiCall} from "tsrpc";
import {ReqRank, ResRank} from "../../cross/protocols/wzry/PtlRank";
import {player} from "../../shared/protocols/user/type";
import {Filter, FindOptions, OptionalId} from "mongodb";
import { CollectionRankList } from "../../module/collection_rank";
export async function getRankList(limit?: number, projection?:any){
let option : FindOptions = {
sort : {
'data.valArr': -1
export async function getRankList(limit?: number, projection?: any, _where?:any) {
let option: FindOptions = {
sort: {
'data.valArr': -1,
'data.player.power': -1
}
}
if(limit!=null){
let filter:Filter<OptionalId<CollectionRankList>> = {type: 'wzryCross'};
if (limit != null) {
option.limit = limit;
}
if(projection!=null){
if (projection != null) {
option.projection = projection;
}
if (_where != null) {
Object.assign(filter, _where);
}
let listArr = await G.mongodb.collection('rankList').find({ type: 'wzryCross' },option).toArray();
let listArr = await G.mongodb.collection('rankList').find(filter, option).toArray();
let list = listArr.map(l => l.data);
return list;
}
export async function getPlayerRank(uid: string) {
let _r = await getRankList(50,{
"data.player.uid":1,
"data.valArr":1,
let _r = await getRankList(50, {
"data.player.uid": 1,
"data.valArr": 1,
});
if (!Object.keys(_r).length) {
return -1
@ -42,14 +41,14 @@ export async function getPlayerRank(uid: string) {
return myrank;
}
export async function getWzryRankList(uid: string, gud: player){
export async function getWzryRankList(uid: string, gud: player) {
let list = await getRankList(50);
return {
rankList: list,
myRank: {
rank: list.findIndex(li => li.player.uid == uid) + 1 || -1,
player: gud,
valArr: [(await G.mongodb.collection('wzry_fight').findOne({ uid: uid }))?.jifen || 0]
valArr: [(await G.mongodb.collection('wzry_fight').findOne({uid: uid}))?.jifen || 0]
}
};
}

View File

@ -0,0 +1,45 @@
import { ApiCall } from "tsrpc";
import { Reqheapdump, Resheapdump } from "../../monopoly/protocols/games/Ptlheapdump";
var heapdump = require('heapdump');
import Inspector from 'inspector-api'
const inspector = new Inspector({ storage: { type: 'fs' } })
export default async function (call: ApiCall<Reqheapdump, Resheapdump>) {
if(call.req.act == "heapdump"){
let name = Date.now() + '.heapsnapshot'
heapdump.writeSnapshot(name);
call.succ({
code:200,
data:name
})
}
if(call.req.act == "gc"){
global.gc();
call.succ({
code:200,
data:"gc..."
})
}
if(call.req.act == "cpustart"){
await inspector.profiler.enable()
await inspector.profiler.start()
console.log('CPU profile has been start')
call.succ({
code:200,
data:"profiler.start"
})
}
if(call.req.act == "cpustop"){
await inspector.profiler.stop()
await inspector.profiler.disable()
console.log('CPU profile has been stop')
call.succ({
code:200,
data:"profiler.cpustop"
})
}
}

View File

@ -32,7 +32,7 @@ export default async function (call: ApiCall<Reqdetails, Resdetails>) {
let _tmp = {
ranking: index,
participantId: elementUser.uid,
value: await (await PayFun.getPayDaysAllPayNum(elementUser.uid, element.stime, element.rtime)).toString()
value: await (await PayFun.getPayDaysAllPayNum(elementUser.uid, element.stime, element.etime)).toString()
}
accountingData.push(_tmp)
}

View File

@ -24,7 +24,6 @@ export default async function (call: ApiCall<Reqdisable, Resdisable>) {
break;
}
let res = await G.mongodb.collection('user').updateOne({uid}, {$set: data});
//G.redis.set('user', uid, typeStr, value);
setGud(uid, data);
let result = res.modifiedCount > 0 ? 0 : 1;
//3. 返回结果

View File

@ -1,10 +1,10 @@
import {ApiCall} from "tsrpc";
import {HeroFun} from '../public/hero';
import {PlayerFun} from '../public/player';
import {defaultUserAppend, UserFun} from '../public/user';
import {ReqBingo, ResBingo} from "../shared/protocols/PtlBingo";
import {ReqEmail} from "../monopoly/protocols/PtlEmail";
import {EmailFun} from "../public/email";
import { ApiCall } from "tsrpc";
import { HeroFun } from '../public/hero';
import { PlayerFun } from '../public/player';
import { defaultUserAppend, UserFun } from '../public/user';
import { ReqBingo, ResBingo } from "../shared/protocols/PtlBingo";
import { ReqEmail } from "../monopoly/protocols/PtlEmail";
import { EmailFun } from "../public/email";
export default async function (call: ApiCall<ReqBingo, ResBingo>) {
// TODO
@ -72,37 +72,37 @@ export default async function (call: ApiCall<ReqBingo, ResBingo>) {
if (!G.gc.item[shell[1]]) return call.error(`道具id不存在${shell[1]}`);
if (isNaN(parseInt(shell[2]))) return call.error(`请输入正确的数量`);
await PlayerFun.addItem(call, [{a: 'item', t: shell[1], n: parseInt(shell[2])}]);
await PlayerFun.addItem(call, [{ a: 'item', t: shell[1], n: parseInt(shell[2]) }]);
} else if (shell[0] == 'hero') {
if (!G.gc.hero[shell[1]]) return call.error(`英雄id不存在${shell[1]}`);
if (isNaN(parseInt(shell[2]))) return call.error(`请输入正确的数量`);
await PlayerFun.addHero(call, [{a: 'item', t: shell[1], n: parseInt(shell[2])}]);
await PlayerFun.addHero(call, [{ a: 'item', t: shell[1], n: parseInt(shell[2]) }]);
} else if (shell[0] == 'equip') {
if (!G.gc.equip[shell[1]]) return call.error(`装备id不存在${shell[1]}`);
if (isNaN(parseInt(shell[2]))) return call.error(`请输入正确的数量`);
await PlayerFun.addEquip(call, [{a: 'equip', t: shell[1], n: parseInt(shell[2])}]);
await PlayerFun.addEquip(call, [{ a: 'equip', t: shell[1], n: parseInt(shell[2]) }]);
} else if (shell[0] == 'shiwu') {
if (!G.gc.shiwu[shell[1]]) return call.error(`饰物id不存在${shell[1]}`);
if (isNaN(parseInt(shell[2]))) return call.error(`请输入正确的数量`);
if (isNaN(parseInt(shell[3]))) return call.error(`请输入正确的品质`);
await PlayerFun.addShiwu(call, [{a: 'shiwu', t: shell[1], n: parseInt(shell[2]), colour: parseInt(shell[3])}]);
await PlayerFun.addShiwu(call, [{ a: 'shiwu', t: shell[1], n: parseInt(shell[2]), colour: parseInt(shell[3]) }]);
} else if (shell[0] == 'peijian') {
if (!G.gc.peijian[shell[1]]) return call.error(`配件id不存在${shell[1]}`);
if (isNaN(parseInt(shell[2]))) return call.error(`请输入正确的数量`);
await PlayerFun.addPeijian(call, [{a: 'peijian', t: shell[1], n: parseInt(shell[2])}]);
await PlayerFun.addPeijian(call, [{ a: 'peijian', t: shell[1], n: parseInt(shell[2]) }]);
} else if (shell[0] == 'attr') {
if (G.gc.attr[shell[1]] == undefined) return call.error(`道具id不存在${shell[1]}`);
if (isNaN(parseInt(shell[2]))) return call.error(`请输入正确的数量`);
await PlayerFun.addAttr(call, [{a: 'attr', t: shell[1], n: parseInt(shell[2])}]);
await PlayerFun.addAttr(call, [{ a: 'attr', t: shell[1], n: parseInt(shell[2]) }]);
} else if (shell.length == 2) {
@ -120,7 +120,12 @@ export default async function (call: ApiCall<ReqBingo, ResBingo>) {
}
} else if (shell[0] == 'heroMaxLv') {
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)) {
await HeroFun.changeHeroAttr(call, hero, {
lv: Object.keys(G.gc.playerLv).length * 3,
@ -136,6 +141,9 @@ export default async function (call: ApiCall<ReqBingo, ResBingo>) {
}
if (shell[3]) emailMsg.prize = JSON.parse(shell[3])
EmailFun.addEmail(emailMsg);
} else if (shell[0] == "heroskin") {
await PlayerFun.sendPrize(call, [{ a: "heroskin", "t": shell[1], n: 1 }]);
}
call.succ('succ');
}

View File

@ -1,16 +1,15 @@
import {ApiCall} from "tsrpc";
import {EventFun} from '../public/event/event';
import {PayFun} from '../public/pay';
import {ReqSyncBtn, ResSyncBtn, syncBtnKeys} from "../shared/protocols/PtlSyncBtn";
import {PublicShared} from '../shared/public/public';
import {HuoDongFun} from "../public/huodongfun";
const defaultKeys: syncBtnKeys[] = [
'huobanzhaomu', 'yibaichou', 'shouchong',
'dayjijin', 'dengjijijin', 'guanqiajijin', 'tianshujijin',
'zhanling',
'xianshilibao',
'xianshizhaomu',
'G123Gift'
'G123Gift',
'christmas',
// 'kaifukuanghuan',
// 'qiridenglu',
@ -36,6 +35,17 @@ export default async function (call: ApiCall<ReqSyncBtn, ResSyncBtn>) {
change[key] = data[key];
}
break;
case 'christmas':
//领完消失
data[key] = {active: false};
change[key] = data[key];
let _hdList = await HuoDongFun.gethdList(call, 8)
if (_hdList.length > 0) {
// 无此活动
data[key] = {active: true};
change[key] = data[key];
}
break;
case 'dayjijin':
case 'dengjijijin':
case 'guanqiajijin':
@ -52,39 +62,40 @@ export default async function (call: ApiCall<ReqSyncBtn, ResSyncBtn>) {
break;
case 'zhanling':
//30天一轮循环不管奖励。常驻活动
if (!PublicShared.getEventIsOpen(G.gc.zhanling.eventOpen, call.conn.gud)) {
data[key] = {active: false};
} else {
let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'});
if (!data[key] || data[key].round != zls.round) {
let lastRunTime = zls && zls.lastRunTime? zls.lastRunTime : G.time
let round = zls && zls.lastRunTime? zls.round : 1
data[key] = {active: true, sTime: lastRunTime, round: round};
change[key] = data[key];
// if (!PublicShared.getEventIsOpen(G.gc.zhanling.eventOpen, call.conn.gud)) {
// data[key] = {active: false};
// } else {
// let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'});
// if (!data[key] || data[key].round != (zls?.round || 0)) {
// let lastRunTime = zls && zls.lastRunTime? zls.lastRunTime : G.time
// let round = zls && zls.lastRunTime? zls.round : 1
PayFun.delPayLog(call.uid, {payId: G.gc.zhanling.payId, val: []});
// data[key] = {active: true, sTime: lastRunTime, round: round};
// change[key] = data[key];
G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'}).then(data => {
//新一轮战令 不管玩家多久没上线 只补发玩家上一轮没有领取的奖励
data && EventFun.reissueZhanLingPrize(data, call.conn.gud);
// PayFun.delPayLog(call.uid, {payId: G.gc.zhanling.payId, val: []});
G.mongodb.cEvent('zhanling').updateOne(
{uid: call.uid, type: 'zhanling'},
{
$set: {
lv: 1,
exp: 0,
rec: {},
isPay: false,
taskRec: [],
refreshTime: G.time
}
},
{upsert: true}
);
});
}
}
// G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'}).then(data => {
// //新一轮战令 不管玩家多久没上线 只补发玩家上一轮没有领取的奖励
// data && EventFun.reissueZhanLingPrize(data, call.conn.gud);
// G.mongodb.cEvent('zhanling').updateOne(
// {uid: call.uid, type: 'zhanling'},
// {
// $set: {
// lv: 1,
// exp: 0,
// rec: {},
// isPay: false,
// taskRec: [],
// refreshTime: G.time
// }
// },
// {upsert: true}
// );
// });
// }
// }
break;
case 'xianshilibao':
// 到时间消失

View File

@ -1,13 +1,13 @@
import { ApiCall, WsClientStatus } from "tsrpc";
import { ActionLog } from '../../public/actionLog/actionLog';
import { ChatFun } from '../../public/chat';
import { ChatFun, getCrossChatGroupByOpenDay } from '../../public/chat';
import { ReqSend, ResSend } from "../../shared/protocols/chat/PtlSend";
import { chatMsgLog } from "../../shared/protocols/type"
import { getGud } from "../../public/gud";
export default async function (call: ApiCall<ReqSend, ResSend>) {
let status_chat = await getGud(call.uid)['status_chat'];
let status_chat = (await getGud(call.uid))['status_chat'];
// 验证是否被禁言
if(status_chat == 1) return call.error(lng.chat_4);
let data = call.req;
@ -40,6 +40,8 @@ export default async function (call: ApiCall<ReqSend, ResSend>) {
if (sendData.type == 'cross' && G.clientCross?.status == WsClientStatus.Opened) {
//如果是跨服的话调用跨服API的这条协议
sendData.otherData.group = getCrossChatGroupByOpenDay();
G.clientCross.sendMsg('msg_cross/CrossChat', sendData);
call.succ({});
return;

View File

@ -1,43 +1,91 @@
import {ApiCall} from "tsrpc";
import {FightFun} from '../../public/fight';
import {PlayerFun} from '../../public/player';
import {ReqFind, ResFind} from "../../shared/protocols/conglinshoulie/PtlFind";
import {PublicShared} from '../../shared/public/public';
import {addStar, clslDb} from './ApiOpen';
import { ApiCall } from "tsrpc";
import { FightFun } from '../../public/fight';
import { PlayerFun } from '../../public/player';
import { ReqFind, ResFind } from "../../shared/protocols/conglinshoulie/PtlFind";
import { PublicShared } from '../../shared/public/public';
import { addStar, clslDb } from './ApiOpen';
import { EmailFun } from "../../public/email";
export default async function (call: ApiCall<ReqFind, ResFind>) {
let weekZeroTime = PublicShared.getToWeekMondayZeroTime();
if (G.time < weekZeroTime + G.gc.clsl_com.fightTime[0] || G.time > weekZeroTime + G.gc.clsl_com.fightTime[1]) return call.errorCode(-1);
let db = await clslDb().findOne({uid: call.uid, type: 'clsl'});
// 未到开启时间
if (G.time < weekZeroTime + G.gc.clsl_com.fightTime[0] || G.time > weekZeroTime + G.gc.clsl_com.fightTime[1]) {
return call.errorCode(-1)
};
// 获取自己的数据
let db = await clslDb().findOne({ uid: call.uid, type: 'clsl' });
let curStar = db?.allStar || 0;
let useNum = db?.useFightNum || 0;
let buyNum = db?.buyFightNum || 0;
let starConf = G.gc.clsl_dan[curStar] || Object.values(G.gc.clsl_dan).slice(-1)[0];
let danPrize = db?.danPrize || [];
let curMaxStar = db?.curMaxStar || 0;
if (useNum >= buyNum + G.gc.clsl_com.fightNum) return call.errorCode(-2);
let my = await call.conn.getDefaultFightData();
let other = (await G.clientCross.callApi('clsl/FindEnemy', {uid: call.uid})).res;
let result = FightFun.fight([my, other.info]);
if ((result.winSide != 0 && starConf.failCut) || result.winSide == 0) {
addStar(call, result.winSide == 0 ? 1 : -starConf.failCut, my);
// 战斗次数不足
if (useNum >= buyNum + G.gc.clsl_com.fightNum) {
return call.errorCode(-2);
}
result.initData[0].star = curStar
result.initData[1].star = other.allStar
// 自己战斗数据
let my = await call.conn.getDefaultFightData();
result.winSide == 0 && clslDb().updateOne({uid: call.uid, type: 'clsl'}, {$inc: {fightWinNum: 1}});
clslDb().updateOne({uid: call.uid, type: 'clsl'}, {$inc: {useFightNum: 1}});
// 获取一个对手
let other = (await G.clientCross.callApi('clsl/FindEnemy', { uid: call.uid, myStasr: curStar })).res;
let result = FightFun.fight([my, other.info]);
let starConf = G.gc.clsl_dan[curStar] || Object.values(G.gc.clsl_dan).slice(-1)[0];
let updata = { $inc: { useFightNum: 1 } };
// 更新战斗胜利的次数
if (result.winSide == 0) {
updata.$inc["fightWinNum"] = 1;
// 首次达到某个段位
if (curStar + 1 > curMaxStar) {
curMaxStar += 1;
updata.$inc["curMaxStar"] = 1;
}
}
// 段位奖励邮件
let title = G.gc.clsl_com.email_dan.title;
let content = G.gc.clsl_com.email_dan.content;
G.gc.clsl_com.danPrize.forEach(conf => {
// 段位未达到 或者 奖励已经发放
if (conf.star > curMaxStar || danPrize.includes(conf.star)) {
return
}
// 发放邮件
EmailFun.addEmail({
uid: call.uid,
type: 'system',
title: title,
content: content,
prize: conf.prize,
contentInsertArr:[conf.title]
})
danPrize.push(conf.star);
updata["$set"] = { danPrize: danPrize };
})
// 输了掉星 或者 赢了加星 同时更新排行数据
addStar(call, result.winSide == 0 ? 1 : -starConf.failCut, my, updata);
result.initData[0].star = curStar;
result.initData[1].star = other.allStar;
// 发送战斗奖励
await PlayerFun.sendPrize(call, starConf.fightPrize);
G.clientCross?.callApi('clsl/Log', {uid: call.uid, result: result});
G.clientCross?.callApi('clsl/Log', {uid: other.info.player.uid, result: result});
// 记录战斗日志
G.clientCross?.callApi('clsl/Log', { uid: call.uid, result: result });
G.clientCross?.callApi('clsl/Log', { uid: other.info.player.uid, result: result });
call.succ({
enemy: other,
result: result
});
call.succ({ enemy: other, result: result });
}

View File

@ -9,8 +9,8 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let db = await clslDb().findOne({ uid: call.uid, type: 'clsl' });
let { _id, uid, type, ...ops } = db || {} as WithId<OptionalId<CollectionPlayerInfo<"clsl">>>;
// 刷新 挑战次数、购买挑战次数、胜利次数任务
if (!db || ops?.refreshTime < PublicShared.getToDayZeroTime()) {
let change: Partial<typeof ops> = {
refreshTime: G.time,
useFightNum: 0,
@ -19,6 +19,13 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
buyFightNum: 0
};
// 隔周刷新星级
if (ops?.refreshTime < PublicShared.getToWeekMondayZeroTime()) {
change.allStar = 0;
change.danPrize = [];
change.curMaxStar = 0;
}
Object.assign(ops, change);
clslDb().updateOne({ uid: call.uid, type: 'clsl' }, { $set: change }, { upsert: true });
@ -29,7 +36,10 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
}
call.succ({
week: PublicShared.getWeek(G.time) || 7,
allStar: ops?.allStar || 0,
danPrize: ops?.danPrize || [],
curMaxStar: ops?.curMaxStar || 0,
buyFightNum: ops?.buyFightNum || 0,
useFightNum: ops?.useFightNum || 0,
fightWinNum: ops?.fightWinNum || 0,
@ -41,7 +51,15 @@ export function clslDb() {
return G.mongodb.cPlayerInfo('clsl');
}
export async function addStar(call: ApiCall, star: number, info?: joinFightData) {
clslDb().updateOne({ uid: call.uid, type: 'clsl' }, { $inc: { allStar: star } }, { upsert: true });
export async function addStar(call: ApiCall, star: number, info?: joinFightData, update?: any) {
update = update || {};
if (update.$inc) {
update.$inc["allStar"] = star
} else {
update["$inc"] = { allStar: star }
}
clslDb().updateOne({ uid: call.uid, type: 'clsl' }, update, { upsert: true });
G.clientCross.callApi('clsl/UpLoad', { uid: call.uid, allStar: star, info: info || await call.conn.getDefaultFightData() });
}

View File

@ -3,19 +3,56 @@ import { PlayerFun } from '../../public/player';
import { ReqRec, ResRec } from "../../shared/protocols/conglinshoulie/PtlRec";
import { HongDianChange } from "../hongdian/fun";
import { addStar, clslDb } from './ApiOpen';
import { EmailFun } from "../../public/email";
export default async function (call: ApiCall<ReqRec, ResRec>) {
let conf = G.gc.clsl_com.fightWinPrize[call.req.index];
if (!conf) return call.errorCode(-1);
let db = await clslDb().findOne({ uid: call.uid, type: 'clsl' });
let curStar = db?.allStar || 0;
let danPrize = db?.danPrize || [];
let curMaxStar = db?.curMaxStar || 0;
if ((db?.fightWinNum || 0) < conf.total || db?.recWinPrize?.includes(call.req.index)) return call.errorCode(-2);
await PlayerFun.sendPrize(call, conf.prize);
addStar(call, conf.star);
let updata = { $push: { recWinPrize: call.req.index } };
clslDb().updateOne({ uid: call.uid, type: 'clsl' }, { $push: { recWinPrize: call.req.index } });
// 首次达到某个段位
if (curStar + conf.star > curMaxStar) {
curMaxStar += conf.star;
updata["$inc"] = { "curMaxStar": conf.star };
}
// 段位奖励邮件
let title = G.gc.clsl_com.email_dan.title;
let content = G.gc.clsl_com.email_dan.content;
G.gc.clsl_com.danPrize.forEach(conf => {
// 段位未达到 或者 奖励已经发放
if (conf.star > curMaxStar || danPrize.includes(conf.star)) {
return
}
// 发放邮件
EmailFun.addEmail({
uid: call.uid,
type: 'system',
title: title,
content: content,
prize: conf.prize,
contentInsertArr:[conf.title]
})
danPrize.push(conf.star);
updata["$set"] = { danPrize: danPrize };
})
addStar(call, conf.star, undefined, updata);
// clslDb().updateOne({ uid: call.uid, type: 'clsl' }, { $push: { recWinPrize: call.req.index } });
HongDianChange.sendChangeKey(call.uid, ['clslhd'])

View File

@ -12,7 +12,7 @@ export default async function (call: ApiCall<ReqFight, ResFight>) {
let change: Partial<ResOpen> = {};
let data = await DxltFun.getData(call);
if (data.killBoss >= G.gc.dxlt_com.dayFightLayer) return call.error(globalThis.lng.dixialeitai_2);
if (data.killBoss >= G.gc.dxlt_com.dayFightLayer) return call.error(globalThis.lng.dixialeitai_13);
if (G.gc.dxlt_layer[data.curLayer].type != 1) return call.error(globalThis.lng.dixialeitai_3);
if (data.over) return call.error(globalThis.lng.dixialeitai_4);
if (!data.heros[call.req]) return call.error(globalThis.lng.dixialeitai_5);

View File

@ -41,7 +41,6 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
} else {
call.succ(data);
}
G.redis.set('dxlt', call.uid, data);
G.ioredis.set(`dxlt:${call.uid}`, JSON.stringify(data));
G.mongodb.collection('dxlt').updateOne({ uid: call.uid }, { $set: { ...data } });
}

View File

@ -6,7 +6,7 @@ import {ReqAllReceive, ResAllReceive} from "../../shared/protocols/email/PtlAllR
export default async function (call: ApiCall<ReqAllReceive, ResAllReceive>) {
// 筛选出有奖励并且未领取的邮件
let emailList = (await EmailFun.getAllEmail(call.uid, false)).filter(email => (
email.prizeData.prize.length > 0 && !email.prizeData?.isGet
email.prizeData?.prize.length > 0 && !email.prizeData?.isGet
));
if (emailList.length < 1) return call.error(globalThis.lng.email_1);

View File

@ -3,9 +3,9 @@ import { EmailFun } from '../../public/email';
import { ReqAllRemove, ResAllRemove } from "../../shared/protocols/email/PtlAllRemove";
export default async function (call: ApiCall<ReqAllRemove, ResAllRemove>) {
// 筛选出没有奖励已读邮件和已经领取过奖励的邮件
// 邮件已读 并且 (没有奖励 或者 (有奖励 并且 领取了))
let emailList = (await EmailFun.getAllEmail(call.uid, true)).filter(email => (
(email.emailRead && email.prizeData.prize.length <= 0) || email.prizeData.isGet
email.emailRead && (!email.prizeData || (email.prizeData?.prize.length > 0 && email.prizeData?.isGet))
));
if (emailList.length < 1) return call.error(globalThis.lng.email_2);

View File

@ -3,11 +3,15 @@ import {EmailFun} from '../../public/email';
import {ReqOpen, ResOpen} from "../../shared/protocols/email/PtlOpen";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
// 存入当前玩家多语言信息
await G.redis.rawSet(`user:lng:${call.uid}`, call.req.lng, {EX: 259200})
let list = await EmailFun.getAllEmail(call.uid, false);
let obj: ResOpen = {};
list.forEach(e => obj[e._id] = e);
call.succ(obj);
for (let email of list) {
obj[email._id] = email;
if (email.prizelist) delete email.prizelist;
}
// 存入当前玩家多语言信息
G.redis.rawSet(`user:lng:${call.uid}`, call.req.lng, {EX: 259200})
call.succ(obj);
}

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,6 @@ 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);
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

@ -1,41 +1,34 @@
import { ApiCall } from "tsrpc";
import { PayFun } from '../../../public/pay';
import { PlayerFun } from '../../../public/player';
import { ReqRec, ResRec } from "../../../shared/protocols/event/136Gift/PtlRec";
import { prizeType } from '../../../shared/protocols/type';
import { PublicShared } from '../../../shared/public/public';
import { HongDianChange } from "../../hongdian/fun";
import {ApiCall} from "tsrpc";
import {PayFun} from '../../../public/pay';
import {PlayerFun} from '../../../public/player';
import {ReqRec, ResRec} from "../../../shared/protocols/event/136Gift/PtlRec";
import {prizeType} from '../../../shared/protocols/type';
import {PublicShared} from '../../../shared/public/public';
import {HongDianChange} from "../../hongdian/fun";
/**
*
* @param call
*/
export default async function (call: ApiCall<ReqRec, ResRec>) {
let conf = G.gc.dixiaheishi['136Gift'][call.req.index];
let buyLog = await PayFun.getPayLog(call.uid, G.gc.dixiaheishi['136Gift'][0].payId);
let buy60 = buyLog.slice(-1)[0]?.eTime >= G.time;
if (!conf) return call.error('', { code: -1 });
if (!buy60 && conf.payId) return call.error('', { code: -2 });
if (!conf || conf.payId) return call.error('', {code: -1});
// if (!buy60 && conf.payId) return call.error('', { code: -2 });
let prize: prizeType[] = [];
let pushIndex: number[] = [];
let db = await G.mongodb.cEvent('136Gift').findOne({ uid: call.uid, type: '136Gift' });
let db = await G.mongodb.cEvent('136Gift').findOne({uid: call.uid, type: '136Gift'});
if (call.req.index == 0) {
G.gc.dixiaheishi['136Gift'].forEach((c, i) => {
if (i == 0 || !c.payId || db.recIndex.includes(i)) return;
pushIndex.push(i);
prize.push(...G.gc.pay[c.payId].prize);
});
if (pushIndex.length < 1) return call.error('', { code: -4 });
} else {
if (db.recIndex.includes(call.req.index)) return call.error('', { code: -3 });
prize.push(...(conf.payId ? G.gc.pay[conf.payId].prize : conf.prize));
pushIndex.push(call.req.index);
}
if (db.recIndex.includes(call.req.index)) return call.error('', {code: -3});
prize.push(...(conf.payId ? G.gc.pay[conf.payId].prize : conf.prize));
pushIndex.push(call.req.index);
prize = PublicShared.mergePrize(prize);
await PlayerFun.sendPrize(call, prize);
G.mongodb.cEvent('136Gift').updateOne(
{ uid: call.uid, type: '136Gift' },
{ $push: { recIndex: { $each: pushIndex } } }
{uid: call.uid, type: '136Gift'},
{$push: {recIndex: {$each: pushIndex}}}
);
// HongDianChange.sendChangeKey(call.uid, ['heishihd', 'heishiMrjx'])

View File

@ -24,8 +24,10 @@ export default async function (call: ApiCall<ReqGame, ResGame>) {
_mydata["val"] += addval
_mydata["gamenum"] += 1
_setData["val"] = _mydata.val
_setData["game"] = _mydata["gamenum"]
_setData["gamenum"] = _mydata["gamenum"]
await Christmasfun.setMyData(call.uid, call.req.hdid, { $set: _setData})
// 监听任务
G.emit("Class_task_154", 'Class_task_154', call, 1, 0);
let changedata = { mydata: _mydata}
// 推送红点
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);

View File

@ -27,7 +27,6 @@ export default async function (call: ApiCall<ReqLiBao, ResLiBao>) {
// 判断是否选择奖励了
return call.error('', { code: -3, message: globalThis.lng.yangchengmubiao_2 })
}
let _prize: atn[] = _con.basep
for (let key in _select) {

View File

@ -19,17 +19,23 @@ export default async function (call: ApiCall<ReqQianDao, ResQianDao>) {
_mydata.qiandao.push(i)
_prize = _prize.concat(_con[i])
}
if (!_prize){
if (_prize.length <= 0){
// 没有奖励可以领取
return call.error('', { code: -1, message: globalThis.lng.yangchengmubiao_2 })
}
let _setData = {}
let _addVal = 0
// 懒得喊后台和前端修改了直接取prize里面的对应的经验字段去添加zhanling经验
for (const p of _prize) {
// 战令经验
if (p.t == "shengdanExp") {
_addVal += p.n
}
}
_mydata["val"] += _addVal
_setData["val"] = _mydata.val
_setData["qiandao"] = _mydata.qiandao
await Christmasfun.setMyData(call.uid, call.req.hdid, { $set: _setData })
await PlayerFun.sendPrize(call, _prize);
let changedata = { mydata: _mydata, prize: _prize}
// 推送红点

View File

@ -22,11 +22,14 @@ export default async function (call: ApiCall<ReqTaskRec, ResTaskRec>) {
return call.error('', { code: -3, message: globalThis.lng.yangchengmubiao_4 })
}
_mydata.taskfinish.push(taskid)
let _addval = _con.addval
let _setData = {}
_mydata["val"] += _addval
_setData["val"] = _mydata.val
_setData["taskfinish"] = _mydata.taskfinish
await Christmasfun.setMyData(call.uid, call.req.hdid, { $set: _setData })
let _prize = _con.prize
await PlayerFun.sendPrize(call, _prize);
let changedata = { mydata: _mydata, prize: _prize}
// 推送红点

View File

@ -30,7 +30,7 @@ export default async function (call: ApiCall<ReqZhanLingRec, ResZhanLingRec>) {
_mydata.gj.push(index)
}
if (!_prize) {
if (_prize.length <= 0) {
// 没有奖励可以领取
return call.error('', { code: -1, message: globalThis.lng.yangchengmubiao_2 })
}

View File

@ -113,11 +113,17 @@ export class Christmasfun {
mydata.taskval = await this.getTaskVal(call, hdid)
mydata.refresh = G.time
mydata.gamenum = 0
await this.setMyData(call.uid, hdid, { $set: { refresh: mydata.refresh, taskfinish: mydata.taskfinish, taskval: mydata.taskval, gamenum: mydata.gamenum} })
mydata.libao = {}
await this.setMyData(call.uid, hdid, { $set: {
refresh: mydata.refresh,
taskfinish: mydata.taskfinish,
taskval: mydata.taskval,
gamenum: mydata.gamenum,
libao:mydata.libao} })
return mydata
}
static async payChristmas(payid, call: ApiCall) {
static async payChristmas(payid, call: any) {
let _hd = await HuoDongFun.gethdList(call, 8)
for (let index = 0; index < _hd.length; index++) {
const hdinfo = _hd[index];
@ -126,8 +132,8 @@ export class Christmasfun {
let _mydata = await Christmasfun.getMyData(call, _hdid)
if (_mydata.pay) continue
await this.setMyData(call.uid, _hdid, { $set: { pay: true} })
let _prize = hdinfo.data.zlpayprize
await PlayerFun.sendPrize(call, _prize);
// let _prize = hdinfo.data.zlpayprize
// await PlayerFun.sendPrize(call, _prize);
}
else{
const libaos = hdinfo.data.libao
@ -140,6 +146,12 @@ export class Christmasfun {
if (_buyNum >= _tmp["buynum"]) continue
_mydata.libao[lbid] = _buyNum + 1
this.setMyData(call.uid, _hdid, { $set: { libao: _mydata.libao} })
let _select = _mydata.select[lbid] || {}
let _prize: atn[] = _tmp["basep"]
for (let key in _select) {
_prize.push(_tmp["dlz"][parseInt(key)][_select[key]])
}
await PlayerFun.sendPrize(call, _prize);
break
}

View File

@ -0,0 +1,41 @@
import HQJGFun from "./fun";
import { ApiCall } from "tsrpc";
import { PlayerFun } from "../../../public/player";
import { ReqDuiHuan, ResDuiHuan } from "../../../shared/protocols/event/huangqijiuguan/PtlDuiHuan";
export default async function (call: ApiCall<ReqDuiHuan, ResDuiHuan>) {
let hd = await HQJGFun.HdInfo(call, call.req.hdid);
if (!hd || Object.keys(hd).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let need = [];
let prize = [];
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
for (let id in call.req.dh) {
let con = hd.data.duihuan.filter(x => x.id == Number(id))[0];
if ((mydata.duihuan[id] || 0) + call.req.dh[id] > con.buyNum) {
return call.error("", { code: -2, message: globalThis.lng.hqjgtips_28 })
}
for (let i = 0; i < call.req.dh[id]; i++) {
need.push(...con.need);
prize.push(...con.prize);
}
mydata.duihuan[id] = (mydata.duihuan[id] || 0) + call.req.dh[id];
}
// 检查消耗
await PlayerFun.checkNeedIsMeet(call, need);
// 发送奖励
await PlayerFun.sendPrize(call, prize);
// 记录兑换次数
await HQJGFun.setMyData(call.uid, hd.hdid, { duihuan: mydata.duihuan });
call.succ({ prize: prize, data: mydata })
}

View File

@ -0,0 +1,40 @@
import { ApiCall } from "tsrpc";
import { ReqFight, ResFight } from "../../../shared/protocols/event/huangqijiuguan/PtlFight";
import { HuoDongFun } from "../../../public/huodongfun";
import HQJGFun from "./fun";
import { fightResult } from "../../../shared/fightControl/fightType";
import { FightFun } from "../../../public/fight";
export default async function (call: ApiCall<ReqFight, ResFight>) {
let hd = await HuoDongFun.getHdidInfo(call, call.req.hdid);
if (!hd) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
// 个人活动信息
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
// 开始战斗
let result: fightResult = await FightFun.fightNpc(call, hd.data.bossId, 'hqjg');
let up = false;
let today = HQJGFun.today(hd);
// 历史最大伤害
if (result.totalDamage[0] > mydata.bossres.maxdps) {
up = true;
mydata.bossres.maxdps = result.totalDamage[0];
}
// 今日最大伤害
if (result.totalDamage[0] > (mydata.bossres.todaydps[today] || 0)) {
up = true;
mydata.bossres.todaydps[today] = result.totalDamage[0];
}
// 更新伤害数据
up && await HQJGFun.setMyData(call.uid, call.req.hdid, { bossres: mydata.bossres });
call.succ({ data: mydata, result: result });
}

View File

@ -0,0 +1,16 @@
import HQJGFun from "./fun";
import { ApiCall } from "tsrpc";
import { HuoDongFun } from "../../../public/huodongfun";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/huangqijiuguan/PtlOpen";
export default async (call: ApiCall<ReqOpen, ResOpen>) => {
let hd = HuoDongFun.getHdidInfo(call, call.req.hdid);
if (!hd || Object.keys(hd).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
call.succ({ data: mydata })
}

View File

@ -0,0 +1,7 @@
import { ApiCall } from "tsrpc";
import { ReqRankList, ResRankList } from "../../../shared/protocols/event/huangqijiuguan/PtlRankList";
import HQJGFun from "./fun";
export default async function (call: ApiCall<ReqRankList, ResRankList>) {
HQJGFun.getRankList(call.req.hdid).then(data => call.succ({ rankList: data }));
}

View File

@ -0,0 +1,47 @@
import { ApiCall } from "tsrpc";
import HQJGFun, { Data } from "./fun";
import { HuoDongFun } from "../../../public/huodongfun";
import { ReqRecDpsPrize, ResRecDpsPrize } from "../../../shared/protocols/event/huangqijiuguan/PtlRecDpsPrize";
import { PlayerFun } from "../../../public/player";
export default async function (call: ApiCall<ReqRecDpsPrize, ResRecDpsPrize>) {
let hd = await HuoDongFun.getHdidInfo(call, call.req.hdid);
if (!hd) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let data = hd.data as Data
// 个人活动信息
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
// 领取伤害奖励
let prize = [];
for (let rec of call.req.recid) {
let con = data.bossTask.filter(x => x.id == rec)[0];
if (mydata.bossres.recdpstask.includes(con.id)) {
continue
}
if (con.need > (mydata.bossres.maxdps || 0)) {
continue
}
mydata.bossres.recdpstask.push(con.id);
prize = prize.concat(con.prize);
}
if (prize.length <= 0) {
call.error("", { code: -2, message: lng.hqjgtips_27 });
} else {
// 发送奖励
await PlayerFun.sendPrize(call, prize);
// 设置领奖记录
await HQJGFun.setMyData(call.uid, call.req.hdid, { bossres: mydata.bossres });
}
call.succ({ data: mydata, prize: prize })
}

View File

@ -0,0 +1,52 @@
import HQJGFun from "./fun";
import { ApiCall } from "tsrpc";
import { ReqTaskRec, ResTaskRec } from "../../../shared/protocols/event/huangqijiuguan/PtlTaskRec";
import { PlayerFun } from "../../../public/player";
export default async function (call: ApiCall<ReqTaskRec, ResTaskRec>) {
let hd = await HQJGFun.HdInfo(call, call.req.hdid);
if (!hd || Object.keys(hd).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let today = HQJGFun.today(hd);
if (today < call.req.day) {
// 未到领取时间
return call.error('', { code: -1, message: globalThis.lng.hqjgtips_29 })
}
let prize = [];
let taskday = `day${call.req.day}`
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
for (let id of call.req.taskid) {
let con = hd.data.task[taskday][id];
if (!con) {
continue
}
if (mydata.task.rec[taskday] && mydata.task.rec[taskday].includes(id)) {
continue
}
if (!mydata.task.val[taskday] || (mydata.task.val[taskday][id] || 0) < con.pval) {
continue
}
prize = prize.concat(con.prize);
mydata.task.rec[taskday] = (mydata.task.rec[taskday] || []).push(id)
}
if (prize.length <= 0) {
return call.error("", { code: -2, message: globalThis.lng.hqjgtips_28 })
}
// 发送奖励
await PlayerFun.sendPrize(call, prize);
// 设置领取记录
await HQJGFun.setMyData(call.uid, call.req.hdid, mydata);
call.succ({ data: mydata, prize: prize });
}

View File

@ -0,0 +1,48 @@
import { ApiCall } from "tsrpc";
import { ReqZhaoMu, ResZhaoMu } from "../../../shared/protocols/event/huangqijiuguan/PtlZhaoMu";
import HQJGFun from "./fun";
import { PlayerFun } from "../../../public/player";
import { PublicShared } from "../../../shared/public/public";
export default async function (call: ApiCall<ReqZhaoMu, ResZhaoMu>) {
let hd = await HQJGFun.HdInfo(call, call.req.hdid);
if (!hd || Object.keys(hd).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let need = [{ a: hd.data.huobi.a, t: hd.data.huobi.t, n: hd.data.huobi.n * call.req.num }];
// 检测消耗
await PlayerFun.checkNeedIsMeet(call, need);
let prize = [];
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
for (let n = 0; n < call.req.num; n++) {
let num = mydata.zhaomu.num + n;
let baodi = hd.data.baodi.filter(x => x.num == num);
if (baodi.length > 0) {
// 触发保底
prize = prize.concat(baodi[0].prize);
} else {
// 常规掉落
let temp = PublicShared.randomDropAny<{
a: string, t: string, n: number, p: number
}>(
hd.data.chouka.filter(x => x.cishu <= num)
);
prize.push({ a: temp.a, t: temp.t, n: temp.n });
}
mydata.zhaomu.num = num;
}
// 扣除消耗
await PlayerFun.cutNeed(call, need);
// 发送奖励
await PlayerFun.sendPrize(call, prize);
// 设置抽卡数据
await HQJGFun.setMyData(call.uid, call.req.hdid, { zhaomu: mydata.zhaomu });
call.succ({ data: mydata, prize: prize })
}

View File

@ -0,0 +1,36 @@
import { ApiCall } from "tsrpc";
import { ReqZhaoMuPrizeRec, ResZhaoMuPrizeRec } from "../../../shared/protocols/event/huangqijiuguan/PtlZhaoMuPrizeRec";
import HQJGFun from "./fun";
import { PlayerFun } from "../../../public/player";
export default async function (call: ApiCall<ReqZhaoMuPrizeRec, ResZhaoMuPrizeRec>) {
let hd = await HQJGFun.HdInfo(call, call.req.hdid);
if (!hd || Object.keys(hd).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let prize = [];
let mydata = await HQJGFun.getMydata(call, call.req.hdid);
for (let rec of call.req.recid) {
let con = hd.data.choukajiangli[rec];
if (con.num > mydata.zhaomu.num || mydata.zhaomu.prize.includes(rec)) {
continue
}
mydata.zhaomu.prize.push(rec);
prize = prize.concat(con.prize);
}
if (prize.length <= 0) {
return call.error('', { code: -2, message: globalThis.lng.hqjgtips_28 })
}
// 发送奖励
await PlayerFun.sendPrize(call, prize);
// 设置领取数据
await HQJGFun.setMyData(call.uid, call.req.hdid, { zhaomu: mydata.zhaomu });
call.succ({ prize: prize, data: mydata })
}

View File

@ -0,0 +1,310 @@
import { ApiCall } from "tsrpc"
import { ReqAddHuoDong } from "../../../monopoly/protocols/PtlAddHuoDong"
import { HuoDongFun } from "../../../public/huodongfun"
import { PublicShared } from "../../../shared/public/public"
import { EmailFun } from "../../../public/email"
// hddata.data
export interface Data {
show: 1
task: {
[k: `day${number}`]: {
[k: string]: { pval: number, stype: string, cond: string[], tiaozhuan: number, prize: atn[], des: string }
}
}
huobi: atn // 抽卡货币
bossId: number // boss表的ID
// boss排行邮件
bossRank_des: string
bossRank_title: string
// boss挑战等级奖励邮
bossLvReward_des: string
bossLvReward_title: string
chouka: { a: string, t: string, n: number, p: number, gailv: number, cishu: number }[]
choukajiangli: { num: number, prize: any[] }[]
baodi: { num: number, prize: any[] }[]
gift: { id: number, free: boolean, payId: string, buynum: number, prize: atn[] }[]
duihuan: { id: number, need: atn[], prize: atn[], buyNum: number }[]
bossLvReward: { lv: number, need: number, prize: atn[] }[]
bossTask: { id: number, need: number, prize: atn[] }[]
bossRank: { id: string, rank: [number, number], prize: atn[] }
}
export interface PlayerData {
// 招募数据
zhaomu: {
// 招募次数
num: number
// 次数奖励领取记录
prize: number[]
};
// 任务计数
task: {
rec: { [k: `day${number}`]: number[] }
val: { [k: `day${number}`]: { [id: string]: number } }
},
// 礼包购买记录
giftbuy: { [id: string]: { num: number, select: number[] } }
// 兑换次数记录
duihuan: { [id: string]: number }
// boss挑战数据
bossres: {
// 历史最大伤害
maxdps: number
// 今日最大伤害
todaydps: {
[k: string]: number
}
// 今日奖励领取记录
recdpstask: number[]
}
// 最后修改数据时间
lasttime: number
}
export default class HQJGFun {
static get htype() {
return 15
};
static rankkey(hdid: number) {
return `rank:huangqijiuguan_${hdid}`
}
/** 默认数据 */
static get defaultData() {
return {
zhaomu: {
num: 0,
prize: []
},
task: {
val: {},
rec: {}
},
giftbuy: {},
duihuan: {},
bossres: {
maxdps: 0,
zhanli: 0,
todaydps: {},
recdpstask: []
},
lasttime: 0
}
}
static today(hdinfo: ReqAddHuoDong) {
/**
* 1
*/
return PublicShared.getDiff(hdinfo.stime, G.time)
}
/**
*
*/
static async getRankList(hdid: number) {
let uids = await G.mongodb.collection("event").find(
{ type: this.dataType(hdid) },
{
sort: { "bossres.maxdps": -1, "bossres.zhanli": -1 },
projection: { uid: 1, bossres: 1 }
}
).limit(50).toArray();
let userinfo = await G.mongodb.collection('user').find(
{ uid: { $in: uids.map(v => v.uid) } },
).toArray();
let res = [];
for (let rank = 1; rank <= uids.length; rank++) {
let uid = uids[rank - 1].uid;
let user = userinfo.find(v => v.uid == uid);
if (user) {
res.push({ rank, ...user, valArr: [uids[rank - 1].bossres.maxdps] });
}
}
return res
}
/** 数据类型 */
static dataType(hdid: number) {
return `huangqijiuguan_${hdid}` as `huangqijiuguan_${number}`
}
/** 获取活动数据 */
static async HdInfo(call: ApiCall, hdid?: number): Promise<ReqAddHuoDong> {
if (!hdid) {
let hdlist = await HuoDongFun.gethdList(
call, this.htype
);
return hdlist.length > 0 ? hdlist[0] : null
} else {
return await HuoDongFun.getHdidInfo(call, hdid) as ReqAddHuoDong
}
}
/** 获取我的数据 */
static async getMydata(call: ApiCall, hdid?: number) {
if (!hdid) {
hdid = (await HQJGFun.HdInfo(call)).hdid;
}
let data = await G.mongodb.cEvent(this.dataType(hdid)).findOne({
uid: call.uid, type: this.dataType(hdid)
}, { projection: { _id: 0 } });
if (!data) {
data = (await G.mongodb.cEvent(this.dataType(hdid)).findOneAndUpdate({
uid: call.uid, type: this.dataType(hdid)
}, {
$set: this.defaultData
}, { upsert: true, returnDocument: 'after', projection: { _id: 0 } })).value;
}
return data
}
/** 设置我的数据 */
static async setMyData(uid: string, hdid: number, update: { [k in keyof Partial<PlayerData>]: PlayerData[k] }) {
if (!update.lasttime) {
update.lasttime = G.time;
}
let res = await G.mongodb.cEvent(this.dataType(hdid)).updateOne(
{ uid: uid, type: this.dataType(hdid) }, { $set: update }
);
if (res.upsertedCount <= 0) {
await G.mongodb.cEvent(this.dataType(hdid)).updateOne(
{ uid: uid, type: this.dataType(hdid) }, { $set: Object.assign(this.defaultData, update) }
);
}
}
static async buy(call: ApiCall, payId: string) {
let hddata = await this.HdInfo(call);
if (!hddata) { // 活动不存在
return
}
let mydata = await this.getMydata(call);
await this.setMyData(call.uid, (await this.HdInfo(call)).hdid, mydata);
}
/**
*
*/
static async dayDpsLvPrize() {
// 取stime小于当前时间的最后一条数据
let hdinfo = await G.mongodb.collection("hdinfo").find({
htype: this.htype, stime: { $lte: G.time }
}, { sort: { stime: -1 } }).limit(1).toArray();
// 没有活动数
if (hdinfo.length <= 0) {
return
}
let hd = hdinfo[0];
let hdid = hdinfo[0].hdid;
if (hd.etime < G.time - 300) {
return
}
let today = PublicShared.getDiff(hd.stime, G.time - 300);
G.mongodb.collection("event").find({ type: `huangqijiuguan_${hdid}` }).toArray().then(datas => {
let hddata = hd.data as Data;
for (let i = 0; i < datas.length; i++) {
let data = datas[i];
let lvprize: { lv: number; need?: number; prize?: atn[] };
let dps = data.bossres.todaydps[today] || 0;
for (let lvinfo of hddata.bossLvReward) {
if (dps < lvinfo.need) {
continue;
}
if (!lvprize || lvprize.lv < lvinfo.lv) {
lvprize = lvinfo;
}
}
if (!lvprize) continue
let title = hddata.bossLvReward_title;
let content = hddata.bossLvReward_des;
EmailFun.addEmail({
uid: data.uid,
title: title,
type: "system",
content: content,
prize: lvprize.prize,
contentInsertArr: [lvprize.lv],
})
}
})
}
/**
*
*/
static async endDpsRankPrize() {
// 取stime小于当前时间的最后一条数据
let hdinfo = await G.mongodb.collection("hdinfo").find({
htype: this.htype, stime: { $lte: G.time }
}, { sort: { stime: -1 } }).limit(1).toArray();
// 没有活动数
if (hdinfo.length <= 0) {
return
}
let hd = hdinfo[0];
let hdid = hdinfo[0].hdid;
if (hd.etime < G.time - 300) {
return
}
let uids = await G.mongodb.collection("event").find(
{ type: this.dataType(hdid) },
{
sort: { "bossres.maxdps": -1, "bossres.zhanli": -1 },
projection: { uid: 1, bossres: 1 }
}
).toArray();
for (let rank = 1; rank <= uids.length; rank++) {
let con = hd.data.bossRank.filter(
(x: { rank: number[] }) => rank >= x.rank[0] && rank <= x.rank[1]
)[0];
if (!con) continue;
// 发送排名奖励
await EmailFun.addEmail({
uid: uids[rank - 1].uid,
title: hd.data.bossRank_title,
type: "system",
content: hd.data.bossRank_des,
prize: con.prize,
contentInsertArr: [rank],
})
}
}
}

View File

@ -1,14 +1,25 @@
import { ApiCall } from "tsrpc";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/huobanzhaomu/PtlOpen";
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/huobanzhaomu/PtlOpen";
import {PayFun} from "../../../public/pay";
import {payLog} from "../../../shared/protocols/pay/PtlGetList";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let db = await G.mongodb.cEvent('huobanzhaomu').findOne({ uid: call.uid, type: 'huobanzhaomu' });
let db = await G.mongodb.cEvent('huobanzhaomu').findOne({uid: call.uid, type: 'huobanzhaomu'});
call.succ({
finish: Object.fromEntries(G.gc.huobanzhaomu.map((conf, i) => {
return [i, conf.gudKey ? call.conn.gud[conf.gudKey] >= conf.total : db?.rec?.length >= G.gc.huobanzhaomu.length - 1];
})),
rec: db?.rec || []
});
let logs: payLog[];
let finish: { [k: number]: boolean } = {};
for (let i = 0; i < G.gc.huobanzhaomu.length; i++) {
let conf = G.gc.huobanzhaomu[i];
if (conf.gudKey == "zhizunyueka") {
if (!logs) {
logs = await PayFun.getPayLog(call.uid, "zhizunyueka");
}
finish[i] = !(logs.length <= 0 || logs.slice(-1)[0].eTime < G.time);
} else {
finish[i] = call.conn.gud[conf.gudKey] >= conf.total;
}
}
call.succ({finish: finish, rec: db?.rec || []});
}

View File

@ -12,8 +12,8 @@ export default async function (call: ApiCall<ReqRec, ResRec>) {
let db = await G.mongodb.cEvent('huobanzhaomu').findOne({uid: call.uid, type: 'huobanzhaomu'});
if (db?.rec.includes(call.req.index)) return call.error('', {code: -3});
if (conf.gudKey == "chaozhiyueka") {
let logs = await PayFun.getPayLog(call.uid, "chaozhiyueka");
if (conf.gudKey == "zhizunyueka") {
let logs = await PayFun.getPayLog(call.uid, "zhizunyueka");
if (!logs || logs.slice(-1)[0].eTime < G.time) {
return call.error('', {code: -4});
}

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

@ -0,0 +1,21 @@
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/leichonglibao/PtlOpen";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let data = await G.mongodb.cEvent(`leichonglibao${call.req.hdid}`).findOne(
{type: `leichonglibao${call.req.hdid}`, uid: call.uid}
)
let change = {opentime: G.time}
if (!data) {
Object.assign(change, {sc: false, buy: []})
}
// 每天open红点
G.mongodb.cEvent(`leichonglibao${call.req.hdid}`).updateOne(
{type: `leichonglibao${call.req.hdid}`, uid: call.uid}, {$set: change}, {upsert: true}
)
let temp = Object.assign((data || {}), change) as ResOpen & { opentime }
call.succ({sc: temp.sc, buy: temp.buy});
}

View File

@ -0,0 +1,120 @@
import {ApiCall} from "tsrpc";
import {HuoDongFun} from "../../../public/huodongfun";
import {ReqReceive, ResReceive} from "../../../shared/protocols/event/leichonglibao/PtlReceive";
import {PlayerFun} from "../../../public/player";
import {PublicShared} from "../../../shared/public/public";
export type LeiChongLiBaoData = {
intr: string
intr2: string
payRewardNum: number
dlz: { [key: string]: atn }[]
gift: {
id: string, name: string, need: atn[], free: boolean, payId: string, scale: number, buynum: number, prize: atn[]
}[]
}
export default async function (call: ApiCall<ReqReceive, ResReceive>) {
let hdinfo = await HuoDongFun.gethdList(call, 12);
if (hdinfo.length <= 0) {
// 无此活动
return call.error('', {code: -1, message: globalThis.lng.huodong_open_1})
}
let hddata = hdinfo.filter(i => i.hdid == call.req.hdid)[0].data as LeiChongLiBaoData;
let data = await G.mongodb.cEvent(`leichonglibao${call.req.hdid}`).findOne(
{type: `leichonglibao${call.req.hdid}`, uid: call.uid}
)
if (data.sc) {
// 自选奖励已领取
return call.error('', {code: -1, message: globalThis.lng.task_finsh_3})
}
if (data.buy.length < hddata.payRewardNum) {
// 累计购买礼包次数不足
return call.error("", {code: -1, message: globalThis.lng.ljlibaotips_8})
}
let _prize: atn[] = [];
for (let i = 0; i < hddata.dlz.length; i++) {
_prize.push(hddata.dlz[i][call.req.select[i] || "1"])
}
// 修改领取标识
await G.mongodb.cEvent(`leichonglibao${call.req.hdid}`).updateOne(
{type: `leichonglibao${call.req.hdid}`, uid: call.uid}, {$set: {sc: true}}
)
PlayerFun.sendPrize(call, _prize)
call.succ({prize: _prize})
}
export async function LeiChongLiBaoBuyGift(call: ApiCall, payId: string) {
let hdinfo = await HuoDongFun.gethdList(call, 12);
if (hdinfo.length <= 0) {
console.log(call.uid, "购买累充礼包 但是活动没有开启", payId);
return
}
let gift: LeiChongLiBaoData["gift"][0];
let hdid = hdinfo[0].hdid;
let hddata = hdinfo[0].data as LeiChongLiBaoData;
for (let g of hddata.gift) {
if (g.payId == payId) {
gift = g;
break;
}
}
if (!gift) return; // 不是购买累充礼包
let mydata = await G.mongodb.cEvent(`leichonglibao${hdid}`).findOne(
{type: `leichonglibao${hdid}`, uid: call.uid}
)
if (mydata && mydata.buy.includes(gift.payId)) {
console.log(call.uid, "购买累充礼包 重复购买", payId);
return
}
let update;
if (mydata) {
update = {$push: {buy: payId}}
} else {
update = {$set: {opentime: G.time, sc: false, buy: [payId]}}
}
PlayerFun.sendPrize(call, gift.prize)
G.mongodb.cEvent(`leichonglibao${hdid}`).updateOne(
{uid: call.uid, type: `leichonglibao${hdid}`}, update
)
}
export async function LeiChongLiBaoGetHongDian(call: ApiCall) {
let hdinfo = await HuoDongFun.gethdList(call, 12);
if (hdinfo.length <= 0) {
return {show: false}
}
let hdid = hdinfo[0].hdid;
let hddata = hdinfo[0].data as LeiChongLiBaoData;
let mydata = await G.mongodb.cEvent(`leichonglibao${hdid}`).findOne(
{type: `leichonglibao${hdid}`, uid: call.uid}
)
if (!mydata || mydata.opentime < PublicShared.getToDayZeroTime()) {
return {show: true}
}
if (!mydata.sc && mydata.buy.length >= hddata.payRewardNum) {
return {show: true}
}
return {show: false}
}

View File

@ -1,32 +1,38 @@
import { ApiCall } from "tsrpc";
import { HuoDongFun } from "../../../public/huodongfun";
import { PayFun } from '../../../public/pay';
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/leijichongzhi/PtlOpen";
import { PublicShared } from '../../../shared/public/public';
import {ApiCall} from "tsrpc";
import {HuoDongFun} from "../../../public/huodongfun";
import {PayFun} from '../../../public/pay';
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/leijichongzhi/PtlOpen";
import {PublicShared} from '../../../shared/public/public';
import {checkNextRound} from "./ApiRec";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid)
if (!_hdinfo || Object.keys(_hdinfo).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
return call.error('', {code: -1, message: globalThis.lng.huodong_open_1})
}
let _dbType: `leijichongzhi${number}` = `leijichongzhi${call.req.hdid}`
let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType });
let db = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType});
let sTime = db?.sTime || PublicShared.getToDayZeroTime(G.time);
if (!db) {
G.mongodb.cEvent(_dbType).updateOne(
{ uid: call.uid, type: _dbType },
{ $set: { sTime: sTime, recIndex: [] } },
{ upsert: true }
await G.mongodb.cEvent(_dbType).updateOne(
{uid: call.uid, type: _dbType},
{$set: {sTime: sTime, recIndex: [], round: 0}},
{upsert: true}
);
}
db = await checkNextRound(call, db, _hdinfo)
let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime)) * 10
payNum = payNum - (db?.round || 0) * R.sort((a, b) => b.total - a.total)(_hdinfo.data.tasks)[0].total
call.succ({
sTime: sTime,
recIndex: db?.recIndex || [],
payNum: await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime),
hdinfo: _hdinfo
payNum: payNum,
hdinfo: _hdinfo,
round: db?.round || 0
});
}

View File

@ -1,37 +1,53 @@
import { ApiCall } from "tsrpc";
import { HuoDongFun } from "../../../public/huodongfun";
import { PayFun } from '../../../public/pay';
import { PlayerFun } from '../../../public/player';
import { ReqRec, ResRec } from "../../../shared/protocols/event/leijichongzhi/PtlRec";
import { HongDianChange } from "../../hongdian/fun";
import {ApiCall} from "tsrpc";
import {HuoDongFun} from "../../../public/huodongfun";
import {PayFun} from '../../../public/pay';
import {PlayerFun} from '../../../public/player';
import {ReqRec, ResRec} from "../../../shared/protocols/event/leijichongzhi/PtlRec";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqRec, ResRec>) {
let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid)
if (!_hdinfo || Object.keys(_hdinfo).length <= 0) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
return call.error('', {code: -1, message: globalThis.lng.huodong_open_1})
}
let _dbType: `leijichongzhi${number}` = `leijichongzhi${call.req.hdid}`
let conf = _hdinfo.data.tasks[call.req.index];
if (!conf) return call.error('', { code: -1 });
if (!conf) return call.error('', {code: -1});
let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType });
if (db.recIndex.includes(call.req.index)) return call.error('', { code: -2 });
let db = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType});
if (db.recIndex.includes(call.req.index)) return call.error('', {code: -2});
let payNum = await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime);
if (payNum < conf.total) return call.error('', { code: -3 });
let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.etime)) * 10;
payNum = payNum - (db.round || 0) * R.sort((a, b) => b.total - a.total)(_hdinfo.data.tasks)[0].total
if (payNum < conf.total) return call.error('', {code: -3});
await PlayerFun.sendPrize(call, conf.prize);
G.mongodb.cEvent(_dbType).updateOne(
{ uid: call.uid, type: _dbType },
{ $push: { recIndex: call.req.index } }
await G.mongodb.cEvent(_dbType).updateOne(
{uid: call.uid, type: _dbType},
{$push: {recIndex: call.req.index}}
);
await checkNextRound(call, db, _hdinfo)
HongDianChange.sendChangeKey(call.uid, ['huodonghd'])
call.succ({
prize: conf.prize
});
}
export async function checkNextRound(call: ApiCall, event, _hdinfo) {
if ((event?.recIndex?.length || 0) < _hdinfo.data.tasks.length) return event
let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.etime)) * 10
payNum = payNum - (event?.round || 0) * R.sort((a, b) => b.total - a.total)(_hdinfo.data.tasks)[0].total
if (payNum < 0) return event
let _dbType: `leijichongzhi${number}` = `leijichongzhi${call.req.hdid}`
return (await G.mongodb.cEvent(_dbType).findOneAndUpdate(
{uid: call.uid, type: _dbType},
{$set: {recIndex: []}, $inc: {round: 1}}, {returnDocument: 'after'}
)).value;
}

View File

@ -0,0 +1,69 @@
import { ApiCall } from "tsrpc";
import { HuoDongFun } from "../../../public/huodongfun";
import { ReqCanReceive, ResCanReceive } from '../../../shared/protocols/event/payForDiamond/PtlCanReceive';
import { PublicShared } from "../../../shared/public/public";
import { ActionLog } from "../../../public/actionLog/actionLog";
import { WithId, OptionalId } from "mongodb";
import { ReqAddHuoDong } from "../../../monopoly/protocols/PtlAddHuoDong";
const hasGotKeyPrefix = 'payForDiamond:hasGot:'; // 已领取额度
const showOffListKeyPrefix = 'payForDiamond:ShowOff:'; // 需要炫耀的玩家列表。 其中需要包含信息:玩家区服, 玩家玩家名称, 领到的数量
export async function playerCanReceive(call: ApiCall, callError : boolean = true) {
let activityId = call.req.activityId;
let activityInfo: WithId<OptionalId<ReqAddHuoDong>>;
if (!activityId) {
activityInfo = (await HuoDongFun.gethdList(call, 13))[0];
} else {
activityInfo = await HuoDongFun.getHdidInfo(call, activityId);
}
if (!activityInfo) {
if (callError) {
return call.error('', { code: -1, message: lng.huodong_open_1 });
} else {
return { result: false };
}
}
activityId = activityInfo.hdid;
const hasReceivedKey = hasGotKeyPrefix + activityId;
const hasReceivedStr = await G.crossioredis.get(hasReceivedKey);
const hasReceived = hasReceivedStr? parseInt(hasReceivedStr) : 0;
const remaining = activityInfo.data['totalmoney'] - hasReceived;
const showOffResult = await G.crossioredis.lrange(showOffListKeyPrefix + activityId, 0, -1);
const showOffList = showOffResult.map(result => JSON.parse(result));
const zeroTime = PublicShared.getToDayZeroTime();
const vipScore = await ActionLog.getDayLog(call.uid, 'pay');
const price = activityInfo.data['price'];
if (!vipScore) {
return {
payNum: 0, remaining, result: false, activityInfo, showOffList, price, gotAmount: 0
};
}
const payNum = vipScore;
// 玩家充值未达标或者奖池余额耗尽则不能领取
if (payNum < price || remaining <= 0) {
return {
payNum, remaining, result: false, activityInfo, showOffList, price, gotAmount: 0
}
}
// 检查玩家今日是否已经领取
const playerActivityInfo = await G.mongodb.cEvent('payForDiamond').findOne({ uid: call.uid, type: 'payForDiamond' });
if (playerActivityInfo) {
if (playerActivityInfo[zeroTime]) {
return {
payNum, remaining, result: false, activityInfo, showOffList, price, gotAmount: playerActivityInfo[zeroTime]
};
}
}
return {
payNum, remaining, result: true, activityInfo, showOffList, price, gotAmount: 0
};
}
export default async function (call: ApiCall<ReqCanReceive, ResCanReceive>) {
const canReceiveResult = await playerCanReceive(call);
if (canReceiveResult) {
const { payNum, remaining, result, showOffList, price, gotAmount } = canReceiveResult;
call.succ({ payNum, remaining, result, showOffList, price, gotAmount });
}
}

View File

@ -0,0 +1,121 @@
import { ApiCall } from "tsrpc";
import { ReqReceive, ResReceive } from '../../../shared/protocols/event/payForDiamond/PtlReceive';
import { playerCanReceive } from './ApiCanReceive';
import { PublicShared } from "../../../shared/public/public";
import { PlayerFun } from "../../../public/player";
type diamondWeightGroup = {
weight: number;
numrange: [ min: number, max: number];
};
const hasGotKeyPrefix = 'payForDiamond:hasGot:'; // 已领取额度
const hasGotLockKey = "payForDiamond:lock"; // 更新锁, TTL 1s
const showOffListKeyPrefix = 'payForDiamond:ShowOff:'; // 需要炫耀的玩家列表。 其中需要包含信息:玩家区服, 玩家玩家名称, 领到的数量
/**
* @param groups
*/
function randomWithWeight(groups: diamondWeightGroup[]) {
let maxAmount: number;
let totalWeights = 0;
for (const group of groups) {
totalWeights += group.weight;
if (!maxAmount) {
maxAmount = group.numrange[1];
} else {
maxAmount = Math.max(maxAmount, group.numrange[1]);
}
}
const randomValue = Math.random() * totalWeights; // 随机值落在[0, totalWeights) 之间
let currSum = 0;
for (const group of groups) {
if (currSum <= randomValue && randomValue < currSum + group.weight) {
return { group, maxAmount };
} else {
currSum += group.weight;
}
}
const length = groups.length;
return { group: groups[length - 1], maxAmount };
}
/**
*
* @param remaining
* @param group
* @param maxAmount
*/
function calcDiamondGot(remaining: number, group: diamondWeightGroup, maxAmount: number) {
const [min, max] = group.numrange;
const randomAmount = Math.floor(Math.random() * (max - min)) + min + 1; // max 值应能够取到, 故 +1
// 剩余数额小于组内随机得到的值, 全给吧
if (randomAmount > remaining) {
return remaining;
}
// 随机值大于最大值, 取最大值
if (randomAmount > maxAmount) {
return maxAmount;
}
return randomAmount;
}
export default async function (call: ApiCall<ReqReceive, ResReceive>) {
const canReceiveResult = await playerCanReceive(call);
if (canReceiveResult) { // 该值不存在的情况已被函数直接返回 error, 无需再处理
if (!canReceiveResult.result) {
return call.succ({
amount: 0,
timesRemaining: 0,
showOff: false
});
}
const activityData = canReceiveResult.activityInfo.data;
// 更新 redis 领取记录之前先加锁, 防止多领
const lockResult = await G.crossioredis.setnx(hasGotLockKey, 1);
if (lockResult) {
await G.crossioredis.expire(hasGotLockKey, 1); // 设置 ttl 避免死锁
const activityId = call.req.activityId;
const hasReceivedKey = hasGotKeyPrefix + activityId;
const hasReceivedStr = await G.crossioredis.get(hasReceivedKey);
const hasReceived = hasReceivedStr? parseInt(hasReceivedStr) : 0;
const remaining = activityData['totalmoney'] - hasReceived;
if (remaining <= 0) {
return call.succ({
amount: 0
});
} else {
const { group, maxAmount } = randomWithWeight(activityData['groupConf']['base']['arr']);
const gotAmount = calcDiamondGot(remaining, group, maxAmount);
await G.crossioredis.incrby(hasReceivedKey, Math.abs(gotAmount)); // 添加已领取的额度
await G.crossioredis.del(hasGotLockKey); // 移除锁
await PlayerFun.sendPrize(call, [{ 'a': 'attr', 't': 'rmbmoney', 'n': gotAmount }]);
const showOff = gotAmount >= activityData['groupConf']['base']['loglimit'];
call.succ({ // 领取核心逻辑完成, 请求可以返回了
amount: gotAmount,
timesRemaining: 0,
showOff,
});
// 添加玩家领取记录
const zeroTime = PublicShared.getToDayZeroTime();
const setObj = {};
setObj[zeroTime] = gotAmount;
await G.mongodb.cEvent('payForDiamond').updateOne({ uid: call.uid, type: 'payForDiamond' }, {
$set: setObj
}, {upsert: true});
// 炫耀
if (showOff) {
const msg = JSON.stringify({
name: call.conn.gud.name, gotAmount, serverID: call.conn.gud.sid
});
const showOffListKey = showOffListKeyPrefix + activityId;
await G.crossioredis.lpush(showOffListKey, msg);
await G.crossioredis.ltrim(showOffListKey, 0, 49); // 限制列表保存 50 条消息, 避免无限增长
}
}
} else {
return call.succ({
amount: 0
});
}
}
}

View File

@ -0,0 +1,27 @@
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/zhoumolibao/PtlOpen";
import {PayFun} from "../../../public/pay";
import {HuoDongFun} from "../../../public/huodongfun";
import {PublicShared} from "../../../shared/public/public";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let _hd = (await HuoDongFun.gethdList(call, 10))[0]
if (!_hd) return call.errorCode(-1)
let payIds = _hd?.data?.gift?.filter(i => i.payId)?.map(i => i.payId)
let payLog: any = await PayFun.getPayLogs(call.uid, payIds)
for (let key in payLog) {
payLog[key] = payLog[key]?.filter(i => i.time > _hd.stime && i.time < _hd.etime)
}
let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne({uid: call.uid, type: `pobinglibao${_hd.hdid}`})
call.succ({
record: data?.record || {},
buyLog: payLog
})
}

View File

@ -0,0 +1,89 @@
import { ApiCall } from "tsrpc";
import { ReqReceive, ResReceive } from "../../../shared/protocols/event/pobinglibao/PtlReceive";
import { HuoDongFun } from "../../../public/huodongfun";
import { PlayerFun } from "../../../public/player";
import { HongDianChange } from "../../hongdian/fun";
import { PayFun } from "../../../public/pay";
import { PublicShared } from "../../../shared/public/public";
export default async function (call: ApiCall<ReqReceive, ResReceive>) {
// 查询活动是否是可领取状态
let _hd = (await HuoDongFun.gethdList(call, 10))[0]
let prize = [];
let update = {};
// 判断活动是否是最后一天
if (PublicShared.chkSameDate(G.time, _hd.etime)) {
let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne(
{ uid: call.uid, type: `pobinglibao${_hd.hdid}` }
);
for (let gift of _hd.data.gift) {
// 查询购买状态
let push = [];
let payLog = await PayFun.getPayLog(call.uid, gift.payId)
payLog = payLog?.filter(i => i.time >= _hd.stime && i.time <= _hd.etime) || []
if (!payLog || !payLog.length) continue;
for (let key of ["prize", "recPrize1", "recPrize2"]) {
if (!data || !data?.record[gift.id] || !data.record[gift.id].includes(key)) {
push.push(key);
prize.push(...gift[key]);
}
}
if (push.length > 0) {
if (update["$push"]) {
update["$push"]["record." + gift.id] = { $each: push }
} else {
update["$push"] = { ["record." + gift.id]: { $each: push } }
}
}
}
if (!prize.length) {
return call.errorCode(-3)
}
} else {
let gift = _hd?.data?.gift?.find(i => i.id == call.req.id);
if (!gift || !call.req.recId) return call.errorCode(-1);
// 查询购买状态
let payLog = await PayFun.getPayLog(call.uid, gift.payId)
payLog = payLog?.filter(i => i.time >= _hd.stime && i.time <= _hd.etime) || []
if (!payLog || !payLog.length) return call.errorCode(-2);
/**
*
*
*
*/
let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne(
{ uid: call.uid, type: `pobinglibao${_hd.hdid}` }
)
let rec = data?.record?.[call.req.id]?.length
let _payDiff = PublicShared.getDiff(payLog[0].time)
_payDiff = _payDiff > 3 ? 3 : _payDiff
if (rec >= _payDiff || data?.record?.[gift.id] == call.req.recId) return call.errorCode(-3)
prize.push(...gift[call.req.recId]);
update = {
$push: { [`record.${gift.id}`]: call.req.recId },
}
}
await PlayerFun.sendPrize(call, prize);
await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).updateOne(
{ uid: call.uid, type: `pobinglibao${_hd.hdid}` }, update, { upsert: true }
);
call.succ({ prize: prize });
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
}

View File

@ -13,28 +13,27 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let _zt = PublicShared.getToDayZeroTime();
let pays = await PayFun.getPayLogs(call.uid, payids);
for (; day <= G.gc.shiwuleichong.tasks.length; day++) {
let pay = pays[G.gc.shiwuleichong.tasks[day].payid];
if (!pay) {
let pay = pays[G.gc.shiwuleichong.tasks[day - 1].payid];
if (!pay || pay.length == 0) {
break
} else {
if (pay.slice(-1)[0].time >= _zt) {
// 如果是最后一天奖励
if (day >= G.gc.shiwuleichong.tasks.length) {
// 充值订单隔天了
if (pay.slice(-1)[0].time < _zt) {
// 重置所有订单
await PayFun.delPayLog(call.uid, ...payids.map(i => {
return {payId: i, val: []}
}))
day = 1;
pays = {};
}
break;
} else if (pay.slice(-1)[0].time >= _zt) {
break
}
}
}
// 如果是最后一天奖励 并且 充值订单隔天了
if (
day == G.gc.shiwuleichong.tasks.length &&
pays[G.gc.shiwuleichong.tasks[day - 1].payid] &&
pays[G.gc.shiwuleichong.tasks[day - 1].payid].slice(-1)[0].time < _zt
) {
// 重置所有订单
await PayFun.delPayLog(call.uid, ...payids.map(i => {
return {payId: i, val: []}
}))
day = 1;
pays = {};
}
call.succ({
day: day,

View File

@ -1,14 +1,14 @@
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/shouchong/PtlOpen";
import { ApiCall } from "tsrpc";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/shouchong/PtlOpen";
import {PayFun} from "../../../public/pay";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let payIds = [];
for (let k in G.gc.shouchong) {
payIds.push(G.gc.shouchong[k].payid)
}
let data = await G.mongodb.cEvent('shouchongzhigou').findOne({uid: call.uid, type: 'shouchongzhigou'})
let pays = await PayFun.getPayLogs(call.uid, payIds)
let payIds = R.compose(R.map(i=>i.payid),R.values())(G.gc.shouchong)
call.succ({payIds: Object.keys(pays).filter((i) => pays[i].length > 0)});
call.succ({
receive: data?.receive || {},
buyLog: await PayFun.getPayLogs(call.uid, payIds)
})
}

View File

@ -0,0 +1,58 @@
import {ApiCall} from "tsrpc";
import {PlayerFun} from '../../../public/player';
import {ReqReceive, ResReceive} from "../../../shared/protocols/event/shouchong/PtlReceive";
import {PublicShared} from '../../../shared/public/public';
import {HongDianChange} from "../../hongdian/fun";
import {PayFun} from "../../../public/pay";
export default async function (call: ApiCall<ReqReceive, ResReceive>) {
let conf = G.gc.shouchong[call.req.k];
if (!conf) return call.error(globalThis.lng.pata_getprize_1);
let payLog = await PayFun.getPayLog(call.uid, conf.payid)
if (!payLog) return call.errorCode(-1)
let data = await G.mongodb.cEvent('shouchongzhigou').findOne({ uid: call.uid, type: 'shouchongzhigou' });
let recArr = data?.receive?.[call.req.k] || [];
// if (call.conn.gud.payExp < conf.paynum) return call.error(globalThis.lng.event_kfkh_9);
if (recArr.length >= conf.prize.length) return call.error(globalThis.lng.event_kfkh_3);
if (recArr.slice(-1)[0] && PublicShared.getToDayZeroTime() < recArr.slice(-1)[0]) return call.error(globalThis.lng.event_kfkh_10);
await PlayerFun.sendPrize(call, conf.prize[recArr.length]);
await G.mongodb.cEvent('shouchongzhigou').updateOne(
{ uid: call.uid, type: 'shouchongzhigou' },
{ $push: G.mongodb.createTreeObj({ key: 'receive', k: call.req.k, val: G.time }) },
{ upsert: true }
);
let recLen = data != null ? Object.values(data.receive).map(arr => arr.length).reduce((a, b) => a + b) + 1 : 1;
let allLen = Object.values(G.gc.shouchong).map(conf => conf.prize.length as number).reduce((a, b) => a + b);
if (data && recLen >= allLen) {
G.mongodb.collection('syncBtns').updateOne({ uid: call.uid }, { $set: { 'shouchong.active': false } }, { upsert: true });
}
HongDianChange.sendChangeKey(call.uid, ['shouchong'])
call.succ({
prize: conf.prize[recArr.length]
});
}
export async function getShouChongRedPoint(call: ApiCall) {
// let data = await G.mongodb.cEvent('shouchong').findOne({ uid: call.uid, type: 'shouchong' });
//
// for (let [id, conf] of Object.entries(G.gc.shouchong)) {
// let rec = data?.receive?.[id] || [];
// if (call.conn.gud.payExp / 10 < conf.paynum || rec.length >= conf.prize.length) continue;
// if (rec.length == 0 || rec.slice(-1)[0] < PublicShared.getToDayZeroTime(G.time)) {
// res = { show: true };
// break;
// }
// }
return {show: false};
}

View File

@ -0,0 +1,82 @@
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/xiaofeijingsai/PtlOpen";
import {HuoDongFun} from "../../../public/huodongfun";
/**
*
* redis缓存60秒
*
* @param call
*/
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let ioList = await G.crossioredis.get(`rank:xiaofeijingsai`);
if (ioList) {
let myData = await getMyData(call, JSON.parse(ioList))
return call.succ({list: JSON.parse(ioList), myData})
}
let _hd = (await HuoDongFun.gethdList(call, 11))[0]
if (!_hd) return call.errorCode(-1)
let limit = _hd.data?.rank?.slice(-1)?.[0]?.rank?.slice(-1)?.[0] || call.req.limit || 100
let rmbuse = await G.crossmongodb.collection('rmbuse').find({type: `xfjs_${G.huodong.xfjsId}`}).sort({change: 1}).limit(limit).toArray()
let list: any = rmbuse.map(i => ({...i, total: R.negate(i.change)}))
let rankList = sortRankList(_hd.data.rank, list)
let users = await G.crossmongodb.collection('huodong_user').find({uid: {$in: rankList.map(i => i._id).filter(i => i != 'system')}}).toArray()
rankList = rankList.map(i => ({...i, player: users.find(v => v.uid == i.uid) || {}}))
// 活动结束前半小时缓存过期时间改为5秒
let exTime = (G.time + 1800) > _hd.etime ? 5 : 10
G.crossioredis.setex(`rank:xiaofeijingsai`, exTime, JSON.stringify(rankList));
let myData = await getMyData(call, rankList)
call.succ({list: rankList, myData})
}
/**
* system占位
* @param rank
* @param list
*/
export function sortRankList(rank, list) {
let rankList = []
rank.map(i => {
for (let k = i.rank[0] - 1; k < i.rank[1]; k++) {
if (list[0]?.total >= i.need[0].n) {
rankList.push({...list[0], rank: k, _id: list[0].uid})
list = R.tail(list)
} else {
rankList.push({_id: 'system', total: i.need[0].n, rank: k, player: {}})
}
}
})
return R.sort((a, b) => a.rank - b.rank)(rankList)
}
// 获取自己的信息
async function getMyData(call: ApiCall, rankList) {
let myData = rankList.find(i => i._id == call.uid)
if (myData) return myData
let myCut: any = await G.crossmongodb.collection('rmbuse').findOne({
uid: call.uid,
type: `xfjs_${G.huodong.xfjsId}`
})
let myUser = await G.mongodb.collection('user').findOne({uid: call.uid})
G.crossmongodb.collection('huodong_user').updateOne({uid: call.uid}, {$set: myUser}, {upsert: true})
if (!myCut) {
myCut = {_id: myUser.uid, total: 0}
}
return {player: myUser, ...myCut, total: R.negate(myCut.change) || 0, rank: -1, _id: myUser.uid}
}

View File

@ -2,6 +2,8 @@ import { ApiCall } from "tsrpc";
import { HuoDongFun } from "../../../public/huodongfun";
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/yangchengmubiao/PtlOpen";
import { YangChengMuBiaofun } from "./fun";
import { PayFun } from "../../../public/pay";
import { payLog } from "../../../shared/protocols/pay/PtlGetList";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid)
@ -9,6 +11,23 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let delPay: { payId: string, val: payLog[] }[] = [];
let payIds = _hdinfo.data.gift.map(v => v.payId);
let payLogs = await PayFun.getPayLogs(call.uid, payIds);
for (let payid in payLogs) {
if (payLogs[payid].length > 0) {
if (payLogs[payid].slice(-1)[0].time < _hdinfo.stime) {
delPay.push({ payId: payid, val: [] });
}
}
}
if (delPay.length > 0) {
await PayFun.delPayLog(call.uid, ...delPay);
}
let _mydata = await YangChengMuBiaofun.getMyData(call, call.req.hdid)
let changedata = { mydata: _mydata, hdinfo: _hdinfo }
call.succ(changedata);

View File

@ -0,0 +1,35 @@
import {ApiCall} from "tsrpc";
import {ReqDMRec, ResDMRec} from "../../../shared/protocols/event/yuandan/PtlDMRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
import {PublicShared} from "../../../shared/public/public";
export default async function (call: ApiCall<ReqDMRec, ResDMRec>) {
// 查询活动是否存在
let _hd = (await HuoDongFun.gethdList(call, 14))[0]
if (!_hd) return call.errorCode(-1)
// 扣除免费次数或相应货币
let data = await G.mongodb.cEvent(`yuandan${_hd.hdid}`).findOne({uid: call.uid, type: `yuandan${_hd.hdid}`})
let rec = data?.gameNum
if (rec && rec >= _hd.data?.gamefree) {
await PlayerFun.checkNeedIsMeet(call, _hd.data.gameneed);
await PlayerFun.cutNeed(call, _hd.data.gameneed);
}
let prize = []
if (call.req.id) {
prize = PublicShared.randomDropGroup('1', 1, {'1': _hd.data.game});
await PlayerFun.sendPrize(call, prize);
}
await G.mongodb.cEvent(`yuandan${_hd.hdid}`).updateOne({uid: call.uid, type: `yuandan${_hd.hdid}`}, {
$inc: {[`gameNum`]: 1},
}, {upsert: true})
call.succ({prize})
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
}

View File

@ -0,0 +1,36 @@
import {ApiCall} from "tsrpc";
import {ReqDZRec, ResDZRec} from "../../../shared/protocols/event/yuandan/PtlDZRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqDZRec, ResDZRec>) {
// 查询活动是否有当前领奖的免费选项
let _hd = (await HuoDongFun.gethdList(call, 14))[0]
let gift = _hd?.data?.gift?.find(i => i.free && i.id == call.req.id)
if (!gift) return call.errorCode(-1)
// 超出限购次数
let data = await G.mongodb.cEvent(`yuandan${_hd.hdid}`).findOne({uid: call.uid, type: `yuandan${_hd.hdid}`})
let rec = data?.gift?.[call.req.id]
if (rec && rec >= gift.buynum) return call.errorCode(-2)
// 奖励不符合,严格判断
let dlzList = R.flatten(gift.dlz.map(i => R.values(i)))
call.req.dlz.map(i => {
let item = dlzList.find(v => i.a == v.a && i.t == v.t && i.n == v.n)
if (!item) call.errorCode(-4)
})
let prize = [...gift.prize, ...call.req.dlz]
await PlayerFun.sendPrize(call, prize);
await G.mongodb.cEvent(`yuandan${_hd.hdid}`).updateOne({uid: call.uid, type: `yuandan${_hd.hdid}`}, {
$set: {[`gift.${gift.id}`]: prize},
}, {upsert: true})
call.succ({[gift.id]: prize})
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
}

View File

@ -0,0 +1,29 @@
import {ApiCall} from "tsrpc";
import {ReqExchange, ResExchange} from "../../../shared/protocols/event/yuandan/PtlExchange";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqExchange, ResExchange>) {
// 礼包不存在
let _hd = (await HuoDongFun.gethdList(call, 14))[0]
let gift = _hd?.data?.duihuan?.find(i => i.id == call.req.id)
if (!gift) return call.errorCode(-1)
// 超出限购次数
let data = await G.mongodb.cEvent(`yuandan${_hd.hdid}`).findOne({uid: call.uid, type: `yuandan${_hd.hdid}`})
let rec = data?.exchange?.[call.req.id]
if (rec && rec >= gift?.buyNum) return call.errorCode(-2)
await PlayerFun.checkNeedIsMeet(call, gift.need);
await PlayerFun.cutNeed(call, gift.need)
await PlayerFun.sendPrize(call, gift.prize);
await G.mongodb.cEvent(`yuandan${_hd.hdid}`).updateOne({uid: call.uid, type: `yuandan${_hd.hdid}`}, {
$inc: {[`exchange.${gift.id}`]: 1},
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
}

View File

@ -0,0 +1,20 @@
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/yuandan/PtlOpen";
import {HuoDongFun} from "../../../public/huodongfun";
import {PayFun} from "../../../public/pay";
import {Yuandanfun} from "./fun";
import {PublicShared} from "../../../shared/public/public";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let _hd = await Yuandanfun.getCon(call)
if (!_hd) return call.errorCode(-1)
let payIds = _hd.data.gift.filter(i => i.payid).map(i => i.payid)
let data = await Yuandanfun.getData(call, _hd.hdid)
call.succ({
data: {...data, isSameDay: PublicShared.chkSameDate(data.qiandaoTime, G.time)},
payLog: await PayFun.getPayLogs(call.uid, payIds),
})
}

View File

@ -0,0 +1,37 @@
import { ApiCall } from "tsrpc";
import { ReqTaskRec, ResTaskRec } from "../../../shared/protocols/event/yuandan/PtlTaskRec";
import {Yuandanfun, Yuandanfun as Christmasfun} from "./fun";
import {HongDianChange} from "../../hongdian/fun";
import {PlayerFun} from "../../../public/player";
export default async function (call: ApiCall<ReqTaskRec, ResTaskRec>) {
let _hd = await Christmasfun.getCon(call)
let taskid = call.req.taskid;
let _con = _hd.data.task[taskid];
if (!_con) {
// 任务id 不存在
return call.error('', { code: -1, message: globalThis.lng.yangchengmubiao_2 })
}
let _mydata = await Yuandanfun.getData(call, _hd.hdid)
if (_mydata.taskval[taskid] < _con.pval) {
// 任务未完成
return call.error('', { code: -2, message: globalThis.lng.yangchengmubiao_3 })
}
if (_mydata.taskfinish.includes(taskid)) {
// 任务已领取
return call.error('', { code: -3, message: globalThis.lng.yangchengmubiao_4 })
}
_mydata.taskfinish.push(taskid)
let _setData = {}
_setData["taskfinish"] = _mydata.taskfinish
await Yuandanfun.setData(call.uid, _hd.hdid, { $set: _setData })
let _prize = _con.prize
await PlayerFun.sendPrize(call, _prize);
let changedata = { data: _mydata, prize: _prize}
call.succ(changedata);
// 推送红点
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
}

View File

@ -0,0 +1,44 @@
import {ApiCall} from "tsrpc";
import {ReqZLRec, ResZLRec} from "../../../shared/protocols/event/yuandan/PtlZLRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
import {Yuandanfun} from "./fun";
import {PublicShared} from "../../../shared/public/public";
export default async function (call: ApiCall<ReqZLRec, ResZLRec>) {
let _hd = await Yuandanfun.getCon(call)
if (!_hd) return call.errorCode(-1)
// 查询是否存在当前传入id的礼品
let gift = _hd?.data?.qiandao?.[call.req.id]
if (!gift) return call.errorCode(-2)
// 奖励已领取
let data = await G.mongodb.cEvent(`yuandan${_hd.hdid}`).findOne({uid: call.uid, type: `yuandan${_hd.hdid}`})
let rec = data?.qiandao?.[call.req.id]
if (rec) return call.errorCode(-3)
if (data && data.qiandaoTime && PublicShared.chkSameDate(data.qiandaoTime, G.time)) {
return call.errorCode(-4)
}
// 奖励不符合,严格判断
let dlzList = R.flatten(gift.dlz.map(i => R.values(i)))
call.req.dlz.map(i => {
let item = dlzList.find(v => i.a == v.a && i.t == v.t && i.n == v.n)
if (!item) call.errorCode(-5)
})
let prize = [...gift.prize, ...call.req.dlz]
await PlayerFun.sendPrize(call, prize);
await G.mongodb.cEvent(`yuandan${_hd.hdid}`).updateOne({uid: call.uid, type: `yuandan${_hd.hdid}`}, {
$set: {[`qiandao.${call.req.id}`]: prize, qiandaoTime: G.time},
}, {upsert: true})
call.succ({[call.req.id]: prize})
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);
}

View File

@ -0,0 +1,116 @@
import {ApiCall} from 'tsrpc';
import {HuoDongFun} from '../../../public/huodongfun';
import {christmas} from '../../../shared/protocols/event/christmas/PtlOpen';
import {PublicShared} from '../../../shared/public/public';
import {PayFun} from "../../../public/pay";
export class Yuandanfun {
/**配置 */
static async getCon(call: ApiCall) {
return (await HuoDongFun.gethdList(call, 14))[0]
}
/**获取我的数据 */
static async getData(call: ApiCall, hdid: number) {
let data = await G.mongodb.cEvent(`yuandan${hdid}`).findOne({uid: call.uid, type: `yuandan${hdid}`})
if (!data || !data.refreshTime || !PublicShared.chkSameDate(data.refreshTime, G.time)) {
// 刷新每日任务
data = (await G.mongodb.cEvent(`yuandan${hdid}`).findOneAndUpdate({uid: call.uid, type: `yuandan${hdid}`}, {
$set: {
gameNum: 0,
gift: {},
exchange: {},
taskfinish: [],
taskval: await this.getTaskVal(call),
qiandaoTime: data?.qiandaoTime || 1,
refreshTime: G.time
},
}, {upsert: true, returnDocument: 'after'})).value
this.refreshPayLog(call)
}
return data
}
static async refreshPayLog(call: ApiCall) {
let _hd = await this.getCon(call)
let payIds = _hd?.data?.gift?.filter(i => i.payId).map(i => i.payId)
PayFun.delPayLog(call.uid, ...payIds.map(i => {
return {payId: i, val: []}
}))
}
/**获取所有taskid 及对应的值 */
static async getTaskVal(call: ApiCall) {
let _initCon = await this.getCon(call)
let _tasks = _initCon.data.task
let _res = {}
for (let index = 0; index < Object.keys(_tasks).length; index++) {
const element = Object.keys(_tasks)[index];
let _tmp = _tasks[element]
_tmp["id"] = element
// 每日登录直接完成
if (_tmp.stype == "128") {
_res[element] = 1
} else {
_res[element] = 0
}
}
return _res
}
/**设置数据 */
static async setData(uid: string, hdid: number, set: {}) {
await G.mongodb.cEvent(`yuandan${hdid}`).updateOne(
{uid: uid, type: `yuandan${hdid}`},
set
)
}
/**设置任务 */
static async setTaskVal(call: ApiCall, stype: number, val: number, chkCall: Function, chkval: number = 0, isinc: number = 0, alchangeVal: Function, arg) {
// 活动过期,不计数
let _hd = await this.getCon(call)
if (!_hd) return
await this.getData(call, _hd.hdid)
let _tasks = _hd.data.task
let _setData = {
$inc: {},
$set: {}
}
let isset = 0
for (let indextask = 0; indextask < Object.keys(_tasks).length; indextask++) {
const ele = Object.keys(_tasks)[indextask];
// 具体任务配置
let _taskCon = _tasks[ele]
if (_taskCon.stype != stype) continue
// 不符合任务要求
if (!(await chkCall(_taskCon["cond"], chkval, arg))) continue
// 根据需求改写
val = await alchangeVal(call, _taskCon, val, arg)
isset = 1
if (isinc == 1) { // 累加
_setData["$inc"][`taskval.${ele}`] = val
} else {
_setData["$set"][`taskval.${ele}`] = val
}
}
// 设置任务
if (isset == 1) {
await G.mongodb.collection('event').updateOne({
uid: call.uid,
type: `yuandan${_hd.hdid}`
}, _setData)
}
}
}

View File

@ -1,14 +1,15 @@
import {ApiCall} from "tsrpc";
import {ZhanLingTasks} from '../../../public/zhanling';
import {ReqOpen, ResOpen} from "../../../shared/protocols/event/zhanling/PtlOpen";
import {player} from '../../../shared/protocols/user/type';
import {PublicShared} from '../../../shared/public/public';
import { ApiCall } from "tsrpc";
import { ZhanLingTasks } from '../../../public/zhanling';
import { ReqOpen, ResOpen } from "../../../shared/protocols/event/zhanling/PtlOpen";
import { player } from '../../../shared/protocols/user/type';
import { PublicShared } from '../../../shared/public/public';
import { PayFun } from "../../../public/pay";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let zls = await G.mongodb.collection('scheduler').findOne({type: 'zhanling'});
let data = await G.mongodb.cEvent('zhanling').findOne({uid: call.uid, type: 'zhanling'});
let zls = await G.mongodb.collection('scheduler').findOne({ type: 'zhanling' });
let data = await G.mongodb.cEvent('zhanling').findOne({ uid: call.uid, type: 'zhanling' });
if (!data || data.round != (zls?.round | 0)) {
if (!data || data.round != (zls?.round || 0)) {
let set = {
lv: 1,
exp: 0,
@ -16,18 +17,25 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
isPay: false,
taskRec: [],
round: zls?.round || 0,
reWeekTime:G.time,
reWeekTime: G.time,
refreshTime: G.time,
}
await PayFun.delPayLog(
call.uid, { payId: G.gc.zhanling.payId, val: [] }
);
// 战令重置的时候需要删除所有的任务进度,但是每天的任务进度不做处理,因为每天会自然重置,怕玩家会刷
// ZhanLingTasks.clearLog(call.uid, 'day');
ZhanLingTasks.clearLog(call.uid, 'week');
ZhanLingTasks.clearLog(call.uid, 'round');
data = (await G.mongodb.cEvent('zhanling').findOneAndUpdate({
uid: call.uid,
type: 'zhanling'
}, {$set: set}, {upsert: true, returnDocument: 'after'})).value;
}, { $set: set }, { upsert: true, returnDocument: 'after' })).value;
}
if (PublicShared.getToWeekMondayZeroTime() > data.reWeekTime || PublicShared.getToDayZeroTime() > data.refreshTime) {
let set: any = {taskRec: []};
let set: any = { taskRec: [] };
let reType = [];
if (PublicShared.getToWeekMondayZeroTime() > data.reWeekTime) {
@ -49,11 +57,11 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
data = (await G.mongodb.cEvent('zhanling').findOneAndUpdate({
uid: call.uid,
type: 'zhanling'
}, {$set: set}, {upsert: true, returnDocument: 'after'})).value;
}, { $set: set }, { upsert: true, returnDocument: 'after' })).value;
}
let tasks = G.gc.zhanling.task.map(t => {
return {type: t.type as 'day' | 'week' | 'round', key: t.taskId};
return { type: t.type as 'day' | 'week' | 'round', key: t.taskId };
});
let taskFinished = await ZhanLingTasks.getLog(call.uid, tasks);
@ -68,14 +76,14 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
}
export async function payZhanLing(player: player) {
let zlData = await G.mongodb.cEvent('zhanling').findOne({uid: player.uid, type: 'zhanling'});
let zlData = await G.mongodb.cEvent('zhanling').findOne({ uid: player.uid, type: 'zhanling' });
let curLv = zlData?.lv || 1;
let maxLv = Number(Object.keys(G.gc.zhanling.lv).slice(-1)[0]);
let addLv = maxLv - curLv >= G.gc.zhanling.payAddLv ? G.gc.zhanling.payAddLv : maxLv - curLv;
await G.mongodb.cEvent('zhanling').updateOne(
{uid: player.uid, type: 'zhanling'},
{$set: {isPay: true, exp: G.gc.zhanling.lv[curLv + addLv], lv: curLv + addLv}},
{upsert: true}
{ uid: player.uid, type: 'zhanling' },
{ $set: { isPay: true, exp: G.gc.zhanling.lv[curLv + addLv], lv: curLv + addLv } },
{ upsert: true }
);
}

View File

@ -15,10 +15,21 @@ export default async function (call: ApiCall<ReqBuy, ResBuy>) {
let conf = _hdinfo.data.gift[call.req.index];
if (!conf || conf.payId) return call.errorCode(-1);
let selectPrize = conf.prize.map((v, i) => v[call.req.prizeIndex[i]]).filter(p => !!p);
if (selectPrize.length < conf.prize.length) return call.errorCode(-2);
let data = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType})
let rec = data?.rec?.[call.req.index]
if (rec) return call.errorCode(-3)
// 奖励不符合,严格判断
let dlzList = R.flatten(conf.dlz.map(i => R.values(i)))
call.req.dlz.map(i => {
let item = dlzList.find(v => i.a == v.a && i.t == v.t && i.n == v.n)
if (!item) call.errorCode(-4)
})
let event = (await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }));
let buyNum = R.values(event?.rec)?.length || 0
let buyNum = (await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }))?.record?.[call.req.index] || 0;
if (buyNum >= conf.buyNum) return call.errorCode(-3);
if (conf.need.length > 0) {
@ -26,15 +37,15 @@ export default async function (call: ApiCall<ReqBuy, ResBuy>) {
await PlayerFun.cutNeed(call, conf.need);
}
await PlayerFun.sendPrize(call, selectPrize);
let prize = [...conf.prize,...call.req.dlz]
G.mongodb.cEvent(_dbType).updateOne(
{ uid: call.uid, type: _dbType },
{ $inc: G.mongodb.createTreeObj({ key: `record.${call.req.index}`, val: 1 }) },
{ upsert: true }
);
await PlayerFun.sendPrize(call, prize);
await G.mongodb.cEvent(_dbType).updateOne({uid: call.uid, type: _dbType}, {
$set: {[`rec.${call.req.index}`]: prize},
}, {upsert: true})
call.succ({
prize: selectPrize
prize: prize
});
}

View File

@ -13,7 +13,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType });
call.succ({
record: db?.record || {},
rec: db?.rec || {},
hdinfo: _hdinfo
});
}

View File

@ -8,4 +8,12 @@ export default async function (call: ApiCall<ReqhdGetList, ReshdGetList>) {
let _hdList = await HuoDongFun.gethdList(call)
call.succ({hdlist: _hdList});
// 消费竞赛是跨服活动,活动开启时,同步当前用户信息到跨服数据库
G.huodong.xfjs = !!_hdList.find(i => i.htype == 11);
if (G.huodong.xfjs) {
G.huodong.xfjsId = _hdList.find(i => i.htype == 11).hdid
let myUser = await G.mongodb.collection('user').findOne({uid: call.uid})
G.crossmongodb.collection('huodong_user').updateOne({uid: call.uid}, {$set: myUser}, {upsert: true})
}
}

View File

@ -15,16 +15,13 @@ export default async function (call: ApiCall<ReqList, ResList>) {
]).toArray();
break;
case 'friend':
//res = await G.redis.gets('user', ...my.data.friendList.map(uid => [uid] as [string]))
res = (await G.mongodb.find('user',{uid:{$in:my.data.friendList}})) as any;
break;
case 'apply':
// 预防申请列表出现脏数据(过滤已添加好友)
//res = await G.redis.gets('user', ...);
res = (await G.mongodb.find('user',{uid:{$in: my.data.applyList.filter(uid => my.data.friendList.indexOf(uid) == -1) }})) as any
break;
case 'black':
//res = await G.redis.gets('user', ...my.data.blacklist.map(uid => [uid] as [string]))
res = (await G.mongodb.find('user',{uid:{$in: my.data.blacklist}})) as any;
break;

View File

@ -5,7 +5,6 @@ export default async function (call: ApiCall<ReqApplyList, ResApplyList>) {
let GHdata = await call.conn.gonghui
if (GHdata.data.applyList?.length > 0) {
//let players = await G.redis.gets('user', ...GHdata.data.applyList.map(a => [a.uid] as [string]));
let uids = GHdata.data.applyList.map((i)=>i.uid);
let players = (await G.mongodb.find('user',{uid:{$in: uids}})) as any;

View File

@ -12,7 +12,6 @@ export default async function (call: ApiCall<ReqFbOpen, ResFbOpen>) {
if (call.req.fbId != gh.data.fuben.id) {
let md = await G.mongodb.collection('gonghuiFb').findOne({ ghId: gh.data._id, fbId: call.req.fbId });
let uids = Object.keys(md.rankList);
//let players = await G.redis.gets('user', ...uids.map(uid => [uid] as [string]));
let players = (await G.mongodb.find('user',{uid:{$in: uids}})) as any;
res.rankList = players.map(p => {
return {
@ -22,7 +21,6 @@ export default async function (call: ApiCall<ReqFbOpen, ResFbOpen>) {
});
} else {
let uids = Object.keys(gh.data.fuben.dps);
//let players = await G.redis.gets('user', ...uids.map(uid => [uid] as [string]));
let players = (await G.mongodb.find('user',{uid:{$in: uids}})) as any;
res.rankList = players.map(p => {
return {

View File

@ -2,20 +2,46 @@ import {ApiCall} from "tsrpc";
import {GHManage} from '../../public/gonghui/manage';
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>) {
let arr: ResGetList['list'] = [];
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]));
// 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);
//let uids = gh.players.map(p => p.uid);
//let zhanli = uids.map(u => (zhanlis[u] || 0)).reduce((a, b) => a + b);
let zhanli = await getGongHuiZhanli(gh._id);
arr.push({
gh: gh,
zhanli: zhanli

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

@ -62,7 +62,7 @@ export default async function (call: ApiCall<ReqRepair, ResRepair>) {
} else {
cutItem = R.find(R.whereEq({a: "item", t: "21"}))(need)
}
let rankKfjs = new RankKfjs(6)
let rankKfjs = RankKfjs(6)
rankKfjs.setDataAndCheck({
player: call.conn.gud,
valArr: [await rankKfjs.getRankScore(call.uid) + cutItem.n]

View File

@ -29,12 +29,8 @@ export async function getFinished(conn: BaseConnection, types: string[]) {
else if (type == 'use_attr_rmbmoney') obj[type] = await ActionLog.getRetainLog(conn.uid, 'use_attr_rmbmoney');
else if (type == 'zccg') obj[type] = (await G.mongodb.collection('pata').findOne({ uid: conn.uid }))?.lv || 0;
else if (type == 'equip_star_5') {
//let equips = await G.redis.get('equip', conn.uid);
//obj[type] = Object.values(equips).filter(e => e.star >= 5).length;
obj[type] = await G.mongodb.collection('equip').count({ uid: conn.uid, star: { $gte: 5 } });
} else if (type == 'peijian_colour_5') {
//let peijians = await G.redis.get('peijian', conn.uid);
//obj[type] = Object.values(peijians).filter(p => G.gc.peijian[p.peijianId].colour >= 5).length;
obj[type] = await G.mongodb.collection('peijian').count({ uid: conn.uid, peijianId: { $in: peijianGteColor5ID } });
}
}

View File

@ -1,18 +1,16 @@
import { ApiCall } from "tsrpc";
import { Rank } from '../../../public/rank/rank';
import { ReqOpen, ResOpen } from "../../../shared/protocols/hbzb/jfs/PtlOpen";
import { PublicShared } from '../../../shared/public/public';
import { getHbzbData, getMyRank, getToper200RankUid, updateHbzbCrossUser } from "./fun";
import {ApiCall} from "tsrpc";
import {Rank} from '../../../public/rank/rank';
import {ReqOpen, ResOpen} from "../../../shared/protocols/hbzb/jfs/PtlOpen";
import {PublicShared} from '../../../shared/public/public';
import {getHbzbData, getMyRank, getToper200RankUid, updateHbzbCrossUser} from "./fun";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
//查看本地数据库里,刷出来的玩家数据
let dbData = await getHbzbData(call.uid );
let dbData = await getHbzbData(call.uid);
let data: typeof dbData.data = dbData?.data || {} as any;
if (dbData == null) {
//如果没有,则同步到跨服
await updateHbzbCrossUser(await call.conn.getDefaultFightData(), true);
}
//如果没有,则同步到跨服
await updateHbzbCrossUser(await call.conn.getDefaultFightData(), dbData == null);
if (!data.refreshTime || data.refreshTime < PublicShared.getToDayZeroTime()) {
data.winNum = 0;
@ -26,24 +24,27 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
//积分赛时的排行榜,是本服积分排序
data.jifen = 0;
//但是刷出来的对手,是跨服的玩家
let callRes = await G.clientCross.callApi('hbzb/jfs/GetEnemy', { uid: call.uid, auto: true });
if (!callRes.isSucc){
let callRes = await G.clientCross.callApi('hbzb/jfs/GetEnemy', {uid: call.uid, auto: true});
if (!callRes.isSucc) {
//todo 健壮性处理
return call.errorCode(-4)
}
if (callRes.res.enemy.length)
data.enemy = callRes.res.enemy.map(e => { return { ...e, result: null }; });
if (callRes.res?.enemy?.length)
data.enemy = callRes.res.enemy.map(e => {
return {...e, result: null};
});
}
G.mongodb.cPlayerInfo('hbzb').updateOne(
{ uid: call.uid, type: 'hbzb' },
{ $set: { data: data } },
{ upsert: true }
{uid: call.uid, type: 'hbzb'},
{$set: {data: data}},
{upsert: true}
);
}
call.succ({
...data,
enemy: data.enemy || [],
rank: await getMyRank(call.uid)
});
}

View File

@ -1,55 +1,58 @@
/**
* 300
* 100
* 100
* 100
*/
export async function zbsGroup(){
export async function zbsGroup() {
let arr = await G.mongodb.collection("hbzb_user_cross").find(
{ "jifen": { $gt: -999999 } }
).sort(
{ "data.player.cTime": -1 }
).project({
uid:1,
jifen:1
}).toArray();
{"jifen": {$gt: -999999}}
).project({
uid: 1,
jifen: 1,
'data.player.cTime': 1
}).toArray();
// 移除mongo查询里的排序↑会造成内存超出报错
// 在内存里按照玩家注册时间相近的排序分组
R.sort((a, b) => b.data.player.cTime - a.data.player.cTime)
//有积分的玩家总数
let groups = [];
let currGroup = [];
arr.map((u,index)=>{
if(currGroup.length >= 300){
arr.map((u, index) => {
if (currGroup.length >= 300) {
//每300个丢一组
groups.push( currGroup );
groups.push(currGroup);
currGroup = [];
}
currGroup.push({uid: u.uid, jifen: u.jifen});
});
//循环完毕后检查余量
if(currGroup.length > 0){
if(currGroup.length >= 100){
if (currGroup.length > 0) {
if (currGroup.length >= 100) {
//如果有100人 就自己一组
groups.push( currGroup );
}else{
groups.push(currGroup);
} else {
//不够100 就合到前一组
groups[groups.length] = (groups[groups.length]||[]).concat(currGroup);
groups[groups.length] = (groups[groups.length] || []).concat(currGroup);
}
currGroup = [];
}
//循环groups里的数据对每一组里按jifen降序排序然后给每个玩家分组
groups.map((group,groupIndex)=>{
group.sort((a,b)=>{
groups.map((group, groupIndex) => {
group.sort((a, b) => {
return b.jifen - a.jifen;
});
for(let i=0;i<group.length;i++){
for (let i = 0; i < group.length; i++) {
G.mongodb.collection("hbzb_user_cross").updateOne(
{ uid: group[i].uid },
{uid: group[i].uid},
{
$set: {
"zbsgroup": "group"+(groupIndex+1),
"rank":(i+1),
"zbsgroup": "group" + (groupIndex + 1),
"rank": (i + 1),
}
}
)
@ -60,51 +63,51 @@ export async function zbsGroup(){
/**
*
*/
export async function getZbsRankList(uid?: string, _zbsgroup?: string) : Promise<{ myRank: any; rankList: any[]; }> {
export async function getZbsRankList(uid?: string, _zbsgroup?: string): Promise<{ myRank: any; rankList: any[]; }> {
let myData;
let zbsgroup = _zbsgroup;
if(uid){
myData = await G.crossmongodb.collection("hbzb_user_cross").findOne({uid:uid});
if(!myData || !myData?.zbsgroup)return null;
if (uid) {
myData = await G.crossmongodb.collection("hbzb_user_cross").findOne({uid: uid});
if (!myData || !myData?.zbsgroup) return null;
zbsgroup = myData?.zbsgroup;
}
let arr = await G.crossmongodb.collection("hbzb_user_cross").find(
{ "zbsgroup": zbsgroup }
{"zbsgroup": zbsgroup}
).sort(
{ "rank": 1 }
{"rank": 1}
).limit(100).toArray();
let rank = {
"myRank":{},
"rankList" : []
"myRank": {},
"rankList": []
}
let myRank = -1;
arr.map((u,index)=>{
rank.rankList.push( {
arr.map((u, index) => {
rank.rankList.push({
player: ((u.data) as any).player || {},
roles: ((u.data) as any).roles || {},
rank : (index+1),
rank: (index + 1),
//兼容前端
valArr: [ (index+1) ]
valArr: [(index + 1)]
});
if(u.uid == uid){
if (u.uid == uid) {
myRank = rank.rankList.length;
rank.myRank = {
player: ((u.data) as any).player || {},
roles: ((u.data) as any).roles || {},
rank : (index+1),
rank: (index + 1),
//兼容前端
valArr: [ (index+1) ]
valArr: [(index + 1)]
};
}
})
return rank;
}

View File

@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
}
} else if (call.req.state == 'change') {
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);
}
if (fightHeros.includes(hero.heroId.toString())) return call.errorCode(-2);
@ -57,6 +57,8 @@ export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
}
fightHeros.push(hero.heroId.toString());
fightHeros = await checkFightHerosAndFix(call.uid, heroPos, fightHeros)
Wjjl.setVal(call.uid, 'fight_hero_colour_4', fightHeros.map(id => G.gc.hero[id].colour).filter(c => c >= 4).length);
let checkMatrixPos = HeroFun.checkMatrixPosAndChange(call, heroPos, matrixPos)
@ -65,4 +67,12 @@ export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
call.conn.refreshPower();
kfjsFun.setHeroLvCount(call)
}
async function checkFightHerosAndFix(uid, heroPos, fightHeros) {
if (fightHeros.length == R.values(heroPos).length) {
return fightHeros
}
let heros = await HeroFun.getHeros({uid}, R.values(heroPos));
return heros.map(i => i.heroId)
}

View File

@ -1,32 +1,37 @@
import { ApiCall } from "tsrpc";
import { RedisCollections2 } from '../../module/redis';
import { ReqGetList, ResGetList } from "../../shared/protocols/hero/PtlGetList";
import {ApiCall} from "tsrpc";
import {RedisCollections2} from '../../module/redis';
import {ReqGetList, ResGetList} from "../../shared/protocols/hero/PtlGetList";
import {PeijianShared} from "../../shared/public/peijian";
export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let list: ResGetList['list'] = {};
let kvList: k_v<RedisCollections2['hero']> = {};
let arrList = await G.mongodb.collection('hero').find({ uid: call.uid }).toArray();
//let kvList: k_v<RedisCollections2['hero']> = {};
let arrList = await G.mongodb.collection('hero').find({uid: call.uid}).toArray();
let heroCon = G.gc.hero;
let color = {};
let maxherolv = 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 > maxherolv) maxherolv = v.lv;
if (!color[heroCon[v.heroId].colour]) color[heroCon[v.heroId].colour] = 0;
color[heroCon[v.heroId].colour] += 1;
});
await checkDataAndFix(call, list)
// 记录玩家最大等级,颜色相关数据 注册任务用
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' },
{ $set: { maxherolv: maxherolv, herocolor: color } }, { upsert: true });
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'},
{$set: {maxherolv: maxherolv, herocolor: color}}, {upsert: true});
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 { uid, _id, type, ...heros } = (recLshd || {});
let recLshd = await G.mongodb.collection('playerInfo', 'lshd_hero').findOne({
uid: call.conn.uid,
type: 'lshd_hero'
});
let {uid, _id, type, ...heros} = (recLshd || {});
call.conn.lshd.hero = heros || {};
@ -34,6 +39,66 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
list: list,
pos: call.conn.heroPos,
lshd: heros || {},
gbzj: (await G.mongodb.cPlayerInfo('gbzj').findOne({ uid: call.uid, type: 'gbzj' }))?.rec || {}
gbzj: (await G.mongodb.cPlayerInfo('gbzj').findOne({uid: call.uid, type: 'gbzj'}))?.rec || {}
});
}
/**
*
* @param call
* @param list
*/
async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
try {
// 修复配件数据
let peijianids = [];
Object.values(list).map(hero => {
hero.peijian && Object.values(hero.peijian).map(
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
)
});
let peijians = (await G.mongodb.collection("peijian").find(
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
let shiwuIds = R.flatten(R.values(list).map(hero => R.values(hero.shiwu).map(i => G.mongodb.conversionId(i._id))))
let shiwus = (await G.mongodb.collection("shiwu").find(
{uid: call.uid, _id: {$in: shiwuIds}}, {projection: {_id: 1}}
).toArray()).map(i => G.mongodb.conversionId(i._id));
let peijianChanges = {};
let shiwuChanges = {};
Object.values(list).map(hero => {
for (let pos in hero.peijian) {
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
hero.peijian[pos] = "";
peijianChanges[hero._id] = hero.peijian;
}
}
for (let pos in hero.shiwu) {
if (!shiwus.includes(hero.shiwu[pos]._id)) {
hero.shiwu = R.omit([pos], hero.shiwu)
shiwuChanges[hero._id] = hero.shiwu;
}
}
})
for (let oid in peijianChanges) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
)
}
for (let oid in shiwuChanges) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {shiwu: shiwuChanges[oid]}}
)
}
} catch (e) {
console.log('======修复英雄配件和饰物报错====',e)
}
}

View File

@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqJinJie, ResJinJie, ServiceType>)
let selectHeros: ResGetList['list'][''][] = [];
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);
selectHeros.push(_hero);
}

View File

@ -36,23 +36,3 @@ export default async function (call: ApiCall<ReqLvUp, ResLvUp, ServiceType>) {
kfjsFun.setHeroLvCount(call)
}
// export default async function (call: ApiCall<ReqLvUp, ResLvUp, ServiceType>) {
// let hero = await G.redis.get('hero', call.uid, call.req.id);
// if (!hero) return call.errorCode(-1);
// if (hero.lv >= call.conn.gud.lv * 3) return call.errorCode(-2);
//
// let need = HeroShared.getHeroLvUpNeed(hero.heroId, hero.lv);
// await PlayerFun.checkNeedIsMeet(call, need);
// await PlayerFun.cutNeed(call, need);
// await HeroFun.changeHeroAttr(call, hero, {
// lv: hero.lv + 1
// });
// event_cszl_record(call.conn.gud, hero.heroId, hero.lv, 'lv')
//
// HongDianChange.sendChangeKey(call.uid, ['taskhd', 'huodonghd']);
//
// call.succ({ lv: hero.lv });
// }

View File

@ -0,0 +1,20 @@
import { ApiCall } from "tsrpc";
import { ReqTakeOff, ResTakeOff } from "../../shared/protocols/heroskin/PtlTakeOff";
import { HeroFun } from "../../public/hero";
export default async function (call: ApiCall<ReqTakeOff, ResTakeOff>) {
let hero = await HeroFun.getHero(call, call.req.heroOid);
if (!hero) { // 英雄不存在
call.error(lng.hero_1);
return;
}
if (!hero.skin) { // 没有穿戴皮肤
call.error(lng.hero_22);
return;
}
await HeroFun.changeHeroAttr(call, hero, { skin: "" });
call.succ({});
}

View File

@ -0,0 +1,38 @@
import { ApiCall } from "tsrpc";
import { PlayerFun } from "../../public/player";
import { ReqUplv, ResUplv } from "../../shared/protocols/heroskin/PtlUplv";
import HeroSkinFun from "../../public/heroskin";
export default async function (call: ApiCall<ReqUplv, ResUplv>) {
let skin = HeroSkinFun.getHeroSkin(call);
if (!skin[call.req.skid]) {// 皮肤未获得
call.error(lng.hero_20);
}
let cur_lv = skin[call.req.skid];
let skinconf = G.gc.heroSkin[call.req.skid];
let need = [];
for (let i = 0; i < call.req.lv; i++) {
need = need.concat(
G.gc.heroSkinLv[skinconf.colour][cur_lv + i].need
)
let conf = G.gc.heroSkin[call.req.skid];
need.push({ a: "item", "t": conf.heroId, "n": G.gc.heroSkinLv[skinconf.colour][cur_lv + i].suipian });
}
// 检测消耗
await PlayerFun.checkNeedIsMeet(call, need);
// 扣除消耗
await PlayerFun.cutNeed(call, need);
// 更新等级
skin[call.req.skid] = cur_lv + call.req.lv;
// 更新skinlv
await HeroSkinFun.updateHeroSkinLv(call, { [call.req.skid]: cur_lv + call.req.lv });
call.succ({});
}

View File

@ -0,0 +1,28 @@
import { ApiCall } from "tsrpc";
import { HeroFun } from "../../public/hero";
import { ReqWear, ResWear } from "../../shared/protocols/heroskin/PtlWear";
import HeroSkinFun from "../../public/heroskin";
export default async function (call: ApiCall<ReqWear, ResWear>) {
let hero = await HeroFun.getHero(call, call.req.heroOid);
if (!hero) { // 英雄不存在
call.error(lng.hero_1);
return;
}
let skin = HeroSkinFun.getHeroSkin(call);
if (!skin || !skin[call.req.skid]) { // 皮肤不存在
call.error(lng.hero_20);
return;
}
let skinconf = G.gc.heroSkin[call.req.skid];
if (skinconf.heroId != hero.heroId) { // 皮肤不属于该英雄
call.error(lng.hero_21);
return;
}
await HeroFun.changeHeroAttr(call, hero, { skin: call.req.skid });
call.succ({});
}

View File

@ -14,11 +14,14 @@ import {PublicShared} from '../../shared/public/public';
import {md_redPoint} from '../gongyu/mingdao/ApiOpen';
import {HongDianFun, HuoDongHongDianFun} from "./fun";
import {FunWeiXiuChang} from "../../public/weixiuchang";
import {getShouChongRedPoint} from "../event/shouchong/ApiReceive";
import {LeiChongLiBaoGetHongDian} from "../event/leichonglibao/ApiReceive";
import { playerCanReceive } from '../event/payForDiamond/ApiCanReceive';
const defaultKeys: hongdianKey[] = ['jiuba', 'jiaotang', 'shouchong', 'clslhd', 'dixiaqianzhuanghd', 'gonghuihd', 'hbzbhd', 'jjchd', 'taskhd',
'xstaskhd', 'lingzhulaixihd', 'dxlthd', 'wzcjhd', 'slzdhd', 'qjzzdhd', 'kuangdonghd', 'qiandaohd', 'kaifukuanghuanhd', 'jijinhd', 'zhuishalinghd',
'yibaichouhd', 'huobanzhaomuhd', 'qirileichonghd', 'jierihd', 'kbzzhd', 'wzryhd', 'yuedujijin', 'mingdao', 'patahd',
'heishihd', 'huodonghd', 'renown', 'weixiuchang', 'kaifujingsai', 'zhoumolibao'];
'heishihd', 'huodonghd', 'renown', 'weixiuchang', 'kaifujingsai', 'zhoumolibao', 'pobinglibao', 'leichonglibao', 'payForDiamond'];
export default async function (call: ApiCall<ReqGet, ResGet>) {
@ -36,7 +39,7 @@ export default async function (call: ApiCall<ReqGet, ResGet>) {
res[key] = {show: (!db || toDayZeroTime >= db.freeTime) ? true : false};
break;
case 'shouchong':
// res[key] = await getShouChongRedPoint(call);
res[key] = await getShouChongRedPoint(call);
break;
case 'dixiaqianzhuanghd':
res[key] = await DiXiaQianZhuangFun.getHongDian(call);
@ -162,6 +165,13 @@ export default async function (call: ApiCall<ReqGet, ResGet>) {
case 'zhoumolibao':
res[key] = await HongDianFun.zhoumolibao(call);
break;
case "leichonglibao":
res[key] = await LeiChongLiBaoGetHongDian(call)
break;
case 'payForDiamond':
const receiveResult = await playerCanReceive(call, false);
res[key] = { show: receiveResult && receiveResult.result };
break;
}
}
}

View File

@ -221,27 +221,6 @@ export class HongDianFun {
let prize = G.gc.pata[_myData.lv - 1]?.sdprize;
_res.val.saodang.show = max - (_myData.saodangNum || 0) > 0 && !!prize
_res.show = _res.show || _res.val.saodang.show
// 商店判断
// 个人爬塔商店购买情况
// let shopData = await G.redis.get('shop', call.uid, '7'); // 商店编号7未理清商店id存放的数据表后续该出尽量改为数据库读取
// 12.12策划确定爬塔id7的商店移除此处商店不再需要红点
// let shopData = await ShopFun.getShopData(call.uid, "7")
// if (shopData) {
// let {buyNum, shopItems} = shopData
// // 获取爬塔商店商品
// for (let index in shopItems) {
// let x = shopItems[index]
// if (x.needZCCG > 0 && x.needZCCG < _myData.lv && (buyNum && !buyNum[index])) {
// // 验证是否达到购买条件
// let isOk = await (await PlayerFun.checkNeedIsMeet(call, x.buyNeed, false)).isOk
// if (isOk) {
// _res.show = true
// _res.val.shopItems.show = true
// }
// }
// }
// }
return _res;
}
@ -290,7 +269,7 @@ export class HongDianFun {
for (let i = 1; i <= 7; i++) {
let prize = kfjsFun.getStatus(i)
if (PublicShared.getOpenServerDay() <= prize.conf.showDay[1]) continue
let rankKfjs = new RankKfjs(i)
let rankKfjs = RankKfjs(i)
let myRank = await rankKfjs.getRankSortByOne(call.uid)
if (prize.type > 0 && !data?.record?.[i] && myRank >= 0) {
canGet[i] = true
@ -327,10 +306,7 @@ export class HuoDongHongDianFun {
hdxq: {}
}
};
let _hdList = []
for (let i = 0; i < 8; i++) {
_hdList.push(...await HuoDongFun.gethdList(call, i + 1))
}
let _hdList = await HuoDongFun.gethdList(call)
// let _hdList = await HuoDongFun.gethdList(call)
for (let index = 0; index < _hdList.length; index++) {
const element = _hdList[index];
@ -364,6 +340,18 @@ export class HuoDongHongDianFun {
// 检测 htype 6 七日登录活动红点
ishd = await this.qiridengluHongDian(call, element)
}
if (element.htype == 8) {
// 检测 htype 8 圣诞活动红点
ishd = await this.christmasHongDian(call, element)
}
if (element.htype == 10) {
// 检测 htype 10 破冰活动红点
ishd = await this.pobinglibao(call, element)
}
if (element.htype == 14) {
// 检测 htype 10 元旦活动红点
ishd = await this.yuandan(call, element)
}
// 此活动有红点
if (ishd.show) {
@ -376,6 +364,65 @@ export class HuoDongHongDianFun {
return _res;
}
/**破冰礼包红点 */
static async pobinglibao(call: ApiCall, _hd: ReqAddHuoDong): Promise<hongdianVal> {
let gift = _hd?.data?.gift?.find(i => i.free == true && !i.payId)
if (gift) return {show: true}
let payIds = _hd?.data?.gift?.filter(i => i.payId).map(i => i.payId)
let payLogs = await PayFun.getPayLogs(call.uid, payIds)
for (let key in payLogs) {
payLogs[key] = payLogs[key]?.filter(i => i.time > _hd.stime && i.time < _hd.etime) || []
}
// 取奖励列表,判断是否有可领取奖励
let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne({
uid: call.uid,
type: `pobinglibao${_hd.hdid}`
})
for (let item of _hd?.data?.gift) {
if (item.free == true && !item.payId) return {show: true}
let payLog = payLogs[item.payId]
if (!payLog.length) continue
let rec = data?.record?.[item.id]?.length
let _payDiff = PublicShared.getDiff(payLog[0].time)
_payDiff = _payDiff > 3 ? 3 : _payDiff
let _endDiff = PublicShared.getDiff(_hd.etime)
if ((rec < _payDiff)) return {show: true}
if ((rec < 3 && _endDiff > 0)) return {show: true}
}
return {show: false}
}
/**元旦活动红点 */
static async yuandan(call: ApiCall, _hd: ReqAddHuoDong): Promise<hongdianVal> {
let gift = _hd?.data?.gift?.find(i => i.free && !i.payId)
// 取奖励列表,判断是否有可领取奖励
let data = await G.mongodb.cEvent(`yuandan${_hd.hdid}`).findOne({uid: call.uid, type: `yuandan${_hd.hdid}`})
if (gift && !data?.gift?.[gift.id]) return {show: true}
if (data?.gameNum < _hd.data.gamefree) return {show: true}
if (!PublicShared.chkSameDate(data?.qiandaoTime || 1, G.time)) {
return {show: true}
}
for (const i in data.taskval) {
if (data?.taskval[i] >= _hd?.data?.task?.[i]?.pval && !data?.taskfinish.find(v => v == i)) {
return {show: true}
}
}
return {show: false}
}
/**开服狂欢红点 */
static async kfkhHongDian(call: ApiCall) {
let _res: hongdianVal = {
@ -609,6 +656,14 @@ export class HuoDongHongDianFun {
if (_mydata?.rec.includes(index)) continue; // 已领取
if (element.gudKey && call.conn.gud[element.gudKey] < element.total) continue; // 未达成
if (!element.gudKey && (_mydata?.rec?.length || 0) < _con.length - 1) continue; // 大奖资格不够
if (element.gudKey == "zhizunyueka") {
let logs = await PayFun.getPayLog(call.uid, "zhizunyueka");
if (logs.length <= 0 || logs.slice(-1)[0].eTime < G.time) {
continue
}
}
_res.show = true;
break;
}
@ -624,7 +679,8 @@ export class HuoDongHongDianFun {
let _con = hdCon.data.tasks;
let db = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType});
let _mydata = db || {sTime: PublicShared.getToDayZeroTime(G.time), recIndex: []};
let payNum = await PayFun.getPayDaysAllPayNum(call.uid, hdCon.stime, hdCon.rtime);
let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, hdCon.stime, hdCon.rtime)) * 10
payNum = payNum - (db?.round || 0) * R.sort((a, b) => b.total - a.total)(hdCon.data.tasks)[0].total
for (let index = 0; index < _con.length; index++) {
const element = _con[index];
if (_mydata.recIndex.includes(index)) continue;
@ -704,7 +760,7 @@ export class HuoDongHongDianFun {
for (let indextask = 0; indextask < Object.keys(_tasks).length; indextask++) {
const elementtask = Object.keys(_tasks)[indextask];
let _tmp = _tasks[elementtask];
if (_tmp.pval <= (_mydata.taskval[elementtask] || 0) && !_mydata.taskfinsih.includes(elementtask)) {
if (_tmp.pval <= (_mydata.taskval[elementtask] || 0) && !_mydata.taskfinish.includes(elementtask)) {
// 任务完成且没有领取
_res.show = true;
return _res;
@ -829,7 +885,7 @@ export class HuoDongHongDianFun {
static async zixuanlibaoHongDian(call: ApiCall, hdCon: ReqAddHuoDong): Promise<hongdianVal> {
let _dbType: `zixuanlibao${number}` = `zixuanlibao${hdCon.hdid}`
let db = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType});
if (!db?.record?.[0]) {
if (!db?.rec) {
return {show: true}
}

View File

@ -4,21 +4,6 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/item/PtlGetList";
import { getItemList } from "../../public/item";
export default async function (call: ApiCall<ReqGetList, ResGetList>) {
// let list: ResGetList['list'] = {};
// let kvList: k_v<RedisCollections2['item']> = {};
// let arrList = await G.mongodb.collection('item').find({ uid: call.uid,num:{$ne:0}}).toArray();
// arrList.forEach(v => {
// let d = G.mongodb.conversionIdObj(v);
// kvList[G.formatRedisKey(d.itemId)] = d;
// list[d.itemId] = d;
// });
//去掉item Redis相关
//G.redis.set('item', call.uid, kvList);
//call.conn.item = list;
let list = await getItemList(call.uid);
call.succ({
list: list

Some files were not shown because too many files have changed in this diff Show More