import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqChangePos, ResChangePos } from "../../shared/protocols/zhanqianbushu/PtlChangePos";

export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
    let req = call.req;
    if (!G.gc.fightPlan[req.type] || !G.gc.herocom.szHeroLimit[req.movePos] || !G.gc.herocom.szHeroLimit[req.toPos]) return call.errorCode(-1);

    let matrixPos: typeof call.conn.gud.matrixPos = JSON.parse(JSON.stringify(call.conn.gud.matrixPos));
    if (!matrixPos[req.type][req.movePos]) return call.errorCode(-2);

    let m = matrixPos[req.type][req.movePos];
    let t = matrixPos[req.type][req.toPos];

    matrixPos[req.type][req.toPos] = m;
    matrixPos[req.type][req.movePos] = t;

    await PlayerFun.addAttr(call, { matrixPos: matrixPos });
    call.succ({});
}