import FguiMgr from "../../../frameWork/fgui/FguiMgr";
import UEBattleRole from "../../../logic/battle/UEBattleRole";
import { BattleMainView } from "../../../logic/fgui/Battle/BattleMain/BattleMainView";
import { FightBase } from "../../../shared/base";
import { ResFightTest } from "../../../shared/fight/PtlFightTest";
import { ViewZOrder } from "../../const/ViewZOrder";
import GameDataCenter from "../../GameDataCenter";
import { BattleModelData } from "./BattleModelData";

export default class BattleModel extends BattleModelData {
	battleRoleList: { [id: string]: UEBattleRole } = {}
	realBattleSpeed: number;
	fightInfo: ResFightTest;

	constructor() {
		super("battle");
		this.realBattleSpeed = 1.8;
	}

	//发起战斗
	startFight(fightInfo: FightBase, closeCb?: Function) {

		FguiMgr.Instance.openUI(BattleMainView, ViewZOrder.Battle, () => {

		}, { fightInfo: fightInfo, closeCb: closeCb });
	}

	addRole(id: string, role: UEBattleRole) {
		this.battleRoleList[id] = role
	}

	setFightInfo(res: ResFightTest) {
		this.fightInfo = res;
	}

	async SendTestFight(cb: Function) {
		let ret = await GameDataCenter.gameServer.ReqApi("fight/FightTest", {});
		if (ret?.res) {
			this.setFightInfo(ret.res);
			cb(ret.res);
		}
	}
}
