寻宝:战斗过程中占用的藏宝图要先扣
This commit is contained in:
@@ -53,7 +53,7 @@ export class ComBattleHandler {
|
|||||||
console.log('createTeam msg: ', msg);
|
console.log('createTeam msg: ', msg);
|
||||||
// 检查藏宝图Id是否合法
|
// 检查藏宝图Id是否合法
|
||||||
if (!blueprtIdValid(blueprtId)) return resResult(STATUS.COM_BATTLE_BLUEPRT_INVALID);
|
if (!blueprtIdValid(blueprtId)) return resResult(STATUS.COM_BATTLE_BLUEPRT_INVALID);
|
||||||
const enoughBlueprt = await hasEnoughBlueprt(roleId, blueprtId);
|
const enoughBlueprt = await hasEnoughBlueprt(roleId, sid, blueprtId);
|
||||||
if (!enoughBlueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
if (!enoughBlueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
||||||
|
|
||||||
const roleInfo = await RoleModel.findByRoleId(roleId, null, true);
|
const roleInfo = await RoleModel.findByRoleId(roleId, null, true);
|
||||||
@@ -395,6 +395,7 @@ export class ComBattleHandler {
|
|||||||
*/
|
*/
|
||||||
async startBattle(msg: {teamCode: string}, session: BackendSession) {
|
async startBattle(msg: {teamCode: string}, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
|
let roleName = session.get('roleName');
|
||||||
let sid = session.get('sid');
|
let sid = session.get('sid');
|
||||||
let { teamCode } = msg;
|
let { teamCode } = msg;
|
||||||
let teamStatus = this.teamMap.get(teamCode);
|
let teamStatus = this.teamMap.get(teamCode);
|
||||||
@@ -423,6 +424,8 @@ export class ComBattleHandler {
|
|||||||
let channel = channelService.getChannel(teamCode, false);
|
let channel = channelService.getChannel(teamCode, false);
|
||||||
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: COM_TEAM_STATUS.LOOSE, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr}, true);
|
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: COM_TEAM_STATUS.LOOSE, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr}, true);
|
||||||
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
||||||
|
// 将藏宝图加回去
|
||||||
|
await addItems(roleId, roleName, sid, [{ id: team.blueprtId, count: 1 }])
|
||||||
teamStatus.timeout = true;
|
teamStatus.timeout = true;
|
||||||
channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, {teamCode, result: false, timeout: true}));
|
channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, {teamCode, result: false, timeout: true}));
|
||||||
thiz.teamMap.delete(teamCode);
|
thiz.teamMap.delete(teamCode);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { getRandRobot, transBossHpArr } from "./battleService";
|
|||||||
import { difference, omit } from 'underscore';
|
import { difference, omit } from 'underscore';
|
||||||
import { Channel, ChannelService } from 'pinus';
|
import { Channel, ChannelService } from 'pinus';
|
||||||
import { TREASURE, EXTERIOR } from '../pubUtils/dicParam';
|
import { TREASURE, EXTERIOR } from '../pubUtils/dicParam';
|
||||||
import { decreaseItems } from './rewardService';
|
import { addItems, decreaseItems, handleCost } from './rewardService';
|
||||||
import { getFriendLvAdd } from './friendService';
|
import { getFriendLvAdd } from './friendService';
|
||||||
import { getRoleIds } from '../pubUtils/friendUtil';
|
import { getRoleIds } from '../pubUtils/friendUtil';
|
||||||
import { getTeamSearchByQuality, rmRoleFromQueue } from './redisService';
|
import { getTeamSearchByQuality, rmRoleFromQueue } from './redisService';
|
||||||
@@ -254,12 +254,18 @@ export async function handleComBtlProgress(teamStatus: MemComBtlTeam, robotHurtT
|
|||||||
let team = await ComBattleTeamModel.syncTeamData({ teamCode, status: battleSt, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr });
|
let team = await ComBattleTeamModel.syncTeamData({ teamCode, status: battleSt, roleStatus: teamStatus.roleStatus, bossHpArr: teamStatus.bossHpArr });
|
||||||
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
||||||
|
|
||||||
// 战斗胜利队长扣减藏宝图
|
// // 战斗胜利队长扣减藏宝图
|
||||||
if (result && teamStatus.capId != 'robot') {
|
// if (result && teamStatus.capId != 'robot') {
|
||||||
|
// const { sid } = channel.getMember(teamStatus.capId);
|
||||||
|
// let res = await decreaseItems(teamStatus.capId, sid, [{ id: teamStatus.blueprtId, count: 1 }]);
|
||||||
|
// if (res === true) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
||||||
|
// }
|
||||||
|
// 为了背包显示,队长藏宝图在创建队伍的时候就扣掉了,如果输了,返还藏宝图
|
||||||
|
if (!result && teamStatus.capId != 'robot') {
|
||||||
const { sid } = channel.getMember(teamStatus.capId);
|
const { sid } = channel.getMember(teamStatus.capId);
|
||||||
let res = await decreaseItems(teamStatus.capId, sid, [{ id: teamStatus.blueprtId, count: 1 }]);
|
await addItems(teamStatus.capId, teamStatus.capId, sid, [{ id: teamStatus.blueprtId, count: 1 }]);
|
||||||
if (res === true) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clearRobotHurtTimer(teamStatus, robotHurtTimer);
|
clearRobotHurtTimer(teamStatus, robotHurtTimer);
|
||||||
channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, { teamCode, result }));
|
channel.pushMessage('onTeamComplete', resResult(STATUS.SUCCESS, { teamCode, result }));
|
||||||
|
|
||||||
@@ -565,13 +571,15 @@ export function createComTeamData(teamCode: string, pub: boolean, blueprtId: num
|
|||||||
* @param {number} blueprtId
|
* @param {number} blueprtId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function hasEnoughBlueprt(roleId: string, blueprtId: number) {
|
export async function hasEnoughBlueprt(roleId: string, sid: string, blueprtId: number) {
|
||||||
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
|
||||||
if (!blueprt) return false;
|
if (!blueprt || blueprt.count <= 0) return false;
|
||||||
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
|
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
|
||||||
let teams = await ComBattleTeamModel.getBlueprtInUse(roleId, COM_TEAM_STATUS.FIGHTING, blueprtId);
|
// 背包中占用的藏宝图不显示,所以这里就扣掉,结束再加回去
|
||||||
if (teams && blueprt.count <= teams.length) return false;
|
let result = await handleCost(roleId, sid, [{ id: blueprtId, count: 1 }]);
|
||||||
return true;
|
// let teams = await ComBattleTeamModel.(roleId, COM_TEAM_STATUS.FIGHTING, blueprtId);
|
||||||
|
// if (teams && blueprt.count <= teams.length) return false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user