import { RoleType } from "../../db/Role";
import { GVGLeagueType } from "../../db/GVGLeague";
import { GVGLeaguePrepareType, Tech } from "../../db/GVGLeaguePrepare";
import { GVGUserDataType } from "../../db/GVGUserData";
import { GuildType } from "../../db/Guild";
import { GVGLeagueFarmType } from "../../db/GVGLeagueFarm";
import { nowSeconds } from "../../pubUtils/timeUtil";
import { DicGVGVestige } from "../../pubUtils/dictionary/DicGVGVestige";
import { EXTERIOR, GVG } from "../../pubUtils/dicParam";
import { DicWarJson } from "../../pubUtils/dictionary/DicWarJson";
import { gameData } from "../../pubUtils/data";
import { HeroType } from "../../db/Hero";
import { RoleRankInfo } from "../rank";
import { GVGCityType } from "../../db/GVGCity";
import { GVGTeamMem } from "../battleField/gvgBattle";
import { GVGTeamType } from "../../db/GVGTeam";

class LeagueLeaderInfo {
    name: string;        // 盟主名
    serverId: number;  // 盟主所处小区
    serverName: number; // 盟主所处小区名

    constructor(leader: RoleType, serverNames: any) {
        this.name = leader.roleName;
        this.serverId = leader.serverId;
        this.serverName = serverNames[this.serverId];
    }
}

class GVGItem {
    id: number; 
    count: number;
    expireTime: number;      // 过期时间
}

class LeaguePlayerData {
    auth: number = 3;              // 我的权限 1-盟主 2-副盟主 3-平民
    job: number = 0;               // 我的职能，1-贤臣 2-猛将 0-未选择
    canPrepare: boolean = false;   // 是否可以使用整备期模块，组建期过后加入的玩家，当天的整备模块不可参与
    canChooseJob: boolean = true;  // 是否可以选择职能，团内选择职业的人数达到最大人数了，已经不可再选职位了
    items: GVGItem[] = [];         // 持有的道具，包括两种令、战功和种子
    // 奖励相关
    receivedLv: number = 0;              // 奖励领到几级
    tasks: GVGTask[] = [];           // 如果没有达成的任务就不放在这个数组里面
    reviveCnt: number = 0;          // 使用元宝复活的次数
}

class LeagueResource {
    food: number = 0;        // 粮食
    mineral: number = 0;     // 矿物
    wood: number = 0;        // 木堆
}

class GVGTask {
    id: number;        // 任务id
    count: number;
    status: number;    // 状态 0-未领取 1-已领取
}

export class GVGMainData {
    configId: number = 0;           // 赛期
    period: number = 1;             // 当前是什么期 1-组建期 2-备战期 3-激战期
    countdownTime: number = 0;      // 这个周期结束时间，10位时间戳单位秒
    type: number = 1;               // 1-单服 2-跨服
    hasLeague: boolean = false;     // 是否拥有联军
    // 左侧联军信息
    leagueCode: string;              // 联军唯一code
    leader: LeagueLeaderInfo;
    name: string;                    // 联军名
    icon: number;                    // 图标
    leagueLv: number;                      // 联军等级
    notice: string;                  // 公告
    guildCnt: number;                // 军团数量
    memberCnt: number;               // 玩家人数
    teamCnt: number;                 // 里面的玩家的队伍数 TODO
    leagueCe: number;                // 联军内所有人总战力
    // 个人信息
    myInfo: LeaguePlayerData = new LeaguePlayerData();
    // 激战期相关，城池背景
    cities: number[] = [];           // 占领的城池id
    
    // 内政相关
    resources: LeagueResource = new LeagueResource(); // 联盟的物资
    activeTech: number[] = [];            // 已激活了的科技树的id
    techQueue: Tech[];
    maxMemberCnt: number;               // 进入备战期总玩家人数
    producerCnt: number;               // 贤臣人数
    fighterCnt: number;               // 猛将人数
    constribute: LeagueContributeInfo[];

    sumTime: number = 0;             // 今日贡献结算时间 10位时间戳

