This commit is contained in:
ciniao 2023-12-14 20:43:33 +08:00
commit 5dea65e51a
28 changed files with 823 additions and 280 deletions

12
oneKeyStartPm2.sh Normal file
View File

@ -0,0 +1,12 @@
git fetch --all && git reset --hard origin/dev && git pull
npm run build_linux
cp src/config.json dist/
pm2 del heijiao_msg_s0
cd dist && pm2 start js_pm2.config.js
pm2 save

View File

@ -8,17 +8,24 @@ import {PlayerFun} from "../../../public/player";
export default async function (call: ApiCall<ReqGame, ResGame>) {
let initCon = await Christmasfun.getCon(call)
let need = initCon[call.req.hdid].data.gameneed;
let freenum = initCon[call.req.hdid].data.gamefree
let addval = initCon[call.req.hdid].data.game[call.req.index];
// 判断消耗是否满足
await PlayerFun.checkNeedIsMeet(call, need);
// 扣除消耗
await PlayerFun.cutNeed(call, need);
let _mydata = await Christmasfun.getMyData(call, call.req.hdid)
// 判断是否有免费配置
if (_mydata.gamenum >= freenum) {
// 判断消耗是否满足
await PlayerFun.checkNeedIsMeet(call, need);
// 扣除消耗
await PlayerFun.cutNeed(call, need);
}
let _setData = {}
_mydata["val"] += addval
_setData["val"] = _mydata["val"]
await Christmasfun.setMyData(call.uid, call.req.hdid, { $set: _setData })
_mydata["gamenum"] += 1
_setData["val"] = _mydata.val
_setData["game"] = _mydata["gamenum"]
await Christmasfun.setMyData(call.uid, call.req.hdid, { $set: _setData})
let changedata = { mydata: _mydata}
// 推送红点
HongDianChange.sendChangeKey(call.uid, ['huodonghd']);

View File

@ -22,13 +22,14 @@ export default async function (call: ApiCall<ReqLiBao, ResLiBao>) {
// 判断是否能购买
return call.error('', { code: -3, message: globalThis.lng.yangchengmubiao_2 })
}
const _select = _mydata.select[lbid] || {}
if (Object.keys(_select).length >= _con.dlz.length) {
let _select = _mydata.select[lbid] || {}
if (Object.keys(_select).length < _con.dlz.length) {
// 判断是否选择奖励了
return call.error('', { code: -3, message: globalThis.lng.yangchengmubiao_2 })
}
let _prize: atn[] = _con.prize
let _prize: atn[] = _con.basep
for (let key in _select) {
_prize.push(_con.dlz[parseInt(key)][_select[key]])
}

View File

@ -9,6 +9,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
// 无此活动
return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 })
}
let _mydata = await Christmasfun.getMyData(call, call.req.hdid)
let changedata = { mydata: _mydata, hdinfo: _hdinfo }
call.succ(changedata);

View File

