Refactor ResourceDisplay and gameStore to support multiple active multipliers. Updated UI to display actual click power and total multiplier, enhancing gameplay feedback.
This commit is contained in:
parent
07c47f566a
commit
a9636d9969
@ -2,7 +2,10 @@ import { Box, HStack, Text } from '@chakra-ui/react'
|
|||||||
import { useGameStore } from '../store/gameStore'
|
import { useGameStore } from '../store/gameStore'
|
||||||
|
|
||||||
export function ResourceDisplay() {
|
export function ResourceDisplay() {
|
||||||
const { points, techParts, pointsPerSecond, techPartsPerSecond, clickMultiplier } = useGameStore()
|
const { points, techParts, pointsPerSecond, techPartsPerSecond, clickPower, getTotalMultiplier, activeMultipliers } = useGameStore()
|
||||||
|
|
||||||
|
const totalMultiplier = getTotalMultiplier()
|
||||||
|
const actualClickPower = clickPower * totalMultiplier
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
@ -22,8 +25,9 @@ export function ResourceDisplay() {
|
|||||||
<Text fontSize="xl" fontWeight="bold">Points</Text>
|
<Text fontSize="xl" fontWeight="bold">Points</Text>
|
||||||
<Text fontSize="2xl">{Math.floor(points)}</Text>
|
<Text fontSize="2xl">{Math.floor(points)}</Text>
|
||||||
<Text fontSize="sm" color="green.400">+{pointsPerSecond}/s</Text>
|
<Text fontSize="sm" color="green.400">+{pointsPerSecond}/s</Text>
|
||||||
{clickMultiplier > 1 && (
|
<Text fontSize="sm" color="green.400">Click Power: {actualClickPower}</Text>
|
||||||
<Text fontSize="sm" color="yellow.400">{clickMultiplier}x Click Power</Text>
|
{activeMultipliers.length > 0 && (
|
||||||
|
<Text fontSize="sm" color="yellow.400">{totalMultiplier}x Active</Text>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
<Box textAlign="center">
|
<Box textAlign="center">
|
||||||
|
|||||||
@ -76,6 +76,15 @@ interface GameState {
|
|||||||
|
|
||||||
// New getter for available buildings
|
// New getter for available buildings
|
||||||
getAvailableBuildings: () => BuildingInfo[]
|
getAvailableBuildings: () => BuildingInfo[]
|
||||||
|
|
||||||
|
// Replace single multiplier with array of active multipliers
|
||||||
|
activeMultipliers: Array<{
|
||||||
|
multiplier: number
|
||||||
|
endTime: number
|
||||||
|
}>
|
||||||
|
|
||||||
|
// Add getter for total multiplier
|
||||||
|
getTotalMultiplier: () => number
|
||||||
}
|
}
|
||||||
|
|
||||||
type BuildingType =
|
type BuildingType =
|
||||||
@ -134,6 +143,7 @@ const initialState = {
|
|||||||
clickMultiplier: 1,
|
clickMultiplier: 1,
|
||||||
multiplierEndTime: null,
|
multiplierEndTime: null,
|
||||||
playerLevel: 1,
|
playerLevel: 1,
|
||||||
|
activeMultipliers: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Production rates per building
|
// Production rates per building
|
||||||
@ -398,8 +408,13 @@ export const useGameStore = create<GameState>()(
|
|||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
techParts: state.techParts - purchase.cost,
|
techParts: state.techParts - purchase.cost,
|
||||||
clickMultiplier: multiplier,
|
activeMultipliers: [
|
||||||
multiplierEndTime: now + duration * 1000,
|
...state.activeMultipliers,
|
||||||
|
{
|
||||||
|
multiplier,
|
||||||
|
endTime: now + duration * 1000
|
||||||
|
}
|
||||||
|
]
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -408,9 +423,10 @@ export const useGameStore = create<GameState>()(
|
|||||||
const state = get()
|
const state = get()
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
|
|
||||||
// Check if multiplier has expired
|
// Check for expired multipliers
|
||||||
if (state.multiplierEndTime && now >= state.multiplierEndTime) {
|
const activeMultipliers = state.activeMultipliers.filter(m => m.endTime > now)
|
||||||
set({ clickMultiplier: 1, multiplierEndTime: null })
|
if (activeMultipliers.length !== state.activeMultipliers.length) {
|
||||||
|
set({ activeMultipliers })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update player level based on points per second
|
// Update player level based on points per second
|
||||||
@ -438,6 +454,15 @@ export const useGameStore = create<GameState>()(
|
|||||||
const state = get()
|
const state = get()
|
||||||
return getAvailableBuildings(state.playerLevel)
|
return getAvailableBuildings(state.playerLevel)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Add getter for total multiplier
|
||||||
|
getTotalMultiplier: () => {
|
||||||
|
const state = get()
|
||||||
|
const now = Date.now()
|
||||||
|
return state.activeMultipliers
|
||||||
|
.filter(m => m.endTime > now)
|
||||||
|
.reduce((total, m) => total + (m.multiplier - 1), 1) // Subtract 1 from each multiplier and add 1 at the end
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
name: 'game-storage',
|
name: 'game-storage',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user