mirror of
https://github.com/chase-manning/pokemon-js.git
synced 2025-11-03 01:18:58 +00:00
✨ create use quest hook
This commit is contained in:
parent
b169c9c12c
commit
d315a908e5
1 changed files with 56 additions and 0 deletions
56
src/app/use-quests.ts
Normal file
56
src/app/use-quests.ts
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue