diff --git a/game-server/app/servers/battle/handler/comBattleHandler.ts b/game-server/app/servers/battle/handler/comBattleHandler.ts index f85ec426a..29c041333 100644 --- a/game-server/app/servers/battle/handler/comBattleHandler.ts +++ b/game-server/app/servers/battle/handler/comBattleHandler.ts @@ -7,7 +7,7 @@ import { difference } from 'underscore'; */ import { IT_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, COM_TEAM_STATUS, COM_BTL_CONST, CONSUME_TYPE, COM_BTL_QUALITY, QUALITY_TYPE } from './../../../consts'; import { getGoodById, getBossHpByBlueprtId, getBlueprtComposeByQuality, getBluePrtByQuality, getWarById, getWarIdByBlueprtId, comBtlRangeInfo, comBtlRangeByLv } from '../../../pubUtils/gamedata'; -import { ComBattleTeamModel, BossHp } from '../../../db/ComBattleTeam'; +import { ComBattleTeamModel, BossHp, ComBattleTeamType } from '../../../db/ComBattleTeam'; import Role, { RoleModel } from '../../../db/Role'; import { STATUS } from '../../../consts/statusCode'; import { Application, BackendSession } from 'pinus'; @@ -17,9 +17,10 @@ import { ItemModel } from '../../../db/Item'; import { handleFixedReward, addItems, handleCost, decreaseItems } from '../../../services/rewardService'; import { checkRoleInQueue, getTeamSearchByQuality, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService'; import { transBossHpArr } from '../../../services/battleService'; -import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult, clearComBtlTimer, getRealReward, getAssistTimesByQuality, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, incEquipPrintDrop, randEquipPrintId, handleComBtlProgress } from '../../../services/comBattleService'; +import { getRandBlueprtId, getRandComBtlRobots, checkComBattleResult, clearComBtlTimer, getRealReward, getAssistTimesByQuality, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, incEquipPrintDrop, randEquipPrintId, handleComBtlProgress, getComBattleFriendAdd } from '../../../services/comBattleService'; import { setAp } from '../../../services/actionPointService'; import { roleLevelup } from '../../../services/normalBattleService'; +import { FriendRelationModel } from '../../../db/FriendRelation'; export default function(app: Application) { return new ComBattleHandler(app); @@ -127,11 +128,22 @@ export class ComBattleHandler { let roleInfo = await RoleModel.findByRoleId(teammate.roleId); if (!roleInfo || roleIds.indexOf(teammate.roleId) !== -1) continue; let {roleId, roleName, headHid = 19, sHid = 19, topFiveCe, lv} = roleInfo; + + // 黑名单屏蔽 + let hasBlackList = false; + for(let hisRoleId of roleIds) { + let isInBlackList = await FriendRelationModel.isInBlackList(roleId, hisRoleId); + if(isInBlackList) { hasBlackList = true; break; } + } + if(hasBlackList) continue; + topFiveCe = reduceCe(topFiveCe); if (topFiveCe < ceLimit) continue; let isFrd = await getFrd(roleId, goodData.quality); const st = new RoleStatus(roleId, roleName, false, isFrd, headHid, sHid, topFiveCe, lv); + await getComBattleFriendAdd(st, roleStatus); + roleStatus.push(st); roleIds.push(roleInfo.roleId); } @@ -215,7 +227,22 @@ export class ComBattleHandler { return resResult(STATUS.COM_BLUEPRT_QUALITY_ERROR); } - const team = await ComBattleTeamModel.getOtherTeamByQualityAndSt(roleId, qualityArr, COM_TEAM_STATUS.DEFAULT, lvRange, topFiveCe); + const teams = await ComBattleTeamModel.getOtherTeamByQualityAndSt(roleId, qualityArr, COM_TEAM_STATUS.DEFAULT, lvRange, topFiveCe); + let team: ComBattleTeamType; + for(let curTeam of teams) { + let { roleIds } = curTeam; + + // 黑名单屏蔽 + let hasBlackList = false; + for(let hisRoleId of roleIds) { + let isInBlackList = await FriendRelationModel.isInBlackList(roleId, hisRoleId); + if(isInBlackList) { hasBlackList = true; break; } + } + if(!hasBlackList) { + team = curTeam; break; + } + } + // TODO: 有匹配的队伍还需要重新 joinTeam 加入,有失败可能,体验不好,需优化 if (team && team.roleIds.length < 3 && team.status === COM_TEAM_STATUS.DEFAULT && team.roleIds.indexOf(roleId) === -1) { return resResult(STATUS.SUCCESS, {teamCode: team.teamCode}); @@ -312,6 +339,13 @@ export class ComBattleHandler { if (!isFrd) { isFrd = await getFrd(roleId, quality); } + + // 一般不会匹配到,手动邀请的可以加入 + // for(let hisRoleId of teamStatus.roleIds) { + // let isInBlackList = await FriendRelationModel.isInBlackList(roleId, hisRoleId); + // if(isInBlackList) return resResult(STATUS.COM_BATTLE_BLACKLIST); + // } + // 加入队伍 let roleStatus = new RoleStatus(roleId, roleName, false, isFrd, headHid, sHid, topFiveCe, lv); const team = await ComBattleTeamModel.addRole(teamCode, roleStatus); @@ -324,6 +358,10 @@ export class ComBattleHandler { let channel = channelService.getChannel(teamCode, false); teamStatus.roleIds.push(roleId); teamStatus.roleStatus.push(roleStatus); + + // 好友加成 + await getComBattleFriendAdd(roleStatus, teamStatus.roleStatus); + let users = channel.getMembers(); if (users.indexOf(roleId) === -1) { channel.add(roleId, sid); diff --git a/game-server/app/services/comBattleService.ts b/game-server/app/services/comBattleService.ts index f7461b06f..97af60a9f 100644 --- a/game-server/app/services/comBattleService.ts +++ b/game-server/app/services/comBattleService.ts @@ -10,6 +10,7 @@ import { difference, omit } from 'underscore'; import { Channel } from 'pinus'; import { TREASURE } from '../pubUtils/dicParam'; import { decreaseItems } from './rewardService'; +import { getFriendLvAdd } from './friendService'; /** * 在给定的品质列表中随机返回一定数量的藏宝图Id @@ -421,4 +422,22 @@ export function randEquipPrintId(warInfo) { return null; } return result.dic.id; +} + +/** + * 按照好友关系,新增加成 + * + * @param {RoleStatus} myRoleStatus 新增的队友 + * @param {RoleStatus[]} roleStatus 队伍内的所有队友 + */ +export async function getComBattleFriendAdd(myRoleStatus: RoleStatus, roleStatus: RoleStatus[]) { + let myAdd = 0; // 多好友,加成直接叠加 + for(let rs of roleStatus) { + if(myRoleStatus.roleId == rs.roleId) continue; + if(myRoleStatus.isRobot || rs.isRobot) continue; + let add = await getFriendLvAdd(myRoleStatus.roleId, rs.roleId); + rs.addFrdRatio(add); + myAdd += add; + } + myRoleStatus.addFrdRatio(myAdd); } \ No newline at end of file diff --git a/game-server/app/services/friendService.ts b/game-server/app/services/friendService.ts index c01c3aaaf..03affa8a5 100644 --- a/game-server/app/services/friendService.ts +++ b/game-server/app/services/friendService.ts @@ -3,7 +3,7 @@ import { RoleType, RoleModel } from "../db/Role"; import { FriendRelationType, Relation } from "../db/FriendRelation"; import { getResStr } from "../pubUtils/util"; import { STATUS, FRIEND_RELATION_TYPE } from "../consts"; -import { FriendShipType } from "../db/FriendShip"; +import { FriendShipType, FriendShipModel } from "../db/FriendShip"; import { outputCnt } from '../pubUtils/friendUtil'; /** @@ -87,4 +87,16 @@ function getSentHeart(roleId: string, relation: Relation) { beSentHeart: json.beSentHeart, beSentHeartTime: json.beSentHeartTime } +} + +export async function getFriendLvAdd(roleId: string, hisRoleId: string) { + let friendShip = await FriendShipModel.getFriendLv(roleId, hisRoleId); + if(!friendShip) { + return 0 + } + let dic = gameData.roleFriendLv.get(friendShip.friendLv); + if(!dic) { + return 0 + } + return dic.comBattleAdd } \ No newline at end of file diff --git a/shared/consts/constModules/selectConst.ts b/shared/consts/constModules/selectConst.ts index b5ac4ac8d..e6b2c0500 100644 --- a/shared/consts/constModules/selectConst.ts +++ b/shared/consts/constModules/selectConst.ts @@ -4,12 +4,14 @@ export enum ROLE_SELECT { ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topFiveCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild', // 玩家列表显示基础数据 SHOW_SIMPLE = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName serverId userInfo.serverType', + // 显示申请需要的信息 SHOW_FRIEND_APPLY_LIST = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName friendCnt recFrdApplyCnt serverId userInfo.serverType', HANDLE_APPLY = 'roleId friendCnt lv', ATTR = 'globalCeAttr', GET_LV = 'lv', GET_ROLE_ID = 'roleId', GET_MY_SERVER = 'lv serverId userInfo.serverType', + COM_BATTLE = 'lv headHid sHid topFiveCe' }; export enum HERO_SELECT { @@ -31,4 +33,8 @@ export enum USER_GUILD_SELECT { export enum GUILD_SELECT { ENTRY = 'guildCode lv memberCnt' +} + +export enum FRIEND_SHIP_SELECT { + GET_FRIEND_VALUE = 'friendValue friendLv' } \ No newline at end of file diff --git a/shared/consts/statusCode.ts b/shared/consts/statusCode.ts index c6b70e57a..c3fc66c7e 100644 --- a/shared/consts/statusCode.ts +++ b/shared/consts/statusCode.ts @@ -107,6 +107,7 @@ export const STATUS = { COM_BATTLE_REWARDED: { code: 20628, simStr: '奖励已领取' }, COM_BATTLE_HEROES_ERR: { code: 20629, simStr: '阵容异常' }, COM_BATTLE_SET_FRD_ERR: { code: 20630, simStr: '设置情谊助战异常' }, + COM_BATTLE_BLACKLIST: { code: 20633, simStr: '队伍中存在黑名单玩家' }, // 共斗藏宝图合成 COM_BLUEPRT_QUALITY_CANNOT_COMPOSE: { code: 20630, simStr: '该品质藏宝图不可合成' }, diff --git a/shared/db/ComBattleTeam.ts b/shared/db/ComBattleTeam.ts index 62480fba3..4af1b5124 100644 --- a/shared/db/ComBattleTeam.ts +++ b/shared/db/ComBattleTeam.ts @@ -46,6 +46,9 @@ export class RoleStatus { // 固定奖励 @prop({ required: true, default: '&' }) fixReward: string; + // 好友间伤害加成 + @prop({ required: true, default: 0 }) + frdRatio: number = 0; constructor(roleId: string, roleName: string, isCap: boolean, isFrd: boolean, headHid: number, sHid: number, topFiveCe: number, lv: number, heroes = [], isRobot = false) { this.roleId = roleId; @@ -61,6 +64,14 @@ export class RoleStatus { this.killed = []; this.isRobot = isRobot; } + + addFrdRatio(frdRatio: number) { + if(!this.frdRatio) { + this.frdRatio = frdRatio; + } else { + this.frdRatio += frdRatio; + } + } } export class BossHp { @@ -233,7 +244,7 @@ export default class ComBattleTeam extends BaseModel { public static async getOtherTeamByQualityAndSt(roleId: string, qualityArr: Array, status: number, lvRange: number, ce = 0, pub = true, cntLmt = 2, lean = true) { const curTime = new Date(Date.now() - 10 * 60 * 1000); // 10分钟之前 - const team: ComBattleTeamType = await ComBattleTeamModel.findOne({quality: {$in: qualityArr}, status, lvRange, ceLimit: {$lte: ce}, pub, roleCnt: {$lte: cntLmt}, roleIds: {$nin: [roleId]}, updatedAt: {$gte: curTime}}).lean(lean); + const team: ComBattleTeamType[] = await ComBattleTeamModel.find({quality: {$in: qualityArr}, status, lvRange, ceLimit: {$lte: ce}, pub, roleCnt: {$lte: cntLmt}, roleIds: {$nin: [roleId]}, updatedAt: {$gte: curTime}}).lean(lean); return team; } diff --git a/shared/db/FriendRelation.ts b/shared/db/FriendRelation.ts index 493c2b6b5..6511ca0a6 100644 --- a/shared/db/FriendRelation.ts +++ b/shared/db/FriendRelation.ts @@ -56,7 +56,9 @@ export default class FriendRelation extends BaseModel { document.populate('friends.friendShip', null, 'FriendShip'); } - let result: FriendRelationType = await document; + let result: FriendRelationType = await document.lean({ getters: true, virtuals: true });; + + console.log(JSON.stringify(result)); return result; } @@ -79,6 +81,13 @@ export default class FriendRelation extends BaseModel { return result } + public static async isInBlackList(roleId: string, hisRoleId: string) { + let result = await FriendRelationModel.find({ + $or: [{ roleId, 'blacklist.roleId': hisRoleId}, { hisRoleId, 'blacklist.roleId': roleId}] + }).lean(); + return result.length > 0; + } + public static async deleteAccount(roleId: string) { let result = await FriendRelationModel.deleteMany({ roleId }); await FriendRelationModel.updateMany({}, { $pull: { friends: { roleId }, blacklist: { roleId } }}); diff --git a/shared/db/FriendShip.ts b/shared/db/FriendShip.ts index 1fd7cf980..1f87dac29 100644 --- a/shared/db/FriendShip.ts +++ b/shared/db/FriendShip.ts @@ -4,7 +4,7 @@ import { getFriendLvByExp } from '../pubUtils/data'; import * as util from '../pubUtils/friendUtil'; import { nowSeconds } from '../pubUtils/timeUtil'; import { FRIEND } from '../pubUtils/dicParam'; -import { FRIEND_SELECT } from '../consts'; +import { FRIEND_SELECT, FRIEND_SHIP_SELECT } from '../consts'; /** * 好友直接的亲密值 @@ -59,7 +59,7 @@ export default class FriendShip extends BaseModel { const doc = new FriendShipModel(); const update = Object.assign(doc.toJSON(), { roleIdA, roleIdB, roleIds }); - const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $setOnInsert: update }, { upsert: true, new: true }).lean(); + const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $setOnInsert: update }, { upsert: true, new: true }).lean({ virtuals: true }); return result; } @@ -69,7 +69,7 @@ export default class FriendShip extends BaseModel { if (roleIdList.length != 2) return false; let { roleIds } = util.getRoleIds(roleIdList); - const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $set: { friendValue: 0 } }, { new: true }).lean(); + const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $set: { friendValue: 0 } }, { new: true }).lean({ virtuals: true }); return result; } @@ -84,7 +84,7 @@ export default class FriendShip extends BaseModel { let obj = this.getRefData(); const result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $set: { ...obj } - }, { new: true }).lean(); + }, { new: true }).lean({ virtuals: true }); return result; } @@ -155,6 +155,13 @@ export default class FriendShip extends BaseModel { .lean({ virtuals: true }); return result; } + + public static async getFriendLv(roleId: string, hisRoleId: string) { + let { roleIds } = util.getRoleIds([roleId, hisRoleId]); + + let result: FriendShipType = await FriendShipModel.findOne({ roleIds }).select(FRIEND_SHIP_SELECT.GET_FRIEND_VALUE).lean({ virtuals: true }); + return result; + } } export const FriendShipModel = getModelForClass(FriendShip);