import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../../public/player';
import { ReqSetSkill, ResSetSkill } from "../../../shared/protocols/gongyu/zuozhanjihua/PtlSetSkill";

export default async function (call: ApiCall<ReqSetSkill, ResSetSkill>) {


    const args = call.req;
    const skillIds = Object.values(args).filter(id => id != '');

    if (skillIds.isDuplication()) return call.error(globalThis.lng.gongyu_4);
    if (skillIds.filter(id => G.gc.xunlianjihua[id] == undefined).length > 0) return call.error(globalThis.lng.gongyu_5);
    if (skillIds.filter(id => call.conn.gud.skills[id] == undefined).length > 0) return call.error(globalThis.lng.gongyu_6);
    if (skillIds.filter(id => G.gc.xunlianjihua[id].use == 0).length > 0) return call.error(globalThis.lng.gongyu_7);

    await PlayerFun.addAttr(call, { fightSkills: args });

    call.succ({});
}