寻宝掉落
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* @Author: 梁桐川
|
* @Author: 梁桐川
|
||||||
* @Date: 2020-11-30 15:05:48
|
* @Date: 2020-11-30 15:05:48
|
||||||
* @Last Modified by: 梁桐川
|
* @Last Modified by: 梁桐川
|
||||||
* @Last Modified time: 2020-12-01 21:11:33
|
* @Last Modified time: 2020-12-02 00:13:35
|
||||||
*/
|
*/
|
||||||
import { COM_BATTLE_ASSIST_TIME, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS } from './../../../consts/consts';
|
import { COM_BATTLE_ASSIST_TIME, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS } from './../../../consts/consts';
|
||||||
import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_BATTLE_CAP_TIME, COM_BATTLE_TIME_LMT } from './../../../consts/consts';
|
import { IT_TYPE, GOLD_COST_RATIO, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_BATTLE_CAP_TIME, COM_BATTLE_TIME_LMT } from './../../../consts/consts';
|
||||||
@@ -267,7 +267,7 @@ export class ComBattleHandler {
|
|||||||
return resResult(STATUS.COM_BATTLE_CE_LIMIT);
|
return resResult(STATUS.COM_BATTLE_CE_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
let teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, [teamStatus.quality], new Date(new Date().setHours(0, 0, 0, 0)), true);
|
let teams = await ComBattleTeamModel.getAssistTeamsByTime(roleId, [teamStatus.quality], new Date(new Date().setHours(0, 0, 0, 0)), true);
|
||||||
if (teams.length >= assistanceTime) resResult(STATUS.COM_BATTLE_ASSIST_NOT_ENOUGH);
|
if (teams.length >= assistanceTime) resResult(STATUS.COM_BATTLE_ASSIST_NOT_ENOUGH);
|
||||||
|
|
||||||
// 加入队伍
|
// 加入队伍
|
||||||
@@ -314,7 +314,7 @@ export class ComBattleHandler {
|
|||||||
*/
|
*/
|
||||||
async getAssistCnt(msg: {}, session: BackendSession) {
|
async getAssistCnt(msg: {}, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
let teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, null, new Date(new Date().setHours(0, 0, 0, 0)), true);
|
let teams = await ComBattleTeamModel.getAssistTeamsByTime(roleId, null, new Date(new Date().setHours(0, 0, 0, 0)), true);
|
||||||
let cnt = [0, 0, 0, 0, 0];
|
let cnt = [0, 0, 0, 0, 0];
|
||||||
teams.forEach(team => {
|
teams.forEach(team => {
|
||||||
if (team && team.quality) {
|
if (team && team.quality) {
|
||||||
@@ -359,18 +359,19 @@ export class ComBattleHandler {
|
|||||||
* @returns
|
* @returns
|
||||||
* @memberof ComBattleHandler
|
* @memberof ComBattleHandler
|
||||||
*/
|
*/
|
||||||
async setupHeroes(msg: {teamCode: string, heroes: Array<number>}, session: BackendSession) {
|
async setupHeroes(msg: {teamCode: string, heroes: Array<number>, battleCode: string}, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
let { teamCode, heroes } = msg;
|
let { teamCode, heroes, battleCode } = msg;
|
||||||
let teamStatus = this.teamMap.get(teamCode);
|
let teamStatus = this.teamMap.get(teamCode);
|
||||||
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
if (!teamStatus || !teamStatus.roleIds || teamStatus.roleIds.indexOf(roleId) === -1) return resResult(STATUS.COM_BATTLE_TEAM_INVALID);
|
||||||
|
|
||||||
let team = await ComBattleTeamModel.updateHeroes(teamCode, roleId, heroes);
|
let team = await ComBattleTeamModel.setupBattleInfo(teamCode, roleId, heroes, battleCode);
|
||||||
if (!team) return resResult(STATUS.COM_BATTLE_UPDATE_HEROES_ERR);
|
if (!team) return resResult(STATUS.COM_BATTLE_UPDATE_HEROES_ERR);
|
||||||
|
|
||||||
teamStatus.roleStatus.forEach(st => {
|
teamStatus.roleStatus.forEach(st => {
|
||||||
if (st && st.roleId === roleId) {
|
if (st && st.roleId === roleId) {
|
||||||
st.heroes = heroes;
|
st.heroes = heroes;
|
||||||
|
st.battleCode = battleCode;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -562,7 +563,18 @@ export class ComBattleHandler {
|
|||||||
let result = battleSt === COM_TEAM_STATUS.WIN;
|
let result = battleSt === COM_TEAM_STATUS.WIN;
|
||||||
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: battleSt, roleStatus: teamStatus.roleStatus});
|
let team = await ComBattleTeamModel.syncTeamData({teamCode, status: battleSt, roleStatus: teamStatus.roleStatus});
|
||||||
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
if (!team) return resResult(STATUS.COM_BATTLE_RESULT_ERR);
|
||||||
channel.pushMessage('onTeamComplete', {teamCode, result});
|
let battleCode = 'default';
|
||||||
|
teamStatus.roleStatus.forEach(st => {
|
||||||
|
if (st.roleId === roleId) {
|
||||||
|
battleCode = st.battleCode;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 战斗胜利扣减藏宝图
|
||||||
|
if (result) {
|
||||||
|
let res = await ItemModel.decreaseItems(roleId, [{id: teamStatus.blueprtId, count: 1}]);
|
||||||
|
if (!res) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
channel.pushMessage('onTeamComplete', {teamCode, battleCode, result});
|
||||||
}
|
}
|
||||||
return resResult(STATUS.SUCCESS);
|
return resResult(STATUS.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { RScriptRecordModel } from '../../../db/RScriptRecord';
|
|||||||
import { updateWarStar, checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService';
|
import { updateWarStar, checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService';
|
||||||
import { checkDungeonNum, checkDungeonAndIncrease } from '../../../services/dungeonService';
|
import { checkDungeonNum, checkDungeonAndIncrease } from '../../../services/dungeonService';
|
||||||
import { switchOnFunc } from '../../../services/funcSwitchService';
|
import { switchOnFunc } from '../../../services/funcSwitchService';
|
||||||
|
import { checkComBattleDrop } from '../../../services/comBattleService';
|
||||||
|
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
return new NormalBattleHandler(app);
|
return new NormalBattleHandler(app);
|
||||||
@@ -219,6 +220,15 @@ export class NormalBattleHandler {
|
|||||||
return checkResult.resResult;
|
return checkResult.resResult;
|
||||||
}
|
}
|
||||||
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
dungeonNum = Object.assign(dungeonNum, checkResult.data)
|
||||||
|
} else if (warInfo.warType == WAR_TYPE.WARLOARDS) {
|
||||||
|
let checkResult = await checkComBattleDrop(roleId, battleCode);
|
||||||
|
if (checkResult.status === -1) {
|
||||||
|
return checkResult.resResult;
|
||||||
|
}
|
||||||
|
// 寻宝会根据是否队长重新计算掉落
|
||||||
|
if (checkResult.fixReward) {
|
||||||
|
warReward.resetFixReward(checkResult.fixReward);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isSuccess) { // 挑战胜利
|
if(isSuccess) { // 挑战胜利
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import { STATUS } from './../consts/statusCode';
|
||||||
import { COM_BATTLE_ROBOT_ID_NAME, COM_BATTLE_ROBOT_CE_RATIO, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS } from './../consts/consts';
|
import { COM_BATTLE_ROBOT_ID_NAME, COM_BATTLE_ROBOT_CE_RATIO, COM_BATTLE_ROBOT_ROUND_LMT, COM_BATTLE_ROBOT_HURT_RATIO, COM_BATTLE_ROBOT_HURT_CH_RATIO, COM_TEAM_STATUS } from './../consts/consts';
|
||||||
import { RoleStatus } from './../db/ComBattleTeam';
|
import { RoleStatus, ComBattleTeamModel } from './../db/ComBattleTeam';
|
||||||
import { getBluePrtByQuality } from "../pubUtils/gamedata";
|
import { getBluePrtByQuality, getRewardByBlueprtId } from "../pubUtils/gamedata";
|
||||||
import { getRandEelm, getRandValue } from "../pubUtils/util";
|
import { getRandEelm, getRandValue, resResult, ratioReward } from "../pubUtils/util";
|
||||||
import { getRandRobot } from "./battleService";
|
import { getRandRobot } from "./battleService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,4 +71,27 @@ export function checkComBattleResult(teamStatus) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return COM_TEAM_STATUS.FIGHTING;
|
return COM_TEAM_STATUS.FIGHTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function checkComBattleDrop(roleId: string, battleCode: string) {
|
||||||
|
let team = await ComBattleTeamModel.getTeamByRoleAndBattleCode(roleId, battleCode);
|
||||||
|
if (team.status !== COM_TEAM_STATUS.WIN) return { status: -1, resResult: resResult(STATUS.COM_BATTLE_REWARD_ERR) };
|
||||||
|
let roleSt = null;
|
||||||
|
team.roleStatus.forEach(st => {
|
||||||
|
if (st.roleId === roleId) {
|
||||||
|
roleSt = st;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!roleSt || roleSt.gotReward) return { status: -1, resResult: resResult(STATUS.COM_BATTLE_REWARD_ERR) };
|
||||||
|
let fixReward = getRewardByBlueprtId(team.blueprtId);
|
||||||
|
if (!roleSt.isCap) {
|
||||||
|
if (roleSt.isFrd) {
|
||||||
|
fixReward = '&';
|
||||||
|
// TODO: 消耗品情谊点添加
|
||||||
|
} else {
|
||||||
|
fixReward = ratioReward(fixReward, COM_BATTLE_ROBOT_HURT_CH_RATIO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await ComBattleTeamModel.updateRewardSt(roleId, battleCode, true);
|
||||||
|
return {status: 0, fixReward};
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,10 @@ export class WarReward {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public resetFixReward(reward: string) {
|
||||||
|
this.fixReward = reward;
|
||||||
|
}
|
||||||
|
|
||||||
public setConditionReward(reward: string) {
|
public setConditionReward(reward: string) {
|
||||||
let str = this.conditionReward;
|
let str = this.conditionReward;
|
||||||
let last = str.substr(str.length-1, 1);
|
let last = str.substr(str.length-1, 1);
|
||||||
|
|||||||
@@ -303,6 +303,8 @@ export const COM_BATTLE_ROBOT_ROUND_LMT = 10;
|
|||||||
export const COM_BATTLE_ROBOT_HURT_RATIO = 0.2;
|
export const COM_BATTLE_ROBOT_HURT_RATIO = 0.2;
|
||||||
// 机器人伤害上下浮动的比例
|
// 机器人伤害上下浮动的比例
|
||||||
export const COM_BATTLE_ROBOT_HURT_CH_RATIO = 0.1;
|
export const COM_BATTLE_ROBOT_HURT_CH_RATIO = 0.1;
|
||||||
|
// 队员奖励比例
|
||||||
|
export const COM_BATTLE_ASSIST_REWARD_RATIO = 0.5;
|
||||||
|
|
||||||
// 机器人名字随机
|
// 机器人名字随机
|
||||||
export const COM_BATTLE_ROBOT_ID_NAME = [
|
export const COM_BATTLE_ROBOT_ID_NAME = [
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ export const STATUS = {
|
|||||||
COM_BATTLE_NO_RECENT_REC: { code: 20624, simStr: '没有最近的寻宝记录' },
|
COM_BATTLE_NO_RECENT_REC: { code: 20624, simStr: '没有最近的寻宝记录' },
|
||||||
COM_BATTLE_HURT_NUM_ERR: { code: 20625, simStr: '血量计算错误' },
|
COM_BATTLE_HURT_NUM_ERR: { code: 20625, simStr: '血量计算错误' },
|
||||||
COM_BATTLE_START_ERR: { code: 20626, simStr: '开始战斗失败' },
|
COM_BATTLE_START_ERR: { code: 20626, simStr: '开始战斗失败' },
|
||||||
|
COM_BATTLE_REWARD_ERR: { code: 20627, simStr: '不能领取奖励' },
|
||||||
|
|
||||||
// 共斗藏宝图合成
|
// 共斗藏宝图合成
|
||||||
COM_BLUEPRT_QUALITY_CANNOT_COMPOSE: { code: 20630, simStr: '该品质藏宝图不可合成' },
|
COM_BLUEPRT_QUALITY_CANNOT_COMPOSE: { code: 20630, simStr: '该品质藏宝图不可合成' },
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ export class RoleStatus {
|
|||||||
// 是否机器人
|
// 是否机器人
|
||||||
@prop({ required: true, default: false })
|
@prop({ required: true, default: false })
|
||||||
isRobot: boolean;
|
isRobot: boolean;
|
||||||
|
// 是否领奖
|
||||||
|
@prop({ required: true, default: false })
|
||||||
|
gotReward: boolean;
|
||||||
|
|
||||||
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, headHid: number, sHid: number, topFiveCe: number, lv: number, heroes = [], isRobot = false) {
|
constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, headHid: number, sHid: number, topFiveCe: number, lv: number, heroes = [], isRobot = false) {
|
||||||
this.roleId = roleId;
|
this.roleId = roleId;
|
||||||
@@ -81,7 +84,7 @@ export default class ComBattleTeam extends BaseModel {
|
|||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
quality: number;
|
quality: number;
|
||||||
|
|
||||||
// 战斗状态 0:未开始,1:已开始,2:胜利,3:失败,4:已领奖
|
// 战斗状态 0:未开始,1:已开始,2:胜利,3:失败
|
||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
status: number;
|
status: number;
|
||||||
|
|
||||||
@@ -125,6 +128,16 @@ export default class ComBattleTeam extends BaseModel {
|
|||||||
return team;
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async setupBattleInfo(teamCode: string, roleId: string, heroes: Array<number>, battleCode: string, lean = true) {
|
||||||
|
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode, 'roleStatus.roleId': roleId}, {$set: {'roleStatus.$.heroes': heroes, 'roleStatus.$.battleCode': battleCode}}, {new: true}).lean(lean);
|
||||||
|
return team;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async updateRewardSt(roleId: string, battleCode: string, gotReward: boolean, lean = true) {
|
||||||
|
const team = await ComBattleTeamModel.findOneAndUpdate({ roleIds: roleId, 'roleStatus.battleCode': battleCode}, {$set: {'roleStatus.$.gotReward': gotReward}}).lean(lean);
|
||||||
|
return team;
|
||||||
|
}
|
||||||
|
|
||||||
public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array<RoleStatus>}, lean = true) {
|
public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array<RoleStatus>}, lean = true) {
|
||||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData, roleCnt: teamData.roleStatus.length}}, {new: true}).lean(lean);
|
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData, roleCnt: teamData.roleStatus.length}}, {new: true}).lean(lean);
|
||||||
return team;
|
return team;
|
||||||
@@ -191,6 +204,26 @@ export default class ComBattleTeam extends BaseModel {
|
|||||||
const teams = await ComBattleTeamModel.find(query).limit(limitCnt).lean(lean);
|
const teams = await ComBattleTeamModel.find(query).limit(limitCnt).lean(lean);
|
||||||
return teams;
|
return teams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async getAssistTeamsByTime(roleId: string, qualityArr?: Array<number>, time?: Date, isAssist?: boolean, lean = true) {
|
||||||
|
let query = {roleIds: roleId, status: {$in: [0, 1, 2]}}; // 失败不计入助战
|
||||||
|
if (qualityArr) {
|
||||||
|
query = Object.assign(query, {quality: {$in: qualityArr}});
|
||||||
|
}
|
||||||
|
if (time) {
|
||||||
|
query = Object.assign(query, {createdAt: {$gte: time}});
|
||||||
|
}
|
||||||
|
if (isAssist) {
|
||||||
|
query = Object.assign(query, {capId: {$ne: roleId}});
|
||||||
|
}
|
||||||
|
const teams = await ComBattleTeamModel.find(query).lean(lean);
|
||||||
|
return teams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async getTeamByRoleAndBattleCode(roleId: string, battleCode: string, lean = true) {
|
||||||
|
const team = await ComBattleTeamModel.findOne({roleIds: roleId, 'roleStatus.battleCode': battleCode}).lean(lean);
|
||||||
|
return team;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ComBattleTeamModel = getModelForClass(ComBattleTeam);
|
export const ComBattleTeamModel = getModelForClass(ComBattleTeam);
|
||||||
@@ -393,10 +393,18 @@ export function getWarIdByBlueprtId(blueprtId: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBossHpByBlueprtId(blueprtId: number) {
|
export function getBossHpByBlueprtId(blueprtId: number) {
|
||||||
let bossHpInfo = getBossHpByWarId(getWarIdByBlueprtId(blueprtId));
|
let warId = getWarIdByBlueprtId(blueprtId);
|
||||||
|
let { dispatchJsonId } = getWarById(warId);
|
||||||
|
let bossHpInfo = getBossHpByWarId(dispatchJsonId);
|
||||||
return bossHpInfo;
|
return bossHpInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRewardByBlueprtId(blueprtId: number) {
|
||||||
|
let warId = getWarIdByBlueprtId(blueprtId);
|
||||||
|
let { fixReward } = getWarById(warId);
|
||||||
|
return fixReward;
|
||||||
|
}
|
||||||
|
|
||||||
export function hasExpeditionById(id: number) {
|
export function hasExpeditionById(id: number) {
|
||||||
return expeditionInfo.has(id);
|
return expeditionInfo.has(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ export function decodeIdCntArrayStr(str: string, multi: number) {
|
|||||||
const strMap = new Map();
|
const strMap = new Map();
|
||||||
strArr.forEach(item => {
|
strArr.forEach(item => {
|
||||||
const kv = item.split('&');
|
const kv = item.split('&');
|
||||||
strMap.set(kv[0], multi? parseInt(kv[1]) * multi: kv[1]);
|
strMap.set(kv[0], multi? Math.ceil(parseInt(kv[1]) * multi): kv[1]);
|
||||||
});
|
});
|
||||||
return strMap;
|
return strMap;
|
||||||
}
|
}
|
||||||
@@ -383,3 +383,12 @@ export async function updateCe(roleId: string, hero: any ) {
|
|||||||
await HeroModel.updateCe(roleId, hid, ce, oldCe, historyCe);
|
await HeroModel.updateCe(roleId, hid, ce, oldCe, historyCe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ratioReward(rewardStr: string, ratio: number): string {
|
||||||
|
let rewards = decodeIdCntArrayStr(rewardStr, ratio);
|
||||||
|
let res = '';
|
||||||
|
for (let [k, v] of rewards) {
|
||||||
|
res += `${k}&${v}|`;
|
||||||
|
}
|
||||||
|
return res.substring(0, res.length - 1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user