✨ feat(gvg): 激战期挑战相关接口整理
This commit is contained in:
@@ -180,4 +180,5 @@ export const PUSH_ROUTE = {
|
||||
LEAGUE_ABDICATE: 'onLeagueAbdicate', // 当被转让盟主
|
||||
LEAGUE_ITEM_UPDATE: 'onLeagueItemUpdate',
|
||||
GVG_TASK_UPDATE: 'onGVGTaskUpdate', // GVG任务更新
|
||||
GVG_TEAM_ATTACKED: 'onTeamAttacked', // 当队伍受到攻击
|
||||
}
|
||||
@@ -369,6 +369,9 @@ export const STATUS = {
|
||||
GVG_BATTLEREC_NOT_FOUND: { code: 21407, simStr: '未找到该记录' },
|
||||
GVG_AREA_NOT_IN_CITY: { code: 21408, simStr: '选择区域不在这座城池中' },
|
||||
GVG_TEAM_NOT_FOUND: { code: 21409, simStr: '未找到这个队伍' },
|
||||
GVG_LOCK_TIME_OUT: { code: 21410, simStr: '挑战超时' },
|
||||
GVG_ATTACK_TEAM_BROKEN: { code: 21411, simStr: '挑战队伍已被击破' },
|
||||
GVG_DEFENSE_TEAM_BROKEN: { code: 21411, simStr: '对方队伍已被击破' },
|
||||
|
||||
// 通用 30000 - 30099
|
||||
DIC_DATA_NOT_FOUND: { code: 30000, simStr: '数据表未找到' },
|
||||
|
||||
@@ -13,7 +13,7 @@ class TeamInfo {
|
||||
teamCode: string; // 玩家队伍唯一标识
|
||||
|
||||
@prop({ required: true })
|
||||
teamId: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
index: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
|
||||
@prop({ required: true })
|
||||
leagueCode: string; // 联军
|
||||
@@ -62,7 +62,7 @@ export default class GVGBattleRec extends BaseModel {
|
||||
|
||||
public static async createRec(attackTeam: GVGTeamType, defenseTeam: GVGTeamType) {
|
||||
const battleCode = genCode(8);
|
||||
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { attackTeam, defenseTeam, isSuccess: false } }).lean();
|
||||
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { attackTeam, defenseTeam, isSuccess: false } }, { new: true, upsert: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+90
-57
@@ -6,12 +6,16 @@ import { LineupHero } from './../domain/roleField/hero';
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { GVG } from "../pubUtils/dicParam";
|
||||
import { DicGVGAreaPoint } from "../pubUtils/dictionary/DicGVGAreaPoint";
|
||||
import { InitTeamParam, SaveTeamUpdateParam } from "../domain/gvgField/gvgDb";
|
||||
|
||||
@index({ roleId: 1, teamId: 1 })
|
||||
@index({ roleId: 1, index: 1 })
|
||||
@index({ teamCode: 1 })
|
||||
@index({ cityId: 1, leagueId: 1 })
|
||||
export default class GVGTeam extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
configId: number; // 赛季,每赛季在enterCity的时候检测,如果不一样就更新durability那些东西
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 玩家id
|
||||
|
||||
@@ -25,7 +29,7 @@ export default class GVGTeam extends BaseModel {
|
||||
teamCode: string; // 玩家队伍唯一标识
|
||||
|
||||
@prop({ required: true })
|
||||
teamId: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
index: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
|
||||
@prop({ required: true })
|
||||
leagueCode: string; // 联军
|
||||
@@ -66,6 +70,12 @@ export default class GVGTeam extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
attackTime: number; // 进攻冷却时间
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
lockTime: number; // 正在被进攻中
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
attackTeam: string; // 正在被这支队伍进攻中
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
fromAreaId: number; // 从那个区域移动
|
||||
|
||||
@@ -79,7 +89,10 @@ export default class GVGTeam extends BaseModel {
|
||||
defenseTime: number; // 防守保护时间
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
point: number; // 积分
|
||||
playerScore: number; // 积分
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
leagueScore: number; // 积分
|
||||
|
||||
@prop({ required: true, type: () => LineupHero, _id: false })
|
||||
lineup: LineupHero[];
|
||||
@@ -96,57 +109,34 @@ export default class GVGTeam extends BaseModel {
|
||||
@prop({ required: true, default: false })
|
||||
isRobot: boolean; // 是否是机器人
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
isCatapult: boolean; // 是否是投石车
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
isBroken: boolean; // 机器人是否被击破,如果没有被击破,那么这个位置上就还是机器人,如果被击破了,这个位置就空出给玩家
|
||||
|
||||
// 创建队伍
|
||||
public static async createTeam(roleId: string, roleName: string, serverId: number, leagueCode: string, leagueName: string, teamId: number, head: number, spine: number, frame: number, durability: number, lineup: [LineupHero], lineupCe: number) {
|
||||
public static async saveTeam(roleId: string, index: number, updateParam: SaveTeamUpdateParam, initParam: InitTeamParam) {
|
||||
const doc = new GVGTeamModel();
|
||||
const teamCode = genCode(8);
|
||||
const update = Object.assign(doc.toJSON(), { roleId, roleName, serverId, leagueCode, leagueName, teamId, teamCode, head, spine, frame, lineup, durability, maxDurability: durability, lineupCe });
|
||||
const team: GVGTeamType | null = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
const insert = Object.assign(doc.toJSON(), { ...initParam, teamCode });
|
||||
delete insert.lineup;
|
||||
const team: GVGTeamType | null = await GVGTeamModel.findOneAndUpdate({ roleId, index }, { $setOnInsert: insert, $set: updateParam }, { upsert: true, new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 保存队伍
|
||||
public static async saveTeam(roleId: string, roleName: string, serverId: number, leagueCode: string, leagueName: string, teamId: number, head: number, spine: number, frame: number, durability: number, lineup: [LineupHero], lineupCe: number) {
|
||||
let team: GVGTeamType = await GVGTeamModel.findOne({ roleId, teamId }).lean();
|
||||
if (!team) {
|
||||
team = await this.createTeam(roleId, roleName, serverId, leagueCode, leagueName, teamId, head, spine, frame, durability, lineup, lineupCe);
|
||||
return team;
|
||||
}
|
||||
|
||||
const update = { head, spine, frame };
|
||||
if (lineup && lineup.length > 0) {
|
||||
update['lineup'] = lineup;
|
||||
}
|
||||
team = await GVGTeamModel.findOneAndUpdate({ roleId, teamId }, { update }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 查找角色队伍数
|
||||
public static async getTeamCntByRole(roleId: string) {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select('teamCode').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
// 通过城池ID获取队伍数
|
||||
public static async getTeamCntByCity(cityId: number, leagueCode?: string) {
|
||||
const query = { cityId };
|
||||
if (leagueCode) {
|
||||
query['leagueCode'] = leagueCode;
|
||||
}
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find(query).select('').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
public static async checkCity(roleId: string, cityId: number, groupId: number, serverType: number) {
|
||||
return await GVGTeamModel.exists({ roleId, cityId, groupId, serverType });
|
||||
}
|
||||
|
||||
// 玩家切换城池更新队伍信息
|
||||
public static async enterCity(roleId: string, cityId: number, areaId: number, groupId: number, serverType: number) {
|
||||
const res = await GVGTeamModel.updateMany({ roleId }, { cityId, areaId, pointId: 0, groupId, serverType }).lean();
|
||||
return !!res['ok'];
|
||||
}
|
||||
|
||||
// 查找角色队伍数
|
||||
public static async getTeamCntByRole(roleId: string) {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select('teamCode').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
// 获取我的编队
|
||||
public static async findByRole(roleId: string, select = '') {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select(select).lean();
|
||||
@@ -161,12 +151,12 @@ export default class GVGTeam extends BaseModel {
|
||||
|
||||
// 移动
|
||||
public static async startMove(teamCode: string, areaId: number, fromAreaId: number) {
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId, stopMoveTime: nowSeconds() + GVG.GVG_DEFAULT_MOVE_CD } }).lean();
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId, stopMoveTime: nowSeconds() + GVG.GVG_DEFAULT_MOVE_CD } }, { new: true }).lean();
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async stopMove(teamCode: string, areaId: number) {
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId: 0, stopMoveTime: nowSeconds() } }).lean();
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId: 0, stopMoveTime: nowSeconds() } }, { new: true }).lean();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -180,40 +170,83 @@ export default class GVGTeam extends BaseModel {
|
||||
}
|
||||
return { attackTeam, defenseTeam }
|
||||
}
|
||||
|
||||
public static async checkRobot(groupId: number, serverType: number, cityId: number) {
|
||||
return await GVGTeamModel.exists({ groupId, serverType, cityId, isRobot: true });
|
||||
}
|
||||
|
||||
public static async initRobots(groupId: number, serverType: number, cityId: number, dicPoints: DicGVGAreaPoint[]) {
|
||||
await GVGTeamModel.bulkWrite(dicPoints.map(dic => {
|
||||
// 每赛季初刷新自己的耐久等东西
|
||||
public static async refreshByConfig(roleId: string, updateArr: GVGTeamUpdate[]) {
|
||||
await GVGTeamModel.bulkWrite(updateArr.map(obj => {
|
||||
return {
|
||||
updateOne: {
|
||||
filter: { groupId, serverType, cityId, pointId: dic.pointId },
|
||||
update: { $setOnInsert: { teamCode: `robot${dic.pointId}`, ...dic, roleName: dic.name, isRobot: true } }, upsert: true
|
||||
filter: { roleId, teamCode: obj.teamCode },
|
||||
update: { $set: obj }
|
||||
}
|
||||
}
|
||||
}));
|
||||
return await GVGTeamModel.findByRole(roleId, '-_id');
|
||||
}
|
||||
|
||||
public static async findRobotTeams(groupId: number, serverType: number, cityId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, isRobot: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 每赛季初刷新机器人
|
||||
public static async initRobots(configId: number, groupId: number, serverType: number, cityId: number, dicPoints: DicGVGAreaPoint[]) {
|
||||
await GVGTeamModel.bulkWrite(dicPoints.map(({ pointId, areaId, name, head, spine, ce, durability }) => {
|
||||
return {
|
||||
updateOne: {
|
||||
filter: { groupId, serverType, cityId, areaId, pointId },
|
||||
update: { $setOnInsert: { teamCode: genCode(8), maxDurability: durability, roleName: name, head, spine, lineupCe: ce, isRobot: true, isBroken: false, startMoveTime: 0, stopMoveTime: 0 }, $set: { configId, durability } },
|
||||
upsert: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
return await this.findRobotTeams(groupId, serverType, cityId);
|
||||
}
|
||||
|
||||
// 攻击方攻击cd
|
||||
public static async lockAttack(teamCode: string, groupId: number, serverType: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD, groupId, serverType } }, { new: true }).lean();
|
||||
public static async battleStartLockAttack(teamCode: string) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 防守方防守cd
|
||||
public static async lockDefense(teamCode: string, groupId: number, serverType: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, groupId, serverType } }, { new: true }).lean();
|
||||
// 防守方锁定cd
|
||||
public static async battleStartLockDefense(teamCode: string, attackTeam: string) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { lockTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD, attackTeam } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 结算挑战方
|
||||
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number, leagueScoreInc: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, playerScore: playerScoreInc, leagueScore: leagueScoreInc } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 结算防守方
|
||||
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD }, $inc: { durability: hpInc, playerScore: playerScoreInc } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 队伍进入修整器
|
||||
public static async teamBreak(teamCode: string, isRobot: boolean, maxDurability: number, areaId: number) {
|
||||
if(!isRobot) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { restartTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, stopMoveTime: nowSeconds(), areaId, durability: maxDurability } }, { new: true }).lean();
|
||||
return team;
|
||||
} else {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { durability: 0, isBroken: true } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
public static async findByAreaId(groupId: number, serverType: number, cityId: number, areaId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, areaId, stopMoveTime: { $lte: nowSeconds() } }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async findByConfigId(configId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ configId, cityId: { $gt: 0 } }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export class GVGTeamMem extends GVGTeam {
|
||||
this.roleName = team.roleName;
|
||||
this.serverId = team.serverId;
|
||||
this.teamCode = team.teamCode;
|
||||
this.teamId = team.teamId;
|
||||
this.index = team.index;
|
||||
this.leagueCode = team.leagueCode;
|
||||
this.guildCode = team.guildCode;
|
||||
this.areaId = team.areaId;
|
||||
@@ -45,7 +45,7 @@ export class GVGTeamMem extends GVGTeam {
|
||||
this.defenseTime = team.defenseTime;
|
||||
this.startMoveTime = team.startMoveTime;
|
||||
this.stopMoveTime = team.stopMoveTime;
|
||||
this.point = team.point;
|
||||
this.playerScore = team.playerScore;
|
||||
}
|
||||
|
||||
public setCity(cityId: number, areaId = 0, pointId = 0) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { gameData } from "../../pubUtils/data";
|
||||
import { EXTERIOR, GVG } from "../../pubUtils/dicParam";
|
||||
import { DicGVGVestige } from "../../pubUtils/dictionary/DicGVGVestige";
|
||||
import { DicWarJson } from "../../pubUtils/dictionary/DicWarJson";
|
||||
import { LineupHero } from "../roleField/hero";
|
||||
|
||||
export class OppPlayerHeroInfo {
|
||||
@prop({ required: true })
|
||||
@@ -246,4 +247,28 @@ export class OppDetailData{
|
||||
let hero = this.heroes.find(cur => cur.actorId == hid);
|
||||
if(hero) hero.setAttribute(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
export interface SaveTeamParam {
|
||||
index: number;
|
||||
head: number;
|
||||
frame: number;
|
||||
spine: number;
|
||||
lineup?: LineupHero[];
|
||||
}
|
||||
|
||||
export interface SaveTeamUpdateParam extends SaveTeamParam {
|
||||
lineupCe?: number;
|
||||
configId: number;
|
||||
groupId: number;
|
||||
serverType: number;
|
||||
}
|
||||
|
||||
export interface InitTeamParam {
|
||||
roleName: string;
|
||||
serverId: number;
|
||||
leagueCode: string;
|
||||
leagueName: string;
|
||||
durability: number;
|
||||
maxDurability: number;
|
||||
}
|
||||
@@ -678,4 +678,42 @@ export class GVGTeamInListOnPoint extends GVGTeamInList {
|
||||
this.hasTeam = hasTeam;
|
||||
if(team) this.isRobot = team.isRobot;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新自己队伍时候的比较详细点的数据
|
||||
export class MyTeamInfo {
|
||||
teamCode: string; // 队伍唯一id
|
||||
index: number; // 队伍位置
|
||||
head: number; // 保存头像
|
||||
frame: number; // 保存相框
|
||||
spine: number; // 保存形象
|
||||
lineup: {
|
||||
actorId: number; // 武将
|
||||
dataId: number; // 出兵表上的位置
|
||||
order: number; // 行动
|
||||
}[];
|
||||
durability: number; // 耐久
|
||||
maxDurability: number; // 最大耐久
|
||||
restartTime: number; // 修整期结束时间
|
||||
attackTime: number; // 进攻冷却结束时间
|
||||
stopMoveTime: number; // 移动冷却结束时间
|
||||
defenseTime: number; // 防守保护时间
|
||||
areaId: number; // 出生在的区域
|
||||
pointId: number;
|
||||
|
||||
constructor(team: GVGTeamType) {
|
||||
this.teamCode = team.teamCode;
|
||||
this.index = team.index;
|
||||
this.head = team.head;
|
||||
this.frame = team.spine;
|
||||
this.lineup = team.lineup;
|
||||
this.durability = team.durability;
|
||||
this.maxDurability = team.maxDurability;
|
||||
this.restartTime = team.restartTime;
|
||||
this.attackTime = team.attackTime;
|
||||
this.stopMoveTime = team.stopMoveTime;
|
||||
this.defenseTime = team.defenseTime;
|
||||
this.areaId = team.areaId;
|
||||
this.pointId = team.pointId;
|
||||
}
|
||||
}
|
||||
@@ -406,4 +406,6 @@ export const GVG = {
|
||||
GVG_DEFAULT_ATTACK_CD: 5, // GVG激战期默认的攻击CD
|
||||
GVG_DEFAULT_DEFENSE_CD: 2, // GVG激战期默认的防御CD
|
||||
GVG_DEFAULT_DURABILITY_MINUS: '5&100', // GVG激战期默认的队伍耐扣除规则,胜&败:num&num
|
||||
GVG_PRODUCE_GAME_RATIO: '1&0.5|2&0.1|3&0.2', // 云台外政中贡献分3种产量分值换算 1:粮食*系数 2:铁矿*系数 3:木材*系数
|
||||
GVG_BATTLE_SCORE: 1000000, // 战力换算积分的除数
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user