114 lines
6.5 KiB
TypeScript
114 lines
6.5 KiB
TypeScript
|
|
// 动态
|
|
import { GVG_REC_ID, GVG_REC_TYPE, GVG_RESOURCE_TYPE } from "../../consts";
|
|
import { GVGBattleRecType } from "../../db/GVGBattleRec";
|
|
import { GVGRecModel } from "../../db/GVGRec";
|
|
import { GVGTeamType } from "../../db/GVGTeam";
|
|
import { GVGVestigeRecType } from "../../db/GVGVestigeRec";
|
|
import { gameData } from "../../pubUtils/data";
|
|
import { nowSeconds } from "../../pubUtils/timeUtil";
|
|
import { getGVGConfig } from "./gvgService";
|
|
|
|
// 加入军团
|
|
export async function guildJoinLeagueRecord(leagueCode: string, guildName: string) {
|
|
await leagueJoinOrQuitGuild(leagueCode, guildName, GVG_REC_ID.LEAGUE_JOIN_GUILD);
|
|
}
|
|
|
|
// 退出军团
|
|
export async function guildQuitLeagueRecord(leagueCode: string, guildName: string) {
|
|
await leagueJoinOrQuitGuild(leagueCode, guildName, GVG_REC_ID.LEAGUE_QUIT_GUILD);
|
|
}
|
|
|
|
async function leagueJoinOrQuitGuild(leagueCode: string, guildName: string, recId: GVG_REC_ID.LEAGUE_JOIN_GUILD|GVG_REC_ID.LEAGUE_QUIT_GUILD) {
|
|
let { configId } = getGVGConfig();
|
|
let params = [guildName];
|
|
await GVGRecModel.addRec({ leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId, createTime: nowSeconds(), params })
|
|
}
|
|
|
|
// 获得资源
|
|
export async function addResourceRecord(roleId: string, roleName: string, leagueCode: string, resourceType: GVG_RESOURCE_TYPE, output: number) {
|
|
let { configId } = getGVGConfig();
|
|
let params = [roleName, getResourceNameByType(resourceType), `${output}`];
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId: GVG_REC_ID.ADD_RESOURCE, createTime: nowSeconds(), params })
|
|
}
|
|
|
|
function getResourceNameByType(resourceType: GVG_RESOURCE_TYPE) {
|
|
switch(resourceType) {
|
|
case GVG_RESOURCE_TYPE.FOOD: return '粮食';
|
|
case GVG_RESOURCE_TYPE.MINERAL: return '矿物';
|
|
case GVG_RESOURCE_TYPE.WOOD: return '木堆';
|
|
}
|
|
}
|
|
|
|
export async function addVestigeBattleEndRec(rec: GVGVestigeRecType) {
|
|
if(!rec) return;
|
|
let { configId, vestigeId } = rec;
|
|
let vestigeName = gameData.gvgVestigeName.get(vestigeId);
|
|
if(rec.defenseInfo && rec.defenseInfo.isRobot) { // 对手是机器人,驻扎动态
|
|
let { roleId, roleName, leagueCode, newRank, isSuccess } = rec.attackInfo;
|
|
if(isSuccess) {
|
|
let params = [ roleName, vestigeName, `第${newRank}名`];
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId: GVG_REC_ID.SETTLE_POINT, createTime: nowSeconds(), params });
|
|
}
|
|
}
|
|
if(rec.defenseInfo && !rec.defenseInfo.isRobot && rec.attackInfo.leagueCode != rec.defenseInfo.leagueCode) {
|
|
let { leagueName, newRank, isSuccess } = rec.attackInfo;
|
|
let { roleId, leagueCode, roleName } = rec.defenseInfo;
|
|
if(isSuccess) {
|
|
let params = [ roleName, vestigeName, `第${newRank}名`, leagueName];
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId: GVG_REC_ID.POINT_BE_GRAB, createTime: nowSeconds(), params });
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function addVestigeLeagueRankRec(configId: number, ranks: { rank: number, field: string }[]) {
|
|
await GVGRecModel.addRecs(ranks.map(({ rank, field: leagueCode }) => {
|
|
let params = [ `第${rank}名`];
|
|
return { leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId: GVG_REC_ID.VESTIGE_RANK, createTime: nowSeconds(), params };
|
|
}));
|
|
}
|
|
|
|
export async function addBattleEndRec(rec: GVGBattleRecType) {
|
|
let { isSuccess, attackTeam, defenseTeam, configId } = rec;
|
|
let { roleId, leagueCode, cityId, index, curTeamBreak, originPointId } = defenseTeam;
|
|
if(!defenseTeam.isRobot) { // 防守的不是机器
|
|
if(isSuccess) {
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_ROLE, recId: GVG_REC_ID.TEAM_BE_HIT, createTime: nowSeconds(), params: [`${attackTeam.roleName}`, `队伍${index}`] });
|
|
if(curTeamBreak && originPointId > 0 ) {
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_ROLE, recId: GVG_REC_ID.TEAM_LOST_POINT, createTime: nowSeconds(), params: [`${attackTeam.roleName}`, `队伍${index}`, getPointName(originPointId)] });
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_CITY, recId: GVG_REC_ID.CITY_OCCUPY_CHANGE, createTime: nowSeconds(), params: [`${attackTeam.roleName}`, `${defenseTeam.roleName}`, getPointName(originPointId)] });
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_LEAGUE, recId: GVG_REC_ID.LEAGUE_OCCUPY_CHANGE, createTime: nowSeconds(), params: [`${attackTeam.roleName}`, `${defenseTeam.roleName}`, getPointName(originPointId)] });
|
|
}
|
|
} else {
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_ROLE, recId: GVG_REC_ID.TEAM_GUARD_SUCCESS, createTime: nowSeconds(), params: [`${attackTeam.roleName}`, `队伍${index}`] });
|
|
|
|
}
|
|
}
|
|
if(defenseTeam.isRobot && defenseTeam.isCatapult) {
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_CITY, recId: GVG_REC_ID.CITY_CATAPULT, createTime: nowSeconds(), params: [`${attackTeam.roleName}`, getCityName(cityId)] });
|
|
}
|
|
|
|
}
|
|
|
|
function getPointName(pointId: number) {
|
|
let dicAreaPoint = gameData.gvgAreaPoint.get(pointId);
|
|
let dicArea = gameData.gvgArea.get(dicAreaPoint?.areaId);
|
|
if(!dicArea) return '';
|
|
return dicArea.areaName||'';
|
|
}
|
|
|
|
function getCityName(cityId: number) {
|
|
let dicCity = gameData.gvgCity.get(cityId);
|
|
return dicCity?.cityName||'';
|
|
}
|
|
|
|
export async function addTeamSettleRec(team: GVGTeamType) {
|
|
let { roleId, roleName, leagueCode, configId, cityId, pointId } = team;
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_CITY, recId: GVG_REC_ID.CITY_TEAM_SETTLE, createTime: nowSeconds(), params: [`${roleName}`, getPointName(pointId)] });
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_LEAGUE, recId: GVG_REC_ID.LEAGUE_TEAM_SETTLE, createTime: nowSeconds(), params: [`${roleName}`, getPointName(pointId)] });
|
|
}
|
|
|
|
export async function addTeamLeaveRec(team: GVGTeamType, pointId: number) {
|
|
let { roleId, roleName, leagueCode, configId, cityId } = team;
|
|
await GVGRecModel.addRec({ roleId, leagueCode, configId, cityId, type: GVG_REC_TYPE.BATTLE_BY_LEAGUE, recId: GVG_REC_ID.LEAGUE_TEAM_LEAVE, createTime: nowSeconds(), params: [`${roleName}`, getPointName(pointId)] });
|
|
} |