import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { TanXianFun } from '../../public/tanxian';
import { ReqGuaJi, ResGuaJi } from "../../shared/protocols/tanxian/PtlGuaJi";
import { TanXianShared } from '../../shared/public/tanxian';
import { event_dldh_addPrize } from '../event/diaoluoduihuan/ApiOpen';

export default async function (call: ApiCall<ReqGuaJi, ResGuaJi>) {

    let data = await TanXianFun.getData(call);

    if (G.time - data.lastGuaJiTime < G.gc.tanxian_com.guaJiPrizeInterval) return call.error(globalThis.lng.tanxian_4);

    let prize = TanXianShared.getGuaJiPrize(G.time - data.lastGuaJiTime, call.conn.gud.mapId, false, {
        shoucangpin: call.conn.gud.shoucangping
    });

    let _p = [].concat(prize.prize, prize.dlz);
    await event_dldh_addPrize(_p, call, G.time - data.lastGuaJiTime);
    await PlayerFun.sendPrize(call, _p);
    TanXianFun.changeData(call, { lastGuaJiTime: G.time });

    call.succ({
        prize: _p,
        lastGuaJiTime: G.time
    });
}