create use quest hook

This commit is contained in:
Chase Manning 2023-10-05 10:51:49 +01:00
commit d315a908e5

56
src/app/use-quests.ts Normal file
View file

@ -0,0 +1,56 @@
import { useDispatch } from "react-redux";
import { MapId } from "../maps/map-types";
import useBadges from "./use-badges";
import { setPos } from "../state/gameSlice";
import { setBlackScreen } from "../state/uiSlice";
export interface QuestType {
trigger: "talk" | "walk";
map: MapId;
positions: Record<number, number[]>;
active: () => boolean;
text: string[];
action: () => void;
}
export const useActiveMapQuests = (map: MapId) => {
const quests = useQuests();
return quests.filter((quest) => quest.map === map && quest.active());
};
const useQuests = () => {
const dispatch = useDispatch();
const badges = useBadges();
const quests: QuestType[] = [
// Pewter City
{
trigger: "walk",
map: MapId.PewterCity,
positions: {
17: [35],
18: [35],
19: [35],
},
active: () => badges.length === 1,
text: [
"You're a Trainer, right?",
"Brock's looking for new challengers.",
"Follow me!",
],
action: () => {
dispatch(setBlackScreen(true));
setTimeout(() => {
dispatch(setPos({ x: 14, y: 19 }));
}, 300);
setTimeout(() => {
dispatch(setBlackScreen(false));
}, 600);
},
},
];
return quests;
};
export default useQuests;