forked from phenom/healer-man
Release Healer Man 0.1.22
This commit is contained in:
1 parent
f6f2375145
commit
7f6001723a
144 files changed
+54107
-690
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { selectedCharacter, useShellStore } from "./shellStore";
|
||||
import { useOnlineGroupStore } from "./onlineGroupStore";
|
||||
import {
|
||||
@@ -6,11 +6,56 @@ import {
|
||||
defaultPartyRoleForClass,
|
||||
type PartyRole,
|
||||
} from "../game/partyRoles";
|
||||
import { isManastormPartySize } from "../game/manastormProgress";
|
||||
import { isManastormPartySize, type ManastormPartySize } from "../game/manastormProgress";
|
||||
import type { OnlineGroupActivity } from "./onlineGroupTypes";
|
||||
import { useContentManagerSnapshot } from "../content/useContentManager";
|
||||
|
||||
const GROUP_POLL_MS = 2_500;
|
||||
const ACTIVITY_JOIN_WINDOW_MS = 10 * 60 * 1000;
|
||||
|
||||
interface OnlineGroupActivityEntryDependencies {
|
||||
readonly installDungeonRuntime: () => Promise<void>;
|
||||
readonly enterDungeon: (dungeonId: string, role?: PartyRole) => boolean;
|
||||
readonly installManastormRuntime: () => Promise<void>;
|
||||
readonly enterManastorm: (role?: PartyRole, partySize?: ManastormPartySize, startingLevel?: number) => boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_ACTIVITY_ENTRY_DEPENDENCIES: OnlineGroupActivityEntryDependencies = {
|
||||
installDungeonRuntime: async () => {
|
||||
const { installDungeonShellRuntime } = await import("./dungeonShellRuntime");
|
||||
installDungeonShellRuntime();
|
||||
},
|
||||
enterDungeon: (dungeonId, role) => useShellStore.getState().enterDungeon(dungeonId, role),
|
||||
installManastormRuntime: async () => {
|
||||
const { installManastormShellRuntime } = await import("./manastormShellRuntime");
|
||||
installManastormShellRuntime();
|
||||
},
|
||||
enterManastorm: (role, partySize, startingLevel) => useShellStore.getState().enterManastorm(
|
||||
role,
|
||||
partySize,
|
||||
startingLevel,
|
||||
),
|
||||
};
|
||||
|
||||
export async function enterOnlineGroupActivity(
|
||||
activity: OnlineGroupActivity,
|
||||
role: PartyRole,
|
||||
consumeActivity: (activityId: string) => void,
|
||||
dependencies: OnlineGroupActivityEntryDependencies = DEFAULT_ACTIVITY_ENTRY_DEPENDENCIES,
|
||||
): Promise<boolean> {
|
||||
let entered: boolean;
|
||||
if (activity.type === "dungeon") {
|
||||
await dependencies.installDungeonRuntime();
|
||||
entered = dependencies.enterDungeon(activity.contentId, role);
|
||||
} else {
|
||||
await dependencies.installManastormRuntime();
|
||||
const partySize = isManastormPartySize(activity.partySize) ? activity.partySize : 5;
|
||||
entered = dependencies.enterManastorm(role, partySize, activity.startingLevel ?? undefined);
|
||||
}
|
||||
if (entered) consumeActivity(activity.id);
|
||||
return entered;
|
||||
}
|
||||
|
||||
export function OnlineGroupCoordinator() {
|
||||
const session = useShellStore((state) => state.session);
|
||||
const character = useShellStore(selectedCharacter);
|
||||
@@ -21,6 +66,8 @@ export function OnlineGroupCoordinator() {
|
||||
const updateMember = useOnlineGroupStore((state) => state.updateMember);
|
||||
const consumeActivity = useOnlineGroupStore((state) => state.consumeActivity);
|
||||
const reset = useOnlineGroupStore((state) => state.reset);
|
||||
const { installedRevision } = useContentManagerSnapshot();
|
||||
const pendingActivityIds = useRef(new Set<string>());
|
||||
|
||||
useEffect(() => {
|
||||
if (!session || session.kind !== "account" || !session.accessToken) {
|
||||
@@ -60,26 +107,16 @@ export function OnlineGroupCoordinator() {
|
||||
if (Date.now() - activity.startedAt > ACTIVITY_JOIN_WINDOW_MS) return;
|
||||
const member = snapshot.group?.members.find((candidate) => candidate.accountId === session.ownerId);
|
||||
if (!member?.character || !member.role) return;
|
||||
consumeActivity(activity.id);
|
||||
void (async () => {
|
||||
if (activity.type === "dungeon") {
|
||||
const { installDungeonShellRuntime } = await import("./dungeonShellRuntime");
|
||||
installDungeonShellRuntime();
|
||||
useShellStore.getState().enterDungeon(activity.contentId, member.role ?? undefined);
|
||||
return;
|
||||
}
|
||||
const { installManastormShellRuntime } = await import("./manastormShellRuntime");
|
||||
installManastormShellRuntime();
|
||||
const partySize = isManastormPartySize(activity.partySize) ? activity.partySize : 5;
|
||||
useShellStore.getState().enterManastorm(
|
||||
member.role ?? undefined,
|
||||
partySize,
|
||||
activity.startingLevel ?? undefined,
|
||||
);
|
||||
})().catch((error) => {
|
||||
useShellStore.getState().setNotice(error instanceof Error ? error.message : "The group activity could not be opened.");
|
||||
});
|
||||
}, [consumeActivity, consumedActivityIds, phase, session?.ownerId, snapshot.group?.activity?.id]);
|
||||
if (pendingActivityIds.current.has(activity.id)) return;
|
||||
pendingActivityIds.current.add(activity.id);
|
||||
void enterOnlineGroupActivity(activity, member.role, consumeActivity)
|
||||
.catch((error) => {
|
||||
useShellStore.getState().setNotice(error instanceof Error ? error.message : "The group activity could not be opened.");
|
||||
})
|
||||
.finally(() => {
|
||||
pendingActivityIds.current.delete(activity.id);
|
||||
});
|
||||
}, [consumeActivity, consumedActivityIds, installedRevision, phase, session?.ownerId, snapshot.group?.activity?.id]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user