feat:
推送礼包新加威望等级推送礼包
This commit is contained in:
parent
7c3b5e985c
commit
bb3cea2f02
@ -1,6 +1,7 @@
|
|||||||
import { ApiCall } from "tsrpc";
|
import { ApiCall } from "tsrpc";
|
||||||
import { ReqUpLv, ResUpLv } from "../../shared/protocols/weiwang/PtlUpLv";
|
import { ReqUpLv, ResUpLv } from "../../shared/protocols/weiwang/PtlUpLv";
|
||||||
import { PlayerFun } from "../../public/player";
|
import { PlayerFun } from "../../public/player";
|
||||||
|
import { PushGiftFun } from "../../public/pushgift";
|
||||||
|
|
||||||
|
|
||||||
export default async function (call: ApiCall<ReqUpLv, ResUpLv>) {
|
export default async function (call: ApiCall<ReqUpLv, ResUpLv>) {
|
||||||
@ -39,7 +40,7 @@ export default async function (call: ApiCall<ReqUpLv, ResUpLv>) {
|
|||||||
|
|
||||||
// 检测消耗是否足够
|
// 检测消耗是否足够
|
||||||
await PlayerFun.checkNeedIsMeet(call, need);
|
await PlayerFun.checkNeedIsMeet(call, need);
|
||||||
|
|
||||||
// 扣除消耗
|
// 扣除消耗
|
||||||
await PlayerFun.cutNeed(call, need);
|
await PlayerFun.cutNeed(call, need);
|
||||||
|
|
||||||
@ -52,6 +53,10 @@ export default async function (call: ApiCall<ReqUpLv, ResUpLv>) {
|
|||||||
$inc: { [call.req.type]: call.req.lv },
|
$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 } });
|
call.succ({ lv: { hp: data.hp, atk: data.atk, def: data.def } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {PayFun} from "./pay";
|
import { PayFun } from "./pay";
|
||||||
|
|
||||||
const PushGiftType = {
|
const PushGiftType = {
|
||||||
LevelGift: 1, // 关卡推送
|
LevelGift: 1, // 关卡推送
|
||||||
@ -6,6 +6,7 @@ const PushGiftType = {
|
|||||||
LoseGift: 3, // 战败推送
|
LoseGift: 3, // 战败推送
|
||||||
RecruitGift: 4, // 十连推送
|
RecruitGift: 4, // 十连推送
|
||||||
LvGift: 5, // 等级推送
|
LvGift: 5, // 等级推送
|
||||||
|
RenownGift: 6, // 影响力等级
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PushGiftFun {
|
export class PushGiftFun {
|
||||||
@ -15,7 +16,7 @@ export class PushGiftFun {
|
|||||||
return (await G.mongodb.collection("pushgift").find({
|
return (await G.mongodb.collection("pushgift").find({
|
||||||
uid: uid
|
uid: uid
|
||||||
}).toArray()).map((i) => {
|
}).toArray()).map((i) => {
|
||||||
let {_id, ...gift} = i;
|
let { _id, ...gift } = i;
|
||||||
return gift
|
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[]) {
|
static async pushGift(uid: string, gift_ids: string[]) {
|
||||||
let gifts = {};
|
let gifts = {};
|
||||||
(await this.getGift(uid)).forEach(i => gifts[i.id] = i)
|
(await this.getGift(uid)).forEach(i => gifts[i.id] = i)
|
||||||
@ -106,11 +125,11 @@ export class PushGiftFun {
|
|||||||
if (conf.type == PushGiftType.RecruitGift) {
|
if (conf.type == PushGiftType.RecruitGift) {
|
||||||
if (gifts[gift_id]) {
|
if (gifts[gift_id]) {
|
||||||
if (gift_ids[gift_id].ext_data.num + 1 >= conf.num[0]) {
|
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 {
|
} else {
|
||||||
G.mongodb.collection("pushgift").updateOne({
|
G.mongodb.collection("pushgift").updateOne({
|
||||||
uid: uid, id: gift_id
|
uid: uid, id: gift_id
|
||||||
}, {"$inc": {"ext_data.num": 1}})
|
}, { "$inc": { "ext_data.num": 1 } })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 招募礼包不存在 初始化数据 记录招募次数
|
// 招募礼包不存在 初始化数据 记录招募次数
|
||||||
@ -120,10 +139,10 @@ export class PushGiftFun {
|
|||||||
$set: {
|
$set: {
|
||||||
ctime: 0,
|
ctime: 0,
|
||||||
passTime: 0,
|
passTime: 0,
|
||||||
ext_data: {num: 1},
|
ext_data: { num: 1 },
|
||||||
buy: conf.payId.map(() => 0),
|
buy: conf.payId.map(() => 0),
|
||||||
}
|
}
|
||||||
}, {upsert: true})
|
}, { upsert: true })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.addGift(uid, gift_id, {})
|
this.addGift(uid, gift_id, {})
|
||||||
@ -143,11 +162,11 @@ export class PushGiftFun {
|
|||||||
passTime: G.time + conf.time,
|
passTime: G.time + conf.time,
|
||||||
buy: conf.payId.map(() => 0),
|
buy: conf.payId.map(() => 0),
|
||||||
}
|
}
|
||||||
}, {upsert: true})
|
}, { upsert: true })
|
||||||
|
|
||||||
// 删除购买记录
|
// 删除购买记录
|
||||||
PayFun.delPayLog(uid, ...conf.payId.map(i => {
|
PayFun.delPayLog(uid, ...conf.payId.map(i => {
|
||||||
return {payId: i, val: []}
|
return { payId: i, val: [] }
|
||||||
}))
|
}))
|
||||||
// 推送客户端消息
|
// 推送客户端消息
|
||||||
G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", conf.id);
|
G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", conf.id);
|
||||||
@ -171,7 +190,7 @@ export class PushGiftFun {
|
|||||||
if (info.passTime >= G.time) {
|
if (info.passTime >= G.time) {
|
||||||
await G.mongodb.collection("pushgift").updateOne({
|
await G.mongodb.collection("pushgift").updateOne({
|
||||||
uid: uid, id: gift.id.toString()
|
uid: uid, id: gift.id.toString()
|
||||||
}, {$inc: {[`buy.${index}`]: 1}})
|
}, { $inc: { [`buy.${index}`]: 1 } })
|
||||||
// 推送客户端消息
|
// 推送客户端消息
|
||||||
G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", gift.id);
|
G.server.sendMsgByUid(uid, "msg_s2c/PushGiftChange", gift.id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user