From bb3cea2f02e0401b6b97c6c7dd99119486d452eb Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Sat, 6 Jan 2024 11:49:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A8=E9=80=81=E7=A4=BC=E5=8C=85?= =?UTF-8?q?=E6=96=B0=E5=8A=A0=E5=A8=81=E6=9C=9B=E7=AD=89=E7=BA=A7=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E7=A4=BC=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/weiwang/ApiUpLv.ts | 7 ++++++- src/public/pushgift.ts | 37 +++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/api_s2c/weiwang/ApiUpLv.ts b/src/api_s2c/weiwang/ApiUpLv.ts index e2212b5..2fb8a6d 100644 --- a/src/api_s2c/weiwang/ApiUpLv.ts +++ b/src/api_s2c/weiwang/ApiUpLv.ts @@ -1,6 +1,7 @@ import { ApiCall } from "tsrpc"; import { ReqUpLv, ResUpLv } from "../../shared/protocols/weiwang/PtlUpLv"; import { PlayerFun } from "../../public/player"; +import { PushGiftFun } from "../../public/pushgift"; export default async function (call: ApiCall) { @@ -39,7 +40,7 @@ export default async function (call: ApiCall) { // 检测消耗是否足够 await PlayerFun.checkNeedIsMeet(call, need); - + // 扣除消耗 await PlayerFun.cutNeed(call, need); @@ -52,6 +53,10 @@ export default async function (call: ApiCall) { $inc: { [call.req.type]: call.req.lv }, }); + // 检测触发推送礼包 + PushGiftFun.chkRenownGift( + call.uid, { atk: data.atk, def: data.def, hp: data.hp } + ); call.succ({ lv: { hp: data.hp, atk: data.atk, def: data.def } }); } diff --git a/src/public/pushgift.ts b/src/public/pushgift.ts index 0e50409..2246416 100644 --- a/src/public/pushgift.ts +++ b/src/public/pushgift.ts @@ -1,4 +1,4 @@ -import {PayFun} from "./pay"; +import { PayFun } from "./pay"; const PushGiftType = { LevelGift: 1, // 关卡推送 @@ -6,6 +6,7 @@ const PushGiftType = { LoseGift: 3, // 战败推送 RecruitGift: 4, // 十连推送 LvGift: 5, // 等级推送 + RenownGift: 6, // 影响力等级 } export class PushGiftFun { @@ -15,7 +16,7 @@ export class PushGiftFun { return (await G.mongodb.collection("pushgift").find({ uid: uid }).toArray()).map((i) => { - let {_id, ...gift} = i; + let { _id, ...gift } = i; return gift }) } @@ -95,6 +96,24 @@ export class PushGiftFun { } } + static async chkRenownGift(uid: string, data: { atk: number, def: number, hp: number }) { + let min_lv = Math.min(data.atk, data.def, data.hp); + + let gift_ids = []; + for (let id in G.gc.tuisonglibao) { + let conf = G.gc.tuisonglibao[id]; + if (conf.type == PushGiftType.RenownGift && conf.num[0] == min_lv) { + 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) @@ -106,11 +125,11 @@ export class PushGiftFun { 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}) + this.addGift(uid, gift_id, { num: 0 }) } else { G.mongodb.collection("pushgift").updateOne({ uid: uid, id: gift_id - }, {"$inc": {"ext_data.num": 1}}) + }, { "$inc": { "ext_data.num": 1 } }) } } else { // 招募礼包不存在 初始化数据 记录招募次数 @@ -120,10 +139,10 @@ export class PushGiftFun { $set: { ctime: 0, passTime: 0, - ext_data: {num: 1}, + ext_data: { num: 1 }, buy: conf.payId.map(() => 0), } - }, {upsert: true}) + }, { upsert: true }) } } else { this.addGift(uid, gift_id, {}) @@ -143,11 +162,11 @@ export class PushGiftFun { passTime: G.time + conf.time, buy: conf.payId.map(() => 0), } - }, {upsert: true}) + }, { upsert: true }) // 删除购买记录 PayFun.delPayLog(uid, ...conf.payId.map(i => { - return {payId: i, val: []} + return { payId: i, val: [] } })) // 推送客户端消息 G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", conf.id); @@ -171,7 +190,7 @@ export class PushGiftFun { if (info.passTime >= G.time) { await G.mongodb.collection("pushgift").updateOne({ uid: uid, id: gift.id.toString() - }, {$inc: {[`buy.${index}`]: 1}}) + }, { $inc: { [`buy.${index}`]: 1 } }) // 推送客户端消息 G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", gift.id); }