fix: check ascension ceremony contributors when changing clan tier #1656
@ -1,8 +1,7 @@
|
|||||||
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
|
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
|
||||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
||||||
import { Guild, GuildMember } from "@/src/models/guildModel";
|
import { Guild } from "@/src/models/guildModel";
|
||||||
import { config } from "@/src/services/configService";
|
import { checkClanAscensionHasRequiredContributors } from "@/src/services/guildService";
|
||||||
import { createMessage } from "@/src/services/inboxService";
|
|
||||||
import { getInventory } from "@/src/services/inventoryService";
|
import { getInventory } from "@/src/services/inventoryService";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
@ -31,43 +30,7 @@ export const contributeGuildClassController: RequestHandler = async (req, res) =
|
|||||||
|
|
||||||
guild.CeremonyContributors.push(new Types.ObjectId(accountId));
|
guild.CeremonyContributors.push(new Types.ObjectId(accountId));
|
||||||
|
|
||||||
// Once required contributor count is hit, the class is committed and there's 72 hours to claim endo.
|
await checkClanAscensionHasRequiredContributors(guild);
|
||||||
if (guild.CeremonyContributors.length == payload.RequiredContributors) {
|
|
||||||
guild.Class = guild.CeremonyClass!;
|
|
||||||
guild.CeremonyClass = undefined;
|
|
||||||
guild.CeremonyResetDate = new Date(Date.now() + (config.fastClanAscension ? 5_000 : 72 * 3600_000));
|
|
||||||
if (!config.fastClanAscension) {
|
|
||||||
// Send message to all active guild members
|
|
||||||
const members = await GuildMember.find({ guildId: payload.GuildId, status: 0 }, "accountId");
|
|
||||||
for (const member of members) {
|
|
||||||
// somewhat unfaithful as on live the "msg" is not a loctag, but since we don't have the string, we'll let the client fill it in with "arg".
|
|
||||||
await createMessage(member.accountId, [
|
|
||||||
{
|
|
||||||
sndr: guild.Name,
|
|
||||||
msg: "/Lotus/Language/Clan/Clan_AscensionCeremonyInProgressDetails",
|
|
||||||
arg: [
|
|
||||||
{
|
|
||||||
Key: "RESETDATE",
|
|
||||||
Tag:
|
|
||||||
guild.CeremonyResetDate.getUTCMonth() +
|
|
||||||
"/" +
|
|
||||||
guild.CeremonyResetDate.getUTCDate() +
|
|
||||||
"/" +
|
|
||||||
(guild.CeremonyResetDate.getUTCFullYear() % 100) +
|
|
||||||
" " +
|
|
||||||
guild.CeremonyResetDate.getUTCHours().toString().padStart(2, "0") +
|
|
||||||
":" +
|
|
||||||
guild.CeremonyResetDate.getUTCMinutes().toString().padStart(2, "0")
|
|
||||||
}
|
|
||||||
],
|
|
||||||
sub: "/Lotus/Language/Clan/Clan_AscensionCeremonyInProgress",
|
|
||||||
icon: "/Lotus/Interface/Graphics/ClanTileImages/ClanEnterDojo.png",
|
|
||||||
highPriority: true
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await guild.save();
|
await guild.save();
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import { IFusionTreasure, ITypeCount } from "../types/inventoryTypes/inventoryTy
|
|||||||
import { IInventoryChanges } from "../types/purchaseTypes";
|
import { IInventoryChanges } from "../types/purchaseTypes";
|
||||||
import { parallelForeach } from "../utils/async-utils";
|
import { parallelForeach } from "../utils/async-utils";
|
||||||
import allDecoRecipes from "@/static/fixed_responses/allDecoRecipes.json";
|
import allDecoRecipes from "@/static/fixed_responses/allDecoRecipes.json";
|
||||||
|
import { createMessage } from "./inboxService";
|
||||||
|
|
||||||
export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
|
export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
@ -601,6 +602,50 @@ const setGuildTier = async (guild: TGuildDatabaseDocument, newTier: number): Pro
|
|||||||
await processGuildTechProjectContributionsUpdate(guild, project);
|
await processGuildTechProjectContributionsUpdate(guild, project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (guild.CeremonyContributors) {
|
||||||
|
await checkClanAscensionHasRequiredContributors(guild);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const checkClanAscensionHasRequiredContributors = async (guild: TGuildDatabaseDocument): Promise<void> => {
|
||||||
|
const requiredContributors = [1, 5, 15, 30, 50][guild.Tier - 1];
|
||||||
|
// Once required contributor count is hit, the class is committed and there's 72 hours to claim endo.
|
||||||
|
if (guild.CeremonyContributors!.length >= requiredContributors) {
|
||||||
|
guild.Class = guild.CeremonyClass!;
|
||||||
|
guild.CeremonyClass = undefined;
|
||||||
|
guild.CeremonyResetDate = new Date(Date.now() + (config.fastClanAscension ? 5_000 : 72 * 3600_000));
|
||||||
|
if (!config.fastClanAscension) {
|
||||||
|
// Send message to all active guild members
|
||||||
|
const members = await GuildMember.find({ guildId: guild._id, status: 0 }, "accountId");
|
||||||
|
await parallelForeach(members, async member => {
|
||||||
|
// somewhat unfaithful as on live the "msg" is not a loctag, but since we don't have the string, we'll let the client fill it in with "arg".
|
||||||
|
await createMessage(member.accountId, [
|
||||||
|
{
|
||||||
|
sndr: guild.Name,
|
||||||
|
msg: "/Lotus/Language/Clan/Clan_AscensionCeremonyInProgressDetails",
|
||||||
|
arg: [
|
||||||
|
{
|
||||||
|
Key: "RESETDATE",
|
||||||
|
Tag:
|
||||||
|
guild.CeremonyResetDate!.getUTCMonth() +
|
||||||
|
"/" +
|
||||||
|
guild.CeremonyResetDate!.getUTCDate() +
|
||||||
|
"/" +
|
||||||
|
(guild.CeremonyResetDate!.getUTCFullYear() % 100) +
|
||||||
|
" " +
|
||||||
|
guild.CeremonyResetDate!.getUTCHours().toString().padStart(2, "0") +
|
||||||
|
":" +
|
||||||
|
guild.CeremonyResetDate!.getUTCMinutes().toString().padStart(2, "0")
|
||||||
|
}
|
||||||
|
],
|
||||||
|
sub: "/Lotus/Language/Clan/Clan_AscensionCeremonyInProgress",
|
||||||
|
icon: "/Lotus/Interface/Graphics/ClanTileImages/ClanEnterDojo.png",
|
||||||
|
highPriority: true
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeDojoKeyItems = (inventory: TInventoryDatabaseDocument): IInventoryChanges => {
|
export const removeDojoKeyItems = (inventory: TInventoryDatabaseDocument): IInventoryChanges => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user