@ -17,7 +17,7 @@ export default async function (call: ApiCall<ReqQianDao, ResQianDao>) {
for(let i = 0; i < _diff; i++) {
if (_mydata.qiandao.includes(i)) continue
_mydata.qiandao.push(i)
_prize.push(_con[i])
_prize = _prize.concat(_con[i])
}
if (!_prize){

View File

@ -20,12 +20,14 @@ export default async function (call: ApiCall<ReqZhanLingRec, ResZhanLingRec>) {
if (!_mydata.pt.includes(index)){
// 如果普通奖励没有领取
_prize.push(_con.pt)
_prize = _prize.concat(_con.pt)
_mydata.pt.push(index)
}
if (_mydata.pay && !_mydata.gj.includes(index)){
// 如果普通奖励没有领取
_prize.push(_con.gj)
_prize = _prize.concat(_con.gj)
_mydata.gj.push(index)
}
if (!_prize) {

View File

@ -1,11 +1,12 @@
import { strict } from 'assert';
import { ApiCall } from 'tsrpc';
import {ApiCall, BaseConnection} from 'tsrpc';
import { ReqAddHuoDong } from '../../../monopoly/protocols/PtlAddHuoDong';
import { HuoDongFun } from '../../../public/huodongfun';
import { TaskFun } from '../../../public/task';
import { christmas } from '../../../shared/protocols/event/christmas/PtlOpen';
import { PublicShared } from '../../../shared/public/public';
import {player} from '../../../shared/protocols/user/type';
import {PlayerFun} from "../../../public/player";
export class Christmasfun {
/**配置 */
@ -61,6 +62,7 @@ export class Christmasfun {
taskval: await this.getTaskVal(call, hdid),
taskfinish: [],
refresh: G.time,
gamenum: 0,
pt: [],
gj: [],
pay: false,
@ -110,24 +112,54 @@ export class Christmasfun {
mydata.taskfinish = []
mydata.taskval = await this.getTaskVal(call, hdid)
mydata.refresh = G.time
await this.setMyData(call.uid, hdid, { $set: { refresh: mydata.refresh, taskfinish: mydata.taskfinish, taskval: mydata.taskval } })
mydata.gamenum = 0
await this.setMyData(call.uid, hdid, { $set: { refresh: mydata.refresh, taskfinish: mydata.taskfinish, taskval: mydata.taskval, gamenum: mydata.gamenum} })
return mydata
}
static async payChristmas(payid, call: ApiCall) {
let _hd = await HuoDongFun.gethdList(call, 8)
for (let index = 0; index < _hd.length; index++) {
const hdinfo = _hd[index];
const _hdid = hdinfo.hdid
if (payid == hdinfo.data.zlpayid){
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);
}
else{
const libaos = hdinfo.data.libao
for (let index = 0; index < Object.keys(libaos).length; index++){
const lbid = Object.keys(libaos)[index];
let _tmp = libaos[lbid]
if (_tmp['payid'] != payid) continue
let _mydata = await Christmasfun.getMyData(call, _hdid)
let _buyNum = _mydata.libao[lbid] || 0
if (_buyNum >= _tmp["buynum"]) continue
_mydata.libao[lbid] = _buyNum + 1
this.setMyData(call.uid, _hdid, { $set: { libao: _mydata.libao} })
break
}
}
}
}
/**设置任务 */
static async setTaskVal(call: ApiCall, stype: number, val: number, chkCall: Function, chkval: number = 0, isinc: number = 0, alchangeVal: Function, arg) {
let hdids = await this.gethdids(call)
if (hdids.length <= 0) return // 活动过期,不计数
let _initCon = await this.getCon(call)
for (let index = 0; index < hdids.length; index++) {
const hdid = hdids[index];
let _mydata = await Christmasfun.getMyData(call, hdid)
let _tasks = _initCon[hdid].data.task
let _setData = {
let _setData= {
$inc: {},
$set: {}
}
@ -165,4 +197,4 @@ export class Christmasfun {
}
}

View File

@ -20,24 +20,32 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
}
export async function checkResetBuyLog(call: ApiCall) {
export async function getConf(call, args?: { id?: string; payId?: string }) {
let _hd = (await HuoDongFun.gethdList(call, 9))[0]
if (!_hd) return []
if (args?.id) return _hd?.data?.gift?.find(i => i.id == args.id)
if (args?.payId) return _hd?.data?.gift?.find(i => i.payId == args.payId)
return _hd?.data?.gift
}
export async function checkResetBuyLog(call) {
let zeroTime = PublicShared.getToDayZeroTime()
let data = await G.mongodb.cEvent('zhoumolibao').findOne({uid: call.uid, type: 'zhoumolibao'})
if (data.refreshTime && data.refreshTime > zeroTime) return
if (data.refreshTime && data.refreshTime <= zeroTime) {
G.mongodb.cEvent(`zhoumolibao`).updateOne(
{uid: call.uid, type: `zhoumolibao`},
{$set: {record: {}}},
{upsert: true}
)
}
G.mongodb.cEvent(`zhoumolibao`).updateOne(
{uid: call.uid, type: `zhoumolibao`},
{$set: {record: {}}},
{upsert: true}
)
let gifts = await getConf(call)
let _hd = (await HuoDongFun.gethdList(call, 9))[0]
let payIds = _hd?.data?.gift?.filter(i => i.payId)?.map(i => i.payId)
let payIds = gifts.filter(i => i.payId)?.map(i => i.payId)
let payLogs = await PayFun.getPayLogs(call.uid, payIds)
let payLogLength = R.values(payLogs).filter(i => i.time < zeroTime).length
if (payLogLength) {
PayFun.delPayLog(call.uid, payIds.map(i => ({payId: i})))
PayFun.delPayLog(call.uid, payIds.map(i => ({payId: i, val: []})))
}
}

View File

@ -2,6 +2,7 @@ import {ApiCall} from "tsrpc";
import {ReqReceive, ResReceive} from "../../../shared/protocols/event/zhoumolibao/PtlReceive";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqReceive, ResReceive>) {
// 查询活动是否有当前领奖的免费选项
@ -12,14 +13,15 @@ export default async function (call: ApiCall<ReqReceive, ResReceive>) {
// 取奖励列表,判断是否有可领取奖励
let data = await G.mongodb.cEvent('zhoumolibao').findOne({uid: call.uid, type: 'zhoumolibao'})
let rec = data?.record?.[call.req.id]
// if (rec && rec >= gift?.buyNum) return call.errorCode(-2)
if (rec && rec >= gift?.buyNum) return call.errorCode(-2)
await PlayerFun.sendPrize(call, gift.prize);
await G.mongodb.cEvent('zhoumolibao').updateOne({uid: call.uid, type: 'zhoumolibao'}, {
$inc: {[`record.${gift.id}`]: 1},
},{ upsert: true })
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['zhoumolibao']);
}

View File

@ -1,25 +1,25 @@
import { ApiCall } from "tsrpc";
import { DiXiaQianZhuangFun } from "../../public/dixiaqianzhuang";
import { DxltFun } from "../../public/dxlt";
import { GongHuiFun } from "../../public/gonghui/gonghui";
import { JJCFun } from "../../public/jjc";
import { KuangDongfun } from "../../public/kuangdong";
import { LingZhuLaiXifun } from "../../public/lingzhulaixi";
import { SignFun } from "../../public/sign";
import { TaskFun } from "../../public/task";
import { WangZheRongYaofun } from "../../public/wzry";
import { XstaskFun } from "../../public/xstask";
import { ReqGet, ResGet, hongdianKey } from "../../shared/protocols/hongdian/PtlGet";
import { PublicShared } from '../../shared/public/public';
import { getShouChongRedPoint } from '../event/shouchong/ApiReceive';
import { md_redPoint } from '../gongyu/mingdao/ApiOpen';
import { HongDianFun, HuoDongHongDianFun } from "./fun";
import { FunWeiXiuChang } from "../../public/weixiuchang";
import {ApiCall} from "tsrpc";
import {DiXiaQianZhuangFun} from "../../public/dixiaqianzhuang";
import {DxltFun} from "../../public/dxlt";
import {GongHuiFun} from "../../public/gonghui/gonghui";
import {JJCFun} from "../../public/jjc";
import {KuangDongfun} from "../../public/kuangdong";
import {LingZhuLaiXifun} from "../../public/lingzhulaixi";
import {SignFun} from "../../public/sign";
import {TaskFun} from "../../public/task";
import {WangZheRongYaofun} from "../../public/wzry";
import {XstaskFun} from "../../public/xstask";
import {ReqGet, ResGet, hongdianKey} from "../../shared/protocols/hongdian/PtlGet";
import {PublicShared} from '../../shared/public/public';
import {getShouChongRedPoint} from '../event/shouchong/ApiReceive';
import {md_redPoint} from '../gongyu/mingdao/ApiOpen';
import {HongDianFun, HuoDongHongDianFun} from "./fun";
import {FunWeiXiuChang} from "../../public/weixiuchang";
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'];
'heishihd', 'huodonghd', 'renown', 'weixiuchang', 'kaifujingsai', 'zhoumolibao'];
export default async function (call: ApiCall<ReqGet, ResGet>) {
@ -28,13 +28,13 @@ export default async function (call: ApiCall<ReqGet, ResGet>) {
let toDayZeroTime = PublicShared.getToDayZeroTime();
//正常跑完引导的等级
if(call.conn.gud.lv >= 7){
if (call.conn.gud.lv >= 7) {
for (let key of keys) {
switch (key) {
case 'jiuba':
case 'jiaotang':
let db = await G.mongodb.collection('playerInfo', key).findOne({ uid: call.uid, type: key });
res[key] = { show: (!db || toDayZeroTime >= db.freeTime) ? true : false };
let db = await G.mongodb.collection('playerInfo', key).findOne({uid: call.uid, type: key});
res[key] = {show: (!db || toDayZeroTime >= db.freeTime) ? true : false};
break;
case 'shouchong':
res[key] = await getShouChongRedPoint(call);
@ -160,6 +160,9 @@ export default async function (call: ApiCall<ReqGet, ResGet>) {
case 'kaifujingsai':
res[key] = await HongDianFun.kaifujingsai(call);
break;
case 'zhoumolibao':
res[key] = await HongDianFun.zhoumolibao(call);
break;
}
}
}

View File

@ -20,7 +20,7 @@ import {PlayerFun} from "../../public/player";
import kfjsFun from "../../public/kaifujingsai";
import {RankKfjs} from "../../public/rank/rank_kfjs";
import {ShopFun} from "../../public/shop";
import { Christmasfun } from '../event/christmas/fun';
import {Christmasfun} from '../event/christmas/fun';
export class HongDianFun {
/**黑榜争霸红点 */
@ -301,6 +301,18 @@ export class HongDianFun {
return {show: true, val: canGet}
}
/**周末礼包 */
static async zhoumolibao(call: ApiCall): Promise<hongdianVal> {
let _hd = (await HuoDongFun.gethdList(call, 9))[0]
let gift = _hd?.data?.gift?.find(i => i.free)
if (!gift) return {show: false}
let data = await G.mongodb.cEvent('zhoumolibao').findOne({uid: call.uid, type: 'zhoumolibao'})
let rec = data?.record?.[gift.id]
if (rec && rec >= gift?.buyNum) return {show: false}
return {show: true}
}
}
@ -708,10 +720,11 @@ export class HuoDongHongDianFun {
if (_buyNum < _tmp.buynum) {
_res.show = true;
return _res;
}}
}
}
let _diff = PublicShared.getDiff(stime)
// 循环判断是否有可以领取的
for(let i = 0; i < _diff; i++) {
for (let i = 0; i < _diff; i++) {
if (_mydata.qiandao.includes(i)) continue
_res.show = true;
return _res;
@ -724,15 +737,15 @@ export class HuoDongHongDianFun {
return _res;
}
let zhanling = _hdCon.zhanling
for (let indexzhanling = 0; indexzhanling < zhanling.length; indexzhanling++){
if (!_mydata.pt.includes(indexzhanling)){
for (let indexzhanling = 0; indexzhanling < zhanling.length; indexzhanling++) {
if (!_mydata.pt.includes(indexzhanling)) {
_res.show = true;
return _res;
}
if (_mydata.pay && !_mydata.gj.includes(indexzhanling)){
_res.show = true;
if (_mydata.pay && !_mydata.gj.includes(indexzhanling)) {
_res.show = true;
return _res;
}
}
}
return _res;

View File

@ -9,6 +9,7 @@ import {ReqLottery, ResLottery} from "../../shared/protocols/jiuba/PtlLottery";
import {PublicShared} from '../../shared/public/public';
import {HongDianChange} from '../hongdian/fun';
import {RankKfjs} from "../../public/rank/rank_kfjs";
import {PushGiftFun} from "../../public/pushgift";
export default async function (call: ApiCall<ReqLottery, ResLottery>) {
@ -142,4 +143,8 @@ export default async function (call: ApiCall<ReqLottery, ResLottery>) {
valArr: [await rankKfjs.getRankScore(call.uid) + call.req.type]
});
// 十连抽推送礼包
if (call.req.type == 10) {
PushGiftFun.chkRecruitGift(call.uid)
}
}

View File

@ -0,0 +1,29 @@
import {ApiCall} from "tsrpc";
import {ReqOpen, ResOpen} from "../../shared/protocols/pushgift/PtlOpen";
import {PushGiftFun} from "../../public/pushgift";
import {Gift} from "../../module/collection_pushgift";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let res: ResOpen = {gifts: []};
// 过滤过期的礼包 和购买完毕的礼包
(await PushGiftFun.getGift(call.uid)).forEach((gift) => {
if (gift.passTime > G.time && chkBuyNum(gift.id, gift)) {
res.gifts.push(gift)
}
})
call.succ(res)
}
function chkBuyNum(gift_id: string, gift_info: Gift) {
let conf = G.gc.tuisonglibao[gift_id];
for (let i = 0; i < conf.payId.length; i++) {
let pay = G.gc.pay[conf.payId[i]];
if (pay.buys > 0 && gift_info.buy[i] < pay.buys) {
return true
}
}
return false
}

View File

@ -15,6 +15,8 @@ import { ZhanLingTasks } from './public/zhanling';
import { player } from './shared/protocols/user/type';
import { PublicShared } from './shared/public/public';
import { setGud } from './public/gud';
import {checkResetBuyLog} from "./api_s2c/event/zhoumolibao/ApiOpen";
import {Christmasfun} from "./api_s2c/event/christmas/fun";
export type gEventType = {
/**玩家断开连接 */
@ -22,7 +24,7 @@ export type gEventType = {
/**玩家修改名字 */
PLAYER_CHANGE_NAME: (gud: player, name: string) => void;
/**玩家充值 */
PLAYER_PAY: (gud: player, payId: string, type: 'user' | 'system') => void;
PLAYER_PAY: (gud: player, payId: string, type: 'user' | 'system', call) => void;
/**玩家发生api调用 */
API_CALL: (node: { call: ApiCall, return: ApiReturn<any>; }) => void;
/**玩家每日首次登陆 */
@ -165,13 +167,14 @@ export function addListener() {
}
});
G.on('PLAYER_PAY', async (player, payId, payArgs) => {
G.on('PLAYER_PAY', async (player, payId, payArgs,call) => {
let conf: any = await PayFun.getConf(payId, payArgs);
ActionLog.addDayLog(player.uid, { key: 'pay', val: conf.payExp[0].n });
ActionLog.addRetainLog(player.uid, { key: 'pay', val: conf.payExp[0].n });
if (payId == G.gc.zhanling.payId) payZhanLing(player);
//圣诞节活动充值
Christmasfun.payChristmas(payId, call);
let payEmailConf = G.gc.payEmail[payId] as _gcType['payEmail']['caifutequan'];
if (payEmailConf?.length > 0) {
let sendEmailConfs = payEmailConf;
@ -209,6 +212,8 @@ export function addListener() {
G.emit("Class_task_135", 'Class_task_135', call, 1, 0);
// 七日登录活动计数
qiRiDengLuAddDay(call);
// 周末礼包检测刷新
checkResetBuyLog(call);
});

View File

@ -1773,6 +1773,24 @@ type gc_yuyuemail = {
'prize': { "a": string, "t": string, "n": number, [x: string]: any }[]
};
type gc_push_gift = {
[k: string]: {
/**礼包id*/
id: number
/**礼包类型*/
type: number
/**礼包参数*/
num: any[]
/**购买id*/
payId: string[]
/**持续时间*/
time: number
/**冷却时间*/
displayCD: number
/**显示返利比*/
scale: number
}
}
type gcType = {
[key: string]: any
@ -1922,6 +1940,7 @@ type gcType = {
kfcb_content: gc_kfcb_content
kfcb_prize: gc_kfcb_prize
yuyuemail: gc_yuyuemail
tuisonglibao: gc_push_gift
}

View File

@ -5,7 +5,7 @@ export default {
/**是否开发模式 */
debug: true,
/**消息服socket端口*/
msgPort: 7778,
msgPort: 7785,
/**http端口 msg服专用*/
// httpPort: 7779,
/**跨服socket端口 */
@ -13,7 +13,7 @@ export default {
/**跨服 ws url */
corssWsUrl: "ws://10.0.1.20:10003",
/**服务器id */
serverId: 0,
serverId: 1001,
/**redis url */
redisUrl: 'redis://:lyMaple525458@10.0.1.20:6379/0',
/**mongodb url */
@ -27,7 +27,7 @@ export default {
/**服务器时间 */
time: '',
/**开服时间 */
openTime: '2022-10-10 1:0:0',
openTime: '2023-12-11 1:0:0',
/**项目名称 */
projectName: 'heijiao',
/**加密key */

View File

@ -0,0 +1,13 @@
import {ObjectId} from "mongodb";
import {ResOpen} from "../shared/protocols/pushgift/PtlOpen";
export type Gift = {
id: string
uid: string
buy: number[]
ctime: number
passTime: number
ext_data: { [key: string]: any }
}
export type CollectionPushGift = Gift & { _id: ObjectId };

View File

@ -59,6 +59,7 @@ import {CollectionPlayerBehavior} from "./collection_player_behavior";
import {CollectionRmbuse} from "./collection_rmbuse";
import {CollectionFightLog} from "./collection_fightLog";
import {CollectionShop} from "./collection_shop";
import {CollectionPushGift} from "./collection_pushgift";
export type MongodbCollections = {
user: CollectionUser;
@ -131,4 +132,5 @@ export type MongodbCollections = {
rmbuse: CollectionRmbuse
fightLog: CollectionFightLog
shop: CollectionShop
pushgift:CollectionPushGift
};

View File

@ -9,6 +9,7 @@ import {HeroFun} from './hero';
import {UserFun} from './user';
import {re, string} from "mathjs";
import {getGud} from './gud';
import {PushGiftFun} from "./pushgift";
type fightType = 'tanxian' | 'pata' | 'jjc' | 'gbtx' | 'qjzzd' | 'meirishilian' | 'wzrycross';
@ -86,9 +87,16 @@ export class FightFun {
/**挑战竞技场 */
static async fightJJc(call: ApiCall, rankInfo: rankInfo) {
if (rankInfo.player.uid.indexOf('npc_') != -1) return await this.fightNpc(call, G.gc.jjc_npc[rankInfo.player.uid].npcId, 'jjc', await this.getPlayerFightData(call.conn.uid));
return this.fight([await this.getPlayerFightData(call.conn.uid), await this.getPlayerFightData(rankInfo.player.uid)]);
let result = this.fight([await this.getPlayerFightData(call.conn.uid), await this.getPlayerFightData(rankInfo.player.uid)]);
// 竞技场 战败触发推送礼包
if (result.winSide != 0) {
PushGiftFun.chkLoseGift(call.uid)
}
return result
}
/**挑战npc */
@ -106,7 +114,13 @@ export class FightFun {
let npc = formatNpcData(npcId);
return this.fight([my, npc], 30, 'pve');
let result = this.fight([my, npc], 30, 'pve');
// 主线 爬塔 战败触发推送礼包
if (result.winSide != 0 && ["tanxian", "pata"].includes(type)) {
PushGiftFun.chkLoseGift(data[0].player.uid)
}
return result
}
/**

View File

@ -9,6 +9,7 @@ import {HuoDongFun} from './huodongfun';
import {call, PlayerFun} from './player';
import {number} from "mathjs";
import {getGud} from './gud';
import {getConf as zmlbGetConf} from '../api_s2c/event/zhoumolibao/ApiOpen';
async function checkPayIsActive(payId: string, logs: payLog[], payArgs) {
let conf: any = await this.getConf(payId, payArgs);
@ -98,7 +99,7 @@ export class PayFun {
}).toArray();
if (payIds?.length) {
return Object.fromEntries(payIds.map(id => [id, logs[id] || []]));
return Object.fromEntries(payIds.map(id => [id, logs.find(i => i.key == id)?.values || []]));
}
let allLogs = {}
logs.map(i => allLogs[i.key] = i.values)
@ -176,13 +177,6 @@ export class PayFun {
let conf: any = await this.getConf(payId, payArgs);
let isReplaceConf = await this.checkBuysAfterPay(uid, payId, conf, payArgs)
if (isReplaceConf) {
let prizePayId = `zuanshi_${conf.money}`
payArgs.toPrizePayId = prizePayId
conf = this.replacePrizeToChongzhi(prizePayId, conf)
}
let prize = [...conf.prize];
//let player = await G.redis.get('user', uid);
let player = await getGud(uid);
@ -225,6 +219,22 @@ export class PayFun {
}
});
}
if (payId.indexOf('wkdlibao') != -1) {
let call = this.getCall(player)
let conf = await zmlbGetConf(call, {payId})
prize.push(...conf.prize)
}
let isReplaceConf = await this.checkBuysAfterPay(uid, payId, conf, payArgs)
if (isReplaceConf) {
let prizePayId = `zuanshi_${conf.money}`
payArgs.toPrizePayId = prizePayId
conf = this.replacePrizeToChongzhi(prizePayId, conf)
prize = [...conf.prize]
}
await PlayerFun.sendPrize(call, prize);
await PlayerFun.addAttr(call, conf.payExp);
if (payId == 'G123SendGift') {
@ -261,7 +271,7 @@ export class PayFun {
}
});
G.emit('PLAYER_PAY', player, payId, payArgs);
G.emit('PLAYER_PAY', player, payId, payArgs, call);
G.emit("Class_task_116", 'Class_task_116', call, 1, 0);
}
@ -362,12 +372,20 @@ export class PayFun {
}
if (conf.buys > 0 && buyLog.length >= conf.buys) return G.server.sendMsgByUid(player.uid, 'msg_s2c/PayResult', {code: -1});
if (conf.time != -1 && buyLog.slice(-1)[0]?.eTime > G.time && conf.buys == 0) return G.server.sendMsgByUid(player.uid, 'msg_s2c/PayResult', {code: -2});
// todo 没看懂这个判断针对什么支付不支持周末礼包这个类型的限购所以加上判断payId.indexOf('wkdlibao') == -1
if (conf.time != -1 && buyLog.slice(-1)[0]?.eTime > G.time && conf.buys == 0 && payId.indexOf('wkdlibao') == -1) {
return G.server.sendMsgByUid(player.uid, 'msg_s2c/PayResult', {code: -2});
}
if (payId.indexOf('136Gift') != -1 && payId != '136Gift1') {
buyLog = await this.getPayLog(player.uid, '136Gift1');
if (buyLog.slice(-1)[0]?.eTime > G.time) return G.server.sendMsgByUid(player.uid, 'msg_s2c/PayResult', {code: -3});
}
if (payId.indexOf('wkdlibao') != -1) {
let call = this.getCall(player)
let conf = await zmlbGetConf(call, {payId})
if (buyLog.length && buyLog.length >= conf.buyNum) return G.server.sendMsgByUid(player.uid, 'msg_s2c/PayResult', {code: -1});
}
}
if (G.config.debug) {

View File

@ -14,9 +14,10 @@ import {PublicShared} from '../shared/public/public';
import {HeroFun} from './hero';
import {ShiwuFun} from './shiwu';
import {UserFun} from './user';
import { getItemByItemId, getItemNum } from './item';
import { getGud, setGud } from './gud';
import {getItemByItemId, getItemNum} from './item';
import {getGud, setGud} from './gud';
import {addGameLog} from "../gameLog";
import {PushGiftFun} from "./pushgift";
export type call = {
@ -35,7 +36,7 @@ export type call = {
};
service: { name: string };
addEventMsg: ApiCall['addEventMsg'];
req: { }
req: {}
};
export class PlayerFun {
@ -66,6 +67,8 @@ export class PlayerFun {
if (has < atn.n) {
if (err) {
// 消耗不足 触发推送礼包
PushGiftFun.chkItemGift(call.uid, atn)
throw new TsrpcError('', {code: -104, atn: atn});
} else {
return {isOk: false, atn: atn};
@ -143,15 +146,15 @@ export class PlayerFun {
shiwu.length > 0 && this.addShiwu(call, shiwu),
peijian.length > 0 && this.addPeijian(call, peijian)
]);
return prizeList;
};
//attr里的指定字段的值不能小于0
static fixAttrLteZero(t:string, val:number){
if(['jinbi','rmbmoney','payExp','nexp'].includes(t) && val < 0){
static fixAttrLteZero(t: string, val: number) {
if (['jinbi', 'rmbmoney', 'payExp', 'nexp'].includes(t) && val < 0) {
return 0
}else{
} else {
return val;
}
}
@ -189,6 +192,16 @@ export class PlayerFun {
// 修改属性应在相关奖励领取之前,否则奖励内获取的用户数据是旧数据
// await this.changeAttr(call.conn.uid, change);
call.addEventMsg('msg_s2c/PlayerChange', change);
// 等级改变 触发推送礼包
if (change["lv"]) {
PushGiftFun.chkLvGift(call.uid, change["lv"])
}
// 关卡改变 触发推送礼包
if (change["mapId"]) {
PushGiftFun.chkLevelGift(call.uid, change["mapId"])
}
}
static async changeAttrLog(uid: string, change, atn, before) {
@ -207,9 +220,9 @@ export class PlayerFun {
static async changeAttr(uid: string, change: Partial<player>) {
//for (let k in change) {
//G.redis.set('user', uid, k as any, change[k]);
//G.redis.set('user', uid, k as any, change[k]);
//}
setGud(uid,change);
setGud(uid, change);
G.mongodb.collection('user').updateOne({uid: uid}, {$set: change});
@ -290,7 +303,11 @@ export class PlayerFun {
G.mongodb.collection('item').updateOne(upObj.filter, upObj.update, upObj.options);
call.addEventMsg('msg_s2c/ItemChange', atn.t, data);
addGameLog(call.uid, "_itemChange", {"additem":1}, {"filter": upObj.filter, "update": upObj.update, "options": upObj.options})
addGameLog(call.uid, "_itemChange", {"additem": 1}, {
"filter": upObj.filter,
"update": upObj.update,
"options": upObj.options
})
} else {
if (item.num + atn.n <= 0) {
await Promise.all([
@ -302,13 +319,13 @@ export class PlayerFun {
//await G.redis.del('item', call.uid, atn.t);
//await G.mongodb.collection('item').deleteOne({uid: call.uid, itemId: atn.t});
call.addEventMsg('msg_s2c/ItemChange', atn.t, {num: 0});
addGameLog(call.uid, "_itemChange",{"delitem":1}, {"itemId": atn.t})
addGameLog(call.uid, "_itemChange", {"delitem": 1}, {"itemId": atn.t})
} else {
await Promise.all([
////去掉item Redis相关
//G.redis.set('item', call.uid, atn.t, 'lastTime', upObj.update.$set.lastTime),
//G.redis.numIncrBy('item', call.uid, atn.t, 'num', atn.n),
G.mongodb.collection('item').updateOne(upObj.filter, upObj.update, upObj.options)
]);
// await G.redis.set('item', call.uid, atn.t, 'lastTime', upObj.update.$set.lastTime);
@ -318,7 +335,12 @@ export class PlayerFun {
num: item.num + atn.n,
lastTime: upObj.update.$set.lastTime
});
addGameLog(call.uid, "_itemChange",{"attritem":1}, {"filter": upObj.filter, "update": upObj.update, "options": upObj.options,newNum:item.num + atn.n})
addGameLog(call.uid, "_itemChange", {"attritem": 1}, {
"filter": upObj.filter,
"update": upObj.update,
"options": upObj.options,
newNum: item.num + atn.n
})
}
}
}
@ -344,7 +366,7 @@ export class PlayerFun {
}).reduce((a, b) => a.concat(b));
let result = await G.mongodb.collection('equip').insertMany(insertData);
addGameLog(call.uid, "_addEquip",{}, insertData)
addGameLog(call.uid, "_addEquip", {}, insertData)
insertData.forEach((v, key) => {
let id = result.insertedIds[key].toHexString();
@ -391,7 +413,7 @@ export class PlayerFun {
G.mongodb.collection('equip').deleteOne({uid: call.uid, _id: new ObjectId(_id)});
call.addEventMsg('msg_s2c/EquipChange', _id, {num: 0});
addGameLog(call.uid, "_cutEquip",{}, {_id:_id})
addGameLog(call.uid, "_cutEquip", {}, {_id: _id})
}
}
@ -419,7 +441,7 @@ export class PlayerFun {
});
let result = await G.mongodb.collection('hero').insertMany(insertData);
addGameLog(call.uid, "_addHero",{}, insertData)
addGameLog(call.uid, "_addHero", {}, insertData)
for (let key = 0; key < insertData.length; key++) {
let v = insertData[key]
@ -474,7 +496,7 @@ export class PlayerFun {
G.redis.del('hero', call.uid, _id);
G.mongodb.collection('hero').deleteOne({uid: call.uid, _id: new ObjectId(_id)});
call.addEventMsg('msg_s2c/HeroChange', _id, {num: 0});
addGameLog(call.uid, "_cutHero",{}, {_id:_id})
addGameLog(call.uid, "_cutHero", {}, {_id: _id})
}
}
@ -505,7 +527,7 @@ export class PlayerFun {
}).reduce((a, b) => a.concat(b));
let result = await G.mongodb.collection('shiwu').insertMany(insertData);
addGameLog(call.uid, "_addShiWu",{}, insertData)
addGameLog(call.uid, "_addShiWu", {}, insertData)
insertData.forEach((v, key) => {
let id = result.insertedIds[key].toHexString();
@ -537,7 +559,7 @@ export class PlayerFun {
// G.redis.del('shiwu', call.uid, _id);
G.mongodb.collection('shiwu').deleteOne({uid: call.uid, _id: new ObjectId(_id)});
call.addEventMsg('msg_s2c/ShiwuChange', _id, {num: 0});
addGameLog(call.uid, "_cutShiwu",{}, {_id:_id})
addGameLog(call.uid, "_cutShiwu", {}, {_id: _id})
}
}
@ -559,7 +581,7 @@ export class PlayerFun {
}).reduce((a, b) => a.concat(b));
let result = await G.mongodb.collection('peijian').insertMany(insertData);
addGameLog(call.uid, "_addPeiJian",{}, insertData)
addGameLog(call.uid, "_addPeiJian", {}, insertData)
insertData.forEach((v, key) => {
let {_id, uid, ...ops} = v;
@ -600,7 +622,7 @@ export class PlayerFun {
G.redis.del('peijian', call.uid, _id);
G.mongodb.collection('peijian').deleteOne({uid: call.uid, _id: new ObjectId(_id)});
call.addEventMsg('msg_s2c/PeijianChange', _id, {num: 0});
addGameLog(call.uid, "_cutPeijian",{}, {_id:_id})
addGameLog(call.uid, "_cutPeijian", {}, {_id: _id})
}
}

155
src/public/pushgift.ts Normal file
View File

@ -0,0 +1,155 @@
import {PayFun} from "./pay";
const PushGiftType = {
LevelGift: 1, // 关卡推送
ItemGift: 2, // 道具推送
LoseGift: 3, // 战败推送
RecruitGift: 4, // 十连推送
LvGift: 5, // 等级推送
}
export class PushGiftFun {
static async getGift(uid: string) {
// 查询所有礼包
return (await G.mongodb.collection("pushgift").find({
uid: uid
}).toArray()).map((i) => {
let {_id, ...gift} = i;
return gift
})
}
static async chkItemGift(uid: string, atn: atn) {
let gift_ids = [];
for (let id in G.gc.tuisonglibao) {
let conf = G.gc.tuisonglibao[id];
if (conf.type == PushGiftType.ItemGift && conf.num[0].a == atn.a && conf.num[0].t == atn.t) {
gift_ids.push(id);
}
}
if (gift_ids.length <= 0) {
return
} else {
this.pushGift(uid, gift_ids)
}
}
static async chkLevelGift(uid: string, level: number) {
let gift_ids = [];
for (let id in G.gc.tuisonglibao) {
let conf = G.gc.tuisonglibao[id];
if (conf.type == PushGiftType.LevelGift && conf.num[0] == level) {
gift_ids.push(id);
}
}
if (gift_ids.length <= 0) {
return
} else {
this.pushGift(uid, gift_ids)
}
}
static async chkLvGift(uid: string, lv: number) {
let gift_ids = [];
for (let id in G.gc.tuisonglibao) {
let conf = G.gc.tuisonglibao[id];
if (conf.type == PushGiftType.LevelGift && conf.num[0] == lv) {
gift_ids.push(id);
}
}
if (gift_ids.length <= 0) {
return
} else {
this.pushGift(uid, gift_ids)
}
}
static async chkLoseGift(uid: string) {
let gift_ids = [];
for (let id in G.gc.tuisonglibao) {
let conf = G.gc.tuisonglibao[id];
if (conf.type == PushGiftType.LoseGift) {
gift_ids.push(id);
}
}
if (gift_ids.length <= 0) {
return
} else {
this.pushGift(uid, gift_ids)
}
}
static async chkRecruitGift(uid: string) {
let gift_ids = [];
for (let id in G.gc.tuisonglibao) {
let conf = G.gc.tuisonglibao[id];
if (conf.type == PushGiftType.RecruitGift) {
gift_ids.push(id);
}
}
if (gift_ids.length <= 0) {
return
} else {
this.pushGift(uid, gift_ids)
}
}
static async pushGift(uid: string, gift_ids: string[]) {
let gifts = {};
(await this.getGift(uid)).forEach(i => gifts[i.id] = i)
for (let gift_id of gift_ids) {
let conf = G.gc.tuisonglibao[gift_id];
if (gifts[gift_id] && conf.displayCD > 0 && gifts[gift_id].ctime + conf.displayCD > G.time) {
continue
}
if (conf.type == PushGiftType.RecruitGift) {
if (gifts[gift_id]) {
if (gift_ids[gift_id].ext_data.num + 1 >= conf.num[0]) {
this.addGift(uid, gift_id, {num: 0})
} else {
G.mongodb.collection("pushgift").updateOne({
uid: uid, id: gift_id
}, {"$inc": {"ext_data.num": 1}})
}
} else {
// 招募礼包不存在 初始化数据 记录招募次数
G.mongodb.collection("pushgift").updateOne({
uid: uid, id: gift_id
}, {
$set: {
ctime: 0,
passTime: 0,
ext_data: {num: 1},
buy: conf.payId.map(() => 0),
}
}, {upsert: true})
}
} else {
this.addGift(uid, gift_id, {})
}
}
}
static async addGift(uid: string, giftid: string, ext_data: { [key: string]: any }) {
let conf = G.gc.tuisonglibao[giftid];
// 更新礼包
G.mongodb.collection("pushgift").updateOne({
uid: uid, id: giftid
}, {
$set: {
ctime: G.time,
ext_data: ext_data,
passTime: G.time + conf.time,
buy: conf.payId.map(() => 0),
}
}, {upsert: true})
// 删除购买记录
PayFun.delPayLog(uid, ...conf.payId.map(i => {
return {payId: i, val: []}
}))
// 推送客户端消息
G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", 1);
}
}

View File

@ -23,6 +23,8 @@ export type christmas = {
taskval: { [id: string]: number }
/**任务领取标识 */
taskfinish: string[]
/**小游戏挑战次数 */
gamenum: number
/**普通战令奖励集合 奖励id */
pt: number[]
/**高级战令奖励集合 奖励id */
@ -36,7 +38,7 @@ export type christmas = {
/**装扮值 */
val: number
/**签到标识 */
qiandao:string[],
qiandao:number[],
/**刷新时间 */
refresh: number
}

View File

@ -2,11 +2,11 @@
"hdid" : 91029302193,
"htype" : 8,
"stype" : 800,
"ttype" : 1,
"stime" : 60,
"rtime" : 90,
"etime" : 90,
"name" : "xinfupeiyang",
"ttype" : 0,
"stime" : 1702396800,
"rtime" : 1703088000,
"etime" : 1703088000,
"name" : "christmas",
"icon" : "icon_xfdj",
"showtime" : "根据玩家注册时间,游戏返回时复写",
"data" : {
@ -52,24 +52,51 @@
}
},
"gameneed": [{"a": "attr", "t":"jinbi", "n": 1}],
"game": [0,1,2,3,4,5],
"zhanling":[
{
"val": 1,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 2,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 3,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1}]
}
],
"game": [0,1, 2, 3, 4, 5],
"gamefree": 3,
"zhanling":[{
"val": 1,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1},{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 2,
"pt": [{"a": "attr", "t":"rmbmoney", "n": 100}],
"gj": [{"a": "attr", "t":"rmbmoney", "n": 100},{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 3,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1},{"a": "attr", "t":"jinbi", "n": 1}]
},{
"val": 4,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1},{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 5,
"pt": [{"a": "attr", "t":"rmbmoney", "n": 100}],
"gj": [{"a": "attr", "t":"rmbmoney", "n": 100},{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 6,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1},{"a": "attr", "t":"jinbi", "n": 1}]
},{
"val": 7,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1},{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 8,
"pt": [{"a": "attr", "t":"rmbmoney", "n": 100}],
"gj": [{"a": "attr", "t":"rmbmoney", "n": 100},{"a": "attr", "t":"jinbi", "n": 1}]
},
{
"val": 9,
"pt": [{"a": "attr", "t":"jinbi", "n": 1}],
"gj": [{"a": "attr", "t":"jinbi", "n": 1},{"a": "attr", "t":"jinbi", "n": 1}]
}],
"zlpayid":"ycmb_1_1",
"libao": {
"1": {

View File

@ -1,5 +1,3 @@
/**
*
*/
@ -13,10 +11,47 @@ export const conf = {
timeIntervalLimit: 0
};
export type hongdianKey = 'jiuba' | 'jiaotang' | 'shouchong' | 'dixiaqianzhuanghd' | 'taskhd' | 'xstaskhd' | 'gonghuihd' | 'jjchd' | 'hbzbhd' |
'clslhd' | 'lingzhulaixihd' | 'dxlthd' | 'wzcjhd' | 'slzdhd' | 'qjzzdhd' | 'kuangdonghd' | 'qiandaohd' | 'kaifukuanghuanhd' | 'jijinhd' | 'zhuishalinghd' |
'yibaichouhd' | 'huobanzhaomuhd' | 'qirileichonghd' | 'jierihd' | 'kbzzhd' | 'wzryhd' | 'yuedujijin' | 'patahd' |
'mingdao' | 'heishihd' |'jitianhaoli'| 'huodonghd' | 'renown' | 'heishiMrjx' | 'weixiuchang' | 'kaifujingsai';
export type hongdianKey =
'jiuba'
| 'jiaotang'
| 'shouchong'
| 'dixiaqianzhuanghd'
| 'taskhd'
| 'xstaskhd'
| 'gonghuihd'
| 'jjchd'
| 'hbzbhd'
|
'clslhd'
| 'lingzhulaixihd'
| 'dxlthd'
| 'wzcjhd'
| 'slzdhd'
| 'qjzzdhd'
| 'kuangdonghd'
| 'qiandaohd'
| 'kaifukuanghuanhd'
| 'jijinhd'
| 'zhuishalinghd'
|
'yibaichouhd'
| 'huobanzhaomuhd'
| 'qirileichonghd'
| 'jierihd'
| 'kbzzhd'
| 'wzryhd'
| 'yuedujijin'
| 'patahd'
|
'mingdao'
| 'heishihd'
| 'jitianhaoli'
| 'huodonghd'
| 'renown'
| 'heishiMrjx'
| 'weixiuchang'
| 'kaifujingsai'
| 'zhoumolibao';
export type hongdianVal = {

View File

@ -0,0 +1 @@
export type MsgPushGiftChange = 1;

View File

@ -0,0 +1,5 @@
import {Gift} from "../../../module/collection_pushgift";
export type ReqOpen = {}
export type ResOpen = { gifts: Gift[] }

File diff suppressed because it is too large Load Diff