    // 是否每天首次登录
    isFirst = false;
    leagueGoods: { itemType: number, id: number, count: number }[];

    constructor(configId: number, period: number, countdownTime: number, type: number) {
        this.configId = configId;
        this.period = period;
        this.countdownTime = countdownTime;
        this.type = type;
    }

    setLeague(league: GVGLeagueType, serverNames: any) {
        if(!league) return;
        this.hasLeague = true;
        this.leagueCode = league.leagueCode;
        let leader = <RoleType>league.leader;
        this.leader = new LeagueLeaderInfo(leader, serverNames);
        this.name = league.name;
        this.icon = league.icon;
        this.notice = league.notice;
        this.guildCnt = league.guildCnt;
        this.memberCnt = league.memberCnt;
    }
    
    setLeagueParpare(leaguePrepare: GVGLeaguePrepareType) {
        if(!leaguePrepare) return; 
        this.leagueLv = leaguePrepare.lv;
        this.resources = leaguePrepare.resources;
        this.activeTech = leaguePrepare.activeTech||[];
        this.maxMemberCnt = leaguePrepare.maxMemberCnt;
        this.producerCnt = leaguePrepare.producerCnt;
        this.fighterCnt = leaguePrepare.fighterCnt;
    }

    setPlayerInfo(userData: GVGUserDataType, auth: number, canPrepare: boolean, canChooseJob: boolean, items: GVGItem[], tasks: GVGTask[]) {
        this.myInfo.auth = auth;
        this.myInfo.canPrepare = canPrepare;
        this.myInfo.canChooseJob = canChooseJob;
        this.myInfo.items = items;
        if(userData) {
            this.myInfo.job = userData?.job||0;
            this.myInfo.receivedLv = userData?.receivedLv||0;
            this.myInfo.reviveCnt = userData?.reviveCnt||0;
        }
        this.myInfo.tasks = tasks;
    }

    setFistLogin(item: { itemType: number, id: number, count: number }[]) {
        this.isFirst = true;
        this.leagueGoods = item;
    }

    setLeagueCe(leagueCe: number) {
        this.leagueCe = leagueCe;
    }

    setCities(cities: number[]) {
        this.cities = cities;
    }

    setTechQueue(techQueue: Tech[]) {
        this.techQueue = techQueue;
    }

    setConstribute(constribute: LeagueContributeInfo[]) {
        this.constribute = constribute;
    }
}

export class LeagueListInfo {
    leagueCode: string;   // 联军唯一id
    name: string;        // 联军名
    icon: number;        // icon
    memberCnt: number;   // 玩家人数
    guildCnt: number;    // 组成军团名
    leaderName: string;  // 大将军的姓名
    leaderServerName: string; // 大将军所处小区名
    leagueCe: number;     // 联军战力
    hasApply: boolean = false; // 是否申请过了

    constructor(league: GVGLeagueType, serverNames: any) {
        if(!league) return;
        this.leagueCode = league.leagueCode;
        this.name = league.name;
        this.icon = league.icon;
        this.memberCnt = league.memberCnt;
        this.guildCnt = league.guildCnt;
        this.leaderName = (<RoleType>league.leader).roleName;
        this.leaderServerName = serverNames[(<RoleType>league.leader).serverId];
    }

    setHasApply(hasApply: boolean) {
        this.hasApply = hasApply;
    }

    setLeagueCe(leagueCe: number) {
        this.leagueCe = leagueCe;
    }
}

export class LeagueSimpleInfo extends LeagueListInfo {
    lv: number = 1;      // 等级
    notice: string;  // 公共
    cities: number[] = [];  // 占领的城池
    
    constructor(league: GVGLeagueType, serverNames: any) {
        super(league, serverNames);
        if(!league) return;
        this.notice = league.notice;
    }

    setCities(cities: number[]) {
        this.cities = cities;
    }

    setLv(lv: number) {
        this.lv = lv;
    }
}

