import { Client } from './Client';
import 'mocha';
import { PinusWSClient } from 'pinus-robot-plugin';
import { expect } from 'chai';
import { checkBattleGoods, checkDisplayItems, checkSuccessResponse, checkTimeStamp, checkWarJson } from './CheckPatten';
import { DEBUG_MAGIC_WORD } from '../app/consts';
import { getRandSingleEelm } from './pureUtil';

const NORMAIL_BATTLEID = 101;
const DUNGEON_BATTLEID = 5001;

describe('战斗测试', function () {
    let pinusClient: PinusWSClient;
    let roleInfo;

    before(function (done) {
        const c = new Client();
        const timer = setInterval(() => {
            if (c.client) {
                pinusClient = c.client;
                roleInfo = c.roleInfo;
                clearInterval(timer);
                done();
            }
        }, 500);
    });

    after(function (done) {
        pinusClient.disconnect();
        // disconnect 后等待 500ms，供服务器清理环境、退出频道等
        setTimeout(() => {
            done();
        }, 500);
    });

    it('获得关卡列表', function (done) {
        pinusClient.request('battle.normalBattleHandler.getBattleList', { types: [1] }, (res) => {
            checkSuccessResponse(res);
            expect(res.data.result).to.be.an('array');
            let battleList = [];
            res.data.result.forEach(elem => {
                expect(elem.list).to.be.an('array');
                battleList = battleList.concat(elem.list);
            });
            battleList.forEach(data => {
                expect(data.battleId).to.be.a('number');
                expect(data.status).to.be.a('number');
                expect(data.star).to.be.a('number');
                expect(data.stars).to.be.an('array');
                data.stars.forEach(star => {
                    expect(star).to.be.a('number');
                })
                expect(data.scriptBefore).to.be.a('string');
                expect(data.scriptAfter).to.be.a('string');
            })
            done();
        });
    });

    let battleCode;
    let paramHeroes;
    it('开始战斗', function (done) {
        paramHeroes = getParamHeroes(roleInfo);
        checkBattle(pinusClient, paramHeroes, NORMAIL_BATTLEID, 'normal', data => {
            battleCode = data.battleCode;
            done();
        });
    });

    it('战斗结算', function (done) {
        battleEnd(pinusClient, paramHeroes, NORMAIL_BATTLEID, battleCode, 'normal', data => {
            done();
        });
    });

    it('战斗扫荡', function (done) {
        battleSweep(pinusClient, NORMAIL_BATTLEID, 'normal', data => {
            done();
        });
    });

    it.skip('保存R剧本', function (done) {
        done();
    });

    it.skip('根据战场获取R剧本', function (done) {
        done();
    });

    it.skip('发送剧情弹幕', function (done) {
        done();
    });

    let dailyList;
    let battleId;
    it('获取每日关卡列表', function (done) {
        pinusClient.request('battle.dailyBattleHandler.getData', {}, (res) => {
            checkSuccessResponse(res);
            expect(res.data.list).to.be.an('array');
            res.data.list.forEach(data => {
                expect(data.type).to.be.a('number');
                expect(data.count).to.be.a('number');
                expect(data.buyCount).to.be.a('number');
                expect(data.wars).to.be.an('array');
                data.wars.forEach(war => {
                    expect(war.battleId).to.be.a('number');
                    expect(war.cost).to.be.a('number');
                    expect(war.star).to.be.a('number');
                    expect(war.status).to.be.a('number');
                });
            });
            dailyList = res.data.list;
            done();
        });
    });

    it.skip('购买每日次数', function (done) {
        done();
    });

    it('每日关卡开始战斗', function (done) {
        let type = 1;
        battleId = 3001;
        for(let data of dailyList) {
            for(let war of data.wars) {
                if(war.status != 0) {
                    type = data.type;
                    battleId = war.battleId;
                    break;
                }
            }
        }
        pinusClient.request('battle.dailyBattleHandler.debugResetNum', { magicWord: DEBUG_MAGIC_WORD, type }, (res) => {
            checkSuccessResponse(res, false);
            checkBattle(pinusClient, paramHeroes, battleId, 'daily', data => {
                battleCode = data.battleCode;
                done();
            })
        });
    });

    it('每日关卡结束战斗', function (done) {
        battleEnd(pinusClient, paramHeroes, battleId, battleCode, 'daily', data => {
            done();
        });
    });

    let event;
    it('获取奇遇事件', function (done) {
        pinusClient.request('battle.eventBattleHandler.getEvents', {}, (res) => {
            checkSuccessResponse(res);
            checkEvents(res.data.list, events => {
                let eventOn = events.filter(cur => cur.status != 3 && cur.status != 4 );
                if(eventOn.length <= 0) {
                    pinusClient.request('battle.eventBattleHandler.debugRefEvent', { magicWord: DEBUG_MAGIC_WORD }, (res) => {
                        checkSuccessResponse(res);
                        checkEvents(res.data.list, events => {
                            let eventOn = events.filter(cur => cur.status != 3 && cur.status != 4 );
                            expect(eventOn.length).not.equal(0);
                            event = getRandSingleEelm(eventOn);
                            done()
                        });
                    });
                } else {
                    event = getRandSingleEelm(eventOn);
                    done();
                }
            });
        });
    });

    function checkEvents(events, cb) {
        expect(events).to.be.an('array');
        events.forEach(event => {
            expect(event.eventCode).to.be.a('string');
            expect(event.battleId).to.be.a('number');
            expect(event.eventId).to.be.a('number');
            expect(event.quality).to.be.a('number');
            if(event.question) {
                expect(event.question).to.be.an('array');
                event.question.forEach(question => {
                    expect(question.id).to.be.a('number');
                    expect(question.question).to.be.a('string');
                    expect(question.answer).to.be.an('array');
                    question.answer.forEach(answer => {
                        expect(answer).to.be.a('string');
                    })
                })
            }
            expect(event.point).to.be.a('number');
            expect(event.status).to.be.a('number');
            expect(event.type).to.be.a('number');
        });
        cb(events);
    }

    it('奇遇事件回答问题', function (done) {
        let { eventId, eventCode, question: questions, status } = event;
        if(event.type == 2 && status == 0) {
            checkAnswer(0);
            function checkAnswer(index) {
                if(index == questions.length) {
                    done();
                } else {
                    let question = questions[index];
                    pinusClient.request('battle.eventBattleHandler.checkAnswer', { eventId, eventCode, questionId: question.id, answer: Math.floor(Math.random() * 3) }, (res) => {
                        checkSuccessResponse(res);
                        expect(res.data.eventCode).to.be.a('string');
                        expect(res.data.eventId).to.be.a('number');
                        expect(res.data.questionId).to.be.a('number');
                        expect(res.data.isCorrect).to.be.a('boolean');
                        expect(res.data.answerNo).to.be.a('number');
                        checkAnswer(index + 1)
                    });
                }
            }
        } else {
            done();
        }
    });

    it('奇遇关卡开始战斗', function (done) {
        let { battleId, status } = event;
        if(event.type == 3 && status == 0) {
            checkBattle(pinusClient, paramHeroes, battleId, 'event', data => {
                battleCode = data.battleCode;
                done();
            });
        } else {
            done();
        }
    });

    it('奇遇关卡结束战斗', function (done) {
        let { battleId, status } = event;
        if(event.type == 3 && status == 0) {
            battleEnd(pinusClient, paramHeroes, battleId, battleCode, 'event', data => {
                done();
            });
        } else {
            done();
        }
    });

    it('奇遇事件领取奖励', function (done) {
        let { eventId, eventCode, status } = event;
        if(status == 0|| status == 1||status == 2) {
            pinusClient.request('battle.eventBattleHandler.receiveEventReward', { eventId, eventCode }, (res) => {
                checkSuccessResponse(res);
                expect(res.data.isSuccess).to.be.a('boolean');
                expect(res.data.eventCode).to.equal(eventCode);
                expect(res.data.eventId).to.equal(eventId);
                expect(res.data.status).to.be.a('number');
                checkDisplayItems(res.data.goods);
                done();
            });
        } else {
            done();
        }
    });

    let expeditionWarRecord;
    let expeditionCode;
    it('获取远征关卡状态', function (done) {
        pinusClient.request('battle.expeditionBattleHandler.getStatus', {}, (res) => {
            checkSuccessResponse(res);
            expect(res.data.expeditionCode).to.be.a('string');
            expeditionCode = res.data.expeditionCode;
            expect(res.data.curLv).to.be.a('number');
            checkExpeditionWarRecord(res.data.expeditionWarRecord);
            checkPointRewards(res.data.pointRewards);
            expect(res.data.heroes).to.be.an('array');
            res.data.heroes.forEach(hero => {
                expect(hero.dataId).to.be.a('number');
                expect(hero.hp).to.be.a('number');
                expect(hero.ap).to.be.a('number');
                expect(hero.shield).to.be.a('number');
            });
            expect(res.data.resetCnt).to.be.a('number');
            done();
        });
    });

    it('重置远征关卡', function (done) {
        pinusClient.request('battle.expeditionBattleHandler.debugResetResetNum', { magicWord: DEBUG_MAGIC_WORD }, (res) => {
            checkSuccessResponse(res, false);
            pinusClient.request('battle.expeditionBattleHandler.resetStatus', {}, (res) => {
                expect(res.data.expeditionCode).to.be.a('string');
                expeditionCode = res.data.expeditionCode;
                expect(res.data.curLv).to.be.a('number');
                checkExpeditionWarRecord(res.data.expeditionWarRecord);
                expect(res.data.heroes).to.be.an('array');
                expect(res.data.resetCnt).to.be.a('number');
                done();
            });
        });
    });

    it('远征获取敌军数据', function (done) {
        let { expeditionId, battleId } = expeditionWarRecord;        
        pinusClient.request('battle.expeditionBattleHandler.getEnemies', { expeditionCode, expeditionId }, (res) => {
            checkSuccessResponse(res, false);
            expect(res.data.expeditionCode).to.equal(expeditionCode);
            expect(res.data.expeditionId).to.equal(expeditionId);
            expect(res.data.battleId).to.equal(battleId);
            expect(res.data.mapseid).to.be.a('number');
            expect(res.data.battleStatus).to.equal(0);
            expect(res.data.enemyFrom).to.be.a('number');
            checkWarJson(res.data.enemies, hero => {
                expect(hero.cur).to.be.an('object');
                expect(hero.cur.hp).to.be.a('number');
                expect(hero.cur.ap).to.be.a('number');
            });
            expect(res.data.curCe).to.be.a('number');
            expect(res.data.nextCe).to.be.a('number');
            done();
        });
    });

    it('远征关卡开始战斗', function (done) {
        let { expeditionId, battleId } = expeditionWarRecord;        
        pinusClient.request('battle.expeditionBattleHandler.checkBattle', { expeditionCode, expeditionId, battleId, heroes: paramHeroes }, (res) => {
            checkSuccessResponse(res, false);
            expect(res.data.expeditionCode).to.equal(expeditionCode);
            expect(res.data.expeditionId).to.equal(expeditionId);
            expect(res.data.battleId).to.equal(battleId);
            expect(res.data.battleCode).to.be.a('string');
            battleCode = res.data.battleCode;
            expect(res.data.battleStatus).to.equal(0);
            done();
        });
    });

    it('远征关卡结束战斗', function (done) {
        let { expeditionId, battleId } = expeditionWarRecord; 
        let heroes = paramHeroes.map(hero => { return { dataId: hero, hp: 100, ap: 100, shield: 100 }})      
        pinusClient.request('battle.expeditionBattleHandler.battleEnd', { 
            expeditionCode, expeditionId, battleId, battleCode, heroes, enemies: [], star: 3, stars: [], isSuccess: true
        }, (res) => {
            checkSuccessResponse(res);
            expect(res.data.expeditionCode).to.equal(expeditionCode);
            expect(res.data.expeditionId).to.equal(expeditionId);
            expect(res.data.battleId).to.equal(battleId);
            expect(res.data.battleCode).to.equal(battleCode);
            expect(res.data.expeditionPoint).to.be.a('number');
            checkBattleGoods(res.data.battleGoods);
            checkActorData(res.data.actordata);
            expect(res.data.lv).to.be.a('number');
            expect(res.data.exp).to.be.a('number');
            expect(res.data.kingExp).to.be.a('number');
            done();
        });
    });

    it.skip('领取远征宝箱', function (done) {
        done();
    });

    function checkExpeditionWarRecord(expeditionWarRecords) {
        expect(expeditionWarRecords).to.be.an('array');
        expeditionWarRecords.forEach(record => {
            expect(record.expeditionId).to.be.a('number');
            expect(record.battleCode).to.be.a('string');
            expect(record.battleId).to.be.a('number');
            expect(record.battleStatus).to.be.a('number');
            expect(record.ce).to.be.a('number');
        })
        for(let record of expeditionWarRecords) {
            if(record.battleStatus == 0) {
                expeditionWarRecord = record;
                break;
            }
        }
    }

    function checkPointRewards(pointRewards) {
        expect(pointRewards).to.be.an('object');
        expect(pointRewards.expeditionPoint).to.be.a('number');
        expect(pointRewards.rewards).to.be.an('array');
        pointRewards.rewards.forEach(reward => {
            expect(reward.point).to.be.a('number');
            expect(reward.received).to.be.a('boolean');
        })
    }

    it('获取秘境数据', function (done) {
        pinusClient.request('battle.dungeonBattleHandler.getData', {}, (res) => {
            checkSuccessResponse(res);
            expect(res.data.nextCostGold).to.be.a('number');
            expect(res.data.battleCount).to.be.a('number');
            expect(res.data.dungeonHeroes).to.be.an('array');
            res.data.dungeonHeroes.forEach(data => {
                expect(data.heroes).to.be.an('array');
                data.heroes.forEach(hero => {
                    expect(hero).to.be.a('number');
                });
                expect(data.battleId).to.be.a('number');
            });
            done();
        });
    });

    it.skip('购买秘境挑战次数', function (done) {
        done();
    });

    it.skip('秘境关卡挑战开始', function (done) {
        pinusClient.request('battle.dungeonBattleHandler.debugResetRefTime', { magicWord: DEBUG_MAGIC_WORD }, (res) => {
            checkSuccessResponse(res, false);
            checkBattle(pinusClient, [], DUNGEON_BATTLEID, 'dungeon', data => {
                battleCode = data.battleCode;
                done();
            });

        });

    });

    it.skip('秘境关卡挑战结束', function (done) {
        battleEnd(pinusClient, [], DUNGEON_BATTLEID, battleCode, 'dungeon', () => {
            done();
        })
        
    });

    it('获取秘境首通信息', function (done) {
        pinusClient.request('battle.dungeonBattleHandler.getFirstInfo', { movePoint: 27 }, (res) => {
            checkSuccessResponse(res);
            expect(res.data.infos).to.be.an('array');
            res.data.infos.forEach(info => {
                expect(info.warId).to.be.a('number');
                checkTimeStamp(info.time, 10, true);
                expect(info.userInfo).of.be.an('object');
                expect(info.userInfo.roleId).to.be.a('string');
                expect(info.userInfo.roleName).to.be.a('string');
                expect(info.userInfo.head).to.be.a('number');
                expect(info.userInfo.frame).to.be.a('number');
                expect(info.userInfo.spine).to.be.a('number');
                expect(info.userInfo.lv).to.be.a('number');
                expect(info.userInfo.title).to.be.a('number');
                expect(info.userInfo.guildName).to.be.a('string');
                expect(info.userInfo.ce).to.be.a('number');
                expect(info.lineup).to.be.an('array');
                info.lineup.forEach(hero => {
                    expect(hero.hid).to.be.a('number');
                    expect(hero.star).to.be.a('number');
                    expect(hero.colorStar).to.be.a('number');
                    expect(hero.lv).to.be.a('number');
                    expect(hero.quality).to.be.a('number');
                    expect(hero.job).to.be.a('number');
                })
            });
            done();
        });
    });

    let progress;
    let towerLv;
    it('获取天梯初始数据', function (done) {
        pinusClient.request('battle.towerBattleHandler.getStatus', {}, (res) => {
            checkSuccessResponse(res);
            expect(res.data.canHungUp).to.be.a('boolean');
            // expect(res.data.hungUpEnableLv).to.be.a('number');
            expect(res.data.canSendTask).to.be.a('boolean');
            expect(res.data.curLv).to.be.a('number');
            towerLv = res.data.curLv;
            expect(res.data.progress).to.be.an('array');
            res.data.progress.forEach(data => {
                expect(data.warId).to.be.a('number');
                expect(data.status).to.be.a('boolean');
            });
            progress = res.data.progress;
            expect(res.data.usedHeroes).to.be.an('array');
            res.data.usedHeroes.forEach(hero => {
                expect(hero).to.be.a('number');
            })
            done();
        });
    });

    it('重置天梯当前层的挑战记录', function (done) {
        pinusClient.request('battle.towerBattleHandler.resetLv', { towerLv }, (res) => {
            checkSuccessResponse(res);
            expect(res.data.roleId).to.be.a('string');
            expect(res.data.curLv).to.be.a('number');
            expect(res.data.heroes).to.be.an('array');
            res.data.heroes.forEach(hero => {
                expect(hero).to.be.a('number');
            })
            expect(res.data.warStatus).to.be.an('array');
            res.data.warStatus.forEach(war => {
                expect(war.warId).to.be.a('number');
                expect(war.status).to.be.a('boolean');
            });
            progress = res.data.warStatus;
            expect(res.data.speedUpCnt).to.be.a('number');
            expect(res.data.speedUpTime).to.be.a('number');
            expect(res.data.passed).to.be.a('boolean');
            done();
        });
    });

    it('天梯关卡开始挑战', function (done) {
        let war = progress.find(cur => !cur.status);
        battleId = war.warId;
        checkBattle(pinusClient, [], battleId, 'tower', data => {
            battleCode = data.battleCode;
            done();
        });
    });

    it('天梯关卡结束挑战', function (done) {
        battleEnd(pinusClient, [], battleId, battleCode, 'tower', () => {
            done();
        })
    });

    it.skip('查询当前挂机收益', function (done) {
        pinusClient.request('battle.towerBattleHandler.checkHangUpRewards', {}, (res) => {
            checkSuccessResponse(res);
            expect(res.data.startTime).to.be.a('string');
            expect(res.data.hangUpPassTime).to.be.a('number');
            checkDisplayItems(res.data.rewards);
            expect(res.data.hangUpSpdUpCnt).to.be.a('number');
            expect(res.data.nextCostGold).to.be.a('number');
            done();
        });
    });

    it.skip('领取挂机收益', function (done) {
        done();
    });

    it.skip('挂机加速', function (done) {
        done();
    });

    it('获取天梯派遣任务', function (done) {
        pinusClient.request('battle.towerBattleHandler.getTasks', {}, (res) => {
            checkSuccessResponse(res);
            checkTowerTasks(res.data.curTasks);

            expect(res.data.refRemainTime).to.be.a('number');
            expect(res.data.nextCostGold).to.be.a('number');
            done();
        });
    });

    function checkTowerTasks(tasks) {
        expect(tasks).to.be.an('array');
        tasks.forEach(task => {
            expect(task.batchCode).to.be.an('string');
            expect(task.status).to.be.a('number');
            expect(task.taskId).to.be.a('number');
            expect(task.taskCode).to.be.a('string');
            if(task.status == 2) expect(task.completeTime).to.be.a('string');
            expect(task.heroes).to.be.an('array');
            task.heroes.forEach(hero => {
                expect(hero.seqId).to.be.a('number');
                expect(hero.hid).to.be.a('number');
                expect(hero.skinId).to.be.a('number');
            })
        })
    }

    it.skip('天梯刷新任务', function (done) {
        done();
    });
 
    it.skip('天梯派遣某个武将到某个任务', function (done) {
        done();
    });

    it.skip('领取奖励', function (done) {
        done();
    });

    it('获取名将擂台战报', function (done) {
        pinusClient.request('battle.ladderHandler.getRec', {}, (res) => {
            checkSuccessResponse(res);
            expect(res.data.rplPrefixUrl).to.be.an('string');
            checkLadderMatchRecs(res.data.list);
            done();
        });
    });

    // 名将擂台战报校验 - 2天内的战报记录
    function checkLadderMatchRecs(ladderMatchRecs) {
        expect(ladderMatchRecs).to.be.an('array');
        let now = new Date().getTime();
        ladderMatchRecs.forEach(ladderMatchRec => {
            expect(ladderMatchRec.battleCode).to.be.a('string');
            expect(ladderMatchRec.roleId1).to.be.a('string');
            expect(ladderMatchRec.roleId2).to.be.a('string');
            let timeDiff = now - ladderMatchRec.endTime;
            expect(timeDiff).to.greaterThan(0);
            expect(ladderMatchRec.rplFileUrl).to.be.a('string');

            // ladderMatchRec.attackInfo
            expect(ladderMatchRec.attackInfo.lv).to.be.a('number');
            expect(ladderMatchRec.attackInfo.head).to.be.a('number');
            expect(ladderMatchRec.attackInfo.frame).to.be.a('number');
            expect(ladderMatchRec.attackInfo.spine).to.be.a('number');
            expect(ladderMatchRec.attackInfo.title).to.be.a('number');
            expect(ladderMatchRec.attackInfo.ce).to.be.a('number');
            expect(ladderMatchRec.attackInfo.isSuccess).to.be.a('boolean');
            expect(ladderMatchRec.attackInfo.oldRank).to.be.a('number');
            expect(ladderMatchRec.attackInfo.newRank).to.be.a('number');
            expect(ladderMatchRec.attackInfo.roleId).to.be.a('string');
            expect(ladderMatchRec.attackInfo.roleName).to.be.a('string');
            expect(ladderMatchRec.attackInfo.heroes).to.be.a('array');
            ladderMatchRec.attackInfo.heroes.forEach(hero => {
                expect(hero.hid).to.be.a('number');
                expect(hero.skinId).to.be.a('number');
                expect(hero.quality).to.be.a('number');
                expect(hero.star).to.be.a('number');
                expect(hero.colorStar).to.be.a('number');
                expect(hero.lv).to.be.a('number');
            });

            // ladderMatchRec.defenseInfo
            expect(ladderMatchRec.defenseInfo.lv).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.head).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.frame).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.spine).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.title).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.ce).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.isSuccess).to.be.a('boolean');
            expect(ladderMatchRec.defenseInfo.oldRank).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.newRank).to.be.a('number');
            expect(ladderMatchRec.defenseInfo.roleId).to.be.a('string');
            expect(ladderMatchRec.defenseInfo.roleName).to.be.a('string');
            expect(ladderMatchRec.defenseInfo.heroes).to.be.a('array');
            ladderMatchRec.defenseInfo.heroes.forEach(hero => {
                expect(hero.hid).to.be.a('number');
                expect(hero.skinId).to.be.a('number');
                expect(hero.quality).to.be.a('number');
                expect(hero.star).to.be.a('number');
                expect(hero.colorStar).to.be.a('number');
                expect(hero.lv).to.be.a('number');
            });
        })
    }
});

