fixed bozos

This commit is contained in:
2025-08-04 00:49:44 +05:30
parent 59d11b1ede
commit de827c3748
4 changed files with 46 additions and 22 deletions

View File

@@ -23,6 +23,8 @@ function App() {
const [previousMilestones, setPreviousMilestones] = useState<Record<string, boolean>>({});
const [mascotEntities, setMascotEntities] = useState<ClickableMascotType[]>([]);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
const gameStateRef = useRef(gameState); // Ref to hold the latest gameState
const clickButtonContainerRef = useRef<HTMLDivElement>(null); // New ref for the click button container
const [location] = useLocation(); // Get current location from wouter
const [adminBroadcastMessage, setAdminBroadcastMessage] = useState<string | null>(null); // New state for admin messages
@@ -66,12 +68,18 @@ function App() {
}
}, [lastMessage]);
// Effect to keep gameStateRef updated
useEffect(() => {
gameStateRef.current = gameState;
}, [gameState]);
// Effect for spawning mascots
useEffect(() => {
if (!gameState) return;
// Use gameStateRef.current for initial check and to get latest state inside spawnMascot
if (!gameStateRef.current) return;
const friendBoostUpgrade = UPGRADES.find(u => u.id === 'friendBoost') as Upgrade | undefined;
const ownedFriendBoost = gameState.upgrades['friendBoost']?.owned || 0;
const ownedFriendBoost = gameStateRef.current.upgrades['friendBoost']?.owned || 0;
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
@@ -81,13 +89,19 @@ function App() {
const baseInterval = 10000; // Increased base interval for less frequent spawns
const minInterval = 1000; // Increased min interval
const interval = Math.max(minInterval, baseInterval / (1 + ownedFriendBoost * 0.2)); // Adjusted scaling
console.log(`Spawning mascots every ${interval} ms for friendBoost level ${ownedFriendBoost}`);
const currentMascotTiers = friendBoostUpgrade.mascotTiers; // Ensure mascotTiers is not undefined
const spawnMascot = () => {
const buttonContainer = document.getElementById('click-button-container');
// Access the latest gameState from the ref inside the closure
const currentGameState = gameStateRef.current;
if (!currentGameState) return; // Should not happen if initial check passes
const buttonContainer = clickButtonContainerRef.current; // Use the ref
if (!buttonContainer) {
console.warn('Click button container not found!');
console.warn('Click button container ref not found!');
timeoutRef.current = setTimeout(spawnMascot, 1000); // Retry after 1 second
return;
}
@@ -152,7 +166,7 @@ function App() {
clearTimeout(timeoutRef.current);
}
};
}, [gameState?.upgrades['friendBoost']?.owned, gameState]);
}, [gameState?.upgrades['friendBoost']?.owned]); // Only depend on friendBoost level
const handleMascotClick = (id: string, multiplierBonus: number) => { // Renamed handler
sendMascotClickBonus(multiplierBonus); // Renamed function call
@@ -234,7 +248,7 @@ function App() {
{/* Main Content */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
{/* Left Column - Click Button */}
<div id="click-button-container" className="lg:col-span-1 flex flex-col items-center justify-center relative"> {/* Added id and relative positioning */}
<div ref={clickButtonContainerRef} id="click-button-container" className="lg:col-span-1 flex flex-col items-center justify-center relative"> {/* Added ref, id and relative positioning */}
<ClickButton
onClick={sendClick}
imageUrl={gameState.currentClickImage}

View File

@@ -26,7 +26,7 @@ export const ClickableMascot: React.FC<ClickableMascotProps> = ({ // Renamed fro
setIsVisible(false);
// Give some time for fade-out animation before actual removal
setTimeout(() => onRemove(id), 500);
}, 7000); // Mascot disappears after 7 seconds if not clicked
}, 8000); // Mascot disappears after 8 seconds if not clicked
return () => clearTimeout(timer);
}, [id, onRemove]);

View File

@@ -2,8 +2,8 @@ import { Milestone } from '../types';
export const MILESTONES: Milestone[] = [
{
threshold: 100,
id: 'first-hundred',
threshold: 1000,
id: 'first-thousand',
name: 'First Steps',
description: 'Welcome to the madness!',
background: 'rainbow',
@@ -11,8 +11,8 @@ export const MILESTONES: Milestone[] = [
reward: '🌈 Rainbow Background Unlocked!'
},
{
threshold: 500,
id: 'five-hundred',
threshold: 5000,
id: 'five-thousand',
name: 'Getting Warmed Up',
description: 'The rat spins faster...',
background: 'matrix',
@@ -20,8 +20,8 @@ export const MILESTONES: Milestone[] = [
reward: '💊 Matrix Mode Activated!'
},
{
threshold: 1000,
id: 'one-thousand',
threshold: 10000,
id: 'ten-thousand',
name: 'Cyber Rat',
description: 'Welcome to the future',
background: 'cyberpunk',
@@ -29,7 +29,7 @@ export const MILESTONES: Milestone[] = [
reward: '🦾 Cyberpunk Aesthetic Engaged!'
},
{
threshold: 2500,
threshold: 50000,
id: 'epic-milestone',
name: 'Space Cadet',
description: 'To infinity and beyond!',
@@ -38,7 +38,7 @@ export const MILESTONES: Milestone[] = [
reward: '🚀 Space Background Unlocked!'
},
{
threshold: 5000,
threshold: 100000,
id: 'legendary',
name: 'Glitch in the Matrix',
description: 'Reality is breaking down',
@@ -47,12 +47,21 @@ export const MILESTONES: Milestone[] = [
reward: '⚡ Glitch Effect Activated!'
},
{
threshold: 10000,
threshold: 500000,
id: 'ultimate',
name: 'Ultimate Bozo',
description: 'You have achieved peak bozo status',
background: 'ultimate',
image: 'https://media1.tenor.com/m/YsWlbVbRWFQAAAAd/rat-spinning.gif',
reward: '👑 Ultimate Power Unlocked!'
},
{
threshold: 1000000,
id: 'god-tier',
name: 'God Tier Bozo',
description: 'You are the ultimate bozo',
background: 'god-tier',
image: 'https://media1.tenor.com/m/x8v1oNUOmg4AAAAd/spinning-rat-rat.gif',
reward: '🌟 God Mode Activated!'
}
];