export class LeagueGuildInfo {
    guildCode: string;   // 军团唯一id
    icon: number;
    name: string;        // 军团名
    serverName: string;  // 区服名
    lv: number;          // 军团等级
    memberCnt: number;   // 人数
    leaderName: string;  // 大将军的姓名
    guildCe: number;     // 军团战力
    hasInvited: boolean; // 是否邀请过了
    active: number;

    constructor(guild: GuildType, serverNames: any) {
        if(!guild) return;
        this.guildCode = guild.code;
        this.icon = guild.icon;
        this.name = guild.name;
        this.serverName = serverNames[guild.serverId];
        this.lv = guild.lv;
        this.memberCnt = guild.memberCnt;
        let leader = <RoleType>guild.leader;
        this.leaderName = leader.roleName;
        this.guildCe = guild.guildCe;
    }

    setHasInvited(hasInvited: boolean) {
        this.hasInvited = hasInvited;
    }

    setActive(active: number) {
        this.active = active;
    }
}

export class LeagueMemberListInfo {
    roleId: string;     // 玩家id
    roleName: string;   // 玩家名
    lv: number;         // 玩家等级
    head: number;       // 玩家头像
    frame: number;      // 玩家相框
    title: number;      // 爵位
    guildName: string;  // 所处军团名
    serverName: string; // 所处小区名
    job: number = 0;        // 官职 1-贤臣 2-猛将
    auth: number = 0;       // 官职
    active: number = 0;     // 活跃
    ce: number;         // 玩家战力
    isOnline: boolean;  // 是否在线
    quitTime: number;   // 离线时间

    constructor(role: RoleType, serverNames: any) {
        if(!role) return;
        this.roleId = role.roleId;
        this.roleName = role.roleName;
        this.lv = role.lv;
        this.head = role.head;
        this.frame = role.frame;
        this.title = role.title;
        this.guildName = role.guildName;
        this.serverName = serverNames[role.serverId];
        this.ce = role.ce;
        this.quitTime = role.quitTime;
    }

    setByUserData(data: GVGUserDataType) {
        if(!data) return;
        this.active = data.active||0;
        this.job = data.job;
    }

    setAuth(auth: number) {
        this.auth = auth;
    }

    setOnline(isOnline: boolean) {
        this.isOnline = isOnline;
    }
}

export class LeagueMemberContributeInfo extends LeagueMemberListInfo{
    rank: number = 0;
    food: number = 0;
    mineral: number = 0;
    wood: number = 0;
    score: number = 0;

    setByUserData(data: GVGUserDataType) {
        if(!data) return;
        this.active = data.active;
        this.job = data.job;
        this.food = data.contribute?.food||0;
        this.mineral = data.contribute?.mineral||0;
        this.wood = data.contribute?.wood||0;
        this.score = data.contribute?.score||0
    }

    setRank(rank: number) {
        this.rank = rank;
    }
}

export class LeagueContributeInfo {
    job: number;        // 1-内政 2-外政
    sumContribute: number;   // 总贡献（宝箱显示）
    receivedBox: number[];   // 已领取的宝箱id
    members: LeagueMemberContributeInfo[];

    constructor(job: number, sumContribute: number, receivedBox: number[]) {
        this.job = job;
        this.sumContribute = sumContribute||0;
        this.receivedBox = receivedBox||[];
    }

    setMembers(members: LeagueMemberContributeInfo[]) {
        this.members = members;
    }
}

export class LeagueFarmListInfo {
    farmId: number;
    count: number;     // 已种植数量
    canHarvest: boolean;

    constructor(farmId: number, count: number, canHarvest: boolean) {
        this.farmId = farmId;
        this.count = count;
        this.canHarvest = canHarvest;
    }
}

export class LeagueField {
    fieldId: number; // 田的编号
    seedType: number; // 已种植了的种子类型 0-未种 1-小麦 2-玉米 3-水稻
    addType: number;    // 特殊加成类型 0-普通田 1-小麦加成 2-玉米 3-水稻
    harvestTime: number; // 收获时间， 10位时间戳
    unlockTime: number; // 锁定时间，会按照内政令的数量给玩家预锁定一批填，超过时间限制就不锁给他了也会分给其他人了
    index: number = 0; // 位置
    output: number = 0; // 产量

