131 lines
4.3 KiB
TypeScript
131 lines
4.3 KiB
TypeScript
import { expect } from 'chai';
|
|
|
|
export function checkSuccessResponse(response, withData = true) {
|
|
if (response.code != 0) {
|
|
console.log('checkSuccessResponse info:', JSON.stringify(response))
|
|
}
|
|
expect(response).to.be.an('object');
|
|
expect(response.code).equal(0);
|
|
if (withData) {
|
|
expect(response.data).to.be.an('object');
|
|
}
|
|
}
|
|
|
|
export function checkDisplayItems(items) {
|
|
expect(items).to.be.an('array');
|
|
items.forEach(item => {
|
|
expect(item.id).to.be.a('number');
|
|
expect(item.count).to.be.a('number');
|
|
})
|
|
}
|
|
|
|
export function checkBattleGoods(items) {
|
|
expect(items).to.be.an('array');
|
|
items.forEach(item => {
|
|
expect(item.dropType).to.be.a('number');
|
|
if(item.seqId) expect(item.seqId).to.be.a('number');
|
|
expect(item.id).to.be.a('number');
|
|
expect(item.count).to.be.a('number');
|
|
})
|
|
}
|
|
|
|
export function checkHero(heroes) {
|
|
expect(heroes).to.be.an('array');
|
|
heroes.forEach(hero => {
|
|
expect(hero.seqId).to.be.a('number');
|
|
expect(hero.hid).to.be.a('number');
|
|
expect(hero.hName).to.be.a('string');
|
|
expect(hero.lv).to.be.a('number');
|
|
expect(hero.exp).to.be.a('number');
|
|
expect(hero.star).to.be.a('number');
|
|
expect(hero.starStage).to.be.a('number');
|
|
expect(hero.colorStar).to.be.a('number');
|
|
expect(hero.colorStarStage).to.be.a('number');
|
|
expect(hero.quality).to.be.a('number');
|
|
expect(hero.job).to.be.a('number');
|
|
expect(hero.jobStage).to.be.a('number');
|
|
expect(hero.connections).to.be.an('array');
|
|
hero.connections.forEach(connection => {
|
|
expect(connection.shipId).to.be.a('number');
|
|
expect(connection.level).to.be.a('number');
|
|
});
|
|
expect(hero.favour).to.be.a('number');
|
|
expect(hero.favourLv).to.be.a('number');
|
|
expect(hero.connections).to.be.an('array');
|
|
hero.skins.forEach(skin => {
|
|
expect(skin.id).to.be.a('number');
|
|
expect(skin.enable).to.be.a('boolean');
|
|
});
|
|
})
|
|
}
|
|
|
|
export function addItem(pinusClient, id: number, count: number, cb) {
|
|
pinusClient.request('role.heroHandler.addItem', { id, count }, res => {
|
|
checkSuccessResponse(res);
|
|
cb(res);
|
|
});
|
|
}
|
|
|
|
export function addItemsIfNotEnough(roleInfo, pinusClient, id: number, count: number, cb) {
|
|
if(id == 31001) {
|
|
if(roleInfo.coin < count) {
|
|
return addItem(pinusClient, id, count, () => {
|
|
roleInfo.coin += count;
|
|
cb();
|
|
});
|
|
}
|
|
} else if (id == 31002) {
|
|
if(roleInfo.gold < count) {
|
|
return addItem(pinusClient, id, count, () => {
|
|
roleInfo.gold += count;
|
|
});
|
|
}
|
|
} else {
|
|
let consumeGoods = roleInfo.consumeGoods||[];
|
|
let cur = consumeGoods.find(cur => cur.id == id);
|
|
if(!cur || cur.count < count) {
|
|
return addItem(pinusClient, id, count, () => {
|
|
if(!cur) {
|
|
consumeGoods.push({ id, count });
|
|
} else {
|
|
cur.count += count;
|
|
}
|
|
roleInfo.consumeGoods = consumeGoods;
|
|
});
|
|
}
|
|
}
|
|
cb();
|
|
}
|
|
|
|
export function checkTimeStamp(time, len, canBeZero) {
|
|
if(canBeZero) {
|
|
if(time == 0) return true;
|
|
} else {
|
|
expect(time).to.be.a('number');
|
|
expect(time.toString().length).to.equal(len);
|
|
}
|
|
}
|
|
|
|
export function checkWarJson(heroes) {
|
|
expect(heroes).to.be.an('array');
|
|
heroes.forEach(hero => {
|
|
expect(hero.actorId).to.be.a('number');
|
|
expect(hero.skinId).to.be.a('number');
|
|
expect(hero.actorName).to.be.a('string');
|
|
expect(hero.dataId).to.be.a('number');
|
|
expect(hero.relation).to.be.a('number');
|
|
expect(hero.dirction).to.be.a('number');
|
|
expect(hero.outIndex).to.be.a('number');
|
|
expect(hero.x).to.be.a('number');
|
|
expect(hero.y).to.be.a('number');
|
|
expect(hero.var).to.be.a('number');
|
|
expect(hero.lv).to.be.a('number');
|
|
expect(hero.hide).to.be.a('number');
|
|
expect(hero.initial_ai).to.be.a('number');
|
|
expect(hero.attribute).to.be.a('string');
|
|
expect(hero.star).to.be.a('number');
|
|
expect(hero.skill).to.be.a('string');
|
|
expect(hero.seid).to.be.a('string');
|
|
expect(hero.spine).to.be.a('string');
|
|
})
|
|
} |