// Metro module 4076 (f4077). import GuildStore from "../../../stores/GuildStore"; import { GUILD_POWERUP_TIER_3_OVERRIDDEN_PURCHASABLE_FEATURES, PURCHASABLE_PREMIUM_FEATURES_BOOST_INFO } from "./constants/GuildPowerupsConstants"; import { AppliedGuildBoostsRequiredForBoostedGuildTier, BoostedGuildTiers, GuildFeatures } from "../../../Constants"; import Module589 from "../../../_bundle/Module589"; import Dispatcher from "../../../Dispatcher"; function $mk73563($env) { return (a0) => { const r1 = $env; const r0 = r1[0]; const unlockedPowerups = r1[1].unlockedPowerups; const sku_id = a0.sku_id; if (r0) { unlockedPowerups[sku_id] = a0; } else { delete unlockedPowerups[sku_id]; } }; } let c2344_7; const calculateAppliedBoosts = function calculateAppliedBoosts(a0) { const guild = GuildStore.getGuild(a0); const r5 = (guild == null ? void 0 : guild.features.has(GuildFeatures.PREMIUM_TIER_3_OVERRIDE)) === true; let r35 = 0; if (!r5) { let r38 = guild?.premiumTier; if (r38 == null) { r38 = BoostedGuildTiers.NONE; } r35 = AppliedGuildBoostsRequiredForBoostedGuildTier[r38]; } let r40 = r35; for (const item of Object.entries(PURCHASABLE_PREMIUM_FEATURES_BOOST_INFO)) { const [r54, r55] = item; if (!(r5 && GUILD_POWERUP_TIER_3_OVERRIDDEN_PURCHASABLE_FEATURES.has(r54))) { const r58 = guild == null; let r59 = void 0; if (!r58) { const premiumFeatures = guild.premiumFeatures; r59 = premiumFeatures == null ? void 0 : premiumFeatures.features.includes(r54); } if (r59) { const isEnabled = r55.isEnabled; let r67 = isEnabled == null ? void 0 : isEnabled.call(r55, a0); if (r67 == null) { r67 = 1; } r59 = r67; } if (r59) { r59 = r55.includedInLevel == null || guild.premiumTier < r55.includedInLevel; } if (r59) { r40 = r40 + r55.boostPrice; } } } return r40; }; c2344_7 = {}; class GuildPowerupsStore extends Module589.PersistedStore { static displayName = "GuildPowerupsStore"; static persistKey = "GuildPowerupsStore"; static migrations = [(a0) => a0 != null ? Object.fromEntries(Object.entries(a0).filter((item) => { const [, r13] = item; return r13 != null && typeof r13 === "object"; }).map((item) => { const [r23, r24] = item; const r26 = [r23, ,]; let allPowerups = r24.allPowerups; if (allPowerups == null) { allPowerups = {}; } let powerupCatalog = r24.powerupCatalog; if (powerupCatalog == null) { powerupCatalog = {}; } let unlockedPowerups = r24.unlockedPowerups; if (unlockedPowerups == null) { unlockedPowerups = {}; } r26[1] = { ...r24, allPowerups, powerupCatalog, unlockedPowerups }; return r26; })) : a0]; initialize(a0) { this.waitFor(GuildStore); if (a0 != null) { c2344_7 = a0; } } getState() { return c2344_7; } getStateForGuild(a0) { return a0 != null ? c2344_7[a0] : void 0; } shouldFetchCatalogForGuild(a0) { const catalogFetchCooldown = c2344_7[a0]?.catalogFetchCooldown; return catalogFetchCooldown == null || catalogFetchCooldown + 86400000 < Date.now(); } shouldFetchPowerupsForGuild(a0) { const unlockedPowerupsFetchCooldown = c2344_7[a0]?.unlockedPowerupsFetchCooldown; return unlockedPowerupsFetchCooldown == null || unlockedPowerupsFetchCooldown + 3600000 < Date.now(); } hasFetchedPowerupCatalog(a0) { return a0 != null && c2344_7[a0]?.hasFetchedPowerupCatalog === true; } hasFetchedUnlockedPowerups(a0) { return a0 != null && c2344_7[a0]?.hasFetchedUnlockedPowerups === true; } } const guildPowerupsStore = new GuildPowerupsStore(Dispatcher, { LOGOUT: function handleReset() { c2344_7 = {}; }, GUILD_POWERUP_CATALOG_FETCH_SUCCESS: function handleGuildPowerupCatalogFetchSuccess({ guildId, allPowerups, powerupCatalog }) { if (c2344_7[guildId] == null) { c2344_7[guildId] = { allPowerups: {}, powerupCatalog: {}, unlockedPowerups: {}, appliedBoosts: calculateAppliedBoosts(guildId) }; } const r19 = c2344_7[guildId]; const r20 = { ...c2344_7 }; r20[guildId] = { ...r19, allPowerups, powerupCatalog, catalogFetchCooldown: Date.now(), hasFetchedPowerupCatalog: true }; c2344_7 = r20; }, GUILD_BOOST_ENTITLEMENTS_FETCH_SUCCESS: function handleGuildBoostEntitlementsFetchSuccess({ guildId, unlockedPowerups }) { if (c2344_7[guildId] == null) { c2344_7[guildId] = { allPowerups: {}, powerupCatalog: {}, unlockedPowerups: {}, appliedBoosts: calculateAppliedBoosts(guildId) }; } const r18 = c2344_7[guildId]; const appliedBoosts = calculateAppliedBoosts(guildId); const r22 = { ...c2344_7 }; r22[guildId] = { ...r18, unlockedPowerups, appliedBoosts, unlockedPowerupsFetchCooldown: Date.now(), hasFetchedUnlockedPowerups: true }; c2344_7 = r22; }, GUILD_POWERUP_ENTITLEMENTS_CREATE: function handleGuildPowerupCreated(a0) { let env13839; const r3 = env13839 = {}; const { guildId, entitlements } = a0; env13839[0] = true; env13839[1] = void 0; if (c2344_7[guildId] == null) { c2344_7[guildId] = { allPowerups: {}, powerupCatalog: {}, unlockedPowerups: {}, appliedBoosts: calculateAppliedBoosts(guildId) }; } const r21 = c2344_7[guildId]; env13839[1] = r21; entitlements.forEach($mk73563(r3)); const r25 = { ...c2344_7 }; r25[guildId] = { ...r21, appliedBoosts: calculateAppliedBoosts(guildId) }; c2344_7 = r25; }, GUILD_POWERUP_ENTITLEMENTS_DELETE: function handleGuildPowerupDeleted(a0) { let env13840; const r3 = env13840 = {}; const { guildId, entitlements } = a0; env13840[0] = false; env13840[1] = void 0; if (c2344_7[guildId] == null) { c2344_7[guildId] = { allPowerups: {}, powerupCatalog: {}, unlockedPowerups: {}, appliedBoosts: calculateAppliedBoosts(guildId) }; } const r21 = c2344_7[guildId]; env13840[1] = r21; entitlements.forEach($mk73563(r3)); const r25 = { ...c2344_7 }; r25[guildId] = { ...r21, appliedBoosts: calculateAppliedBoosts(guildId) }; c2344_7 = r25; }, GUILD_UPDATE: function handleGuildUpdated(a0) { const id = a0.guild.id; if (c2344_7[id] == null) { c2344_7[id] = { allPowerups: {}, powerupCatalog: {}, unlockedPowerups: {}, appliedBoosts: calculateAppliedBoosts(id) }; } c2344_7[id] = { ...c2344_7[id], appliedBoosts: calculateAppliedBoosts(id) }; }, GAME_SERVER_FETCH_INSTANCES_SUCCESS: function handleGameServerInstanceFetched({ guildId }) { if (c2344_7[guildId] == null) { c2344_7[guildId] = { allPowerups: {}, powerupCatalog: {}, unlockedPowerups: {}, appliedBoosts: calculateAppliedBoosts(guildId) }; } c2344_7[guildId] = { ...c2344_7[guildId], appliedBoosts: calculateAppliedBoosts(guildId) }; } }); export default guildPowerupsStore;