    constructor(leagueFarm: GVGLeagueFarmType) {
        if(!leagueFarm) return;
        this.fieldId = leagueFarm.fieldId;
        this.seedType = leagueFarm.seedType;
        this.addType = leagueFarm.addType;
        this.harvestTime = leagueFarm.harvestTime;
        this.unlockTime = leagueFarm.unlockTime;
        this.index = leagueFarm.index||0;
        this.output = leagueFarm.output;
    }
}

export class LeagueFarmMember {
    roleId: string; // 种田玩家
    roleName: string;
    guildName: string;
    serverName: string;
    count: number;      // 种植地块
    output: number;    // 预计产量
    canHelp: boolean;       // 是否可以帮收
    harvestTime: number; // 收成时间，10位时间戳

    constructor(role: RoleType, serverNames: any) {
        this.roleId = role.roleId;
        this.roleName = role.roleName;
        this.guildName = role.guildName;
        this.serverName = serverNames[role.serverId];
    }

    setByFields(fields: GVGLeagueFarmType[]) {
        this.count = fields.length;
        this.harvestTime = Math.min(...fields.map(cur => cur.harvestTime))||0;
        this.canHelp = !!fields.find(cur => cur.harvestTime > 0 && cur.harvestTime < nowSeconds());
        this.output = fields.reduce((pre, cur) => (pre + cur.output||0), 0);
    }
    
    setByMines(mines: GVGLeagueFarmType[]) {
        this.count = mines.length;
        this.output = mines.reduce((pre, cur) => (pre + cur.output||0), 0);
    }
}

export interface LeagueGood {
    itemType: number,
    id: number,
    count: number
}

export class GVGVestigeOppPlayer {
    rank: number;
    roleId: string;
    roleName: string;
    lv: number;
    head: number;
    frame: number;
    spine: number;
    title: number;
    guildName: string;
    serverName: string;
    lineupCe: number;
    score: number;
    leagueCode: string;
    leagueName: string;

    constructor(rank: number) {
        this.rank = rank;
    }

    setByRole(role: RoleType, serverNames: any, lineupCe: number, score: number, leagueCode: string, leagueName: string) {
        this.roleId = role.roleId;
        this.roleName = role.roleName;
        this.lv = role.lv;
        this.head = role.head;
        this.frame = role.frame;
        this.spine = role.spine;
        this.title = role.title;
        this.guildName = role.guildName;
        this.serverName = serverNames[role.serverId];
        this.lineupCe = lineupCe;
        this.score = score;
        this.leagueCode = leagueCode;
        this.leagueName = leagueName;
    }

    setByDic(dic: DicGVGVestige, serverName: string) {
        this.lineupCe = dic.ce;
        this.roleId = `robot${this.rank}`;
        this.roleName = GVG.GVG_ROBOT_NAME;
        this.lv = dic.level;
        this.head = dic.head;
        this.frame = EXTERIOR.EXTERIOR_FACECASE;
        this.spine = dic.spine;
        this.title = 1;
        this.guildName = '';
        this.serverName = serverName;
        this.lineupCe = dic.ce;
        this.score = dic.score;
        this.leagueCode = 'robot';
        this.leagueName = '遗迹守卫军';
    }
}

// getOppLineup返回
export class GVGVestigeOppLineupHero {
    hid: number;   // 武将
    skinId: number;    // 皮肤id
    quality: number;   // 品质
    star: number;      // 星级
    colorStar: number; // 彩星
    lv: number;        // 等级

    setByWarJson(warJson: DicWarJson) {
        this.hid = warJson.actorId;
        this.skinId = warJson.actorId;
        this.lv = warJson.lv;
        let dicHero = gameData.hero.get(warJson.actorId);
        if(dicHero) {
            this.quality = dicHero.quality;
            if(this.quality == 4) {
                this.star = 6;
                this.colorStar = warJson.star;
            } else {
                this.star = warJson.star;
                this.colorStar = 0;
            }
        }
    }


