From 6d8caeae7c3317e93948f0b2ad3ed2a1d47cec7b Mon Sep 17 00:00:00 2001 From: san Date: Thu, 31 Oct 2024 12:59:56 +0530 Subject: [PATCH] add tavern keeper quotes --- app/src/components/PixelatedQuote.tsx | 119 ++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 16 deletions(-) diff --git a/app/src/components/PixelatedQuote.tsx b/app/src/components/PixelatedQuote.tsx index 45cabf9..2579399 100644 --- a/app/src/components/PixelatedQuote.tsx +++ b/app/src/components/PixelatedQuote.tsx @@ -1,51 +1,138 @@ import { useState, useEffect, useRef } from "react"; -import styles from "../styles/Army.module.css" +import { usePlayer } from "../providers/PlayerProvider"; +import styles from "../styles/Army.module.css"; -const tavernerQuotes = [ +// Quote categories based on total minted GELD +const PROGRESSION_TIERS = { + BEGINNER: BigInt(1000000), + NOVICE: BigInt(10000000), + INTERMEDIATE: BigInt(100000000), + EXPERIENCED: BigInt(1000000000), + EXPERT: BigInt(10000000000), + MASTER: BigInt(100000000000), + LEGENDARY: BigInt(1000000000000), +}; + +const quotes = { + BEGINNER: [ + "Well, well... another fresh face looking to be a hero. At least you're holding your weapon the right way up.", + "Ha! Your armor's so shiny I can see my reflection. Give it a week, rookie.", + "Another raider? The rats in the cellar are trembling... with laughter.", + "Don't worry, we keep the bandages cheap for newcomers like yourself.", + "The practice dummy out back is taking bets against you. Just thought you should know.", + ], + NOVICE: [ + "Back again? You're lasting longer than most of the fresh blood.", + "You're developing some calluses finally. Good, you'll need them.", + "Starting to walk with a bit of confidence, eh? Don't let it go to your head.", + "The local wolves don't laugh quite as hard when they see you coming now.", + "The raiders have stopped taking bets on when you'll quit. Progress!", + ], + INTERMEDIATE: [ + "Now there's a familiar face that's earned their drink!", + "The usual? You've been around long enough to have a usual!", + "Looking more battle-worn these days. It suits you.", + "Your reputation's growing. Heard some kids playing 'mighty raider' in the street.", + "Those monsters in the forest? They're starting to learn your name.", + ], + EXPERIENCED: [ + "Honor to serve you, friend. Your exploits bring customers to my humble establishment.", + "The bards are starting to write songs about you. Decent ones, too!", + "Ah, the hero of the hour! Your usual table awaits.", + "Your presence honors us. What tales will you bring today?", + "They say you've met Moloch face to face. Now that's a tale worth hearing!", + ], + EXPERT: [ + "My most esteemed patron! The usual bottle of our finest?", + "Blessed are we to host a hero of your caliber!", + "The stuff of legends walks among us, friends!", + "They say you've slain dragons now. Dragons! In my tavern!", + "Even the ancient raiders speak of your deeds with reverence.", + ], + MASTER: [ + "You humble us with your magnificent presence!", + "Champions and heroes seek you out for guidance now. How far you've come!", + "They say your name in whispers in the dark kingdoms of Moloch. In fear.", + "To think, I've watched you grow from newcomer to living legend!", + "The ancient prophecies speak of one such as you...", + ], + LEGENDARY: [ + "The greatest raider of our age graces us! All hail!", + "Let it be known - a living legend walks among us!", + "Champion of champions! Slayer of the Moloch!", + "The Moloch speaks your name in terror!", + "Even the gods watch your journey with interest!", + ], +}; + +const EARLY_GAME_QUOTES = [ "There is always Moloch to be slain here...", "We prioritize Shipping at All Costs!", "Get out there RAIDER, Moloch won't Slay Himself!", ]; function PixelatedQuote() { + const { player } = usePlayer(); const [isShown, setIsShown] = useState(true); - const [currentQuote, setCurrentQuote] = useState( - "Welcome to the Dark Forest!" - ); - const intervalIdRef = useRef(null); // Define the type for Node environment compatibility + const [currentQuote, setCurrentQuote] = useState("Welcome to the Dark Forest!"); + const intervalIdRef = useRef(null); + const hasShownWelcome = useRef(false); + + // Determine which tier of quotes to use based on total minted + const getQuoteTier = (totalMinted: bigint) => { + if (totalMinted >= PROGRESSION_TIERS.LEGENDARY) return "LEGENDARY"; + if (totalMinted >= PROGRESSION_TIERS.MASTER) return "MASTER"; + if (totalMinted >= PROGRESSION_TIERS.EXPERT) return "EXPERT"; + if (totalMinted >= PROGRESSION_TIERS.EXPERIENCED) return "EXPERIENCED"; + if (totalMinted >= PROGRESSION_TIERS.INTERMEDIATE) return "INTERMEDIATE"; + if (totalMinted >= PROGRESSION_TIERS.NOVICE) return "NOVICE"; + return "BEGINNER"; + }; useEffect(() => { if (intervalIdRef.current !== null) { clearInterval(intervalIdRef.current); - } // Clear interval if it exists + } - // Set up an interval to show the toast every 10 seconds intervalIdRef.current = setInterval(() => { - setCurrentQuote( - tavernerQuotes[Math.floor(Math.random() * tavernerQuotes.length)] - ); + const totalMinted = player?.total_minted ?? BigInt(0); + + // Show welcome message only once at the start + if (!hasShownWelcome.current) { + setCurrentQuote("Welcome to the Dark Forest!"); + hasShownWelcome.current = true; + } else if (totalMinted < PROGRESSION_TIERS.BEGINNER) { + // Show early game quotes until player reaches beginner level + setCurrentQuote( + EARLY_GAME_QUOTES[Math.floor(Math.random() * EARLY_GAME_QUOTES.length)] + ); + } else { + const tier = getQuoteTier(totalMinted); + const tierQuotes = quotes[tier]; + setCurrentQuote( + tierQuotes[Math.floor(Math.random() * tierQuotes.length)] + ); + } setIsShown(true); - // Hide the toast after 4 seconds setTimeout(() => { setIsShown(false); }, 4000); }, 6000); - // Clean up the interval on component unmount return () => { if (intervalIdRef.current !== null) { - clearInterval(intervalIdRef.current); // Clear interval using correct reference + clearInterval(intervalIdRef.current); intervalIdRef.current = null; } }; - }, []); + }, [player?.total_minted]); return (
{currentQuote}