军团活动:诸侯混战自动宣战
This commit is contained in:
@@ -344,7 +344,7 @@ export class GmHandler {
|
||||
|
||||
// 清空旧数据
|
||||
if (day <= 2) {
|
||||
await GuildActivityCityModel.deleteMany({});
|
||||
await GuildActivityCityModel.clearGuardAndStartNext();
|
||||
}
|
||||
if(aid != 0) await delGuildActivityRank(aid);
|
||||
await GuildActivityRecordModel.updateTodayInfo({ status: 2 });
|
||||
|
||||
@@ -36,12 +36,17 @@ export class CityActivityObject {
|
||||
}
|
||||
}
|
||||
|
||||
public hasSent(serverId: number, cityId: number) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
return this.sentCity.indexOf(key) != -1;
|
||||
}
|
||||
|
||||
public getAllCities() {
|
||||
let allCities = new Array<{ serverId: number, cityId: number, guildCodes: string[]}>();
|
||||
let serverlists = new Array<number>();
|
||||
for(let [key, guildCodes] of this.cities) {
|
||||
if(this.sentCity.indexOf(key) == -1) {
|
||||
let { serverId, cityId } = this.decodeKey(key);
|
||||
let { serverId, cityId } = this.decodeKey(key);
|
||||
if(!this.hasSent(serverId, cityId)) {
|
||||
allCities.push({ serverId, cityId, guildCodes });
|
||||
if(!serverlists.includes(serverId)) serverlists.push(serverId);
|
||||
}
|
||||
|
||||
@@ -444,6 +444,7 @@ async function updateUserRecAndSendHonour(honour: number, myScore: number, rank:
|
||||
*/
|
||||
export async function cityActivitySettleReward(cityId: number, serverId: number) {
|
||||
let obj = getCityActivityObj();
|
||||
if(obj.hasSent(serverId, cityId)) return;
|
||||
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if (!dicCity) return;
|
||||
@@ -455,9 +456,10 @@ export async function cityActivitySettleReward(cityId: number, serverId: number)
|
||||
for (let { rank: guildRank, code: guildCode, name, num } of ranks) {
|
||||
if (guildRank == 1) {
|
||||
if (isSuccess) {
|
||||
await GuildActivityCityModel.guard(serverId, cityId, guildCode, name); // 占领
|
||||
console.log(dicCity)
|
||||
await GuildActivityCityModel.guard(serverId, cityId, dicCity?.nextCity, guildCode, name); // 占领
|
||||
} else {
|
||||
await GuildActivityCityModel.guard(serverId, cityId, "", ""); // 无人能占领
|
||||
await GuildActivityCityModel.guard(serverId, cityId, 0, "", ""); // 无人能占领
|
||||
}
|
||||
}
|
||||
let rewards = getGuildAuctionRewards(GUILD_ACTIVITY_TYPE.CITY_ACTIVITY, guildRank, cityId);
|
||||
@@ -496,18 +498,10 @@ export async function cityActivitySettleReward(cityId: number, serverId: number)
|
||||
* 清空完declareGuilds之后,做下一次活动的自动宣战
|
||||
*/
|
||||
export async function autoDeclare(serverId: number) {
|
||||
let allCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let guardList = new Array<{ cityId: number, guardGuildCode: string }>();
|
||||
for (let { cityId, guardGuildCode } of allCities) {
|
||||
guardList.push({ cityId, guardGuildCode });
|
||||
await GuildActivityCityModel.clearGuard(serverId, cityId);
|
||||
}
|
||||
// console.log(JSON.stringify(guardList));
|
||||
for (let { cityId, guardGuildCode } of guardList) {
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if (guardGuildCode && dicCity.nextCity) {
|
||||
await GuildActivityCityModel.declare(serverId, dicCity.nextCity, guardGuildCode);
|
||||
}
|
||||
await GuildActivityCityModel.clearGuardAndStartNext(serverId);
|
||||
for(let [ cityId ] of gameData.cityActivity) {
|
||||
let msg = { cityId, declareGuildCode: "", declareCount: 0 };
|
||||
await sendMessageToCityWithSuc(cityId, PUSH_ROUTE.GUILD_CITY_DECLARE, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,61 +27,65 @@ export default class GuildActivityCity extends BaseModel {
|
||||
@prop({ required: true })
|
||||
guardTime: Date; // 占领日期
|
||||
|
||||
@prop({ required: true })
|
||||
status: number; // 0-过去的 1-现在的 2-未来的
|
||||
|
||||
// 每天宣战一次
|
||||
public static async getAllCities(serverId: number) {
|
||||
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
|
||||
let rec: GuildActivityCityType[] = await GuildActivityCityModel.find({ serverId, createdAt: { $gte: curWeek }}).lean();
|
||||
let rec: GuildActivityCityType[] = await GuildActivityCityModel.find({ serverId, status: 1 }).lean();
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async getCity(serverId: number, cityId: number) {
|
||||
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
|
||||
let rec: GuildActivityCityType = await GuildActivityCityModel.findOne({ serverId, cityId, createdAt: { $gte: curWeek }}).lean();
|
||||
let rec: GuildActivityCityType = await GuildActivityCityModel.findOne({ serverId, cityId, status: 1}).lean();
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
// 检查是否宣战过
|
||||
public static async checkDeclartion(serverId: number, guildCode: string) {
|
||||
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
|
||||
let rec: GuildActivityCityType = await GuildActivityCityModel.findOne(
|
||||
{ serverId, createdAt: { $gte: curWeek }, declareGuilds: { $in: [guildCode]}}).lean();
|
||||
{ serverId, status: 1, declareGuilds: { $in: [guildCode]}}).lean();
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
// 宣言
|
||||
public static async declare(serverId: number, cityId: number, guildCode: string) {
|
||||
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
|
||||
let rec: GuildActivityCityType = await GuildActivityCityModel.findOneAndUpdate(
|
||||
{ serverId, cityId, createdAt: { $gte: curWeek } },
|
||||
{ $setOnInsert: { serverId, cityId }, $push: { declareGuilds: guildCode }, $inc: {declareCount: 1 } },
|
||||
{ serverId, cityId, status: 1 },
|
||||
{ $push: { declareGuilds: guildCode }, $inc: {declareCount: 1 } },
|
||||
{new: true, upsert: true}).lean();
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
// 占领
|
||||
public static async guard(serverId: number, cityId: number, guildCode: string, guildName: string) {
|
||||
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
|
||||
public static async guard(serverId: number, cityId: number, nextCityId: number, guildCode: string, guildName: string) {
|
||||
let rec: GuildActivityCityType = await GuildActivityCityModel.findOneAndUpdate(
|
||||
{ serverId, cityId, createdAt: { $gte: curWeek } },
|
||||
{ serverId, cityId, status: 1 },
|
||||
{ $set: { guardGuildCode: guildCode, guardGuildName: guildName, guardTime: new Date()} },
|
||||
{ new: true }).lean();
|
||||
|
||||
|
||||
if(nextCityId) {
|
||||
await GuildActivityCityModel.findOneAndUpdate(
|
||||
{ serverId, cityId: nextCityId, status: 2 },
|
||||
{ $push: { declareGuilds: guildCode }, $inc: {declareCount: 1 } },
|
||||
{new: true, upsert: true}).lean();
|
||||
}
|
||||
return rec;
|
||||
}
|
||||
|
||||
// 活动结束后需要清空占领情况
|
||||
public static async clearGuard(serverId: number, cityId: number) {
|
||||
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
|
||||
let rec: GuildActivityCityType = await GuildActivityCityModel.findOneAndUpdate(
|
||||
{ serverId, cityId, createdAt: { $gte: curWeek } },
|
||||
{ $set: { guardGuildCode: "", guardGuildName: "", declareCount: 0, declareGuilds: [] } },
|
||||
{ new: true }).lean();
|
||||
|
||||
return rec;
|
||||
public static async clearGuardAndStartNext(serverId?: number) {
|
||||
if(serverId) {
|
||||
await GuildActivityCityModel.updateMany({ serverId, status: 1 }, { $set: { status: 0 } });
|
||||
await GuildActivityCityModel.updateMany({ serverId, status: 2 }, { $set: { status: 1 } });
|
||||
} else {
|
||||
await GuildActivityCityModel.updateMany({ status: 1 }, { $set: { status: 0 } });
|
||||
await GuildActivityCityModel.updateMany({ status: 2 }, { $set: { status: 1 } });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user