寻宝:抽象把玩家数据加入队伍的逻辑

This commit is contained in:
liangtongchuan
2021-02-19 17:04:25 +08:00
parent c7ca97d19d
commit ea5d507983
2 changed files with 50 additions and 22 deletions
@@ -1,3 +1,4 @@
import { MemComBtlTeam } from './../domain/battleField/ComBattleTeamField';
import { ItemModel } from './../db/Item';
import { IT_TYPE } from './../consts/consts';
import { COM_BTL_QUALITY } from './../consts/constModules/itemConst';
@@ -547,6 +548,13 @@ export function createComTeamData(teamCode: string, pub: boolean, blueprtId: num
};
}
/**
* @description 检查是否有足够的藏宝图,未结束的战斗也占用一张藏宝图
* @export
* @param {string} roleId
* @param {number} blueprtId
* @returns
*/
export async function hasEnoughBlueprt(roleId: string, blueprtId: number) {
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
if (!blueprt) return false;
@@ -554,4 +562,32 @@ export async function hasEnoughBlueprt(roleId: string, blueprtId: number) {
let teams = await ComBattleTeamModel.getTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING);
if (teams && blueprt.count <= teams.length) return false;
return true;
}
/**
* @description 将玩家加入到队伍数据结构中,需将玩家信息做转化
* @export
* @param {MemComBtlTeam} comTeam 队伍数据结构
* @param {RoleType} roleInfo 原始玩家信息
* @param {boolean} isCap
* @param {boolean} isFrd
*/
export async function addRoleToTeam(comTeam: MemComBtlTeam, roleInfo: RoleType, isCap: boolean, isFrd: boolean) {
const { roleId, roleName, headHid = 19, sHid = 19, lv } = roleInfo;
let { topFiveCe = 1000 } = roleInfo;
topFiveCe = reduceCe(topFiveCe);
const roleSt = new RoleStatus(roleId, roleName, isCap, isFrd, headHid, sHid, topFiveCe, lv);
addRoleStToTeam(comTeam, roleSt);
}
/**
* @description 将玩家加入到队伍数据结构中
* @export
* @param {MemComBtlTeam} comTeam 队伍数据结构
* @param {RoleStatus} roleSt 要加入的玩家数据
*/
export function addRoleStToTeam(comTeam: MemComBtlTeam, roleSt: RoleStatus) {
const { roleStatus = [], roleIds = [] } = comTeam;
comTeam.roleStatus = [roleSt, ...roleStatus];
comTeam.roleIds = [roleSt.roleId, ...roleIds];
}