    setByDefenseHero(hero: HeroType) {
        this.hid = hero.hid;
        this.skinId = hero.skinId;
        this.quality = hero.quality;
        this.star = hero.star;
        this.colorStar = hero.colorStar;
        this.lv = hero.lv;
    }
}

class OppData {
    leagueCode: string;
    leagueName: string;
    rank: number;
    score: number;
    isRobot: boolean;
    roleId: string;
    roleName: string;
    serverName: string;
    guildName: string;
    lv: number;
    head: number;
    frame: number;
    spine: number;
    title: number;
    lineupCe: number = 0;   // 阵容战力
    heroes: GVGVestigeOppLineupHero[] = [];


    setRobot(dic: DicGVGVestige, warJsons: DicWarJson[], serverName: string) {
        this.isRobot = true;
        this.rank = dic.rank;
        this.score = dic.score;
        this.roleId = `robot${dic.rank}`;
        this.roleName = GVG.GVG_ROBOT_NAME;
        this.serverName = serverName;
        this.guildName = '';
        this.lineupCe = dic.ce;
        this.lv = dic.level;
        this.head = dic.head;
        this.frame = EXTERIOR.EXTERIOR_FACECASE;
        this.spine = dic.spine;
        this.title = 1;
        this.leagueName = '遗迹守卫军';
        this.leagueCode = 'robot';

        for(let warJson of warJsons) {
            if(warJson.relation == 2) {
                let hero = new GVGVestigeOppLineupHero();
                hero.setByWarJson(warJson);
                this.heroes.push(hero);
            }
        }
    }

    setPlayer(dic: DicGVGVestige, role: RoleType, heroes: HeroType[], serverNames: any, leagueName: string, leagueCode: string) {
        this.isRobot = false;
        this.rank = dic.rank;
        this.score = dic.score;
        this.roleId = role.roleId;
        this.roleName = role.roleName;
        this.serverName = serverNames[role.serverId];
        this.guildName = role.guildName;
        this.title = role.title;
        this.lv = role.lv;
        this.head = role.head;
        this.frame = role.frame;
        this.spine = role.spine;
        this.leagueName = leagueName;
        this.leagueCode = leagueCode;

        for(let hero of heroes) {
            this.lineupCe += hero.ce;
            let obj = new GVGVestigeOppLineupHero();
            obj.setByDefenseHero(hero);
            this.heroes.push(obj);
        }
    }
}

export class GVGVestigeOppLineup {
    vestigeId: number;  // 遗迹id
    myRank: number;
    opp: OppData = new OppData();

    constructor(vestigeId: number) {
        this.vestigeId = vestigeId;
    }

    setMyRank(myRank: number) {
        this.myRank = myRank;
    }


    setRobot(dic: DicGVGVestige, warJsons: DicWarJson[], serverName: string) {
        this.opp.setRobot(dic, warJsons, serverName);
    }

    setPlayer(dic: DicGVGVestige, role: RoleType, heroes: HeroType[], serverNames: any, leagueName: string, leagueCode: string) {
        this.opp.setPlayer(dic, role, heroes, serverNames, leagueName, leagueCode);
    }
}

export class VestigeRank {
    rank: number;
    roleId: string;
    roleName: string;
    guildName: string;
    serverName: string;
    lv: number;
    head: number;
    frame: number;
    lineupCe: number;
    score: number;

    setByRankParam(obj: RoleRankInfo, serverName: string, lineupCe: number, score: number) {
        this.rank = obj.rank;
        this.roleId = obj.roleId;
        this.roleName = obj.roleName;
        this.guildName = obj.guildName;
        this.serverName = serverName;
        this.lv = obj.lv;
        this.head = obj.head;
        this.frame = obj.frame;
        this.lineupCe = lineupCe;
        this.score = score;
    }

    setByRole(role: RoleType, serverName: string) {
        this.rank = 0;
        this.roleId = role.roleId;
        this.roleName = role.roleName;
        this.guildName = role.guildName;
        this.serverName = serverName;
        this.lv = role.lv;
        this.head = role.head;
        this.frame = role.frame;
        this.lineupCe = 0;
        this.score = 0;
    }
}

