|
|
|
@@ -2,14 +2,14 @@ import { ServerlistModel } from "../db/Serverlist";
|
|
|
|
|
import { RoleModel } from "../db/Role";
|
|
|
|
|
import { reduceCe } from "../pubUtils/util";
|
|
|
|
|
import { GUILDACTIVITY } from "../pubUtils/dicParam";
|
|
|
|
|
import { gameData, getGuildAuctionRewards, getTodayGuildActivity } from "../pubUtils/data";
|
|
|
|
|
import { gameData, getGuildAuctionRewards } from "../pubUtils/data";
|
|
|
|
|
import { getCurHourPoint, getCutDay, nowSeconds } from "../pubUtils/timeUtil";
|
|
|
|
|
import { GUILD_ACTIVITY_STATUS, GET_POINT_WAYS, GUILD_ACTIVITY_TYPE, REDIS_KEY, AUCTION_SOURCE, MAIL_TYPE } from "../consts";
|
|
|
|
|
import { GUILD_ACTIVITY_STATUS, GET_POINT_WAYS, GUILD_ACTIVITY_TYPE, REDIS_KEY, AUCTION_SOURCE, MAIL_TYPE, CITY_STATUS } from "../consts";
|
|
|
|
|
import { Record, UserGuildActivityRecModel } from "../db/UserGuildActivityRec";
|
|
|
|
|
import { GateMembersRec, GateActivityObject } from "../domain/battleField/guildActivity";
|
|
|
|
|
import { GateMembersRec, GateActivityObject, CityActivityObject, CityParam } from "../domain/battleField/guildActivity";
|
|
|
|
|
import { DicGuildActivity } from "../pubUtils/dictionary/DicGuildActivity";
|
|
|
|
|
import { getUnionRank, getRank, getGuildKeyName, getMyUnionRank, getRankScore } from "./redisService";
|
|
|
|
|
import Guild, { GuildModel } from "../db/Guild";
|
|
|
|
|
import { getUnionRank, getRank, getGuildKeyName, getMyUnionRank, getRankScore, getCityKeyName } from "./redisService";
|
|
|
|
|
import { GuildModel } from "../db/Guild";
|
|
|
|
|
import { SimpleGuildRankParam, SimpleRoleRankParam } from "../domain/rank";
|
|
|
|
|
import { getGuildChannelSid, getWorldChannelSid } from "./chatChannelService";
|
|
|
|
|
import { pinus } from "pinus";
|
|
|
|
@@ -18,15 +18,22 @@ import { uniq } from 'underscore'
|
|
|
|
|
import { genAuction } from "./auctionService";
|
|
|
|
|
import { sendMail } from "./mailService";
|
|
|
|
|
import { getHonourObject } from '../pubUtils/itemUtils';
|
|
|
|
|
import { GuildActivityCityType } from "../db/GuildActivityCity";
|
|
|
|
|
|
|
|
|
|
let gateActivityObj: GateActivityObject;
|
|
|
|
|
export function getGuildActivityObj(aid: number) {
|
|
|
|
|
if(aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
|
|
|
|
if(!gateActivityObj) {
|
|
|
|
|
gateActivityObj = new GateActivityObject()
|
|
|
|
|
}
|
|
|
|
|
return gateActivityObj;
|
|
|
|
|
let cityActivityObj: CityActivityObject;
|
|
|
|
|
export function getGateActivityObj() {
|
|
|
|
|
if(!gateActivityObj) {
|
|
|
|
|
gateActivityObj = new GateActivityObject();
|
|
|
|
|
}
|
|
|
|
|
return gateActivityObj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCityActivityObj() {
|
|
|
|
|
if(!cityActivityObj) {
|
|
|
|
|
cityActivityObj = new CityActivityObject();
|
|
|
|
|
}
|
|
|
|
|
return cityActivityObj
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -137,6 +144,20 @@ export function getRecordScore(aid: number, record: { round: number, dataId: num
|
|
|
|
|
return { score: sum, newRecords, memberRecord }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getGateActivityRank(guildCode: string, serverId: number, roleId?: string, roleName?: string) {
|
|
|
|
|
let guildKey = REDIS_KEY.GATE_ACTIVITY;
|
|
|
|
|
let memberKey = getGuildKeyName(REDIS_KEY.USER_GATE_ACTIVITY, guildCode);
|
|
|
|
|
let rec = await getGuildActivityRank(guildKey, memberKey, guildCode, serverId, roleId, roleName);
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getCityActivityRank(guildCode: string, serverId: number, cityId: number, roleId?: string, roleName?: string) {
|
|
|
|
|
let guildKey = getCityKeyName(REDIS_KEY.USER_CITY_ACTIVITY, cityId);
|
|
|
|
|
let memberKey = getGuildKeyName(REDIS_KEY.USER_CITY_ACTIVITY, guildCode);
|
|
|
|
|
let rec = await getGuildActivityRank(guildKey, memberKey, guildCode, serverId, roleId, roleName);
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获得军团活动排行榜
|
|
|
|
|
* @param guildCode
|
|
|
|
@@ -144,9 +165,9 @@ export function getRecordScore(aid: number, record: { round: number, dataId: num
|
|
|
|
|
* @param roleId
|
|
|
|
|
* @param roleName
|
|
|
|
|
*/
|
|
|
|
|
export async function getGuildActivityRank(guildCode: string, serverId: number, roleId?: string, roleName?: string) {
|
|
|
|
|
export async function getGuildActivityRank(guildKey: string, memberKey: string, guildCode: string, serverId: number, roleId?: string, roleName?: string) {
|
|
|
|
|
|
|
|
|
|
let guildRankResult = await getUnionRank(REDIS_KEY.GATE_ACTIVITY, serverId, guildCode);
|
|
|
|
|
let guildRankResult = await getUnionRank(guildKey, serverId, guildCode);
|
|
|
|
|
let guildRank = new Array<SimpleGuildRankParam>();
|
|
|
|
|
for(let { rank, code, name, num } of guildRankResult.ranks) {
|
|
|
|
|
let param = new SimpleGuildRankParam(rank, code, name, num);
|
|
|
|
@@ -161,7 +182,7 @@ export async function getGuildActivityRank(guildCode: string, serverId: number,
|
|
|
|
|
myGuildRank = new SimpleGuildRankParam(0, guildCode, guild.name, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let memberRankResult = await getRank(getGuildKeyName(REDIS_KEY.USER_GATE_ACTIVITY, guildCode), serverId, roleId);
|
|
|
|
|
let memberRankResult = await getRank(memberKey, serverId, roleId);
|
|
|
|
|
let memberRank = new Array<SimpleRoleRankParam>();
|
|
|
|
|
for(let { rank, roleId, roleName, num } of memberRankResult.ranks) {
|
|
|
|
|
let param = new SimpleRoleRankParam(rank, roleId, roleName, num);
|
|
|
|
@@ -185,14 +206,16 @@ export async function getGuildActivityRank(guildCode: string, serverId: number,
|
|
|
|
|
* @param aid 活动类型
|
|
|
|
|
*/
|
|
|
|
|
export async function sendAllGuildRanks(aid: number) {
|
|
|
|
|
let obj = getGuildActivityObj(aid);
|
|
|
|
|
let guilds = obj.getGuilds();
|
|
|
|
|
for(let [ serverId, guildCodes ] of guilds) {
|
|
|
|
|
// TODO 不需要每个军团都排序一次
|
|
|
|
|
for(let guildCode of guildCodes) {
|
|
|
|
|
let ranks = await getGuildActivityRank(guildCode, serverId);
|
|
|
|
|
let chatSid = await getGuildChannelSid(guildCode);
|
|
|
|
|
pinus.app.rpc.chat.guildRemote.pushRank.toServer(chatSid, guildCode, ranks);
|
|
|
|
|
if(aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
|
|
|
|
let obj = getGateActivityObj();
|
|
|
|
|
let guilds = obj.getGuilds();
|
|
|
|
|
for(let [ serverId, guildCodes ] of guilds) {
|
|
|
|
|
// TODO 不需要每个军团都排序一次
|
|
|
|
|
for(let guildCode of guildCodes) {
|
|
|
|
|
let ranks = await getGateActivityRank(guildCode, serverId);
|
|
|
|
|
let chatSid = await getGuildChannelSid(guildCode);
|
|
|
|
|
pinus.app.rpc.chat.guildRemote.pushRank.toServer(chatSid, guildCode, ranks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -202,7 +225,7 @@ export async function sendAllGuildRanks(aid: number) {
|
|
|
|
|
* @param aid 活动类型
|
|
|
|
|
*/
|
|
|
|
|
export async function sendGuildActEndMsg(aid: number) {
|
|
|
|
|
let obj = getGuildActivityObj(aid);
|
|
|
|
|
let obj = getGateActivityObj();
|
|
|
|
|
let guilds = obj.getGuilds();
|
|
|
|
|
for(let [ serverId, guildCodes ] of guilds) {
|
|
|
|
|
let chatSid = await getWorldChannelSid(serverId);
|
|
|
|
@@ -232,7 +255,7 @@ export async function sendSingleGuildGateActEndMsg(guildCode: string, serverId:
|
|
|
|
|
* @param serverId
|
|
|
|
|
*/
|
|
|
|
|
export async function gateActivitySettleReward(guildCode: string, serverId: number) {
|
|
|
|
|
let obj = getGuildActivityObj(GUILD_ACTIVITY_TYPE.GATE_ACTIVITY);
|
|
|
|
|
let obj = getGateActivityObj();
|
|
|
|
|
let { gateHp, members } = obj.getObj(guildCode, serverId);
|
|
|
|
|
members = uniq(members, cur => cur.roleId);
|
|
|
|
|
|
|
|
|
@@ -277,4 +300,54 @@ export async function participants(guildCode: string, sourceType: number, source
|
|
|
|
|
if(!rec) return [];
|
|
|
|
|
|
|
|
|
|
return rec.members||[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getCities(guildCode: string, dbCities: GuildActivityCityType[]) {
|
|
|
|
|
|
|
|
|
|
let cities = new Array<CityParam>();
|
|
|
|
|
for(let [ cityId, dic ] of gameData.cityActivity) {
|
|
|
|
|
let param = new CityParam(cityId);
|
|
|
|
|
let curCity = dbCities.find(cur => cur.cityId == cityId);
|
|
|
|
|
|
|
|
|
|
if(curCity) {
|
|
|
|
|
param.guardGuildCode = curCity.guardGuildCode;
|
|
|
|
|
param.guardGuildName = curCity.guardGuildName;
|
|
|
|
|
param.declareCount = curCity.declareCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
param.status = getCityStatus(guildCode, cityId, dic.preCity, dbCities);
|
|
|
|
|
cities.push(param);
|
|
|
|
|
}
|
|
|
|
|
return cities
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 诸侯混战 获取城池状态
|
|
|
|
|
* @param guildCode
|
|
|
|
|
* @param cityId
|
|
|
|
|
* @param preCity
|
|
|
|
|
* @param dbCities
|
|
|
|
|
*/
|
|
|
|
|
export function getCityStatus(guildCode: string, cityId: number, preCity: number[], dbCities: GuildActivityCityType[]) {
|
|
|
|
|
let status = CITY_STATUS.NOT_OPEN;
|
|
|
|
|
if(preCity && preCity.length) {
|
|
|
|
|
let hasGuardCity = dbCities.find(cur => {
|
|
|
|
|
return preCity.includes(cur.cityId) && cur.guardGuildCode == guildCode;
|
|
|
|
|
});
|
|
|
|
|
if(!!hasGuardCity) {
|
|
|
|
|
status = CITY_STATUS.CAN_DECLARE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
status = CITY_STATUS.CAN_DECLARE;
|
|
|
|
|
}
|
|
|
|
|
let curCity = dbCities.find(cur => cur.cityId == cityId);
|
|
|
|
|
if(curCity) {
|
|
|
|
|
if(curCity.guardGuildCode == guildCode) {
|
|
|
|
|
status = CITY_STATUS.GUARD;
|
|
|
|
|
} else if (curCity.declareGuilds.includes(guildCode)) {
|
|
|
|
|
status = CITY_STATUS.DECLARED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|