HJ_Server/src/api_s2c/kuangdong/ApiYanShi.ts
2024-01-11 20:23:08 +08:00

58 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {ApiCall} from "tsrpc";
import {KuangDongfun} from "../../public/kuangdong";
import {PlayerFun} from "../../public/player";
import {ReqYanShi, ResYanShi} from "../../shared/protocols/kuangdong/PtlYanShi";
export default async function (call: ApiCall<ReqYanShi, ResYanShi>) {
//return call.errorCode(1)
let hdid = call.req.hdid
let con = await KuangDongfun.getCon(hdid)
let kdInfo
if (con.public_map == 1){
kdInfo = await KuangDongfun.getKaiCaiInfo(hdid)
}else {
kdInfo = await KuangDongfun.getKaiCaiInfo(hdid, call.uid)
}
if (!kdInfo || !con) {
return call.error('', {code: -1, message: globalThis.lng.kudangdong_1})
}
// 不是自己占领的
if (kdInfo.uid != call.uid) {
return call.error('', {code: -2, message: globalThis.lng.kudangdong_8})
}
// 已经延时
if (kdInfo.yanshi != 0) {
return call.error('', {code: -2, message: globalThis.lng.kudangdong_10})
}
// @ts-ignore
let _need: atn[] = G.gc.com.dpzd_time.value;
// 扣资源
// _need = [{ a: 'attr', t: 'rmbmoney', n: 120 }]
await PlayerFun.checkNeedIsMeet(call, _need)
_need && await PlayerFun.cutNeed(call, _need);
kdInfo.yanshi = 8 * 3600
if (!kdInfo.ctime) kdInfo.ctime = G.time
if (!kdInfo.etime) kdInfo.etime = G.time
if (!kdInfo.kdtype) kdInfo.kdtype = con.type
// 如果调用这个方法会upsert在没有查到数据的情况下
// 会插入空数据,全服玩家的查询列表接口都会报错
// await KuangDongfun.setminingZhanLing(call.uid, hdid, { $set: { yanshi: kdInfo.yanshi } })
await G.mongodb.collection('kuangdong').updateOne({uid: call.uid, hdid: hdid},
{$set: kdInfo});
kdInfo._id = kdInfo._id.toString()
let changeData = {
kdinfo: kdInfo
}
call.succ(changeData)
}