// 大地图上城池占林
export class GVGCityMapInfo {
    cityId: number;   // 城池id
    guardLeagueCode: string;  // 驻守城池的联军id
    guardLeagueName: string; // 驻守这个城池的联军
    guardLeagueIcon: number;  // 驻守这个城池的联军的icon
    teamCnt: number;  // 我方人数
    score: number;

    constructor(city: GVGCityType) {
        if(!city) return;
        this.cityId = city.cityId;
        this.guardLeagueCode = city.guardLeague;
        this.guardLeagueName = city.guardLeagueName;
        this.guardLeagueIcon = city.guardLeagueIcon;
    }

    setTeamCnt(teamCnt: number) {
        this.teamCnt = teamCnt;
    }

    setScore(score: number) {
        this.score = score;
    }
}

export class GVGTeamSpineInMap {
    spine: number = 0;
    roleId: string = '';
    roleName: string = '';
    serverName: string = '';
    startMoveTime: number = 0;
    stopMoveTime: number = 0;
    moveCdTime: number = 0;
    isMoving: boolean = false;
    pointId: number = 0;
    areaId: number = 0;
    fromAreaId: number = 0;
    teamCode: string = '';
    leagueCode: string = '';
    leagueName: string = '';


    constructor(obj: GVGTeamMem, serverNames: {[serverId: string]: string}) {
        this.spine = obj.spine;
        this.roleId = obj.roleId;
        this.roleName = obj.roleName;
        if(obj.serverId) this.serverName = serverNames[obj.serverId];
        this.startMoveTime = obj.startMoveTime;
        this.stopMoveTime = obj.stopMoveTime;
        this.moveCdTime = obj.moveCdTime;
        this.isMoving = nowSeconds() < this.stopMoveTime;
        this.areaId = obj.areaId;
        this.pointId = obj.pointId;
        this.fromAreaId = obj.fromAreaId;
        this.teamCode = obj.teamCode;
        this.leagueCode = obj.leagueCode;
        this.leagueName = obj.leagueName;
    }
}

export class GVGAreaInMap {
    areaId: number;
    spines: GVGTeamSpineInMap[] = [];
}

// 地图右边列表上的队伍信息
export class GVGTeamInList {
    areaId: number;
    pointId: number;
    teamCode: string;
    roleId: string;
    roleName: string;
    head: number;
    frame: number;
    lv: number;
    lineupCe: number;
    leagueCode: string;
    leagueName: string;
    durability: number;  // 耐久
    maxDurability: number;  // 最大耐久
    restartTime: number;
    defenseTime: number;
    curTeamBreak: boolean;

    constructor(team: GVGTeamType) {
        if(!team) return;
        this.areaId = team.areaId;
        this.pointId = team.pointId;
        this.teamCode = team.teamCode;
        this.roleId = team.roleId;
        this.roleName = team.roleName;
        this.head = team.head;
        this.frame = team.frame;
        this.lv = team.lv;
        this.lineupCe = team.lineupCe;
        this.leagueCode = team.leagueCode;
        this.leagueName = team.leagueName;
        this.durability = team.durability;
        this.maxDurability = team.maxDurability;
        this.restartTime = team.restartTime;
        this.defenseTime = team.defenseTime;
        this.curTeamBreak = !!team.curTeamBreak;
    }
}

// 地图右边列表上的队伍信息
export class GVGAttackSpine {
    teamCode: string;  // 队伍唯一id
    durability: number; // 耐久
    maxDurability: number;  // 最大耐久
    hurt: number;      // 投石车造成的伤害
    pointId: number;   // 可能会被打下积分点
    areaId: number;    // 被打到哪个区域

    constructor(team: GVGTeamType, hurt: number) {
        if(!team) return;
        this.teamCode = team.teamCode;
        this.durability = team.durability;
        this.maxDurability = team.maxDurability;
        this.pointId = team.pointId;
        this.areaId = team.areaId;
        this.hurt = hurt;
    }
}

