修改天梯接口问题,天梯和挂机已测试
This commit is contained in:
@@ -8,7 +8,7 @@ import { getTowerDataByLv } from "../util/gamedata"
|
||||
import { decodeArrayStr } from '../util/util';
|
||||
import { handleFixedReward } from './rewardService';
|
||||
|
||||
export async function checkTowerWar(roleId: string, battleId: number) {
|
||||
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
|
||||
const battleIdStr = `${battleId}`;
|
||||
let { towerLv } = await RoleModel.findByRoleId(roleId);
|
||||
const towerInfo = getTowerDataByLv(towerLv);
|
||||
@@ -16,19 +16,24 @@ export async function checkTowerWar(roleId: string, battleId: number) {
|
||||
console.error(`天梯层数异常,lv ${towerLv} by ${roleId}`);
|
||||
return { status: -1, msg: '天梯层数异常' };
|
||||
}
|
||||
const warArray = decodeArrayStr(towerInfo.warArray) || [];
|
||||
if (warArray.indexOf(battleIdStr) === -1) {
|
||||
const warIds = decodeArrayStr(towerInfo.warIds) || [];
|
||||
if (warIds.indexOf(battleIdStr) === -1) {
|
||||
return { status: -1, msg: '战斗 Id 异常' };
|
||||
}
|
||||
|
||||
let { heroes = [], warStatus = [] } = await TowerRecordModel.getRecordByLv(roleId, towerLv);
|
||||
let { heroes: recHeroes = [], warStatus = [] } = await TowerRecordModel.getRecordByLv(roleId, towerLv);
|
||||
for (let hid of heroes) {
|
||||
if (recHeroes.indexOf(hid) !== -1) {
|
||||
return { status: -1, msg: '使用了重复的武将' };
|
||||
}
|
||||
}
|
||||
const curWarStatus = warStatus.find(elem => elem.warId == battleId);
|
||||
if (curWarStatus.status) {
|
||||
return {status: -1, msg: '天梯关卡不能重复挑战'};
|
||||
}
|
||||
|
||||
return { status: 0, data: {
|
||||
heroes, warStatus: curWarStatus
|
||||
heroes: recHeroes, warStatus: curWarStatus
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -54,20 +59,24 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
})
|
||||
let newRec = await TowerRecordModel.updateRecord(roleId, towerLv, battleCode, battleId, heroes, inc);
|
||||
let bonusReward = null;
|
||||
let towerReward = null;
|
||||
if (inc === 1) {
|
||||
await RoleModel.towerLvUp(roleId);
|
||||
const nextTowerInfo = getTowerDataByLv(towerLv + 1);
|
||||
if (nextTowerInfo) {
|
||||
const { wars } = nextTowerInfo;
|
||||
const sts = wars.map(id => {
|
||||
return {warId: id, status: false};
|
||||
const { warIds } = nextTowerInfo;
|
||||
const sts = decodeArrayStr(warIds).map(id => {
|
||||
return {warId: parseInt(id), status: false};
|
||||
});
|
||||
await TowerRecordModel.createRecord({roleId, lv: towerLv + 1, warStatus: sts});
|
||||
}
|
||||
const { bonus } = getTowerDataByLv(towerLv);
|
||||
const { bonus, fixReward } = getTowerDataByLv(towerLv);
|
||||
if (bonus) {
|
||||
bonusReward = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
}
|
||||
if (fixReward) {
|
||||
towerReward = await handleFixedReward(roleId, roleName, fixReward, 1);
|
||||
}
|
||||
if (towerLv + 1 >= HANG_UP_CONSTS.ENABLE_LV) {
|
||||
await startHangUp(roleId, roleName);
|
||||
channelService.pushMessageByUids('hangUpEnable', {code: 200, data: {enable: true}}, [{uid: roleId, sid}]);
|
||||
@@ -77,7 +86,7 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
status: 0,
|
||||
data: {
|
||||
newRec,
|
||||
bonusReward,
|
||||
bonusReward, towerReward,
|
||||
towerStatus: !!inc
|
||||
}
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ export async function handleFixedReward(roleId: string, roleName: string, reward
|
||||
for(let goods of rewards) {
|
||||
let goodInfo = getGoodById(goods.gid);
|
||||
if(goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
|
||||
let result = await rewardWeapons(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
let result = await rewardWeapons(roleId, roleName, goodInfo, {id: goods.gid, cnt: goods.count * multi });
|
||||
for(let obj of result) {
|
||||
returnGoods.push({dropType: goods.type, ...obj})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user