function getParamHeroes(roleInfo) {
    let heroes = [];
    for(let i = 0; i < 6; i++) {
        if(roleInfo.heros.length - 1 < i) break;
        heroes.push(roleInfo.heros[i].seqId);
    }
    return heroes
}

function checkBattle(pinusClient, heroes, battleId, type, cb) {
    pinusClient.request('battle.normalBattleHandler.checkBattle', { battleId, heroes }, (res) => {
        checkSuccessResponse(res);
        expect(res.data.battleId).to.be.a('number');
        expect(res.data.battleCode).to.be.a('string');
        expect(res.data.status).to.equal(0);
        
        if(type == 'daily') {
            expect(res.data.dailyNum).to.be.an('object');
            expect(res.data.dailyNum.type).to.be.a('number');
            expect(res.data.dailyNum.count).to.be.a('number');
            expect(res.data.dailyNum.buyCount).to.be.a('number');
        } else if (type == 'tower') {
            expect(res.data.towerData.heroes).to.be.an('array');
            res.data.towerData.heroes.forEach(hero => {
                expect(hero).to.be.a('number');
            })
            expect(res.data.towerData.warStatus).to.be.an('object');
            expect(res.data.towerData.warStatus.warId).to.be.a('number');
            expect(res.data.towerData.warStatus.status).to.be.a('boolean');
        } else if (type == 'dungeon') {
            expect(res.data.battleCount).to.be.a('number');
            expect(res.data.buyCount).to.be.a('number');
        }
        cb(res.data, heroes);
    });
}

