import { ApiCall } from "tsrpc";
import { ReqSetWzFight, ResSetWzFight } from "../../cross/protocols/wzry/PtlSetWzFight";
import { Rank } from "../../public/rank/rank";
import { getPlayerRank } from "./ApiRank";

export default async function (call: ApiCall<ReqSetWzFight, ResSetWzFight>) {
    let _setData = {
        zkey: call.req.zkey,
        data: call.req.data,
        jifen: call.req.jifen,
        uid: call.req.data.player.uid
    }
    await G.mongodb.collection('wzry_fight').updateOne({ uid: call.req.data.player.uid }, { $set: _setData })
    // 有积分数据更新积分
    if (_setData.jifen) {
        let data = {
            valArr: [_setData.jifen],
            ..._setData.data
        }
        await Rank.list.wzryCross.addNew(data)
    }

    let rank = await getPlayerRank(call.req.data.player.uid) || -1
    call.succ({ mydata: _setData, rank: rank });
}