HJ_Server/src/api_s2c/shootGame/ApiRec.ts
DESKTOP-15R5JU0\legu 97e070ea81 init
2023-11-17 12:02:12 +08:00

30 lines
1.1 KiB
TypeScript

import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqRec, ResRec } from "../../shared/protocols/shootGame/PtlRec";
export default async function (call: ApiCall<ReqRec, ResRec>) {
const req = call.req;
const conf = G.gc.shoot;
const data = await G.mongodb.collection('playerInfo', 'shootGame').findOne({ uid: call.uid, type: 'shootGame' });
const passList = data.passList || {};
if (!conf[req.id] || !conf[req.id].prize[req.level]) return call.error(globalThis.lng.shootgame_1);
if (conf[Number(req.id) - 1] && !!!data.passList[Number(req.id) - 1]) return call.error(globalThis.lng.shootgame_2);
if (data?.receiveList.includes(req.id)) return call.error(globalThis.lng.shootgame_3);
await PlayerFun.sendPrize(call, conf[req.id].prize[req.level].content);
let obj = {};
obj[`passList.${req.id}`] = 1;
G.mongodb.collection('playerInfo', 'shootGame').updateOne(
{ uid: call.uid, type: 'shootGame' },
{ $inc: obj, $push: { receiveList: req.id } }
);
call.succ({
prize: conf[req.id].prize[req.level].content
});
}