function checkActorData(actordata) {
    expect(actordata).to.be.an('array');
    actordata.forEach(actor => {
        expect(actor.lv).to.be.a('number');
        expect(actor.exp).to.be.a('number');
        expect(actor.getExp).to.be.a('number');
        expect(actor.mostExp).to.be.a('number');
    })
}

function battleEnd(pinusClient, heroes, battleId, battleCode, type, cb) {
    console.log('#### battleEnd', battleId)
    pinusClient.request('battle.normalBattleHandler.battleEnd', { battleId, battleCode, heroes, isSuccess: true, stars: [1,1,1] }, (res) => {
        checkSuccessResponse(res);
        expect(res.data.battleId).to.be.a('number');
        expect(res.data.battleCode).to.be.a('string');
        expect(res.data.status).to.equal(1);
        checkBattleGoods(res.data.battleGoods);
        expect(res.data.lv).to.be.a('number');
        expect(res.data.exp).to.be.a('number');
        expect(res.data.kingExp).to.be.a('number');
        checkActorData(res.data.actordata);
        if(type == 'daily') {
            expect(res.data.dailyNum).to.be.an('object');
            expect(res.data.dailyNum.type).to.be.a('number');
            expect(res.data.dailyNum.count).to.be.a('number');
            expect(res.data.dailyNum.buyCount).to.be.a('number');
            expect(res.data.dailyNum.war).to.be.an('object');
            expect(res.data.dailyNum.war.battleId).to.be.a('number');
            expect(res.data.dailyNum.war.cost).to.be.a('number');
            expect(res.data.dailyNum.war.star).to.be.a('number');
            expect(res.data.dailyNum.war.status).to.be.a('number');
        } else if (type == 'tower') {

        } else if (type == 'dungeon') {
            expect(res.data.battleCount).to.be.a('number');
            expect(res.data.buyCount).to.be.a('number');
        }
        
        cb(res.data);
    });
}

function battleSweep(pinusClient, battleId, type, cb) {

    pinusClient.request('battle.normalBattleHandler.battleSweep', { battleId, count: 1 }, (res) => {
        checkSuccessResponse(res);
        expect(res.data.battleId).to.be.a('number');
        expect(res.data.count).to.be.a('number');
        checkBattleGoods(res.data.battleGoods);
        checkActorData(res.data.actordata);
        expect(res.data.lv).to.be.a('number');
        expect(res.data.exp).to.be.a('number');
        expect(res.data.kingExp).to.be.a('number');

        if(type == 'daily') {

        } else if (type == 'tower') {

        } else if (type == 'dungeon') {

        }
        cb();
    });
}