Merge remote-tracking branch 'origin/pushgift' into release
# Conflicts: # src/api_s2c/pushgift/ApiOpen.ts # src/public/fight.ts # src/public/pushgift.ts # src/shared/protocols/msg_s2c/MsgPushGiftChange.ts # src/shared/protocols/serviceProto.ts
This commit is contained in:
commit
474246463c
9
src/api_s2c/pushgift/ApiItemNoEnough.ts
Normal file
9
src/api_s2c/pushgift/ApiItemNoEnough.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import {ApiCall} from "tsrpc";
|
||||||
|
import {ReqItemNoEnough, ResItemNoEnough} from "../../shared/protocols/pushgift/PtlItemNoEnough";
|
||||||
|
import {PushGiftFun} from "../../public/pushgift";
|
||||||
|
|
||||||
|
export default async function (call: ApiCall<ReqItemNoEnough, ResItemNoEnough>) {
|
||||||
|
// 物品不足 前端拦截的 通知后端 检测推送礼包
|
||||||
|
PushGiftFun.chkItemGift(call.uid, {a: call.req.need.a, t: call.req.need.t, n: 0})
|
||||||
|
call.succ({})
|
||||||
|
}
|
30
src/api_s2c/pushgift/ApiOpen.ts
Normal file
30
src/api_s2c/pushgift/ApiOpen.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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]];
|
||||||
|
let buy = gift_info.buy.map(i => i != 0);
|
||||||
|
if (pay.buys > 0 && gift_info.buy[i] < pay.buys) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
@ -17,6 +17,7 @@ import { PublicShared } from './shared/public/public';
|
|||||||
import { setGud } from './public/gud';
|
import { setGud } from './public/gud';
|
||||||
import {checkResetBuyLog} from "./api_s2c/event/zhoumolibao/ApiOpen";
|
import {checkResetBuyLog} from "./api_s2c/event/zhoumolibao/ApiOpen";
|
||||||
import {Christmasfun} from "./api_s2c/event/christmas/fun";
|
import {Christmasfun} from "./api_s2c/event/christmas/fun";
|
||||||
|
import {PushGiftFun} from "./public/pushgift";
|
||||||
|
|
||||||
export type gEventType = {
|
export type gEventType = {
|
||||||
/**玩家断开连接 */
|
/**玩家断开连接 */
|
||||||
@ -200,6 +201,7 @@ export function addListener() {
|
|||||||
{ $inc: { payNum: conf.money } },
|
{ $inc: { payNum: conf.money } },
|
||||||
{ upsert: true }
|
{ upsert: true }
|
||||||
);
|
);
|
||||||
|
PushGiftFun.buy(player.uid, payId) // 推送礼包
|
||||||
});
|
});
|
||||||
|
|
||||||
G.on("FIRST_LOGIN_EVERY_DAY", (gud, lastTime, curTime) => {
|
G.on("FIRST_LOGIN_EVERY_DAY", (gud, lastTime, curTime) => {
|
||||||
|
@ -9,6 +9,7 @@ import {HeroFun} from './hero';
|
|||||||
import {UserFun} from './user';
|
import {UserFun} from './user';
|
||||||
import {re, string} from "mathjs";
|
import {re, string} from "mathjs";
|
||||||
import {getGud} from './gud';
|
import {getGud} from './gud';
|
||||||
|
import {PushGiftFun} from "./pushgift";
|
||||||
|
|
||||||
type fightType = 'tanxian' | 'pata' | 'jjc' | 'gbtx' | 'qjzzd' | 'meirishilian' | 'wzrycross';
|
type fightType = 'tanxian' | 'pata' | 'jjc' | 'gbtx' | 'qjzzd' | 'meirishilian' | 'wzrycross';
|
||||||
|
|
||||||
@ -86,9 +87,16 @@ export class FightFun {
|
|||||||
|
|
||||||
/**挑战竞技场 */
|
/**挑战竞技场 */
|
||||||
static async fightJJc(call: ApiCall, rankInfo: rankInfo) {
|
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));
|
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 */
|
/**挑战npc */
|
||||||
@ -106,7 +114,13 @@ export class FightFun {
|
|||||||
|
|
||||||
let npc = formatNpcData(npcId);
|
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(call.uid)
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
179
src/public/pushgift.ts
Normal file
179
src/public/pushgift.ts
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
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.LvGift && 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];
|
||||||
|
// 更新礼包
|
||||||
|
await 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", conf.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async buy(uid: string, payId: string) {
|
||||||
|
// 购买礼包
|
||||||
|
let gift;
|
||||||
|
for (let gift_id in G.gc.tuisonglibao) {
|
||||||
|
let temp = G.gc.tuisonglibao[gift_id];
|
||||||
|
if (temp.payId.includes(payId)) {
|
||||||
|
gift = temp;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!gift) return;
|
||||||
|
let index = gift.payId.indexOf(payId);
|
||||||
|
let info = await G.mongodb.collection("pushgift").findOne({
|
||||||
|
uid: uid, id: gift.id.toString()
|
||||||
|
})
|
||||||
|
if (info.passTime >= G.time) {
|
||||||
|
await G.mongodb.collection("pushgift").updateOne({
|
||||||
|
uid: uid, id: gift.id.toString()
|
||||||
|
}, {$inc: {[`buy.${index}`]: 1}})
|
||||||
|
// 推送客户端消息
|
||||||
|
G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", gift.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
src/shared/protocols/msg_s2c/MsgPushGiftChange.ts
Normal file
1
src/shared/protocols/msg_s2c/MsgPushGiftChange.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export type MsgPushGiftChange = number;
|
7
src/shared/protocols/pushgift/PtlItemNoEnough.ts
Normal file
7
src/shared/protocols/pushgift/PtlItemNoEnough.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import {Gift} from "../../../module/collection_pushgift";
|
||||||
|
|
||||||
|
export type ReqItemNoEnough = {
|
||||||
|
need: { a: string, t: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ResItemNoEnough = {}
|
Loading…
Reference in New Issue
Block a user