import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqRefresh, ResRefresh } from "../../shared/protocols/gonglukuangbiao/PtlRefresh";
import { refreshEnemys } from './ApiOpen';

export default async function (call: ApiCall<ReqRefresh, ResRefresh>) {

    if (!call.req.free) {
        let need = G.gc.gonglukuangbiao.refreshNeed;
        await PlayerFun.checkNeedIsMeet(call, need);
        await PlayerFun.cutNeed(call, need);
    }

    let enemys = await refreshEnemys(call);
    G.mongodb.collection('wanted').updateOne({ uid: call.uid }, { $set: { enemys: enemys } });

    call.succ({ enemys: enemys });
}