好友:寻宝关系加成及黑名单屏蔽
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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'
|
||||
}
|
||||
@@ -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: '该品质藏宝图不可合成' },
|
||||
|
||||
@@ -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<number>, 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 } }});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user