export class GVGTeamInListOnPoint extends GVGTeamInList {
    pointId: number; // 积分点
    hasTeam: boolean; // 是否有队伍占领
    isRobot: boolean;  // 这个队伍是不是擂台守卫者

    constructor(pointId: number, hasTeam: boolean, team?: GVGTeamType) {
        super(team);
        this.pointId = pointId;
        this.hasTeam = hasTeam;
        if(team) this.isRobot = team.isRobot;
    }
}

export class MyTeamSimpleInfo {
    teamCode: string;  // 队伍唯一id
    index: number;    // 队伍位置
    head: number;    // 保存头像
    frame: number;   // 保存相框
    spine: number;   // 保存形象
    lineup: { 
        actorId: number; // 武将
        dataId: number;  // 出兵表上的位置
        order: number;   // 行动
    }[];

    constructor(team: GVGTeamType) {
        this.teamCode = team.teamCode;
        this.index = team.index;
        this.head = team.head;
        this.frame = team.frame;
        this.spine = team.spine;
        this.lineup = team.lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex }));
    }
}

// 更新自己队伍时候的比较详细点的数据
export class MyTeamInfo {
    teamCode: string;  // 队伍唯一id
    index: number;    // 队伍位置
    head: number;    // 保存头像
    frame: number;   // 保存相框
    spine: number;   // 保存形象
    lv: number;
    lineup: { 
        actorId: number; // 武将
        dataId: number;  // 出兵表上的位置
        order: number;   // 行动
    }[];
    durability: number; // 耐久
    maxDurability: number;  // 最大耐久
    restartTime: number; // 修整期结束时间
    attackTime: number;  // 进攻冷却结束时间
    stopMoveTime: number;    // 移动结束时间
    moveCdTime: number;    // 移动冷却结束时间
    defenseTime: number; // 防守保护时间
    areaId: number;   // 出生在的区域
    pointId: number;
    curTeamBreak: boolean;

    constructor(team: GVGTeamType) {
        this.teamCode = team.teamCode;
        this.index = team.index;
        this.head = team.head;
        this.frame = team.frame;
        this.spine = team.spine;
        this.lv = team.lv;
        if(team.lineup) this.lineup = team.lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex }));
        this.durability = team.durability;
        this.maxDurability = team.maxDurability;
        this.restartTime = team.restartTime;
        this.attackTime = team.attackTime;
        this.stopMoveTime = team.stopMoveTime;
        this.moveCdTime = team.moveCdTime;
        this.defenseTime = team.defenseTime;
        this.areaId = team.areaId;
        this.pointId = team.pointId;
        this.curTeamBreak = team.curTeamBreak;
    }
}

// 情报
// 联军排名
export class LeagueRankInInfoPage {
    rank: number;
    leagueCode: string = '';
    leagueName: string = '';
    lv: number = 1;
    leaderName: string = '';
    leagueCe: number = 0;
    cities: number[] = [];

    constructor(rank: number, league: GVGLeagueType, prepare: GVGLeaguePrepareType, ce: number, cities: number[]) {
        this.rank = rank;
        if(league) {
            this.leagueCode = league.leagueCode;
            this.leagueName = league.name;
            this.leaderName = (<RoleType>league.leader)?.roleName;
        }
        if(prepare) {
            this.lv = prepare.lv;
        }
        this.leagueCe = ce;
        this.cities = cities;
    }
}

export class GuardCityInfoPage {
    cityId: number;
    guardLeagueCode: string = '';
    guardLeagueName: string = '';
    lv: number = 0;
    leaderName: string = '';
    leagueCe: number = 0;

    constructor(cityId: number) {
        this.cityId = cityId;
    }

    setGuardLeague(league: GVGLeagueType, prepare: GVGLeaguePrepareType, ce: number) {
        if(league) {
            this.guardLeagueCode = league.leagueCode;
            this.guardLeagueName = league.name;
            this.leaderName = (<RoleType>league.leader)?.roleName;
        }
        if(prepare) {
            this.lv = prepare.lv;
        }
        this.leagueCe = ce;
    }
}